From 899585ba7f7e63ca3746f92d6fd1599dc95557ba Mon Sep 17 00:00:00 2001 From: Wu Yue Date: Thu, 10 Jul 2025 11:20:30 +0800 Subject: [PATCH] fix(core): old ai messages not cleared before retrying (#13119) Close [AI-258](https://linear.app/affine-design/issue/AI-258) ## Summary by CodeRabbit * **Bug Fixes** * Improved the retry behavior in AI chat by ensuring previous streaming data is properly cleared before retrying, resulting in more accurate and consistent chat message handling. --- .../ai/components/ai-chat-messages/ai-chat-messages.ts | 1 + .../core/src/blocksuite/ai/peek-view/chat-block-peek-view.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-messages/ai-chat-messages.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-messages/ai-chat-messages.ts index 5e596e6177..41c5311416 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-messages/ai-chat-messages.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-messages/ai-chat-messages.ts @@ -437,6 +437,7 @@ export class AIChatMessages extends WithDisposable(ShadowlessElement) { const last = messages[messages.length - 1]; if ('content' in last) { last.content = ''; + last.streamObjects = []; last.createdAt = new Date().toISOString(); } this.updateContext({ diff --git a/packages/frontend/core/src/blocksuite/ai/peek-view/chat-block-peek-view.ts b/packages/frontend/core/src/blocksuite/ai/peek-view/chat-block-peek-view.ts index 9637c9fbfd..471ff6689a 100644 --- a/packages/frontend/core/src/blocksuite/ai/peek-view/chat-block-peek-view.ts +++ b/packages/frontend/core/src/blocksuite/ai/peek-view/chat-block-peek-view.ts @@ -372,7 +372,7 @@ export class AIChatBlockPeekView extends LitElement { const last = messages[messages.length - 1]; if ('content' in last) { last.content = ''; - last.id = ''; + last.streamObjects = []; last.createdAt = new Date().toISOString(); } this.updateContext({