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 d58ebecc7b..f6139096f6 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 @@ -28,6 +28,7 @@ import { BlockEnum } from '@/app/components/workflow/types' import { useNodesSyncDraft, } from '@/app/components/workflow/hooks' +import useInspectVarsCrud from '@/app/components/workflow/hooks/use-inspect-vars-crud' const singleRunFormParamsHooks: Record = { [BlockEnum.LLM]: useLLMSingleRunFormParams, @@ -101,6 +102,7 @@ type Params = OneStepRunParams const useLastRun = ({ ...oneStepRunParams }: Params) => { + const { conversationVars } = useInspectVarsCrud() const blockType = oneStepRunParams.data.type const { handleSyncWorkflowDraft } = useNodesSyncDraft() const { @@ -167,41 +169,20 @@ const useLastRun = ({ const workflowStore = useWorkflowStore() const { - getInspectVar, + hasSetInspectVar, } = workflowStore.getState() const getExistVarValuesInForms = (forms: FormProps[]) => { if (!forms || forms.length === 0) return [] const valuesArr = forms.map((form) => { - const values: Record = {} + const values: Record = {} form.inputs.forEach(({ variable }) => { - // #nodeId.path1?.path2?...# => [nodeId, path1] - // TODO: conversation vars and envs const selector = variable.slice(1, -1).split('.') const [nodeId, varName] = selector.slice(0, 2) - const inspectVarValue = getInspectVar(nodeId, varName) - if (inspectVarValue !== undefined) { - const subPathArr = selector.slice(2) - if (subPathArr.length > 0) { - let current = inspectVarValue.value - let invalid = false - subPathArr.forEach((subPath) => { - if (invalid) - return - - if (current && typeof current === 'object' && subPath in current) { - current = current[subPath] - return - } - invalid = true - }) - values[variable] = current - } - else { - values[variable] = inspectVarValue - } - } + const inspectVarValue = hasSetInspectVar(nodeId, varName, conversationVars) // also detect system var , env and conversation var + if (inspectVarValue) + values[variable] = true }) return values }) 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 7e3b98dfc2..eb50f2242f 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 @@ -1,8 +1,9 @@ import type { StateCreator } from 'zustand' import produce from 'immer' import type { NodeWithVar, VarInInspect } from '@/types/workflow' -import type { ValueSelector } from '../../../types' +import { BlockEnum, 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 @@ -25,6 +26,7 @@ type InspectVarsActions = { 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, conversationVars: VarInInspect[]) => boolean isInspectVarEdited: (nodeId: string, name: string) => boolean } @@ -172,6 +174,22 @@ export const createInspectVarsSlice: StateCreator = (set, })?.value return variable }, + hasSetInspectVar: (nodeId, name, conversationVars: VarInInspect[]) => { + const isEnv = isENV([nodeId]) + if (isEnv) // always have value + return true + const isSys = isSystemVar([nodeId]) + if (isSys) { + const isStartNodeRun = get().nodesWithInspectVars.some((node) => { + return node.nodeType === BlockEnum.Start + }) + return isStartNodeRun + } + 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)