优化: 聊天体验批与Web规范合规
This commit is contained in:
@@ -25,10 +25,19 @@ export function handleToolEvent(event: AiChatEvent): boolean {
|
||||
}
|
||||
// 同 id 重复 Started 不重复 push(provider id 不稳,防残留 running 空卡)
|
||||
if (!findToolCall(event.id)) {
|
||||
// #15(2026-10-05):末条非 assistant(如 system 占位/思考 pill/完成轨迹折叠重排)时
|
||||
// 原直接丢弃工具卡 → running 卡消失但工具仍在执行。兜底向前找最近 assistant 落卡;
|
||||
// 全程无 assistant(极端:首轮工具前无任何回复)才真丢弃(与原行为一致)。
|
||||
const lastMsg = state.messages[state.messages.length - 1]
|
||||
if (lastMsg && lastMsg.role === 'assistant') {
|
||||
lastMsg.toolCalls = lastMsg.toolCalls || []
|
||||
lastMsg.toolCalls.push(info)
|
||||
let target = (lastMsg && lastMsg.role === 'assistant') ? lastMsg : null
|
||||
if (!target) {
|
||||
for (let i = state.messages.length - 1; i >= 0; i--) {
|
||||
if (state.messages[i].role === 'assistant') { target = state.messages[i]; break }
|
||||
}
|
||||
}
|
||||
if (target) {
|
||||
target.toolCalls = target.toolCalls || []
|
||||
target.toolCalls.push(info)
|
||||
}
|
||||
}
|
||||
// 工具开始执行即挂慢执行计时器(超时仅 toast,不动 running 态)
|
||||
|
||||
Reference in New Issue
Block a user