From 7d7e0f9800fff48cb89187cab4f938fd25207bf8 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 22 Oct 2024 18:26:17 +0800 Subject: [PATCH] fix: tool use file caused error (#9660) --- .../nodes/tool/components/input-var-list.tsx | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/web/app/components/workflow/nodes/tool/components/input-var-list.tsx b/web/app/components/workflow/nodes/tool/components/input-var-list.tsx index 41be301a4b..9d9940b8e9 100644 --- a/web/app/components/workflow/nodes/tool/components/input-var-list.tsx +++ b/web/app/components/workflow/nodes/tool/components/input-var-list.tsx @@ -99,6 +99,18 @@ const InputVarList: FC = ({ } }, [value, onChange]) + const handleFileChange = useCallback((variable: string) => { + return (varValue: ValueSelector | string) => { + const newValue = produce(value, (draft: ToolVarInputs) => { + draft[variable] = { + type: VarKindType.variable, + value: varValue, + } + }) + onChange(newValue) + } + }, [value, onChange]) + const [inputsIsFocus, setInputsIsFocus] = useState>({}) const handleInputFocus = useCallback((variable: string) => { return (value: boolean) => { @@ -129,7 +141,8 @@ const InputVarList: FC = ({ const isSelect = type === FormTypeEnum.select const isFile = type === FormTypeEnum.file const isFileArray = type === FormTypeEnum.files - const isString = type !== FormTypeEnum.textNumber && type !== FormTypeEnum.files && type !== FormTypeEnum.select + const isString = !isNumber && !isSelect && !isFile && !isFileArray + return (
@@ -158,7 +171,6 @@ const InputVarList: FC = ({ value={varInput?.type === VarKindType.constant ? (varInput?.value || '') : (varInput?.value || [])} onChange={handleNotMixedTypeChange(variable)} onOpen={handleOpen(index)} - isSupportConstantValue={isSupportConstantValue} defaultVarKindType={varInput?.type} filterVar={isNumber ? filterVar : undefined} availableVars={isSelect ? availableVars : undefined} @@ -170,8 +182,8 @@ const InputVarList: FC = ({ readonly={readOnly} isShowNodeName nodeId={nodeId} - value={varInput?.type === VarKindType.constant ? (varInput?.value || '') : (varInput?.value || [])} - onChange={handleNotMixedTypeChange(variable)} + value={varInput?.value || []} + onChange={handleFileChange(variable)} onOpen={handleOpen(index)} defaultVarKindType={VarKindType.variable} filterVar={(varPayload: Var) => varPayload.type === VarType.file} @@ -182,8 +194,8 @@ const InputVarList: FC = ({ readonly={readOnly} isShowNodeName nodeId={nodeId} - value={varInput?.type === VarKindType.constant ? (varInput?.value || '') : (varInput?.value || [])} - onChange={handleNotMixedTypeChange(variable)} + value={varInput?.value || []} + onChange={handleFileChange(variable)} onOpen={handleOpen(index)} defaultVarKindType={VarKindType.variable} filterVar={(varPayload: Var) => varPayload.type === VarType.arrayFile}