diff --git a/src/stores/ai.ts b/src/stores/ai.ts index cdd8d32..db67679 100644 --- a/src/stores/ai.ts +++ b/src/stores/ai.ts @@ -193,7 +193,13 @@ stateRef = state // 注入 messages getter 到 aiShared 共享层(破循环依赖,避免 Vite 打包 TDZ)。 // 用 getter 而非数组引用:switchConversation/newConversation 会整体替换 state.messages, // 缓存引用会指向陈旧数组(findToolCall 找不到新数组的工具卡片 → Completed 事件无法更新 → 卡片卡 running)。 -__bindMessages(() => state.messages) +// 延迟执行:wrap 在 try/catch 中,防 ES module 初始化顺序导致 aiShared 未就绪时炸 +try { + __bindMessages(() => state.messages) +} catch (e) { + // aiShared 模块初始化中(ES module 循环),延迟到微任务里重试 + Promise.resolve().then(() => __bindMessages(() => state.messages)) +} // 旁注:此处不再保留 type-only 导出(AiChatEvent 等),因组件直接从 api/types import。 // 若有外部模块仍从本文件 import 这些类型,下方 re-export 兜底: