fix: 修复多迭代 Agent Loop 的两个UI bug

Bug 1: 正在思考占位符作为独立消息残留
- 根因: renderMessages() 将 loading placeholder 计入 existingCount,
  导致新保存的消息不被渲染,旧 placeholder 永远留在页面上
- 修复: onNewIteration 保存消息前先移除旧 placeholder

Bug 2: 只有最后一条AI消息显示 token 统计
- 根因: onNewIteration 保存中间消息时不附带 token/duration 统计,
  只有 onDone 对最后一条才添加 loopStats(总累计值)
- 修复: 追踪每轮迭代的 eval_count 增量和耗时,
  中间消息和最后消息均保存 per-iteration 统计,
  确保 updateTotalTokens 求和不重复计数
This commit is contained in:
thzxx
2026-04-21 09:05:07 +08:00
parent 2496e04685
commit e5acf646c8
2 changed files with 33 additions and 6 deletions
+1 -1
View File
@@ -581,7 +581,7 @@ export async function runAgentLoop(
content += chunk.message.content;
callbacks.onContent(content);
}
if (chunk.eval_count) totalEvalCount = chunk.eval_count;
if (chunk.eval_count) { totalEvalCount = chunk.eval_count; state.set('_currentEvalCount', totalEvalCount); }
if (chunk.message?.tool_calls?.length) {
for (const tc of chunk.message.tool_calls) {
if (tc.function?.name) {