From a5509fbe5abe8c344e505a54143c2bc66b03bd57 Mon Sep 17 00:00:00 2001 From: AkaraChen Date: Mon, 30 Dec 2024 11:28:51 +0800 Subject: [PATCH] feat: agent node toolbox --- .../nodes/agent/components/tool-icon.tsx | 26 ++++++++---- .../components/workflow/nodes/agent/node.tsx | 41 +++++++++---------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/web/app/components/workflow/nodes/agent/components/tool-icon.tsx b/web/app/components/workflow/nodes/agent/components/tool-icon.tsx index aca1a75f5d..893472af5e 100644 --- a/web/app/components/workflow/nodes/agent/components/tool-icon.tsx +++ b/web/app/components/workflow/nodes/agent/components/tool-icon.tsx @@ -1,30 +1,40 @@ import Tooltip from '@/app/components/base/tooltip' import Indicator from '@/app/components/header/indicator' import classNames from '@/utils/classnames' -import { useRef } from 'react' +import { useMemo, useRef } from 'react' +import { useAllBuiltInTools, useAllCustomTools, useAllWorkflowTools } from '@/service/use-tools' export type ToolIconProps = { - src: string - alt?: string status?: 'error' | 'warning' tooltip?: string + providerName: string } -export const ToolIcon = ({ src, status, tooltip, alt }: ToolIconProps) => { +export const ToolIcon = ({ status, tooltip, providerName }: ToolIconProps) => { const indicator = status === 'error' ? 'red' : status === 'warning' ? 'yellow' : undefined const containerRef = useRef(null) const notSuccess = (['error', 'warning'] as Array).includes(status) + const { data: buildInTools } = useAllBuiltInTools() + const { data: customTools } = useAllCustomTools() + const { data: workflowTools } = useAllWorkflowTools() + const currentProvider = useMemo(() => { + const mergedTools = [...(buildInTools || []), ...(customTools || []), ...(workflowTools || [])] + return mergedTools.find((toolWithProvider) => { + return toolWithProvider.name === providerName + }) + }, [providerName, buildInTools, customTools, workflowTools]) return
+ {/* eslint-disable-next-line @next/next/no-img-element */} {alt} diff --git a/web/app/components/workflow/nodes/agent/node.tsx b/web/app/components/workflow/nodes/agent/node.tsx index 626f38b11f..73ea2e87f9 100644 --- a/web/app/components/workflow/nodes/agent/node.tsx +++ b/web/app/components/workflow/nodes/agent/node.tsx @@ -8,13 +8,11 @@ import type { ToolIconProps } from './components/tool-icon' import { ToolIcon } from './components/tool-icon' import useConfig from './use-config' import { useTranslation } from 'react-i18next' -import { useInstalledPluginList } from '@/service/use-plugins' import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' const AgentNode: FC> = (props) => { const { inputs, currentStrategy } = useConfig(props.id, props.data) const { t } = useTranslation() - const pluginList = useInstalledPluginList() // TODO: Implement models const models = useMemo(() => { if (!inputs) return [] @@ -41,17 +39,28 @@ const AgentNode: FC> = (props) => { const tools = useMemo(() => { const tools: Array = [] currentStrategy?.parameters.forEach((param) => { - if (['array[tool]', 'tool'].includes(param.type)) { - const vari = inputs.agent_parameters?.[param.name] - if (!vari) return - if (Array.isArray(vari.value)) { - // TODO: Implement array of tools + if (param.type === FormTypeEnum.toolSelector) { + const field = param.name + const value = inputs.agent_parameters?.[field] + if (value) { + tools.push({ + providerName: value.provider_name, + }) } - else { - // TODO: Implement single tool + } + if (param.type === FormTypeEnum.multiToolSelector) { + const field = param.name + const value = inputs.agent_parameters?.[field] + if (value) { + (value as any[]).forEach((item) => { + tools.push({ + providerName: item.provider_name, + }) + }) } } }) + return tools }, [currentStrategy, inputs.agent_parameters]) return
{inputs.agent_strategy_name @@ -89,19 +98,7 @@ const AgentNode: FC> = (props) => { {t('workflow.nodes.agent.toolbox')} }>
- - - + {tools.map(tool => )}