From 881d23876030a2d88f3963f0ba42ebf08ea3c531 Mon Sep 17 00:00:00 2001 From: sd0ric4 <1286518974@qq.com> Date: Wed, 26 Mar 2025 17:51:09 +0800 Subject: [PATCH] feat: refactor onNextNodeDebug to use parameter object for better readability --- .../WorkflowComponents/context/index.tsx | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/projects/app/src/pageComponents/app/detail/WorkflowComponents/context/index.tsx b/projects/app/src/pageComponents/app/detail/WorkflowComponents/context/index.tsx index 66a831441..9201921b2 100644 --- a/projects/app/src/pageComponents/app/detail/WorkflowComponents/context/index.tsx +++ b/projects/app/src/pageComponents/app/detail/WorkflowComponents/context/index.tsx @@ -167,16 +167,11 @@ type WorkflowContextType = { history?: ChatItemType[]; } | undefined; - onNextNodeDebug: ( - history?: ChatItemType[], - query?: UserChatItemValueItemType[], - debugData?: { - runtimeNodes: RuntimeNodeItemType[]; - runtimeEdges: RuntimeEdgeItemType[]; - nextRunNodes: RuntimeNodeItemType[]; - variables: Record; - } - ) => Promise; + onNextNodeDebug: (params?: { + history?: ChatItemType[]; + query?: UserChatItemValueItemType[]; + debugData?: DebugDataType; + }) => Promise; onStartNodeDebug: ({ entryNodeId, runtimeNodes, @@ -253,11 +248,11 @@ export const WorkflowContext = createContext({ throw new Error('Function not implemented.'); }, workflowDebugData: undefined, - onNextNodeDebug: function ( - history?: ChatItemType[], - query?: UserChatItemValueItemType[], - debugData?: any - ): Promise { + onNextNodeDebug: function (params?: { + history?: ChatItemType[]; + query?: UserChatItemValueItemType[]; + debugData?: DebugDataType; + }): Promise { throw new Error('Function not implemented.'); }, onStartNodeDebug: function ({ @@ -576,11 +571,13 @@ const WorkflowContextProvider = ({ /* debug */ const [workflowDebugData, setWorkflowDebugData] = useState(); const onNextNodeDebug = useCallback( - async ( - history?: ChatItemType[], - query?: UserChatItemValueItemType[], - debugData = workflowDebugData - ) => { + async (params?: { + history?: ChatItemType[]; + query?: UserChatItemValueItemType[]; + debugData?: DebugDataType; + }) => { + // 解构参数并提供默认值 + const { history, query, debugData = workflowDebugData } = params || {}; if (!debugData) return; // 1. Cancel node selected status and debugResult.showStatus setNodes((state) => @@ -707,7 +704,7 @@ const WorkflowContextProvider = ({ // Check for an empty response if (flowResponses.length === 0 && nextStepRunNodes.length > 0) { - onNextNodeDebug(history, query, newStoreDebugData); + onNextNodeDebug({ history, query, debugData: newStoreDebugData }); } } catch (error) { entryNodes.forEach((node) => { @@ -767,7 +764,11 @@ const WorkflowContextProvider = ({ onStopNodeDebug(); setWorkflowDebugData(data); - onNextNodeDebug(history, query, data); + onNextNodeDebug({ + history, + query, + debugData: data + }); } );