feat(ui): 实现消息 parts 有序渲染
- Server: API 返回 parts 数组保持原始顺序 - Server: 添加 MessagePart 类型定义 (text/tool/reasoning) - UI: ChatMessage 按 parts 顺序交叉渲染文本和工具调用 - UI: 新增 ToolPartItem 组件渲染单个工具 part - UI: useChat 创建消息时添加 parts 字段
This commit is contained in:
@@ -29,19 +29,62 @@ export interface ToolCallInfo {
|
||||
duration?: number; // 执行时长 ms
|
||||
}
|
||||
|
||||
// ============ 消息 Parts 相关 ============
|
||||
|
||||
/**
|
||||
* 文本 Part
|
||||
*/
|
||||
export interface TextMessagePart {
|
||||
type: 'text';
|
||||
id: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具调用 Part
|
||||
*/
|
||||
export interface ToolMessagePart {
|
||||
type: 'tool';
|
||||
id: string;
|
||||
toolCallId: string;
|
||||
toolName: string;
|
||||
status: ToolCallStatus;
|
||||
arguments: Record<string, unknown>;
|
||||
result?: unknown;
|
||||
error?: string;
|
||||
duration?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推理 Part
|
||||
*/
|
||||
export interface ReasoningMessagePart {
|
||||
type: 'reasoning';
|
||||
id: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息 Part 联合类型
|
||||
*/
|
||||
export type MessagePart = TextMessagePart | ToolMessagePart | ReasoningMessagePart;
|
||||
|
||||
/**
|
||||
* 消息格式(存储层已经是 2-message 格式,无需 API 层合并)
|
||||
*
|
||||
* 只有 user 和 assistant 两种角色:
|
||||
* - user: 用户输入
|
||||
* - assistant: AI 回复(包含文本和工具调用)
|
||||
* - assistant: AI 回复(包含文本和工具调用,按原始顺序)
|
||||
*/
|
||||
export interface Message {
|
||||
id: string;
|
||||
role: 'user' | 'assistant';
|
||||
content: string;
|
||||
timestamp: string;
|
||||
/** 工具调用列表 */
|
||||
/** 有序的消息内容 Parts */
|
||||
parts: MessagePart[];
|
||||
/** 所有文本拼接(兼容字段) */
|
||||
content?: string;
|
||||
/** 所有工具调用(兼容字段) */
|
||||
toolCalls?: ToolCallInfo[];
|
||||
/** 是否包含推理过程 */
|
||||
hasReasoning?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user