Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor PowerPagesChatParticipant and add CommandRegistry #1050

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/common/chat-participants/CommandRegistry.ts
Original file line number Diff line number Diff line change
@@ -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<any>;
}

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];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved

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 });
Expand Down Expand Up @@ -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 }, {});
Expand Down
Loading