Skip to content

Commit 01ce8d8

Browse files
authored
More chat participant API comments (microsoft#205617)
More docs
1 parent d32a86a commit 01ce8d8

File tree

5 files changed

+56
-51
lines changed

5 files changed

+56
-51
lines changed

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
16711671
RelatedInformationType: extHostTypes.RelatedInformationType,
16721672
SpeechToTextStatus: extHostTypes.SpeechToTextStatus,
16731673
KeywordRecognitionStatus: extHostTypes.KeywordRecognitionStatus,
1674-
ChatResponseTextPart: extHostTypes.ChatResponseTextPart,
16751674
ChatResponseMarkdownPart: extHostTypes.ChatResponseMarkdownPart,
16761675
ChatResponseFileTreePart: extHostTypes.ChatResponseFileTreePart,
16771676
ChatResponseAnchorPart: extHostTypes.ChatResponseAnchorPart,

src/vs/workbench/api/common/extHostChatAgents2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class ExtHostChatAgents2 implements ExtHostChatAgentsShape2 {
234234
res.push(new extHostTypes.ChatRequestTurn(h.request.message, h.request.command, h.request.variables.variables.map(typeConvert.ChatAgentResolvedVariable.to), { extensionId: '', participant: h.request.agentId }));
235235

236236
// RESPONSE turn
237-
const parts = coalesce(h.response.map(r => typeConvert.ChatResponsePart.from(r, this.commands.converter)));
237+
const parts = coalesce(h.response.map(r => typeConvert.ChatResponsePart.fromContent(r, this.commands.converter)));
238238
res.push(new extHostTypes.ChatResponseTurn(parts, result, { extensionId: '', participant: h.request.agentId }, h.request.command));
239239
}
240240

@@ -402,7 +402,7 @@ class ExtHostChatAgent {
402402

403403
return {
404404
name: c.name,
405-
description: c.description,
405+
description: c.description ?? '',
406406
followupPlaceholder: c.isSticky2?.placeholder,
407407
isSticky: c.isSticky2?.isSticky ?? c.isSticky,
408408
sampleRequest: c.sampleRequest

src/vs/workbench/api/common/extHostTypeConverters.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,18 +2330,6 @@ export namespace InteractiveEditorResponseFeedbackKind {
23302330
}
23312331
}
23322332

2333-
export namespace ChatResponseTextPart {
2334-
export function to(part: vscode.ChatResponseTextPart): Dto<IChatMarkdownContent> {
2335-
return {
2336-
kind: 'markdownContent',
2337-
content: MarkdownString.from(new types.MarkdownString().appendText(part.value))
2338-
};
2339-
}
2340-
export function from(part: Dto<IChatMarkdownContent>): vscode.ChatResponseTextPart {
2341-
return new types.ChatResponseTextPart(part.content.value);
2342-
}
2343-
}
2344-
23452333
export namespace ChatResponseMarkdownPart {
23462334
export function to(part: vscode.ChatResponseMarkdownPart): Dto<IChatMarkdownContent> {
23472335
return {
@@ -2475,14 +2463,27 @@ export namespace ChatResponsePart {
24752463
}
24762464

24772465
export function from(part: extHostProtocol.IChatProgressDto, commandsConverter: CommandsConverter): vscode.ChatResponsePart | undefined {
2466+
switch (part.kind) {
2467+
case 'reference': return ChatResponseReferencePart.from(part);
2468+
case 'markdownContent':
2469+
case 'inlineReference':
2470+
case 'progressMessage':
2471+
case 'treeData':
2472+
case 'command':
2473+
return fromContent(part, commandsConverter);
2474+
}
2475+
return undefined;
2476+
}
2477+
2478+
export function fromContent(part: extHostProtocol.IChatContentProgressDto, commandsConverter: CommandsConverter): vscode.ChatResponseMarkdownPart | vscode.ChatResponseFileTreePart | vscode.ChatResponseAnchorPart | vscode.ChatResponseCommandButtonPart | undefined {
24782479
switch (part.kind) {
24792480
case 'markdownContent': return ChatResponseMarkdownPart.from(part);
24802481
case 'inlineReference': return ChatResponseAnchorPart.from(part);
2481-
case 'reference': return ChatResponseReferencePart.from(part);
2482-
case 'progressMessage': return ChatResponseProgressPart.from(part);
2482+
case 'progressMessage': return undefined;
24832483
case 'treeData': return ChatResponseFilesPart.from(part);
24842484
case 'command': return ChatResponseCommandButtonPart.from(part, commandsConverter);
24852485
}
2486+
24862487
return undefined;
24872488
}
24882489
}

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4205,14 +4205,6 @@ export enum ChatResultFeedbackKind {
42054205
Helpful = 1,
42064206
}
42074207

4208-
4209-
export class ChatResponseTextPart {
4210-
value: string;
4211-
constructor(value: string) {
4212-
this.value = value;
4213-
}
4214-
}
4215-
42164208
export class ChatResponseMarkdownPart {
42174209
value: vscode.MarkdownString;
42184210
constructor(value: string | vscode.MarkdownString) {
@@ -4272,7 +4264,7 @@ export class ChatRequestTurn implements vscode.ChatRequestTurn {
42724264
export class ChatResponseTurn implements vscode.ChatResponseTurn {
42734265

42744266
constructor(
4275-
readonly response: ReadonlyArray<ChatResponseTextPart | ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>,
4267+
readonly response: ReadonlyArray<ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>,
42764268
readonly result: vscode.ChatResult,
42774269
readonly participant: { extensionId: string; participant: string },
42784270
readonly command?: string

src/vscode-dts/vscode.proposed.chatParticipant.d.ts

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66
declare module 'vscode' {
77

8+
/**
9+
* Represents a user request in chat history.
10+
*/
811
export class ChatRequestTurn {
912

1013
/**
1114
* The prompt as entered by the user.
1215
*
13-
* Information about variables used in this request are is stored in {@link ChatRequest.variables}.
16+
* Information about variables used in this request is stored in {@link ChatRequestTurn.variables}.
1417
*
1518
* *Note* that the {@link ChatParticipant.name name} of the participant and the {@link ChatCommand.name command}
1619
* are not part of the prompt.
@@ -35,26 +38,32 @@ declare module 'vscode' {
3538
private constructor(prompt: string, command: string | undefined, variables: ChatResolvedVariable[], participant: { extensionId: string; participant: string });
3639
}
3740

41+
/**
42+
* Represents a chat participant's response in chat history.
43+
*/
3844
export class ChatResponseTurn {
3945

4046
/**
41-
* The content that was received from the chat participant. Only the progress parts that represent actual content (not metadata) are represented.
47+
* The content that was received from the chat participant. Only the stream parts that represent actual content (not metadata) are represented.
4248
*/
43-
readonly response: ReadonlyArray<ChatResponseTextPart | ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>;
49+
readonly response: ReadonlyArray<ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>;
4450

4551
/**
4652
* The result that was received from the chat participant.
4753
*/
4854
readonly result: ChatResult;
4955

5056
/**
51-
* The name of the chat participant and contributing extension to which this request was directed.
57+
* The name of the chat participant and contributing extension that this response came from.
5258
*/
5359
readonly participant: { readonly extensionId: string; readonly participant: string };
5460

61+
/**
62+
* The name of the command that this response came from.
63+
*/
5564
readonly command?: string;
5665

57-
private constructor(response: ReadonlyArray<ChatResponseTextPart | ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>, result: ChatResult, participant: { extensionId: string; participant: string });
66+
private constructor(response: ReadonlyArray<ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>, result: ChatResult, participant: { extensionId: string; participant: string });
5867
}
5968

6069
export interface ChatContext {
@@ -98,7 +107,7 @@ declare module 'vscode' {
98107
errorDetails?: ChatErrorDetails;
99108

100109
/**
101-
* Arbitrary metadata for this result. Can be anything but must be JSON-stringifyable.
110+
* Arbitrary metadata for this result. Can be anything, but must be JSON-stringifyable.
102111
*/
103112
readonly metadata?: { readonly [key: string]: any };
104113
}
@@ -123,7 +132,8 @@ declare module 'vscode' {
123132
*/
124133
export interface ChatResultFeedback {
125134
/**
126-
* This instance of ChatResult has the same properties as the result returned from the participant callback, including `metadata`, but is not the same instance.
135+
* The ChatResult that the user is providing feedback for.
136+
* This instance has the same properties as the result returned from the participant callback, including `metadata`, but is not the same instance.
127137
*/
128138
readonly result: ChatResult;
129139

@@ -158,8 +168,11 @@ declare module 'vscode' {
158168
readonly isSticky?: boolean;
159169
}
160170

171+
/**
172+
* A ChatCommandProvider returns {@link ChatCommands commands} that can be invoked on a chat participant using `/`. For example, `@participant /command`.
173+
* These can be used as shortcuts to let the user explicitly invoke different functionalities provided by the participant.
174+
*/
161175
export interface ChatCommandProvider {
162-
163176
/**
164177
* Returns a list of commands that its participant is capable of handling. A command
165178
* can be selected by the user and will then be passed to the {@link ChatRequestHandler handler}
@@ -175,7 +188,7 @@ declare module 'vscode' {
175188
}
176189

177190
/**
178-
* A followup question suggested by the model.
191+
* A followup question suggested by the participant.
179192
*/
180193
export interface ChatFollowup {
181194
/**
@@ -184,7 +197,7 @@ declare module 'vscode' {
184197
prompt: string;
185198

186199
/**
187-
* A title to show the user, when it is different than the message.
200+
* A title to show the user. The prompt will be shown by default, when this is unspecified.
188201
*/
189202
label?: string;
190203

@@ -205,8 +218,8 @@ declare module 'vscode' {
205218
*/
206219
export interface ChatFollowupProvider {
207220
/**
208-
*
209-
* @param result The same instance of the result object that was returned by the chat participant, and it can be extended with arbitrary properties if needed.
221+
* Provide followups for the given result.
222+
* @param result This instance has the same properties as the result returned from the participant callback, including `metadata`, but is not the same instance.
210223
* @param token A cancellation token.
211224
*/
212225
provideFollowups(result: ChatResult, token: CancellationToken): ProviderResult<ChatFollowup[]>;
@@ -217,16 +230,19 @@ declare module 'vscode' {
217230
*/
218231
export type ChatRequestHandler = (request: ChatRequest, context: ChatContext, response: ChatResponseStream, token: CancellationToken) => ProviderResult<ChatResult>;
219232

220-
233+
/**
234+
* A chat participant can be invoked by the user in a chat session, using the `@` prefix. When it is invoked, it handles the chat request and is solely
235+
* responsible for providing a response to the user. A ChatParticipant is created using {@link chat.createChatParticipant}.
236+
*/
221237
export interface ChatParticipant {
222-
223238
/**
224239
* The short name by which this participant is referred to in the UI, e.g `workspace`.
225240
*/
226241
readonly name: string;
227242

228243
/**
229244
* The full name of this participant.
245+
* TODO@API This is only used for the default participant, but it seems useful, so should we keep it so we can use it in the future?
230246
*/
231247
fullName: string;
232248

@@ -293,7 +309,6 @@ declare module 'vscode' {
293309
* A resolved variable value is a name-value pair as well as the range in the prompt where a variable was used.
294310
*/
295311
export interface ChatResolvedVariable {
296-
297312
/**
298313
* The name of the variable.
299314
*
@@ -315,7 +330,6 @@ declare module 'vscode' {
315330
}
316331

317332
export interface ChatRequest {
318-
319333
/**
320334
* The prompt as entered by the user.
321335
*
@@ -336,16 +350,20 @@ declare module 'vscode' {
336350
*
337351
* *Note* that the prompt contains varibale references as authored and that it is up to the participant
338352
* to further modify the prompt, for instance by inlining variable values or creating links to
339-
* headings which contain the resolved values. vvariables are sorted in reverse by their range
353+
* headings which contain the resolved values. Variables are sorted in reverse by their range
340354
* in the prompt. That means the last variable in the prompt is the first in this list. This simplifies
341355
* string-manipulation of the prompt.
342356
*/
343357
// TODO@API Q? are there implicit variables that are not part of the prompt?
344358
readonly variables: readonly ChatResolvedVariable[];
345359
}
346360

361+
/**
362+
* The ChatResponseStream is how a participant is able to return content to the chat view. It provides several methods for streaming different types of content
363+
* which will be rendered in an appropriate way in the chat view. A participant can use the helper method for the type of content it wants to return, or it
364+
* can instantiate a {@link ChatResponsePart} and use the generic {@link ChatResponseStream.push} method to return it.
365+
*/
347366
export interface ChatResponseStream {
348-
349367
/**
350368
* Push a markdown part to this stream. Short-hand for
351369
* `push(new ChatResponseMarkdownPart(value))`.
@@ -359,6 +377,7 @@ declare module 'vscode' {
359377
/**
360378
* Push an anchor part to this stream. Short-hand for
361379
* `push(new ChatResponseAnchorPart(value, title))`.
380+
* An anchor is an inline reference to some type of resource.
362381
*
363382
* @param value A uri or location
364383
* @param title An optional title that is rendered with value
@@ -413,11 +432,6 @@ declare module 'vscode' {
413432
push(part: ChatResponsePart): ChatResponseStream;
414433
}
415434

416-
export class ChatResponseTextPart {
417-
value: string;
418-
constructor(value: string);
419-
}
420-
421435
export class ChatResponseMarkdownPart {
422436
value: MarkdownString;
423437
constructor(value: string | MarkdownString);
@@ -458,12 +472,11 @@ declare module 'vscode' {
458472
/**
459473
* Represents the different chat response types.
460474
*/
461-
export type ChatResponsePart = ChatResponseTextPart | ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart
475+
export type ChatResponsePart = ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart
462476
| ChatResponseProgressPart | ChatResponseReferencePart | ChatResponseCommandButtonPart;
463477

464478

465479
export namespace chat {
466-
467480
/**
468481
* Create a new {@link ChatParticipant chat participant} instance.
469482
*

0 commit comments

Comments
 (0)