From 9997664aedd066759a901f79bfc58c87f885a0f8 Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Tue, 12 Nov 2024 15:46:11 +0530 Subject: [PATCH 1/5] Hook for create site command with nl2page&site --- .../PowerPagesChatParticipantConstants.ts | 3 ++ .../commands/create-site/CreateSiteCommand.ts | 41 ++++++++++++++++ .../commands/create-site/CreateSiteHelper.ts | 49 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts create mode 100644 src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts index 2145a6e3..1faa46f6 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts @@ -53,3 +53,6 @@ export const NL2SITE_SCENARIO = 'NL2Site'; export const NL2PAGE_GENERATE_NEW_PAGE = 'GenerateNewPage'; export const NL2SITE_GENERATE_NEW_SITE = 'GenerateNewSite'; export const NL2PAGE_SCOPE = 'Page'; +export const NL2SITE_REQUEST_FAILED = vscode.l10n.t('Failed to get site content from NL2Site service'); +export const NL2PAGE_GENERATING_WEBPAGES = vscode.l10n.t("Generating webpages..."); +export const NL2PAGE_RESPONSE_FAILED = 'Failed to get page content from NL2Page service'; diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts new file mode 100644 index 00000000..aa871c9a --- /dev/null +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + +import { Command } from "../../../CommandRegistry"; +import * as vscode from 'vscode'; +import { createSite } from "./CreateSiteHelper"; + +export class CreateSiteCommand implements Command { + async execute(request: any, stream: vscode.ChatResponseStream): Promise { + const { prompt, intelligenceAPIEndpointInfo, intelligenceApiToken, powerPagesAgentSessionId, telemetry } = request; + + stream.progress('Generating a new Power Pages site...'); + try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const result = await createSite( + intelligenceAPIEndpointInfo.intelligenceEndpoint, + intelligenceApiToken, + prompt, + powerPagesAgentSessionId, + stream, + telemetry + ); + // Process the result + + return { + metadata: { + command: 'create-site', + } + }; + } catch (error) { + //TODO: Handle error + return { + metadata: { + command: '' + } + }; + } + } +} diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts new file mode 100644 index 00000000..cb6f362b --- /dev/null +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts @@ -0,0 +1,49 @@ +/* + * 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 { ITelemetry } from '../../../../OneDSLoggerTelemetry/telemetry/ITelemetry'; +import { getNL2PageData } from './Nl2PageService'; +import { getNL2SiteData } from './Nl2SiteService'; +import { NL2SITE_REQUEST_FAILED, NL2PAGE_GENERATING_WEBPAGES, NL2PAGE_RESPONSE_FAILED } from '../../PowerPagesChatParticipantConstants'; + +export const createSite = async (intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, stream: vscode.ChatResponseStream, telemetry: ITelemetry) => { + try { + const { siteName, siteDescription } = await fetchSiteAndPageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry, stream); + + return { + siteName, + //websiteId, + siteDescription, + }; + + } catch (error) { + stream.markdown(`Error: ${(error as Error).message}`); + throw error; + } +}; + +async function fetchSiteAndPageData(intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, telemetry: ITelemetry, stream: vscode.ChatResponseStream) { + // Call NL2Site service to get initial site content + const { siteName, pages, siteDescription } = await getNL2SiteData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry); + + if (!siteName) { + stream.markdown(NL2SITE_REQUEST_FAILED); + throw new Error(NL2SITE_REQUEST_FAILED); + } + + const sitePagesList = pages.map((page: { pageName: string; }) => page.pageName); + + stream.progress(NL2PAGE_GENERATING_WEBPAGES); + + // Call NL2Page service to get page content + const sitePages = await getNL2PageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, siteName, sitePagesList, sessionId, telemetry); + + if (!sitePages) { + throw new Error(NL2PAGE_RESPONSE_FAILED); + } + + return { siteName, sitePagesList, sitePages, siteDescription }; +} From 3ea57344fb6e430774446b30865856062df3e69b Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Tue, 12 Nov 2024 15:59:13 +0530 Subject: [PATCH 2/5] Disable any type validation --- .../powerpages/commands/create-site/CreateSiteCommand.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts index aa871c9a..7bf8fcf1 100644 --- a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts @@ -8,6 +8,7 @@ import * as vscode from 'vscode'; import { createSite } from "./CreateSiteHelper"; export class CreateSiteCommand implements Command { + // eslint-disable-next-line @typescript-eslint/no-explicit-any async execute(request: any, stream: vscode.ChatResponseStream): Promise { const { prompt, intelligenceAPIEndpointInfo, intelligenceApiToken, powerPagesAgentSessionId, telemetry } = request; From 0689502c737578d66d81a3c250f096c20600e90f Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Wed, 13 Nov 2024 14:16:14 +0530 Subject: [PATCH 3/5] Refactor PowerPagesChatParticipantConstants and CreateSiteCommand - Add NL2SITE_GENERATING_SITE constant for generating a new Power Pages site - Update progress message in CreateSiteCommand to use NL2SITE_GENERATING_SITE constant - Remove unnecessary markdown formatting in CreateSiteHelper error handling --- .../powerpages/PowerPagesChatParticipantConstants.ts | 1 + .../powerpages/commands/create-site/CreateSiteCommand.ts | 3 ++- .../powerpages/commands/create-site/CreateSiteHelper.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts index 1faa46f6..4fe360ad 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts @@ -56,3 +56,4 @@ export const NL2PAGE_SCOPE = 'Page'; export const NL2SITE_REQUEST_FAILED = vscode.l10n.t('Failed to get site content from NL2Site service'); export const NL2PAGE_GENERATING_WEBPAGES = vscode.l10n.t("Generating webpages..."); export const NL2PAGE_RESPONSE_FAILED = 'Failed to get page content from NL2Page service'; +export const NL2SITE_GENERATING_SITE = vscode.l10n.t("Generating a new Power Pages site..."); diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts index 7bf8fcf1..53171c8c 100644 --- a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts @@ -6,13 +6,14 @@ import { Command } from "../../../CommandRegistry"; import * as vscode from 'vscode'; import { createSite } from "./CreateSiteHelper"; +import { NL2SITE_GENERATING_SITE } from "../../PowerPagesChatParticipantConstants"; export class CreateSiteCommand implements Command { // eslint-disable-next-line @typescript-eslint/no-explicit-any async execute(request: any, stream: vscode.ChatResponseStream): Promise { const { prompt, intelligenceAPIEndpointInfo, intelligenceApiToken, powerPagesAgentSessionId, telemetry } = request; - stream.progress('Generating a new Power Pages site...'); + stream.progress(NL2SITE_GENERATING_SITE); try { // eslint-disable-next-line @typescript-eslint/no-unused-vars const result = await createSite( diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts index cb6f362b..ae671bde 100644 --- a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts @@ -20,7 +20,7 @@ export const createSite = async (intelligenceEndpoint: string, intelligenceApiTo }; } catch (error) { - stream.markdown(`Error: ${(error as Error).message}`); + stream.markdown(`${(error as Error).message}`); throw error; } }; From 6cb3c290133f6887adc771f8d9af2ce6edf8c55e Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Wed, 13 Nov 2024 14:56:24 +0530 Subject: [PATCH 4/5] Refactor localization files and update Power Pages chat participant utils --- l10n/bundle.l10n.json | 5 ++++- loc/translations-export/vscode-powerplatform.xlf | 9 +++++++++ .../powerpages/PowerPagesChatParticipantUtils.ts | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index ef2a7b41..36ca2d22 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -83,6 +83,9 @@ "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.", + "Failed to get site content from NL2Site service": "Failed to get site content from NL2Site service", + "Generating webpages...": "Generating webpages...", + "Generating a new Power Pages site...": "Generating a new Power Pages site...", "Select Folder for new PCF Control/Do not translate 'PCF' as it is a product name.": { "message": "Select Folder for new PCF Control", "comment": [ @@ -256,4 +259,4 @@ "The {0} represents profile's Azure Cloud Instances" ] } -} +} \ No newline at end of file diff --git a/loc/translations-export/vscode-powerplatform.xlf b/loc/translations-export/vscode-powerplatform.xlf index e324304d..5cba25db 100644 --- a/loc/translations-export/vscode-powerplatform.xlf +++ b/loc/translations-export/vscode-powerplatform.xlf @@ -159,6 +159,9 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca Failed to get file ready for edit: {0} + + Failed to get site content from NL2Site service + Feature is not enabled for this geo. @@ -178,6 +181,12 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca GETTING STARTED + + Generating a new Power Pages site... + + + Generating webpages... + Get GitHub Copilot to try @powerpages diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts index 23ccd9cb..94749968 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts @@ -11,7 +11,8 @@ import { ITelemetry } from "../../OneDSLoggerTelemetry/telemetry/ITelemetry"; import { ArtemisService } from "../../services/ArtemisService"; import { dataverseAuthentication } from "../../services/AuthenticationProvider"; import { IIntelligenceAPIEndpointInformation } from "../../services/Interfaces"; -import { SUPPORTED_ENTITIES, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSDOWN, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSUP, EXPLAIN_CODE_PROMPT, FORM_PROMPT, LIST_PROMPT, STATER_PROMPTS, WEB_API_PROMPT } from "./PowerPagesChatParticipantConstants"; +import { SUPPORTED_ENTITIES, EXPLAIN_CODE_PROMPT, FORM_PROMPT, LIST_PROMPT, STATER_PROMPTS, WEB_API_PROMPT } from "./PowerPagesChatParticipantConstants"; +import { VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSUP, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSDOWN } from "./PowerPagesChatParticipantTelemetryConstants"; import { IComponentInfo, IPowerPagesChatResult } from "./PowerPagesChatParticipantTypes"; import * as vscode from 'vscode'; From 6544b114013ba6e5f240c632b3ad87f332d58856 Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Wed, 13 Nov 2024 16:20:54 +0530 Subject: [PATCH 5/5] Refactor NL2SiteService and Nl2PageService to include additional telemetry logging --- .../powerpages/PowerPagesChatParticipant.ts | 51 ++++++++++--------- .../PowerPagesChatParticipantConstants.ts | 3 +- ...rPagesChatParticipantTelemetryConstants.ts | 5 ++ .../commands/create-site/CreateSiteCommand.ts | 15 ++++-- .../commands/create-site/CreateSiteHelper.ts | 33 ++++++------ .../commands/create-site/Nl2PageService.ts | 4 +- .../commands/create-site/Nl2SiteService.ts | 9 ++-- 7 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts index 3a6d9a08..e1586846 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts @@ -23,7 +23,7 @@ import { isPowerPagesGitHubCopilotEnabled } from '../../copilot/utils/copilotUti import { ADX_WEBPAGE, IApiRequestParams, IRelatedFiles } from '../../constants'; import { oneDSLoggerWrapper } from '../../OneDSLoggerTelemetry/oneDSLoggerWrapper'; import { CommandRegistry } from '../CommandRegistry'; -import { VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NOT_AVAILABLE_ECS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_LOCATION_REFERENCED, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WEBPAGE_RELATED_FILES, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR } from './PowerPagesChatParticipantTelemetryConstants'; +import { VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NOT_AVAILABLE_ECS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_LOCATION_REFERENCED, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WEBPAGE_RELATED_FILES, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_COMMAND_TRIGGERED } from './PowerPagesChatParticipantTelemetryConstants'; // Initialize Command Registry and Register Commands const commandRegistry = new CommandRegistry(); @@ -141,18 +141,18 @@ export class PowerPagesChatParticipant { userPrompt = removeChatVariables(userPrompt); - this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT, {sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); - oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT, {sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SUCCESSFUL_PROMPT, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); if (userPrompt === WELCOME_PROMPT) { stream.markdown(WELCOME_MESSAGE); - this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT, {sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); - oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT, {sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WELCOME_PROMPT, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); return createSuccessResult(STATER_PROMPTS, RESPONSE_SCENARIOS.WELCOME_PROMPT, this.orgID); } else if (!userPrompt) { stream.markdown(NO_PROMPT_MESSAGE); - this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT, {sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); - oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT, {sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_NO_PROMPT, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); return createSuccessResult('', RESPONSE_SCENARIOS.NO_PROMPT, this.orgID); } @@ -160,6 +160,9 @@ export class PowerPagesChatParticipant { const location = activeFileUri ? createAndReferenceLocation(activeFileUri, startLine, endLine) : undefined; if (request.command) { + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_COMMAND_TRIGGERED, { commandName: request.command, sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_COMMAND_TRIGGERED, { commandName: request.command, sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + const command = commandRegistry.get(request.command); const commandRequest = { @@ -168,11 +171,13 @@ export class PowerPagesChatParticipant { intelligenceAPIEndpointInfo, intelligenceApiToken, powerPagesAgentSessionId: this.powerPagesAgentSessionId, - telemetry: this.telemetry + telemetry: this.telemetry, + orgID: this.orgID, + envID: this.environmentID, + userId: userId }; 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 }); @@ -182,19 +187,19 @@ export class PowerPagesChatParticipant { const relatedFiles: IRelatedFiles[] = []; - // Based on dataverse entity fetch required context for the active file - switch (activeFileParams.dataverseEntity) { - case ADX_WEBPAGE: - if (activeFileUri) { - this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WEBPAGE_RELATED_FILES, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); - oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WEBPAGE_RELATED_FILES, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); - const files = await fetchRelatedFiles(activeFileUri, activeFileParams.dataverseEntity, activeFileParams.fieldType, this.telemetry, this.powerPagesAgentSessionId); - relatedFiles.push(...files); - } - break; - default: - break; - } + // Based on dataverse entity fetch required context for the active file + switch (activeFileParams.dataverseEntity) { + case ADX_WEBPAGE: + if (activeFileUri) { + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WEBPAGE_RELATED_FILES, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_WEBPAGE_RELATED_FILES, { sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID, userId: userId }); + const files = await fetchRelatedFiles(activeFileUri, activeFileParams.dataverseEntity, activeFileParams.fieldType, this.telemetry, this.powerPagesAgentSessionId); + relatedFiles.push(...files); + } + break; + default: + break; + } const { componentInfo, entityName }: IComponentInfo = await getComponentInfo(this.telemetry, this.orgUrl, activeFileParams, this.powerPagesAgentSessionId); @@ -242,7 +247,7 @@ export class PowerPagesChatParticipant { } }; - private async initializeOrgDetails(): Promise { + private async initializeOrgDetails(): Promise { try { const { orgID, orgUrl, environmentID } = await initializeOrgDetails(this.isOrgDetailsInitialized, this._pacWrapper); diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts index 4fe360ad..5acd6fb3 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts @@ -53,7 +53,8 @@ export const NL2SITE_SCENARIO = 'NL2Site'; export const NL2PAGE_GENERATE_NEW_PAGE = 'GenerateNewPage'; export const NL2SITE_GENERATE_NEW_SITE = 'GenerateNewSite'; export const NL2PAGE_SCOPE = 'Page'; -export const NL2SITE_REQUEST_FAILED = vscode.l10n.t('Failed to get site content from NL2Site service'); +export const NL2SITE_REQUEST_FAILED = 'Failed to get site content from NL2Site service'; export const NL2PAGE_GENERATING_WEBPAGES = vscode.l10n.t("Generating webpages..."); export const NL2PAGE_RESPONSE_FAILED = 'Failed to get page content from NL2Page service'; export const NL2SITE_GENERATING_SITE = vscode.l10n.t("Generating a new Power Pages site..."); +export const FAILED_TO_CREATE_SITE = vscode.l10n.t('Failed to create a new Power Pages site. Please try again.'); diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantTelemetryConstants.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantTelemetryConstants.ts index 368a2284..0f685709 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantTelemetryConstants.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantTelemetryConstants.ts @@ -20,3 +20,8 @@ export const VSCODE_EXTENSION_NL2PAGE_REQUEST_FAILED = 'VSCodeExtensionNL2PageRe export const VSCODE_EXTENSION_NL2PAGE_REQUEST_SUCCESS = 'VSCodeExtensionNL2PageRequestSuccess'; export const VSCODE_EXTENSION_NL2SITE_REQUEST_FAILED = 'VSCodeExtensionNL2SiteRequestFailed'; export const VSCODE_EXTENSION_NL2SITE_REQUEST_SUCCESS = 'VSCodeExtensionNL2SiteRequestSuccess'; +export const VSCODE_EXTENSION_CREATE_SITE_REQUEST_SUCCESS = 'VSCodeExtensionNL2SiteRequestSuccess'; +export const VSCODE_EXTENSION_CREATE_SITE_COMMAND_FAILED = 'VSCodeExtensionNL2SiteCommandFailed'; +export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_COMMAND_TRIGGERED = 'VSCodeExtensionGitHubPowerPagesAgentCommandTriggered'; +export const VSCODE_EXTENSION_NL2PAGE_REQUEST = 'VSCodeExtensionNL2PageRequest'; +export const VSCODE_EXTENSION_NL2SITE_REQUEST = 'VSCodeExtensionNL2SiteRequest'; diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts index 53171c8c..b2db45a2 100644 --- a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteCommand.ts @@ -6,12 +6,14 @@ import { Command } from "../../../CommandRegistry"; import * as vscode from 'vscode'; import { createSite } from "./CreateSiteHelper"; -import { NL2SITE_GENERATING_SITE } from "../../PowerPagesChatParticipantConstants"; +import { FAILED_TO_CREATE_SITE, NL2SITE_GENERATING_SITE } from "../../PowerPagesChatParticipantConstants"; +import { oneDSLoggerWrapper } from "../../../../OneDSLoggerTelemetry/oneDSLoggerWrapper"; +import { VSCODE_EXTENSION_CREATE_SITE_COMMAND_FAILED} from "../../PowerPagesChatParticipantTelemetryConstants"; export class CreateSiteCommand implements Command { // eslint-disable-next-line @typescript-eslint/no-explicit-any async execute(request: any, stream: vscode.ChatResponseStream): Promise { - const { prompt, intelligenceAPIEndpointInfo, intelligenceApiToken, powerPagesAgentSessionId, telemetry } = request; + const { prompt, intelligenceAPIEndpointInfo, intelligenceApiToken, powerPagesAgentSessionId, telemetry, orgId, envId, userId } = request; stream.progress(NL2SITE_GENERATING_SITE); try { @@ -22,7 +24,10 @@ export class CreateSiteCommand implements Command { prompt, powerPagesAgentSessionId, stream, - telemetry + telemetry, + orgId, + envId, + userId ); // Process the result @@ -32,7 +37,9 @@ export class CreateSiteCommand implements Command { } }; } catch (error) { - //TODO: Handle error + stream.markdown(FAILED_TO_CREATE_SITE); + telemetry.sendTelemetryEvent(VSCODE_EXTENSION_CREATE_SITE_COMMAND_FAILED, { sessionId: powerPagesAgentSessionId, orgId:orgId, envId: envId, userId: userId, error: error as string }); + oneDSLoggerWrapper.getLogger().traceError(VSCODE_EXTENSION_CREATE_SITE_COMMAND_FAILED, error as string, error as Error, { sessionId: powerPagesAgentSessionId, orgId:orgId, envId: envId, userId: userId}, {}); return { metadata: { command: '' diff --git a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts index ae671bde..ddf2092a 100644 --- a/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts +++ b/src/common/chat-participants/powerpages/commands/create-site/CreateSiteHelper.ts @@ -8,29 +8,26 @@ import { ITelemetry } from '../../../../OneDSLoggerTelemetry/telemetry/ITelemetr import { getNL2PageData } from './Nl2PageService'; import { getNL2SiteData } from './Nl2SiteService'; import { NL2SITE_REQUEST_FAILED, NL2PAGE_GENERATING_WEBPAGES, NL2PAGE_RESPONSE_FAILED } from '../../PowerPagesChatParticipantConstants'; +import { oneDSLoggerWrapper } from '../../../../OneDSLoggerTelemetry/oneDSLoggerWrapper'; +import { VSCODE_EXTENSION_NL2PAGE_REQUEST, VSCODE_EXTENSION_NL2SITE_REQUEST } from '../../PowerPagesChatParticipantTelemetryConstants'; -export const createSite = async (intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, stream: vscode.ChatResponseStream, telemetry: ITelemetry) => { - try { - const { siteName, siteDescription } = await fetchSiteAndPageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry, stream); +export const createSite = async (intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, stream: vscode.ChatResponseStream, telemetry: ITelemetry, orgId: string, envID: string, userId: string) => { + const { siteName, siteDescription } = await fetchSiteAndPageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry, stream, orgId, envID, userId); - return { - siteName, - //websiteId, - siteDescription, - }; - - } catch (error) { - stream.markdown(`${(error as Error).message}`); - throw error; - } + return { + siteName, + //websiteId, + siteDescription, + }; }; -async function fetchSiteAndPageData(intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, telemetry: ITelemetry, stream: vscode.ChatResponseStream) { +async function fetchSiteAndPageData(intelligenceEndpoint: string, intelligenceApiToken: string, userPrompt: string, sessionId: string, telemetry: ITelemetry, stream: vscode.ChatResponseStream, orgId: string, envId: string, userId: string) { // Call NL2Site service to get initial site content - const { siteName, pages, siteDescription } = await getNL2SiteData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry); + telemetry.sendTelemetryEvent(VSCODE_EXTENSION_NL2SITE_REQUEST, { sessionId: sessionId, orgId: orgId, environmentId: envId, userId: userId }); + oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_NL2SITE_REQUEST, { sessionId: sessionId, orgId: orgId, environmentId: envId, userId: userId }); + const { siteName, pages, siteDescription } = await getNL2SiteData(intelligenceEndpoint, intelligenceApiToken, userPrompt, sessionId, telemetry, orgId, envId, userId); if (!siteName) { - stream.markdown(NL2SITE_REQUEST_FAILED); throw new Error(NL2SITE_REQUEST_FAILED); } @@ -39,7 +36,9 @@ async function fetchSiteAndPageData(intelligenceEndpoint: string, intelligenceAp stream.progress(NL2PAGE_GENERATING_WEBPAGES); // Call NL2Page service to get page content - const sitePages = await getNL2PageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, siteName, sitePagesList, sessionId, telemetry); + telemetry.sendTelemetryEvent(VSCODE_EXTENSION_NL2PAGE_REQUEST, { sessionId: sessionId, orgId: orgId, environmentId: envId, userId: userId }); + oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_NL2PAGE_REQUEST, { sessionId: sessionId, orgId: orgId, environmentId: envId, userId: userId }); + const sitePages = await getNL2PageData(intelligenceEndpoint, intelligenceApiToken, userPrompt, siteName, sitePagesList, sessionId, telemetry, orgId, envId, userId); if (!sitePages) { throw new Error(NL2PAGE_RESPONSE_FAILED); diff --git a/src/common/chat-participants/powerpages/commands/create-site/Nl2PageService.ts b/src/common/chat-participants/powerpages/commands/create-site/Nl2PageService.ts index f410f0fd..8cba41c3 100644 --- a/src/common/chat-participants/powerpages/commands/create-site/Nl2PageService.ts +++ b/src/common/chat-participants/powerpages/commands/create-site/Nl2PageService.ts @@ -3,12 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. */ +import { oneDSLoggerWrapper } from "../../../../OneDSLoggerTelemetry/oneDSLoggerWrapper"; import { ITelemetry } from "../../../../OneDSLoggerTelemetry/telemetry/ITelemetry"; import { getCommonHeaders } from "../../../../services/AuthenticationProvider"; import { ABOUT_PAGE_TYPE, FAQ_PAGE_TYPE, HOME_PAGE_TYPE, INFO_PAGE_TYPE, NL2PAGE_GENERATE_NEW_PAGE, NL2PAGE_REQUEST_FAILED, NL2PAGE_SCENARIO, NL2PAGE_SCOPE} from "../../PowerPagesChatParticipantConstants"; import { VSCODE_EXTENSION_NL2PAGE_REQUEST_FAILED, VSCODE_EXTENSION_NL2PAGE_REQUEST_SUCCESS } from "../../PowerPagesChatParticipantTelemetryConstants"; -export async function getNL2PageData(aibEndpoint: string, aibToken: string, userPrompt: string, siteName: string, sitePagesList: string[], sessionId: string, telemetry: ITelemetry) { +export async function getNL2PageData(aibEndpoint: string, aibToken: string, userPrompt: string, siteName: string, sitePagesList: string[], sessionId: string, telemetry: ITelemetry, orgId: string, envId: string, userId: string) { const constructRequestBody = (pageType: string, colorNumber:number, exampleNumber: number) => ({ "crossGeoOptions": { @@ -59,6 +60,7 @@ export async function getNL2PageData(aibEndpoint: string, aibToken: string, user return null; } catch (error) { telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_NL2PAGE_REQUEST_FAILED, { error: (error as Error)?.message, pageType }); + oneDSLoggerWrapper.getLogger().traceError(VSCODE_EXTENSION_NL2PAGE_REQUEST_FAILED, error as string, error as Error, { sessionId: sessionId, orgId:orgId, envId: envId, userId: userId, pageType: pageType}, {}); return null; } }); diff --git a/src/common/chat-participants/powerpages/commands/create-site/Nl2SiteService.ts b/src/common/chat-participants/powerpages/commands/create-site/Nl2SiteService.ts index 20a1a8e8..d13716af 100644 --- a/src/common/chat-participants/powerpages/commands/create-site/Nl2SiteService.ts +++ b/src/common/chat-participants/powerpages/commands/create-site/Nl2SiteService.ts @@ -5,10 +5,11 @@ import { ITelemetry } from "../../../../OneDSLoggerTelemetry/telemetry/ITelemetry"; import { NL2SITE_GENERATE_NEW_SITE, NL2SITE_INVALID_RESPONSE, NL2SITE_SCENARIO} from "../../PowerPagesChatParticipantConstants"; -import { VSCODE_EXTENSION_NL2SITE_REQUEST_SUCCESS, VSCODE_EXTENSION_NL2SITE_REQUEST_FAILED } from "../../PowerPagesChatParticipantTelemetryConstants"; +import {VSCODE_EXTENSION_NL2SITE_REQUEST_FAILED, VSCODE_EXTENSION_NL2SITE_REQUEST_SUCCESS } from "../../PowerPagesChatParticipantTelemetryConstants"; import { getCommonHeaders } from "../../../../services/AuthenticationProvider"; +import { oneDSLoggerWrapper } from "../../../../OneDSLoggerTelemetry/oneDSLoggerWrapper"; -export async function getNL2SiteData(aibEndpoint: string, aibToken: string, userPrompt: string, sessionId: string, telemetry: ITelemetry) { +export async function getNL2SiteData(aibEndpoint: string, aibToken: string, userPrompt: string, sessionId: string, telemetry: ITelemetry, orgId: string, envId: string, userId: string) { const requestBody = { "crossGeoOptions": { "enableCrossGeoCall": true @@ -43,12 +44,14 @@ export async function getNL2SiteData(aibEndpoint: string, aibToken: string, user if (responseBody && responseBody.additionalData[0]?.website) { telemetry.sendTelemetryEvent(VSCODE_EXTENSION_NL2SITE_REQUEST_SUCCESS, {sessionId: sessionId}); + oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_NL2SITE_REQUEST_SUCCESS, { sessionId: sessionId, orgId: orgId, environmentId: envId, userId: userId }); return responseBody.additionalData[0].website; // Contains the pages, siteName & site description } else { throw new Error(NL2SITE_INVALID_RESPONSE); } } catch (error) { - telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_NL2SITE_REQUEST_FAILED, { error: (error as Error)?.message }); + telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_NL2SITE_REQUEST_FAILED, { sessionId: sessionId, error: (error as Error)?.message }); + oneDSLoggerWrapper.getLogger().traceError(VSCODE_EXTENSION_NL2SITE_REQUEST_FAILED, error as string, error as Error, { sessionId: sessionId, orgId:orgId, envId: envId, userId: userId}, {}); return null; } }