Path: blob/main/extensions/copilot/test/simulation/fixtures/edit/issue-5755/vscode.proposed.chatParticipantAdditions.d.ts
13405 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' {67/**8* The location at which the chat is happening.9*/10export enum ChatLocation {11/**12* The chat panel13*/14Panel = 1,15/**16* Terminal inline chat17*/18Terminal = 2,19/**20* Notebook inline chat21*/22Notebook = 3,23/**24* Code editor inline chat25*/26Editor = 427}2829export interface ChatRequest {30/**31* The attempt number of the request. The first request has attempt number 0.32*/33readonly attempt: number;3435/**36* If automatic command detection is enabled.37*/38readonly enableCommandDetection: boolean;3940/**41* The location at which the chat is happening. This will always be one of the supported values42*/43readonly location: ChatLocation;44}4546export interface ChatParticipant {47onDidPerformAction: Event<ChatUserActionEvent>;48supportIssueReporting?: boolean;4950/**51* Temp, support references that are slow to resolve and should be tools rather than references.52*/53supportsSlowReferences?: boolean;54}5556export interface ChatErrorDetails {57/**58* If set to true, the message content is completely hidden. Only ChatErrorDetails#message will be shown.59*/60responseIsRedacted?: boolean;61}6263/**64* Now only used for the "intent detection" API below65*/66export interface ChatCommand {67readonly name: string;68readonly description: string;69}7071export class ChatResponseDetectedParticipantPart {72participant: string;73// TODO@API validate this against statically-declared slash commands?74command?: ChatCommand;75constructor(participant: string, command?: ChatCommand);76}7778export interface ChatVulnerability {79title: string;80description: string;81// id: string; // Later we will need to be able to link these across multiple content chunks.82}8384export class ChatResponseMarkdownWithVulnerabilitiesPart {85value: MarkdownString;86vulnerabilities: ChatVulnerability[];87constructor(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]);88}8990/**91* Displays a {@link Command command} as a button in the chat response.92*/93export interface ChatCommandButton {94command: Command;95}9697export interface ChatDocumentContext {98uri: Uri;99version: number;100ranges: Range[];101}102103export class ChatResponseTextEditPart {104uri: Uri;105edits: TextEdit[];106constructor(uri: Uri, edits: TextEdit | TextEdit[]);107}108109export class ChatResponseConfirmationPart {110title: string;111message: string;112data: any;113constructor(title: string, message: string, data: any);114}115116export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseDetectedParticipantPart | ChatResponseConfirmationPart;117118export class ChatResponseWarningPart {119value: MarkdownString;120constructor(value: string | MarkdownString);121}122123export class ChatResponseProgressPart2 extends ChatResponseProgressPart {124value: string;125task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>;126constructor(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>);127}128129export interface ChatResponseStream {130131/**132* Push a progress part to this stream. Short-hand for133* `push(new ChatResponseProgressPart(value))`.134*135* @param value A progress message136* @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.137* @returns This stream.138*/139progress(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>): void;140141textEdit(target: Uri, edits: TextEdit | TextEdit[]): void;142markdownWithVulnerabilities(value: string | MarkdownString, vulnerabilities: ChatVulnerability[]): void;143detectedParticipant(participant: string, command?: ChatCommand): void;144push(part: ChatResponsePart | ChatResponseTextEditPart | ChatResponseDetectedParticipantPart | ChatResponseWarningPart | ChatResponseProgressPart2): void;145146/**147* Show an inline message in the chat view asking the user to confirm an action.148* Multiple confirmations may be shown per response. The UI might show "Accept All" / "Reject All" actions.149* @param title The title of the confirmation entry150* @param message An extra message to display to the user151* @param data An arbitrary JSON-stringifiable object that will be included in the ChatRequest when152* the confirmation is accepted or rejected153* TODO@API should this be MarkdownString?154* TODO@API should actually be a more generic function that takes an array of buttons155*/156confirmation(title: string, message: string, data: any): void;157158/**159* Push a warning to this stream. Short-hand for160* `push(new ChatResponseWarningPart(message))`.161*162* @param message A warning message163* @returns This stream.164*/165warning(message: string | MarkdownString): void;166167reference(value: Uri | Location | { variableName: string; value?: Uri | Location }, iconPath?: Uri | ThemeIcon | { light: Uri; dark: Uri }): void;168169push(part: ExtendedChatResponsePart): void;170}171172/**173* Does this piggy-back on the existing ChatRequest, or is it a different type of request entirely?174* Does it show up in history?175*/176export interface ChatRequest {177/**178* The `data` for any confirmations that were accepted179*/180acceptedConfirmationData?: any[];181182/**183* The `data` for any confirmations that were rejected184*/185rejectedConfirmationData?: any[];186}187188// TODO@API fit this into the stream189export interface ChatUsedContext {190documents: ChatDocumentContext[];191}192193export interface ChatParticipant {194/**195* Provide a set of variables that can only be used with this participant.196*/197participantVariableProvider?: { provider: ChatParticipantCompletionItemProvider; triggerCharacters: string[] };198}199200export interface ChatParticipantCompletionItemProvider {201provideCompletionItems(query: string, token: CancellationToken): ProviderResult<ChatCompletionItem[]>;202}203204export class ChatCompletionItem {205id: string;206label: string | CompletionItemLabel;207values: ChatVariableValue[];208insertText?: string;209fullName?: string;210icon?: ThemeIcon;211detail?: string;212documentation?: string | MarkdownString;213command?: Command;214215constructor(id: string, label: string | CompletionItemLabel, values: ChatVariableValue[]);216}217218export type ChatExtendedRequestHandler = (request: ChatRequest, context: ChatContext, response: ChatResponseStream, token: CancellationToken) => ProviderResult<ChatResult | void>;219220export namespace chat {221/**222* Create a chat participant with the extended progress type223*/224export function createChatParticipant(id: string, handler: ChatExtendedRequestHandler): ChatParticipant;225226export function createDynamicChatParticipant(id: string, dynamicProps: DynamicChatParticipantProps, handler: ChatExtendedRequestHandler): ChatParticipant;227228/**229* Current version of the proposal. Changes whenever backwards-incompatible changes are made.230* 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.231* But if a change is made to an existing feature that would break existing code, the version should be incremented.232* The chat extension should not activate if it doesn't support the current version.233*/234export const _version: 1 | number;235}236237/**238* 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.239*/240export interface DynamicChatParticipantProps {241name: string;242publisherName: string;243description?: string;244fullName?: string;245}246247/*248* User action events249*/250251export enum ChatCopyKind {252// Keyboard shortcut or context menu253Action = 1,254Toolbar = 2255}256257export interface ChatCopyAction {258// eslint-disable-next-line local/vscode-dts-string-type-literals259kind: 'copy';260codeBlockIndex: number;261copyKind: ChatCopyKind;262copiedCharacters: number;263totalCharacters: number;264copiedText: string;265}266267export interface ChatInsertAction {268// eslint-disable-next-line local/vscode-dts-string-type-literals269kind: 'insert';270codeBlockIndex: number;271totalCharacters: number;272newFile?: boolean;273}274275export interface ChatTerminalAction {276// eslint-disable-next-line local/vscode-dts-string-type-literals277kind: 'runInTerminal';278codeBlockIndex: number;279languageId?: string;280}281282export interface ChatCommandAction {283// eslint-disable-next-line local/vscode-dts-string-type-literals284kind: 'command';285commandButton: ChatCommandButton;286}287288export interface ChatFollowupAction {289// eslint-disable-next-line local/vscode-dts-string-type-literals290kind: 'followUp';291followup: ChatFollowup;292}293294export interface ChatBugReportAction {295// eslint-disable-next-line local/vscode-dts-string-type-literals296kind: 'bug';297}298299export interface ChatEditorAction {300kind: 'editor';301accepted: boolean;302}303304export interface ChatUserActionEvent {305readonly result: ChatResult;306readonly action: ChatCopyAction | ChatInsertAction | ChatTerminalAction | ChatCommandAction | ChatFollowupAction | ChatBugReportAction | ChatEditorAction;307}308309export interface ChatPromptReference {310/**311* TODO Needed for now to drive the variableName-type reference, but probably both of these should go away in the future.312*/313readonly name: string;314}315316/**317* The detail level of this chat variable value.318*/319export enum ChatVariableLevel {320Short = 1,321Medium = 2,322Full = 3323}324325export interface ChatVariableValue {326/**327* 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.328*/329level: ChatVariableLevel;330331/**332* 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.333*/334value: string | Uri;335336/**337* A description of this value, which could be provided to the LLM as a hint.338*/339description?: string;340}341342export interface ChatVariableResolverResponseStream {343/**344* Push a progress part to this stream. Short-hand for345* `push(new ChatResponseProgressPart(value))`.346*347* @param value348* @returns This stream.349*/350progress(value: string): ChatVariableResolverResponseStream;351352/**353* Push a reference to this stream. Short-hand for354* `push(new ChatResponseReferencePart(value))`.355*356* *Note* that the reference is not rendered inline with the response.357*358* @param value A uri or location359* @returns This stream.360*/361reference(value: Uri | Location): ChatVariableResolverResponseStream;362363/**364* Pushes a part to this stream.365*366* @param part A response part, rendered or metadata367*/368push(part: ChatVariableResolverResponsePart): ChatVariableResolverResponseStream;369}370371export type ChatVariableResolverResponsePart = ChatResponseProgressPart | ChatResponseReferencePart;372373export interface ChatVariableResolver {374/**375* A callback to resolve the value of a chat variable.376* @param name The name of the variable.377* @param context Contextual information about this chat request.378* @param token A cancellation token.379*/380resolve2?(name: string, context: ChatVariableContext, stream: ChatVariableResolverResponseStream, token: CancellationToken): ProviderResult<ChatVariableValue[]>;381}382}383384385