diff --git a/web/app/components/workflow/hooks/use-current-vars.ts b/web/app/components/workflow/hooks/use-current-vars.ts index b674da158b..eeddb9728b 100644 --- a/web/app/components/workflow/hooks/use-current-vars.ts +++ b/web/app/components/workflow/hooks/use-current-vars.ts @@ -2,7 +2,7 @@ import { useWorkflowStore } from '../store' const useCurrentVars = () => { const workflowStore = useWorkflowStore() const { - nodes: currentNodes, + nodesWithInspectVars: currentNodes, getInspectVar: getCurrentVar, setInspectVar: setCurrentVar, clearInspectVars: clearCurrentVars, diff --git a/web/app/components/workflow/store/workflow/var-inspect-slice.ts b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts similarity index 69% rename from web/app/components/workflow/store/workflow/var-inspect-slice.ts rename to web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts index db1bdefed4..93a8fe0f96 100644 --- a/web/app/components/workflow/store/workflow/var-inspect-slice.ts +++ b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts @@ -1,15 +1,16 @@ import type { StateCreator } from 'zustand' import produce from 'immer' import type { NodeWithVar, VarInInspect } from '@/types/workflow' -import type { ValueSelector } from '../../types' +import type { ValueSelector } from '../../../types' type InspectVarsState = { currentFocusNodeId: string | null - nodes: NodeWithVar[] // the nodes have data + nodesWithInspectVars: NodeWithVar[] // the nodes have data conversationVars: VarInInspect[] } type InspectVarsActions = { + setCurrentFocusNodeId: (nodeId: string | null) => void getAllInspectVars: () => NodeWithVar[] clearInspectVars: () => void setNodeInspectVars: (nodeId: string, payload: NodeWithVar) => void @@ -20,24 +21,29 @@ type InspectVarsActions = { getInspectVar: (nodeId: string, selector: ValueSelector) => any } -export type CurrentVarsSliceShape = InspectVarsState & InspectVarsActions +export type InspectVarsSliceShape = InspectVarsState & InspectVarsActions -export const createInspectVarsSlice: StateCreator = (set, get) => { +export const createInspectVarsSlice: StateCreator = (set, get) => { return ({ currentFocusNodeId: null, - nodes: [], + nodesWithInspectVars: [], conversationVars: [], + setCurrentFocusNodeId: (nodeId) => { + set(() => ({ + currentFocusNodeId: nodeId, + })) + }, getAllInspectVars: () => { - return get().nodes + return get().nodesWithInspectVars }, clearInspectVars: () => { set(() => ({ - nodes: [], + nodesWithInspectVars: [], })) }, setNodeInspectVars: (nodeId, payload) => { set((state) => { - const prevNodes = state.nodes + const prevNodes = state.nodesWithInspectVars const nodes = produce(prevNodes, (draft) => { const index = prevNodes.findIndex(node => node.nodeId === nodeId) if (index === -1) @@ -47,27 +53,27 @@ export const createInspectVarsSlice: StateCreator = (set, }) return { - nodes, + nodesWithInspectVars: nodes, } }) }, clearNodeInspectVars: (nodeId) => { - set(produce((state: CurrentVarsSliceShape) => { - const nodes = state.nodes.filter(node => node.nodeId !== nodeId) - state.nodes = nodes + set(produce((state: InspectVarsSliceShape) => { + const nodes = state.nodesWithInspectVars.filter(node => node.nodeId !== nodeId) + state.nodesWithInspectVars = nodes }, )) }, getNodeInspectVars: (nodeId) => { - const nodes = get().nodes + const nodes = get().nodesWithInspectVars return nodes.find(node => node.nodeId === nodeId) }, hasNodeInspectVars: (nodeId) => { return !!get().getNodeInspectVars(nodeId) }, setInspectVar: (nodeId, selector, value) => { - set(produce((state: CurrentVarsSliceShape) => { - const nodes = state.nodes.map((node) => { + set(produce((state: InspectVarsSliceShape) => { + const nodes = state.nodesWithInspectVars.map((node) => { if (node.nodeId === nodeId) { return produce(node, (draft) => { const needChangeVarIndex = draft.vars.findIndex((varItem) => { @@ -79,7 +85,7 @@ export const createInspectVarsSlice: StateCreator = (set, } return node }) - state.nodes = nodes + state.nodesWithInspectVars = nodes })) }, getInspectVar(nodeId, key) { diff --git a/web/app/components/workflow/store/workflow/last-run-slice.ts b/web/app/components/workflow/store/workflow/debug/last-run-slice.ts similarity index 100% rename from web/app/components/workflow/store/workflow/last-run-slice.ts rename to web/app/components/workflow/store/workflow/debug/last-run-slice.ts diff --git a/web/app/components/workflow/store/workflow/index.ts b/web/app/components/workflow/store/workflow/index.ts index a3f368561d..2c1d1a4c6c 100644 --- a/web/app/components/workflow/store/workflow/index.ts +++ b/web/app/components/workflow/store/workflow/index.ts @@ -28,10 +28,10 @@ import type { WorkflowDraftSliceShape } from './workflow-draft-slice' import { createWorkflowDraftSlice } from './workflow-draft-slice' import type { WorkflowSliceShape } from './workflow-slice' import { createWorkflowSlice } from './workflow-slice' -import type { LastRunSliceShape } from './last-run-slice' -import { createLastRunSlice } from './last-run-slice' -import type { CurrentVarsSliceShape } from './var-inspect-slice' -import { createInspectVarsSlice } from './var-inspect-slice' +import type { LastRunSliceShape } from './debug/last-run-slice' +import { createLastRunSlice } from './debug/last-run-slice' +import type { InspectVarsSliceShape } from './debug/inspect-vars-slice' +import { createInspectVarsSlice } from './debug/inspect-vars-slice' import { WorkflowContext } from '@/app/components/workflow/context' import type { LayoutSliceShape } from './layout-slice' @@ -51,7 +51,7 @@ export type Shape = WorkflowDraftSliceShape & WorkflowSliceShape & LastRunSliceShape & - CurrentVarsSliceShape & + InspectVarsSliceShape & LayoutSliceShape & WorkflowAppSliceShape diff --git a/web/types/workflow.ts b/web/types/workflow.ts index f67cf067b1..ece3b6a31c 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -379,11 +379,11 @@ export enum VarInInspectType { } export type VarInInspect = { - id: string + id?: string // value parse from output not has id type: VarInInspectType name: string description: string - selector: ValueSelector + selector: ValueSelector // can get node id from selector[0] value_type: VarType value: any edited: boolean