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 f10de8d2e6..4815cb062a 100644 --- a/web/app/components/workflow/store/workflow/current-vars-slice.ts +++ b/web/app/components/workflow/store/workflow/current-vars-slice.ts @@ -1,17 +1,9 @@ import type { StateCreator } from 'zustand' - import produce from 'immer' +import type { NodeTracing } from '@/types/workflow' -type NodeVars = { - id: string - name: string - type: string - vars: { - key: string - type: string - value: any - }[] -} +// TODO: Missing var type +type NodeVars = NodeTracing type CurrentVarsState = { currentNodes: NodeVars[] @@ -33,12 +25,7 @@ export type CurrentVarsSliceShape = CurrentVarsState & CurrentVarsActions export const createCurrentVarsSlice: StateCreator = (set, get) => { return ({ - currentNodes: [{ - id: 'abc', - name: '', - type: '', - vars: [], - }], + currentNodes: [], setCurrentVars: (vars) => { set(() => ({ currentNodes: vars, @@ -52,13 +39,12 @@ export const createCurrentVarsSlice: StateCreator = (set, currentNodes: [], })) }, - setCurrentNodeVars: (nodeId, vars) => { + setCurrentNodeVars: (nodeId, payload) => { set((state) => { const nodes = state.currentNodes.map((node) => { - if (node.id === nodeId) { - return produce(node, (draft) => { - draft.vars = vars.vars - }) + // eslint-disable-next-line curly + if (node.node_id === nodeId) { + return payload } return node @@ -70,14 +56,14 @@ export const createCurrentVarsSlice: StateCreator = (set, }, clearCurrentNodeVars: (nodeId) => { set(produce((state: CurrentVarsSliceShape) => { - const nodes = state.currentNodes.filter(node => node.id !== nodeId) + const nodes = state.currentNodes.filter(node => node.node_id !== nodeId) state.currentNodes = nodes }, )) }, getCurrentNodeVars: (nodeId) => { const nodes = get().currentNodes - return nodes.find(node => node.id === nodeId) + return nodes.find(node => node.node_id === nodeId) }, hasCurrentNodeVars: (nodeId) => { return !!get().getCurrentNodeVars(nodeId) @@ -87,9 +73,9 @@ export const createCurrentVarsSlice: StateCreator = (set, const nodes = state.currentNodes.map((node) => { if (node.id === nodeId) { return produce(node, (draft) => { - const index = draft.vars.findIndex(v => v.key === key) - if (index !== -1) - draft.vars[index].value = value + if (!draft.outputs) + draft.outputs = {} + draft.outputs[key] = value }) } return node @@ -102,11 +88,8 @@ export const createCurrentVarsSlice: StateCreator = (set, if (!node) return undefined - const variable = node.vars.find(v => v.key === key) - if (!variable) - return undefined - - return variable.value + const variable = node.outputs?.[key] + return variable }, }) } 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 662e5b2727..57059e2171 100644 --- a/web/app/components/workflow/store/workflow/last-run-slice.ts +++ b/web/app/components/workflow/store/workflow/last-run-slice.ts @@ -1,18 +1,7 @@ +import type { NodeTracing } from '@/types/workflow' import type { StateCreator } from 'zustand' -type NodeInfo = { - id: string - name: string - type: string - vars: { - key: string - type: string - value: any - }[] -} & { - input: Record - output: Record -} +type NodeInfo = NodeTracing type LastRunState = { nodes: NodeInfo[] @@ -29,14 +18,7 @@ export type LastRunSliceShape = LastRunState & LastRunActions export const createLastRunSlice: StateCreator = (set, get) => { return ({ - nodes: [{ - id: 'test', - name: '', - type: '', - vars: [], - input: {}, - output: {}, - }], + nodes: [], setLastRunInfos: (vars) => { set(() => ({ nodes: vars, @@ -52,18 +34,18 @@ export const createLastRunSlice: StateCreator = (set, get) => }, getLastRunNodeInfo: (nodeId) => { const nodes = get().nodes - return nodes.find(node => node.id === nodeId) + return nodes.find(node => node.node_id === nodeId) }, getLastRunVar: (nodeId, key) => { const node = get().getLastRunNodeInfo(nodeId) if (!node) return undefined - const varItem = node.vars.find(v => v.key === key) + const varItem = node if (!varItem) return undefined - return varItem.value + return varItem.outputs?.[key] }, }) } diff --git a/web/types/workflow.ts b/web/types/workflow.ts index 2628ac2cc7..3ec801afbe 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -38,7 +38,7 @@ export type NodeTracing = { title: string inputs: any process_data: any - outputs?: any + outputs?: Record status: string parallel_run_id?: string error?: string