diff --git a/web/app/components/workflow/nodes/_base/components/variable/__tests__/utils.spec.ts b/web/app/components/workflow/nodes/_base/components/variable/__tests__/utils.spec.ts index 010fad6afa..ec7c4f17de 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/__tests__/utils.spec.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/__tests__/utils.spec.ts @@ -4,7 +4,7 @@ import type { LLMNodeType } from '@/app/components/workflow/nodes/llm/types' import type { Node, PromptItem } from '@/app/components/workflow/types' import { describe, expect, it } from 'vitest' import { DeliveryMethodType } from '@/app/components/workflow/nodes/human-input/types' -import { BlockEnum, EditionType, PromptRole } from '@/app/components/workflow/types' +import { BlockEnum, EditionType, InputVarType, PromptRole } from '@/app/components/workflow/types' import { AppModeEnum } from '@/types/app' import { getNodeUsedVars, updateNodeVars } from '../utils' @@ -62,7 +62,26 @@ describe('variable utils', () => { title: 'Human Input', desc: '', form_content: '', - inputs: [], + inputs: [ + { + type: InputVarType.paragraph, + output_variable_name: 'summary', + default: { + type: 'variable', + selector: ['conversation', 'memory'], + value: '', + }, + }, + { + type: InputVarType.select, + output_variable_name: 'decision', + option_source: { + type: 'variable', + selector: ['env', 'OPTIONS'], + value: [], + }, + }, + ], user_actions: [], timeout: 1, timeout_unit: 'day', @@ -84,6 +103,8 @@ describe('variable utils', () => { expect(getNodeUsedVars(node)).toEqual( expect.arrayContaining([ ['env', 'API_KEY'], + ['conversation', 'memory'], + ['env', 'OPTIONS'], ]), ) }) @@ -129,7 +150,26 @@ describe('variable utils', () => { title: 'Human Input', desc: '', form_content: '', - inputs: [], + inputs: [ + { + type: InputVarType.paragraph, + output_variable_name: 'summary', + default: { + type: 'variable', + selector: ['env', 'API_KEY'], + value: '', + }, + }, + { + type: InputVarType.select, + output_variable_name: 'decision', + option_source: { + type: 'variable', + selector: ['env', 'API_KEY'], + value: [], + }, + }, + ], user_actions: [], timeout: 1, timeout_unit: 'day', @@ -154,6 +194,16 @@ describe('variable utils', () => { subject: 'Subject {{#conversation.memory#}}', body: 'Body {{#env.RENAMED_KEY#}}', }) + expect((updatedNode.data as HumanInputNodeType).inputs[0]).toMatchObject({ + default: { + selector: ['env', 'RENAMED_KEY'], + }, + }) + expect((updatedNode.data as HumanInputNodeType).inputs[1]).toMatchObject({ + option_source: { + selector: ['env', 'RENAMED_KEY'], + }, + }) }) }) }) diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 3754058b50..80a33eecc6 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -1530,7 +1530,14 @@ export const getNodeUsedVars = (node: Node): ValueSelector[] => { return [] return [method.config.body] }) - res = matchNotSystemVars([formContent, ...mailTemplates]) + const inputSelectors = payload.inputs.flatMap((input) => { + if (input.type === InputVarType.paragraph && input.default.type === 'variable') + return [input.default.selector] + if (input.type === InputVarType.select && input.option_source.type === 'variable') + return [input.option_source.selector] + return [] + }) + res = [...matchNotSystemVars([formContent, ...mailTemplates]), ...inputSelectors] break } } @@ -2032,6 +2039,15 @@ export const updateNodeVars = ( }, } }) + payload.inputs = payload.inputs.map((input) => { + if (input.type === InputVarType.paragraph && input.default.type === 'variable' && input.default.selector.join('.') === oldVarSelector.join('.')) { + input.default.selector = newVarSelector + } + if (input.type === InputVarType.select && input.option_source.type === 'variable' && input.option_source.selector.join('.') === oldVarSelector.join('.')) { + input.option_source.selector = newVarSelector + } + return input + }) break } }