@microsoft/agents-copilotstudio-client 0.5.12-g2d752e9b13 → 0.5.19-gc1e2ea1096
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/browser.mjs +7 -7
- package/dist/src/browser.mjs.map +4 -4
- package/dist/src/connectionSettings.js +2 -2
- package/dist/src/connectionSettings.js.map +1 -1
- package/dist/src/copilotStudioClient.d.ts +5 -0
- package/dist/src/copilotStudioClient.js +5 -0
- package/dist/src/copilotStudioClient.js.map +1 -1
- package/dist/src/powerPlatformEnvironment.d.ts +11 -0
- package/dist/src/powerPlatformEnvironment.js +92 -1
- package/dist/src/powerPlatformEnvironment.js.map +1 -1
- package/package.json +3 -3
- package/src/connectionSettings.ts +2 -2
- package/src/copilotStudioClient.ts +7 -1
- package/src/powerPlatformEnvironment.ts +92 -1
|
@@ -35,10 +35,10 @@ const loadCopilotStudioConnectionSettingsFromEnv = () => {
|
|
|
35
35
|
appClientId: (_a = process.env.appClientId) !== null && _a !== void 0 ? _a : '',
|
|
36
36
|
tenantId: (_b = process.env.tenantId) !== null && _b !== void 0 ? _b : '',
|
|
37
37
|
environmentId: (_c = process.env.environmentId) !== null && _c !== void 0 ? _c : '',
|
|
38
|
-
cloud: cloudStr ? powerPlatformCloud_1.PowerPlatformCloud[cloudStr] :
|
|
38
|
+
cloud: cloudStr ? powerPlatformCloud_1.PowerPlatformCloud[cloudStr] : powerPlatformCloud_1.PowerPlatformCloud.Prod,
|
|
39
39
|
customPowerPlatformCloud: process.env.customPowerPlatformCloud,
|
|
40
40
|
agentIdentifier: process.env.agentIdentifier,
|
|
41
|
-
copilotAgentType: agentStr ? agentType_1.AgentType[agentStr] :
|
|
41
|
+
copilotAgentType: agentStr ? agentType_1.AgentType[agentStr] : agentType_1.AgentType.Published,
|
|
42
42
|
directConnectUrl: process.env.directConnectUrl,
|
|
43
43
|
useExperimentalEndpoint: ((_d = process.env.useExperimentalEndpoint) === null || _d === void 0 ? void 0 : _d.toLocaleLowerCase()) === 'true'
|
|
44
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionSettings.js","sourceRoot":"","sources":["../../src/connectionSettings.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAAuC;AAEvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,kBAAkB;IAA/B;QACE,wCAAwC;QACjC,gBAAW,GAAW,EAAE,CAAA;QAC/B,wCAAwC;QACjC,aAAQ,GAAW,EAAE,CAAA;QAC5B,6CAA6C;QACtC,kBAAa,GAAW,EAAE,CAAA;QAWjC,yDAAyD;QAClD,4BAAuB,GAAa,KAAK,CAAA;IAClD,CAAC;CAAA;AAnBD,gDAmBC;AAED;;;GAGG;AACI,MAAM,0CAA0C,GAA6B,GAAG,EAAE;;IACvF,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,KAAoD,CAAA;IACjF,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAsD,CAAA;IAEnF,OAAO;QACL,WAAW,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,WAAW,mCAAI,EAAE;QAC1C,QAAQ,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,mCAAI,EAAE;QACpC,aAAa,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,aAAa,mCAAI,EAAE;QAC9C,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,uCAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"connectionSettings.js","sourceRoot":"","sources":["../../src/connectionSettings.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAAuC;AAEvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,kBAAkB;IAA/B;QACE,wCAAwC;QACjC,gBAAW,GAAW,EAAE,CAAA;QAC/B,wCAAwC;QACjC,aAAQ,GAAW,EAAE,CAAA;QAC5B,6CAA6C;QACtC,kBAAa,GAAW,EAAE,CAAA;QAWjC,yDAAyD;QAClD,4BAAuB,GAAa,KAAK,CAAA;IAClD,CAAC;CAAA;AAnBD,gDAmBC;AAED;;;GAGG;AACI,MAAM,0CAA0C,GAA6B,GAAG,EAAE;;IACvF,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,KAAoD,CAAA;IACjF,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAsD,CAAA;IAEnF,OAAO;QACL,WAAW,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,WAAW,mCAAI,EAAE;QAC1C,QAAQ,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,QAAQ,mCAAI,EAAE;QACpC,aAAa,EAAE,MAAA,OAAO,CAAC,GAAG,CAAC,aAAa,mCAAI,EAAE;QAC9C,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,uCAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,uCAAkB,CAAC,IAAI;QACxE,wBAAwB,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB;QAC9D,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe;QAC5C,gBAAgB,EAAE,QAAQ,CAAC,CAAC,CAAC,qBAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,qBAAS,CAAC,SAAS;QACtE,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB;QAC9C,uBAAuB,EAAE,CAAA,MAAA,OAAO,CAAC,GAAG,CAAC,uBAAuB,0CAAE,iBAAiB,EAAE,MAAK,MAAM;KAChE,CAAA;AAChC,CAAC,CAAA;AAfY,QAAA,0CAA0C,8CAetD"}
|
|
@@ -17,6 +17,11 @@ export declare class CopilotStudioClient {
|
|
|
17
17
|
private readonly client;
|
|
18
18
|
/** The logger for debugging. */
|
|
19
19
|
private readonly logger;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the Scope URL needed to connect to Copilot Studio from the Connection Settings.
|
|
22
|
+
* @param settings Copilot Studio Connection Settings.
|
|
23
|
+
*/
|
|
24
|
+
static scopeFromSettings: (settings: ConnectionSettings) => string;
|
|
20
25
|
/**
|
|
21
26
|
* Creates an instance of CopilotStudioClient.
|
|
22
27
|
* @param settings The connection settings.
|
|
@@ -168,4 +168,9 @@ exports.CopilotStudioClient = CopilotStudioClient;
|
|
|
168
168
|
CopilotStudioClient.conversationIdHeaderKey = 'x-ms-conversationid';
|
|
169
169
|
/** Island Header key */
|
|
170
170
|
CopilotStudioClient.islandExperimentalUrlHeaderKey = 'x-ms-d2e-experimental';
|
|
171
|
+
/**
|
|
172
|
+
* Returns the Scope URL needed to connect to Copilot Studio from the Connection Settings.
|
|
173
|
+
* @param settings Copilot Studio Connection Settings.
|
|
174
|
+
*/
|
|
175
|
+
CopilotStudioClient.scopeFromSettings = powerPlatformEnvironment_1.getTokenAudience;
|
|
171
176
|
//# sourceMappingURL=copilotStudioClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilotStudioClient.js","sourceRoot":"","sources":["../../src/copilotStudioClient.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,kDAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"copilotStudioClient.js","sourceRoot":"","sources":["../../src/copilotStudioClient.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,kDAAgE;AAChE,yEAA4F;AAC5F,gEAAyF;AACzF,6DAAyD;AACzD,kDAA6C;AAC7C,uGAAuE;AACvE,4CAAmB;AAOnB,MAAa,mBAAmB;IAqB9B;;;;OAIG;IACH,YAAa,QAA4B,EAAE,KAAa;QApBxD,0CAA0C;QAClC,mBAAc,GAAW,EAAE,CAAA;QAoBjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,EAAE,CAAA;QAC5B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAA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AAM,GAAuB;YACjC,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,UAAU;YACf,OAAO,EAAE;gBACP,MAAM,EAAE,mBAAmB;gBAC3B,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,KAAK;YACX,YAAY,EAAE,QAAQ;YACtB,OAAO,EAAE,OAAO;SACjB,CAAA;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAClD,OAAO,MAAM,CAAA;IACf,CAAC;;AAnLH,kDAoLC;AAnLC,sCAAsC;AACd,2CAAuB,GAAW,qBAAqB,AAAhC,CAAgC;AAC/E,wBAAwB;AACA,kDAA8B,GAAW,uBAAuB,AAAlC,CAAkC;AAWxF;;;GAGG;AACI,qCAAiB,GAA6C,2CAAgB,AAA7D,CAA6D"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { ConnectionSettings } from './connectionSettings';
|
|
6
|
+
import { PowerPlatformCloud } from './powerPlatformCloud';
|
|
6
7
|
/**
|
|
7
8
|
* Generates the connection URL for Copilot Studio.
|
|
8
9
|
* @param settings - The connection settings.
|
|
@@ -11,3 +12,13 @@ import { ConnectionSettings } from './connectionSettings';
|
|
|
11
12
|
* @throws Will throw an error if required settings are missing or invalid.
|
|
12
13
|
*/
|
|
13
14
|
export declare function getCopilotStudioConnectionUrl(settings: ConnectionSettings, conversationId?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the Power Platform API Audience.
|
|
17
|
+
* @param settings - Configuration Settings to use.
|
|
18
|
+
* @param cloud - Optional Power Platform Cloud Hosting Agent.
|
|
19
|
+
* @param cloudBaseAddress - Optional Power Platform API endpoint to use if Cloud is configured as "other".
|
|
20
|
+
* @param directConnectUrl - Optional DirectConnection URL to a given Copilot Studio agent, if provided all other settings are ignored.
|
|
21
|
+
* @returns The Power Platform Audience.
|
|
22
|
+
* @throws Will throw an error if required settings are missing or invalid.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getTokenAudience(settings?: ConnectionSettings, cloud?: PowerPlatformCloud, cloudBaseAddress?: string, directConnectUrl?: string): string;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.getCopilotStudioConnectionUrl = getCopilotStudioConnectionUrl;
|
|
8
|
+
exports.getTokenAudience = getTokenAudience;
|
|
8
9
|
const agentType_1 = require("./agentType");
|
|
9
10
|
const powerPlatformCloud_1 = require("./powerPlatformCloud");
|
|
10
11
|
const prebuiltBotStrategy_1 = require("./strategies/prebuiltBotStrategy");
|
|
@@ -82,9 +83,70 @@ function getCopilotStudioConnectionUrl(settings, conversationId) {
|
|
|
82
83
|
}[agentType]();
|
|
83
84
|
return strategy.getConversationUrl(conversationId);
|
|
84
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the Power Platform API Audience.
|
|
88
|
+
* @param settings - Configuration Settings to use.
|
|
89
|
+
* @param cloud - Optional Power Platform Cloud Hosting Agent.
|
|
90
|
+
* @param cloudBaseAddress - Optional Power Platform API endpoint to use if Cloud is configured as "other".
|
|
91
|
+
* @param directConnectUrl - Optional DirectConnection URL to a given Copilot Studio agent, if provided all other settings are ignored.
|
|
92
|
+
* @returns The Power Platform Audience.
|
|
93
|
+
* @throws Will throw an error if required settings are missing or invalid.
|
|
94
|
+
*/
|
|
95
|
+
function getTokenAudience(settings, cloud = powerPlatformCloud_1.PowerPlatformCloud.Unknown, cloudBaseAddress = '', directConnectUrl = '') {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
if (!directConnectUrl && !(settings === null || settings === void 0 ? void 0 : settings.directConnectUrl)) {
|
|
98
|
+
if (cloud === powerPlatformCloud_1.PowerPlatformCloud.Other && !cloudBaseAddress) {
|
|
99
|
+
throw new Error('cloudBaseAddress must be provided when PowerPlatformCloudCategory is Other');
|
|
100
|
+
}
|
|
101
|
+
if (!settings && cloud === powerPlatformCloud_1.PowerPlatformCloud.Unknown) {
|
|
102
|
+
throw new Error('Either settings or cloud must be provided');
|
|
103
|
+
}
|
|
104
|
+
if (settings && settings.cloud && settings.cloud !== powerPlatformCloud_1.PowerPlatformCloud.Unknown) {
|
|
105
|
+
cloud = settings.cloud;
|
|
106
|
+
}
|
|
107
|
+
if (cloud === powerPlatformCloud_1.PowerPlatformCloud.Other) {
|
|
108
|
+
if (cloudBaseAddress && isValidUri(cloudBaseAddress)) {
|
|
109
|
+
cloud = powerPlatformCloud_1.PowerPlatformCloud.Other;
|
|
110
|
+
}
|
|
111
|
+
else if ((settings === null || settings === void 0 ? void 0 : settings.customPowerPlatformCloud) && isValidUri(settings.customPowerPlatformCloud)) {
|
|
112
|
+
cloud = powerPlatformCloud_1.PowerPlatformCloud.Other;
|
|
113
|
+
cloudBaseAddress = settings.customPowerPlatformCloud;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw new Error('Either CustomPowerPlatformCloud or cloudBaseAddress must be provided when PowerPlatformCloudCategory is Other');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
cloudBaseAddress !== null && cloudBaseAddress !== void 0 ? cloudBaseAddress : (cloudBaseAddress = 'api.unknown.powerplatform.com');
|
|
120
|
+
return `https://${getEndpointSuffix(cloud, cloudBaseAddress)}/.default`;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
if (!directConnectUrl) {
|
|
124
|
+
directConnectUrl = (_a = settings === null || settings === void 0 ? void 0 : settings.directConnectUrl) !== null && _a !== void 0 ? _a : '';
|
|
125
|
+
}
|
|
126
|
+
if (directConnectUrl && isValidUri(directConnectUrl)) {
|
|
127
|
+
if (decodeCloudFromURI(new URL(directConnectUrl)) === powerPlatformCloud_1.PowerPlatformCloud.Unknown) {
|
|
128
|
+
const cloudToTest = (_b = settings === null || settings === void 0 ? void 0 : settings.cloud) !== null && _b !== void 0 ? _b : cloud;
|
|
129
|
+
if (cloudToTest === powerPlatformCloud_1.PowerPlatformCloud.Other || cloudToTest === powerPlatformCloud_1.PowerPlatformCloud.Unknown) {
|
|
130
|
+
throw new Error('Unable to resolve the PowerPlatform Cloud from DirectConnectUrl. The Token Audience resolver requires a specific PowerPlatformCloudCategory.');
|
|
131
|
+
}
|
|
132
|
+
if (cloudToTest !== powerPlatformCloud_1.PowerPlatformCloud.Unknown) {
|
|
133
|
+
return `https://${getEndpointSuffix(cloudToTest, '')}/.default`;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
throw new Error('Unable to resolve the PowerPlatform Cloud from DirectConnectUrl. The Token Audience resolver requires a specific PowerPlatformCloudCategory.');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return `https://${getEndpointSuffix(decodeCloudFromURI(new URL(directConnectUrl)), '')}/.default`;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
throw new Error('DirectConnectUrl must be provided when DirectConnectUrl is set');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
85
146
|
function isValidUri(uri) {
|
|
86
147
|
try {
|
|
87
|
-
const
|
|
148
|
+
const absoluteUrl = uri.startsWith('http') ? uri : `https://${uri}`;
|
|
149
|
+
const newUri = new URL(absoluteUrl);
|
|
88
150
|
return !!newUri;
|
|
89
151
|
}
|
|
90
152
|
catch {
|
|
@@ -165,4 +227,33 @@ function getIdSuffixLength(cloud) {
|
|
|
165
227
|
return 1;
|
|
166
228
|
}
|
|
167
229
|
}
|
|
230
|
+
function decodeCloudFromURI(uri) {
|
|
231
|
+
const host = uri.host.toLowerCase();
|
|
232
|
+
switch (host) {
|
|
233
|
+
case 'api.powerplatform.localhost':
|
|
234
|
+
return powerPlatformCloud_1.PowerPlatformCloud.Local;
|
|
235
|
+
case 'api.exp.powerplatform.com':
|
|
236
|
+
return powerPlatformCloud_1.PowerPlatformCloud.Exp;
|
|
237
|
+
case 'api.dev.powerplatform.com':
|
|
238
|
+
return powerPlatformCloud_1.PowerPlatformCloud.Dev;
|
|
239
|
+
case 'api.prv.powerplatform.com':
|
|
240
|
+
return powerPlatformCloud_1.PowerPlatformCloud.Prv;
|
|
241
|
+
case 'api.test.powerplatform.com':
|
|
242
|
+
return powerPlatformCloud_1.PowerPlatformCloud.Test;
|
|
243
|
+
case 'api.preprod.powerplatform.com':
|
|
244
|
+
return powerPlatformCloud_1.PowerPlatformCloud.Preprod;
|
|
245
|
+
case 'api.powerplatform.com':
|
|
246
|
+
return powerPlatformCloud_1.PowerPlatformCloud.Prod;
|
|
247
|
+
case 'api.gov.powerplatform.microsoft.us':
|
|
248
|
+
return powerPlatformCloud_1.PowerPlatformCloud.GovFR;
|
|
249
|
+
case 'api.high.powerplatform.microsoft.us':
|
|
250
|
+
return powerPlatformCloud_1.PowerPlatformCloud.High;
|
|
251
|
+
case 'api.appsplatform.us':
|
|
252
|
+
return powerPlatformCloud_1.PowerPlatformCloud.DoD;
|
|
253
|
+
case 'api.powerplatform.partner.microsoftonline.cn':
|
|
254
|
+
return powerPlatformCloud_1.PowerPlatformCloud.Mooncake;
|
|
255
|
+
default:
|
|
256
|
+
return powerPlatformCloud_1.PowerPlatformCloud.Unknown;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
168
259
|
//# sourceMappingURL=powerPlatformEnvironment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powerPlatformEnvironment.js","sourceRoot":"","sources":["../../src/powerPlatformEnvironment.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAeH,sEAmFC;
|
|
1
|
+
{"version":3,"file":"powerPlatformEnvironment.js","sourceRoot":"","sources":["../../src/powerPlatformEnvironment.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAeH,sEAmFC;AAWD,4CAiDC;AA5JD,2CAAuC;AAEvC,6DAAyD;AACzD,0EAAsE;AACtE,4EAAwE;AAExE;;;;;;GAMG;AACH,SAAgB,6BAA6B,CAC3C,QAA4B,EAC5B,cAAuB;;IAEvB,IA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
|
|
3
|
+
"version": "0.5.19-gc1e2ea1096",
|
|
4
4
|
"homepage": "https://github.com/microsoft/Agents-for-js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"build:browser": "esbuild --platform=browser --target=es2019 --format=esm --bundle --sourcemap --minify --outfile=dist/src/browser.mjs src/index.ts"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@microsoft/agents-activity": "0.5.
|
|
30
|
+
"@microsoft/agents-activity": "0.5.19-gc1e2ea1096",
|
|
31
31
|
"axios": "^1.9.0",
|
|
32
32
|
"debug": "^4.3.7",
|
|
33
33
|
"rxjs": "5.5.12",
|
|
@@ -52,6 +52,6 @@
|
|
|
52
52
|
"./package.json": "./package.json"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
|
-
"node": ">=
|
|
55
|
+
"node": ">=20.0.0"
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -43,10 +43,10 @@ export const loadCopilotStudioConnectionSettingsFromEnv: () => ConnectionSetting
|
|
|
43
43
|
appClientId: process.env.appClientId ?? '',
|
|
44
44
|
tenantId: process.env.tenantId ?? '',
|
|
45
45
|
environmentId: process.env.environmentId ?? '',
|
|
46
|
-
cloud: cloudStr ? PowerPlatformCloud[cloudStr] :
|
|
46
|
+
cloud: cloudStr ? PowerPlatformCloud[cloudStr] : PowerPlatformCloud.Prod,
|
|
47
47
|
customPowerPlatformCloud: process.env.customPowerPlatformCloud,
|
|
48
48
|
agentIdentifier: process.env.agentIdentifier,
|
|
49
|
-
copilotAgentType: agentStr ? AgentType[agentStr] :
|
|
49
|
+
copilotAgentType: agentStr ? AgentType[agentStr] : AgentType.Published,
|
|
50
50
|
directConnectUrl: process.env.directConnectUrl,
|
|
51
51
|
useExperimentalEndpoint: process.env.useExperimentalEndpoint?.toLocaleLowerCase() === 'true'
|
|
52
52
|
} satisfies ConnectionSettings
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { ConnectionSettings } from './connectionSettings'
|
|
7
7
|
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'
|
|
8
|
-
import { getCopilotStudioConnectionUrl } from './powerPlatformEnvironment'
|
|
8
|
+
import { getCopilotStudioConnectionUrl, getTokenAudience } from './powerPlatformEnvironment'
|
|
9
9
|
import { Activity, ActivityTypes, ConversationAccount } from '@microsoft/agents-activity'
|
|
10
10
|
import { ExecuteTurnRequest } from './executeTurnRequest'
|
|
11
11
|
import createDebug, { Debugger } from 'debug'
|
|
@@ -32,6 +32,12 @@ export class CopilotStudioClient {
|
|
|
32
32
|
/** The logger for debugging. */
|
|
33
33
|
private readonly logger: Debugger
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Returns the Scope URL needed to connect to Copilot Studio from the Connection Settings.
|
|
37
|
+
* @param settings Copilot Studio Connection Settings.
|
|
38
|
+
*/
|
|
39
|
+
static scopeFromSettings: (settings: ConnectionSettings) => string = getTokenAudience
|
|
40
|
+
|
|
35
41
|
/**
|
|
36
42
|
* Creates an instance of CopilotStudioClient.
|
|
37
43
|
* @param settings The connection settings.
|
|
@@ -101,9 +101,69 @@ export function getCopilotStudioConnectionUrl (
|
|
|
101
101
|
return strategy.getConversationUrl(conversationId)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Returns the Power Platform API Audience.
|
|
106
|
+
* @param settings - Configuration Settings to use.
|
|
107
|
+
* @param cloud - Optional Power Platform Cloud Hosting Agent.
|
|
108
|
+
* @param cloudBaseAddress - Optional Power Platform API endpoint to use if Cloud is configured as "other".
|
|
109
|
+
* @param directConnectUrl - Optional DirectConnection URL to a given Copilot Studio agent, if provided all other settings are ignored.
|
|
110
|
+
* @returns The Power Platform Audience.
|
|
111
|
+
* @throws Will throw an error if required settings are missing or invalid.
|
|
112
|
+
*/
|
|
113
|
+
export function getTokenAudience (
|
|
114
|
+
settings?: ConnectionSettings,
|
|
115
|
+
cloud: PowerPlatformCloud = PowerPlatformCloud.Unknown,
|
|
116
|
+
cloudBaseAddress: string = '',
|
|
117
|
+
directConnectUrl: string = ''): string {
|
|
118
|
+
if (!directConnectUrl && !settings?.directConnectUrl) {
|
|
119
|
+
if (cloud === PowerPlatformCloud.Other && !cloudBaseAddress) {
|
|
120
|
+
throw new Error('cloudBaseAddress must be provided when PowerPlatformCloudCategory is Other')
|
|
121
|
+
}
|
|
122
|
+
if (!settings && cloud === PowerPlatformCloud.Unknown) {
|
|
123
|
+
throw new Error('Either settings or cloud must be provided')
|
|
124
|
+
}
|
|
125
|
+
if (settings && settings.cloud && settings.cloud !== PowerPlatformCloud.Unknown) {
|
|
126
|
+
cloud = settings.cloud
|
|
127
|
+
}
|
|
128
|
+
if (cloud === PowerPlatformCloud.Other) {
|
|
129
|
+
if (cloudBaseAddress && isValidUri(cloudBaseAddress)) {
|
|
130
|
+
cloud = PowerPlatformCloud.Other
|
|
131
|
+
} else if (settings?.customPowerPlatformCloud && isValidUri(settings!.customPowerPlatformCloud)) {
|
|
132
|
+
cloud = PowerPlatformCloud.Other
|
|
133
|
+
cloudBaseAddress = settings.customPowerPlatformCloud
|
|
134
|
+
} else {
|
|
135
|
+
throw new Error('Either CustomPowerPlatformCloud or cloudBaseAddress must be provided when PowerPlatformCloudCategory is Other')
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
cloudBaseAddress ??= 'api.unknown.powerplatform.com'
|
|
139
|
+
return `https://${getEndpointSuffix(cloud, cloudBaseAddress)}/.default`
|
|
140
|
+
} else {
|
|
141
|
+
if (!directConnectUrl) {
|
|
142
|
+
directConnectUrl = settings?.directConnectUrl ?? ''
|
|
143
|
+
}
|
|
144
|
+
if (directConnectUrl && isValidUri(directConnectUrl)) {
|
|
145
|
+
if (decodeCloudFromURI(new URL(directConnectUrl)) === PowerPlatformCloud.Unknown) {
|
|
146
|
+
const cloudToTest: PowerPlatformCloud = settings?.cloud ?? cloud
|
|
147
|
+
|
|
148
|
+
if (cloudToTest === PowerPlatformCloud.Other || cloudToTest === PowerPlatformCloud.Unknown) {
|
|
149
|
+
throw new Error('Unable to resolve the PowerPlatform Cloud from DirectConnectUrl. The Token Audience resolver requires a specific PowerPlatformCloudCategory.')
|
|
150
|
+
}
|
|
151
|
+
if ((cloudToTest as PowerPlatformCloud) !== PowerPlatformCloud.Unknown) {
|
|
152
|
+
return `https://${getEndpointSuffix(cloudToTest, '')}/.default`
|
|
153
|
+
} else {
|
|
154
|
+
throw new Error('Unable to resolve the PowerPlatform Cloud from DirectConnectUrl. The Token Audience resolver requires a specific PowerPlatformCloudCategory.')
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return `https://${getEndpointSuffix(decodeCloudFromURI(new URL(directConnectUrl)), '')}/.default`
|
|
158
|
+
} else {
|
|
159
|
+
throw new Error('DirectConnectUrl must be provided when DirectConnectUrl is set')
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
104
163
|
function isValidUri (uri: string): boolean {
|
|
105
164
|
try {
|
|
106
|
-
const
|
|
165
|
+
const absoluteUrl = uri.startsWith('http') ? uri : `https://${uri}`
|
|
166
|
+
const newUri = new URL(absoluteUrl)
|
|
107
167
|
return !!newUri
|
|
108
168
|
} catch {
|
|
109
169
|
return false
|
|
@@ -202,3 +262,34 @@ function getIdSuffixLength (cloud: PowerPlatformCloud): number {
|
|
|
202
262
|
return 1
|
|
203
263
|
}
|
|
204
264
|
}
|
|
265
|
+
|
|
266
|
+
function decodeCloudFromURI (uri: URL): PowerPlatformCloud {
|
|
267
|
+
const host = uri.host.toLowerCase()
|
|
268
|
+
|
|
269
|
+
switch (host) {
|
|
270
|
+
case 'api.powerplatform.localhost':
|
|
271
|
+
return PowerPlatformCloud.Local
|
|
272
|
+
case 'api.exp.powerplatform.com':
|
|
273
|
+
return PowerPlatformCloud.Exp
|
|
274
|
+
case 'api.dev.powerplatform.com':
|
|
275
|
+
return PowerPlatformCloud.Dev
|
|
276
|
+
case 'api.prv.powerplatform.com':
|
|
277
|
+
return PowerPlatformCloud.Prv
|
|
278
|
+
case 'api.test.powerplatform.com':
|
|
279
|
+
return PowerPlatformCloud.Test
|
|
280
|
+
case 'api.preprod.powerplatform.com':
|
|
281
|
+
return PowerPlatformCloud.Preprod
|
|
282
|
+
case 'api.powerplatform.com':
|
|
283
|
+
return PowerPlatformCloud.Prod
|
|
284
|
+
case 'api.gov.powerplatform.microsoft.us':
|
|
285
|
+
return PowerPlatformCloud.GovFR
|
|
286
|
+
case 'api.high.powerplatform.microsoft.us':
|
|
287
|
+
return PowerPlatformCloud.High
|
|
288
|
+
case 'api.appsplatform.us':
|
|
289
|
+
return PowerPlatformCloud.DoD
|
|
290
|
+
case 'api.powerplatform.partner.microsoftonline.cn':
|
|
291
|
+
return PowerPlatformCloud.Mooncake
|
|
292
|
+
default:
|
|
293
|
+
return PowerPlatformCloud.Unknown
|
|
294
|
+
}
|
|
295
|
+
}
|