RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
feat: save graph data before opening the debug drawer #918 (#1387)
balibabu472fcba7af1f
diff --git a/web/src/pages/flow/chat/hooks.ts b/web/src/pages/flow/chat/hooks.tsindex 0059c07972..b7d19262aa 100644--- a/web/src/pages/flow/chat/hooks.ts+++ b/web/src/pages/flow/chat/hooks.ts@@ -1,5 +1,5 @@import { MessageType } from '@/constants/chat';-import { useFetchFlow, useResetFlow } from '@/hooks/flow-hooks';+import { useFetchFlow } from '@/hooks/flow-hooks';import {useHandleMessageInputChange,useScrollToBottom,@@ -12,6 +12,7 @@ import { message } from 'antd';import { useCallback, useEffect, useState } from 'react';import { useParams } from 'umi';import { v4 as uuid } from 'uuid';+import { receiveMessageError } from '../utils';const antMessage = message;@@ -94,7 +95,6 @@ export const useSendMessage = (const { id: flowId } = useParams();const { handleInputChange, value, setValue } = useHandleMessageInputChange();const { refetch } = useFetchFlow();- const { resetFlow } = useResetFlow();const { send, answer, done } = useSendMessageWithSse(api.runCanvas);@@ -108,7 +108,7 @@ export const useSendMessage = (}const res = await send(params);- if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {+ if (receiveMessageError(res)) {antMessage.error(res?.data?.retmsg);// cancel loading@@ -128,28 +128,12 @@ export const useSendMessage = ([sendMessage],);- /**- * Call the reset api before opening the run drawer each time- */- const resetFlowBeforeFetchingPrologue = useCallback(async () => {- // After resetting, all previous messages will be cleared.- const ret = await resetFlow();- if (ret.retcode === 0) {- // fetch prologue- sendMessage('');- }- }, [resetFlow, sendMessage]);-useEffect(() => {if (answer.answer) {addNewestAnswer(answer);}}, [answer, addNewestAnswer]);- useEffect(() => {- resetFlowBeforeFetchingPrologue();- }, [resetFlowBeforeFetchingPrologue]);-const handlePressEnter = useCallback(() => {if (done) {setValue('');diff --git a/web/src/pages/flow/header/index.tsx b/web/src/pages/flow/header/index.tsxindex ef5c13960e..551604849f 100644--- a/web/src/pages/flow/header/index.tsx+++ b/web/src/pages/flow/header/index.tsx@@ -3,7 +3,7 @@ import { Button, Flex, Space } from 'antd';import { useFetchFlow } from '@/hooks/flow-hooks';import { ArrowLeftOutlined } from '@ant-design/icons';import { Link } from 'umi';-import { useSaveGraph } from '../hooks';+import { useSaveGraph, useSaveGraphBeforeOpeningDebugDrawer } from '../hooks';import styles from './index.less';@@ -13,7 +13,7 @@ interface IProps {const FlowHeader = ({ showChatDrawer }: IProps) => {const { saveGraph } = useSaveGraph();-+ const handleRun = useSaveGraphBeforeOpeningDebugDrawer(showChatDrawer);const { data } = useFetchFlow();return (@@ -31,7 +31,7 @@ const FlowHeader = ({ showChatDrawer }: IProps) => {<h3>{data.title}</h3></Space><Space size={'large'}>- <Button onClick={showChatDrawer}>+ <Button onClick={handleRun}><b>Run</b></Button><Button type="primary" onClick={saveGraph}>diff --git a/web/src/pages/flow/hooks.ts b/web/src/pages/flow/hooks.tsindex d0776b9d8f..3d3b103652 100644--- a/web/src/pages/flow/hooks.ts+++ b/web/src/pages/flow/hooks.ts@@ -1,5 +1,5 @@import { useSetModalState } from '@/hooks/commonHooks';-import { useFetchFlow, useSetFlow } from '@/hooks/flow-hooks';+import { useFetchFlow, useResetFlow, useSetFlow } from '@/hooks/flow-hooks';import { useFetchLlmList } from '@/hooks/llmHooks';import { IGraph } from '@/interfaces/database/flow';import { useIsFetching } from '@tanstack/react-query';@@ -17,8 +17,9 @@ import {ModelVariableType,settledModelVariableMap,} from '@/constants/knowledge';-import { useFetchModelId } from '@/hooks/logicHooks';+import { useFetchModelId, useSendMessageWithSse } from '@/hooks/logicHooks';import { Variable } from '@/interfaces/database/chat';+import api from '@/utils/api';import { useDebounceEffect } from 'ahooks';import { FormInstance, message } from 'antd';import { humanId } from 'human-id';@@ -37,7 +38,7 @@ import {initialRewriteQuestionValues,} from './constant';import useGraphStore, { RFState } from './store';-import { buildDslComponentsByGraph } from './utils';+import { buildDslComponentsByGraph, receiveMessageError } from './utils';const selector = (state: RFState) => ({nodes: state.nodes,@@ -193,9 +194,9 @@ export const useSaveGraph = () => {const { setFlow } = useSetFlow();const { id } = useParams();const { nodes, edges } = useGraphStore((state) => state);- const saveGraph = useCallback(() => {+ const saveGraph = useCallback(async () => {const dslComponents = buildDslComponentsByGraph(nodes, edges);- setFlow({+ return setFlow({id,title: data.title,dsl: { ...data.dsl, graph: { nodes, edges }, components: dslComponents },@@ -345,3 +346,29 @@ export const useHandleNodeNameChange = (node?: Node) => {return { name, handleNameBlur, handleNameChange };};++export const useSaveGraphBeforeOpeningDebugDrawer = (show: () => void) => {+ const { id } = useParams();+ const { saveGraph } = useSaveGraph();+ const { resetFlow } = useResetFlow();+ const { send } = useSendMessageWithSse(api.runCanvas);+ const handleRun = useCallback(async () => {+ const saveRet = await saveGraph();+ if (saveRet?.retcode === 0) {+ // Call the reset api before opening the run drawer each time+ const resetRet = await resetFlow();+ // After resetting, all previous messages will be cleared.+ if (resetRet?.retcode === 0) {+ // fetch prologue+ const sendRet = await send({ id });+ if (receiveMessageError(sendRet)) {+ message.error(sendRet?.data?.retmsg);+ } else {+ show();+ }+ }+ }+ }, [saveGraph, resetFlow, id, send, show]);++ return handleRun;+};diff --git a/web/src/pages/flow/utils.ts b/web/src/pages/flow/utils.tsindex fff2cf38e5..80a5a32144 100644--- a/web/src/pages/flow/utils.ts+++ b/web/src/pages/flow/utils.ts@@ -181,3 +181,6 @@ export const buildDslComponentsByGraph = (return components;};++export const receiveMessageError = (res: any) =>+ res && (res?.response.status !== 200 || res?.data?.retcode !== 0);