From eacee49e07e8ea64a1749458fb1db38dfdbe792c Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Tue, 16 Jul 2024 15:12:58 +0530 Subject: [PATCH 1/5] feat: Add @powerpages feedback telemetry --- .../powerpages/PowerPagesChatParticipant.ts | 31 ++++++++++++++++--- .../PowerPagesChatParticipantConstants.ts | 2 ++ .../PowerPagesChatParticipantTypes.ts | 2 ++ .../PowerPagesChatParticipantUtils.ts | 13 +++++++- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts index 880b3525..0574f6cf 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts @@ -13,7 +13,7 @@ import { intelligenceAPIAuthentication } from '../../services/AuthenticationProv import { ActiveOrgOutput } from '../../../client/pac/PacTypes'; import { AUTHENTICATION_FAILED_MSG, COPILOT_NOT_AVAILABLE_MSG, NO_PROMPT_MESSAGE, PAC_AUTH_NOT_FOUND, POWERPAGES_CHAT_PARTICIPANT_ID, RESPONSE_AWAITED_MSG, SKIP_CODES, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, 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 } from './PowerPagesChatParticipantConstants'; import { ORG_DETAILS_KEY, handleOrgChangeSuccess, initializeOrgDetails } from '../../utilities/OrgHandlerUtils'; -import { getComponentInfo, getEndpoint } from './PowerPagesChatParticipantUtils'; +import { getComponentInfo, getEndpoint, handleChatParticipantFeedback } from './PowerPagesChatParticipantUtils'; import { checkCopilotAvailability, getActiveEditorContent } from '../../utilities/Utils'; import { IIntelligenceAPIEndpointInformation } from '../../services/Interfaces'; import { v4 as uuidv4 } from 'uuid'; @@ -42,6 +42,11 @@ export class PowerPagesChatParticipant { //TODO: Check the icon image this.chatParticipant.iconPath = vscode.Uri.joinPath(context.extensionUri, 'src', 'common', 'chat-participants', 'powerpages', 'assets', 'copilot.png'); + this.chatParticipant.onDidReceiveFeedback((feedback: vscode.ChatResultFeedback) => { + handleChatParticipantFeedback(feedback, this.powerPagesAgentSessionId, this.telemetry); + } + ); + this.powerPagesAgentSessionId = uuidv4(); this.telemetry = telemetry; @@ -91,7 +96,8 @@ export class PowerPagesChatParticipant { this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND, { sessionId: this.powerPagesAgentSessionId }); return { metadata: { - command: '' + command: '', + scenario: 'PAC_AUTH_NOT_FOUND' } }; } @@ -105,6 +111,8 @@ export class PowerPagesChatParticipant { return { metadata: { command: '', + scenario: 'AUTHENTICATION_FAILED_MSG', + orgId: this.orgID } }; } @@ -119,7 +127,9 @@ export class PowerPagesChatParticipant { stream.markdown(COPILOT_NOT_AVAILABLE_MSG) return { metadata: { - command: '' + command: '', + scenario: 'COPILOT_NOT_AVAILABLE_MSG', + orgId: this.orgID } }; } @@ -138,7 +148,9 @@ export class PowerPagesChatParticipant { return { metadata: { - command: '' + command: '', + scenario: 'NO_PROMPT_MESSAGE', + orgId: this.orgID } }; } @@ -163,11 +175,20 @@ export class PowerPagesChatParticipant { stream.markdown('\n'); }); + return { + metadata: { + command: '', + scenario: scenario.toString(), + orgId: this.orgID + } + }; } return { metadata: { - command: '' + command: '', + scenario: '', + orgId: this.orgID } }; diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts index 0a0f8271..071c3d43 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts @@ -18,6 +18,8 @@ export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED = 'GitHubPowerPag export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS = 'GitHubPowerPagesAgentOrgDetails'; export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND = 'GitHubPowerPagesAgentOrgDetailsNotFound'; export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO = 'GitHubPowerPagesAgentScenario'; +export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSUP = 'GitHubPowerPagesAgentScenarioFeedbackThumbsUp'; +export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSDOWN = 'GitHubPowerPagesAgentScenarioFeedbackThumbsDown'; export const SKIP_CODES = ["", null, undefined, "violation", "unclear", "explain"]; diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantTypes.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantTypes.ts index 2f852de4..bbe60240 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantTypes.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantTypes.ts @@ -8,6 +8,8 @@ import * as vscode from 'vscode'; export interface IPowerPagesChatResult extends vscode.ChatResult { metadata: { command: string; + scenario: string; + orgId?: string; } } export interface IOrgDetails { diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts index 96128ead..a785d66f 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts @@ -10,8 +10,9 @@ import { ITelemetry } from "../../OneDSLoggerTelemetry/telemetry/ITelemetry"; import { ArtemisService } from "../../services/ArtemisService"; import { dataverseAuthentication } from "../../services/AuthenticationProvider"; import { IIntelligenceAPIEndpointInformation } from "../../services/Interfaces"; -import { SUPPORTED_ENTITIES } from "./PowerPagesChatParticipantConstants"; +import { SUPPORTED_ENTITIES, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSDOWN, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSUP } from "./PowerPagesChatParticipantConstants"; import { IComponentInfo } from "./PowerPagesChatParticipantTypes"; +import * as vscode from 'vscode'; export async function getEndpoint( orgID: string, @@ -55,3 +56,13 @@ export async function getComponentInfo(telemetry: ITelemetry, orgUrl: string | u export function isEntityInSupportedList(entity: string): boolean { return SUPPORTED_ENTITIES.includes(entity); } + +export function handleChatParticipantFeedback (feedback: vscode.ChatResultFeedback, sessionId: string, telemetry: ITelemetry) { + const scenario = feedback.result.metadata?.scenario; + const orgId = feedback.result.metadata?.orgId; + if (feedback.kind === 1) { + telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSUP, { feedback: feedback.kind.toString(), scenario: scenario, orgId:orgId, sessionId: sessionId }); + } else if (feedback.kind === 0) { + telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSDOWN, { feedback: feedback.kind.toString(), scenario: scenario, orgId: orgId, sessionId: sessionId}); + } +} From 9dd42a923a6d901f9956ef26d719ab7ebfe1c8c7 Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Wed, 14 Aug 2024 18:06:27 +0530 Subject: [PATCH 2/5] refactor: response return and feedback --- .../powerpages/PowerPagesChatParticipant.ts | 177 ++++++++---------- .../PowerPagesChatParticipantConstants.ts | 2 + .../PowerPagesChatParticipantUtils.ts | 24 ++- 3 files changed, 98 insertions(+), 105 deletions(-) diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts index 06c97377..00a96173 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts @@ -12,9 +12,9 @@ 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, NO_PROMPT_MESSAGE, PAC_AUTH_NOT_FOUND, POWERPAGES_CHAT_PARTICIPANT_ID, RESPONSE_AWAITED_MSG, SKIP_CODES, STATER_PROMPTS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, 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, WELCOME_MESSAGE, WELCOME_PROMPT } from './PowerPagesChatParticipantConstants'; +import { AUTHENTICATION_FAILED_MSG, COPILOT_NOT_AVAILABLE_MSG, DISCLAIMER_MESSAGE, INVALID_RESPONSE, NO_PROMPT_MESSAGE, PAC_AUTH_NOT_FOUND, POWERPAGES_CHAT_PARTICIPANT_ID, RESPONSE_AWAITED_MSG, SKIP_CODES, STATER_PROMPTS, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR, VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, 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, WELCOME_MESSAGE, WELCOME_PROMPT } from './PowerPagesChatParticipantConstants'; import { ORG_DETAILS_KEY, handleOrgChangeSuccess, initializeOrgDetails } from '../../utilities/OrgHandlerUtils'; -import { createAndReferenceLocation, getComponentInfo, getEndpoint, provideChatParticipantFollowups, handleChatParticipantFeedback } from './PowerPagesChatParticipantUtils'; +import { createAndReferenceLocation, getComponentInfo, getEndpoint, provideChatParticipantFollowups, handleChatParticipantFeedback, createErrorResult, createSuccessResult } from './PowerPagesChatParticipantUtils'; import { checkCopilotAvailability, getActiveEditorContent } from '../../utilities/Utils'; import { IIntelligenceAPIEndpointInformation } from '../../services/Interfaces'; import { v4 as uuidv4 } from 'uuid'; @@ -85,127 +85,96 @@ export class PowerPagesChatParticipant { stream: vscode.ChatResponseStream, //_token: vscode.CancellationToken ): Promise => { - // Handle chat requests here + try { + stream.progress(RESPONSE_AWAITED_MSG); + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, { sessionId: this.powerPagesAgentSessionId }); - stream.progress(RESPONSE_AWAITED_MSG) + await this.initializeOrgDetails(); - this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_INVOKED, { sessionId: this.powerPagesAgentSessionId }); - - await this.initializeOrgDetails(); - - if (!this.orgID || !this.environmentID) { - stream.markdown(PAC_AUTH_NOT_FOUND); - this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND, { sessionId: this.powerPagesAgentSessionId }); - return { - metadata: { - command: '', - scenario: 'PAC_AUTH_NOT_FOUND' - } - }; - } - - this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS, { orgID: this.orgID, environmentID: this.environmentID, sessionId: this.powerPagesAgentSessionId }); - - const intelligenceApiAuthResponse = await intelligenceAPIAuthentication(this.telemetry, this.powerPagesAgentSessionId, this.orgID, true); - - if (!intelligenceApiAuthResponse) { - stream.markdown(AUTHENTICATION_FAILED_MSG); - return { - metadata: { - command: '', - scenario: 'AUTHENTICATION_FAILED_MSG', - orgId: this.orgID - } - }; - } - - const intelligenceApiToken = intelligenceApiAuthResponse.accessToken; - - const intelligenceAPIEndpointInfo = await getEndpoint(this.orgID, this.environmentID, this.telemetry, this.cachedEndpoint, this.powerPagesAgentSessionId); - - const copilotAvailabilityStatus = checkCopilotAvailability(intelligenceAPIEndpointInfo.intelligenceEndpoint, this.orgID, this.telemetry, this.powerPagesAgentSessionId); + if (!this.orgID || !this.environmentID) { + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND, { sessionId: this.powerPagesAgentSessionId }); + return createErrorResult(PAC_AUTH_NOT_FOUND, 'PAC_AUTH_NOT_FOUND', ''); + } - if (!copilotAvailabilityStatus) { - stream.markdown(COPILOT_NOT_AVAILABLE_MSG) - return { - metadata: { - command: '', - scenario: 'COPILOT_NOT_AVAILABLE_MSG', - orgId: this.orgID - } - }; - } + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS, { orgID: this.orgID, environmentID: this.environmentID, sessionId: this.powerPagesAgentSessionId }); - const userPrompt = request.prompt; + const intelligenceApiAuthResponse = await intelligenceAPIAuthentication(this.telemetry, this.powerPagesAgentSessionId, this.orgID, true); - if (userPrompt === WELCOME_PROMPT) { - stream.markdown(WELCOME_MESSAGE); - return { - metadata: { - command: STATER_PROMPTS - } + if (!intelligenceApiAuthResponse) { + return createErrorResult(AUTHENTICATION_FAILED_MSG, 'AUTHENTICATION_FAILED_MSG', this.orgID); } - } - - if (!userPrompt) { - stream.markdown(NO_PROMPT_MESSAGE); - return { - metadata: { - command: '', - scenario: 'NO_PROMPT_MESSAGE', - orgId: this.orgID - } - }; - } - const { activeFileContent, activeFileUri, startLine, endLine, activeFileParams } = getActiveEditorContent(); + const intelligenceApiToken = intelligenceApiAuthResponse.accessToken; + const intelligenceAPIEndpointInfo = await getEndpoint(this.orgID, this.environmentID, this.telemetry, this.cachedEndpoint, this.powerPagesAgentSessionId); - const location = activeFileUri ? createAndReferenceLocation(activeFileUri, startLine, endLine) : undefined; + const copilotAvailabilityStatus = checkCopilotAvailability(intelligenceAPIEndpointInfo.intelligenceEndpoint, this.orgID, this.telemetry, this.powerPagesAgentSessionId); - if (location) { - stream.reference(location); - } - if (request.command) { - //TODO: Handle command scenarios + if (!copilotAvailabilityStatus) { + return createErrorResult(COPILOT_NOT_AVAILABLE_MSG, 'COPILOT_NOT_AVAILABLE_MSG', this.orgID); + } - } else { - const { componentInfo, entityName }: IComponentInfo = await getComponentInfo(this.telemetry, this.orgUrl, activeFileParams, this.powerPagesAgentSessionId); + const userPrompt = request.prompt; - const llmResponse = await sendApiRequest([{ displayText: userPrompt, code: activeFileContent }], activeFileParams, this.orgID, intelligenceApiToken, this.powerPagesAgentSessionId, entityName, componentInfo, this.telemetry, intelligenceAPIEndpointInfo.intelligenceEndpoint, intelligenceAPIEndpointInfo.geoName, intelligenceAPIEndpointInfo.crossGeoDataMovementEnabledPPACFlag); + if (userPrompt === WELCOME_PROMPT) { + stream.markdown(WELCOME_MESSAGE); + return createSuccessResult(STATER_PROMPTS, 'WELCOME_MESSAGE', this.orgID); + } - const scenario = llmResponse.length > 1 ? llmResponse[llmResponse.length - 1] : llmResponse[0].displayText; + if (!userPrompt) { + stream.markdown(NO_PROMPT_MESSAGE); + return createSuccessResult('', 'NO_PROMPT_MESSAGE', this.orgID); + } - this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO, { scenario: scenario, sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID }) + const { activeFileContent, activeFileUri, startLine, endLine, activeFileParams } = getActiveEditorContent(); + const location = activeFileUri ? createAndReferenceLocation(activeFileUri, startLine, endLine) : undefined; - llmResponse.forEach((response: { displayText: string | vscode.MarkdownString; code: string; }) => { + if (location) { + stream.reference(location); + } - if (response.displayText) { - stream.markdown(response.displayText); + if (request.command) { + //TODO: Handle command scenarios + } else { + const { componentInfo, entityName }: IComponentInfo = await getComponentInfo(this.telemetry, this.orgUrl, activeFileParams, this.powerPagesAgentSessionId); + + const llmResponse = await sendApiRequest( + [{ displayText: userPrompt, code: activeFileContent }], + activeFileParams, + this.orgID, + intelligenceApiToken, + this.powerPagesAgentSessionId, + entityName, + componentInfo, + this.telemetry, + intelligenceAPIEndpointInfo.intelligenceEndpoint, + intelligenceAPIEndpointInfo.geoName, + intelligenceAPIEndpointInfo.crossGeoDataMovementEnabledPPACFlag + ); + + const scenario = llmResponse.length > 1 ? llmResponse[llmResponse.length - 1] : llmResponse[0].displayText; + + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO, { scenario: scenario, sessionId: this.powerPagesAgentSessionId, orgId: this.orgID, environmentId: this.environmentID }); + + llmResponse.forEach((response: { displayText: string | vscode.MarkdownString; code: string; }) => { + if (response.displayText) { + stream.markdown(response.displayText); + stream.markdown('\n'); + } + if (response.code && !SKIP_CODES.includes(response.code)) { + stream.markdown('\n```javascript\n' + response.code + '\n```'); + } stream.markdown('\n'); - } - if (response.code && !SKIP_CODES.includes(response.code)) { - stream.markdown('\n```javascript\n' + response.code + '\n```'); - } - stream.markdown('\n'); - }); - stream.markdown(DISCLAIMER_MESSAGE); - return { - metadata: { - command: '', - scenario: scenario.toString(), - orgId: this.orgID - } - }; - } + }); - return { - metadata: { - command: '', - scenario: '', - orgId: this.orgID + stream.markdown(DISCLAIMER_MESSAGE); + return createSuccessResult('', scenario.toString(), this.orgID); } - }; + return createSuccessResult('', '', this.orgID); + } catch (error) { + this.telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR, { sessionId: this.powerPagesAgentSessionId, error: error as string }); + return createErrorResult(INVALID_RESPONSE, 'UNEXPECTED_ERROR', this.orgID? this.orgID : ''); + } }; private async initializeOrgDetails(): Promise { diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts index 69273acd..5e5e8dc9 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts @@ -12,6 +12,7 @@ export const RESPONSE_AWAITED_MSG = vscode.l10n.t('Working on it...'); export const AUTHENTICATION_FAILED_MSG = vscode.l10n.t('Authentication failed. Please try again.'); export const COPILOT_NOT_AVAILABLE_MSG = vscode.l10n.t('Copilot is not available. Please contact your administrator.'); export const PAC_AUTH_NOT_FOUND = vscode.l10n.t('Active auth profile is not found or has expired. Please try again.'); +export const INVALID_RESPONSE = vscode.l10n.t('Something went wrong. Don’t worry, you can try again.'); 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 SUPPORTED_ENTITIES = [ADX_ENTITYFORM, ADX_ENTITYLIST]; // Telemetry Event Names @@ -21,6 +22,7 @@ export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ORG_DETAILS_NOT_FOUND = ' export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO = 'GitHubPowerPagesAgentScenario'; export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSUP = 'GitHubPowerPagesAgentScenarioFeedbackThumbsUp'; export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_SCENARIO_FEEDBACK_THUMBSDOWN = 'GitHubPowerPagesAgentScenarioFeedbackThumbsDown'; +export const VSCODE_EXTENSION_GITHUB_POWER_PAGES_AGENT_ERROR = 'GitHubPowerPagesAgentError'; export const SKIP_CODES = ["", null, undefined, "violation", "unclear", "explain"]; export const EXPLAIN_CODE_PROMPT = vscode.l10n.t('Explain the following code {% include \'Page Copy\'%}'); export const WEB_API_PROMPT = vscode.l10n.t('Write web API code to query active contact records.'); diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts index 727738ba..c57dd51e 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantUtils.ts @@ -85,5 +85,27 @@ export function provideChatParticipantFollowups(result: IPowerPagesChatResult, _ { prompt: FORM_PROMPT } ]; } -} +} + +export function createErrorResult(message: string, scenario: string, orgId: string): IPowerPagesChatResult { + return { + metadata: { + command: '', + scenario: scenario, + orgId: orgId + }, + errorDetails: { + message: message + } + }; +} +export function createSuccessResult(command: string, scenario: string, orgId: string): IPowerPagesChatResult { + return { + metadata: { + command: command, + scenario: scenario, + orgId: orgId + } + }; +} From 5e8f59659f3e05f73ba7992d32cdf0c2c85141bf Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Wed, 21 Aug 2024 15:20:02 +0530 Subject: [PATCH 3/5] refactor:ADX_WEBPAGE CONSTANT --- .../powerpages/PowerPagesChatParticipant.ts | 24 +++++++++---------- src/common/constants.ts | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts index 260eee3a..44917981 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts @@ -19,7 +19,7 @@ import { checkCopilotAvailability, fetchRelatedFiles, getActiveEditorContent } f import { IIntelligenceAPIEndpointInformation } from '../../services/Interfaces'; import { v4 as uuidv4 } from 'uuid'; import { orgChangeErrorEvent, orgChangeEvent } from '../../../client/OrgChangeNotifier'; -import { IRelatedFiles } from '../../constants'; +import { ADX_WEBPAGE, IRelatedFiles } from '../../constants'; export class PowerPagesChatParticipant { private static instance: PowerPagesChatParticipant | null = null; @@ -138,17 +138,17 @@ 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) { - 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) { + 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); diff --git a/src/common/constants.ts b/src/common/constants.ts index 137dd692..2aae2c94 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -65,3 +65,4 @@ export interface IRelatedFiles { } export const COPILOT_RELATED_FILES_FETCH_FAILED = "CopilotRelatedFilesFetchFailed"; +export const ADX_WEBPAGE = 'adx_webpage' From 38a028fe8c0c2ac17008776e576444bc588e52f3 Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Thu, 22 Aug 2024 07:05:11 +0530 Subject: [PATCH 4/5] refactor: Update PowerPagesChatParticipantConstants formatting --- .../PowerPagesChatParticipantConstants.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts index 93171d1b..703a9f19 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipantConstants.ts @@ -31,6 +31,18 @@ export const LIST_PROMPT = vscode.l10n.t('Write JavaScript code to highlight the export const STATER_PROMPTS = "starterPrompts" export const WELCOME_PROMPT = 'how can you help with coding for my website?' export const WELCOME_MESSAGE = vscode.l10n.t('Hi! @powerpages can help you write, edit, and even summarize your website code.') -export const RESPONSE_SCENARIOS = {PAC_AUTH_NOT_FOUND: 'PAC_AUTH_NOT_FOUND', AUTHENTICATION_FAILED: 'AUTHENTICATION_FAILED', COPILOT_NOT_AVAILABLE: 'COPILOT_NOT_AVAILABLE', INVALID_RESPONSE: 'INVALID_RESPONSE', RESPONSE_AWAITED: 'RESPONSE_AWAITED', NO_PROMPT: 'NO_PROMPT', EXPLAIN_CODE_PROMPT: 'EXPLAIN_CODE_PROMPT', FORM_PROMPT: 'FORM_PROMPT', LIST_PROMPT: 'LIST_PROMPT', WEB_API_PROMPT: 'WEB_API_PROMPT', WELCOME_PROMPT: 'WELCOME_PROMPT'}; +export const RESPONSE_SCENARIOS = { + PAC_AUTH_NOT_FOUND: 'PAC_AUTH_NOT_FOUND', + AUTHENTICATION_FAILED: 'AUTHENTICATION_FAILED', + COPILOT_NOT_AVAILABLE: 'COPILOT_NOT_AVAILABLE', + INVALID_RESPONSE: 'INVALID_RESPONSE', + RESPONSE_AWAITED: 'RESPONSE_AWAITED', + NO_PROMPT: 'NO_PROMPT', + EXPLAIN_CODE_PROMPT: 'EXPLAIN_CODE_PROMPT', + FORM_PROMPT: 'FORM_PROMPT', + LIST_PROMPT: 'LIST_PROMPT', + WEB_API_PROMPT: 'WEB_API_PROMPT', + WELCOME_PROMPT: 'WELCOME_PROMPT' +}; From d0044a9901676158c95224ff2b7f8a1bbb789ff3 Mon Sep 17 00:00:00 2001 From: amitjoshi Date: Sun, 25 Aug 2024 18:57:46 +0530 Subject: [PATCH 5/5] refactor: Improve PowerPagesChatParticipant logic and error handling --- .../powerpages/PowerPagesChatParticipant.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts index 44917981..39e1c504 100644 --- a/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts +++ b/src/common/chat-participants/powerpages/PowerPagesChatParticipant.ts @@ -110,7 +110,7 @@ export class PowerPagesChatParticipant { const copilotAvailabilityStatus = checkCopilotAvailability(intelligenceAPIEndpointInfo.intelligenceEndpoint, this.orgID, this.telemetry, this.powerPagesAgentSessionId); - if (!copilotAvailabilityStatus) { + if (!copilotAvailabilityStatus || !intelligenceAPIEndpointInfo.intelligenceEndpoint) { return createErrorResult(COPILOT_NOT_AVAILABLE_MSG, RESPONSE_SCENARIOS.COPILOT_NOT_AVAILABLE, this.orgID); } @@ -119,9 +119,7 @@ export class PowerPagesChatParticipant { if (userPrompt === WELCOME_PROMPT) { stream.markdown(WELCOME_MESSAGE); return createSuccessResult(STATER_PROMPTS, RESPONSE_SCENARIOS.WELCOME_PROMPT, this.orgID); - } - - if (!userPrompt) { + } else if (!userPrompt) { stream.markdown(NO_PROMPT_MESSAGE); return createSuccessResult('', RESPONSE_SCENARIOS.NO_PROMPT, this.orgID); }