Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vscode-dts/vscode.proposed.chatSessionsProvider.d.ts
5270 views
1
/*---------------------------------------------------------------------------------------------
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
// version: 3
7
8
declare module 'vscode' {
9
/**
10
* Represents the status of a chat session.
11
*/
12
export enum ChatSessionStatus {
13
/**
14
* The chat session failed to complete.
15
*/
16
Failed = 0,
17
18
/**
19
* The chat session completed successfully.
20
*/
21
Completed = 1,
22
23
/**
24
* The chat session is currently in progress.
25
*/
26
InProgress = 2,
27
28
/**
29
* The chat session needs user input (e.g. an unresolved confirmation).
30
*/
31
NeedsInput = 3
32
}
33
34
export namespace chat {
35
/**
36
* Registers a new {@link ChatSessionItemProvider chat session item provider}.
37
*
38
* To use this, also make sure to also add `chatSessions` contribution in the `package.json`.
39
*
40
* @param chatSessionType The type of chat session the provider is for.
41
* @param provider The provider to register.
42
*
43
* @returns A disposable that unregisters the provider when disposed.
44
*/
45
export function registerChatSessionItemProvider(chatSessionType: string, provider: ChatSessionItemProvider): Disposable;
46
47
/**
48
* Creates a new {@link ChatSessionItemController chat session item controller} with the given unique identifier.
49
*/
50
export function createChatSessionItemController(id: string, refreshHandler: (token: CancellationToken) => Thenable<void>): ChatSessionItemController;
51
}
52
53
/**
54
* Provides a list of information about chat sessions.
55
*/
56
export interface ChatSessionItemProvider {
57
/**
58
* Event that the provider can fire to signal that chat sessions have changed.
59
*/
60
readonly onDidChangeChatSessionItems: Event<void>;
61
62
/**
63
* Provides a list of chat sessions.
64
*/
65
// TODO: Do we need a flag to try auth if needed?
66
provideChatSessionItems(token: CancellationToken): ProviderResult<ChatSessionItem[]>;
67
68
// #region Unstable parts of API
69
70
/**
71
* Event that the provider can fire to signal that the current (original) chat session should be replaced with a new (modified) chat session.
72
* The UI can use this information to gracefully migrate the user to the new session.
73
*/
74
readonly onDidCommitChatSessionItem: Event<{ original: ChatSessionItem /** untitled */; modified: ChatSessionItem /** newly created */ }>;
75
76
// #endregion
77
}
78
79
/**
80
* Provides a list of information about chat sessions.
81
*/
82
export interface ChatSessionItemController {
83
readonly id: string;
84
85
/**
86
* Unregisters the controller, disposing of its associated chat session items.
87
*/
88
dispose(): void;
89
90
/**
91
* Managed collection of chat session items
92
*/
93
readonly items: ChatSessionItemCollection;
94
95
/**
96
* Creates a new managed chat session item that be added to the collection.
97
*/
98
createChatSessionItem(resource: Uri, label: string): ChatSessionItem;
99
100
/**
101
* Handler called to refresh the collection of chat session items.
102
*
103
* This is also called on first load to get the initial set of items.
104
*/
105
refreshHandler: (token: CancellationToken) => Thenable<void>;
106
107
/**
108
* Fired when an item's archived state changes.
109
*/
110
readonly onDidChangeChatSessionItemState: Event<ChatSessionItem>;
111
}
112
113
/**
114
* A collection of chat session items. It provides operations for managing and iterating over the items.
115
*/
116
export interface ChatSessionItemCollection extends Iterable<readonly [id: Uri, chatSessionItem: ChatSessionItem]> {
117
/**
118
* Gets the number of items in the collection.
119
*/
120
readonly size: number;
121
122
/**
123
* Replaces the items stored by the collection.
124
* @param items Items to store.
125
*/
126
replace(items: readonly ChatSessionItem[]): void;
127
128
/**
129
* Iterate over each entry in this collection.
130
*
131
* @param callback Function to execute for each entry.
132
* @param thisArg The `this` context used when invoking the handler function.
133
*/
134
forEach(callback: (item: ChatSessionItem, collection: ChatSessionItemCollection) => unknown, thisArg?: any): void;
135
136
/**
137
* Adds the chat session item to the collection. If an item with the same resource URI already
138
* exists, it'll be replaced.
139
* @param item Item to add.
140
*/
141
add(item: ChatSessionItem): void;
142
143
/**
144
* Removes a single chat session item from the collection.
145
* @param resource Item resource to delete.
146
*/
147
delete(resource: Uri): void;
148
149
/**
150
* Efficiently gets a chat session item by resource, if it exists, in the collection.
151
* @param resource Item resource to get.
152
* @returns The found item or undefined if it does not exist.
153
*/
154
get(resource: Uri): ChatSessionItem | undefined;
155
}
156
157
export interface ChatSessionItem {
158
/**
159
* The resource associated with the chat session.
160
*
161
* This is uniquely identifies the chat session and is used to open the chat session.
162
*/
163
resource: Uri;
164
165
/**
166
* Human readable name of the session shown in the UI
167
*/
168
label: string;
169
170
/**
171
* An icon for the participant shown in UI.
172
*/
173
iconPath?: IconPath;
174
175
/**
176
* An optional description that provides additional context about the chat session.
177
*/
178
description?: string | MarkdownString;
179
180
/**
181
* An optional badge that provides additional context about the chat session.
182
*/
183
badge?: string | MarkdownString;
184
185
/**
186
* An optional status indicating the current state of the session.
187
*/
188
status?: ChatSessionStatus;
189
190
/**
191
* The tooltip text when you hover over this item.
192
*/
193
tooltip?: string | MarkdownString;
194
195
/**
196
* Whether the chat session has been archived.
197
*/
198
archived?: boolean;
199
200
/**
201
* Timing information for the chat session
202
*/
203
timing?: {
204
/**
205
* Timestamp when the session was created in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
206
*/
207
created: number;
208
209
/**
210
* Timestamp when the most recent request started in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
211
*
212
* Should be undefined if no requests have been made yet.
213
*/
214
lastRequestStarted?: number;
215
216
/**
217
* Timestamp when the most recent request completed in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
218
*
219
* Should be undefined if the most recent request is still in progress or if no requests have been made yet.
220
*/
221
lastRequestEnded?: number;
222
223
/**
224
* Session start timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
225
* @deprecated Use `created` and `lastRequestStarted` instead.
226
*/
227
startTime?: number;
228
229
/**
230
* Session end timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
231
* @deprecated Use `lastRequestEnded` instead.
232
*/
233
endTime?: number;
234
};
235
236
/**
237
* Statistics about the chat session.
238
*/
239
changes?: readonly ChatSessionChangedFile[] | readonly ChatSessionChangedFile2[];
240
241
/**
242
* Arbitrary metadata for the chat session. Can be anything, but must be JSON-stringifyable.
243
*
244
* To update the metadata you must re-set this property.
245
*/
246
metadata?: { readonly [key: string]: any };
247
}
248
249
export class ChatSessionChangedFile {
250
/**
251
* URI of the file.
252
*/
253
modifiedUri: Uri;
254
255
/**
256
* File opened when the user takes the 'compare' action.
257
*/
258
originalUri?: Uri;
259
260
/**
261
* Number of insertions made during the session.
262
*/
263
insertions: number;
264
265
/**
266
* Number of deletions made during the session.
267
*/
268
deletions: number;
269
270
constructor(modifiedUri: Uri, insertions: number, deletions: number, originalUri?: Uri);
271
}
272
273
export class ChatSessionChangedFile2 {
274
/**
275
* URI of the file.
276
*/
277
readonly uri: Uri;
278
279
/**
280
* URI of the original file. Undefined if the file was created.
281
*/
282
readonly originalUri: Uri | undefined;
283
284
/**
285
* URI of the modified file. Undefined if the file was deleted.
286
*/
287
readonly modifiedUri: Uri | undefined;
288
289
/**
290
* Number of insertions made during the session.
291
*/
292
insertions: number;
293
294
/**
295
* Number of deletions made during the session.
296
*/
297
deletions: number;
298
299
constructor(uri: Uri, originalUri: Uri | undefined, modifiedUri: Uri | undefined, insertions: number, deletions: number);
300
}
301
302
export interface ChatSession {
303
/**
304
* The full history of the session
305
*
306
* This should not include any currently active responses
307
*/
308
// TODO: Are these the right types to use?
309
// TODO: link request + response to encourage correct usage?
310
readonly history: ReadonlyArray<ChatRequestTurn | ChatResponseTurn2>;
311
312
/**
313
* Options configured for this session as key-value pairs.
314
* Keys correspond to option group IDs (e.g., 'models', 'subagents').
315
* Values can be either:
316
* - A string (the option item ID) for backwards compatibility
317
* - A ChatSessionProviderOptionItem object to include metadata like locked state
318
* TODO: Strongly type the keys
319
*/
320
readonly options?: Record<string, string | ChatSessionProviderOptionItem>;
321
322
/**
323
* Callback invoked by the editor for a currently running response. This allows the session to push items for the
324
* current response and stream these in as them come in. The current response will be considered complete once the
325
* callback resolved.
326
*
327
* If not provided, the chat session is assumed to not currently be running.
328
*/
329
readonly activeResponseCallback?: (stream: ChatResponseStream, token: CancellationToken) => Thenable<void>;
330
331
/**
332
* Handles new request for the session.
333
*
334
* If not set, then the session will be considered read-only and no requests can be made.
335
*/
336
// TODO: Should we introduce our own type for `ChatRequestHandler` since not all field apply to chat sessions?
337
// TODO: Revisit this to align with code.
338
readonly requestHandler: ChatRequestHandler | undefined;
339
}
340
341
/**
342
* Event fired when chat session options change.
343
*/
344
export interface ChatSessionOptionChangeEvent {
345
/**
346
* Identifier of the chat session being updated.
347
*/
348
readonly resource: Uri;
349
/**
350
* Collection of option identifiers and their new values. Only the options that changed are included.
351
*/
352
readonly updates: ReadonlyArray<{
353
/**
354
* Identifier of the option that changed (for example `model`).
355
*/
356
readonly optionId: string;
357
358
/**
359
* The new value assigned to the option. When `undefined`, the option is cleared.
360
*/
361
readonly value: string | ChatSessionProviderOptionItem;
362
}>;
363
}
364
365
/**
366
* Provides the content for a chat session rendered using the native chat UI.
367
*/
368
export interface ChatSessionContentProvider {
369
/**
370
* Event that the provider can fire to signal that the options for a chat session have changed.
371
*/
372
readonly onDidChangeChatSessionOptions?: Event<ChatSessionOptionChangeEvent>;
373
374
/**
375
* Event that the provider can fire to signal that the available provider options have changed.
376
*
377
* When fired, the editor will re-query {@link ChatSessionContentProvider.provideChatSessionProviderOptions}
378
* and update the UI to reflect the new option groups.
379
*/
380
readonly onDidChangeChatSessionProviderOptions?: Event<void>;
381
382
/**
383
* Provides the chat session content for a given uri.
384
*
385
* The returned {@linkcode ChatSession} is used to populate the history of the chat UI.
386
*
387
* @param resource The URI of the chat session to resolve.
388
* @param token A cancellation token that can be used to cancel the operation.
389
*
390
* @return The {@link ChatSession chat session} associated with the given URI.
391
*/
392
provideChatSessionContent(resource: Uri, token: CancellationToken): Thenable<ChatSession> | ChatSession;
393
394
/**
395
* @param resource Identifier of the chat session being updated.
396
* @param updates Collection of option identifiers and their new values. Only the options that changed are included.
397
* @param token A cancellation token that can be used to cancel the notification if the session is disposed.
398
*/
399
provideHandleOptionsChange?(resource: Uri, updates: ReadonlyArray<ChatSessionOptionUpdate>, token: CancellationToken): void;
400
401
/**
402
* Called as soon as you register (call me once)
403
* @param token
404
*/
405
provideChatSessionProviderOptions?(token: CancellationToken): Thenable<ChatSessionProviderOptions | ChatSessionProviderOptions>;
406
}
407
408
export interface ChatSessionOptionUpdate {
409
/**
410
* Identifier of the option that changed (for example `model`).
411
*/
412
readonly optionId: string;
413
414
/**
415
* The new value assigned to the option. When `undefined`, the option is cleared.
416
*/
417
readonly value: string | undefined;
418
}
419
420
export namespace chat {
421
/**
422
* Registers a new {@link ChatSessionContentProvider chat session content provider}.
423
*
424
* @param scheme The uri-scheme to register for. This must be unique.
425
* @param provider The provider to register.
426
*
427
* @returns A disposable that unregisters the provider when disposed.
428
*/
429
export function registerChatSessionContentProvider(scheme: string, provider: ChatSessionContentProvider, chatParticipant: ChatParticipant, capabilities?: ChatSessionCapabilities): Disposable;
430
}
431
432
export interface ChatContext {
433
readonly chatSessionContext?: ChatSessionContext;
434
}
435
436
export interface ChatSessionContext {
437
readonly chatSessionItem: ChatSessionItem; // Maps to URI of chat session editor (could be 'untitled-1', etc..)
438
readonly isUntitled: boolean;
439
}
440
441
export interface ChatSessionCapabilities {
442
/**
443
* Whether sessions can be interrupted and resumed without side-effects.
444
*/
445
supportsInterruptions?: boolean;
446
}
447
448
/**
449
* Represents a single selectable item within a provider option group.
450
*/
451
export interface ChatSessionProviderOptionItem {
452
/**
453
* Unique identifier for the option item.
454
*/
455
readonly id: string;
456
457
/**
458
* Human-readable name displayed in the UI.
459
*/
460
readonly name: string;
461
462
/**
463
* Optional description shown in tooltips.
464
*/
465
readonly description?: string;
466
467
/**
468
* When true, this option is locked and cannot be changed by the user.
469
* The option will still be visible in the UI but will be disabled.
470
* Use this when an option is set but cannot be hot-swapped (e.g., model already initialized).
471
*/
472
readonly locked?: boolean;
473
474
/**
475
* An icon for the option item shown in UI.
476
*/
477
readonly icon?: ThemeIcon;
478
479
/**
480
* Indicates if this option should be selected by default.
481
* Only one item per option group should be marked as default.
482
*/
483
readonly default?: boolean;
484
}
485
486
/**
487
* Represents a group of related provider options (e.g., models, sub-agents).
488
*/
489
export interface ChatSessionProviderOptionGroup {
490
/**
491
* Unique identifier for the option group (e.g., "models", "subagents").
492
*/
493
readonly id: string;
494
495
/**
496
* Human-readable name for the option group.
497
*/
498
readonly name: string;
499
500
/**
501
* Optional description providing context about this option group.
502
*/
503
readonly description?: string;
504
505
/**
506
* The selectable items within this option group.
507
*/
508
readonly items: ChatSessionProviderOptionItem[];
509
510
/**
511
* A context key expression that controls when this option group picker is visible.
512
* When specified, the picker is only shown when the expression evaluates to true.
513
* The expression can reference other option group values via `chatSessionOption.<groupId>`.
514
*
515
* Example: `"chatSessionOption.models == 'gpt-4'"` - only show this picker when
516
* the 'models' option group has 'gpt-4' selected.
517
*/
518
readonly when?: string;
519
520
/**
521
* When true, displays a searchable QuickPick with a "See more..." option.
522
* Recommended for option groups with additional async items (e.g., repositories).
523
*/
524
readonly searchable?: boolean;
525
526
/**
527
* An icon for the option group shown in UI.
528
*/
529
readonly icon?: ThemeIcon;
530
531
/**
532
* Handler for dynamic search when `searchable` is true.
533
* Called when the user types in the searchable QuickPick or clicks "See more..." to load additional items.
534
*
535
* @param query The search query entered by the user. Empty string for initial load.
536
* @param token A cancellation token.
537
* @returns Additional items to display in the searchable QuickPick.
538
*/
539
readonly onSearch?: (query: string, token: CancellationToken) => Thenable<ChatSessionProviderOptionItem[]>;
540
541
/**
542
* Optional commands.
543
*
544
* These commands will be displayed at the bottom of the group.
545
*/
546
readonly commands?: Command[];
547
}
548
549
export interface ChatSessionProviderOptions {
550
/**
551
* Provider-defined option groups (0-2 groups supported).
552
* Examples: models picker, sub-agents picker, etc.
553
*/
554
optionGroups?: ChatSessionProviderOptionGroup[];
555
}
556
}
557
558