import { memo, useCallback, } from 'react' import { useTranslation } from 'react-i18next' import { RiAddLine, } from '@remixicon/react' import cn from '@/utils/classnames' import { ArrowUpRight } from '@/app/components/base/icons/src/vender/line/arrows' import { Check } from '@/app/components/base/icons/src/vender/line/general' import { Tag01 } from '@/app/components/base/icons/src/vender/line/financeAndECommerce' import type { ToolWithProvider } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types' import BlockIcon from '@/app/components/workflow/block-icon' import Tooltip from '@/app/components/base/tooltip' import Button from '@/app/components/base/button' import { useGetLanguage } from '@/context/i18n' import { useStore as useLabelStore } from '@/app/components/tools/labels/store' import Empty from '@/app/components/tools/add-tool-modal/empty' import type { Tool } from '@/app/components/tools/types' import { CollectionType } from '@/app/components/tools/types' import type { AgentTool } from '@/types/app' import { MAX_TOOLS_NUM } from '@/config' type ToolsProps = { showWorkflowEmpty: boolean tools: ToolWithProvider[] addedTools: AgentTool[] onSelect: (provider: ToolWithProvider, tool: Tool) => void onAuthSetup: (provider: ToolWithProvider) => void } const Blocks = ({ showWorkflowEmpty, tools, addedTools, onSelect, onAuthSetup, }: ToolsProps) => { const { t } = useTranslation() const language = useGetLanguage() const labelList = useLabelStore(s => s.labelList) const addable = addedTools.length < MAX_TOOLS_NUM const renderGroup = useCallback((toolWithProvider: ToolWithProvider) => { const list = toolWithProvider.tools const needAuth = toolWithProvider.allow_delete && !toolWithProvider.is_team_authorization && toolWithProvider.type === CollectionType.builtIn return (
{toolWithProvider.label[language]} {t('tools.addToolModal.manageInTools')}
{list.map((tool) => { const labelContent = (() => { if (!tool.labels) return '' return tool.labels.map((name) => { const label = labelList.find(item => item.name === name) return label?.label[language] }).filter(Boolean).join(', ') })() const added = !!addedTools?.find(v => v.provider_id === toolWithProvider.id && v.provider_type === toolWithProvider.type && v.tool_name === tool.name) return (
{tool.label[language]}
{tool.description[language]}
{tool.labels?.length > 0 && (
{labelContent}
)}
)} >
{tool.label[language]}
{!needAuth && added && (
{t('tools.addToolModal.added').toLocaleUpperCase()}
)} {!needAuth && !added && addable && ( )} {needAuth && ( )}
) })} ) }, [addable, language, t, labelList, addedTools, onAuthSetup, onSelect]) return (
{!tools.length && !showWorkflowEmpty && (
{t('workflow.tabs.noResult')}
)} {!tools.length && showWorkflowEmpty && (
)} {!!tools.length && tools.map(renderGroup)}
) } export default memo(Blocks)