Skip to content

Commit b99fbe9

Browse files
authored
Fix build from breaking chat participant API change (#8415)
1 parent ee3be3e commit b99fbe9

File tree

5 files changed

+413
-94
lines changed

5 files changed

+413
-94
lines changed

src/@types/vscode.proposed.chatContextProvider.d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ declare module 'vscode' {
1616
* Providers registered without a selector will not be called for resource-based context.
1717
* - Explicitly. These context items are shown as options when the user explicitly attaches context.
1818
*
19-
* To ensure your extension is activated when chat context is requested, make sure to include the `onChatContextProvider:<id>` activation event in your `package.json`.
19+
* To ensure your extension is activated when chat context is requested, make sure to include the following activations events:
20+
* - If your extension implements `provideWorkspaceChatContext` or `provideChatContextForResource`, find an activation event which is a good signal to activate.
21+
* Ex: `onLanguage:<languageId>`, `onWebviewPanel:<viewType>`, etc.`
22+
* - If your extension implements `provideChatContextExplicit`, your extension will be automatically activated when the user requests explicit context.
2023
*
2124
* @param selector Optional document selector to filter which resources the provider is called for. If omitted, the provider will only be called for explicit context requests.
2225
* @param id Unique identifier for the provider.
@@ -49,7 +52,7 @@ declare module 'vscode' {
4952
value?: string;
5053
/**
5154
* An optional command that is executed when the context item is clicked.
52-
* The original context item will be passed as an argument to the command.
55+
* The original context item will be passed as the first argument to the command.
5356
*/
5457
command?: Command;
5558
}
@@ -62,7 +65,11 @@ declare module 'vscode' {
6265
onDidChangeWorkspaceChatContext?: Event<void>;
6366

6467
/**
65-
* Provide a list of chat context items to be included as workspace context for all chat sessions.
68+
* TODO @API: should this be a separate provider interface?
69+
*
70+
* Provide a list of chat context items to be included as workspace context for all chat requests.
71+
* This should be used very sparingly to avoid providing useless context and to avoid using up the context window.
72+
* A good example use case is to provide information about which branch the user is working on in a source control context.
6673
*
6774
* @param token A cancellation token.
6875
*/
@@ -82,7 +89,7 @@ declare module 'vscode' {
8289
* Chat context items can be provided without a `value`, as the `value` can be resolved later using `resolveChatContext`.
8390
* `resolveChatContext` is only called for items that do not have a `value`.
8491
*
85-
* Currently only called when the resource is a webview.
92+
* Called when the resource is a webview or a text editor.
8693
*
8794
* @param options Options include the resource for which to provide context.
8895
* @param token A cancellation token.

src/@types/vscode.proposed.chatParticipantAdditions.d.ts

Lines changed: 176 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ declare module 'vscode' {
6565
constructor(uri: Uri, edits: NotebookEdit | NotebookEdit[]);
6666
}
6767

68+
/**
69+
* Represents a file-level edit (creation, deletion, or rename).
70+
*/
71+
export interface ChatWorkspaceFileEdit {
72+
/**
73+
* The original file URI (undefined for new files).
74+
*/
75+
oldResource?: Uri;
76+
77+
/**
78+
* The new file URI (undefined for deleted files).
79+
*/
80+
newResource?: Uri;
81+
}
82+
83+
/**
84+
* Represents a workspace edit containing file-level operations.
85+
*/
86+
export class ChatResponseWorkspaceEditPart {
87+
edits: ChatWorkspaceFileEdit[];
88+
constructor(edits: ChatWorkspaceFileEdit[]);
89+
}
90+
6891
export class ChatResponseConfirmationPart {
6992
title: string;
7093
message: string | MarkdownString;
@@ -80,9 +103,12 @@ declare module 'vscode' {
80103
constructor(value: Uri, license: string, snippet: string);
81104
}
82105

83-
export class ChatPrepareToolInvocationPart {
84-
toolName: string;
85-
constructor(toolName: string);
106+
export interface ChatToolInvocationStreamData {
107+
/**
108+
* Partial or not-yet-validated arguments that have streamed from the language model.
109+
* Tools may use this to render interim UI while the full invocation input is collected.
110+
*/
111+
readonly partialInput?: unknown;
86112
}
87113

88114
export interface ChatTerminalToolInvocationData {
@@ -92,6 +118,48 @@ declare module 'vscode' {
92118
toolEdited?: string;
93119
};
94120
language: string;
121+
122+
/**
123+
* Terminal command output. Displayed when the terminal is no longer available.
124+
*/
125+
output?: {
126+
/** The raw output text, may include ANSI escape codes. */
127+
text: string;
128+
};
129+
130+
/**
131+
* Command execution state.
132+
*/
133+
state?: {
134+
/** Exit code of the command. */
135+
exitCode?: number;
136+
/** Duration of execution in milliseconds. */
137+
duration?: number;
138+
};
139+
}
140+
141+
export class McpToolInvocationContentData {
142+
/**
143+
* The mime type which determines how the data property is interpreted.
144+
*/
145+
mimeType: string;
146+
147+
/**
148+
* The byte data for this part.
149+
*/
150+
data: Uint8Array;
151+
152+
/**
153+
* Construct a generic data part with the given content.
154+
* @param data The byte data for this part.
155+
* @param mimeType The mime type of the data.
156+
*/
157+
constructor(data: Uint8Array, mimeType: string);
158+
}
159+
160+
export interface ChatMcpToolInvocationData {
161+
input: string;
162+
output: McpToolInvocationContentData[];
95163
}
96164

97165
export class ChatToolInvocationPart {
@@ -103,8 +171,8 @@ declare module 'vscode' {
103171
pastTenseMessage?: string | MarkdownString;
104172
isConfirmed?: boolean;
105173
isComplete?: boolean;
106-
toolSpecificData?: ChatTerminalToolInvocationData;
107-
fromSubAgent?: boolean;
174+
toolSpecificData?: ChatTerminalToolInvocationData | ChatMcpToolInvocationData;
175+
subAgentInvocationId?: string;
108176
presentation?: 'hidden' | 'hiddenAfterComplete' | undefined;
109177

110178
constructor(toolName: string, toolCallId: string, isError?: boolean);
@@ -176,7 +244,7 @@ declare module 'vscode' {
176244
constructor(uris: Uri[], callback: () => Thenable<unknown>);
177245
}
178246

179-
export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseNotebookEditPart | ChatResponseConfirmationPart | ChatResponseCodeCitationPart | ChatResponseReferencePart2 | ChatResponseMovePart | ChatResponseExtensionsPart | ChatResponsePullRequestPart | ChatPrepareToolInvocationPart | ChatToolInvocationPart | ChatResponseMultiDiffPart | ChatResponseThinkingProgressPart | ChatResponseExternalEditPart;
247+
export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseNotebookEditPart | ChatResponseWorkspaceEditPart | ChatResponseConfirmationPart | ChatResponseCodeCitationPart | ChatResponseReferencePart2 | ChatResponseMovePart | ChatResponseExtensionsPart | ChatResponsePullRequestPart | ChatToolInvocationPart | ChatResponseMultiDiffPart | ChatResponseThinkingProgressPart | ChatResponseExternalEditPart;
180248
export class ChatResponseWarningPart {
181249
value: MarkdownString;
182250
constructor(value: string | MarkdownString);
@@ -310,6 +378,12 @@ declare module 'vscode' {
310378

311379
notebookEdit(target: Uri, isDone: true): void;
312380

381+
/**
382+
* Push a workspace edit containing file-level operations (create, delete, rename).
383+
* @param edits Array of file-level edits to apply
384+
*/
385+
workspaceEdit(edits: ChatWorkspaceFileEdit[]): void;
386+
313387
/**
314388
* Makes an external edit to one or more resources. Changes to the
315389
* resources made within the `callback` and before it resolves will be
@@ -349,7 +423,21 @@ declare module 'vscode' {
349423

350424
codeCitation(value: Uri, license: string, snippet: string): void;
351425

352-
prepareToolInvocation(toolName: string): void;
426+
/**
427+
* Begin a tool invocation in streaming mode. This creates a tool invocation that will
428+
* display streaming progress UI until the tool is actually invoked.
429+
* @param toolCallId Unique identifier for this tool call, used to correlate streaming updates and final invocation.
430+
* @param toolName The name of the tool being invoked.
431+
* @param streamData Optional initial streaming data with partial arguments.
432+
*/
433+
beginToolInvocation(toolCallId: string, toolName: string, streamData?: ChatToolInvocationStreamData & { subagentInvocationId?: string }): void;
434+
435+
/**
436+
* Update the streaming data for a tool invocation that was started with `beginToolInvocation`.
437+
* @param toolCallId The tool call ID that was passed to `beginToolInvocation`.
438+
* @param streamData New streaming data with updated partial arguments.
439+
*/
440+
updateToolInvocation(toolCallId: string, streamData: ChatToolInvocationStreamData): void;
353441

354442
push(part: ExtendedChatResponsePart): void;
355443

@@ -404,7 +492,7 @@ declare module 'vscode' {
404492
/**
405493
* A map of all tools that should (`true`) and should not (`false`) be used in this request.
406494
*/
407-
readonly tools: Map<string, boolean>;
495+
readonly tools: Map<LanguageModelToolInformation, boolean>;
408496
}
409497

410498
export namespace lm {
@@ -494,6 +582,47 @@ declare module 'vscode' {
494582

495583
export type ChatExtendedRequestHandler = (request: ChatRequest, context: ChatContext, response: ChatResponseStream, token: CancellationToken) => ProviderResult<ChatResult | void>;
496584

585+
/**
586+
* Details about the prompt token usage by category and label.
587+
*/
588+
export interface ChatResultPromptTokenDetail {
589+
/**
590+
* The category this token usage belongs to (e.g., "System", "Context", "Conversation").
591+
*/
592+
readonly category: string;
593+
594+
/**
595+
* The label for this specific token usage (e.g., "System prompt", "Attached files").
596+
*/
597+
readonly label: string;
598+
599+
/**
600+
* The percentage of the total prompt tokens this represents (0-100).
601+
*/
602+
readonly percentageOfPrompt: number;
603+
}
604+
605+
/**
606+
* Token usage information for a chat request.
607+
*/
608+
export interface ChatResultUsage {
609+
/**
610+
* The number of prompt tokens used in this request.
611+
*/
612+
readonly promptTokens: number;
613+
614+
/**
615+
* The number of completion tokens generated in this response.
616+
*/
617+
readonly completionTokens: number;
618+
619+
/**
620+
* Optional breakdown of prompt token usage by category and label.
621+
* If the percentages do not sum to 100%, the remaining will be shown as "Uncategorized".
622+
*/
623+
readonly promptTokenDetails?: readonly ChatResultPromptTokenDetail[];
624+
}
625+
497626
export interface ChatResult {
498627
nextQuestion?: {
499628
prompt: string;
@@ -504,6 +633,12 @@ declare module 'vscode' {
504633
* An optional detail string that will be rendered at the end of the response in certain UI contexts.
505634
*/
506635
details?: string;
636+
637+
/**
638+
* Token usage information for this request, if available.
639+
* This is typically provided by the underlying language model.
640+
*/
641+
readonly usage?: ChatResultUsage;
507642
}
508643

509644
export namespace chat {
@@ -668,6 +803,39 @@ declare module 'vscode' {
668803

669804
export interface LanguageModelToolInvocationOptions<T> {
670805
model?: LanguageModelChat;
806+
chatStreamToolCallId?: string;
807+
}
808+
809+
export interface LanguageModelToolInvocationStreamOptions<T> {
810+
/**
811+
* Raw argument payload, such as the streamed JSON fragment from the language model.
812+
*/
813+
readonly rawInput?: unknown;
814+
815+
readonly chatRequestId?: string;
816+
/** @deprecated Use {@link chatSessionResource} instead */
817+
readonly chatSessionId?: string;
818+
readonly chatSessionResource?: Uri;
819+
readonly chatInteractionId?: string;
820+
}
821+
822+
export interface LanguageModelToolStreamResult {
823+
/**
824+
* A customized progress message to show while the tool runs.
825+
*/
826+
invocationMessage?: string | MarkdownString;
827+
}
828+
829+
export interface LanguageModelTool<T> {
830+
/**
831+
* Called zero or more times before {@link LanguageModelTool.prepareInvocation} while the
832+
* language model streams argument data for the invocation. Use this to update progress
833+
* or UI with the partial arguments that have been generated so far.
834+
*
835+
* Implementations must be free of side-effects and should be resilient to receiving
836+
* malformed or incomplete input.
837+
*/
838+
handleToolStream?(options: LanguageModelToolInvocationStreamOptions<T>, token: CancellationToken): ProviderResult<LanguageModelToolStreamResult>;
671839
}
672840

673841
export interface ChatRequest {

0 commit comments

Comments
 (0)