Get rid of 'slash command' from API (#203924)

Also don't send an empty string for 'subCommand' when there is no slash command selected
This commit is contained in:
Rob Lourens 2024-01-31 16:41:08 -03:00 committed by GitHub
parent 3ad2e082c5
commit 790e20c0f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 41 deletions

View file

@ -9,7 +9,6 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { Emitter } from 'vs/base/common/event';
import { StopWatch } from 'vs/base/common/stopwatch';
import { assertType } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
@ -72,16 +71,12 @@ export class ExtHostChatAgents2 implements ExtHostChatAgentsShape2 {
token.onCancellationRequested(() => commandExecution.complete());
this._extHostChatProvider.allowListExtensionWhile(agent.extension.identifier, commandExecution.p);
const slashCommand = request.command
? await agent.validateSlashCommand(request.command)
: undefined;
const stopWatch = StopWatch.create(false);
let firstProgress: number | undefined;
try {
const convertedHistory = await this.prepareHistory(agent, request, context);
const task = agent.invoke(
typeConvert.ChatAgentRequest.to(request, slashCommand),
typeConvert.ChatAgentRequest.to(request),
{ history: convertedHistory },
new Progress<vscode.ChatAgentExtendedProgress>(progress => {
throwIfDone();
@ -141,7 +136,7 @@ export class ExtHostChatAgents2 implements ExtHostChatAgentsShape2 {
const result = request.agentId === h.request.agentId && this._resultsBySessionAndRequestId.get(request.sessionId)?.get(h.request.requestId)
|| h.result;
return {
request: typeConvert.ChatAgentRequest.to(h.request, undefined),
request: typeConvert.ChatAgentRequest.to(h.request),
response: coalesce(h.response.map(r => typeConvert.ChatResponseProgress.toProgressContent(r))),
result
} satisfies vscode.ChatAgentHistoryEntry;
@ -159,7 +154,7 @@ export class ExtHostChatAgents2 implements ExtHostChatAgentsShape2 {
// this is OK, the agent might have disposed while the request was in flight
return [];
}
return agent.provideSlashCommand(token);
return agent.provideSlashCommands(token);
}
$provideFollowups(handle: number, sessionId: string, token: CancellationToken): Promise<IChatFollowup[]> {
@ -227,8 +222,7 @@ export class ExtHostChatAgents2 implements ExtHostChatAgentsShape2 {
class ExtHostChatAgent<TResult extends vscode.ChatAgentResult2> {
private _slashCommandProvider: vscode.ChatAgentSubCommandProvider | undefined;
private _lastSlashCommands: vscode.ChatAgentSubCommand[] | undefined;
private _subCommandProvider: vscode.ChatAgentSubCommandProvider | undefined;
private _followupProvider: vscode.FollowupProvider<TResult> | undefined;
private _description: string | undefined;
private _fullName: string | undefined;
@ -267,28 +261,14 @@ class ExtHostChatAgent<TResult extends vscode.ChatAgentResult2> {
return await this._agentVariableProvider.provider.provideCompletionItems(query, token) ?? [];
}
async validateSlashCommand(command: string) {
if (!this._lastSlashCommands) {
await this.provideSlashCommand(CancellationToken.None);
assertType(this._lastSlashCommands);
}
const result = this._lastSlashCommands.find(candidate => candidate.name === command);
if (!result) {
throw new Error(`Unknown slashCommand: ${command}`);
}
return result;
}
async provideSlashCommand(token: CancellationToken): Promise<IChatAgentCommand[]> {
if (!this._slashCommandProvider) {
async provideSlashCommands(token: CancellationToken): Promise<IChatAgentCommand[]> {
if (!this._subCommandProvider) {
return [];
}
const result = await this._slashCommandProvider.provideSubCommands(token);
const result = await this._subCommandProvider.provideSubCommands(token);
if (!result) {
return [];
}
this._lastSlashCommands = result;
return result
.map(c => ({
name: c.name,
@ -333,7 +313,7 @@ class ExtHostChatAgent<TResult extends vscode.ChatAgentResult2> {
'dark' in this._iconPath ? this._iconPath.dark :
undefined,
themeIcon: this._iconPath instanceof extHostTypes.ThemeIcon ? this._iconPath : undefined,
hasSlashCommands: this._slashCommandProvider !== undefined,
hasSlashCommands: this._subCommandProvider !== undefined,
hasFollowups: this._followupProvider !== undefined,
isDefault: this._isDefault,
isSecondary: this._isSecondary,
@ -373,10 +353,10 @@ class ExtHostChatAgent<TResult extends vscode.ChatAgentResult2> {
updateMetadataSoon();
},
get subCommandProvider() {
return that._slashCommandProvider;
return that._subCommandProvider;
},
set subCommandProvider(v) {
that._slashCommandProvider = v;
that._subCommandProvider = v;
updateMetadataSoon();
},
get followupProvider() {
@ -470,7 +450,7 @@ class ExtHostChatAgent<TResult extends vscode.ChatAgentResult2> {
,
dispose() {
disposed = true;
that._slashCommandProvider = undefined;
that._subCommandProvider = undefined;
that._followupProvider = undefined;
that._onDidReceiveFeedback.dispose();
that._proxy.$unregisterAgent(that._handle);

View file

@ -2432,11 +2432,10 @@ export namespace ChatResponseProgress {
}
export namespace ChatAgentRequest {
export function to(request: IChatAgentRequest, slashCommand: vscode.ChatAgentSubCommand | undefined): vscode.ChatAgentRequest {
export function to(request: IChatAgentRequest): vscode.ChatAgentRequest {
return {
prompt: request.message,
variables: ChatVariable.objectTo(request.variables),
slashCommand,
subCommand: request.command,
agentId: request.agentId,
};

View file

@ -542,7 +542,7 @@ export class ChatService extends Disposable implements IChatService {
agentId: agent.id,
message: variableData.message,
variables: variableData.variables,
command: agentSlashCommandPart?.command.name ?? '',
command: agentSlashCommandPart?.command.name,
};
const agentResult = await this.chatAgentService.invokeAgent(agent.id, requestProps, progressCallback, history, token);

View file

@ -5,9 +5,23 @@
declare module 'vscode' {
/**
* One request/response pair in chat history.
*/
export interface ChatAgentHistoryEntry {
/**
* The request that was sent to the chat agent.
*/
request: ChatAgentRequest;
/**
* The content that was received from the chat agent. Only the progress parts that represent actual content (not metadata) are represented.
*/
response: ChatAgentContentProgress[];
/**
* The result that was received from the chat agent.
*/
result: ChatAgentResult2;
}
@ -252,13 +266,6 @@ declare module 'vscode' {
*/
agentId: string;
/**
* 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?: ChatAgentSubCommand;
/**
* The name of the {@link ChatAgentSubCommand subCommand} that was selected for this request.
*/