From e00da7a1d87b3f8ce4d1320203f4b4b0d74145c9 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Thu, 26 Dec 2024 17:02:29 +0800 Subject: [PATCH] tool setting form --- .../plugins/plugin-detail-panel/index.tsx | 14 ++- .../tool-selector/index.tsx | 114 +++++++++++++----- .../block-selector/tool/action-item.tsx | 1 + .../workflow/block-selector/types.ts | 1 + 4 files changed, 97 insertions(+), 33 deletions(-) diff --git a/web/app/components/plugins/plugin-detail-panel/index.tsx b/web/app/components/plugins/plugin-detail-panel/index.tsx index 3378d75b5b..3e746741cc 100644 --- a/web/app/components/plugins/plugin-detail-panel/index.tsx +++ b/web/app/components/plugins/plugin-detail-panel/index.tsx @@ -59,12 +59,14 @@ const PluginDetailPanel: FC = ({ {!!detail.declaration.agent_strategy && } {!!detail.declaration.endpoint && } {!!detail.declaration.model && } -
- testChange(item)} - /> -
+ {false && ( +
+ testChange(item)} + /> +
+ )} )} diff --git a/web/app/components/plugins/plugin-detail-panel/tool-selector/index.tsx b/web/app/components/plugins/plugin-detail-panel/tool-selector/index.tsx index 54e3fdba59..18ff2a3707 100644 --- a/web/app/components/plugins/plugin-detail-panel/tool-selector/index.tsx +++ b/web/app/components/plugins/plugin-detail-panel/tool-selector/index.tsx @@ -2,6 +2,9 @@ import type { FC } from 'react' import React, { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' +import { + RiArrowRightUpLine, +} from '@remixicon/react' import { PortalToFollowElem, PortalToFollowElemContent, @@ -14,6 +17,9 @@ import Indicator from '@/app/components/header/indicator' import ToolCredentialForm from '@/app/components/plugins/plugin-detail-panel/tool-selector/tool-credentials-form' import Toast from '@/app/components/base/toast' import Textarea from '@/app/components/base/textarea' +import Divider from '@/app/components/base/divider' +import Form from '@/app/components/header/account-setting/model-provider-page/model-modal/Form' +import { addDefaultValue, toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema' import { useAppContext } from '@/context/app-context' import { @@ -69,19 +75,22 @@ const ToolSelector: FC = ({ const { data: customTools } = useAllCustomTools() const { data: workflowTools } = useAllWorkflowTools() const invalidateAllBuiltinTools = useInvalidateAllBuiltInTools() + const currentProvider = useMemo(() => { const mergedTools = [...(buildInTools || []), ...(customTools || []), ...(workflowTools || [])] return mergedTools.find((toolWithProvider) => { return toolWithProvider.id === value?.provider && toolWithProvider.tools.some(tool => tool.name === value?.tool_name) }) }, [value, buildInTools, customTools, workflowTools]) + const [isShowChooseTool, setIsShowChooseTool] = useState(false) const handleSelectTool = (tool: ToolDefaultValue) => { + const paramValues = addDefaultValue(tool.params, toolParametersToFormSchemas(tool.paramSchemas as any)) const toolValue = { provider: tool.provider_id, tool_name: tool.tool_name, description: '', - parameters: {}, + parameters: paramValues, } onSelect(toolValue) setIsShowChooseTool(false) @@ -96,6 +105,21 @@ const ToolSelector: FC = ({ } as any) } + const currentToolParams = useMemo(() => { + if (!currentProvider) return [] + return currentProvider.tools.find(tool => tool.name === value?.tool_name)?.parameters || [] + }, [currentProvider, value]) + + const formSchemas = useMemo(() => toolParametersToFormSchemas(currentToolParams), [currentToolParams]) + + const handleFormChange = (v: Record) => { + const toolValue = { + ...value, + parameters: v, + } + onSelect(toolValue as any) + } + // authorization const { isCurrentWorkspaceManager } = useAppContext() const [isShowSettingAuth, setShowSettingAuth] = useState(false) @@ -133,8 +157,9 @@ const ToolSelector: FC = ({ /> -
+
{t('plugin.detailPanel.toolSelector.title')}
+ {/* base form */}
{t('plugin.detailPanel.toolSelector.toolLabel')}
@@ -166,6 +191,38 @@ const ToolSelector: FC = ({ />
+ {/* authorization */} + {!isShowSettingAuth && currentProvider && currentProvider.type === CollectionType.builtIn && currentProvider.allow_delete && ( +
+
+
{t('plugin.detailPanel.toolSelector.auth')}
+ +
+
+ {!currentProvider.is_team_authorization && ( + + )} + {currentProvider.is_team_authorization && ( + + )} +
+
+ )} {/* authorization panel */} {isShowSettingAuth && currentProvider && (
@@ -179,31 +236,34 @@ const ToolSelector: FC = ({ />
)} - {!isShowSettingAuth && currentProvider && currentProvider.type === CollectionType.builtIn && currentProvider.is_team_authorization && currentProvider.allow_delete && ( -
-
{t('plugin.detailPanel.toolSelector.auth')}
- {isCurrentWorkspaceManager && ( - - )} -
- )} - {!isShowSettingAuth && currentProvider && currentProvider.type === CollectionType.builtIn && !currentProvider.is_team_authorization && currentProvider.allow_delete && ( -
- + {/* tool settings */} + {currentToolParams.length > 0 && currentProvider?.is_team_authorization && ( +
+
+
{t('plugin.detailPanel.toolSelector.settings')}
+ +
+
+
item.url + ? ( + {t('tools.howToGet')} + + ) + : null} + /> +
)}
diff --git a/web/app/components/workflow/block-selector/tool/action-item.tsx b/web/app/components/workflow/block-selector/tool/action-item.tsx index bc8db404a0..46c1917e39 100644 --- a/web/app/components/workflow/block-selector/tool/action-item.tsx +++ b/web/app/components/workflow/block-selector/tool/action-item.tsx @@ -59,6 +59,7 @@ const ToolItem: FC = ({ title: payload.label[language], is_team_authorization: provider.is_team_authorization, output_schema: payload.output_schema, + paramSchemas: payload.parameters, params, }) }} diff --git a/web/app/components/workflow/block-selector/types.ts b/web/app/components/workflow/block-selector/types.ts index d0fc7782f9..c02a74e3a4 100644 --- a/web/app/components/workflow/block-selector/types.ts +++ b/web/app/components/workflow/block-selector/types.ts @@ -27,5 +27,6 @@ export type ToolDefaultValue = { title: string is_team_authorization: boolean params: Record + paramSchemas: Record output_schema: Record }