Track human input selector variable references

This commit is contained in:
JzoNg 2026-04-22 08:28:46 +08:00
parent b879748ba0
commit cbe2f66f1b
2 changed files with 70 additions and 4 deletions

View File

@ -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'],
},
})
})
})
})

View File

@ -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
}
}