Skip to content

Commit

Permalink
ECS Initialization in Desktop and @powerpages FCB (#1037)
Browse files Browse the repository at this point in the history
* chore:ECS config for @powerpages

* feat: Add ECSFeaturesClient initialization in extension.ts

* feat: Initialize ECSFeaturesClient with environment ID, tenant ID, and Aad ID

This commit initializes the ECSFeaturesClient in the extension.ts file with the environment ID, tenant ID, and Aad ID. It retrieves these values from the pacActiveAuth object and uses them to configure the ECSFeaturesClient. This change ensures that the ECSFeaturesClient is properly initialized with the necessary information for its functionality.

Co-authored-by: amitjoshi <[email protected]>

* chore: Update PowerPagesChatParticipant with ecs

* chore: Update telemetry constants for environment and tenant IDs

* chore: ecs update for region.stamp

* icon update

* refactor: Update telemetry events for @powerpages ecs

* refactor: localization strings

* refactor: Remove unused parameter in initializeOrgDetails function

---------

Co-authored-by: amitjoshi <[email protected]>
  • Loading branch information
amitjoshi438 and amitjoshi authored Sep 10, 2024
1 parent 876aef5 commit 0912e35
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 32 deletions.
5 changes: 3 additions & 2 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@
"Explain the following code {% include 'Page Copy'%}": "Explain the following code {% include 'Page Copy'%}",
"Hi! @powerpages can help you write, edit, and even summarize your website code.": "Hi! @powerpages can help you write, edit, and even summarize your website code.",
"Authentication failed. Please try again.": "Authentication failed. Please try again.",
"Copilot is not available. Please contact your administrator.": "Copilot is not available. Please contact your administrator.",
"AI features have been disabled by your organization. Contact your admin for details. [Learn more](https://go.microsoft.com/fwlink/?linkid=2285848)": "AI features have been disabled by your organization. Contact your admin for details. [Learn more](https://go.microsoft.com/fwlink/?linkid=2285848)",
"Active auth profile is not found or has expired. Please try again.": "Active auth profile is not found or has expired. Please try again.",
"Something went wrong. Don’t worry, you can try again.": "Something went wrong. Don’t worry, you can try again.",
"Make sure AI-generated content is accurate and appropriate before using. [Learn more](https://go.microsoft.com/fwlink/?linkid=2240145) | [View terms](https://go.microsoft.com/fwlink/?linkid=2189520)": "Make sure AI-generated content is accurate and appropriate before using. [Learn more](https://go.microsoft.com/fwlink/?linkid=2240145) | [View terms](https://go.microsoft.com/fwlink/?linkid=2189520)",
"Hi! Power Pages lets you build secure, professional websites that you can quickly configure and publish across web browsers and devices.\n\nTo create your website, visit the [Power Pages](https://powerpages.microsoft.com/).\nReturn to this chat and @powerpages can help you write and edit your website code.": "Hi! Power Pages lets you build secure, professional websites that you can quickly configure and publish across web browsers and devices.\n\nTo create your website, visit the [Power Pages](https://powerpages.microsoft.com/).\nReturn to this chat and @powerpages can help you write and edit your website code.",
"Checking for active auth profile...": "Checking for active auth profile...",
"@PowerPages is not yet available in your region.": "@PowerPages is not yet available in your region.",
"Select Folder for new PCF Control/Do not translate 'PCF' as it is a product name.": {
"message": "Select Folder for new PCF Control",
"comment": [
Expand Down Expand Up @@ -255,4 +256,4 @@
"The {0} represents profile's Azure Cloud Instances"
]
}
}
}
9 changes: 6 additions & 3 deletions loc/translations-export/vscode-powerplatform.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="bundle" source-language="en" datatype="plaintext"><body>
<trans-unit id="++CODE++29bb69945e50cb632fabf16f3f89a25d813910c19059d8a792f66262a952039d">
<source xml:lang="en">@PowerPages is not yet available in your region.</source>
</trans-unit>
<trans-unit id="++CODE++32e135c21be9286cda2fda96fbe713f9af60f5f933e4e58468f256dd54b95575">
<source xml:lang="en">A content snippet with the same name already exists. Please enter a different name.</source>
</trans-unit>
Expand All @@ -13,6 +16,9 @@
<trans-unit id="++CODE++22a97bc8f9b1cf66fa77f878b5a2cc57c52ad534e6ca38fbd6e5dd3b9854602c">
<source xml:lang="en">A webtemplate with the same name already exists. Please enter a different name.</source>
</trans-unit>
<trans-unit id="++CODE++bcfb3427790816de073090a76469fec945a3c7f5f82bbac338378ea22784c70a">
<source xml:lang="en">AI features have been disabled by your organization. Contact your admin for details. [Learn more](https://go.microsoft.com/fwlink/?linkid=2285848)</source>
</trans-unit>
<trans-unit id="++CODE++8d35e64354d3db3df1df4ef8e6068b6b9dd58514fcf980f7071e10ed160db95a">
<source xml:lang="en">AI-generated content can contain mistakes</source>
</trans-unit>
Expand Down Expand Up @@ -88,9 +94,6 @@
<trans-unit id="++CODE++916fa4a51e4d90e09a42289aa7961a6aff3401424f633240c630ac47f58a6d30">
<source xml:lang="en">Copied to clipboard!</source>
</trans-unit>
<trans-unit id="++CODE++6f6ff1fc17821e030a88681092957c279c6a5b1177f940017a4c5fd99fd1ea7b">
<source xml:lang="en">Copilot is not available. Please contact your administrator.</source>
</trans-unit>
<trans-unit id="++CODE++b749e205302cc21952a1e9646569ca0af9017cc5f39dd741830551bdd4ae823e">
<source xml:lang="en">Copy to clipboard</source>
</trans-unit>
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@
"name": "powerpages",
"fullName": "Copilot for Power Pages",
"description": "Copilot for Power Pages",
"isSticky": true,
"when": "never"
"isSticky": true
}
],
"problemMatchers": [
Expand Down
23 changes: 20 additions & 3 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ import { ArtemisService } from "../common/services/ArtemisService";
import { workspaceContainsPortalConfigFolder } from "../common/utilities/PathFinderUtil";
import { getPortalsOrgURLs } from "../common/utilities/WorkspaceInfoFinderUtil";
import { EXTENSION_ID, SUCCESS } from "../common/constants";
import { AadIdKey } from "../common/OneDSLoggerTelemetry/telemetryConstants";
import { AadIdKey, EnvIdKey, TenantIdKey } from "../common/OneDSLoggerTelemetry/telemetryConstants";
import { PowerPagesAppName, PowerPagesClientName } from "../common/ecs-features/constants";
import { ECSFeaturesClient } from "../common/ecs-features/ecsFeatureClient";

let client: LanguageClient;
let _context: vscode.ExtensionContext;
Expand Down Expand Up @@ -193,12 +195,27 @@ export async function activate(
const orgID = orgDetails.OrgId;
const artemisResponse = await ArtemisService.getArtemisResponse(orgID, _telemetry, "");
if (artemisResponse !== null && artemisResponse.response !== null) {
const { geoName, geoLongName } = artemisResponse.response;
const pacActiveAuth = await pacTerminal.getWrapper()?.activeAuth();
let AadIdObject;
let AadIdObject, EnvID, TenantID;
if ((pacActiveAuth && pacActiveAuth.Status === SUCCESS)) {
AadIdObject = pacActiveAuth.Results?.filter(obj => obj.Key === AadIdKey);
EnvID = pacActiveAuth.Results?.filter(obj => obj.Key === EnvIdKey);
TenantID = pacActiveAuth.Results?.filter(obj => obj.Key === TenantIdKey);
}
const { geoName, geoLongName } = artemisResponse.response;

if (EnvID?.[0]?.Value && TenantID?.[0]?.Value && AadIdObject?.[0]?.Value) {
await ECSFeaturesClient.init(_telemetry,
{
AppName: PowerPagesAppName,
EnvID: EnvID[0].Value,
UserID: AadIdObject[0].Value,
TenantID: TenantID[0].Value,
Region: artemisResponse.stamp
},
PowerPagesClientName);
}

oneDSLoggerWrapper.instantiate(geoName, geoLongName);
let initContext: object = { ...orgDetails, orgGeo: geoName };
if (AadIdObject?.[0]?.Value) {
Expand Down
4 changes: 3 additions & 1 deletion src/common/OneDSLoggerTelemetry/telemetryConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ export enum GeoNames {
// Custom telemetry feature flag
export const CUSTOM_TELEMETRY_FOR_POWER_PAGES_SETTING_NAME = 'enableTelemetry';

export const AadIdKey= 'Entra ID Object Id:';
export const AadIdKey= 'Entra ID Object Id:';
export const EnvIdKey = "Environment Id:";
export const TenantIdKey = "Tenant Id:";
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import { sendApiRequest } from '../../copilot/IntelligenceApiService';
import { PacWrapper } from '../../../client/pac/PacWrapper';
import { intelligenceAPIAuthentication } from '../../services/AuthenticationProvider';
import { ActiveOrgOutput } from '../../../client/pac/PacTypes';
import { AUTHENTICATION_FAILED_MSG, COPILOT_NOT_AVAILABLE_MSG, DISCLAIMER_MESSAGE, INVALID_RESPONSE, NO_PROMPT_MESSAGE, PAC_AUTH_INPUT, PAC_AUTH_NOT_FOUND, POWERPAGES_CHAT_PARTICIPANT_ID, RESPONSE_AWAITED_MSG, RESPONSE_SCENARIOS, SKIP_CODES, STATER_PROMPTS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_LOCATION_REFERENCED, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WEBPAGE_RELATED_FILES, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT, WELCOME_MESSAGE, WELCOME_PROMPT } from './PowerPagesChatParticipantConstants';
import { AUTHENTICATION_FAILED_MSG, COPILOT_NOT_AVAILABLE_MSG, COPILOT_NOT_RELEASED_MSG, DISCLAIMER_MESSAGE, INVALID_RESPONSE, NO_PROMPT_MESSAGE, PAC_AUTH_INPUT, PAC_AUTH_NOT_FOUND, POWERPAGES_CHAT_PARTICIPANT_ID, RESPONSE_AWAITED_MSG, RESPONSE_SCENARIOS, SKIP_CODES, STATER_PROMPTS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_LOCATION_REFERENCED, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NOT_AVAILABLE_ECS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WEBPAGE_RELATED_FILES, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT, WELCOME_MESSAGE, WELCOME_PROMPT } from './PowerPagesChatParticipantConstants';
import { ORG_DETAILS_KEY, handleOrgChangeSuccess, initializeOrgDetails } from '../../utilities/OrgHandlerUtils';
import { createAndReferenceLocation, getComponentInfo, getEndpoint, provideChatParticipantFollowups, handleChatParticipantFeedback, createErrorResult, createSuccessResult, removeChatVariables } from './PowerPagesChatParticipantUtils';
import { checkCopilotAvailability, fetchRelatedFiles, getActiveEditorContent } from '../../utilities/Utils';
import { IIntelligenceAPIEndpointInformation } from '../../services/Interfaces';
import { v4 as uuidv4 } from 'uuid';
import { orgChangeErrorEvent, orgChangeEvent } from '../../../client/OrgChangeNotifier';
import { isPowerPagesGitHubCopilotEnabled } from '../../copilot/utils/copilotUtil';
import { ADX_WEBPAGE, IApiRequestParams, IRelatedFiles } from '../../constants';
import { oneDSLoggerWrapper } from '../../OneDSLoggerTelemetry/oneDSLoggerWrapper';

Expand All @@ -42,7 +43,7 @@ export class PowerPagesChatParticipant {
this.chatParticipant = createChatParticipant(POWERPAGES_CHAT_PARTICIPANT_ID, this.handler);

//TODO: Check the icon image
this.chatParticipant.iconPath = vscode.Uri.joinPath(context.extensionUri, 'src', 'common', 'chat-participants', 'powerpages', 'assets', 'copilot.png');
this.chatParticipant.iconPath = vscode.Uri.joinPath(context.extensionUri, 'src', 'common', 'chat-participants', 'powerpages', 'assets', 'copilot.svg');

this.chatParticipant.onDidReceiveFeedback((feedback: vscode.ChatResultFeedback) => {
handleChatParticipantFeedback(feedback, this.powerPagesAgentSessionId, this.telemetry);
Expand Down Expand Up @@ -107,6 +108,13 @@ export class PowerPagesChatParticipant {
this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS, { orgID: this.orgID, environmentID: this.environmentID, sessionId: this.powerPagesAgentSessionId });
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS, { orgID: this.orgID, environmentID: this.environmentID, sessionId: this.powerPagesAgentSessionId });

if (!isPowerPagesGitHubCopilotEnabled()) {
stream.markdown(COPILOT_NOT_RELEASED_MSG);
this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NOT_AVAILABLE_ECS, { sessionId: this.powerPagesAgentSessionId, orgID: this.orgID });
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NOT_AVAILABLE_ECS, { sessionId: this.powerPagesAgentSessionId, orgID: this.orgID });
return createSuccessResult('', RESPONSE_SCENARIOS.COPILOT_NOT_RELEASED, this.orgID);
}

const intelligenceApiAuthResponse = await intelligenceAPIAuthentication(this.telemetry, this.powerPagesAgentSessionId, this.orgID, true);

if (!intelligenceApiAuthResponse) {
Expand Down Expand Up @@ -219,7 +227,7 @@ export class PowerPagesChatParticipant {

private async initializeOrgDetails(): Promise<void> {
try {
const { orgID, orgUrl, environmentID } = await initializeOrgDetails(this.isOrgDetailsInitialized, this.extensionContext, this._pacWrapper);
const { orgID, orgUrl, environmentID } = await initializeOrgDetails(this.isOrgDetailsInitialized, this._pacWrapper);

if (!orgID) {
return;
Expand All @@ -234,7 +242,7 @@ export class PowerPagesChatParticipant {
}

private async handleOrgChangeSuccess(orgDetails: ActiveOrgOutput): Promise<void> {
const { orgID, orgUrl, environmentID } = handleOrgChangeSuccess(orgDetails, this.extensionContext);
const { orgID, orgUrl, environmentID } = handleOrgChangeSuccess(orgDetails);
this.orgID = orgID;
this.orgUrl = orgUrl;
this.environmentID = environmentID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const RESPONSE_SCENARIOS = {
FORM_PROMPT: 'FORM_PROMPT',
LIST_PROMPT: 'LIST_PROMPT',
WEB_API_PROMPT: 'WEB_API_PROMPT',
WELCOME_PROMPT: 'WELCOME_PROMPT'
WELCOME_PROMPT: 'WELCOME_PROMPT',
COPILOT_NOT_RELEASED: 'COPILOT_NOT_RELEASED'
};

// Localized strings
Expand All @@ -40,6 +41,7 @@ export const INVALID_RESPONSE = vscode.l10n.t('Something went wrong. Don’t wor
export const DISCLAIMER_MESSAGE = vscode.l10n.t('Make sure AI-generated content is accurate and appropriate before using. [Learn more](https://go.microsoft.com/fwlink/?linkid=2240145) | [View terms](https://go.microsoft.com/fwlink/?linkid=2189520)');
export const NO_PROMPT_MESSAGE = vscode.l10n.t('Hi! Power Pages lets you build secure, professional websites that you can quickly configure and publish across web browsers and devices.\n\nTo create your website, visit the [Power Pages](https://powerpages.microsoft.com/).\nReturn to this chat and @powerpages can help you write and edit your website code.');
export const PAC_AUTH_INPUT = vscode.l10n.t("Checking for active auth profile...");
export const COPILOT_NOT_RELEASED_MSG = vscode.l10n.t("@PowerPages is not yet available in your region.")

// Telemetry Event Names
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED = 'VSCodeExtensionGitHubPowerPagesAgentInvoked';
Expand All @@ -54,5 +56,6 @@ export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_LOCATION_REFERENCED = 'VS
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT = 'VSCodeExtensionGitHubPowerPagesAgentNoPrompt';
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT = 'VSCodeExtensionGitHubPowerPagesAgentWelcomePrompt';
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT = 'VSCodeExtensionGitHubPowerPagesAgentSuccessfulPrompt';
export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NOT_AVAILABLE_ECS = 'VSCodeExtensionGitHubPowerPagesAgentNotAvailableECS';


36 changes: 36 additions & 0 deletions src/common/chat-participants/powerpages/assets/copilot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion src/common/copilot/utils/copilotUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as vscode from "vscode";
import { PacWrapper } from "../../../client/pac/PacWrapper";
import { ECSFeaturesClient } from "../../ecs-features/ecsFeatureClient";
import { CopilotDisableList, EnableProDevCopilot } from "../../ecs-features/ecsFeatureGates";
import { CopilotDisableList, EnablePowerPagesGitHubCopilot, EnableProDevCopilot } from "../../ecs-features/ecsFeatureGates";
import { AUTH_CREATE_FAILED, AUTH_CREATE_MESSAGE } from "../constants";
import { showInputBoxAndGetOrgUrl, showProgressWithNotification } from "../../utilities/Utils";
import { SUCCESS } from "../../constants";
Expand Down Expand Up @@ -79,3 +79,13 @@ export function enableCrossGeoDataFlowInGeo() {

return enableCrossGeoDataFlowInGeo.split(',').map(org => org.trim());
}

export function isPowerPagesGitHubCopilotEnabled() {
const enablePowerpagesInGithubCopilot = ECSFeaturesClient.getConfig(EnablePowerPagesGitHubCopilot).enablePowerpagesInGithubCopilot

if(enablePowerpagesInGithubCopilot === undefined) {
return false;
}

return enablePowerpagesInGithubCopilot;
}
10 changes: 10 additions & 0 deletions src/common/ecs-features/ecsFeatureGates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ export const {
"capiSupportedProDevCopilotGeoWithCrossGeoDataFlow": "eu,se,ch,fr,de,no"
},
});

export const {
feature: EnablePowerPagesGitHubCopilot
} = getFeatureConfigs({
teamName: PowerPagesClientName,
description: 'Enable Power Pages GitHub Copilot',
fallback: {
enablePowerpagesInGithubCopilot: false,
},
});
Loading

0 comments on commit 0912e35

Please sign in to comment.