diff --git a/src/common/chat-participants/CommandRegistry.ts b/src/common/chat-participants/CommandRegistry.ts new file mode 100644 index 00000000..ac1281fa --- /dev/null +++ b/src/common/chat-participants/CommandRegistry.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + +import * as vscode from "vscode"; + +export interface Command { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + execute(request: any, stream: vscode.ChatResponseStream): Promise; +} + +export class CommandRegistry { + private commands: { [key: string]: Command } = {}; + + register(commandName: string, command: Command) { + this.commands[commandName] = command; + } + + get(commandName: string): Command { + return this.commands[commandName]; + } +} diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts index 85de5fbc..163fc193 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts @@ -22,6 +22,11 @@ import { orgChangeErrorEvent, orgChangeEvent } from '../../../client/OrgChangeNo import { isPowerPagesGitHubCopilotEnabled } from '../../copilot/utils/copilotUtil'; import { ADX_WEBPAGE, IApiRequestParams, IRelatedFiles } from '../../constants'; import { oneDSLoggerWrapper } from '../../OneDSLoggerTelemetry/oneDSLoggerWrapper'; +import { CommandRegistry } from '../CommandRegistry'; + +// Initialize Command Registry and Register Commands +const commandRegistry = new CommandRegistry(); +//Register Commands export class PowerPagesChatParticipant { private static instance: PowerPagesChatParticipant | null = null; @@ -154,7 +159,19 @@ export class PowerPagesChatParticipant { const location = activeFileUri ? createAndReferenceLocation(activeFileUri, startLine, endLine) : undefined; if (request.command) { - //TODO: Handle command scenarios + const command = commandRegistry.get(request.command); + + const commandRequest = { + request, + stream, + intelligenceAPIEndpointInfo, + intelligenceApiToken, + powerPagesAgentSessionId: this.powerPagesAgentSessionId, + telemetry: this.telemetry + }; + + return await command.execute(commandRequest, stream); + } else { if (location) { this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_LOCATION_REFERENCED, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); @@ -217,7 +234,6 @@ export class PowerPagesChatParticipant { return createSuccessResult('', scenario.toString(), this.orgID); } - return createSuccessResult('', '', this.orgID); } catch (error) { this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR, { sessionId: this.powerPagesAgentSessionId, error: error as string }); oneDSLoggerWrapper.getLogger().traceError(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR, error as string, error as Error, { sessionId: this.powerPagesAgentSessionId }, {});