-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@powerpages] GitHub copilot auth handling for AIB and PAC (#947)
* chore: Update package.json with extension dependencies and enabled API proposals for chat participants * feat: Add PowerPagesChatParticipant for chat functionality * feat: Add logic to handle chat requests in PowerPagesChatParticipant * feat: Removed logs * TODO * feat: Add logic to handle chat requests in PowerPagesChatParticipant(correct response format) * chore: Remove unused code and update PowerPagesChatParticipant initialization * chore: Update PowerPagesChatParticipant initialization and pac integration * feat: Initialize organization details in PowerPagesChatParticipant * chore: Remove unnecessary code and update OrgChangeNotifier initialization * Fix lint warnings * feat: Refactor PowerPagesChatParticipant class The code changes refactor the PowerPagesChatParticipant class in the `PowerPagesChatParticipant.ts` file. The changes include: - Fixing a typo in the `instance` property declaration - Updating the constructor parameters to have consistent spacing - Adding a comment to handle chat requests - Removing a console.log statement - Updating the `intializeOrgDetails` method to have consistent spacing - Updating the `intializeOrgDetails` method to use destructuring assignment - Updating the `intializeOrgDetails` method to update the `orgDetails` in the global state - Removing unused code Co-authored-by: amitjoshi <[email protected]> * Added response for error scenarios * Added & removed comments * refactor: Update PowerPagesCopilot name in package.json The code changes in the package.json file update the "name" property for the "powerpages" module to "Power Pages Copilot". This change reflects the updated name for the module. Co-authored-by: amitjoshi <[email protected]> * Code refactoring for utils and constants * Enhanced pac auth handling * refactor: Update PowerPagesChatParticipantConstants The code changes in the `PowerPagesChatParticipantConstants.ts` file refactor the constants used in the PowerPages chat participant. The changes include: - Cleaning up the code formatting Co-authored-by: amitjoshi <[email protected]> --------- Co-authored-by: amitjoshi <[email protected]> Co-authored-by: tyaginidhi <[email protected]> Co-authored-by: Nidhi Tyagi 🌟🐇🌴❄️ <[email protected]>
- Loading branch information
1 parent
5945ef7
commit 67dc648
Showing
12 changed files
with
952 additions
and
748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { ExtensionContext } from 'vscode'; | ||
import { ActiveOrgOutput } from '../client/pac/PacTypes'; | ||
import { PacWrapper } from '../client/pac/PacWrapper'; | ||
import { OrgDetails } from './chat-participants/powerpages/PowerPagesChatParticipantTypes'; | ||
import { PAC_SUCCESS } from './copilot/constants'; | ||
import { createAuthProfileExp } from './Utils'; | ||
|
||
export const ORG_DETAILS_KEY = 'orgDetails'; | ||
|
||
export function handleOrgChangeSuccess( | ||
orgDetails: ActiveOrgOutput, | ||
extensionContext: ExtensionContext | ||
): { orgID: string, orgUrl: string } { | ||
const orgID = orgDetails.OrgId; | ||
const orgUrl = orgDetails.OrgUrl; | ||
|
||
extensionContext.globalState.update(ORG_DETAILS_KEY, { orgID, orgUrl }); | ||
|
||
//TODO: Handle AIB GEOs | ||
|
||
return { orgID, orgUrl }; | ||
} | ||
|
||
export async function initializeOrgDetails( | ||
isOrgDetailsInitialized: boolean, | ||
extensionContext: ExtensionContext, | ||
pacWrapper?: PacWrapper | ||
): Promise<{ orgID?: string, orgUrl?: string }> { | ||
if (isOrgDetailsInitialized) { | ||
return {}; | ||
} | ||
|
||
const orgDetails: OrgDetails | undefined = extensionContext.globalState.get(ORG_DETAILS_KEY); | ||
let orgID: string | undefined; | ||
let orgUrl: string | undefined; | ||
|
||
if (orgDetails && orgDetails.orgID && orgDetails.orgUrl) { | ||
orgID = orgDetails.orgID; | ||
orgUrl = orgDetails.orgUrl; | ||
} else { | ||
if (pacWrapper) { | ||
const pacActiveOrg = await pacWrapper.activeOrg(); | ||
if (pacActiveOrg && pacActiveOrg.Status === PAC_SUCCESS) { | ||
const orgDetails = handleOrgChangeSuccess(pacActiveOrg.Results, extensionContext); | ||
orgID = orgDetails.orgID; | ||
orgUrl = orgDetails.orgUrl; | ||
} else { | ||
await createAuthProfileExp(pacWrapper); | ||
} | ||
} | ||
} | ||
|
||
return { orgID, orgUrl }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
||
export const POWERPAGES_CHAT_PARTICIPANT_ID = 'powerpages'; | ||
export const RESPONSE_AWAITED_MSG = 'Working on it...' | ||
export const AUTHENTICATION_FAILED_MSG = 'Authentication failed. Please try again.'; | ||
export const COPILOT_NOT_AVAILABLE_MSG = 'Copilot is not available. Please contact your administrator.'; | ||
export const PAC_AUTH_NOT_FOUND = 'Active auth profile is not found or has expired. Please try again.'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { ITelemetry } from "../../../client/telemetry/ITelemetry"; | ||
import { getIntelligenceEndpoint } from "../../ArtemisService"; | ||
|
||
export async function getEndpoint( | ||
orgID: string, | ||
telemetry: ITelemetry, | ||
cachedEndpoint: { intelligenceEndpoint: string; geoName: string } | null | ||
): Promise<{ intelligenceEndpoint: string; geoName: string }> { | ||
if (!cachedEndpoint) { | ||
cachedEndpoint = await getIntelligenceEndpoint(orgID, telemetry, '') as { intelligenceEndpoint: string; geoName: string }; | ||
} | ||
return cachedEndpoint; | ||
} |
Oops, something went wrong.