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

User/amitjoshi/GitHub copilot endpoint handling #954

Draft
wants to merge 12 commits into
base: features/PowerPagesAgent
Choose a base branch
from
Prev Previous commit
Next Next commit
feat: Add PowerPagesChatParticipant for chat functionality
  • Loading branch information
amitjoshi committed May 1, 2024
commit b49bccc2ee0ace2425d22c2a332c842ada10d369
4 changes: 4 additions & 0 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ import { oneDSLoggerWrapper } from "../common/OneDSLoggerTelemetry/oneDSLoggerWr
import { OrgChangeNotifier, orgChangeEvent } from "../common/OrgChangeNotifier";
import { ActiveOrgOutput } from "./pac/PacTypes";
import { telemetryEventNames } from "./telemetry/TelemetryEventNames";
import { PowerPagesChatParticipant } from "../common/chat-participants/powerpages/PowerPagesChatParticipant";

let client: LanguageClient;
let _context: vscode.ExtensionContext;
@@ -177,6 +178,9 @@ export async function activate(
// Add CRUD related callback subscription here
await handleFileSystemCallbacks(_context, _telemetry);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const PowerPagesChatParticipantInstance = new PowerPagesChatParticipant(_context, _telemetry);

const cliContext = new CliAcquisitionContext(_context, _telemetry);
const cli = new CliAcquisition(cliContext);
const cliPath = await cli.ensureInstalled();
10 changes: 10 additions & 0 deletions src/common/chat-participants/ChatParticipantUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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 function createChatParticipant(participantId: string, handler: vscode.ChatRequestHandler): vscode.ChatParticipant {
return vscode.chat.createChatParticipant(participantId, handler);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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';
import { createChatParticipant } from '../ChatParticipantUtils';
import { IPowerPagesChatResult } from './PowerPagesChatParticipantTypes';
import { intelligenceAPIAuthentication } from '../../../web/client/common/authenticationProvider';
import { ITelemetry } from '../../../client/telemetry/ITelemetry';
import TelemetryReporter from '@vscode/extension-telemetry';


export class PowerPagesChatParticipant {
private chatParticipant: vscode.ChatParticipant;
private telemetry: ITelemetry;

constructor(context: vscode.ExtensionContext, telemetry: ITelemetry | TelemetryReporter,) {
console.log("PowerPagesChatParticipant constructor");

this.chatParticipant = createChatParticipant('powerpages', this.handler);

this.chatParticipant.iconPath = vscode.Uri.joinPath(context.extensionUri, 'src', 'common', 'chat-participants', 'powerpages', 'assets', 'copilot.png');

this.telemetry = telemetry;

}

private handler: vscode.ChatRequestHandler = async (
request: vscode.ChatRequest,
context: vscode.ChatContext,
stream: vscode.ChatResponseStream,
token: vscode.CancellationToken
): Promise<IPowerPagesChatResult> => {
// Handle chat requests here

const aibAuth = await intelligenceAPIAuthentication(this.telemetry, 'sessionID', '9ba620dc-4b37-430e-b779-2f9a7e7a52a6', true)

if(aibAuth.accessToken) {

console.log(request.command);
console.log(context);
stream.markdown('Hello from PowerPagesChatParticipant');
console.log(token);

console.log("PowerPagesChatParticipant handler");

} else {
// User is not signed in
stream.markdown("Please sign in to use Power Pages")
}

return {
metadata: {
command: 'powerpages'
}
};

};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 IPowerPagesChatResult extends vscode.ChatResult {
metadata: {
command: string;
}
}
3 changes: 3 additions & 0 deletions src/common/chat-participants/powerpages/assets/copilot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.