diff --git a/web/app/components/workflow/block-selector/tool-item.tsx b/web/app/components/workflow/block-selector/tool-item.tsx new file mode 100644 index 0000000000..a5e1639392 --- /dev/null +++ b/web/app/components/workflow/block-selector/tool-item.tsx @@ -0,0 +1,110 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import { RiArrowRightSLine } from '@remixicon/react' +import { useBoolean } from 'ahooks' +import BlockIcon from '../block-icon' +import type { ToolWithProvider } from '../types' +import { BlockEnum } from '../types' +import type { ToolDefaultValue } from './types' +import Tooltip from '@/app/components/base/tooltip' +import type { Tool } from '@/app/components/tools/types' +import { useGetLanguage } from '@/context/i18n' + +type Props = { + isToolPlugin: boolean // Tool plugin should choose action + provider: ToolWithProvider + payload: Tool + onSelect: (type: BlockEnum, tool?: ToolDefaultValue) => void +} + +const ToolItem: FC = ({ + isToolPlugin, + provider, + payload, + onSelect, +}) => { + const language = useGetLanguage() + const [isFold, { + toggle: toggleFold, + }] = useBoolean(true) + + const actions = [ + 'DuckDuckGo AI Search', + 'DuckDuckGo Connect', + ] + + return ( + + +
{payload.label[language]}
+
{payload.description[language]}
+ + )} + > +
+
{ + if (isToolPlugin) { + toggleFold() + return + } + onSelect(BlockEnum.Tool, { + provider_id: provider.id, + provider_type: provider.type, + provider_name: provider.name, + tool_name: payload.name, + tool_label: payload.label[language], + title: payload.label[language], + }) + }} + > + {isToolPlugin && ( + + )} + +
{payload.label[language]}
+
+ {(!isFold && isToolPlugin) && ( +
+ {actions.map(action => ( +
{ + onSelect(BlockEnum.Tool, { + provider_id: provider.id, + provider_type: provider.type, + provider_name: provider.name, + tool_name: payload.name, + tool_label: payload.label[language], + title: payload.label[language], + }) + }} + > +
{action}
+
+ ))} +
+ )} +
+ +
+ ) +} +export default React.memo(ToolItem) diff --git a/web/app/components/workflow/block-selector/tools.tsx b/web/app/components/workflow/block-selector/tools.tsx index a2ae845997..534fe1499d 100644 --- a/web/app/components/workflow/block-selector/tools.tsx +++ b/web/app/components/workflow/block-selector/tools.tsx @@ -4,12 +4,10 @@ import { useRef, } from 'react' import { useTranslation } from 'react-i18next' -import BlockIcon from '../block-icon' -import { BlockEnum } from '../types' -import type { ToolWithProvider } from '../types' +import type { BlockEnum, ToolWithProvider } from '../types' import IndexBar, { groupItems } from './index-bar' import type { ToolDefaultValue } from './types' -import Tooltip from '@/app/components/base/tooltip' +import ToolItem from './tool-item' import Empty from '@/app/components/tools/add-tool-modal/empty' import { useGetLanguage } from '@/context/i18n' @@ -42,42 +40,13 @@ const Blocks = ({ { list.map(tool => ( - - -
{tool.label[language]}
-
{tool.description[language]}
- - )} - > -
onSelect(BlockEnum.Tool, { - provider_id: toolWithProvider.id, - provider_type: toolWithProvider.type, - provider_name: toolWithProvider.name, - tool_name: tool.name, - tool_label: tool.label[language], - title: tool.label[language], - })} - > - -
{tool.label[language]}
-
-
+ isToolPlugin={toolWithProvider.type === 'builtin'} + provider={toolWithProvider} + payload={tool} + onSelect={onSelect} + /> )) }