refactor(ui,server): 移除冗余的 toolCalls 兼容字段

删除从 parts 中提取的冗余 toolCalls 数组:
- 移除 ToolCallInfo 类型定义
- 移除 Message.toolCalls 字段
- 移除 ToolCallsDisplay/ToolCallItem 组件
- 简化 sessions.ts 消息构建逻辑
This commit is contained in:
2025-12-17 21:46:28 +08:00
parent c6dd3695e5
commit 2ff74e446c
4 changed files with 12 additions and 168 deletions
+2 -17
View File
@@ -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,
});
}
-15
View File
@@ -349,19 +349,6 @@ export interface ReasoningMessagePart {
*/
export type MessagePart = TextMessagePart | ToolMessagePart | ReasoningMessagePart;
/**
* 工具调用信息(兼容字段,合并后)
*/
export interface ToolCallInfo {
id: string;
name: string;
arguments: Record<string, unknown>;
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;