From e1e1b29afbb30cad31d12ef478c2f6e62f62136e Mon Sep 17 00:00:00 2001 From: donteatfriedrice Date: Wed, 31 Jul 2024 04:14:06 +0000 Subject: [PATCH] fix: cannot clean chat panel histories (#7673) --- .../core/src/blocksuite/presets/ai/chat-panel/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts index 8f92e279b..b18bf3932 100644 --- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts +++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts @@ -97,8 +97,6 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) { private readonly _chatMessages: Ref = createRef(); - private _chatSessionId = ''; - private _resettingCounter = 0; private readonly _resetItems = debounce(() => { @@ -119,7 +117,6 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) { if (histories?.at(-1)) { const history = histories.at(-1); if (!history) return; - this._chatSessionId = history.sessionId; this.chatContextValue.chatSessionId = history.sessionId; items.push(...history.messages); AIProvider.LAST_ROOT_SESSION_ID = history.sessionId; @@ -175,13 +172,14 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) { }) ) { await AIProvider.histories?.cleanup(this.doc.collection.id, this.doc.id, [ - this._chatSessionId, + this.chatContextValue.chatSessionId ?? '', ...( this.chatContextValue.items.filter( item => 'sessionId' in item ) as ChatAction[] ).map(item => item.sessionId), ]); + this.chatContextValue.chatSessionId = null; notification.toast('History cleared'); this._resetItems(); }