Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/fixtures/edit/issue-5755/vscode.proposed.chatParticipantAdditions.d.ts
13405 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
/**
9
* The location at which the chat is happening.
10
*/
11
export enum ChatLocation {
12
/**
13
* The chat panel
14
*/
15
Panel = 1,
16
/**
17
* Terminal inline chat
18
*/
19
Terminal = 2,
20
/**
21
* Notebook inline chat
22
*/
23
Notebook = 3,
24
/**
25
* Code editor inline chat
26
*/
27
Editor = 4
28
}
29
30
export interface ChatRequest {
31
/**
32
* The attempt number of the request. The first request has attempt number 0.
33
*/
34
readonly attempt: number;
35
36
/**
37
* If automatic command detection is enabled.
38
*/
39
readonly enableCommandDetection: boolean;
40
41
/**
42
* The location at which the chat is happening. This will always be one of the supported values
43
*/
44
readonly location: ChatLocation;
45
}
46
47
export interface ChatParticipant {
48
onDidPerformAction: Event<ChatUserActionEvent>;
49
supportIssueReporting?: boolean;
50
51
/**
52
* Temp, support references that are slow to resolve and should be tools rather than references.
53
*/
54
supportsSlowReferences?: boolean;
55
}
56
57
export interface ChatErrorDetails {
58
/**
59
* If set to true, the message content is completely hidden. Only ChatErrorDetails#message will be shown.
60
*/
61
responseIsRedacted?: boolean;
62
}
63
64
/**
65
* Now only used for the "intent detection" API below
66
*/
67
export interface ChatCommand {
68
readonly name: string;
69
readonly description: string;
70
}
71
72
export class ChatResponseDetectedParticipantPart {
73
participant: string;
74
// TODO@API validate this against statically-declared slash commands?
75
command?: ChatCommand;
76
constructor(participant: string, command?: ChatCommand);
77
}
78
79
export interface ChatVulnerability {
80
title: string;
81
description: string;
82
// id: string; // Later we will need to be able to link these across multiple content chunks.
83
}
84
85
export class ChatResponseMarkdownWithVulnerabilitiesPart {
86
value: MarkdownString;
87
vulnerabilities: ChatVulnerability[];
88
constructor(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]);
89
}
90
91
/**
92
* Displays a {@link Command command} as a button in the chat response.
93
*/
94
export interface ChatCommandButton {
95
command: Command;
96
}
97
98
export interface ChatDocumentContext {
99
uri: Uri;
100
version: number;
101
ranges: Range[];
102
}
103
104
export class ChatResponseTextEditPart {
105
uri: Uri;
106
edits: TextEdit[];
107
constructor(uri: Uri, edits: TextEdit | TextEdit[]);
108
}
109
110
export class ChatResponseConfirmationPart {
111
title: string;
112
message: string;
113
data: any;
114
constructor(title: string, message: string, data: any);
115
}
116
117
export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseDetectedParticipantPart | ChatResponseConfirmationPart;
118
119
export class ChatResponseWarningPart {
120
value: MarkdownString;
121
constructor(value: string | MarkdownString);
122
}
123
124
export class ChatResponseProgressPart2 extends ChatResponseProgressPart {
125
value: string;
126
task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>;
127
constructor(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>);
128
}
129
130
export interface ChatResponseStream {
131
132
/**
133
* Push a progress part to this stream. Short-hand for
134
* `push(new ChatResponseProgressPart(value))`.
135
*
136
* @param value A progress message
137
* @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.
138
* @returns This stream.
139
*/
140
progress(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>): void;
141
142
textEdit(target: Uri, edits: TextEdit | TextEdit[]): void;
143
markdownWithVulnerabilities(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]): void;
144
detectedParticipant(participant: string, command?: ChatCommand): void;
145
push(part: ChatResponsePart | ChatResponseTextEditPart | ChatResponseDetectedParticipantPart | ChatResponseWarningPart | ChatResponseProgressPart2): void;
146
147
/**
148
* Show an inline message in the chat view asking the user to confirm an action.
149
* Multiple confirmations may be shown per response. The UI might show "Accept All" / "Reject All" actions.
150
* @param title The title of the confirmation entry
151
* @param message An extra message to display to the user
152
* @param data An arbitrary JSON-stringifiable object that will be included in the ChatRequest when
153
* the confirmation is accepted or rejected
154
* TODO@API should this be MarkdownString?
155
* TODO@API should actually be a more generic function that takes an array of buttons
156
*/
157
confirmation(title: string, message: string, data: any): void;
158
159
/**
160
* Push a warning to this stream. Short-hand for
161
* `push(new ChatResponseWarningPart(message))`.
162
*
163
* @param message A warning message
164
* @returns This stream.
165
*/
166
warning(message: string | MarkdownString): void;
167
168
reference(value: Uri | Location | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { light: Uri; dark: Uri }): void;
169
170
push(part: ExtendedChatResponsePart): void;
171
}
172
173
/**
174
* Does this piggy-back on the existing ChatRequest, or is it a different type of request entirely?
175
* Does it show up in history?
176
*/
177
export interface ChatRequest {
178
/**
179
* The `data` for any confirmations that were accepted
180
*/
181
acceptedConfirmationData?: any[];
182
183
/**
184
* The `data` for any confirmations that were rejected
185
*/
186
rejectedConfirmationData?: any[];
187
}
188
189
// TODO@API fit this into the stream
190
export interface ChatUsedContext {
191
documents: ChatDocumentContext[];
192
}
193
194
export interface ChatParticipant {
195
/**
196
* Provide a set of variables that can only be used with this participant.
197
*/
198
participantVariableProvider?: { provider: ChatParticipantCompletionItemProvider; triggerCharacters: string[] };
199
}
200
201
export interface ChatParticipantCompletionItemProvider {
202
provideCompletionItems(query: string, token: CancellationToken): ProviderResult<ChatCompletionItem[]>;
203
}
204
205
export class ChatCompletionItem {
206
id: string;
207
label: string | CompletionItemLabel;
208
values: ChatVariableValue[];
209
insertText?: string;
210
fullName?: string;
211
icon?: ThemeIcon;
212
detail?: string;
213
documentation?: string | MarkdownString;
214
command?: Command;
215
216
constructor(id: string, label: string | CompletionItemLabel, values: ChatVariableValue[]);
217
}
218
219
export type ChatExtendedRequestHandler = (request: ChatRequest, context: ChatContext, response: ChatResponseStream, token: CancellationToken) => ProviderResult<ChatResult | void>;
220
221
export namespace chat {
222
/**
223
* Create a chat participant with the extended progress type
224
*/
225
export function createChatParticipant(id: string, handler: ChatExtendedRequestHandler): ChatParticipant;
226
227
export function createDynamicChatParticipant(id: string, dynamicProps: DynamicChatParticipantProps, handler: ChatExtendedRequestHandler): ChatParticipant;
228
229
/**
230
* Current version of the proposal. Changes whenever backwards-incompatible changes are made.
231
* If a new feature is added that doesn't break existing code, the version is not incremented. When the extension uses this new feature, it should set its engines.vscode version appropriately.
232
* But if a change is made to an existing feature that would break existing code, the version should be incremented.
233
* The chat extension should not activate if it doesn't support the current version.
234
*/
235
export const _version: 1 | number;
236
}
237
238
/**
239
* These don't get set on the ChatParticipant after creation, like other props, because they are typically defined in package.json and we want them at the time of creation.
240
*/
241
export interface DynamicChatParticipantProps {
242
name: string;
243
publisherName: string;
244
description?: string;
245
fullName?: string;
246
}
247
248
/*
249
* User action events
250
*/
251
252
export enum ChatCopyKind {
253
// Keyboard shortcut or context menu
254
Action = 1,
255
Toolbar = 2
256
}
257
258
export interface ChatCopyAction {
259
// eslint-disable-next-line local/vscode-dts-string-type-literals
260
kind: 'copy';
261
codeBlockIndex: number;
262
copyKind: ChatCopyKind;
263
copiedCharacters: number;
264
totalCharacters: number;
265
copiedText: string;
266
}
267
268
export interface ChatInsertAction {
269
// eslint-disable-next-line local/vscode-dts-string-type-literals
270
kind: 'insert';
271
codeBlockIndex: number;
272
totalCharacters: number;
273
newFile?: boolean;
274
}
275
276
export interface ChatTerminalAction {
277
// eslint-disable-next-line local/vscode-dts-string-type-literals
278
kind: 'runInTerminal';
279
codeBlockIndex: number;
280
languageId?: string;
281
}
282
283
export interface ChatCommandAction {
284
// eslint-disable-next-line local/vscode-dts-string-type-literals
285
kind: 'command';
286
commandButton: ChatCommandButton;
287
}
288
289
export interface ChatFollowupAction {
290
// eslint-disable-next-line local/vscode-dts-string-type-literals
291
kind: 'followUp';
292
followup: ChatFollowup;
293
}
294
295
export interface ChatBugReportAction {
296
// eslint-disable-next-line local/vscode-dts-string-type-literals
297
kind: 'bug';
298
}
299
300
export interface ChatEditorAction {
301
kind: 'editor';
302
accepted: boolean;
303
}
304
305
export interface ChatUserActionEvent {
306
readonly result: ChatResult;
307
readonly action: ChatCopyAction | ChatInsertAction | ChatTerminalAction | ChatCommandAction | ChatFollowupAction | ChatBugReportAction | ChatEditorAction;
308
}
309
310
export interface ChatPromptReference {
311
/**
312
* TODO Needed for now to drive the variableName-type reference, but probably both of these should go away in the future.
313
*/
314
readonly name: string;
315
}
316
317
/**
318
* The detail level of this chat variable value.
319
*/
320
export enum ChatVariableLevel {
321
Short = 1,
322
Medium = 2,
323
Full = 3
324
}
325
326
export interface ChatVariableValue {
327
/**
328
* 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.
329
*/
330
level: ChatVariableLevel;
331
332
/**
333
* 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.
334
*/
335
value: string | Uri;
336
337
/**
338
* A description of this value, which could be provided to the LLM as a hint.
339
*/
340
description?: string;
341
}
342
343
export interface ChatVariableResolverResponseStream {
344
/**
345
* Push a progress part to this stream. Short-hand for
346
* `push(new ChatResponseProgressPart(value))`.
347
*
348
* @param value
349
* @returns This stream.
350
*/
351
progress(value: string): ChatVariableResolverResponseStream;
352
353
/**
354
* Push a reference to this stream. Short-hand for
355
* `push(new ChatResponseReferencePart(value))`.
356
*
357
* *Note* that the reference is not rendered inline with the response.
358
*
359
* @param value A uri or location
360
* @returns This stream.
361
*/
362
reference(value: Uri | Location): ChatVariableResolverResponseStream;
363
364
/**
365
* Pushes a part to this stream.
366
*
367
* @param part A response part, rendered or metadata
368
*/
369
push(part: ChatVariableResolverResponsePart): ChatVariableResolverResponseStream;
370
}
371
372
export type ChatVariableResolverResponsePart = ChatResponseProgressPart | ChatResponseReferencePart;
373
374
export interface ChatVariableResolver {
375
/**
376
* A callback to resolve the value of a chat variable.
377
* @param name The name of the variable.
378
* @param context Contextual information about this chat request.
379
* @param token A cancellation token.
380
*/
381
resolve2?(name: string, context: ChatVariableContext, stream: ChatVariableResolverResponseStream, token: CancellationToken): ProviderResult<ChatVariableValue[]>;
382
}
383
}
384
385