diff --git a/web/app/components/plugins/plugin-detail-panel/index.tsx b/web/app/components/plugins/plugin-detail-panel/index.tsx index 150158e42c..57aa24bf84 100644 --- a/web/app/components/plugins/plugin-detail-panel/index.tsx +++ b/web/app/components/plugins/plugin-detail-panel/index.tsx @@ -7,6 +7,7 @@ import ActionList from './action-list' import ModelList from './model-list' import AgentStrategyList from './agent-strategy-list' import Drawer from '@/app/components/base/drawer' +import MultipleToolSelector from '@/app/components/plugins/plugin-detail-panel/multiple-tool-selector' import type { PluginDetail } from '@/app/components/plugins/types' import cn from '@/utils/classnames' @@ -58,13 +59,15 @@ const PluginDetailPanel: FC = ({ {!!detail.declaration.agent_strategy && } {!!detail.declaration.endpoint && } {!!detail.declaration.model && } - {/*
- -
*/} + {false && ( +
+ +
+ )} )} diff --git a/web/app/components/plugins/plugin-detail-panel/multiple-tool-selector/index.tsx b/web/app/components/plugins/plugin-detail-panel/multiple-tool-selector/index.tsx index 47c6833369..a6532ae6f7 100644 --- a/web/app/components/plugins/plugin-detail-panel/multiple-tool-selector/index.tsx +++ b/web/app/components/plugins/plugin-detail-panel/multiple-tool-selector/index.tsx @@ -5,10 +5,11 @@ import { RiArrowDropDownLine, RiQuestionLine, } from '@remixicon/react' -import type { ToolValue } from '@/app/components/plugins/plugin-detail-panel/tool-selector' +import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-selector' import ActionButton from '@/app/components/base/action-button' import Tooltip from '@/app/components/base/tooltip' import Divider from '@/app/components/base/divider' +import type { ToolValue } from '@/app/components/plugins/plugin-detail-panel/tool-selector' import cn from '@/utils/classnames' type Props = { @@ -18,25 +19,57 @@ type Props = { required?: boolean tooltip?: any supportCollapse?: boolean - onChange: (value: ToolValue[]) => void scope?: string + onChange: (value: ToolValue[]) => void } const MultipleToolSelector = ({ + disabled, value, label, required, tooltip, supportCollapse, + scope, + onChange, }: Props) => { const { t } = useTranslation() + // collapse control const [collapse, setCollapse] = React.useState(false) - const handleCollapse = () => { if (supportCollapse) setCollapse(!collapse) } + // add tool + const [open, setOpen] = React.useState(false) + const handleAdd = (val: ToolValue) => { + const newValue = [...value, val] + // deduplication + const deduplication = newValue.reduce((acc, cur) => { + if (!acc.find(item => item.provider_name === cur.provider_name && item.tool_name === cur.tool_name)) + acc.push(cur) + return acc + }, [] as ToolValue[]) + // update value + onChange(deduplication) + setOpen(false) + } + + // delete tool + const handleDelete = (index: number) => { + const newValue = [...value] + newValue.splice(index, 1) + onChange(newValue) + } + + // configure tool + const handleConfigure = (val: ToolValue, index: number) => { + const newValue = [...value] + newValue[index] = val + onChange(newValue) + } + return ( <>
@@ -74,15 +107,38 @@ const MultipleToolSelector = ({ )} - {}}> - - + {!disabled && ( + setOpen(!open)}> + + + )}
{!collapse && ( <> + + } + /> {value.length === 0 && (
{t('plugin.detailPanel.toolSelector.empty')}
)} + {value.length > 0 && value.map((item, index) => ( +
+ handleConfigure(item, index)} + onDelete={() => handleDelete(index)} + supportEnableSwitch + /> +
+ ))} )} 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 7bf6165971..d21a0a1ded 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 @@ -49,10 +49,11 @@ export type ToolValue = { } type Props = { - value?: ToolValue disabled?: boolean placement?: Placement offset?: OffsetOptions + scope?: string + value?: ToolValue onSelect: (tool: { provider_name: string tool_name: string @@ -60,8 +61,11 @@ type Props = { extra?: Record }) => void onDelete?: () => void + supportEnableSwitch?: boolean supportAddCustomTool?: boolean - scope?: string + trigger?: React.ReactNode + controlledState?: boolean + onControlledStateChange?: (state: boolean) => void } const ToolSelector: FC = ({ value, @@ -71,6 +75,10 @@ const ToolSelector: FC = ({ onSelect, onDelete, scope, + supportEnableSwitch, + trigger, + controlledState, + onControlledStateChange, }) => { const { t } = useTranslation() const [isShow, onShowChange] = useState(false) @@ -98,14 +106,13 @@ const ToolSelector: FC = ({ provider_name: tool.provider_id, tool_name: tool.tool_name, parameters: paramValues, + enabled: tool.is_team_authorization, extra: { description: '', }, } onSelect(toolValue) setIsShowChooseTool(false) - // if (tool.provider_type === CollectionType.builtIn && tool.is_team_authorization) - // onShowChange(false) } const handleDescriptionChange = (e: React.ChangeEvent) => { @@ -133,6 +140,13 @@ const ToolSelector: FC = ({ onSelect(toolValue as any) } + const handleEnabledChange = (state: boolean) => { + onSelect({ + ...value, + enabled: state, + } as any) + } + // authorization const { isCurrentWorkspaceManager } = useAppContext() const [isShowSettingAuth, setShowSettingAuth] = useState(false) @@ -155,14 +169,15 @@ const ToolSelector: FC = ({ - {!value?.provider_name && ( + {trigger} + {!trigger && !value?.provider_name && ( = ({ provider={currentProvider} /> )} - {value?.provider_name && ( + {!trigger && value?.provider_name && ( setShowSettingAuth(true)} - // uninstalled + // uninstalled TODO + // isError TODO errorTip={

{t('workflow.nodes.agent.pluginNotInstalled')}

{t('workflow.nodes.agent.pluginNotInstalledDesc')}

diff --git a/web/app/components/plugins/plugin-detail-panel/tool-selector/tool-item.tsx b/web/app/components/plugins/plugin-detail-panel/tool-selector/tool-item.tsx index a20e0d6e6f..f2ff56d07b 100644 --- a/web/app/components/plugins/plugin-detail-panel/tool-selector/tool-item.tsx +++ b/web/app/components/plugins/plugin-detail-panel/tool-selector/tool-item.tsx @@ -77,7 +77,10 @@ const ToolItem = ({ )}
{ + e.stopPropagation() + onDelete?.() + }} onMouseOver={() => setIsDeleting(true)} onMouseLeave={() => setIsDeleting(false)} > @@ -85,11 +88,13 @@ const ToolItem = ({
{!isError && !uninstalled && !noAuth && showSwitch && ( - +
e.stopPropagation()}> + +
)} {!isError && !uninstalled && noAuth && (