From 5ee7fc4fdeddf1f1fe72def3dba9095019db7bb4 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 15 Mar 2024 22:15:36 +0800 Subject: [PATCH] feat: tools vars limit --- .../nodes/tool/components/input-var-list.tsx | 5 ++++- .../components/workflow/nodes/tool/panel.tsx | 2 ++ .../workflow/nodes/tool/use-config.ts | 22 +++++++++++++------ 3 files changed, 21 insertions(+), 8 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 7bc0d79431b2ea..4933e6460b1967 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 @@ -4,7 +4,7 @@ import React, { useCallback } from 'react' import produce from 'immer' import type { ToolVarInput } from '../types' import { VarType as VarKindType } from '../types' -import { type ValueSelector } from '@/app/components/workflow/types' +import type { ValueSelector, Var } from '@/app/components/workflow/types' import type { CredentialFormSchema } from '@/app/components/header/account-setting/model-provider-page/declarations' import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks' @@ -17,6 +17,7 @@ type Props = { value: ToolVarInput[] onChange: (value: ToolVarInput[]) => void isSupportConstantValue?: boolean + filterVar?: (payload: Var, valueSelector: ValueSelector) => boolean } const InputVarList: FC = ({ @@ -26,6 +27,7 @@ const InputVarList: FC = ({ value, onChange, isSupportConstantValue, + filterVar, }) => { const language = useLanguage() @@ -92,6 +94,7 @@ const InputVarList: FC = ({ onChange={handleChange(variable)} isSupportConstantValue={isSupportConstantValue} defaultVarKindType={varInput?.variable_type} + filterVar={filterVar} /> {tooltip &&
{tooltip[language] || tooltip.en_US}
} diff --git a/web/app/components/workflow/nodes/tool/panel.tsx b/web/app/components/workflow/nodes/tool/panel.tsx index 5a5573c264c4f9..4349801864e6af 100644 --- a/web/app/components/workflow/nodes/tool/panel.tsx +++ b/web/app/components/workflow/nodes/tool/panel.tsx @@ -28,6 +28,7 @@ const Panel: FC> = ({ inputs, toolInputVarSchema, setInputVar, + filterVar, toolSettingSchema, toolSettingValue, setToolSettingValue, @@ -80,6 +81,7 @@ const Panel: FC> = ({ schema={toolInputVarSchema as any} value={inputs.tool_parameters} onChange={setInputVar} + filterVar={filterVar} isSupportConstantValue /> diff --git a/web/app/components/workflow/nodes/tool/use-config.ts b/web/app/components/workflow/nodes/tool/use-config.ts index e28528266d0803..bf2816b31c0f87 100644 --- a/web/app/components/workflow/nodes/tool/use-config.ts +++ b/web/app/components/workflow/nodes/tool/use-config.ts @@ -12,10 +12,9 @@ import { fetchBuiltInToolList, fetchCollectionList, fetchCustomToolList, updateB import { addDefaultValue, toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema' import Toast from '@/app/components/base/toast' import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form' -import { InputVarType } from '@/app/components/workflow/types' -import type { InputVar } from '@/app/components/workflow/types' +import { InputVarType, VarType as VarVarType } from '@/app/components/workflow/types' +import type { InputVar, Var } from '@/app/components/workflow/types' import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run' - const useConfig = (id: string, payload: ToolNodeType) => { const { t } = useTranslation() const language = useLanguage() @@ -27,7 +26,7 @@ const useConfig = (id: string, payload: ToolNodeType) => { * tool_configurations: tool setting, not dynamic setting * tool_parameters: tool dynamic setting(by user) */ - const { provider_id, provider_name, provider_type, tool_name, tool_configurations, tool_parameters: toolInputs } = inputs + const { provider_id, provider_name, provider_type, tool_name, tool_configurations } = inputs const isBuiltIn = provider_type === CollectionType.builtIn const [currCollection, setCurrCollection] = useState(null) const fetchCurrCollection = useCallback(async () => { @@ -43,6 +42,7 @@ const useConfig = (id: string, payload: ToolNodeType) => { return fetchCurrCollection() + // eslint-disable-next-line react-hooks/exhaustive-deps }, [provider_id]) // Auth @@ -63,7 +63,7 @@ const useConfig = (id: string, payload: ToolNodeType) => { }) await fetchCurrCollection() hideSetAuthModal() - }, [currCollection]) + }, [currCollection?.name, fetchCurrCollection, hideSetAuthModal, t]) const [currTool, setCurrTool] = useState(null) const formSchemas = currTool ? toolParametersToFormSchemas(currTool.parameters) : [] @@ -94,6 +94,7 @@ const useConfig = (id: string, payload: ToolNodeType) => { }) }) setInputs(inputsWithDefaultValue) + // eslint-disable-next-line react-hooks/exhaustive-deps }, [currTool]) // setting when call @@ -104,6 +105,11 @@ const useConfig = (id: string, payload: ToolNodeType) => { }) }, [inputs, setInputs]) + // TODO: dynamic setting as the current var type + const filterVar = useCallback((varPayload: Var) => { + return varPayload.type !== VarVarType.arrayFile + }, []) + const isLoading = currTool && (isBuiltIn ? !currCollection : false) useEffect(() => { @@ -123,6 +129,7 @@ const useConfig = (id: string, payload: ToolNodeType) => { if (currTool) setCurrTool(currTool) })() + // eslint-disable-next-line react-hooks/exhaustive-deps }, [provider_name]) // single run @@ -149,13 +156,13 @@ const useConfig = (id: string, payload: ToolNodeType) => { const singleRunForms = (() => { const formInputs: InputVar[] = [] toolInputVarSchema.forEach((item: any) => { - const targetItem = toolInputs.find(input => input.variable === item.variable) + // const targetItem = toolInputs.find(input => input.variable === item.variable) // TODO: support selector // if (targetItem?.variable_type === VarType.selector) { formInputs.push({ label: item.label[language] || item.label.en_US, variable: item.variable, - type: InputVarType.textInput, + type: InputVarType.textInput, // TODO: to form input required: item.required, }) // } @@ -176,6 +183,7 @@ const useConfig = (id: string, payload: ToolNodeType) => { setToolSettingValue, toolInputVarSchema, setInputVar, + filterVar, currCollection, isShowAuthBtn, showSetAuth,