From c5dcad3990920757574a6a31017ede4e3bbbc356 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 18 Jun 2025 10:54:24 +0800 Subject: [PATCH] fix: iteration files type not support --- .../_base/components/before-run-form/form-item.tsx | 13 +++++++------ .../nodes/_base/components/before-run-form/form.tsx | 4 +++- .../components/workflow/nodes/iteration/types.ts | 1 + .../workflow/nodes/iteration/use-config.ts | 3 ++- .../nodes/iteration/use-single-run-form-params.ts | 5 +++-- web/app/components/workflow/types.ts | 1 + 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx b/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx index 9f415adda9..269f5e0a96 100644 --- a/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx +++ b/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx @@ -95,6 +95,7 @@ const FormItem: FC = ({ const isArrayLikeType = [InputVarType.contexts, InputVarType.iterator].includes(type) const isContext = type === InputVarType.contexts const isIterator = type === InputVarType.iterator + const isIteratorItemFile = isIterator && payload.isFileItem const singleFileValue = useMemo(() => { if (payload.variable === '#files#') return value?.[0] || [] @@ -202,12 +203,12 @@ const FormItem: FC = ({ }} /> )} - {(type === InputVarType.multiFiles) && ( + {(type === InputVarType.multiFiles || isIteratorItemFile) && ( onChange(files)} fileConfig={{ - allowed_file_types: inStepRun + allowed_file_types: (inStepRun || isIteratorItemFile) ? [ SupportUploadFileTypes.image, SupportUploadFileTypes.document, @@ -215,7 +216,7 @@ const FormItem: FC = ({ SupportUploadFileTypes.video, ] : payload.allowed_file_types, - allowed_file_extensions: inStepRun + allowed_file_extensions: (inStepRun || isIteratorItemFile) ? [ ...FILE_EXTS[SupportUploadFileTypes.image], ...FILE_EXTS[SupportUploadFileTypes.document], @@ -223,8 +224,8 @@ const FormItem: FC = ({ ...FILE_EXTS[SupportUploadFileTypes.video], ] : payload.allowed_file_extensions, - allowed_file_upload_methods: inStepRun ? [TransferMethod.local_file, TransferMethod.remote_url] : payload.allowed_file_upload_methods, - number_limits: inStepRun ? 5 : payload.max_length, + allowed_file_upload_methods: (inStepRun || isIteratorItemFile) ? [TransferMethod.local_file, TransferMethod.remote_url] : payload.allowed_file_upload_methods, + number_limits: (inStepRun || isIteratorItemFile) ? 5 : payload.max_length, fileUploadConfig: fileSettings?.fileUploadConfig, }} /> @@ -272,7 +273,7 @@ const FormItem: FC = ({ } { - isIterator && ( + (isIterator && !isIteratorItemFile) && (
{(value || []).map((item: any, index: number) => ( = ({ } }, [valuesRef, onChange, mapKeysWithSameValueSelector]) const isArrayLikeType = [InputVarType.contexts, InputVarType.iterator].includes(inputs[0]?.type) + const isIteratorItemFile = inputs[0]?.type === InputVarType.iterator && inputs[0]?.isFileItem + const isContext = inputs[0]?.type === InputVarType.contexts const handleAddContext = useCallback(() => { const newValues = produce(values, (draft: any) => { @@ -77,7 +79,7 @@ const Form: FC = ({ {label && (
{label}
- {isArrayLikeType && ( + {isArrayLikeType && !isIteratorItemFile && ( )}
diff --git a/web/app/components/workflow/nodes/iteration/types.ts b/web/app/components/workflow/nodes/iteration/types.ts index 4a20dbd456..9a68050d6f 100644 --- a/web/app/components/workflow/nodes/iteration/types.ts +++ b/web/app/components/workflow/nodes/iteration/types.ts @@ -11,6 +11,7 @@ export type IterationNodeType = CommonNodeType & { start_node_id: string // start node id in the iteration iteration_id?: string iterator_selector: ValueSelector + iterator_input_type: VarType output_selector: ValueSelector output_type: VarType // output type. is_parallel: boolean // open the parallel mode or not diff --git a/web/app/components/workflow/nodes/iteration/use-config.ts b/web/app/components/workflow/nodes/iteration/use-config.ts index cebe3e65ce..c8656aa937 100644 --- a/web/app/components/workflow/nodes/iteration/use-config.ts +++ b/web/app/components/workflow/nodes/iteration/use-config.ts @@ -28,9 +28,10 @@ const useConfig = (id: string, payload: IterationNodeType) => { return [VarType.array, VarType.arrayString, VarType.arrayNumber, VarType.arrayObject, VarType.arrayFile].includes(varPayload.type) }, []) - const handleInputChange = useCallback((input: ValueSelector | string) => { + const handleInputChange = useCallback((input: ValueSelector | string, _varKindType: VarKindType, varInfo?: Var) => { const newInputs = produce(inputs, (draft) => { draft.iterator_selector = input as ValueSelector || [] + draft.iterator_input_type = varInfo?.type || VarType.arrayString }) setInputs(newInputs) }, [inputs, setInputs]) diff --git a/web/app/components/workflow/nodes/iteration/use-single-run-form-params.ts b/web/app/components/workflow/nodes/iteration/use-single-run-form-params.ts index 2a0ab34106..b6c96bac48 100644 --- a/web/app/components/workflow/nodes/iteration/use-single-run-form-params.ts +++ b/web/app/components/workflow/nodes/iteration/use-single-run-form-params.ts @@ -5,7 +5,7 @@ import type { IterationNodeType } from './types' import { useTranslation } from 'react-i18next' import { useIsNodeInIteration, useWorkflow } from '../../hooks' import { getNodeInfoById, getNodeUsedVarPassToServerKey, getNodeUsedVars, isSystemVar } from '../_base/components/variable/utils' -import { InputVarType } from '@/app/components/workflow/types' +import { InputVarType, VarType } from '@/app/components/workflow/types' import formatTracing from '@/app/components/workflow/run/utils/format-log' import type { NodeTracing } from '@/types/workflow' import { VALUE_SELECTOR_DELIMITER as DELIMITER } from '@/config' @@ -124,12 +124,13 @@ const useSingleRunFormParams = ({ type: InputVarType.iterator, required: false, getVarValueFromDependent: true, + isFileItem: payload.iterator_input_type === VarType.arrayFile, }], values: { [iteratorInputKey]: iterator }, onChange: (keyValue: Record) => setIterator(keyValue[iteratorInputKey]), }, ] - }, [inputVarValues, iterator, iteratorInputKey, setInputVarValues, setIterator, t, usedOutVars]) + }, [inputVarValues, iterator, iteratorInputKey, payload.iterator_input_type, setInputVarValues, setIterator, t, usedOutVars]) const nodeInfo = formatTracing(iterationRunResult, t)[0] diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index fd710f7772..072000bc12 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -201,6 +201,7 @@ export type InputVar = { value_selector?: ValueSelector getVarValueFromDependent?: boolean hide?: boolean + isFileItem?: boolean } & Partial export type ModelConfig = {