chatWidgetHistoryService.ts ×18

Frontier kind: Code frontier

unlabeled · c_68c320976aa6

24 tests · 26194 LOC · 139 files · introduces 0 tests · 174 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges174 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
3005 ranges26194 lines · 139 files · Browse complete extent
All tests (intent)
24 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 174 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/common/widget/chatWidgetHistoryService.ts 134 introduced LOC · 18 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- chatWidgetHistoryService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { equals as arraysEqual } from '../../../../../base/common/arrays.js';
7 > import { Emitter, Event } from '../../../../../base/common/event.js';
8 > import { Disposable } from '../../../../../base/common/lifecycle.js';
9 > import { createDecorator } from '../../../../../platform/instantiation/common/instantiation.js';
10 > import { IStorageService, StorageScope, StorageTarget } from '../../../../../platform/storage/common/storage.js';
11 > import { Memento } from '../../../../common/memento.js';
12 > import { IChatModelInputState } from '../model/chatModel.js';
13 > import { CHAT_PROVIDER_ID } from '../participants/chatParticipantContribTypes.js';
14 > import { IChatRequestVariableEntry } from '../attachments/chatVariableEntries.js';
15 > import { ChatAgentLocation, ChatModeKind } from '../constants.js';
16 >
17 > interface IChatHistoryEntry {
18 > text: string;
19 > state?: IChatInputState;
20 > }
21 >
22 > /** The collected input state for chat history entries */
23 > interface IChatInputState {
24 > // eslint-disable-next-line @typescript-eslint/no-explicit-any
25 > [key: string]: any;
26 > chatContextAttachments?: ReadonlyArray<IChatRequestVariableEntry>;
27 >
28 > /**
29 > * This should be a mode id (ChatMode | string).
30 > * { id: string } is the old IChatMode. This is deprecated but may still be in persisted data.
31 > */
32 > chatMode?: ChatModeKind | string | { id: string };
33 > }
34 >
35 > export const IChatWidgetHistoryService = createDecorator<IChatWidgetHistoryService>('IChatWidgetHistoryService');
36 > export interface IChatWidgetHistoryService {
37 > _serviceBrand: undefined;
38 >
39 > readonly onDidChangeHistory: Event<ChatHistoryChange>;
40 >
41 > clearHistory(): void;
42 > getHistory(location: ChatAgentLocation, historyKey?: string): readonly IChatModelInputState[];
43 > append(location: ChatAgentLocation, history: IChatModelInputState, historyKey?: string): void;
44 > moveHistory(location: ChatAgentLocation, fromHistoryKey: string, toHistoryKey: string): void;
45 > }
46 >
47 > interface IChatHistory {
48 > history?: { [providerId: string]: IChatModelInputState[] };
49 > }
50 >
51 > export type ChatHistoryChange = { kind: 'append'; location: ChatAgentLocation; historyKey: string | undefined; entry: IChatModelInputState } | { kind: 'move'; location: ChatAgentLocation; fromHistoryKey: string; toHistoryKey: string } | { kind: 'clear' };
52 >
53 > export const ChatInputHistoryMaxEntries = 40;
54 >
55 > export class ChatWidgetHistoryService extends Disposable implements IChatWidgetHistoryService {
56 > _serviceBrand: undefined;
57 >
58 > private memento: Memento<IChatHistory>;
59 > private viewState: IChatHistory;
60 >
61 > private readonly _onDidChangeHistory = this._register(new Emitter<ChatHistoryChange>());
62 > private changed = false;
63 > readonly onDidChangeHistory = this._onDidChangeHistory.event;
64 >
65 > constructor(
66 > @IStorageService storageService: IStorageService
67 > ) {
68 > super();
69 >
70 > this.memento = new Memento<IChatHistory>('interactive-session', storageService);
71 > const loadedState = this.memento.getMemento(StorageScope.WORKSPACE, StorageTarget.MACHINE);
72 > this.viewState = loadedState;
73 >
74 > this._register(storageService.onWillSaveState(() => {
75 if (this.changed) {
76 this.memento.saveMemento();
77 this.changed = false;
78 }
80 > }
81 >
82 > getHistory(location: ChatAgentLocation, historyKey?: string): IChatModelInputState[] {
83 const key = this.getKey(location, historyKey);
84 const history = this.viewState.history?.[key] ?? [];
85 return history.map(entry => this.migrateHistoryEntry(entry));
86 }
88 > // eslint-disable-next-line @typescript-eslint/no-explicit-any
89 > private migrateHistoryEntry(entry: any): IChatModelInputState {
90 // If it's already in the new format (has 'inputText' property), return as-is
91 if (entry.inputText !== undefined) {
134 };
135 }
137 > private getKey(location: ChatAgentLocation, historyKey?: string): string {
138 // Preserve history for panel by continuing to use the same old provider id. Use the location as a key for other chat locations.
139 const locationKey = location === ChatAgentLocation.Chat ? CHAT_PROVIDER_ID : location;
140 return historyKey === undefined ? locationKey : `${locationKey}:${historyKey}`;
141 }
143 > append(location: ChatAgentLocation, history: IChatModelInputState, historyKey?: string): void {
144 this.viewState.history ??= {};
145
149 this._onDidChangeHistory.fire({ kind: 'append', location, historyKey, entry: history });
150 }
152 > moveHistory(location: ChatAgentLocation, fromHistoryKey: string, toHistoryKey: string): void {
153 if (fromHistoryKey === toHistoryKey) {
154 return;
169 this._onDidChangeHistory.fire({ kind: 'move', location, fromHistoryKey, toHistoryKey });
170 }
172 > clearHistory(): void {
173 this.viewState.history = {};
174 this.changed = true;
175 this._onDidChangeHistory.fire({ kind: 'clear' });
176 }
178 >
179 > export class ChatHistoryNavigator extends Disposable {
180 > /**
181 > * Index of our point in history. Goes 1 past the length of `_history`
182 > */
183 > private _currentIndex: number;
184 > private _history: readonly IChatModelInputState[];
185 > private _overlay: (IChatModelInputState | undefined)[] = [];
186 > private _historyKey: string | undefined;
187 >
188 > public get values() {
189 > return this.chatWidgetHistoryService.getHistory(this.location, this._historyKey);
190 > }
191 >
192 > constructor(
193 private readonly location: ChatAgentLocation,
194 @IChatWidgetHistoryService private readonly chatWidgetHistoryService: IChatWidgetHistoryService
231 }));
232 }
234 > public setHistoryKey(historyKey: string | undefined) {
235 if (this._historyKey === historyKey) {
236 return;
242 this._overlay = [];
243 }
245 > public isAtEnd() {
246 return this._currentIndex === Math.max(this._history.length, this._overlay.length);
247 }
249 > public isAtStart() {
250 return this._currentIndex === 0;
251 }
253 > /**
254 > * Replaces a history entry at the current index in this view of the history.
255 > * Allows editing of old history entries while preventing accidental navigation
256 > * from losing the edits.
257 > */
258 > public overlay(entry: IChatModelInputState) {
259 this._overlay[this._currentIndex] = entry;
260 }
262 > public resetCursor() {
263 this._currentIndex = this._history.length;
264 }
266 > public previous() {
267 this._currentIndex = Math.max(this._currentIndex - 1, 0);
268 return this.current();
269 }
271 > public next() {
272 this._currentIndex = Math.min(this._currentIndex + 1, this._history.length);
273 return this.current();
274 }
276 > public current() {
277 return this._overlay[this._currentIndex] ?? this._history[this._currentIndex];
278 }
280 > /**
281 > * Appends a new entry to the navigator. Resets the state back to the end
282 > * and clears any overlayed entries.
283 > */
284 > public append(entry: IChatModelInputState) {
285 this._overlay = [];
286 this._currentIndex = this._history.length;
290 }
291 }
293 >
294 function entriesEqual(a: IChatModelInputState | undefined, b: IChatModelInputState | undefined): boolean {
295 if (!a || !b) {
src/vs/workbench/contrib/chat/common/participants/chatParticipantContribTypes.ts 40 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- chatParticipantContribTypes.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { ChatModeKind, RawChatParticipantLocation } from '../constants.js';
7 >
8 > export interface IRawChatCommandContribution {
9 > name: string;
10 > description: string;
11 > sampleRequest?: string;
12 > isSticky?: boolean;
13 > when?: string;
14 > disambiguation?: { category: string; categoryName?: string /** Deprecated */; description: string; examples: string[] }[];
15 > }
16 >
17 > export interface IRawChatParticipantContribution {
18 > id: string;
19 > name: string;
20 > fullName: string;
21 > when?: string;
22 > description?: string;
23 > isDefault?: boolean;
24 > isSticky?: boolean;
25 > sampleRequest?: string;
26 > commands?: IRawChatCommandContribution[];
27 > locations?: RawChatParticipantLocation[];
28 > /**
29 > * Valid for default participants in 'panel' location
30 > */
31 > modes?: ChatModeKind[];
32 > disambiguation?: { category: string; categoryName?: string /** Deprecated */; description: string; examples: string[] }[];
33 > }
34 >
35 > /**
36 > * Hardcoding the previous id of the Copilot Chat provider to avoid breaking view locations, persisted data, etc.
37 > * DON'T use this for any new data, only for old persisted data.
38 > * @deprecated
39 > */
40 > export const CHAT_PROVIDER_ID = 'copilot';