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, {