diff --git a/packages/server/src/routes/sessions.ts b/packages/server/src/routes/sessions.ts index 4022247..e526221 100644 --- a/packages/server/src/routes/sessions.ts +++ b/packages/server/src/routes/sessions.ts @@ -8,12 +8,11 @@ import { Hono } from 'hono'; import { getSessionManager } from '../session/manager.js'; import { CreateSessionInputSchema, - type ToolCallInfo, type Message, type MessagePart, } from '../types.js'; -import type { MessageInfo, Part, ToolPart, ApiPart } from '@ai-assistant/core'; -import { MessageStorage, PartStorage, partsToApiFormat, getToolInput, getToolDuration } from '@ai-assistant/core'; +import type { MessageInfo, Part, ApiPart } from '@ai-assistant/core'; +import { MessageStorage, PartStorage, partsToApiFormat } from '@ai-assistant/core'; export const sessionsRouter = new Hono(); @@ -187,19 +186,6 @@ sessionsRouter.get('/:id/messages', async (c) => { .map((p) => p.text ?? '') .join(''); - // 兼容字段:提取工具调用(使用 Core 工具函数) - const toolCalls: ToolCallInfo[] = parts - .filter((p): p is ToolPart => p.type === 'tool') - .map((p) => ({ - id: p.toolCallId ?? '', - name: p.toolName ?? '', - arguments: getToolInput(p), - status: p.state.status, - result: p.state.status === 'completed' ? (p.state as { output: unknown }).output : undefined, - error: p.state.status === 'error' ? (p.state as { error: string }).error : undefined, - duration: getToolDuration(p), - })); - messages.push({ id: msgInfo.id, sessionId: msgInfo.sessionId, @@ -207,7 +193,6 @@ sessionsRouter.get('/:id/messages', async (c) => { timestamp: new Date(msgInfo.createdAt).toISOString(), parts: messageParts, content: textContent || undefined, - toolCalls: toolCalls.length > 0 ? toolCalls : undefined, }); } diff --git a/packages/server/src/types.ts b/packages/server/src/types.ts index fcba7c9..c5d7052 100644 --- a/packages/server/src/types.ts +++ b/packages/server/src/types.ts @@ -349,19 +349,6 @@ export interface ReasoningMessagePart { */ export type MessagePart = TextMessagePart | ToolMessagePart | ReasoningMessagePart; -/** - * 工具调用信息(兼容字段,合并后) - */ -export interface ToolCallInfo { - id: string; - name: string; - arguments: Record; - status: ToolStatus; - result?: unknown; - error?: string; - duration?: number; -} - /** * 消息格式(包含有序 Parts) * @@ -378,8 +365,6 @@ export interface Message { parts: MessagePart[]; /** 所有文本拼接(兼容字段) */ content?: string; - /** 所有工具调用(兼容字段) */ - toolCalls?: ToolCallInfo[]; metadata?: { model?: string; stepCount?: number; diff --git a/packages/ui/src/api/types.ts b/packages/ui/src/api/types.ts index 977568e..ed60943 100644 --- a/packages/ui/src/api/types.ts +++ b/packages/ui/src/api/types.ts @@ -20,19 +20,6 @@ export type ToolStatus = 'pending' | 'running' | 'completed' | 'error'; /** @deprecated 使用 ToolStatus 代替 */ export type ToolCallStatus = ToolStatus; -/** - * 工具调用信息 - */ -export interface ToolCallInfo { - id: string; - name: string; - arguments: Record; - status: ToolStatus; - result?: unknown; - error?: string; - duration?: number; // 执行时长 ms -} - // ============ 消息 Parts 相关 ============ /** @@ -128,8 +115,6 @@ export interface Message { parts: MessagePart[]; /** 所有文本拼接(兼容字段) */ content?: string; - /** 所有工具调用(兼容字段) */ - toolCalls?: ToolCallInfo[]; /** 是否包含推理过程 */ hasReasoning?: boolean; /** 推理内容 */ diff --git a/packages/ui/src/components/ChatMessage.tsx b/packages/ui/src/components/ChatMessage.tsx index 858ba40..635245d 100644 --- a/packages/ui/src/components/ChatMessage.tsx +++ b/packages/ui/src/components/ChatMessage.tsx @@ -23,7 +23,7 @@ import { fadeInUp, smoothTransition } from '../utils/animations'; import { getAgentDisplayName } from '../utils/agent'; import { Markdown } from './Markdown'; import { FileMentionText } from './FileMentionTag'; -import type { Message, ToolCallInfo, ToolStatus, ToolMessagePart, QuestionMessagePart, FileDiffInfo } from '../api/types.js'; +import type { Message, ToolStatus, ToolMessagePart, QuestionMessagePart, FileDiffInfo } from '../api/types.js'; import { AskUserQuestion } from './AskUserQuestion.js'; interface ChatMessageProps { @@ -117,22 +117,17 @@ export const ChatMessage = forwardRef( ); } - // 回退:使用旧的 content + toolCalls 字段 + // 回退:使用 content 字段(无 parts 时) return ( - <> - {!isUser && message.toolCalls && message.toolCalls.length > 0 && ( - +
+ {isUser ? ( +
+ +
+ ) : ( + )} -
- {isUser ? ( -
- -
- ) : ( - - )} -
- +
); }; @@ -384,109 +379,3 @@ function formatDuration(ms?: number): string { return `${(ms / 1000).toFixed(1)}s`; } -/** - * 工具调用列表容器 - */ -interface ToolCallsDisplayProps { - toolCalls: ToolCallInfo[]; -} - -function ToolCallsDisplay({ toolCalls }: ToolCallsDisplayProps) { - return ( -
- {toolCalls.map((toolCall) => ( - - ))} -
- ); -} - -/** - * 单个工具调用项 - */ -interface ToolCallItemProps { - toolCall: ToolCallInfo; -} - -function ToolCallItem({ toolCall }: ToolCallItemProps) { - const [expanded, setExpanded] = useState(false); - const hasDetails = - Object.keys(toolCall.arguments).length > 0 || - toolCall.result !== undefined || - toolCall.error !== undefined; - - return ( -
- {/* 头部:工具名称、状态、时长 */} - - - {/* 展开的详情 */} - - {expanded && hasDetails && ( - -
- {/* 参数 */} - {Object.keys(toolCall.arguments).length > 0 && ( -
-
Arguments:
-
-                    {JSON.stringify(toolCall.arguments, null, 2)}
-                  
-
- )} - - {/* 结果 */} - {toolCall.result !== undefined && ( -
-
Result:
-
-                    {typeof toolCall.result === 'string'
-                      ? toolCall.result
-                      : JSON.stringify(toolCall.result, null, 2)}
-                  
-
- )} - - {/* 错误 */} - {toolCall.error && ( -
-
Error:
-
-                    {toolCall.error}
-                  
-
- )} -
-
- )} -
-
- ); -}