diff --git a/src/vs/workbench/api/browser/mainThreadChat.ts b/src/vs/workbench/api/browser/mainThreadChat.ts index 914acca811f..4a6634dc248 100644 --- a/src/vs/workbench/api/browser/mainThreadChat.ts +++ b/src/vs/workbench/api/browser/mainThreadChat.ts @@ -40,24 +40,6 @@ export class MainThreadChat extends Disposable implements MainThreadChatShape { })); } - async $registerSlashCommandProvider(handle: number, chatProviderId: string): Promise { - const unreg = this._chatService.registerSlashCommandProvider({ - chatProviderId, - provideSlashCommands: async token => { - return this._proxy.$provideProviderSlashCommands(handle, token); - }, - resolveSlashCommand: async (command, token) => { - return this._proxy.$resolveSlashCommand(handle, command, token); - } - }); - - this._providerRegistrations.set(handle, unreg); - } - - async $unregisterSlashCommandProvider(handle: number): Promise { - this._providerRegistrations.deleteAndDispose(handle); - } - $transferChatSession(sessionId: number, toWorkspace: UriComponents): void { const sessionIdStr = this._chatService.getSessionId(sessionId); if (!sessionIdStr) { diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 961372ad4f1..7aee01902ab 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1316,14 +1316,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I } }; - // namespace: interactiveSlashCommands - const interactiveSlashCommands: typeof vscode.interactiveSlashCommands = { - registerSlashCommandProvider(chatProviderId: string, provider: vscode.InteractiveSlashCommandProvider) { - checkProposedApiEnabled(extension, 'interactiveSlashCommands'); - return extHostChat.registerSlashCommandProvider(extension, chatProviderId, provider); - } - }; - // namespace: ai const ai: typeof vscode.ai = { registerSemanticSimilarityProvider(provider: vscode.SemanticSimilarityProvider) { @@ -1355,13 +1347,12 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I authentication, commands, comments, + chat, debug, env, extensions, interactive, - interactiveSlashCommands, l10n, - chat, languages, notebooks, scm, diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index acf8470a381..0314fe1b5b0 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1203,9 +1203,6 @@ export interface MainThreadChatShape extends IDisposable { $unregisterChatProvider(handle: number): Promise; $acceptResponseProgress(handle: number, sessionId: number, progress: IChatResponseProgressDto, responsePartHandle?: number): Promise; $transferChatSession(sessionId: number, toWorkspace: UriComponents): void; - - $registerSlashCommandProvider(handle: number, chatProviderId: string): Promise; - $unregisterSlashCommandProvider(handle: number): Promise; } export interface ExtHostChatShape { @@ -1218,9 +1215,6 @@ export interface ExtHostChatShape { $provideSlashCommands(handle: number, sessionId: number, token: CancellationToken): Promise; $releaseSession(sessionId: number): void; $onDidPerformUserAction(event: IChatUserActionEvent): Promise; - - $provideProviderSlashCommands(handle: number, token: CancellationToken): Promise; - $resolveSlashCommand(handle: number, command: string, token: CancellationToken): Promise; } export interface ExtHostUrlsShape { diff --git a/src/vs/workbench/api/common/extHostChat.ts b/src/vs/workbench/api/common/extHostChat.ts index df995d8fc23..674b557b889 100644 --- a/src/vs/workbench/api/common/extHostChat.ts +++ b/src/vs/workbench/api/common/extHostChat.ts @@ -33,7 +33,7 @@ export class ExtHostChat implements ExtHostChatShape { private static _nextId = 0; private readonly _chatProvider = new Map>(); - private readonly _slashCommandProvider = new Map>(); + private readonly _chatSessions = new Map(); // private readonly _providerResponsesByRequestId = new Map; sessionId: number }>(); @@ -286,37 +286,4 @@ export class ExtHostChat implements ExtHostChatShape { } //#endregion - - registerSlashCommandProvider(extension: Readonly, chatProviderId: string, provider: vscode.InteractiveSlashCommandProvider): vscode.Disposable { - const wrapper = new ChatProviderWrapper(extension, provider); - this._slashCommandProvider.set(wrapper.handle, wrapper); - this._proxy.$registerSlashCommandProvider(wrapper.handle, chatProviderId); - return toDisposable(() => { - this._proxy.$unregisterSlashCommandProvider(wrapper.handle); - this._slashCommandProvider.delete(wrapper.handle); - }); - } - - async $provideProviderSlashCommands(handle: number, token: CancellationToken): Promise { - const entry = this._slashCommandProvider.get(handle); - if (!entry) { - return undefined; - } - - const slashCommands = await entry.provider.provideSlashCommands(token); - return slashCommands?.map(c => ({ - ...c, - kind: typeConvert.CompletionItemKind.from(c.kind) - })); - } - - async $resolveSlashCommand(handle: number, command: string, token: CancellationToken): Promise { - const entry = this._slashCommandProvider.get(handle); - if (!entry) { - return undefined; - } - - const resolved = await entry.provider.resolveSlashCommand(command, token); - return resolved ?? undefined; - } } diff --git a/src/vs/workbench/contrib/chat/common/chatService.ts b/src/vs/workbench/contrib/chat/common/chatService.ts index 07e7a964c6d..1bed4de4b2b 100644 --- a/src/vs/workbench/contrib/chat/common/chatService.ts +++ b/src/vs/workbench/contrib/chat/common/chatService.ts @@ -65,15 +65,8 @@ export interface IChatProvider { removeRequest?(session: IChat, requestId: string): void; } -export interface ISlashCommandProvider { - chatProviderId: string; - provideSlashCommands(token: CancellationToken): ProviderResult; - resolveSlashCommand(command: string, token: CancellationToken): ProviderResult; -} - export interface ISlashCommand { command: string; - provider?: ISlashCommandProvider; sortText?: string; detail?: string; @@ -208,7 +201,6 @@ export interface IChatService { onDidSubmitSlashCommand: Event<{ slashCommand: string; sessionId: string }>; registerProvider(provider: IChatProvider): IDisposable; - registerSlashCommandProvider(provider: ISlashCommandProvider): IDisposable; getProviderInfos(): IChatProviderInfo[]; startSession(providerId: string, token: CancellationToken): ChatModel | undefined; getSession(sessionId: string): IChatModel | undefined; diff --git a/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts b/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts index 6332f29721c..a0a5c5f59b6 100644 --- a/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts +++ b/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts @@ -24,7 +24,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace import { CONTEXT_PROVIDER_EXISTS } from 'vs/workbench/contrib/chat/common/chatContextKeys'; import { ChatModel, ChatWelcomeMessageModel, IChatModel, ISerializableChatData, ISerializableChatsData } from 'vs/workbench/contrib/chat/common/chatModel'; import { ChatMessageRole, IChatMessage } from 'vs/workbench/contrib/chat/common/chatProvider'; -import { IChat, IChatCompleteResponse, IChatDetail, IChatDynamicRequest, IChatProgress, IChatProvider, IChatProviderInfo, IChatReplyFollowup, IChatResponse, IChatService, IChatTransferredSessionData, IChatUserActionEvent, ISlashCommand, ISlashCommandProvider, InteractiveSessionCopyKind, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService'; +import { IChat, IChatCompleteResponse, IChatDetail, IChatDynamicRequest, IChatProgress, IChatProvider, IChatProviderInfo, IChatReplyFollowup, IChatResponse, IChatService, IChatTransferredSessionData, IChatUserActionEvent, ISlashCommand, InteractiveSessionCopyKind, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService'; import { IChatSlashCommandService, IChatSlashFragment } from 'vs/workbench/contrib/chat/common/chatSlashCommands'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; @@ -125,7 +125,7 @@ export class ChatService extends Disposable implements IChatService { declare _serviceBrand: undefined; private readonly _providers = new Map(); - private readonly _slashCommandProviders = new Set(); + private readonly _sessionModels = new Map(); private readonly _pendingRequests = new Map>(); private readonly _persistedSessions: ISerializableChatsData; @@ -559,13 +559,8 @@ export class ChatService extends Disposable implements IChatService { private async handleSlashCommand(sessionId: string, command: string): Promise { const slashCommands = await this.getSlashCommands(sessionId, CancellationToken.None); for (const slashCommand of slashCommands ?? []) { - if (command.startsWith(`/${slashCommand.command}`)) { - if (slashCommand.provider) { - return await slashCommand.provider.resolveSlashCommand(command, CancellationToken.None) ?? command; - } else if (this.chatSlashCommandService.hasCommand(slashCommand.command)) { - return slashCommand.command; - } - + if (command.startsWith(`/${slashCommand.command}`) && this.chatSlashCommandService.hasCommand(slashCommand.command)) { + return slashCommand.command; } } return command; @@ -583,18 +578,6 @@ export class ChatService extends Disposable implements IChatService { throw new Error(`Unknown provider: ${model.providerId}`); } - if (!provider.provideSlashCommands) { - return; - } - - const mainProviderRequest = provider.provideSlashCommands(model.session!, token); - const slashCommandProviders = Array.from(this._slashCommandProviders).filter(p => p.chatProviderId === model.providerId); - const providerResults = Promise.all([ - mainProviderRequest, - ...slashCommandProviders.map(p => Promise.resolve(p.provideSlashCommands(token)) - .then(commands => commands?.map(c => ({ ...c, provider: p })))) - ]); - const serviceResults = this.chatSlashCommandService.getCommands().map(data => { return { command: data.command, @@ -604,14 +587,18 @@ export class ChatService extends Disposable implements IChatService { }; }); + const mainProviderRequest = provider.provideSlashCommands?.(model.session!, token); + try { - const slashCommands = (await providerResults).filter(c => !!c) as ISlashCommand[][]; - return slashCommands.flat().concat(serviceResults); + const providerResults = await mainProviderRequest; + if (providerResults) { + return providerResults.concat(serviceResults); + } + return serviceResults; + } catch (e) { this.logService.error(e); - - // If one of the other contributed providers fails, return the main provider's result - return await mainProviderRequest ?? undefined; + return serviceResults; } } @@ -712,16 +699,6 @@ export class ChatService extends Disposable implements IChatService { }); } - registerSlashCommandProvider(provider: ISlashCommandProvider): IDisposable { - this.trace('registerProvider', `Adding new slash command provider`); - - this._slashCommandProviders.add(provider); - return toDisposable(() => { - this.trace('registerProvider', `Disposing slash command provider`); - this._slashCommandProviders.delete(provider); - }); - } - getProviderInfos(): IChatProviderInfo[] { return Array.from(this._providers.values()).map(provider => { return { diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index b500f2cc8d5..5c4ca2842b0 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -53,7 +53,6 @@ export const allApiProposals = Object.freeze({ indentSize: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.indentSize.d.ts', inlineCompletionsAdditions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts', interactive: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactive.d.ts', - interactiveSlashCommands: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveSlashCommands.d.ts', interactiveUserActions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveUserActions.d.ts', interactiveWindow: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveWindow.d.ts', ipc: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.ipc.d.ts', diff --git a/src/vscode-dts/vscode.proposed.interactiveSlashCommands.d.ts b/src/vscode-dts/vscode.proposed.interactiveSlashCommands.d.ts deleted file mode 100644 index b07ecf06747..00000000000 --- a/src/vscode-dts/vscode.proposed.interactiveSlashCommands.d.ts +++ /dev/null @@ -1,16 +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 InteractiveSlashCommandProvider { - provideSlashCommands(token: CancellationToken): ProviderResult; - resolveSlashCommand(command: string, token: CancellationToken): ProviderResult; - } - - export namespace interactiveSlashCommands { - export function registerSlashCommandProvider(chatProviderId: string, provider: InteractiveSlashCommandProvider): Disposable; - } -}