feat(api): 实现消息合并 API,支持工具调用显示

- 新增 MergedMessage、ToolCallInfo 类型定义
- 创建 message-merger.ts 消息合并工具
- 更新 sessions 路由使用合并后的消息格式
- 前端新增 ToolCallsDisplay 组件展示工具调用
- 工具调用显示状态、时长,可展开查看参数和结果
This commit is contained in:
2025-12-15 12:21:16 +08:00
parent e9e8bfa30a
commit eda2ccb171
7 changed files with 567 additions and 43 deletions
+8 -3
View File
@@ -97,9 +97,14 @@ export async function listBySession(sessionId: string): Promise<MessageInfo[]> {
}
}
// 消息 ID 是降序的,所以排序后最新的在后面(时间升序
// 实际上按 ID 字符串排序即可,因为降序 ID 自然会让旧消息在前
return messages.sort((a, b) => b.id.localeCompare(a.id)).reverse();
// 按创建时间升序排列(最旧的在前
// 当时间相同时,按 ID 降序排列(ID 使用降序时间戳,所以 ID 大的更旧)
return messages.sort((a, b) => {
const timeDiff = a.createdAt - b.createdAt;
if (timeDiff !== 0) return timeDiff;
// ID 降序时间戳:数字大 = 时间旧,所以用 b - a 让旧的在前
return b.id.localeCompare(a.id);
});
}
/**
+2 -2
View File
@@ -150,12 +150,12 @@ export async function createTool(
messageId: string,
toolCallId: string,
toolName: string,
args: Record<string, unknown>
args?: Record<string, unknown>
): Promise<ToolPart> {
return create<ToolPart>(messageId, 'tool', {
toolCallId,
toolName,
args,
args: args ?? {},
status: 'pending',
});
}