From 77773c9c5ca494a66ff6406600fd24d7fba704db Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 20 May 2025 14:17:53 +0800 Subject: [PATCH] fix: llm can get the right filled var --- .../workflow/hooks/use-inspect-vars-crud.ts | 24 +++++++++-------- .../use-nodes-interactions-without-sync.ts | 5 +--- .../workflow-panel/last-run/use-last-run.ts | 27 ++++++++++++++----- .../nodes/llm/use-single-run-form-params.ts | 23 ++++++++++++++++ 4 files changed, 57 insertions(+), 22 deletions(-) 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 2beb3ee047..2ae571b822 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts @@ -19,6 +19,7 @@ import { isConversationVar, isENV, isSystemVar } from '../nodes/_base/components import produce from 'immer' import type { Node } from '@/app/components/workflow/types' import { useNodesInteractionsWithoutSync } from './use-nodes-interactions-without-sync' +import { useEdgesInteractionsWithoutSync } from './use-edges-interactions-without-sync' const useInspectVarsCrud = () => { const workflowStore = useWorkflowStore() @@ -45,7 +46,7 @@ const useInspectVarsCrud = () => { const { mutate: doEditInspectorVar } = useEditInspectorVar(appId) const { handleCancelNodeSuccessStatus } = useNodesInteractionsWithoutSync() - + const { handleEdgeCancelRunningStatus } = useEdgesInteractionsWithoutSync() const getNodeInspectVars = useCallback((nodeId: string) => { const node = nodesWithInspectVars.find(node => node.nodeId === nodeId) return node @@ -61,15 +62,15 @@ const useInspectVarsCrud = () => { return varId }, [getNodeInspectVars]) - const getInspectVar = useCallback((nodeId: string, name: string) => { + const getInspectVar = useCallback((nodeId: string, name: string): VarInInspect | undefined => { const node = getNodeInspectVars(nodeId) - if (!node) - return undefined + if (!node) + return undefined - const variable = node.vars.find((varItem) => { - return varItem.selector[1] === name - })?.value - return variable + const variable = node.vars.find((varItem) => { + return varItem.name === name + }) + return variable }, [getNodeInspectVars]) const hasSetInspectVar = useCallback((nodeId: string, name: string, sysVars: VarInInspect[], conversationVars: VarInInspect[]) => { @@ -145,6 +146,7 @@ const useInspectVarsCrud = () => { await invalidateConversationVarValues() await invalidateSysVarValues() deleteAllInspectVarsInStore() + handleEdgeCancelRunningStatus() } const editInspectVarValue = useCallback(async (nodeId: string, varId: string, value: any) => { @@ -191,10 +193,10 @@ const useInspectVarsCrud = () => { const isInspectVarEdited = useCallback((nodeId: string, name: string) => { const inspectVar = getInspectVar(nodeId, name) - if (!inspectVar) - return false + if (!inspectVar) + return false - return inspectVar.edited + return inspectVar.edited }, [getInspectVar]) const resetToLastRunVar = (nodeId: string, varId: string) => { diff --git a/web/app/components/workflow/hooks/use-nodes-interactions-without-sync.ts b/web/app/components/workflow/hooks/use-nodes-interactions-without-sync.ts index 4484da0a0f..e01609cdb6 100644 --- a/web/app/components/workflow/hooks/use-nodes-interactions-without-sync.ts +++ b/web/app/components/workflow/hooks/use-nodes-interactions-without-sync.ts @@ -2,11 +2,9 @@ import { useCallback } from 'react' import produce from 'immer' import { useStoreApi } from 'reactflow' import { NodeRunningStatus } from '../types' -import { useEdgesInteractionsWithoutSync } from './use-edges-interactions-without-sync' export const useNodesInteractionsWithoutSync = () => { const store = useStoreApi() - const { handleEdgeCancelRunningStatus } = useEdgesInteractionsWithoutSync() const handleNodeCancelRunningStatus = useCallback(() => { const { @@ -38,8 +36,7 @@ export const useNodesInteractionsWithoutSync = () => { }) }) setNodes(newNodes) - handleEdgeCancelRunningStatus() - }, [handleEdgeCancelRunningStatus, store]) + }, [store]) const handleCancelNodeSuccessStatus = useCallback((nodeId: string) => { const { 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 127c54ef08..6d32c02adc 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 @@ -21,7 +21,7 @@ import useVariableAggregatorSingleRunFormParams from '@/app/components/workflow/ import useToolGetDataForCheckMore from '@/app/components/workflow/nodes/tool/use-get-data-for-check-more' // import -import type { CommonNodeType } from '@/app/components/workflow/types' +import type { CommonNodeType, ValueSelector } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types' import { useNodesSyncDraft, @@ -171,7 +171,10 @@ const useLastRun = ({ const valuesArr = forms.map((form) => { const values: Record = {} form.inputs.forEach(({ variable }) => { - const selector = variable.slice(1, -1).split('.') + if(!variable.includes('.') && !singleRunParams?.getDependentVar) + return + + const selector = !variable.includes('.') ? singleRunParams?.getDependentVar(variable) : variable.slice(1, -1).split('.') const [nodeId, varName] = selector.slice(0, 2) const inspectVarValue = hasSetInspectVar(nodeId, varName, systemVars, conversationVars) // also detect system var , env and conversation var if (inspectVarValue) @@ -182,6 +185,16 @@ const useLastRun = ({ return valuesArr } + const isAllVarsHasValue = (vars?: ValueSelector[]) => { + if(!vars || vars.length === 0) + return true + return vars.every((varItem) => { + const [nodeId, varName] = varItem.slice(0, 2) + const inspectVarValue = hasSetInspectVar(nodeId, varName, systemVars, conversationVars) // also detect system var , env and conversation var + return inspectVarValue + }) + } + const getFilteredExistVarForms = (forms: FormProps[]) => { if (!forms || forms.length === 0) return [] @@ -200,14 +213,14 @@ const useLastRun = ({ } const handleSingleRun = () => { - const filteredExistVarForms = getFilteredExistVarForms(singleRunParams.forms) - if (filteredExistVarForms.length > 0) { - showSingleRun() - } - else { // no need to input params + // no need to input params + if (isAllVarsHasValue(singleRunParams?.getDependentVars?.())) { callRunApi({}) setTabType(TabType.lastRun) } + else { + showSingleRun() + } } return { diff --git a/web/app/components/workflow/nodes/llm/use-single-run-form-params.ts b/web/app/components/workflow/nodes/llm/use-single-run-form-params.ts index 8e6aa005da..93a8638d05 100644 --- a/web/app/components/workflow/nodes/llm/use-single-run-form-params.ts +++ b/web/app/components/workflow/nodes/llm/use-single-run-form-params.ts @@ -167,8 +167,31 @@ const useSingleRunFormParams = ({ return forms })() + const getDependentVars = () => { + const promptVars = varInputs.map(item => item.variable.slice(1, -1).split('.')) + const contextVar = payload.context.variable_selector + const vars = [...promptVars, contextVar] + if (isVisionModel && payload.vision?.enabled && payload.vision?.configs?.variable_selector) { + const visionVar = payload.vision.configs.variable_selector + vars.push(visionVar) + } + return vars + } + + const getDependentVar = (variable: string) => { + if(variable === '#context#') + return payload.context.variable_selector + + if(variable === '#files#') + return payload.vision.configs?.variable_selector + + return false + } + return { forms, + getDependentVars, + getDependentVar, } }