修复: 工具卡片永远显示执行中
根因:aiShared 的消息引用在会话切换时失效。 switchConversation 和 newConversation 会整体替换 state.messages (赋值新数组),但 aiShared 缓存的是旧数组引用。切换后 findToolCall 在旧数组中找不到新消息的工具卡片,AiToolCallCompleted 事件无法更新卡片状态,卡片永远停在 running。 修复:缓存数组引用改为 getter 函数,每次调用实时从 state 读取 最新数组,确保切换会话后仍能找到工具卡片。
This commit is contained in:
@@ -190,8 +190,10 @@ export const state = reactive(_stateBase) as typeof _stateBase & {
|
||||
}
|
||||
// 回填 stateRef:accessor 闭包读此引用(经 reactive 包装后的代理对象,activeConversationId 变化可追踪)。
|
||||
stateRef = state
|
||||
// 注入 messages 引用到 aiShared 共享层(破循环依赖,避免 Vite 打包 TDZ)。
|
||||
__bindMessages(state.messages)
|
||||
// 注入 messages getter 到 aiShared 共享层(破循环依赖,避免 Vite 打包 TDZ)。
|
||||
// 用 getter 而非数组引用:switchConversation/newConversation 会整体替换 state.messages,
|
||||
// 缓存引用会指向陈旧数组(findToolCall 找不到新数组的工具卡片 → Completed 事件无法更新 → 卡片卡 running)。
|
||||
__bindMessages(() => state.messages)
|
||||
|
||||
// 旁注:此处不再保留 type-only 导出(AiChatEvent 等),因组件直接从 api/types import。
|
||||
// 若有外部模块仍从本文件 import 这些类型,下方 re-export 兜底:
|
||||
|
||||
Reference in New Issue
Block a user