mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Merge pull request #939 from microsoft/roblou/tiny-baboon
Update chat agent sample
This commit is contained in:
@ -13,7 +13,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
// To talk to an LLM in your slash command 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.slashCommand?.name == 'teach') {
|
||||
if (request.subCommand == 'teach') {
|
||||
const access = await vscode.chat.requestChatAccess('copilot');
|
||||
const topics = ['linked list', 'recursion', 'stack', 'queue', 'pointers'];
|
||||
const topic = topics[Math.floor(Math.random() * topics.length)];
|
||||
@ -32,7 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
progress.report({ content: fragment });
|
||||
}
|
||||
return { slashCommand: 'teach' };
|
||||
} else if (request.slashCommand?.name == 'play') {
|
||||
} else if (request.subCommand == 'play') {
|
||||
const access = await vscode.chat.requestChatAccess('copilot');
|
||||
const messages = [
|
||||
{
|
||||
|
||||
@ -5,11 +5,17 @@
|
||||
|
||||
declare module 'vscode' {
|
||||
|
||||
export interface ChatAgentHistoryEntry {
|
||||
request: ChatAgentRequest;
|
||||
response: ChatAgentContentProgress[];
|
||||
result: ChatAgentResult2;
|
||||
}
|
||||
|
||||
export interface ChatAgentContext {
|
||||
/**
|
||||
* All of the chat messages so far in the current chat session.
|
||||
*/
|
||||
history: ChatMessage[];
|
||||
history: ChatAgentHistoryEntry[];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,12 +70,12 @@ declare module 'vscode' {
|
||||
/**
|
||||
* Represents user feedback for a result.
|
||||
*/
|
||||
export interface ChatAgentResult2Feedback {
|
||||
export interface ChatAgentResult2Feedback<TResult extends ChatAgentResult2> {
|
||||
/**
|
||||
* This instance of ChatAgentResult2 is the same instance that was returned from the chat agent,
|
||||
* and it can be extended with arbitrary properties if needed.
|
||||
*/
|
||||
readonly result: ChatAgentResult2;
|
||||
readonly result: TResult;
|
||||
|
||||
/**
|
||||
* The kind of feedback that was received.
|
||||
@ -102,11 +108,13 @@ declare module 'vscode' {
|
||||
* slash command is prepended to the chat input.
|
||||
*/
|
||||
readonly shouldRepopulate?: boolean;
|
||||
|
||||
/**
|
||||
* Placeholder text to render in the chat input
|
||||
* when the slash command 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;
|
||||
}
|
||||
|
||||
@ -159,16 +167,16 @@ declare module 'vscode' {
|
||||
/**
|
||||
* Will be invoked once after each request to get suggested followup questions to show the user. The user can click the followup to send it to the chat.
|
||||
*/
|
||||
export interface FollowupProvider {
|
||||
export interface FollowupProvider<TResult extends ChatAgentResult2> {
|
||||
/**
|
||||
*
|
||||
* @param result The same instance of the result object that was returned by the chat agent, and it can be extended with arbitrary properties if needed.
|
||||
* @param token A cancellation token.
|
||||
*/
|
||||
provideFollowups(result: ChatAgentResult2, token: CancellationToken): ProviderResult<ChatAgentFollowup[]>;
|
||||
provideFollowups(result: TResult, token: CancellationToken): ProviderResult<ChatAgentFollowup[]>;
|
||||
}
|
||||
|
||||
export interface ChatAgent2 {
|
||||
export interface ChatAgent2<TResult extends ChatAgentResult2> {
|
||||
|
||||
/**
|
||||
* The short name by which this agent is referred to in the UI, e.g `workspace`.
|
||||
@ -207,7 +215,7 @@ declare module 'vscode' {
|
||||
/**
|
||||
* This provider will be called once after each request to retrieve suggested followup questions.
|
||||
*/
|
||||
followupProvider?: FollowupProvider;
|
||||
followupProvider?: FollowupProvider<TResult>;
|
||||
|
||||
/**
|
||||
* When the user clicks this agent in `/help`, this text will be submitted to this slash command
|
||||
@ -221,10 +229,9 @@ declare module 'vscode' {
|
||||
* The passed {@link ChatAgentResult2Feedback.result result} is guaranteed to be the same instance that was
|
||||
* previously returned from this chat agent.
|
||||
*/
|
||||
onDidReceiveFeedback: Event<ChatAgentResult2Feedback>;
|
||||
onDidReceiveFeedback: Event<ChatAgentResult2Feedback<TResult>>;
|
||||
|
||||
/**
|
||||
* TODO@API explain what happens wrt to history, in-flight requests etc...
|
||||
* Dispose this agent and free resources
|
||||
*/
|
||||
dispose(): void;
|
||||
@ -240,23 +247,45 @@ declare module 'vscode' {
|
||||
*/
|
||||
prompt: string;
|
||||
|
||||
/**
|
||||
* The ID of the chat agent to which this request was directed.
|
||||
*/
|
||||
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}.
|
||||
* @deprecated this will be replaced by `subCommand`
|
||||
*/
|
||||
slashCommand?: ChatAgentSlashCommand;
|
||||
|
||||
/**
|
||||
* The name of the {@link ChatAgentSlashCommand slash command} that was selected for this request.
|
||||
*/
|
||||
subCommand?: string;
|
||||
|
||||
variables: Record<string, ChatVariableValue[]>;
|
||||
}
|
||||
|
||||
// TODO@API should these each be prefixed ChatAgentProgress*?
|
||||
export type ChatAgentProgress =
|
||||
export type ChatAgentContentProgress =
|
||||
| ChatAgentContent
|
||||
| ChatAgentTask
|
||||
| ChatAgentFileTree
|
||||
| ChatAgentInlineContentReference
|
||||
| ChatAgentTask;
|
||||
|
||||
export type ChatAgentMetadataProgress =
|
||||
| ChatAgentUsedContext
|
||||
| ChatAgentContentReference
|
||||
| ChatAgentInlineContentReference;
|
||||
| ChatAgentProgressMessage;
|
||||
|
||||
export type ChatAgentProgress = ChatAgentContentProgress | ChatAgentMetadataProgress;
|
||||
|
||||
/**
|
||||
* Is displayed in the UI to communicate steps of progress to the user. Should be used when the agent may be slow to respond, e.g. due to doing extra work before sending the actual request to the LLM.
|
||||
*/
|
||||
export interface ChatAgentProgressMessage {
|
||||
message: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates a piece of content that was used by the chat agent while processing the request. Will be displayed to the user.
|
||||
@ -306,6 +335,8 @@ declare module 'vscode' {
|
||||
/**
|
||||
* A Thenable resolving to the real content. The placeholder will be replaced with this content once it's available.
|
||||
*/
|
||||
// TODO@API Should this be an async iterable or progress instance instead
|
||||
// TODO@API Should this include more inline-renderable items like `ChatAgentInlineContentReference`
|
||||
resolvedContent: Thenable<ChatAgentContent | ChatAgentFileTree>;
|
||||
}
|
||||
|
||||
@ -331,8 +362,17 @@ declare module 'vscode' {
|
||||
/**
|
||||
* A Uri for this node, opened when it's clicked.
|
||||
*/
|
||||
// TODO@API why label and uri. Can the former be derived from the latter?
|
||||
// TODO@API don't use uri but just names? This API allows to to build nonsense trees where the data structure doesn't match the uris
|
||||
// path-structure.
|
||||
uri: Uri;
|
||||
|
||||
/**
|
||||
* The type of this node. Defaults to {@link FileType.Directory} if it has {@link ChatAgentFileTreeData.children children}.
|
||||
*/
|
||||
// TODO@API cross API usage
|
||||
type?: FileType;
|
||||
|
||||
/**
|
||||
* The children of this node.
|
||||
*/
|
||||
@ -363,6 +403,57 @@ declare module 'vscode' {
|
||||
* @param handler The reply-handler of the agent.
|
||||
* @returns A new chat agent
|
||||
*/
|
||||
export function createChatAgent(name: string, handler: ChatAgentHandler): ChatAgent2;
|
||||
export function createChatAgent<TResult extends ChatAgentResult2>(name: string, handler: ChatAgentHandler): ChatAgent2<TResult>;
|
||||
|
||||
/**
|
||||
* Register a variable which can be used in a chat request to any agent.
|
||||
* @param name The name of the variable, to be used in the chat input as `#name`.
|
||||
* @param description A description of the variable for the chat input suggest widget.
|
||||
* @param resolver Will be called to provide the chat variable's value when it is used.
|
||||
*/
|
||||
export function registerVariable(name: string, description: string, resolver: ChatVariableResolver): Disposable;
|
||||
}
|
||||
|
||||
/**
|
||||
* The detail level of this chat variable value.
|
||||
*/
|
||||
export enum ChatVariableLevel {
|
||||
Short = 1,
|
||||
Medium = 2,
|
||||
Full = 3
|
||||
}
|
||||
|
||||
export interface ChatVariableValue {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
level: ChatVariableLevel;
|
||||
|
||||
/**
|
||||
* The variable's value, which can be included in an LLM prompt as-is, or the chat agent may decide to read the value and do something else with it.
|
||||
*/
|
||||
value: string | Uri;
|
||||
|
||||
/**
|
||||
* A description of this value, which could be provided to the LLM as a hint.
|
||||
*/
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface ChatVariableContext {
|
||||
/**
|
||||
* The message entered by the user, which includes this variable.
|
||||
*/
|
||||
prompt: string;
|
||||
}
|
||||
|
||||
export interface ChatVariableResolver {
|
||||
/**
|
||||
* A callback to resolve the value of a chat variable.
|
||||
* @param name The name of the variable.
|
||||
* @param context Contextual information about this chat request.
|
||||
* @param token A cancellation token.
|
||||
*/
|
||||
resolve(name: string, context: ChatVariableContext, token: CancellationToken): ProviderResult<ChatVariableValue[]>;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare module 'vscode' {
|
||||
|
||||
export interface InteractiveRequest {
|
||||
variables: Record<string, ChatVariableValue[]>;
|
||||
}
|
||||
|
||||
export enum ChatVariableLevel {
|
||||
Short = 1,
|
||||
Medium = 2,
|
||||
Full = 3
|
||||
}
|
||||
|
||||
export interface ChatVariableValue {
|
||||
level: ChatVariableLevel;
|
||||
value: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface ChatVariableContext {
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface ChatVariableResolver {
|
||||
resolve(name: string, context: ChatVariableContext, token: CancellationToken): ProviderResult<ChatVariableValue[]>;
|
||||
}
|
||||
|
||||
export namespace chat {
|
||||
export function registerVariable(name: string, description: string, resolver: ChatVariableResolver): Disposable;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user