From dac52c9521cb06b89d5f7d1dcdd5277d486011dd Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Mon, 20 Jan 2025 21:32:06 -0800 Subject: [PATCH] Small fix to saving chat history (#238327) Trim it before saving, not after, and make it a bit smaller just because --- src/vs/workbench/contrib/chat/browser/chatInputPart.ts | 4 ++-- .../workbench/contrib/chat/common/chatWidgetHistoryService.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/chatInputPart.ts b/src/vs/workbench/contrib/chat/browser/chatInputPart.ts index 932c62a3c4e56..1cefed6c759cd 100644 --- a/src/vs/workbench/contrib/chat/browser/chatInputPart.ts +++ b/src/vs/workbench/contrib/chat/browser/chatInputPart.ts @@ -87,7 +87,7 @@ import { ChatRequestDynamicVariablePart } from '../common/chatParserTypes.js'; import { IChatFollowup } from '../common/chatService.js'; import { IChatVariablesService } from '../common/chatVariables.js'; import { IChatResponseViewModel } from '../common/chatViewModel.js'; -import { IChatHistoryEntry, IChatInputState, IChatWidgetHistoryService } from '../common/chatWidgetHistoryService.js'; +import { ChatInputHistoryMaxEntries, IChatHistoryEntry, IChatInputState, IChatWidgetHistoryService } from '../common/chatWidgetHistoryService.js'; import { ILanguageModelChatMetadata, ILanguageModelsService } from '../common/languageModels.js'; import { CancelAction, ChatModelPickerActionId, ChatSubmitAction, ChatSubmitSecondaryAgentAction, IChatExecuteActionContext } from './actions/chatExecuteActions.js'; import { ImplicitContextAttachmentWidget } from './attachments/implicitContextAttachment.js'; @@ -392,7 +392,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge this.promptInstructionsAttached = ChatContextKeys.instructionsAttached.bindTo(contextKeyService); this.history = this.loadHistory(); - this._register(this.historyService.onDidClearHistory(() => this.history = new HistoryNavigator2([{ text: '' }], 50, historyKeyFn))); + this._register(this.historyService.onDidClearHistory(() => this.history = new HistoryNavigator2([{ text: '' }], ChatInputHistoryMaxEntries, historyKeyFn))); this._register(this.configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration(AccessibilityVerbositySettingId.Chat)) { diff --git a/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts b/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts index 2ea99b4bcfacf..d2ab31d58ce3e 100644 --- a/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts +++ b/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts @@ -40,6 +40,8 @@ interface IChatHistory { history: { [providerId: string]: IChatHistoryEntry[] }; } +export const ChatInputHistoryMaxEntries = 40; + export class ChatWidgetHistoryService implements IChatWidgetHistoryService { _serviceBrand: undefined; @@ -78,7 +80,7 @@ export class ChatWidgetHistoryService implements IChatWidgetHistoryService { } const key = this.getKey(location); - this.viewState.history[key] = history; + this.viewState.history[key] = history.slice(-ChatInputHistoryMaxEntries); this.memento.saveMemento(); }