From 76aec62d36d164b1616520fb595822dd6c29b30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Tue, 30 Jun 2026 23:26:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20stores/ai=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E9=A1=B6=E5=B1=82=20=5F=5FbindMessages=20TDZ=20?= =?UTF-8?q?=E9=98=B2=E5=BE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - __bindMessages 包装 try/catch,aiShared 未就绪时延迟到微任务重试 - 防 ES module 循环初始化顺序导致的 Cannot access before initialization --- src/stores/ai.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 兜底: