mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
Adopt chat participant ID (#992)
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
"contributes": {
|
||||
"chatParticipants": [
|
||||
{
|
||||
"id": "chat-sample.cat",
|
||||
"name": "cat",
|
||||
"description": "Meow! What can I teach you?",
|
||||
"commands": [
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const CAT_NAMES_COMMAND_ID = 'cat.namesInEditor';
|
||||
const CAT_PARTICIPANT_NAME = 'cat';
|
||||
const CAT_PARTICIPANT_ID = 'chat-sample.cat';
|
||||
|
||||
interface ICatChatResult extends vscode.ChatResult {
|
||||
metadata: {
|
||||
@ -68,7 +68,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
// Chat participants appear as top-level options in the chat input
|
||||
// when you type `@`, and can contribute sub-commands in the chat input
|
||||
// that appear when you type `/`.
|
||||
const cat = vscode.chat.createChatParticipant(CAT_PARTICIPANT_NAME, handler);
|
||||
const cat = vscode.chat.createChatParticipant(CAT_PARTICIPANT_ID, handler);
|
||||
cat.isSticky = true; // Cat is persistant, whenever a user starts interacting with @cat, @cat will automatically be added to the following messages
|
||||
cat.iconPath = vscode.Uri.joinPath(context.extensionUri, 'cat.jpeg');
|
||||
cat.followupProvider = {
|
||||
@ -163,7 +163,7 @@ function getTopic(history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatRes
|
||||
const topics = ['linked list', 'recursion', 'stack', 'queue', 'pointers'];
|
||||
// Filter the chat history to get only the responses from the cat
|
||||
const previousCatResponses = history.filter(h => {
|
||||
return h instanceof vscode.ChatResponseTurn && h.participant.name == CAT_PARTICIPANT_NAME
|
||||
return h instanceof vscode.ChatResponseTurn && h.participant == CAT_PARTICIPANT_ID
|
||||
}) as vscode.ChatResponseTurn[];
|
||||
// Filter the topics to get only the topics that have not been taught by the cat yet
|
||||
const topicsNoRepetition = topics.filter(topic => {
|
||||
|
||||
@ -21,21 +21,21 @@ declare module 'vscode' {
|
||||
readonly prompt: string;
|
||||
|
||||
/**
|
||||
* The name of the chat participant and contributing extension to which this request was directed.
|
||||
* The id of the chat participant and contributing extension to which this request was directed.
|
||||
*/
|
||||
readonly participant: { readonly extensionId: string; readonly name: string };
|
||||
readonly participant: string;
|
||||
|
||||
/**
|
||||
* The name of the {@link ChatCommand command} that was selected for this request.
|
||||
*/
|
||||
readonly command: string | undefined;
|
||||
readonly command?: string;
|
||||
|
||||
/**
|
||||
* The variables that were referenced in this message.
|
||||
*/
|
||||
readonly variables: ChatResolvedVariable[];
|
||||
|
||||
private constructor(prompt: string, command: string | undefined, variables: ChatResolvedVariable[], participant: { extensionId: string; name: string });
|
||||
private constructor(prompt: string, command: string | undefined, variables: ChatResolvedVariable[], participant: string);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,16 +54,16 @@ declare module 'vscode' {
|
||||
readonly result: ChatResult;
|
||||
|
||||
/**
|
||||
* The name of the chat participant and contributing extension that this response came from.
|
||||
* The id of the chat participant and contributing extension that this response came from.
|
||||
*/
|
||||
readonly participant: { readonly extensionId: string; readonly name: string };
|
||||
readonly participant: string;
|
||||
|
||||
/**
|
||||
* The name of the command that this response came from.
|
||||
*/
|
||||
readonly command?: string;
|
||||
|
||||
private constructor(response: ReadonlyArray<ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>, result: ChatResult, participant: { extensionId: string; name: string });
|
||||
private constructor(response: ReadonlyArray<ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>, result: ChatResult, participant: string);
|
||||
}
|
||||
|
||||
export interface ChatContext {
|
||||
@ -158,7 +158,7 @@ declare module 'vscode' {
|
||||
label?: string;
|
||||
|
||||
/**
|
||||
* By default, the followup goes to the same participant/command. But this property can be set to invoke a different participant.
|
||||
* By default, the followup goes to the same participant/command. But this property can be set to invoke a different participant by ID.
|
||||
* Followups can only invoke a participant that was contributed by the same extension.
|
||||
*/
|
||||
participant?: string;
|
||||
@ -192,9 +192,9 @@ declare module 'vscode' {
|
||||
*/
|
||||
export interface ChatParticipant {
|
||||
/**
|
||||
* The short name by which this participant is referred to in the UI, e.g `workspace`.
|
||||
* A unique ID for this participant.
|
||||
*/
|
||||
readonly name: string;
|
||||
readonly id: string;
|
||||
|
||||
/**
|
||||
* Icon for the participant shown in UI.
|
||||
@ -263,12 +263,33 @@ declare module 'vscode' {
|
||||
* *Note* that the indices take the leading `#`-character into account which means they can
|
||||
* used to modify the prompt as-is.
|
||||
*/
|
||||
readonly range: [start: number, end: number];
|
||||
readonly range?: [start: number, end: number];
|
||||
|
||||
// TODO@API decouple of resolve API, use `value: string | Uri | (maybe) unknown?`
|
||||
/**
|
||||
* The values of the variable. Can be an empty array if the variable doesn't currently have a value.
|
||||
*/
|
||||
readonly values: ChatVariableValue[];
|
||||
}
|
||||
|
||||
/**
|
||||
* The location at which the chat is happening.
|
||||
*/
|
||||
export enum ChatLocation {
|
||||
/**
|
||||
* The chat panel
|
||||
*/
|
||||
Panel = 1,
|
||||
/**
|
||||
* Terminal inline chat
|
||||
*/
|
||||
Terminal = 2,
|
||||
/**
|
||||
* Notebook inline chat
|
||||
*/
|
||||
Notebook = 3
|
||||
}
|
||||
|
||||
export interface ChatRequest {
|
||||
/**
|
||||
* The prompt as entered by the user.
|
||||
@ -296,6 +317,11 @@ declare module 'vscode' {
|
||||
*/
|
||||
// TODO@API Q? are there implicit variables that are not part of the prompt?
|
||||
readonly variables: readonly ChatResolvedVariable[];
|
||||
|
||||
/**
|
||||
* The location at which the chat is happening. This will always be one of the supported values
|
||||
*/
|
||||
readonly location: ChatLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -420,12 +446,11 @@ declare module 'vscode' {
|
||||
/**
|
||||
* Create a new {@link ChatParticipant chat participant} instance.
|
||||
*
|
||||
* @param name Short name by which the participant is referred to in the UI. The name must be unique for the extension
|
||||
* contributing the participant but can collide with names from other extensions.
|
||||
* @param id A unique identifier for the participant.
|
||||
* @param handler A request handler for the participant.
|
||||
* @returns A new chat participant
|
||||
*/
|
||||
export function createChatParticipant(name: string, handler: ChatRequestHandler): ChatParticipant;
|
||||
export function createChatParticipant(id: string, handler: ChatRequestHandler): ChatParticipant;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user