/** * 工具调用面板组件 - 显示 MCP 工具调用过程 * 移动端优化:默认折叠,点击展开 */ 'use client'; import { useState } from 'react'; interface ToolCall { tool: string; result: unknown; } interface ToolCallPanelProps { toolCalls: ToolCall[]; isLoading: boolean; } export default function ToolCallPanel({ toolCalls, isLoading }: ToolCallPanelProps) { const [isExpanded, setIsExpanded] = useState(false); const [expandedItems, setExpandedItems] = useState>(new Set()); const toggleItem = (idx: number) => { setExpandedItems((prev) => { const newSet = new Set(prev); if (newSet.has(idx)) { newSet.delete(idx); } else { newSet.add(idx); } return newSet; }); }; // 移动端:显示为底部可折叠面板 // 桌面端:显示为右侧固定面板 const isMobile = typeof window !== 'undefined' && window.innerWidth < 768; if (isMobile) { return (
{/* 折叠头部 */} {/* 可折叠内容 */} {isExpanded && (
{toolCalls.length === 0 && isLoading && (

AI 正在调用工具...

)} {toolCalls.map((call, idx) => { const isItemExpanded = expandedItems.has(idx); return (
{isItemExpanded && (
                        {JSON.stringify(call.result, null, 2)}
                      
)}
); })} {isLoading && toolCalls.length > 0 && (

处理中...

)}
)}
); } // 桌面端布局 return (

工具调用

{toolCalls.length === 0 && isLoading && (

AI 正在思考...

)} {toolCalls.map((call, idx) => (
{call.tool} #{idx + 1}
              {JSON.stringify(call.result, null, 2)}
            
))} {isLoading && toolCalls.length > 0 && (

处理中...

)}
); }