Update chat-agent-sample for the slash command changes that will go out in the next day's Insiders build (#940)

This commit is contained in:
Rob Lourens
2024-01-18 20:00:07 -03:00
committed by GitHub
parent 7795e7b7bb
commit 4e7619b851
4 changed files with 35 additions and 29 deletions

View File

@ -9,7 +9,7 @@
},
"version": "0.1.0",
"engines": {
"vscode": "^1.84.0"
"vscode": "^1.86.0"
},
"extensionDependencies": [
"github.copilot-chat"

View File

@ -3,14 +3,14 @@ import * as vscode from 'vscode';
const MEOW_COMMAND_ID = 'cat.meow';
interface ICatChatAgentResult extends vscode.ChatAgentResult2 {
slashCommand: string;
subCommand: string;
}
export function activate(context: vscode.ExtensionContext) {
// Define a Cat chat agent handler.
const handler: vscode.ChatAgentHandler = async (request: vscode.ChatAgentRequest, context: vscode.ChatAgentContext, progress: vscode.Progress<vscode.ChatAgentProgress>, token: vscode.CancellationToken): Promise<ICatChatAgentResult> => {
// To talk to an LLM in your slash command handler implementation, your
// To talk to an LLM in your subcommand handler implementation, your
// extension can use VS Code's `requestChatAccess` API to access the Copilot API.
// The GitHub Copilot Chat extension implements this provider.
if (request.subCommand == 'teach') {
@ -31,7 +31,7 @@ export function activate(context: vscode.ExtensionContext) {
for await (const fragment of chatRequest.response) {
progress.report({ content: fragment });
}
return { slashCommand: 'teach' };
return { subCommand: 'teach' };
} else if (request.subCommand == 'play') {
const access = await vscode.chat.requestChatAccess('copilot');
const messages = [
@ -48,7 +48,7 @@ export function activate(context: vscode.ExtensionContext) {
for await (const fragment of chatRequest.response) {
progress.report({ content: fragment });
}
return { slashCommand: 'play' };
return { subCommand: 'play' };
} else {
const access = await vscode.chat.requestChatAccess('copilot');
const messages = [
@ -66,7 +66,7 @@ export function activate(context: vscode.ExtensionContext) {
progress.report({ content: fragment });
}
return { slashCommand: '' };
return { subCommand: '' };
}
};
@ -77,8 +77,8 @@ export function activate(context: vscode.ExtensionContext) {
agent.iconPath = vscode.Uri.joinPath(context.extensionUri, 'cat.jpeg');
agent.description = vscode.l10n.t('Meow! What can I help you with?');
agent.fullName = vscode.l10n.t('Cat');
agent.slashCommandProvider = {
provideSlashCommands(token) {
agent.subCommandProvider = {
provideSubCommands(token) {
return [
{ name: 'teach', description: 'Pick at random a computer science concept then explain it in purfect way of a cat' },
{ name: 'play', description: 'Do whatever you want, you are a cat after all' }
@ -88,13 +88,13 @@ export function activate(context: vscode.ExtensionContext) {
agent.followupProvider = {
provideFollowups(result: ICatChatAgentResult, token: vscode.CancellationToken) {
if (result.slashCommand === 'teach') {
if (result.subCommand === 'teach') {
return [{
commandId: MEOW_COMMAND_ID,
message: '@cat thank you',
title: vscode.l10n.t('Meow!')
}];
} else if (result.slashCommand === 'play') {
} else if (result.subCommand === 'play') {
return [{
message: '@cat let us play',
title: vscode.l10n.t('Play with the cat')

View File

@ -83,12 +83,12 @@ declare module 'vscode' {
readonly kind: ChatAgentResultFeedbackKind;
}
export interface ChatAgentSlashCommand {
export interface ChatAgentSubCommand {
/**
* A short name by which this command is referred to in the UI, e.g. `fix` or
* `explain` for commands that fix an issue or explain code.
*
* **Note**: The name should be unique among the slash commands provided by this agent.
* **Note**: The name should be unique among the subCommands provided by this agent.
*/
readonly name: string;
@ -98,39 +98,39 @@ declare module 'vscode' {
readonly description: string;
/**
* When the user clicks this slash command in `/help`, this text will be submitted to this slash command
* When the user clicks this subCommand in `/help`, this text will be submitted to this subCommand
*/
readonly sampleRequest?: string;
/**
* Whether executing the command puts the
* chat into a persistent mode, where the
* slash command is prepended to the chat input.
* subCommand is prepended to the chat input.
*/
readonly shouldRepopulate?: boolean;
/**
* Placeholder text to render in the chat input
* when the slash command has been repopulated.
* when the subCommand has been repopulated.
* Has no effect if `shouldRepopulate` is `false`.
*/
// TODO@API merge this with shouldRepopulate? so that invalid state cannot be represented?
readonly followupPlaceholder?: string;
}
export interface ChatAgentSlashCommandProvider {
export interface ChatAgentSubCommandProvider {
/**
* Returns a list of slash commands that its agent is capable of handling. A slash command
* Returns a list of subCommands that its agent is capable of handling. A subCommand
* can be selected by the user and will then be passed to the {@link ChatAgentHandler handler}
* via the {@link ChatAgentRequest.slashCommand slashCommand} property.
* via the {@link ChatAgentRequest.subCommand subCommand} property.
*
*
* @param token A cancellation token.
* @returns A list of slash commands. The lack of a result can be signaled by returning `undefined`, `null`, or
* @returns A list of subCommands. The lack of a result can be signaled by returning `undefined`, `null`, or
* an empty array.
*/
provideSlashCommands(token: CancellationToken): ProviderResult<ChatAgentSlashCommand[]>;
provideSubCommands(token: CancellationToken): ProviderResult<ChatAgentSubCommand[]>;
}
// TODO@API This should become a progress type, and use vscode.Command
@ -208,9 +208,9 @@ declare module 'vscode' {
} | ThemeIcon;
/**
* This provider will be called to retrieve the agent's slash commands.
* This provider will be called to retrieve the agent's subCommands.
*/
slashCommandProvider?: ChatAgentSlashCommandProvider;
subCommandProvider?: ChatAgentSubCommandProvider;
/**
* This provider will be called once after each request to retrieve suggested followup questions.
@ -218,7 +218,7 @@ declare module 'vscode' {
followupProvider?: FollowupProvider<TResult>;
/**
* When the user clicks this agent in `/help`, this text will be submitted to this slash command
* When the user clicks this agent in `/help`, this text will be submitted to this subCommand
*/
sampleRequest?: string;
@ -240,10 +240,10 @@ declare module 'vscode' {
export interface ChatAgentRequest {
/**
* The prompt entered by the user. The {@link ChatAgent2.name name} of the agent or the {@link ChatAgentSlashCommand.name slash command}
* The prompt entered by the user. The {@link ChatAgent2.name name} of the agent or the {@link ChatAgentSubCommand.name subCommand}
* are not part of the prompt.
*
* @see {@link ChatAgentRequest.slashCommand}
* @see {@link ChatAgentRequest.subCommand}
*/
prompt: string;
@ -253,14 +253,14 @@ declare module 'vscode' {
agentId: string;
/**
* The {@link ChatAgentSlashCommand slash command} that was selected for this request. It is guaranteed that the passed slash
* command is an instance that was previously returned from the {@link ChatAgentSlashCommandProvider.provideSlashCommands slash command provider}.
* The {@link ChatAgentSubCommand subCommand} that was selected for this request. It is guaranteed that the passed subCommand
* is an instance that was previously returned from the {@link ChatAgentSubCommandProvider.provideSubCommands subCommand provider}.
* @deprecated this will be replaced by `subCommand`
*/
slashCommand?: ChatAgentSlashCommand;
slashCommand?: ChatAgentSubCommand;
/**
* The name of the {@link ChatAgentSlashCommand slash command} that was selected for this request.
* The name of the {@link ChatAgentSubCommand subCommand} that was selected for this request.
*/
subCommand?: string;

View File

@ -67,6 +67,12 @@ declare module 'vscode' {
*/
isRevoked: boolean;
/**
* The name of the model that is used for this chat access. It is expected that the model name can
* be used to lookup properties like token limits and ChatML support
*/
model: string;
/**
* Make a chat request.
*