From 6a7b0d52808c711355f9bac2032458526fdaa878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nidhi=20Tyagi=20=F0=9F=8C=9F=F0=9F=90=87=F0=9F=8C=B4?= =?UTF-8?q?=E2=9D=84=EF=B8=8F?= Date: Tue, 28 Nov 2023 13:00:19 +0530 Subject: [PATCH] Expand to Eu, AU, and UK geos for copilot --- src/common/ArtemisService.ts | 106 +++++++++++++++++--------------- src/common/copilot/constants.ts | 29 +++++---- 2 files changed, 71 insertions(+), 64 deletions(-) diff --git a/src/common/ArtemisService.ts b/src/common/ArtemisService.ts index c8f930b5..9e9509b4 100644 --- a/src/common/ArtemisService.ts +++ b/src/common/ArtemisService.ts @@ -4,29 +4,29 @@ */ import fetch, { RequestInit } from "node-fetch"; -import { COPILOT_UNAVAILABLE, US_GEO } from "./copilot/constants"; +import { AUSTRALIA_GEO, COPILOT_UNAVAILABLE, EUROPE_GEO, UK_GEO, US_GEO } from "./copilot/constants"; import { ITelemetry } from "../client/telemetry/ITelemetry"; import { sendTelemetryEvent } from "./copilot/telemetry/copilotTelemetry"; import { CopilotArtemisFailureEvent, CopilotArtemisSuccessEvent } from "./copilot/telemetry/telemetryConstants"; export async function getIntelligenceEndpoint(orgId: string, telemetry: ITelemetry, sessionID: string) { - const artemisResponse = await fetchArtemisResponse(orgId, telemetry, sessionID); + const artemisResponse = await fetchArtemisResponse(orgId, telemetry, sessionID); - if (!artemisResponse) { - return null; - } + if (!artemisResponse) { + return null; + } - const { geoName, environment, clusterNumber } = artemisResponse[0]; - sendTelemetryEvent(telemetry, { eventName: CopilotArtemisSuccessEvent, copilotSessionId: sessionID, geoName: String(geoName), orgId: orgId }); + const { geoName, environment, clusterNumber } = artemisResponse[0]; + sendTelemetryEvent(telemetry, { eventName: CopilotArtemisSuccessEvent, copilotSessionId: sessionID, geoName: String(geoName), orgId: orgId }); - if (geoName !== US_GEO) { - return COPILOT_UNAVAILABLE; - } + if (!isGeoSupported(geoName)) { + return COPILOT_UNAVAILABLE; + } - const intelligenceEndpoint = `https://aibuildertextapiservice.${geoName}-${'il' + clusterNumber}.gateway.${environment}.island.powerapps.com/v1.0/${orgId}/appintelligence/chat` + const intelligenceEndpoint = `https://aibuildertextapiservice.${geoName}-${'il' + clusterNumber}.gateway.${environment}.island.powerapps.com/v1.0/${orgId}/appintelligence/chat` - return intelligenceEndpoint; + return intelligenceEndpoint; } @@ -38,35 +38,35 @@ export async function fetchArtemisResponse(orgId: string, telemetry: ITelemetry, const artemisResponse = await fetchIslandInfo(endpoints, telemetry, sessionID); return artemisResponse; - } +} async function fetchIslandInfo(endpoints: string[], telemetry: ITelemetry, sessionID: string) { - const requestInit: RequestInit = { - method: 'GET', - redirect: 'follow' - }; - - try { - const promises = endpoints.map(async endpoint => { - try { - const response = await fetch(endpoint, requestInit); - if (!response.ok) { - throw new Error('Request failed'); - } - return response.json(); - } catch (error) { + const requestInit: RequestInit = { + method: 'GET', + redirect: 'follow' + }; + + try { + const promises = endpoints.map(async endpoint => { + try { + const response = await fetch(endpoint, requestInit); + if (!response.ok) { + throw new Error('Request failed'); + } + return response.json(); + } catch (error) { + return null; + } + }); + + const responses = await Promise.all(promises); + const successfulResponses = responses.filter(response => response !== null); + return successfulResponses; + } catch (error) { + sendTelemetryEvent(telemetry, { eventName: CopilotArtemisFailureEvent, copilotSessionId: sessionID, error: error as Error }) return null; - } - }); - - const responses = await Promise.all(promises); - const successfulResponses = responses.filter(response => response !== null); - return successfulResponses; - } catch (error) { - sendTelemetryEvent(telemetry, { eventName: CopilotArtemisFailureEvent, copilotSessionId: sessionID, error: error as Error }) - return null; - } + } } @@ -79,18 +79,22 @@ async function fetchIslandInfo(endpoints: string[], telemetry: ITelemetry, sessi * Prod: https:// c7809087d9b84a00a78aa4b901caa2.3f.organization.api.powerplatform.com/artemis */ export function convertGuidToUrls(orgId: string) { - const updatedOrgId = orgId.replace(/-/g, ""); - const domain = updatedOrgId.slice(0, -1); - const domainProd = updatedOrgId.slice(0, -2); - const nonProdSegment = updatedOrgId.slice(-1); - const prodSegment = updatedOrgId.slice(-2); - const tstUrl = `https://${domain}.${nonProdSegment}.organization.api.test.powerplatform.com/gateway/cluster?api-version=1`; - const preprodUrl = `https://${domain}.${nonProdSegment}.organization.api.preprod.powerplatform.com/gateway/cluster?api-version=1`; - const prodUrl = `https://${domainProd}.${prodSegment}.organization.api.powerplatform.com/gateway/cluster?api-version=1`; - - return { - tstUrl, - preprodUrl, - prodUrl - }; + const updatedOrgId = orgId.replace(/-/g, ""); + const domain = updatedOrgId.slice(0, -1); + const domainProd = updatedOrgId.slice(0, -2); + const nonProdSegment = updatedOrgId.slice(-1); + const prodSegment = updatedOrgId.slice(-2); + const tstUrl = `https://${domain}.${nonProdSegment}.organization.api.test.powerplatform.com/gateway/cluster?api-version=1`; + const preprodUrl = `https://${domain}.${nonProdSegment}.organization.api.preprod.powerplatform.com/gateway/cluster?api-version=1`; + const prodUrl = `https://${domainProd}.${prodSegment}.organization.api.powerplatform.com/gateway/cluster?api-version=1`; + + return { + tstUrl, + preprodUrl, + prodUrl + }; +} + +export function isGeoSupported(geoName: string) { + return geoName === US_GEO || geoName === AUSTRALIA_GEO || geoName === EUROPE_GEO || geoName === UK_GEO; } diff --git a/src/common/copilot/constants.ts b/src/common/copilot/constants.ts index 34f0f4ba..954e83d4 100644 --- a/src/common/copilot/constants.ts +++ b/src/common/copilot/constants.ts @@ -16,6 +16,9 @@ export const sendIconSvg = ` ([ - ['webpage', 'adx_webpage'], - ['list', 'adx_entitylist'], - ['webtemplate', 'adx_webtemplate'], - ['basicform', 'adx_entityform'], - ['advancedformstep', 'adx_entityform'], + ['webpage', 'adx_webpage'], + ['list', 'adx_entitylist'], + ['webtemplate', 'adx_webtemplate'], + ['basicform', 'adx_entityform'], + ['advancedformstep', 'adx_entityform'], ]); export const EntityFieldMap = new Map([ - ['custom_javascript', 'adx_customjavascript'], - ['source', 'adx_source'], - ['copy', 'adx_copy'] + ['custom_javascript', 'adx_customjavascript'], + ['source', 'adx_source'], + ['copy', 'adx_copy'] ]); export const FieldTypeMap = new Map([ - ['js', 'JavaScript'], - ['html', 'html'] + ['js', 'JavaScript'], + ['html', 'html'] ]); export const AuthProfileNotFound = [{ displayText: "Active auth profile is not found or has expired. Create an Auth profile to start chatting with Copilot again.", code: '' }];