Skip to content

Commit

Permalink
Small fix to saving chat history (#238327)
Browse files Browse the repository at this point in the history
Trim it before saving, not after, and make it a bit smaller just because
  • Loading branch information
roblourens authored Jan 21, 2025
1 parent 3f5e781 commit dac52c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/chat/browser/chatInputPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ interface IChatHistory {
history: { [providerId: string]: IChatHistoryEntry[] };
}

export const ChatInputHistoryMaxEntries = 40;

export class ChatWidgetHistoryService implements IChatWidgetHistoryService {
_serviceBrand: undefined;

Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit dac52c9

Please sign in to comment.