From 8f14881aff0549c4a130fe79dbf8098806e60d81 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Thu, 14 Nov 2024 21:21:50 +0800 Subject: [PATCH] app parameters --- .../file-from-link-or-local/index.tsx | 2 +- .../model-provider-page/model-modal/Form.tsx | 56 +++---- .../app-selector/app-inputs-form.tsx | 125 ++++++++++++++ .../app-selector/app-inputs-panel.tsx | 156 +++++++++++++++++- .../app-selector/index.tsx | 27 ++- .../plugin-detail-panel/endpoint-modal.tsx | 9 - web/service/use-apps.ts | 6 +- web/service/use-common.ts | 14 ++ web/service/use-workflow.ts | 18 ++ 9 files changed, 362 insertions(+), 51 deletions(-) create mode 100644 web/app/components/plugins/plugin-detail-panel/app-selector/app-inputs-form.tsx create mode 100644 web/service/use-common.ts create mode 100644 web/service/use-workflow.ts diff --git a/web/app/components/base/file-uploader/file-from-link-or-local/index.tsx b/web/app/components/base/file-uploader/file-from-link-or-local/index.tsx index 1ff2bdd174..8ae8bb0538 100644 --- a/web/app/components/base/file-uploader/file-from-link-or-local/index.tsx +++ b/web/app/components/base/file-uploader/file-from-link-or-local/index.tsx @@ -59,7 +59,7 @@ const FileFromLinkOrLocal = ({ setOpen(v => !v)} asChild> {trigger(open)} - +
{ showFromLink && ( diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx index 711cb39007..f4e23b566b 100644 --- a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx +++ b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx @@ -18,7 +18,7 @@ import { SimpleSelect } from '@/app/components/base/select' import Tooltip from '@/app/components/base/tooltip' import Radio from '@/app/components/base/radio' import ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal' -// import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-selector' +import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-selector' import AppSelector from '@/app/components/plugins/plugin-detail-panel/app-selector' type FormProps = { @@ -318,34 +318,34 @@ const Form: FC = ({ ) } - // if (formSchema.type === FormTypeEnum.toolSelector) { - // const { - // variable, - // label, - // required, - // } = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput) + if (formSchema.type === FormTypeEnum.toolSelector) { + const { + variable, + label, + required, + } = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput) - // return ( - //
- //
- // {label[language] || label.en_US} - // { - // required && ( - // * - // ) - // } - // {tooltipContent} - //
- // handleFormChange(variable, item as any)} - // /> - // {fieldMoreInfo?.(formSchema)} - // {validating && changeKey === variable && } - //
- // ) - // } + return ( +
+
+ {label[language] || label.en_US} + { + required && ( + * + ) + } + {tooltipContent} +
+ handleFormChange(variable, item as any)} + /> + {fieldMoreInfo?.(formSchema)} + {validating && changeKey === variable && } +
+ ) + } if (formSchema.type === FormTypeEnum.appSelector) { const { diff --git a/web/app/components/plugins/plugin-detail-panel/app-selector/app-inputs-form.tsx b/web/app/components/plugins/plugin-detail-panel/app-selector/app-inputs-form.tsx new file mode 100644 index 0000000000..6dd9926d35 --- /dev/null +++ b/web/app/components/plugins/plugin-detail-panel/app-selector/app-inputs-form.tsx @@ -0,0 +1,125 @@ +import { useCallback } from 'react' +import { useTranslation } from 'react-i18next' +import Input from '@/app/components/base/input' +import Textarea from '@/app/components/base/textarea' +import { PortalSelect } from '@/app/components/base/select' +import { InputVarType } from '@/app/components/workflow/types' +import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader' + +type Props = { + inputsForms: any[] + inputs: Record + inputsRef: any + onFormChange: (value: Record) => void +} +const AppInputsForm = ({ + inputsForms, + inputs, + inputsRef, + onFormChange, +}: Props) => { + const { t } = useTranslation() + + const handleFormChange = useCallback((variable: string, value: any) => { + onFormChange({ + ...inputsRef.current, + [variable]: value, + }) + }, [onFormChange, inputsRef]) + + const renderField = (form: any) => { + const { + label, + variable, + options, + } = form + if (form.type === InputVarType.textInput) { + return ( + handleFormChange(variable, e.target.value)} + placeholder={label} + /> + ) + } + if (form.type === InputVarType.number) { + return ( + handleFormChange(variable, e.target.value)} + placeholder={label} + /> + ) + } + if (form.type === InputVarType.paragraph) { + return ( +