'use client' import type { FC } from 'react' import React, { useState } from 'react' import { useTranslation } from 'react-i18next' import cn from 'classnames' import type { ToolInfoInThought } from '../type' import Panel from './panel' import Loading02 from '@/app/components/base/icons/line/loading-02' import ChevronDown from '@/app/components/base/icons/line/arrows/chevron-down' import CheckCircle from '@/app/components/base/icons/solid/general/check-circle' import DataSetIcon from '@/app/components/base/icons/public/data-set' import type { Emoji } from '@/types/tools' import AppIcon from '@/app/components/base/app-icon' interface Props { payload: ToolInfoInThought allToolIcons?: Record } const getIcon = (toolName: string, allToolIcons: Record) => { if (toolName.startsWith('dataset-')) { return } const icon = allToolIcons[toolName] if (!icon) { return null } return ( typeof icon === 'string' ? (
) : ( )) } const Tool: FC = ({ payload, allToolIcons = {}, }) => { const { t } = useTranslation() const { name, input, isFinished, output } = payload const toolName = name.startsWith('dataset-') ? t('dataset.knowledge') : name const [isShowDetail, setIsShowDetail] = useState(false) const icon = getIcon(toolName, allToolIcons) as any return (
setIsShowDetail(!isShowDetail)} > {!isFinished && ( )} {isFinished && !isShowDetail && ( )} {isFinished && isShowDetail && ( icon )} {t(`tools.thought.${isFinished ? 'used' : 'using'}`)} {toolName}
{isShowDetail && (
{output && ( )}
)}
) } export default React.memo(Tool)