'use client' import type { FC } from 'react' import { useState } from 'react' import { RiCheckboxCircleLine, RiErrorWarningLine, } from '@remixicon/react' import { useContext } from 'use-context-selector' import cn from '@/utils/classnames' import BlockIcon from '@/app/components/workflow/block-icon' import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor' import { CodeLanguage } from '@/app/components/workflow/nodes/code/types' import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows' import type { ToolCall } from '@/models/log' import { BlockEnum } from '@/app/components/workflow/types' import I18n from '@/context/i18n' type Props = { toolCall: ToolCall isLLM: boolean isFinal?: boolean tokens?: number observation?: any finalAnswer?: any } const ToolCallItem: FC = ({ toolCall, isLLM = false, isFinal, tokens, observation, finalAnswer }) => { const [collapseState, setCollapseState] = useState(true) const { locale } = useContext(I18n) const toolName = isLLM ? 'LLM' : (toolCall.tool_label[locale] || toolCall.tool_label[locale.replaceAll('-', '_')]) const getTime = (time: number) => { if (time < 1) return `${(time * 1000).toFixed(3)} ms` if (time > 60) return `${parseInt(Math.round(time / 60).toString())} m ${(time % 60).toFixed(3)} s` return `${time.toFixed(3)} s` } const getTokenCount = (tokens: number) => { if (tokens < 1000) return tokens if (tokens >= 1000 && tokens < 1000000) return `${parseFloat((tokens / 1000).toFixed(3))}K` if (tokens >= 1000000) return `${parseFloat((tokens / 1000000).toFixed(3))}M` } return (
setCollapseState(!collapseState)} >
{toolName}
{toolCall.time_cost && ( {getTime(toolCall.time_cost || 0)} )} {isLLM && ( {`${getTokenCount(tokens || 0)} tokens`} )}
{toolCall.status === 'success' && ( )} {toolCall.status === 'error' && ( )}
{!collapseState && (
{toolCall.status === 'error' && (
{toolCall.error}
)}
{toolCall.tool_input && (
INPUT
} language={CodeLanguage.json} value={toolCall.tool_input} isJSONStringifyBeauty />
)} {toolCall.tool_output && (
OUTPUT
} language={CodeLanguage.json} value={toolCall.tool_output} isJSONStringifyBeauty />
)} {isLLM && (
OBSERVATION
} language={CodeLanguage.json} value={observation} isJSONStringifyBeauty />
)} {isLLM && (
{isFinal ? 'FINAL ANSWER' : 'THOUGHT'}
} language={CodeLanguage.json} value={finalAnswer} isJSONStringifyBeauty /> )} )} ) } export default ToolCallItem