Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vscode-dts/vscode.proposed.chatParticipantAdditions.d.ts
3290 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
declare module 'vscode' {
7
8
export interface ChatParticipant {
9
onDidPerformAction: Event<ChatUserActionEvent>;
10
}
11
12
/**
13
* Now only used for the "intent detection" API below
14
*/
15
export interface ChatCommand {
16
readonly name: string;
17
readonly description: string;
18
}
19
20
export interface ChatVulnerability {
21
title: string;
22
description: string;
23
// id: string; // Later we will need to be able to link these across multiple content chunks.
24
}
25
26
export class ChatResponseMarkdownWithVulnerabilitiesPart {
27
value: MarkdownString;
28
vulnerabilities: ChatVulnerability[];
29
constructor(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]);
30
}
31
32
export class ChatResponseCodeblockUriPart {
33
isEdit?: boolean;
34
value: Uri;
35
constructor(value: Uri, isEdit?: boolean);
36
}
37
38
/**
39
* Displays a {@link Command command} as a button in the chat response.
40
*/
41
export interface ChatCommandButton {
42
command: Command;
43
}
44
45
export interface ChatDocumentContext {
46
uri: Uri;
47
version: number;
48
ranges: Range[];
49
}
50
51
export class ChatResponseTextEditPart {
52
uri: Uri;
53
edits: TextEdit[];
54
isDone?: boolean;
55
constructor(uri: Uri, done: true);
56
constructor(uri: Uri, edits: TextEdit | TextEdit[]);
57
}
58
59
export class ChatResponseNotebookEditPart {
60
uri: Uri;
61
edits: NotebookEdit[];
62
isDone?: boolean;
63
constructor(uri: Uri, done: true);
64
constructor(uri: Uri, edits: NotebookEdit | NotebookEdit[]);
65
}
66
67
export class ChatResponseConfirmationPart {
68
title: string;
69
message: string | MarkdownString;
70
data: any;
71
buttons?: string[];
72
constructor(title: string, message: string | MarkdownString, data: any, buttons?: string[]);
73
}
74
75
export class ChatResponseCodeCitationPart {
76
value: Uri;
77
license: string;
78
snippet: string;
79
constructor(value: Uri, license: string, snippet: string);
80
}
81
82
export class ChatPrepareToolInvocationPart {
83
toolName: string;
84
constructor(toolName: string);
85
}
86
87
export interface ChatTerminalToolInvocationData {
88
commandLine: {
89
original: string;
90
userEdited?: string;
91
toolEdited?: string;
92
};
93
language: string;
94
}
95
96
export class ChatToolInvocationPart {
97
toolName: string;
98
toolCallId: string;
99
isError?: boolean;
100
invocationMessage?: string | MarkdownString;
101
originMessage?: string | MarkdownString;
102
pastTenseMessage?: string | MarkdownString;
103
isConfirmed?: boolean;
104
isComplete?: boolean;
105
toolSpecificData?: ChatTerminalToolInvocationData;
106
107
constructor(toolName: string, toolCallId: string, isError?: boolean);
108
}
109
110
/**
111
* Represents a single file diff entry in a multi diff view.
112
*/
113
export interface ChatResponseDiffEntry {
114
/**
115
* The original file URI (undefined for new files).
116
*/
117
originalUri?: Uri;
118
119
/**
120
* The modified file URI (undefined for deleted files).
121
*/
122
modifiedUri?: Uri;
123
124
/**
125
* Optional URI to navigate to when clicking on the file.
126
*/
127
goToFileUri?: Uri;
128
129
/**
130
* Added data (e.g. line numbers) to show in the UI
131
*/
132
added?: number;
133
134
/**
135
* Removed data (e.g. line numbers) to show in the UI
136
*/
137
removed?: number;
138
}
139
140
/**
141
* Represents a part of a chat response that shows multiple file diffs.
142
*/
143
export class ChatResponseMultiDiffPart {
144
/**
145
* Array of file diff entries to display.
146
*/
147
value: ChatResponseDiffEntry[];
148
149
/**
150
* The title for the multi diff editor.
151
*/
152
title: string;
153
154
/**
155
* Create a new ChatResponseMultiDiffPart.
156
* @param value Array of file diff entries.
157
* @param title The title for the multi diff editor.
158
*/
159
constructor(value: ChatResponseDiffEntry[], title: string);
160
}
161
162
export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseNotebookEditPart | ChatResponseConfirmationPart | ChatResponseCodeCitationPart | ChatResponseReferencePart2 | ChatResponseMovePart | ChatResponseExtensionsPart | ChatResponsePullRequestPart | ChatPrepareToolInvocationPart | ChatToolInvocationPart | ChatResponseMultiDiffPart | ChatResponseThinkingProgressPart;
163
export class ChatResponseWarningPart {
164
value: MarkdownString;
165
constructor(value: string | MarkdownString);
166
}
167
168
export class ChatResponseProgressPart2 extends ChatResponseProgressPart {
169
value: string;
170
task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>;
171
constructor(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>);
172
}
173
174
/**
175
* A specialized progress part for displaying thinking/reasoning steps.
176
*/
177
export class ChatResponseThinkingProgressPart {
178
value: string | string[];
179
id?: string;
180
metadata?: { readonly [key: string]: any };
181
task?: (progress: Progress<LanguageModelThinkingPart>) => Thenable<string | void>;
182
183
/**
184
* Creates a new thinking progress part.
185
* @param value An initial progress message
186
* @param task A task that will emit thinking parts during its execution
187
*/
188
constructor(value: string | string[], id?: string, metadata?: { readonly [key: string]: any }, task?: (progress: Progress<LanguageModelThinkingPart>) => Thenable<string | void>);
189
}
190
191
export class ChatResponseReferencePart2 {
192
/**
193
* The reference target.
194
*/
195
value: Uri | Location | { variableName: string; value?: Uri | Location } | string;
196
197
/**
198
* The icon for the reference.
199
*/
200
iconPath?: Uri | ThemeIcon | {
201
/**
202
* The icon path for the light theme.
203
*/
204
light: Uri;
205
/**
206
* The icon path for the dark theme.
207
*/
208
dark: Uri;
209
};
210
options?: { status?: { description: string; kind: ChatResponseReferencePartStatusKind } };
211
212
/**
213
* Create a new ChatResponseReferencePart.
214
* @param value A uri or location
215
* @param iconPath Icon for the reference shown in UI
216
*/
217
constructor(value: Uri | Location | { variableName: string; value?: Uri | Location } | string, iconPath?: Uri | ThemeIcon | {
218
/**
219
* The icon path for the light theme.
220
*/
221
light: Uri;
222
/**
223
* The icon path for the dark theme.
224
*/
225
dark: Uri;
226
}, options?: { status?: { description: string; kind: ChatResponseReferencePartStatusKind } });
227
}
228
229
export class ChatResponseMovePart {
230
231
readonly uri: Uri;
232
readonly range: Range;
233
234
constructor(uri: Uri, range: Range);
235
}
236
237
export interface ChatResponseAnchorPart {
238
/**
239
* The target of this anchor.
240
*
241
* If this is a {@linkcode Uri} or {@linkcode Location}, this is rendered as a normal link.
242
*
243
* If this is a {@linkcode SymbolInformation}, this is rendered as a symbol link.
244
*
245
* TODO mjbvz: Should this be a full `SymbolInformation`? Or just the parts we need?
246
* TODO mjbvz: Should we allow a `SymbolInformation` without a location? For example, until `resolve` completes?
247
*/
248
value2: Uri | Location | SymbolInformation;
249
250
/**
251
* Optional method which fills in the details of the anchor.
252
*
253
* THis is currently only implemented for symbol links.
254
*/
255
resolve?(token: CancellationToken): Thenable<void>;
256
}
257
258
export class ChatResponseExtensionsPart {
259
260
readonly extensions: string[];
261
262
constructor(extensions: string[]);
263
}
264
265
export class ChatResponsePullRequestPart {
266
readonly uri: Uri;
267
readonly linkTag: string;
268
readonly title: string;
269
readonly description: string;
270
readonly author: string;
271
constructor(uri: Uri, title: string, description: string, author: string, linkTag: string);
272
}
273
274
export interface ChatResponseStream {
275
276
/**
277
* Push a progress part to this stream. Short-hand for
278
* `push(new ChatResponseProgressPart(value))`.
279
*
280
* @param value A progress message
281
* @param task If provided, a task to run while the progress is displayed. When the Thenable resolves, the progress will be marked complete in the UI, and the progress message will be updated to the resolved string if one is specified.
282
* @returns This stream.
283
*/
284
progress(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>): void;
285
286
thinkingProgress(thinkingDelta: ThinkingDelta): void;
287
288
textEdit(target: Uri, edits: TextEdit | TextEdit[]): void;
289
290
textEdit(target: Uri, isDone: true): void;
291
292
notebookEdit(target: Uri, edits: NotebookEdit | NotebookEdit[]): void;
293
294
notebookEdit(target: Uri, isDone: true): void;
295
296
markdownWithVulnerabilities(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]): void;
297
codeblockUri(uri: Uri, isEdit?: boolean): void;
298
push(part: ChatResponsePart | ChatResponseTextEditPart | ChatResponseWarningPart | ChatResponseProgressPart2): void;
299
300
/**
301
* Show an inline message in the chat view asking the user to confirm an action.
302
* Multiple confirmations may be shown per response. The UI might show "Accept All" / "Reject All" actions.
303
* @param title The title of the confirmation entry
304
* @param message An extra message to display to the user
305
* @param data An arbitrary JSON-stringifiable object that will be included in the ChatRequest when
306
* the confirmation is accepted or rejected
307
* TODO@API should this be MarkdownString?
308
* TODO@API should actually be a more generic function that takes an array of buttons
309
*/
310
confirmation(title: string, message: string | MarkdownString, data: any, buttons?: string[]): void;
311
312
/**
313
* Push a warning to this stream. Short-hand for
314
* `push(new ChatResponseWarningPart(message))`.
315
*
316
* @param message A warning message
317
* @returns This stream.
318
*/
319
warning(message: string | MarkdownString): void;
320
321
reference(value: Uri | Location | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { light: Uri; dark: Uri }): void;
322
323
reference2(value: Uri | Location | string | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { light: Uri; dark: Uri }, options?: { status?: { description: string; kind: ChatResponseReferencePartStatusKind } }): void;
324
325
codeCitation(value: Uri, license: string, snippet: string): void;
326
327
prepareToolInvocation(toolName: string): void;
328
329
push(part: ExtendedChatResponsePart): void;
330
331
clearToPreviousToolInvocation(reason: ChatResponseClearToPreviousToolInvocationReason): void;
332
}
333
334
export enum ChatResponseReferencePartStatusKind {
335
Complete = 1,
336
Partial = 2,
337
Omitted = 3
338
}
339
340
export type ThinkingDelta = {
341
text?: string | string[];
342
id: string;
343
metadata?: { readonly [key: string]: any };
344
} | {
345
text?: string | string[];
346
id?: string;
347
metadata: { readonly [key: string]: any };
348
} |
349
{
350
text: string | string[];
351
id?: string;
352
metadata?: { readonly [key: string]: any };
353
};
354
355
export enum ChatResponseClearToPreviousToolInvocationReason {
356
NoReason = 0,
357
FilteredContentRetry = 1,
358
CopyrightContentRetry = 2,
359
}
360
361
/**
362
* Does this piggy-back on the existing ChatRequest, or is it a different type of request entirely?
363
* Does it show up in history?
364
*/
365
export interface ChatRequest {
366
/**
367
* The `data` for any confirmations that were accepted
368
*/
369
acceptedConfirmationData?: any[];
370
371
/**
372
* The `data` for any confirmations that were rejected
373
*/
374
rejectedConfirmationData?: any[];
375
}
376
377
export interface ChatRequest {
378
379
/**
380
* A map of all tools that should (`true`) and should not (`false`) be used in this request.
381
*/
382
readonly tools: Map<string, boolean>;
383
}
384
385
export namespace lm {
386
/**
387
* Fired when the set of tools on a chat request changes.
388
*/
389
export const onDidChangeChatRequestTools: Event<ChatRequest>;
390
}
391
392
export class LanguageModelToolExtensionSource {
393
/**
394
* ID of the extension that published the tool.
395
*/
396
readonly id: string;
397
398
/**
399
* Label of the extension that published the tool.
400
*/
401
readonly label: string;
402
403
private constructor(id: string, label: string);
404
}
405
406
export class LanguageModelToolMCPSource {
407
/**
408
* Editor-configured label of the MCP server that published the tool.
409
*/
410
readonly label: string;
411
412
/**
413
* Server-defined name of the MCP server.
414
*/
415
readonly name: string;
416
417
/**
418
* Server-defined instructions for MCP tool use.
419
*/
420
readonly instructions?: string;
421
422
private constructor(label: string, name: string, instructions?: string);
423
}
424
425
export interface LanguageModelToolInformation {
426
source: LanguageModelToolExtensionSource | LanguageModelToolMCPSource | undefined;
427
}
428
429
// TODO@API fit this into the stream
430
export interface ChatUsedContext {
431
documents: ChatDocumentContext[];
432
}
433
434
export interface ChatParticipant {
435
/**
436
* Provide a set of variables that can only be used with this participant.
437
*/
438
participantVariableProvider?: { provider: ChatParticipantCompletionItemProvider; triggerCharacters: string[] };
439
440
/**
441
* Event that fires when a request is paused or unpaused.
442
* Chat requests are initially unpaused in the {@link requestHandler}.
443
*/
444
onDidChangePauseState: Event<ChatParticipantPauseStateEvent>;
445
}
446
447
export interface ChatParticipantPauseStateEvent {
448
request: ChatRequest;
449
isPaused: boolean;
450
}
451
452
export interface ChatParticipantCompletionItemProvider {
453
provideCompletionItems(query: string, token: CancellationToken): ProviderResult<ChatCompletionItem[]>;
454
}
455
456
export class ChatCompletionItem {
457
id: string;
458
label: string | CompletionItemLabel;
459
values: ChatVariableValue[];
460
fullName?: string;
461
icon?: ThemeIcon;
462
insertText?: string;
463
detail?: string;
464
documentation?: string | MarkdownString;
465
command?: Command;
466
467
constructor(id: string, label: string | CompletionItemLabel, values: ChatVariableValue[]);
468
}
469
470
export type ChatExtendedRequestHandler = (request: ChatRequest, context: ChatContext, response: ChatResponseStream, token: CancellationToken) => ProviderResult<ChatResult | void>;
471
472
export interface ChatResult {
473
nextQuestion?: {
474
prompt: string;
475
participant?: string;
476
command?: string;
477
};
478
/**
479
* An optional detail string that will be rendered at the end of the response in certain UI contexts.
480
*/
481
details?: string;
482
}
483
484
export namespace chat {
485
/**
486
* Create a chat participant with the extended progress type
487
*/
488
export function createChatParticipant(id: string, handler: ChatExtendedRequestHandler): ChatParticipant;
489
}
490
491
/*
492
* User action events
493
*/
494
495
export enum ChatCopyKind {
496
// Keyboard shortcut or context menu
497
Action = 1,
498
Toolbar = 2
499
}
500
501
export interface ChatCopyAction {
502
// eslint-disable-next-line local/vscode-dts-string-type-literals
503
kind: 'copy';
504
codeBlockIndex: number;
505
copyKind: ChatCopyKind;
506
copiedCharacters: number;
507
totalCharacters: number;
508
copiedText: string;
509
totalLines: number;
510
copiedLines: number;
511
modelId: string;
512
languageId?: string;
513
}
514
515
export interface ChatInsertAction {
516
// eslint-disable-next-line local/vscode-dts-string-type-literals
517
kind: 'insert';
518
codeBlockIndex: number;
519
totalCharacters: number;
520
totalLines: number;
521
languageId?: string;
522
modelId: string;
523
newFile?: boolean;
524
}
525
526
export interface ChatApplyAction {
527
// eslint-disable-next-line local/vscode-dts-string-type-literals
528
kind: 'apply';
529
codeBlockIndex: number;
530
totalCharacters: number;
531
totalLines: number;
532
languageId?: string;
533
modelId: string;
534
newFile?: boolean;
535
codeMapper?: string;
536
}
537
538
export interface ChatTerminalAction {
539
// eslint-disable-next-line local/vscode-dts-string-type-literals
540
kind: 'runInTerminal';
541
codeBlockIndex: number;
542
languageId?: string;
543
}
544
545
export interface ChatCommandAction {
546
// eslint-disable-next-line local/vscode-dts-string-type-literals
547
kind: 'command';
548
commandButton: ChatCommandButton;
549
}
550
551
export interface ChatFollowupAction {
552
// eslint-disable-next-line local/vscode-dts-string-type-literals
553
kind: 'followUp';
554
followup: ChatFollowup;
555
}
556
557
export interface ChatBugReportAction {
558
// eslint-disable-next-line local/vscode-dts-string-type-literals
559
kind: 'bug';
560
}
561
562
export interface ChatEditorAction {
563
// eslint-disable-next-line local/vscode-dts-string-type-literals
564
kind: 'editor';
565
accepted: boolean;
566
}
567
568
export interface ChatEditingSessionAction {
569
// eslint-disable-next-line local/vscode-dts-string-type-literals
570
kind: 'chatEditingSessionAction';
571
uri: Uri;
572
hasRemainingEdits: boolean;
573
outcome: ChatEditingSessionActionOutcome;
574
}
575
576
export interface ChatEditingHunkAction {
577
// eslint-disable-next-line local/vscode-dts-string-type-literals
578
kind: 'chatEditingHunkAction';
579
uri: Uri;
580
lineCount: number;
581
linesAdded: number;
582
linesRemoved: number;
583
outcome: ChatEditingSessionActionOutcome;
584
hasRemainingEdits: boolean;
585
}
586
587
export enum ChatEditingSessionActionOutcome {
588
Accepted = 1,
589
Rejected = 2,
590
Saved = 3
591
}
592
593
export interface ChatUserActionEvent {
594
readonly result: ChatResult;
595
readonly action: ChatCopyAction | ChatInsertAction | ChatApplyAction | ChatTerminalAction | ChatCommandAction | ChatFollowupAction | ChatBugReportAction | ChatEditorAction | ChatEditingSessionAction | ChatEditingHunkAction;
596
}
597
598
export interface ChatPromptReference {
599
/**
600
* TODO Needed for now to drive the variableName-type reference, but probably both of these should go away in the future.
601
*/
602
readonly name: string;
603
604
/**
605
* The list of tools were referenced in the value of the reference
606
*/
607
readonly toolReferences?: readonly ChatLanguageModelToolReference[];
608
}
609
610
export interface ChatResultFeedback {
611
readonly unhelpfulReason?: string;
612
}
613
614
export namespace lm {
615
export function fileIsIgnored(uri: Uri, token?: CancellationToken): Thenable<boolean>;
616
}
617
618
export interface ChatVariableValue {
619
/**
620
* The detail level of this chat variable value. If possible, variable resolvers should try to offer shorter values that will consume fewer tokens in an LLM prompt.
621
*/
622
level: ChatVariableLevel;
623
624
/**
625
* The variable's value, which can be included in an LLM prompt as-is, or the chat participant may decide to read the value and do something else with it.
626
*/
627
value: string | Uri;
628
629
/**
630
* A description of this value, which could be provided to the LLM as a hint.
631
*/
632
description?: string;
633
}
634
635
/**
636
* The detail level of this chat variable value.
637
*/
638
export enum ChatVariableLevel {
639
Short = 1,
640
Medium = 2,
641
Full = 3
642
}
643
644
export interface LanguageModelToolInvocationOptions<T> {
645
model?: LanguageModelChat;
646
}
647
648
export interface ChatRequest {
649
modeInstructions?: string;
650
modeInstructionsToolReferences?: readonly ChatLanguageModelToolReference[];
651
}
652
}
653
654