diff --git a/web/app/components/plugins/plugin-detail-panel/endpoint-card.tsx b/web/app/components/plugins/plugin-detail-panel/endpoint-card.tsx index 72f89d8194..066c6cc737 100644 --- a/web/app/components/plugins/plugin-detail-panel/endpoint-card.tsx +++ b/web/app/components/plugins/plugin-detail-panel/endpoint-card.tsx @@ -1,9 +1,10 @@ -import React, { useState } from 'react' +import React, { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { useBoolean } from 'ahooks' import { RiDeleteBinLine, RiEditLine, RiLoginCircleLine } from '@remixicon/react' import type { EndpointListItem } from '../types' import EndpointModal from './endpoint-modal' +import { addDefaultValue, toolCredentialToFormSchemas } from '@/app/components/tools/utils/to-form-schema' import ActionButton from '@/app/components/base/action-button' import CopyBtn from '@/app/components/base/copy-btn' import Confirm from '@/app/components/base/confirm' @@ -86,6 +87,13 @@ const EndpointCard = ({ setFalse: hideEndpointModalConfirm, }] = useBoolean(false) + const formSchemas = useMemo(() => { + return toolCredentialToFormSchemas(data.declaration.settings) + }, [data.declaration.settings]) + const formValue = useMemo(() => { + return addDefaultValue(data.settings, formSchemas) + }, [data.settings, formSchemas]) + return (
@@ -160,6 +168,9 @@ const EndpointCard = ({ )} {isShowEndpointModal && ( )} diff --git a/web/app/components/plugins/plugin-detail-panel/endpoint-list.tsx b/web/app/components/plugins/plugin-detail-panel/endpoint-list.tsx index 2906d422fc..a40f7345da 100644 --- a/web/app/components/plugins/plugin-detail-panel/endpoint-list.tsx +++ b/web/app/components/plugins/plugin-detail-panel/endpoint-list.tsx @@ -1,21 +1,36 @@ -import React from 'react' +import React, { useMemo } from 'react' import { useTranslation } from 'react-i18next' +import { useBoolean } from 'ahooks' import { RiAddLine } from '@remixicon/react' import type { EndpointListItem, PluginEndpointDeclaration } from '../types' +import EndpointModal from './endpoint-modal' import EndpointCard from './endpoint-card' +import { toolCredentialToFormSchemas } from '@/app/components/tools/utils/to-form-schema' import ActionButton from '@/app/components/base/action-button' import Tooltip from '@/app/components/base/tooltip' type Props = { + pluginUniqueID: string declaration: PluginEndpointDeclaration list: EndpointListItem[] } const EndpointList = ({ + pluginUniqueID, declaration, list, }: Props) => { const { t } = useTranslation() + + const [isShowEndpointModal, { + setTrue: showEndpointModal, + setFalse: hideEndpointModal, + }] = useBoolean(false) + + const formSchemas = useMemo(() => { + return toolCredentialToFormSchemas(declaration.settings) + }, [declaration.settings]) + return (
@@ -27,7 +42,7 @@ const EndpointList = ({ } />
- +
@@ -42,6 +57,13 @@ const EndpointList = ({ /> ))}
+ {isShowEndpointModal && ( + + )}
) } diff --git a/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx b/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx index bc65596044..aac18dbcbb 100644 --- a/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx +++ b/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx @@ -2,27 +2,33 @@ import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' -import Drawer from '@/app/components/base/drawer' +import { RiArrowRightUpLine, RiCloseLine } from '@remixicon/react' +import ActionButton from '@/app/components/base/action-button' import Button from '@/app/components/base/button' +import Drawer from '@/app/components/base/drawer' +import Form from '@/app/components/header/account-setting/model-provider-page/model-modal/Form' // import Toast from '@/app/components/base/toast' -// import Form from '@/app/components/header/account-setting/model-provider-page/model-modal/Form' -// import { LinkExternal02 } from '@/app/components/base/icons/src/vender/line/general' import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks' import cn from '@/utils/classnames' type Props = { + id: string + formSchemas: any + defaultValues?: any onCancel: () => void // onSaved: (value: Record) => void - onRemove?: () => void } const EndpointModal: FC = ({ + id, + formSchemas, + defaultValues = {}, onCancel, // onSaved, - onRemove = () => { }, }) => { const { t } = useTranslation() const language = useLanguage() + const [tempCredential, setTempCredential] = React.useState(defaultValues) const handleSave = () => { // for (const field of credentialSchema) { @@ -45,31 +51,44 @@ const EndpointModal: FC = ({ panelClassname={cn('justify-start mt-[64px] mr-2 mb-2 !w-[420px] !max-w-[420px] !p-0 !bg-components-panel-bg rounded-2xl border-[0.5px] border-components-panel-border shadow-xl')} > <> - {/*
{ - setTempCredential(v) - }} - formSchemas={credentialSchema} - isEditMode={true} - showOnVariableMap={{}} - validating={false} - inputClassName='!bg-gray-50' - fieldMoreInfo={item => item.url - ? ( - {t('tools.howToGet')} - - ) - : null} - /> */} -
- < div className='flex space-x-2'> - - +
+
+
{t('plugin.detailPanel.endpointModalTitle')}
+ + + +
+
{t('plugin.detailPanel.endpointModalDesc')}
+
+
+
+ { + setTempCredential(v) + }} + formSchemas={formSchemas} + isEditMode={true} + showOnVariableMap={{}} + validating={false} + inputClassName='!bg-gray-50' + fieldMoreInfo={item => item.url + ? ( + {t('tools.howToGet')} + + ) + : null} + /> +
+
+
+ + +
diff --git a/web/app/components/plugins/plugin-detail-panel/index.tsx b/web/app/components/plugins/plugin-detail-panel/index.tsx index 3f60d19196..76ae8d7625 100644 --- a/web/app/components/plugins/plugin-detail-panel/index.tsx +++ b/web/app/components/plugins/plugin-detail-panel/index.tsx @@ -48,6 +48,7 @@ const PluginDetailPanel: FC = ({
{!!pluginDetail.declaration.endpoint && ( diff --git a/web/app/components/plugins/plugin-detail-panel/mock.ts b/web/app/components/plugins/plugin-detail-panel/mock.ts index dd76c7bdbe..dffe753922 100644 --- a/web/app/components/plugins/plugin-detail-panel/mock.ts +++ b/web/app/components/plugins/plugin-detail-panel/mock.ts @@ -33,14 +33,14 @@ export const toolNotion = { default: null, options: null, label: { - 'en-US': 'API-key', - 'zh-Hans': 'API-key', + en_US: 'API-key', + zh_Hans: 'API-key', }, help: null, url: null, placeholder: { - 'en-US': 'Please input your API key', - 'zh-Hans': '请输入你的 API key', + en_US: 'Please input your API key', + zh_Hans: '请输入你的 API key', }, }, ], @@ -81,14 +81,14 @@ export const toolNotionEndpoints = [ default: null, options: null, label: { - 'en-US': 'API-key', - 'zh-Hans': 'API-key', + en_US: 'API-key', + zh_Hans: 'API-key', }, help: null, url: null, placeholder: { - 'en-US': 'Please input your API key', - 'zh-Hans': '请输入你的 API key', + en_US: 'Please input your API key', + zh_Hans: '请输入你的 API key', }, }, ], diff --git a/web/app/components/plugins/types.ts b/web/app/components/plugins/types.ts index 574b407895..2becf1e43d 100644 --- a/web/app/components/plugins/types.ts +++ b/web/app/components/plugins/types.ts @@ -1,4 +1,5 @@ import type { CredentialFormSchemaBase } from '../header/account-setting/model-provider-page/declarations' +import type { ToolCredential } from '@/app/components/tools/types' import type { Locale } from '@/i18n' export enum PluginType { @@ -23,11 +24,11 @@ export type PluginToolDeclaration = { label: Record tags: string[] } - credentials_schema: CredentialFormSchemaBase[] // TODO + credentials_schema: ToolCredential[] // TODO } export type PluginEndpointDeclaration = { - settings: CredentialFormSchemaBase[] + settings: ToolCredential[] endpoints: EndpointItem[] } diff --git a/web/i18n/en-US/plugin.ts b/web/i18n/en-US/plugin.ts index 3866263fb7..b2ce5654ad 100644 --- a/web/i18n/en-US/plugin.ts +++ b/web/i18n/en-US/plugin.ts @@ -25,6 +25,8 @@ const translation = { endpointDisableContent: 'Would you like to disable {{name}}? ', endpointDeleteTip: 'Remove Endpoint', endpointDeleteContent: 'Would you like to remove {{name}}? ', + endpointModalTitle: 'Setup endpoint', + endpointModalDesc: 'After configuring form, all members within the workspace can use this endpoint when orchestrating applications.', serviceOk: 'Service OK', disabled: 'Disabled', modelNum: '{{num}} MODELS INCLUDED', diff --git a/web/i18n/zh-Hans/plugin.ts b/web/i18n/zh-Hans/plugin.ts index 26f913ce2f..69f0aeb079 100644 --- a/web/i18n/zh-Hans/plugin.ts +++ b/web/i18n/zh-Hans/plugin.ts @@ -25,6 +25,8 @@ const translation = { endpointDisableContent: '是否要停用 {{name}} 的 Endpoint ?', endpointDeleteTip: '移除 Endpoint', endpointDeleteContent: '是否要移除 {{name}} ?', + endpointModalTitle: '设置 Endpoint', + endpointModalDesc: '配置表单后,工作区内的所有成员都可以在编排应用时使用此端点。', serviceOk: '服务正常', disabled: '停用', modelNum: '{{num}} 模型已包含',