mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Create empty agent #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -1,4 +1,8 @@
|
||||
import { useFetchFlow, useResetFlow, useSetFlow } from '@/hooks/flow-hooks';
|
||||
import {
|
||||
useFetchAgent,
|
||||
useResetAgent,
|
||||
useSetAgent,
|
||||
} from '@/hooks/use-agent-request';
|
||||
import { RAGFlowNodeType } from '@/interfaces/database/flow';
|
||||
import { useDebounceEffect } from 'ahooks';
|
||||
import dayjs from 'dayjs';
|
||||
@ -8,20 +12,20 @@ import useGraphStore from '../store';
|
||||
import { useBuildDslData } from './use-build-dsl';
|
||||
|
||||
export const useSaveGraph = () => {
|
||||
const { data } = useFetchFlow();
|
||||
const { setFlow, loading } = useSetFlow();
|
||||
const { data } = useFetchAgent();
|
||||
const { setAgent, loading } = useSetAgent();
|
||||
const { id } = useParams();
|
||||
const { buildDslData } = useBuildDslData();
|
||||
|
||||
const saveGraph = useCallback(
|
||||
async (currentNodes?: RAGFlowNodeType[]) => {
|
||||
return setFlow({
|
||||
return setAgent({
|
||||
id,
|
||||
title: data.title,
|
||||
dsl: buildDslData(currentNodes),
|
||||
});
|
||||
},
|
||||
[setFlow, id, data.title, buildDslData],
|
||||
[setAgent, id, data.title, buildDslData],
|
||||
);
|
||||
|
||||
return { saveGraph, loading };
|
||||
@ -29,21 +33,21 @@ export const useSaveGraph = () => {
|
||||
|
||||
export const useSaveGraphBeforeOpeningDebugDrawer = (show: () => void) => {
|
||||
const { saveGraph, loading } = useSaveGraph();
|
||||
const { resetFlow } = useResetFlow();
|
||||
const { resetAgent } = useResetAgent();
|
||||
|
||||
const handleRun = useCallback(
|
||||
async (nextNodes?: RAGFlowNodeType[]) => {
|
||||
const saveRet = await saveGraph(nextNodes);
|
||||
if (saveRet?.code === 0) {
|
||||
// Call the reset api before opening the run drawer each time
|
||||
const resetRet = await resetFlow();
|
||||
const resetRet = await resetAgent();
|
||||
// After resetting, all previous messages will be cleared.
|
||||
if (resetRet?.code === 0) {
|
||||
show();
|
||||
}
|
||||
}
|
||||
},
|
||||
[saveGraph, resetFlow, show],
|
||||
[saveGraph, resetAgent, show],
|
||||
);
|
||||
|
||||
return { handleRun, loading };
|
||||
@ -54,7 +58,7 @@ export const useWatchAgentChange = (chatDrawerVisible: boolean) => {
|
||||
const nodes = useGraphStore((state) => state.nodes);
|
||||
const edges = useGraphStore((state) => state.edges);
|
||||
const { saveGraph } = useSaveGraph();
|
||||
const { data: flowDetail } = useFetchFlow();
|
||||
const { data: flowDetail } = useFetchAgent();
|
||||
|
||||
const setSaveTime = useCallback((updateTime: number) => {
|
||||
setTime(dayjs(updateTime).format('YYYY-MM-DD HH:mm:ss'));
|
||||
|
||||
Reference in New Issue
Block a user