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

GitHub copilot chat - @powerpages contribution #927

18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
"onDebug",
"onFileSystem:powerplatform-vfs"
],
"extensionDependencies": [
"github.copilot-chat"
],
"enabledApiProposals": [
"chatParticipant",
"chatVariableResolver",
"languageModels"
],
"capabilities": {
"untrustedWorkspaces": {
"supported": "limited",
Expand All @@ -112,6 +120,14 @@
}
},
"contributes": {
"chatParticipants": [
{
"id": "powerpages",
"name": "powerpages",
"description": "Power Pages Copilot",
"isSticky": true
}
],
"problemMatchers": [
{
"name": "pcf-scripts-build",
Expand Down Expand Up @@ -1124,4 +1140,4 @@
"bufferutil": "^4.0.6",
"utf-8-validate": "^5.0.9"
}
}
}
4 changes: 4 additions & 0 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
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,63 @@
/*
* 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');

amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved
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

// TODO: Remove hardcoded values
const aibAuth = await intelligenceAPIAuthentication(this.telemetry, 'sessionID', '9ba620dc-4b37-430e-b779-2f9a7e7a52a6', true)
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved

if(aibAuth.accessToken) {

// User is signed in
stream.markdown("Welcome to Power Pages! 🚀")
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved

//TODO: Add logic to handle the request
console.log(request)
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved
console.log(context)
console.log(token)

} else {
// User is not signed in
stream.markdown("Please sign in to use Power Pages")
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved
}

return {
metadata: {
command: 'powerpages'
amitjoshi438 marked this conversation as resolved.
Show resolved Hide resolved
}
};

};

}
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.
Loading