重构: 审批交互重设计

This commit is contained in:
lxy
2026-10-05 14:59:12 +08:00
parent 24d6803ecc
commit 2eea0118db
7 changed files with 254 additions and 30 deletions
+16
View File
@@ -42,6 +42,8 @@ export function handleToolEvent(event: AiChatEvent): boolean {
tc.status = 'completed'
tc.result = event.result
tc.completedAt = Date.now()
// 清流式缓冲:结果由 result 渲染,流式行是执行中间态,留着会双显
tc.streamLines = undefined
}
// 移除待审批(含 per-conv 集合,后台会话集合里的同 id 挂起一并清)
removePendingApprovalById(event.id)
@@ -57,6 +59,20 @@ export function handleToolEvent(event: AiChatEvent): boolean {
return true
}
case 'AiCommandOutput': {
// 工具执行实时流式(run_command shell 行级 / ask_uclaw 进度块级):
// 按 id 路由到对应工具卡,streamLines 追加(上限 200 行防长任务刷爆响应式数组,
// 超限丢头保尾——最新进度更有价值)。Completed 时清空(结果由 result 渲染,防双显)。
// 找不到工具卡(极早到/已收尾)静默忽略。
const tc = findToolCall(event.id)
if (tc) {
if (!tc.streamLines) tc.streamLines = []
tc.streamLines.push(event.line)
if (tc.streamLines.length > 200) tc.streamLines.splice(0, tc.streamLines.length - 200)
}
return true
}
case 'AiApprovalRequired': {
clearStreamWatchdog(event.conversation_id || undefined) // 等用户审批,不计整流超时
const info: AiToolCallInfo = {