[P1/高] AgentStore setCurrentSession 过滤 tool 消息但 UI 仍渲染 ToolMessage,逻辑矛盾 #38

Open
opened 2026-07-21 21:56:03 +08:00 by thzxx · 0 comments
Owner

问题类型

缺陷 / 高 / 前端组件

文件位置

  • src/stores/agent-store.ts (setCurrentSession)
  • src/components/chat/ (ToolMessage 渲染)

问题描述

setCurrentSession 加载会话历史时:

const filtered = messages.filter(m => m.role !== 'tool');

过滤掉 tool 角色消息(防止冗余 UI 卡片)。
但前端组件中仍存在 ToolMessage 组件用于渲染 tool 消息:

  • 与过滤逻辑矛盾
  • 开发者难以理解预期行为
  • 可能导致 assistant 消息中的 tool_calls 失去对应 tool result

影响

  • 代码逻辑混乱
  • 维护困难
  • 潜在的 UI bug

建议修复

明确决策:

方案 A:显示 tool 消息(移除过滤)

// 不再过滤
const filtered = messages;

方案 B:不显示 tool 消息,但保留 tool_calls 与 tool result 的关联

// 过滤独立的 tool 消息
// 但保留 assistant 消息中的 tool_calls
const filtered = messages.filter(m => m.role !== 'tool');
// 删除 ToolMessage 组件

方案 B 更符合用户预期(不显示工具调用细节)。统一代码与 UI。

## 问题类型 缺陷 / 高 / 前端组件 ## 文件位置 - `src/stores/agent-store.ts` (setCurrentSession) - `src/components/chat/` (ToolMessage 渲染) ## 问题描述 setCurrentSession 加载会话历史时: ```ts const filtered = messages.filter(m => m.role !== 'tool'); ``` 过滤掉 tool 角色消息(防止冗余 UI 卡片)。 但前端组件中仍存在 ToolMessage 组件用于渲染 tool 消息: - 与过滤逻辑矛盾 - 开发者难以理解预期行为 - 可能导致 assistant 消息中的 tool_calls 失去对应 tool result ## 影响 - 代码逻辑混乱 - 维护困难 - 潜在的 UI bug ## 建议修复 明确决策: **方案 A**:显示 tool 消息(移除过滤) ```ts // 不再过滤 const filtered = messages; ``` **方案 B**:不显示 tool 消息,但保留 tool_calls 与 tool result 的关联 ```ts // 过滤独立的 tool 消息 // 但保留 assistant 消息中的 tool_calls const filtered = messages.filter(m => m.role !== 'tool'); // 删除 ToolMessage 组件 ``` 方案 B 更符合用户预期(不显示工具调用细节)。统一代码与 UI。
thzxx added the ??????? labels 2026-07-21 21:56:03 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#38