From ada980d5633d7f1ff5ee58dd64819f5f3a008bff Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Sun, 3 Dec 2023 22:58:17 -0600 Subject: [PATCH] Merge interactiveUserActions proposal into chatAgents2Additions, and get rid of the old global event (#199916) Towards #197687 --- extensions/vscode-api-tests/package.json | 3 +- .../workbench/api/browser/mainThreadChat.ts | 6 -- .../workbench/api/common/extHost.api.impl.ts | 6 +- .../workbench/api/common/extHost.protocol.ts | 1 - src/vs/workbench/api/common/extHostChat.ts | 10 +-- src/vs/workbench/api/common/extHostTypes.ts | 2 +- .../browser/actions/chatCodeblockActions.ts | 6 +- .../contrib/chat/common/chatService.ts | 4 +- .../contrib/chat/common/chatServiceImpl.ts | 4 +- .../common/extensionsApiProposals.ts | 1 - .../vscode.proposed.chatAgents2Additions.d.ts | 62 +++++++++++++-- ...scode.proposed.interactiveUserActions.d.ts | 77 ------------------- 12 files changed, 68 insertions(+), 114 deletions(-) delete mode 100644 src/vscode-dts/vscode.proposed.interactiveUserActions.d.ts diff --git a/extensions/vscode-api-tests/package.json b/extensions/vscode-api-tests/package.json index 401b9a4da03..20b69bfc674 100644 --- a/extensions/vscode-api-tests/package.json +++ b/extensions/vscode-api-tests/package.json @@ -53,8 +53,7 @@ "workspaceTrust", "telemetry", "testingActiveProfile", - "windowActivity", - "interactiveUserActions" + "windowActivity" ], "private": true, "activationEvents": [], diff --git a/src/vs/workbench/api/browser/mainThreadChat.ts b/src/vs/workbench/api/browser/mainThreadChat.ts index 476bf6da65c..a67f5d4b250 100644 --- a/src/vs/workbench/api/browser/mainThreadChat.ts +++ b/src/vs/workbench/api/browser/mainThreadChat.ts @@ -28,12 +28,6 @@ export class MainThreadChat extends Disposable implements MainThreadChatShape { ) { super(); this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostChat); - - this._register(this._chatService.onDidPerformUserAction(e => { - if (!e.agentId) { - this._proxy.$onDidPerformUserAction(e); - } - })); } $transferChatSession(sessionId: number, toWorkspace: UriComponents): void { diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index b3546f88c2b..9d5fe872e94 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1334,10 +1334,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I checkProposedApiEnabled(extension, 'interactive'); return extHostChat.sendInteractiveRequestToProvider(providerId, message); }, - get onDidPerformUserAction() { - checkProposedApiEnabled(extension, 'interactiveUserActions'); - return extHostChat.onDidPerformUserAction; - }, transferChatSession(session: vscode.InteractiveSession, toWorkspace: vscode.Uri) { checkProposedApiEnabled(extension, 'interactive'); return extHostChat.transferChatSession(session, toWorkspace); @@ -1609,7 +1605,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I LogLevel: LogLevel, EditSessionIdentityMatch: EditSessionIdentityMatch, InteractiveSessionVoteDirection: extHostTypes.InteractiveSessionVoteDirection, - InteractiveSessionCopyKind: extHostTypes.InteractiveSessionCopyKind, + ChatAgentCopyKind: extHostTypes.ChatAgentCopyKind, InteractiveEditorResponseFeedbackKind: extHostTypes.InteractiveEditorResponseFeedbackKind, StackFrameFocus: extHostTypes.StackFrameFocus, ThreadFocus: extHostTypes.ThreadFocus, diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 391234eac91..40e2e999ec8 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1287,7 +1287,6 @@ export interface ExtHostChatShape { $provideWelcomeMessage(handle: number, token: CancellationToken): Promise<(string | IMarkdownString | IChatReplyFollowup[])[] | undefined>; $provideSampleQuestions(handle: number, token: CancellationToken): Promise; $releaseSession(sessionId: number): void; - $onDidPerformUserAction(event: IChatUserActionEvent): Promise; } export interface ExtHostUrlsShape { diff --git a/src/vs/workbench/api/common/extHostChat.ts b/src/vs/workbench/api/common/extHostChat.ts index 870c8a78848..74935c0e51f 100644 --- a/src/vs/workbench/api/common/extHostChat.ts +++ b/src/vs/workbench/api/common/extHostChat.ts @@ -4,14 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import { CancellationToken } from 'vs/base/common/cancellation'; -import { Emitter } from 'vs/base/common/event'; import { IMarkdownString } from 'vs/base/common/htmlContent'; import { Iterable } from 'vs/base/common/iterator'; import { toDisposable } from 'vs/base/common/lifecycle'; import { IRelaxedExtensionDescription } from 'vs/platform/extensions/common/extensions'; import { ExtHostChatShape, IChatDto, IMainContext, MainContext, MainThreadChatShape } from 'vs/workbench/api/common/extHost.protocol'; import * as typeConvert from 'vs/workbench/api/common/extHostTypeConverters'; -import { IChatReplyFollowup, IChatUserActionEvent } from 'vs/workbench/contrib/chat/common/chatService'; +import { IChatReplyFollowup } from 'vs/workbench/contrib/chat/common/chatService'; import type * as vscode from 'vscode'; class ChatProviderWrapper { @@ -33,9 +32,6 @@ export class ExtHostChat implements ExtHostChatShape { private readonly _chatSessions = new Map(); - private readonly _onDidPerformUserAction = new Emitter(); - public readonly onDidPerformUserAction = this._onDidPerformUserAction.event; - private readonly _proxy: MainThreadChatShape; constructor( @@ -140,9 +136,5 @@ export class ExtHostChat implements ExtHostChatShape { this._chatSessions.delete(sessionId); } - async $onDidPerformUserAction(event: IChatUserActionEvent): Promise { - this._onDidPerformUserAction.fire(event as any); - } - //#endregion } diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index 97d25527562..1e10046d465 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -4111,7 +4111,7 @@ export enum InteractiveSessionVoteDirection { Up = 1 } -export enum InteractiveSessionCopyKind { +export enum ChatAgentCopyKind { Action = 1, Toolbar = 2 } diff --git a/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.ts b/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.ts index 2d6c3a5ef10..bbf5ba106b9 100644 --- a/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.ts +++ b/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.ts @@ -28,7 +28,7 @@ import { CHAT_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatAct import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat'; import { ICodeBlockActionContext } from 'vs/workbench/contrib/chat/browser/codeBlockPart'; import { CONTEXT_IN_CHAT_INPUT, CONTEXT_IN_CHAT_SESSION, CONTEXT_PROVIDER_EXISTS } from 'vs/workbench/contrib/chat/common/chatContextKeys'; -import { IChatService, IDocumentContext, InteractiveSessionCopyKind } from 'vs/workbench/contrib/chat/common/chatService'; +import { IChatService, IDocumentContext, ChatAgentCopyKind } from 'vs/workbench/contrib/chat/common/chatService'; import { IChatResponseViewModel, isResponseVM } from 'vs/workbench/contrib/chat/common/chatViewModel'; import { CTX_INLINE_CHAT_VISIBLE } from 'vs/workbench/contrib/inlineChat/common/inlineChat'; import { insertCell } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations'; @@ -114,7 +114,7 @@ export function registerChatCodeBlockActions() { action: { kind: 'copy', codeBlockIndex: context.codeBlockIndex, - copyType: InteractiveSessionCopyKind.Toolbar, + copyKind: ChatAgentCopyKind.Toolbar, copiedCharacters: context.code.length, totalCharacters: context.code.length, copiedText: context.code, @@ -157,7 +157,7 @@ export function registerChatCodeBlockActions() { action: { kind: 'copy', codeBlockIndex: context.codeBlockIndex, - copyType: InteractiveSessionCopyKind.Action, + copyKind: ChatAgentCopyKind.Action, copiedText, copiedCharacters: copiedText.length, totalCharacters, diff --git a/src/vs/workbench/contrib/chat/common/chatService.ts b/src/vs/workbench/contrib/chat/common/chatService.ts index 9f372473a94..4cf8455129d 100644 --- a/src/vs/workbench/contrib/chat/common/chatService.ts +++ b/src/vs/workbench/contrib/chat/common/chatService.ts @@ -200,7 +200,7 @@ export interface IChatVoteAction { reportIssue?: boolean; } -export enum InteractiveSessionCopyKind { +export enum ChatAgentCopyKind { // Keyboard shortcut or context menu Action = 1, Toolbar = 2 @@ -209,7 +209,7 @@ export enum InteractiveSessionCopyKind { export interface IChatCopyAction { kind: 'copy'; codeBlockIndex: number; - copyType: InteractiveSessionCopyKind; + copyKind: ChatAgentCopyKind; copiedCharacters: number; totalCharacters: number; copiedText: string; diff --git a/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts b/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts index 47ebd3b8604..6c873f5a4f5 100644 --- a/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts +++ b/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts @@ -26,7 +26,7 @@ import { ChatModel, ChatModelInitState, ChatRequestModel, ChatWelcomeMessageMode import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestSlashCommandPart, IParsedChatRequest } from 'vs/workbench/contrib/chat/common/chatParserTypes'; import { ChatMessageRole, IChatMessage } from 'vs/workbench/contrib/chat/common/chatProvider'; import { ChatRequestParser } from 'vs/workbench/contrib/chat/common/chatRequestParser'; -import { IChat, IChatCompleteResponse, IChatDetail, IChatDynamicRequest, IChatFollowup, IChatProgress, IChatProvider, IChatProviderInfo, IChatResponse, IChatService, IChatTransferredSessionData, IChatUserActionEvent, InteractiveSessionCopyKind, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService'; +import { IChat, IChatCompleteResponse, IChatDetail, IChatDynamicRequest, IChatFollowup, IChatProgress, IChatProvider, IChatProviderInfo, IChatResponse, IChatService, IChatTransferredSessionData, IChatUserActionEvent, ChatAgentCopyKind, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService'; import { IChatSlashCommandService } from 'vs/workbench/contrib/chat/common/chatSlashCommands'; import { IChatVariablesService } from 'vs/workbench/contrib/chat/common/chatVariables'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; @@ -224,7 +224,7 @@ export class ChatService extends Disposable implements IChatService { } else if (action.action.kind === 'copy') { this.telemetryService.publicLog2('interactiveSessionCopy', { providerId: action.providerId, - copyKind: action.action.copyType === InteractiveSessionCopyKind.Action ? 'action' : 'toolbar' + copyKind: action.action.copyKind === ChatAgentCopyKind.Action ? 'action' : 'toolbar' }); } else if (action.action.kind === 'insert') { this.telemetryService.publicLog2('interactiveSessionInsert', { diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index e45c2d9a5ec..79467b47ff6 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -57,7 +57,6 @@ export const allApiProposals = Object.freeze({ idToken: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.idToken.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', - 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', languageStatusText: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.languageStatusText.d.ts', diff --git a/src/vscode-dts/vscode.proposed.chatAgents2Additions.d.ts b/src/vscode-dts/vscode.proposed.chatAgents2Additions.d.ts index 1e0684cd03c..2ad0993986f 100644 --- a/src/vscode-dts/vscode.proposed.chatAgents2Additions.d.ts +++ b/src/vscode-dts/vscode.proposed.chatAgents2Additions.d.ts @@ -5,11 +5,6 @@ declare module 'vscode' { - export interface ChatAgentUserActionEvent { - readonly result: ChatAgentResult2; - readonly action: InteractiveSessionCopyAction | InteractiveSessionInsertAction | InteractiveSessionTerminalAction | InteractiveSessionCommandAction | InteractiveSessionFollowupAction | InteractiveSessionBugReportAction; - } - export interface ChatAgent2 { onDidPerformAction: Event; supportIssueReporting?: boolean; @@ -77,4 +72,61 @@ declare module 'vscode' { */ export function createChatAgent(name: string, handler: ChatAgentExtendedHandler): ChatAgent2; } + + /* + * User action events + */ + + export enum ChatAgentCopyKind { + // Keyboard shortcut or context menu + Action = 1, + Toolbar = 2 + } + + export interface ChatAgentCopyAction { + // eslint-disable-next-line local/vscode-dts-string-type-literals + kind: 'copy'; + codeBlockIndex: number; + copyKind: ChatAgentCopyKind; + copiedCharacters: number; + totalCharacters: number; + copiedText: string; + } + + export interface ChatAgentInsertAction { + // eslint-disable-next-line local/vscode-dts-string-type-literals + kind: 'insert'; + codeBlockIndex: number; + totalCharacters: number; + newFile?: boolean; + } + + export interface ChatAgentTerminalAction { + // eslint-disable-next-line local/vscode-dts-string-type-literals + kind: 'runInTerminal'; + codeBlockIndex: number; + languageId?: string; + } + + export interface ChatAgentCommandAction { + // eslint-disable-next-line local/vscode-dts-string-type-literals + kind: 'command'; + command: ChatAgentCommandFollowup; + } + + export interface ChatAgentSessionFollowupAction { + // eslint-disable-next-line local/vscode-dts-string-type-literals + kind: 'followUp'; + followup: ChatAgentReplyFollowup; + } + + export interface ChatAgentBugReportAction { + // eslint-disable-next-line local/vscode-dts-string-type-literals + kind: 'bug'; + } + + export interface ChatAgentUserActionEvent { + readonly result: ChatAgentResult2; + readonly action: ChatAgentCopyAction | ChatAgentInsertAction | ChatAgentTerminalAction | ChatAgentCommandAction | ChatAgentSessionFollowupAction | ChatAgentBugReportAction; + } } diff --git a/src/vscode-dts/vscode.proposed.interactiveUserActions.d.ts b/src/vscode-dts/vscode.proposed.interactiveUserActions.d.ts deleted file mode 100644 index c4f89f80bbe..00000000000 --- a/src/vscode-dts/vscode.proposed.interactiveUserActions.d.ts +++ /dev/null @@ -1,77 +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 enum InteractiveSessionVoteDirection { - Down = 0, - Up = 1 - } - - export interface InteractiveSessionVoteAction { - // eslint-disable-next-line local/vscode-dts-string-type-literals - kind: 'vote'; - direction: InteractiveSessionVoteDirection; - } - - export enum InteractiveSessionCopyKind { - // Keyboard shortcut or context menu - Action = 1, - Toolbar = 2 - } - - export interface InteractiveSessionCopyAction { - // eslint-disable-next-line local/vscode-dts-string-type-literals - kind: 'copy'; - codeBlockIndex: number; - copyType: InteractiveSessionCopyKind; - copiedCharacters: number; - totalCharacters: number; - copiedText: string; - } - - export interface InteractiveSessionInsertAction { - // eslint-disable-next-line local/vscode-dts-string-type-literals - kind: 'insert'; - codeBlockIndex: number; - totalCharacters: number; - newFile?: boolean; - } - - export interface InteractiveSessionTerminalAction { - // eslint-disable-next-line local/vscode-dts-string-type-literals - kind: 'runInTerminal'; - codeBlockIndex: number; - languageId?: string; - } - - export interface InteractiveSessionCommandAction { - // eslint-disable-next-line local/vscode-dts-string-type-literals - kind: 'command'; - command: InteractiveResponseCommand; - } - - export interface InteractiveSessionFollowupAction { - // eslint-disable-next-line local/vscode-dts-string-type-literals - kind: 'followUp'; - followup: InteractiveSessionReplyFollowup; - } - - export interface InteractiveSessionBugReportAction { - // eslint-disable-next-line local/vscode-dts-string-type-literals - kind: 'bug'; - } - - export type InteractiveSessionUserAction = InteractiveSessionVoteAction | InteractiveSessionCopyAction | InteractiveSessionInsertAction | InteractiveSessionTerminalAction | InteractiveSessionCommandAction | InteractiveSessionBugReportAction; - - export interface InteractiveSessionUserActionEvent { - action: InteractiveSessionUserAction; - providerId: string; - } - - export namespace interactive { - export const onDidPerformUserAction: Event; - } -}