From acd1641d1662fb1c057705e325be6d673ef8bbe6 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Wed, 22 Apr 2026 07:41:15 +0800 Subject: [PATCH] Infer human input output variable types --- .../__tests__/human-input.spec.tsx | 8 +++++-- .../workflow/nodes/human-input/default.ts | 23 +++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/web/app/components/workflow/nodes/human-input/__tests__/human-input.spec.tsx b/web/app/components/workflow/nodes/human-input/__tests__/human-input.spec.tsx index cbc9cddd4a..d5d6b32c7d 100644 --- a/web/app/components/workflow/nodes/human-input/__tests__/human-input.spec.tsx +++ b/web/app/components/workflow/nodes/human-input/__tests__/human-input.spec.tsx @@ -503,8 +503,10 @@ describe('DSL Import with Human Input Node', () => { const payload = { ...humanInputDefault.defaultValue, inputs: [ - { type: 'text-input', output_variable_name: 'review_result', default: { selector: [], type: 'constant' as const, value: '' } }, - { type: 'text-input', output_variable_name: 'comment', default: { selector: [], type: 'constant' as const, value: '' } }, + { type: 'paragraph', output_variable_name: 'review_result', default: { selector: [], type: 'constant' as const, value: '' } }, + { type: 'file', output_variable_name: 'attachment', allowed_file_extensions: [], allowed_file_types: [], allowed_file_upload_methods: [] }, + { type: 'file-list', output_variable_name: 'attachments', allowed_file_extensions: [], allowed_file_types: [], allowed_file_upload_methods: [], max_upload_count: 3 }, + { type: 'select', output_variable_name: 'comment', option_source: { type: 'constant', selector: [], value: ['A', 'B'] } }, ], } as HumanInputNodeType @@ -512,6 +514,8 @@ describe('DSL Import with Human Input Node', () => { expect(outputVars).toEqual([ { variable: 'review_result', type: 'string' }, + { variable: 'attachment', type: 'file' }, + { variable: 'attachments', type: 'array[file]' }, { variable: 'comment', type: 'string' }, ]) }) diff --git a/web/app/components/workflow/nodes/human-input/default.ts b/web/app/components/workflow/nodes/human-input/default.ts index 7e3d8d581e..196f3f840b 100644 --- a/web/app/components/workflow/nodes/human-input/default.ts +++ b/web/app/components/workflow/nodes/human-input/default.ts @@ -1,5 +1,5 @@ import type { NodeDefault, Var } from '../../types' -import type { HumanInputNodeType } from './types' +import type { FormInputItem, HumanInputNodeType } from './types' import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types' import { BlockEnum, VarType } from '@/app/components/workflow/types' import { genNodeMetaData } from '@/app/components/workflow/utils' @@ -12,11 +12,21 @@ const metaData = genNodeMetaData({ type: BlockEnum.HumanInput, }) -const buildOutputVars = (variables: string[]): Var[] => { - return variables.map((variable) => { +const getFormInputVarType = (input: FormInputItem): VarType => { + if (input.type === 'file') + return VarType.file + + if (input.type === 'file-list') + return VarType.arrayFile + + return VarType.string +} + +const buildOutputVars = (inputs: FormInputItem[]): Var[] => { + return inputs.map((input) => { return { - variable, - type: VarType.string, + variable: input.output_variable_name, + type: getFormInputVarType(input), } }) } @@ -67,8 +77,7 @@ const nodeDefault: NodeDefault = { } }, getOutputVars(payload, _allPluginInfoList, _ragVars) { - const variables = payload.inputs.map(input => input.output_variable_name) - return buildOutputVars(variables) + return buildOutputVars(payload.inputs) }, }