Path: blob/main/src/vscode-dts/vscode.proposed.chatParticipantAdditions.d.ts
3290 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45declare module 'vscode' {67export interface ChatParticipant {8onDidPerformAction: Event<ChatUserActionEvent>;9}1011/**12* Now only used for the "intent detection" API below13*/14export interface ChatCommand {15readonly name: string;16readonly description: string;17}1819export interface ChatVulnerability {20title: string;21description: string;22// id: string; // Later we will need to be able to link these across multiple content chunks.23}2425export class ChatResponseMarkdownWithVulnerabilitiesPart {26value: MarkdownString;27vulnerabilities: ChatVulnerability[];28constructor(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]);29}3031export class ChatResponseCodeblockUriPart {32isEdit?: boolean;33value: Uri;34constructor(value: Uri, isEdit?: boolean);35}3637/**38* Displays a {@link Command command} as a button in the chat response.39*/40export interface ChatCommandButton {41command: Command;42}4344export interface ChatDocumentContext {45uri: Uri;46version: number;47ranges: Range[];48}4950export class ChatResponseTextEditPart {51uri: Uri;52edits: TextEdit[];53isDone?: boolean;54constructor(uri: Uri, done: true);55constructor(uri: Uri, edits: TextEdit | TextEdit[]);56}5758export class ChatResponseNotebookEditPart {59uri: Uri;60edits: NotebookEdit[];61isDone?: boolean;62constructor(uri: Uri, done: true);63constructor(uri: Uri, edits: NotebookEdit | NotebookEdit[]);64}6566export class ChatResponseConfirmationPart {67title: string;68message: string | MarkdownString;69data: any;70buttons?: string[];71constructor(title: string, message: string | MarkdownString, data: any, buttons?: string[]);72}7374export class ChatResponseCodeCitationPart {75value: Uri;76license: string;77snippet: string;78constructor(value: Uri, license: string, snippet: string);79}8081export class ChatPrepareToolInvocationPart {82toolName: string;83constructor(toolName: string);84}8586export interface ChatTerminalToolInvocationData {87commandLine: {88original: string;89userEdited?: string;90toolEdited?: string;91};92language: string;93}9495export class ChatToolInvocationPart {96toolName: string;97toolCallId: string;98isError?: boolean;99invocationMessage?: string | MarkdownString;100originMessage?: string | MarkdownString;101pastTenseMessage?: string | MarkdownString;102isConfirmed?: boolean;103isComplete?: boolean;104toolSpecificData?: ChatTerminalToolInvocationData;105106constructor(toolName: string, toolCallId: string, isError?: boolean);107}108109/**110* Represents a single file diff entry in a multi diff view.111*/112export interface ChatResponseDiffEntry {113/**114* The original file URI (undefined for new files).115*/116originalUri?: Uri;117118/**119* The modified file URI (undefined for deleted files).120*/121modifiedUri?: Uri;122123/**124* Optional URI to navigate to when clicking on the file.125*/126goToFileUri?: Uri;127128/**129* Added data (e.g. line numbers) to show in the UI130*/131added?: number;132133/**134* Removed data (e.g. line numbers) to show in the UI135*/136removed?: number;137}138139/**140* Represents a part of a chat response that shows multiple file diffs.141*/142export class ChatResponseMultiDiffPart {143/**144* Array of file diff entries to display.145*/146value: ChatResponseDiffEntry[];147148/**149* The title for the multi diff editor.150*/151title: string;152153/**154* Create a new ChatResponseMultiDiffPart.155* @param value Array of file diff entries.156* @param title The title for the multi diff editor.157*/158constructor(value: ChatResponseDiffEntry[], title: string);159}160161export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseNotebookEditPart | ChatResponseConfirmationPart | ChatResponseCodeCitationPart | ChatResponseReferencePart2 | ChatResponseMovePart | ChatResponseExtensionsPart | ChatResponsePullRequestPart | ChatPrepareToolInvocationPart | ChatToolInvocationPart | ChatResponseMultiDiffPart | ChatResponseThinkingProgressPart;162export class ChatResponseWarningPart {163value: MarkdownString;164constructor(value: string | MarkdownString);165}166167export class ChatResponseProgressPart2 extends ChatResponseProgressPart {168value: string;169task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>;170constructor(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>);171}172173/**174* A specialized progress part for displaying thinking/reasoning steps.175*/176export class ChatResponseThinkingProgressPart {177value: string | string[];178id?: string;179metadata?: { readonly [key: string]: any };180task?: (progress: Progress<LanguageModelThinkingPart>) => Thenable<string | void>;181182/**183* Creates a new thinking progress part.184* @param value An initial progress message185* @param task A task that will emit thinking parts during its execution186*/187constructor(value: string | string[], id?: string, metadata?: { readonly [key: string]: any }, task?: (progress: Progress<LanguageModelThinkingPart>) => Thenable<string | void>);188}189190export class ChatResponseReferencePart2 {191/**192* The reference target.193*/194value: Uri | Location | { variableName: string; value?: Uri | Location } | string;195196/**197* The icon for the reference.198*/199iconPath?: Uri | ThemeIcon | {200/**201* The icon path for the light theme.202*/203light: Uri;204/**205* The icon path for the dark theme.206*/207dark: Uri;208};209options?: { status?: { description: string; kind: ChatResponseReferencePartStatusKind } };210211/**212* Create a new ChatResponseReferencePart.213* @param value A uri or location214* @param iconPath Icon for the reference shown in UI215*/216constructor(value: Uri | Location | { variableName: string; value?: Uri | Location } | string, iconPath?: Uri | ThemeIcon | {217/**218* The icon path for the light theme.219*/220light: Uri;221/**222* The icon path for the dark theme.223*/224dark: Uri;225}, options?: { status?: { description: string; kind: ChatResponseReferencePartStatusKind } });226}227228export class ChatResponseMovePart {229230readonly uri: Uri;231readonly range: Range;232233constructor(uri: Uri, range: Range);234}235236export interface ChatResponseAnchorPart {237/**238* The target of this anchor.239*240* If this is a {@linkcode Uri} or {@linkcode Location}, this is rendered as a normal link.241*242* If this is a {@linkcode SymbolInformation}, this is rendered as a symbol link.243*244* TODO mjbvz: Should this be a full `SymbolInformation`? Or just the parts we need?245* TODO mjbvz: Should we allow a `SymbolInformation` without a location? For example, until `resolve` completes?246*/247value2: Uri | Location | SymbolInformation;248249/**250* Optional method which fills in the details of the anchor.251*252* THis is currently only implemented for symbol links.253*/254resolve?(token: CancellationToken): Thenable<void>;255}256257export class ChatResponseExtensionsPart {258259readonly extensions: string[];260261constructor(extensions: string[]);262}263264export class ChatResponsePullRequestPart {265readonly uri: Uri;266readonly linkTag: string;267readonly title: string;268readonly description: string;269readonly author: string;270constructor(uri: Uri, title: string, description: string, author: string, linkTag: string);271}272273export interface ChatResponseStream {274275/**276* Push a progress part to this stream. Short-hand for277* `push(new ChatResponseProgressPart(value))`.278*279* @param value A progress message280* @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.281* @returns This stream.282*/283progress(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>): void;284285thinkingProgress(thinkingDelta: ThinkingDelta): void;286287textEdit(target: Uri, edits: TextEdit | TextEdit[]): void;288289textEdit(target: Uri, isDone: true): void;290291notebookEdit(target: Uri, edits: NotebookEdit | NotebookEdit[]): void;292293notebookEdit(target: Uri, isDone: true): void;294295markdownWithVulnerabilities(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]): void;296codeblockUri(uri: Uri, isEdit?: boolean): void;297push(part: ChatResponsePart | ChatResponseTextEditPart | ChatResponseWarningPart | ChatResponseProgressPart2): void;298299/**300* Show an inline message in the chat view asking the user to confirm an action.301* Multiple confirmations may be shown per response. The UI might show "Accept All" / "Reject All" actions.302* @param title The title of the confirmation entry303* @param message An extra message to display to the user304* @param data An arbitrary JSON-stringifiable object that will be included in the ChatRequest when305* the confirmation is accepted or rejected306* TODO@API should this be MarkdownString?307* TODO@API should actually be a more generic function that takes an array of buttons308*/309confirmation(title: string, message: string | MarkdownString, data: any, buttons?: string[]): void;310311/**312* Push a warning to this stream. Short-hand for313* `push(new ChatResponseWarningPart(message))`.314*315* @param message A warning message316* @returns This stream.317*/318warning(message: string | MarkdownString): void;319320reference(value: Uri | Location | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { light: Uri; dark: Uri }): void;321322reference2(value: Uri | Location | string | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { light: Uri; dark: Uri }, options?: { status?: { description: string; kind: ChatResponseReferencePartStatusKind } }): void;323324codeCitation(value: Uri, license: string, snippet: string): void;325326prepareToolInvocation(toolName: string): void;327328push(part: ExtendedChatResponsePart): void;329330clearToPreviousToolInvocation(reason: ChatResponseClearToPreviousToolInvocationReason): void;331}332333export enum ChatResponseReferencePartStatusKind {334Complete = 1,335Partial = 2,336Omitted = 3337}338339export type ThinkingDelta = {340text?: string | string[];341id: string;342metadata?: { readonly [key: string]: any };343} | {344text?: string | string[];345id?: string;346metadata: { readonly [key: string]: any };347} |348{349text: string | string[];350id?: string;351metadata?: { readonly [key: string]: any };352};353354export enum ChatResponseClearToPreviousToolInvocationReason {355NoReason = 0,356FilteredContentRetry = 1,357CopyrightContentRetry = 2,358}359360/**361* Does this piggy-back on the existing ChatRequest, or is it a different type of request entirely?362* Does it show up in history?363*/364export interface ChatRequest {365/**366* The `data` for any confirmations that were accepted367*/368acceptedConfirmationData?: any[];369370/**371* The `data` for any confirmations that were rejected372*/373rejectedConfirmationData?: any[];374}375376export interface ChatRequest {377378/**379* A map of all tools that should (`true`) and should not (`false`) be used in this request.380*/381readonly tools: Map<string, boolean>;382}383384export namespace lm {385/**386* Fired when the set of tools on a chat request changes.387*/388export const onDidChangeChatRequestTools: Event<ChatRequest>;389}390391export class LanguageModelToolExtensionSource {392/**393* ID of the extension that published the tool.394*/395readonly id: string;396397/**398* Label of the extension that published the tool.399*/400readonly label: string;401402private constructor(id: string, label: string);403}404405export class LanguageModelToolMCPSource {406/**407* Editor-configured label of the MCP server that published the tool.408*/409readonly label: string;410411/**412* Server-defined name of the MCP server.413*/414readonly name: string;415416/**417* Server-defined instructions for MCP tool use.418*/419readonly instructions?: string;420421private constructor(label: string, name: string, instructions?: string);422}423424export interface LanguageModelToolInformation {425source: LanguageModelToolExtensionSource | LanguageModelToolMCPSource | undefined;426}427428// TODO@API fit this into the stream429export interface ChatUsedContext {430documents: ChatDocumentContext[];431}432433export interface ChatParticipant {434/**435* Provide a set of variables that can only be used with this participant.436*/437participantVariableProvider?: { provider: ChatParticipantCompletionItemProvider; triggerCharacters: string[] };438439/**440* Event that fires when a request is paused or unpaused.441* Chat requests are initially unpaused in the {@link requestHandler}.442*/443onDidChangePauseState: Event<ChatParticipantPauseStateEvent>;444}445446export interface ChatParticipantPauseStateEvent {447request: ChatRequest;448isPaused: boolean;449}450451export interface ChatParticipantCompletionItemProvider {452provideCompletionItems(query: string, token: CancellationToken): ProviderResult<ChatCompletionItem[]>;453}454455export class ChatCompletionItem {456id: string;457label: string | CompletionItemLabel;458values: ChatVariableValue[];459fullName?: string;460icon?: ThemeIcon;461insertText?: string;462detail?: string;463documentation?: string | MarkdownString;464command?: Command;465466constructor(id: string, label: string | CompletionItemLabel, values: ChatVariableValue[]);467}468469export type ChatExtendedRequestHandler = (request: ChatRequest, context: ChatContext, response: ChatResponseStream, token: CancellationToken) => ProviderResult<ChatResult | void>;470471export interface ChatResult {472nextQuestion?: {473prompt: string;474participant?: string;475command?: string;476};477/**478* An optional detail string that will be rendered at the end of the response in certain UI contexts.479*/480details?: string;481}482483export namespace chat {484/**485* Create a chat participant with the extended progress type486*/487export function createChatParticipant(id: string, handler: ChatExtendedRequestHandler): ChatParticipant;488}489490/*491* User action events492*/493494export enum ChatCopyKind {495// Keyboard shortcut or context menu496Action = 1,497Toolbar = 2498}499500export interface ChatCopyAction {501// eslint-disable-next-line local/vscode-dts-string-type-literals502kind: 'copy';503codeBlockIndex: number;504copyKind: ChatCopyKind;505copiedCharacters: number;506totalCharacters: number;507copiedText: string;508totalLines: number;509copiedLines: number;510modelId: string;511languageId?: string;512}513514export interface ChatInsertAction {515// eslint-disable-next-line local/vscode-dts-string-type-literals516kind: 'insert';517codeBlockIndex: number;518totalCharacters: number;519totalLines: number;520languageId?: string;521modelId: string;522newFile?: boolean;523}524525export interface ChatApplyAction {526// eslint-disable-next-line local/vscode-dts-string-type-literals527kind: 'apply';528codeBlockIndex: number;529totalCharacters: number;530totalLines: number;531languageId?: string;532modelId: string;533newFile?: boolean;534codeMapper?: string;535}536537export interface ChatTerminalAction {538// eslint-disable-next-line local/vscode-dts-string-type-literals539kind: 'runInTerminal';540codeBlockIndex: number;541languageId?: string;542}543544export interface ChatCommandAction {545// eslint-disable-next-line local/vscode-dts-string-type-literals546kind: 'command';547commandButton: ChatCommandButton;548}549550export interface ChatFollowupAction {551// eslint-disable-next-line local/vscode-dts-string-type-literals552kind: 'followUp';553followup: ChatFollowup;554}555556export interface ChatBugReportAction {557// eslint-disable-next-line local/vscode-dts-string-type-literals558kind: 'bug';559}560561export interface ChatEditorAction {562// eslint-disable-next-line local/vscode-dts-string-type-literals563kind: 'editor';564accepted: boolean;565}566567export interface ChatEditingSessionAction {568// eslint-disable-next-line local/vscode-dts-string-type-literals569kind: 'chatEditingSessionAction';570uri: Uri;571hasRemainingEdits: boolean;572outcome: ChatEditingSessionActionOutcome;573}574575export interface ChatEditingHunkAction {576// eslint-disable-next-line local/vscode-dts-string-type-literals577kind: 'chatEditingHunkAction';578uri: Uri;579lineCount: number;580linesAdded: number;581linesRemoved: number;582outcome: ChatEditingSessionActionOutcome;583hasRemainingEdits: boolean;584}585586export enum ChatEditingSessionActionOutcome {587Accepted = 1,588Rejected = 2,589Saved = 3590}591592export interface ChatUserActionEvent {593readonly result: ChatResult;594readonly action: ChatCopyAction | ChatInsertAction | ChatApplyAction | ChatTerminalAction | ChatCommandAction | ChatFollowupAction | ChatBugReportAction | ChatEditorAction | ChatEditingSessionAction | ChatEditingHunkAction;595}596597export interface ChatPromptReference {598/**599* TODO Needed for now to drive the variableName-type reference, but probably both of these should go away in the future.600*/601readonly name: string;602603/**604* The list of tools were referenced in the value of the reference605*/606readonly toolReferences?: readonly ChatLanguageModelToolReference[];607}608609export interface ChatResultFeedback {610readonly unhelpfulReason?: string;611}612613export namespace lm {614export function fileIsIgnored(uri: Uri, token?: CancellationToken): Thenable<boolean>;615}616617export interface ChatVariableValue {618/**619* 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.620*/621level: ChatVariableLevel;622623/**624* 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.625*/626value: string | Uri;627628/**629* A description of this value, which could be provided to the LLM as a hint.630*/631description?: string;632}633634/**635* The detail level of this chat variable value.636*/637export enum ChatVariableLevel {638Short = 1,639Medium = 2,640Full = 3641}642643export interface LanguageModelToolInvocationOptions<T> {644model?: LanguageModelChat;645}646647export interface ChatRequest {648modeInstructions?: string;649modeInstructionsToolReferences?: readonly ChatLanguageModelToolReference[];650}651}652653654