From cae6006a960377de808e9c1876faf4350f8cb1af Mon Sep 17 00:00:00 2001 From: Suzumiya Date: Wed, 16 Sep 2026 00:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=96=87=E6=9C=AC=E6=AE=B5=E8=A2=AB?= =?UTF-8?q?=E6=88=AA=E6=96=AD=EF=BC=9A=E5=90=8C=E4=B8=80=20item=20?= =?UTF-8?q?=E7=9A=84=E6=96=87=E6=9C=AC=E6=8C=89=E6=9B=B4=E9=95=BF=E4=BC=98?= =?UTF-8?q?=E5=85=88=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 现象:回合正文只剩前缀(如"我来"),后面的完整文本没进对话流 - 根因:文本段快照的 updatedAt 未必单调递增,而合并规则只在 updatedAt 更新(或同刻)时才替换,后到的更长文本被判为"更旧"而丢弃 - Rust(direct_turn_stream.rs):kind=text 时更长文本优先;合并后 updated_at 取两者最大值,不回退顺序元数据 - 前端(App.tsx mergeTurnStreamItems):同规则改为更长优先 - 验证:cargo build 0 error、tsc 0 错误 --- .../src-tauri/src/agent/direct_turn_stream.rs | 5 ++++- apps/ai-game-creator-shell/src/App.tsx | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_turn_stream.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_turn_stream.rs index 4b9bdbfb7..5bbdb7d20 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_turn_stream.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_turn_stream.rs @@ -211,13 +211,16 @@ fn merge_stream_snapshot( .map(Iterator::count) .unwrap_or_default() }; + // 文本段按"更长优先":同一个 item 的文本只会增长,而快照的 updated_at 未必单调递增; + // 只认 updated_at 更新会把后到的完整文本丢掉(实机表现:正文只剩前缀"我来")。 let take_incoming = incoming.updated_at > existing.updated_at + || (incoming.kind == "text" && text_len(incoming) > text_len(existing)) || (incoming.updated_at == existing.updated_at && text_len(incoming) > text_len(existing)); let mut merged = existing.clone(); if take_incoming { merged.text = incoming.text.clone(); - merged.updated_at = incoming.updated_at; } + merged.updated_at = merged.updated_at.max(incoming.updated_at); if merged.call_id.is_none() { merged.call_id = incoming.call_id.clone(); } diff --git a/apps/ai-game-creator-shell/src/App.tsx b/apps/ai-game-creator-shell/src/App.tsx index 00eb59762..78cb692fb 100644 --- a/apps/ai-game-creator-shell/src/App.tsx +++ b/apps/ai-game-creator-shell/src/App.tsx @@ -550,8 +550,12 @@ function mergeTurnStreamItems( // 内容只在更新(或同刻更长)的快照上替换;`seq` 取最早,位置不许回退。 const textLength = (value: TurnStreamItem) => value.kind === 'text' ? (value.text?.length ?? 0) : 0; + // 文本段按"更长优先":同一个 item 的文本只会增长,而快照的 updatedAt 未必单调递增; + // 只认 updatedAt 更新会把后到的完整文本丢掉(实机表现:正文只剩前缀"我来")。 const takeIncoming = normalized.updatedAt > previous.updatedAt || + (normalized.kind === 'text' && + textLength(normalized) > textLength(previous)) || (normalized.updatedAt === previous.updatedAt && textLength(normalized) > textLength(previous)); byId.set(id, {