// dashboard/src/components/agent/ToolCallCard.tsx // 工具调用卡片:展示参数和结果,皆可独立折叠 import { Settings, Eye } from 'lucide-react'; import type { ColorScheme } from './constants'; import { getToolDisplayName } from './toolDisplayNames'; import { AgentMarkdown } from './AgentMarkdown'; import { useAutoScroll } from './useAutoScroll'; interface ToolCallCardProps { step: number; name: string; arguments: Record; result?: { output: string; isError: boolean }; isStreaming: boolean; colorScheme: ColorScheme; isArgsExpanded: boolean; isResultExpanded: boolean; onToggleArgs: () => void; onToggleResult: () => void; } export function ToolCallCard({ step, name, arguments: args, result, isStreaming, colorScheme, isArgsExpanded, isResultExpanded, onToggleArgs, onToggleResult, }: ToolCallCardProps) { const hasResult = !!result; const dotColor = isStreaming ? colorScheme.tool_call.active : colorScheme.tool_call.idle; const { chatEndRef, scrollContainerRef, handleScroll } = useAutoScroll( result ? [result.output] : [], ); return (
{/* 工具名称 */}
调用工具: {getToolDisplayName(name)} · Step {step}
{/* 参数 */} {isArgsExpanded && (
{JSON.stringify(args, null, 2)}
)} {/* 结果 */} {hasResult && (
观测与反馈 (Observation) {result!.isError && ( 错误返回 )}
{isResultExpanded ? (
{result!.output}
) : (
结果已截断 (共 {result!.output.length} 字符)。点击右侧展开。
)}
)}
); }