import React from 'react'; import { ThoughtChain } from '@ant-design/x'; interface ToolCall { id: string; name: string; input: string; output?: string; isError?: boolean; } interface ToolChainProps { tools: ToolCall[]; } const ToolChain: React.FC = ({ tools }) => { const items = tools.map((tool) => { const hasResult = tool.output !== undefined; let status: 'loading' | 'success' | 'error' = 'loading'; if (hasResult) { status = tool.isError ? 'error' : 'success'; } return { key: tool.id, status, title: tool.name, description: hasResult ? (tool.isError ? '执行出错' : '执行完成') : '执行中...', collapsible: true, content: (
{tool.input && (
输入
                {tryFormatJSON(tool.input)}
              
)} {tool.output !== undefined && (
{tool.isError ? '错误' : '输出'}
                {tool.output}
              
)}
), }; }); if (items.length === 0) return null; return ; }; function tryFormatJSON(str: string): string { try { return JSON.stringify(JSON.parse(str), null, 2); } catch { return str; } } export default ToolChain; export type { ToolCall };