diff --git a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts index 2f650b611a..daa2600e0b 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts @@ -152,7 +152,19 @@ const useOneStepRun = ({ }, []) const iterationTimes = iteratorInputKey ? runInputData[iteratorInputKey].length : 0 const loopTimes = loopInputKey ? runInputData[loopInputKey].length : 0 - const [runResult, setRunResult] = useState(null) + + const workflowStore = useWorkflowStore() + const { + setLastRunNodeInfo, + setCurrentNodeVars, + setShowSingleRunPanel, + } = workflowStore.getState() + const [runResult, doSetRunResult] = useState(null) + const setRunResult = useCallback((data: NodeRunResult | null) => { + doSetRunResult(data) + setLastRunNodeInfo(id, data as any) + setCurrentNodeVars(id, data as any) + }, [id, setLastRunNodeInfo, setCurrentNodeVars]) const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useNodeDataUpdate() const [canShowSingleRun, setCanShowSingleRun] = useState(false) @@ -186,10 +198,9 @@ const useOneStepRun = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [data._isSingleRun]) - const workflowStore = useWorkflowStore() useEffect(() => { - workflowStore.getState().setShowSingleRunPanel(!!isShowSingleRun) - }, [isShowSingleRun, workflowStore]) + setShowSingleRunPanel(!!isShowSingleRun) + }, [isShowSingleRun, setShowSingleRunPanel]) const hideSingleRun = () => { handleNodeDataUpdate({ diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx index 9307b0967c..b09e283af1 100644 --- a/web/app/components/workflow/nodes/llm/panel.tsx +++ b/web/app/components/workflow/nodes/llm/panel.tsx @@ -33,9 +33,8 @@ const Panel = forwardRef>(({ const { t } = useTranslation() const { currentVars, - getLastRunInfos, } = useCurrentVars() - // console.log(currentVars, getLastRunInfos()) + console.log(currentVars) const { readOnly, inputs, diff --git a/web/app/components/workflow/store/workflow/current-vars-slice.ts b/web/app/components/workflow/store/workflow/current-vars-slice.ts index 4815cb062a..a72a2e0d26 100644 --- a/web/app/components/workflow/store/workflow/current-vars-slice.ts +++ b/web/app/components/workflow/store/workflow/current-vars-slice.ts @@ -41,14 +41,15 @@ export const createCurrentVarsSlice: StateCreator = (set, }, setCurrentNodeVars: (nodeId, payload) => { set((state) => { - const nodes = state.currentNodes.map((node) => { - // eslint-disable-next-line curly - if (node.node_id === nodeId) { - return payload - } - - return node + const prevNodes = state.currentNodes + const nodes = produce(prevNodes, (draft) => { + const index = prevNodes.findIndex(node => node.id === nodeId) + if (index === -1) + draft.push(payload) + else + draft[index] = payload }) + return { currentNodes: nodes, } diff --git a/web/app/components/workflow/store/workflow/last-run-slice.ts b/web/app/components/workflow/store/workflow/last-run-slice.ts index 57059e2171..6fc16ed3d5 100644 --- a/web/app/components/workflow/store/workflow/last-run-slice.ts +++ b/web/app/components/workflow/store/workflow/last-run-slice.ts @@ -1,4 +1,5 @@ import type { NodeTracing } from '@/types/workflow' +import produce from 'immer' import type { StateCreator } from 'zustand' type NodeInfo = NodeTracing @@ -10,6 +11,7 @@ type LastRunState = { type LastRunActions = { setLastRunInfos: (vars: NodeInfo[]) => void getLastRunInfos: () => NodeInfo[] + setLastRunNodeInfo: (nodeId: string, payload: NodeInfo) => void getLastRunNodeInfo: (nodeId: string) => NodeInfo | undefined getLastRunVar: (nodeId: string, key: string) => any } @@ -32,6 +34,22 @@ export const createLastRunSlice: StateCreator = (set, get) => nodes: [], })) }, + setLastRunNodeInfo: (nodeId, payload) => { + set((state) => { + const prevNodes = state.nodes + const nodes = produce(prevNodes, (draft) => { + const index = prevNodes.findIndex(node => node.id === nodeId) + if (index === -1) + draft.push(payload) + else + draft[index] = payload + }) + + return { + nodes, + } + }) + }, getLastRunNodeInfo: (nodeId) => { const nodes = get().nodes return nodes.find(node => node.node_id === nodeId)