优化: 会话状态键控与提示补全
- 队列清空/发送失败补提示,错误接入分类文案 - 审批超时气泡按会话归属,流守卫按会话清理 - 会话操作失败就近反馈,拖拽非法流转提示原因
This commit is contained in:
@@ -175,13 +175,8 @@ export function startApprovalTimer(
|
||||
denyP.catch(e => {
|
||||
console.error('[AI] 审批超时自动拒绝 IPC 未送达:', e)
|
||||
})
|
||||
getMessages().push({
|
||||
id: `approval-timeout-${nextMsgId()}` as MessageId,
|
||||
role: 'assistant',
|
||||
content: t('ai.approvalTimeout', { toolName }),
|
||||
isError: true,
|
||||
timestamp: Date.now(),
|
||||
})
|
||||
// UX-P2-A3:气泡推送改经 per-conv 守卫(函数追加在本文件尾部),后台会话超时不串当前视图
|
||||
pushApprovalTimeoutBubble(toolName, toolCallId)
|
||||
}, timeoutMs)
|
||||
_approvalTimers.set(toolCallId, { timer, startedAt: Date.now(), timeoutMs })
|
||||
}
|
||||
@@ -665,3 +660,37 @@ export function clearConvAgentFinished(convId: string | null | undefined): void
|
||||
if (!convId) return
|
||||
convAgentFinished.delete(convId)
|
||||
}
|
||||
|
||||
// ── UX-P2-A3 审批超时错误气泡 per-conv 守卫 ──
|
||||
//
|
||||
// 背景:startApprovalTimer 到点把「审批超时已自动拒绝」错误气泡直接推进 getMessages()
|
||||
// (当前活跃视图),后台会话 A 的审批超时,气泡落在用户正查看的会话 B 里(跨会话串扰)。
|
||||
// 本守卫按审批所属 conv 过滤:仅当审批所属会话是当前活跃会话(或无法归属)才推视图气泡;
|
||||
// 后台会话的超时拒绝 IPC 照常执行,只是不串视图。
|
||||
// 归属反查:到点时刻从 per-conv 待审批集合(convPendingApprovals)按 toolCallId 反查 convId——
|
||||
// 此时拒绝 IPC 才刚发出,审批结果事件未到,集合项必在;查不到(旧数据/已被清)保守回落为推,
|
||||
// 不改变无归属场景的原行为。
|
||||
export function pushApprovalTimeoutBubble(toolName: string, toolCallId: string): void {
|
||||
let convId: string | null = null
|
||||
for (const [k, arr] of convPendingApprovals) {
|
||||
if (arr.some(p => p.id === toolCallId)) {
|
||||
convId = k
|
||||
break
|
||||
}
|
||||
}
|
||||
const active = getState()?.activeConversationId ?? null
|
||||
if (convId && convId !== active) return
|
||||
getMessages().push({
|
||||
id: `approval-timeout-${nextMsgId()}` as MessageId,
|
||||
role: 'assistant',
|
||||
content: t('ai.approvalTimeout', { toolName }),
|
||||
isError: true,
|
||||
timestamp: Date.now(),
|
||||
})
|
||||
}
|
||||
|
||||
/** 队列被清空的统一提示(UX-P2-A2:AiError/regenerate/editMessage 清队从静默改 toast,
|
||||
* 清 0 条不提示;经 ai-toast 事件总线,AiChat 本地 toast 消费) */
|
||||
export function notifyQueueCleared(n: number): void {
|
||||
if (n > 0) void emit('ai-toast', { msg: t('ai.queueCleared', { n }), type: 'warning' })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user