diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts index ee47adda48..f52150abbe 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts @@ -1,6 +1,7 @@ import { fetchNodeInspectVars } from '@/service/workflow' import { useStore, useWorkflowStore } from '../store' import type { ValueSelector } from '../types' +import type { VarInInspect } from '@/types/workflow' import { VarInInspectType } from '@/types/workflow' import { useConversationVarValues, @@ -14,6 +15,7 @@ import { useSysVarValues, } from '@/service/use-workflow' import { useCallback, useEffect, useState } from 'react' +import { isConversationVar, isENV, isSystemVar } from '../nodes/_base/components/variable/utils' const useInspectVarsCrud = () => { const workflowStore = useWorkflowStore() @@ -22,12 +24,10 @@ const useInspectVarsCrud = () => { appId, setNodeInspectVars, setInspectVarValue, - getVarId, renameInspectVarName: renameInspectVarNameInStore, deleteAllInspectVars: deleteAllInspectVarsInStore, deleteNodeInspectVars: deleteNodeInspectVarsInStore, deleteInspectVar: deleteInspectVarInStore, - isInspectVarEdited, } = workflowStore.getState() const { data: conversationVars } = useConversationVarValues(appId) @@ -46,6 +46,40 @@ const useInspectVarsCrud = () => { return node }, [nodesWithInspectVars]) + const getVarId = useCallback((nodeId: string, varName: string) => { + const node = getNodeInspectVars(nodeId) + if (!node) + return undefined + const varId = node.vars.find((varItem) => { + return varItem.selector[1] === varName + })?.id + return varId + }, [getNodeInspectVars]) + + const getInspectVar = useCallback((nodeId: string, name: string) => { + const node = getNodeInspectVars(nodeId) + if (!node) + return undefined + + const variable = node.vars.find((varItem) => { + return varItem.selector[1] === name + })?.value + return variable + }, [getNodeInspectVars]) + + const hasSetInspectVar = useCallback((nodeId: string, name: string, sysVars: VarInInspect[], conversationVars: VarInInspect[]) => { + const isEnv = isENV([nodeId]) + if (isEnv) // always have value + return true + const isSys = isSystemVar([nodeId]) + if (isSys) + return sysVars.some(varItem => varItem.selector?.[1] === name) + const isChatVar = isConversationVar([nodeId]) + if (isChatVar) + return conversationVars.some(varItem => varItem.selector?.[1] === name) + return getInspectVar(nodeId, name) !== undefined + }, [getInspectVar]) + const hasNodeInspectVars = useCallback((nodeId: string) => { return !!getNodeInspectVars(nodeId) }, [getNodeInspectVars]) @@ -129,6 +163,14 @@ const useInspectVarsCrud = () => { renameInspectVarNameInStore(nodeId, varId, newSelector) } + const isInspectVarEdited = useCallback((nodeId: string, name: string) => { + const inspectVar = getInspectVar(nodeId, name) + if (!inspectVar) + return false + + return inspectVar.edited + }, [getInspectVar]) + const resetToLastRunVar = (nodeId: string, varId: string) => { setCurrNodeId(nodeId) setCurrEditVarId(varId) @@ -139,6 +181,7 @@ const useInspectVarsCrud = () => { systemVars: systemVars || [], nodesWithInspectVars, hasNodeInspectVars, + hasSetInspectVar, fetchInspectVarValue, editInspectVarValue, renameInspectVarName, diff --git a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts index 00ecb11491..127c54ef08 100644 --- a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts +++ b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts @@ -2,7 +2,6 @@ import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-s import type { Params as OneStepRunParams } from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run' import { useCallback, useState } from 'react' import { TabType } from '../tab' -import { useWorkflowStore } from '@/app/components/workflow/store' import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form' import useStartSingleRunFormParams from '@/app/components/workflow/nodes/start/use-single-run-form-params' import useLLMSingleRunFormParams from '@/app/components/workflow/nodes/llm/use-single-run-form-params' @@ -19,7 +18,6 @@ import useDocExtractorSingleRunFormParams from '@/app/components/workflow/nodes/ import useLoopSingleRunFormParams from '@/app/components/workflow/nodes/loop/use-single-run-form-params' import useIfElseSingleRunFormParams from '@/app/components/workflow/nodes/if-else/use-single-run-form-params' import useVariableAggregatorSingleRunFormParams from '@/app/components/workflow/nodes/variable-assigner/use-single-run-form-params' - import useToolGetDataForCheckMore from '@/app/components/workflow/nodes/tool/use-get-data-for-check-more' // import @@ -102,7 +100,7 @@ type Params = OneStepRunParams const useLastRun = ({ ...oneStepRunParams }: Params) => { - const { conversationVars, systemVars } = useInspectVarsCrud() + const { conversationVars, systemVars, hasSetInspectVar } = useInspectVarsCrud() const blockType = oneStepRunParams.data.type const { handleSyncWorkflowDraft } = useNodesSyncDraft() const { @@ -166,10 +164,6 @@ const useLastRun = ({ setTabType(type) }, []) - const workflowStore = useWorkflowStore() - const { - hasSetInspectVar, - } = workflowStore.getState() const getExistVarValuesInForms = (forms: FormProps[]) => { if (!forms || forms.length === 0) return [] diff --git a/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts index 94b9089cb2..97588d8f2c 100644 --- a/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts +++ b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts @@ -3,7 +3,6 @@ import produce from 'immer' import type { NodeWithVar, VarInInspect } from '@/types/workflow' import type { ValueSelector } from '../../../types' import type { Node } from '@/app/components/workflow/types' -import { isConversationVar, isENV, isSystemVar } from '../../../nodes/_base/components/variable/utils' type InspectVarsState = { currentFocusNodeId: string | null @@ -15,18 +14,12 @@ type InspectVarsActions = { setCurrentFocusNodeId: (nodeId: string | null) => void setNodesWithInspectVars: (payload: NodeWithVar[]) => void deleteAllInspectVars: () => void - getAllInspectVars: () => NodeWithVar[] setNodeInspectVars: (nodeId: string, payload: VarInInspect[]) => void appendNodeInspectVars: (nodeId: string, payload: VarInInspect[], allNodes: Node[]) => void deleteNodeInspectVars: (nodeId: string) => void - getNodeInspectVars: (nodeId: string) => NodeWithVar | undefined - getVarId: (nodeId: string, varName: string) => string | undefined setInspectVarValue: (nodeId: string, name: string, value: any) => void renameInspectVarName: (nodeId: string, varId: string, selector: ValueSelector) => void deleteInspectVar: (nodeId: string, varId: string) => void - getInspectVar: (nodeId: string, name: string) => any - hasSetInspectVar: (nodeId: string, name: string, sysVars: VarInInspect[], conversationVars: VarInInspect[]) => boolean - isInspectVarEdited: (nodeId: string, name: string) => boolean } export type InspectVarsSliceShape = InspectVarsState & InspectVarsActions @@ -46,9 +39,6 @@ export const createInspectVarsSlice: StateCreator = (set, nodesWithInspectVars: payload, })) }, - getAllInspectVars: () => { - return get().nodesWithInspectVars - }, deleteAllInspectVars: () => { set(() => ({ nodesWithInspectVars: [], @@ -101,19 +91,6 @@ export const createInspectVarsSlice: StateCreator = (set, }, )) }, - getNodeInspectVars: (nodeId) => { - const nodes = get().nodesWithInspectVars - return nodes.find(node => node.nodeId === nodeId) - }, - getVarId: (nodeId: string, varName: string) => { - const node = get().getNodeInspectVars(nodeId) - if (!node) - return undefined - const varId = node.vars.find((varItem) => { - return varItem.selector[1] === varName - })?.id - return varId - }, setInspectVarValue: (nodeId, varId, value) => { set(produce((state: InspectVarsSliceShape) => { const nodes = state.nodesWithInspectVars.map((node) => { @@ -167,34 +144,5 @@ export const createInspectVarsSlice: StateCreator = (set, state.nodesWithInspectVars = nodes })) }, - getInspectVar: (nodeId, name) => { - const node = get().getNodeInspectVars(nodeId) - if (!node) - return undefined - - const variable = node.vars.find((varItem) => { - return varItem.selector[1] === name - })?.value - return variable - }, - hasSetInspectVar: (nodeId, name, sysVars, conversationVars) => { - const isEnv = isENV([nodeId]) - if (isEnv) // always have value - return true - const isSys = isSystemVar([nodeId]) - if (isSys) - return sysVars.some(varItem => varItem.selector?.[1] === name) - const isChatVar = isConversationVar([nodeId]) - if (isChatVar) - return conversationVars.some(varItem => varItem.selector?.[1] === name) - return get().getInspectVar(nodeId, name) !== undefined - }, - isInspectVarEdited: (nodeId, name) => { - const inspectVar = get().getInspectVar(nodeId, name) - if (!inspectVar) - return false - - return inspectVar.edited - }, }) }