@microsoft/agents-copilotstudio-client 0.5.4-ga4d0401645 → 0.5.12-g2d752e9b13

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.
Files changed (44) hide show
  1. package/README.md +92 -15
  2. package/dist/src/browser/os.d.ts +7 -0
  3. package/dist/src/{directToEngineConnectionSettings.js → browser/os.js} +2 -1
  4. package/dist/src/browser/os.js.map +1 -0
  5. package/dist/src/browser.mjs +10 -0
  6. package/dist/src/browser.mjs.map +7 -0
  7. package/dist/src/connectionSettings.d.ts +10 -3
  8. package/dist/src/connectionSettings.js +11 -5
  9. package/dist/src/connectionSettings.js.map +1 -1
  10. package/dist/src/copilotStudioClient.d.ts +10 -0
  11. package/dist/src/copilotStudioClient.js +39 -5
  12. package/dist/src/copilotStudioClient.js.map +1 -1
  13. package/dist/src/{directToEngineConnectionSettings.d.ts → copilotStudioConnectionSettings.d.ts} +10 -6
  14. package/dist/src/copilotStudioConnectionSettings.js +7 -0
  15. package/dist/src/copilotStudioConnectionSettings.js.map +1 -0
  16. package/dist/src/copilotStudioWebChat.d.ts +65 -0
  17. package/dist/src/copilotStudioWebChat.js +107 -0
  18. package/dist/src/copilotStudioWebChat.js.map +1 -0
  19. package/dist/src/index.d.ts +8 -7
  20. package/dist/src/index.js +8 -7
  21. package/dist/src/index.js.map +1 -1
  22. package/dist/src/powerPlatformEnvironment.js +45 -17
  23. package/dist/src/powerPlatformEnvironment.js.map +1 -1
  24. package/dist/src/strategies/prebuiltBotStrategy.d.ts +15 -0
  25. package/dist/src/strategies/prebuiltBotStrategy.js +25 -0
  26. package/dist/src/strategies/prebuiltBotStrategy.js.map +1 -0
  27. package/dist/src/strategies/publishedBotStrategy.d.ts +15 -0
  28. package/dist/src/strategies/publishedBotStrategy.js +25 -0
  29. package/dist/src/strategies/publishedBotStrategy.js.map +1 -0
  30. package/dist/src/strategies/strategy.d.ts +7 -0
  31. package/dist/src/strategies/strategy.js +7 -0
  32. package/dist/src/strategies/strategy.js.map +1 -0
  33. package/package.json +19 -5
  34. package/src/browser/os.ts +8 -0
  35. package/src/connectionSettings.ts +19 -6
  36. package/src/copilotStudioClient.ts +46 -4
  37. package/src/{directToEngineConnectionSettings.ts → copilotStudioConnectionSettings.ts} +16 -6
  38. package/src/copilotStudioWebChat.ts +164 -0
  39. package/src/index.ts +8 -7
  40. package/src/powerPlatformEnvironment.ts +55 -26
  41. package/src/strategies/prebuiltBotStrategy.ts +37 -0
  42. package/src/strategies/publishedBotStrategy.ts +37 -0
  43. package/src/strategies/strategy.ts +8 -0
  44. package/dist/src/directToEngineConnectionSettings.js.map +0 -1
@@ -2,10 +2,13 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { AgentType } from './agentType';
6
+ import { CopilotStudioConnectionSettings } from './copilotStudioConnectionSettings';
7
+ import { PowerPlatformCloud } from './powerPlatformCloud';
5
8
  /**
6
9
  * Represents the settings required to establish a connection to Copilot Studio.
7
10
  */
8
- export declare class ConnectionSettings {
11
+ export declare class ConnectionSettings implements CopilotStudioConnectionSettings {
9
12
  /** The client ID of the application. */
10
13
  appClientId: string;
11
14
  /** The tenant ID of the application. */
@@ -13,13 +16,17 @@ export declare class ConnectionSettings {
13
16
  /** The environment ID of the application. */
14
17
  environmentId: string;
15
18
  /** The cloud environment of the application. */
16
- cloud: string;
19
+ cloud?: PowerPlatformCloud;
17
20
  /** The custom Power Platform cloud URL, if any. */
18
21
  customPowerPlatformCloud?: string;
19
22
  /** The identifier of the agent. */
20
23
  agentIdentifier?: string;
21
24
  /** The type of the Copilot agent. */
22
- copilotAgentType?: string;
25
+ copilotAgentType?: AgentType;
26
+ /** The URL to connect directly to Copilot Studio endpoint */
27
+ directConnectUrl?: string;
28
+ /** Flag to use the experimental endpoint if available */
29
+ useExperimentalEndpoint?: boolean;
23
30
  }
24
31
  /**
25
32
  * Loads the connection settings for Copilot Studio from environment variables.
@@ -5,6 +5,8 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.loadCopilotStudioConnectionSettingsFromEnv = exports.ConnectionSettings = void 0;
8
+ const agentType_1 = require("./agentType");
9
+ const powerPlatformCloud_1 = require("./powerPlatformCloud");
8
10
  /**
9
11
  * Represents the settings required to establish a connection to Copilot Studio.
10
12
  */
@@ -16,8 +18,8 @@ class ConnectionSettings {
16
18
  this.tenantId = '';
17
19
  /** The environment ID of the application. */
18
20
  this.environmentId = '';
19
- /** The cloud environment of the application. */
20
- this.cloud = '';
21
+ /** Flag to use the experimental endpoint if available */
22
+ this.useExperimentalEndpoint = false;
21
23
  }
22
24
  }
23
25
  exports.ConnectionSettings = ConnectionSettings;
@@ -26,15 +28,19 @@ exports.ConnectionSettings = ConnectionSettings;
26
28
  * @returns The connection settings.
27
29
  */
28
30
  const loadCopilotStudioConnectionSettingsFromEnv = () => {
29
- var _a, _b, _c;
31
+ var _a, _b, _c, _d;
32
+ const cloudStr = process.env.cloud;
33
+ const agentStr = process.env.copilotAgentType;
30
34
  return {
31
35
  appClientId: (_a = process.env.appClientId) !== null && _a !== void 0 ? _a : '',
32
36
  tenantId: (_b = process.env.tenantId) !== null && _b !== void 0 ? _b : '',
33
37
  environmentId: (_c = process.env.environmentId) !== null && _c !== void 0 ? _c : '',
34
- cloud: process.env.cloud,
38
+ cloud: cloudStr ? powerPlatformCloud_1.PowerPlatformCloud[cloudStr] : undefined,
35
39
  customPowerPlatformCloud: process.env.customPowerPlatformCloud,
36
40
  agentIdentifier: process.env.agentIdentifier,
37
- copilotAgentType: process.env.copilotAgentType
41
+ copilotAgentType: agentStr ? agentType_1.AgentType[agentStr] : undefined,
42
+ directConnectUrl: process.env.directConnectUrl,
43
+ useExperimentalEndpoint: ((_d = process.env.useExperimentalEndpoint) === null || _d === void 0 ? void 0 : _d.toLocaleLowerCase()) === 'true'
38
44
  };
39
45
  };
40
46
  exports.loadCopilotStudioConnectionSettingsFromEnv = loadCopilotStudioConnectionSettingsFromEnv;
@@ -1 +1 @@
1
- {"version":3,"file":"connectionSettings.js","sourceRoot":"","sources":["../../src/connectionSettings.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;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;QACjC,gDAAgD;QACzC,UAAK,GAAW,EAAE,CAAA;IAO3B,CAAC;CAAA;AAfD,gDAeC;AAED;;;GAGG;AACI,MAAM,0CAA0C,GAA6B,GAAG,EAAE;;IACvF,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,OAAO,CAAC,GAAG,CAAC,KAAK;QACxB,wBAAwB,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB;QAC9D,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe;QAC5C,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB;KACzB,CAAA;AACzB,CAAC,CAAA;AAVY,QAAA,0CAA0C,8CAUtD"}
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,SAAS;QAC1D,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,SAAS;QAC5D,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"}
@@ -5,6 +5,10 @@
5
5
  import { ConnectionSettings } from './connectionSettings';
6
6
  import { Activity } from '@microsoft/agents-activity';
7
7
  export declare class CopilotStudioClient {
8
+ /** Header key for conversation ID. */
9
+ private static readonly conversationIdHeaderKey;
10
+ /** Island Header key */
11
+ private static readonly islandExperimentalUrlHeaderKey;
8
12
  /** The ID of the current conversation. */
9
13
  private conversationId;
10
14
  /** The connection settings for the client. */
@@ -20,6 +24,12 @@ export declare class CopilotStudioClient {
20
24
  */
21
25
  constructor(settings: ConnectionSettings, token: string);
22
26
  private postRequestAsync;
27
+ /**
28
+ * Appends this package.json version to the User-Agent header.
29
+ * - For browser environments, it includes the user agent of the browser.
30
+ * - For Node.js environments, it includes the Node.js version, platform, architecture, and release.
31
+ * @returns A string containing the product information, including version and user agent.
32
+ */
23
33
  private static getProductInfo;
24
34
  /**
25
35
  * Starts a new conversation with the Copilot Studio service.
@@ -27,11 +27,28 @@ class CopilotStudioClient {
27
27
  this.settings = settings;
28
28
  this.client = axios_1.default.create();
29
29
  this.client.defaults.headers.common.Authorization = `Bearer ${token}`;
30
+ this.client.defaults.headers.common['User-Agent'] = CopilotStudioClient.getProductInfo();
30
31
  this.logger = (0, debug_1.default)('copilot-studio-client');
31
32
  }
32
33
  async postRequestAsync(axiosConfig) {
34
+ var _a, _b, _c, _d;
33
35
  const activities = [];
36
+ this.logger(`>>> SEND TO ${axiosConfig.url}`);
34
37
  const response = await this.client(axiosConfig);
38
+ if (this.settings.useExperimentalEndpoint && !((_a = this.settings.directConnectUrl) === null || _a === void 0 ? void 0 : _a.trim())) {
39
+ const islandExperimentalUrl = (_b = response.headers) === null || _b === void 0 ? void 0 : _b[CopilotStudioClient.islandExperimentalUrlHeaderKey];
40
+ if (islandExperimentalUrl) {
41
+ this.settings.directConnectUrl = islandExperimentalUrl;
42
+ this.logger(`Island Experimental URL: ${islandExperimentalUrl}`);
43
+ }
44
+ }
45
+ this.conversationId = (_d = (_c = response.headers) === null || _c === void 0 ? void 0 : _c[CopilotStudioClient.conversationIdHeaderKey]) !== null && _d !== void 0 ? _d : '';
46
+ if (this.conversationId) {
47
+ this.logger(`Conversation ID: ${this.conversationId}`);
48
+ }
49
+ this.logger('=====================================================');
50
+ this.logger(`Headers: ${JSON.stringify(response.headers, null, 2)}`);
51
+ this.logger('=====================================================');
35
52
  const stream = response.data;
36
53
  const reader = stream.pipeThrough(new TextDecoderStream()).getReader();
37
54
  let result = '';
@@ -52,10 +69,16 @@ class CopilotStudioClient {
52
69
  const values = event.toString().split('\n');
53
70
  const validEvents = values.filter(e => e.substring(0, 4) === 'data' && e !== 'data: end\r');
54
71
  validEvents.forEach(ve => {
72
+ var _a, _b;
55
73
  try {
56
74
  const act = agents_activity_1.Activity.fromJson(ve.substring(5, ve.length));
57
75
  if (act.type === agents_activity_1.ActivityTypes.Message) {
58
76
  activities.push(act);
77
+ if (!this.conversationId.trim()) {
78
+ // Did not get it from the header.
79
+ this.conversationId = (_b = (_a = act.conversation) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '';
80
+ this.logger(`Conversation ID: ${this.conversationId}`);
81
+ }
59
82
  }
60
83
  else {
61
84
  this.logger('Activity type: ', act.type);
@@ -69,8 +92,18 @@ class CopilotStudioClient {
69
92
  });
70
93
  return activities;
71
94
  }
95
+ /**
96
+ * Appends this package.json version to the User-Agent header.
97
+ * - For browser environments, it includes the user agent of the browser.
98
+ * - For Node.js environments, it includes the Node.js version, platform, architecture, and release.
99
+ * @returns A string containing the product information, including version and user agent.
100
+ */
72
101
  static getProductInfo() {
73
- return `CopilotStudioClient.agents-sdk-js/${package_json_1.default.version} nodejs/${process.version} ${os_1.default.platform()}-${os_1.default.arch()}/${os_1.default.release()}`;
102
+ const version = `CopilotStudioClient.agents-sdk-js/${package_json_1.default.version}`;
103
+ if (typeof window !== 'undefined' && window.navigator) {
104
+ return `${version} ${navigator.userAgent}`;
105
+ }
106
+ return `${version} nodejs/${process.version} ${os_1.default.platform()}-${os_1.default.arch()}/${os_1.default.release()}`;
74
107
  }
75
108
  /**
76
109
  * Starts a new conversation with the Copilot Studio service.
@@ -78,7 +111,6 @@ class CopilotStudioClient {
78
111
  * @returns A promise that resolves to the initial activity of the conversation.
79
112
  */
80
113
  async startConversationAsync(emitStartConversationEvent = true) {
81
- var _a;
82
114
  const uriStart = (0, powerPlatformEnvironment_1.getCopilotStudioConnectionUrl)(this.settings);
83
115
  const body = { emitStartConversationEvent };
84
116
  const config = {
@@ -87,7 +119,6 @@ class CopilotStudioClient {
87
119
  headers: {
88
120
  Accept: 'text/event-stream',
89
121
  'Content-Type': 'application/json',
90
- 'User-Agent': CopilotStudioClient.getProductInfo(),
91
122
  },
92
123
  data: body,
93
124
  responseType: 'stream',
@@ -95,7 +126,6 @@ class CopilotStudioClient {
95
126
  };
96
127
  const values = await this.postRequestAsync(config);
97
128
  const act = values[0];
98
- this.conversationId = (_a = act.conversation) === null || _a === void 0 ? void 0 : _a.id;
99
129
  return act;
100
130
  }
101
131
  /**
@@ -123,7 +153,7 @@ class CopilotStudioClient {
123
153
  url: uriExecute,
124
154
  headers: {
125
155
  Accept: 'text/event-stream',
126
- 'Content-Type': 'application/json'
156
+ 'Content-Type': 'application/json',
127
157
  },
128
158
  data: qbody,
129
159
  responseType: 'stream',
@@ -134,4 +164,8 @@ class CopilotStudioClient {
134
164
  }
135
165
  }
136
166
  exports.CopilotStudioClient = CopilotStudioClient;
167
+ /** Header key for conversation ID. */
168
+ CopilotStudioClient.conversationIdHeaderKey = 'x-ms-conversationid';
169
+ /** Island Header key */
170
+ CopilotStudioClient.islandExperimentalUrlHeaderKey = 'x-ms-d2e-experimental';
137
171
  //# sourceMappingURL=copilotStudioClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"copilotStudioClient.js","sourceRoot":"","sources":["../../src/copilotStudioClient.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,kDAAgE;AAChE,yEAA0E;AAC1E,gEAAyF;AACzF,6DAAyD;AACzD,kDAA6C;AAC7C,uGAAuE;AACvE,4CAAmB;AAOnB,MAAa,mBAAmB;IAU9B;;;;OAIG;IACH,YAAa,QAA4B,EAAE,KAAa;QAdxD,0CAA0C;QAClC,mBAAc,GAAW,EAAE,CAAA;QAcjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,EAAE,CA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Represents the settings required to establish a direct connection to the engine.
9
9
  */
10
- export interface DirectToEngineConnectionSettings {
10
+ export interface CopilotStudioConnectionSettings {
11
11
  /** The identifier of the agent. */
12
- agentIdentifier: string;
12
+ agentIdentifier?: string;
13
13
  /** The custom Power Platform cloud URL. */
14
- customPowerPlatformCloud: string;
14
+ customPowerPlatformCloud?: string;
15
15
  /** The environment ID of the application. */
16
- environmentId: string;
16
+ environmentId?: string;
17
17
  /** The cloud environment of the application. */
18
- cloud: PowerPlatformCloud;
18
+ cloud?: PowerPlatformCloud;
19
19
  /** The type of the Copilot agent. */
20
- copilotAgentType: AgentType;
20
+ copilotAgentType?: AgentType;
21
+ /** URL provided to connect directly to Copilot Studio endpoint. When provided all other settings are ignored. */
22
+ directConnectUrl?: string;
23
+ /** Directs Copilot Studio Client to use the experimental endpoint if available. */
24
+ useExperimentalEndpoint?: boolean;
21
25
  }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=copilotStudioConnectionSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilotStudioConnectionSettings.js","sourceRoot":"","sources":["../../src/copilotStudioConnectionSettings.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { Activity } from '@microsoft/agents-activity';
6
+ import { Observable, BehaviorSubject } from 'rxjs';
7
+ import { CopilotStudioClient } from './copilotStudioClient';
8
+ export interface CopilotStudioWebChatSettings {
9
+ /**
10
+ * Whether to show typing indicators in the WebChat.
11
+ * Defaults to false.
12
+ */
13
+ showTyping?: boolean;
14
+ }
15
+ export interface CopilotStudioWebChatConnection {
16
+ /**
17
+ * An observable that emits the connection status.
18
+ * 0 - Disconnected
19
+ * 1 - Connecting
20
+ * 2 - Connected
21
+ */
22
+ connectionStatus$: BehaviorSubject<number>;
23
+ /**
24
+ * An observable that emits incoming activities.
25
+ * The emitted activities will have a 'webchat:sequence-id' in their channelData.
26
+ */
27
+ activity$: Observable<Partial<Activity>>;
28
+ /**
29
+ * Posts an activity to the Copilot Studio service.
30
+ * The activity must have a non-empty text field.
31
+ * Returns an observable that emits the activity ID once the activity is posted.
32
+ *
33
+ * @param activity - The activity to post.
34
+ * @returns An observable that emits the activity ID.
35
+ */
36
+ postActivity(activity: Activity): Observable<string>;
37
+ /**
38
+ * Ends the connection.
39
+ * This will complete the connectionStatus$ and activity$ observables.
40
+ */
41
+ end(): void;
42
+ }
43
+ /**
44
+ * This class is intended to be used in WebChat applications to connect to the Copilot Studio service.
45
+ *
46
+ * example usage:
47
+ * ```javascript
48
+ * const client = new CopilotStudioClient(...)
49
+ * window.WebChat.renderWebChat({
50
+ * directLine: CopilotStudioWebChat.createConnection(client)
51
+ * })
52
+ * ```
53
+ */
54
+ export declare class CopilotStudioWebChat {
55
+ /**
56
+ * Creates a new DirectLine-Like connection to WebChat.
57
+ * When an activity is posted in WebChat, the connection will send it to the Copilot Studio service, awaiting response.
58
+ * After a response is received, it will emit the incoming activity back to WebChat.
59
+ *
60
+ * @param client - The Copilot Studio client instance.
61
+ * @param settings - Optional settings for the WebChat connection.
62
+ * @returns A new instance of CopilotStudioWebChatConnection.
63
+ */
64
+ static createConnection(client: CopilotStudioClient, settings?: CopilotStudioWebChatSettings): CopilotStudioWebChatConnection;
65
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.CopilotStudioWebChat = void 0;
8
+ const uuid_1 = require("uuid");
9
+ const rxjs_1 = require("rxjs");
10
+ /**
11
+ * This class is intended to be used in WebChat applications to connect to the Copilot Studio service.
12
+ *
13
+ * example usage:
14
+ * ```javascript
15
+ * const client = new CopilotStudioClient(...)
16
+ * window.WebChat.renderWebChat({
17
+ * directLine: CopilotStudioWebChat.createConnection(client)
18
+ * })
19
+ * ```
20
+ */
21
+ class CopilotStudioWebChat {
22
+ /**
23
+ * Creates a new DirectLine-Like connection to WebChat.
24
+ * When an activity is posted in WebChat, the connection will send it to the Copilot Studio service, awaiting response.
25
+ * After a response is received, it will emit the incoming activity back to WebChat.
26
+ *
27
+ * @param client - The Copilot Studio client instance.
28
+ * @param settings - Optional settings for the WebChat connection.
29
+ * @returns A new instance of CopilotStudioWebChatConnection.
30
+ */
31
+ static createConnection(client, settings) {
32
+ let sequence = 0;
33
+ let activityObserver;
34
+ let conversation;
35
+ const connectionStatus$ = new rxjs_1.BehaviorSubject(0);
36
+ const activity$ = rxjs_1.Observable.create(async (observer) => {
37
+ activityObserver = observer;
38
+ if (connectionStatus$.value < 2) {
39
+ connectionStatus$.next(2);
40
+ return;
41
+ }
42
+ notifyTyping();
43
+ const activity = await client.startConversationAsync();
44
+ conversation = activity.conversation;
45
+ sequence = 0;
46
+ notifyActivity(activity);
47
+ });
48
+ const notifyActivity = (activity) => {
49
+ activityObserver === null || activityObserver === void 0 ? void 0 : activityObserver.next({
50
+ ...activity,
51
+ timestamp: new Date().toISOString(),
52
+ channelData: {
53
+ ...activity.channelData,
54
+ 'webchat:sequence-id': sequence++,
55
+ },
56
+ });
57
+ };
58
+ const notifyTyping = () => {
59
+ if (!(settings === null || settings === void 0 ? void 0 : settings.showTyping)) {
60
+ return;
61
+ }
62
+ const from = conversation
63
+ ? { id: conversation.id, name: conversation.name }
64
+ : { id: 'agent', name: 'Agent' };
65
+ notifyActivity({ type: 'typing', from });
66
+ };
67
+ return {
68
+ connectionStatus$,
69
+ activity$,
70
+ postActivity(activity) {
71
+ var _a;
72
+ if (!((_a = activity.text) === null || _a === void 0 ? void 0 : _a.trim())) {
73
+ throw new Error('Activity text cannot be empty.');
74
+ }
75
+ if (!activityObserver) {
76
+ throw new Error('Activity observer is not initialized.');
77
+ }
78
+ return rxjs_1.Observable.create(async (observer) => {
79
+ try {
80
+ const id = (0, uuid_1.v4)();
81
+ notifyActivity({ ...activity, id });
82
+ notifyTyping();
83
+ const activities = await client.askQuestionAsync(activity.text);
84
+ for (const responseActivity of activities) {
85
+ notifyActivity(responseActivity);
86
+ }
87
+ observer.next(id);
88
+ observer.complete();
89
+ }
90
+ catch (error) {
91
+ observer.error(error);
92
+ }
93
+ });
94
+ },
95
+ end() {
96
+ connectionStatus$.complete();
97
+ activity$.complete();
98
+ if (activityObserver) {
99
+ activityObserver.complete();
100
+ activityObserver = undefined;
101
+ }
102
+ },
103
+ };
104
+ }
105
+ }
106
+ exports.CopilotStudioWebChat = CopilotStudioWebChat;
107
+ //# sourceMappingURL=copilotStudioWebChat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilotStudioWebChat.js","sourceRoot":"","sources":["../../src/copilotStudioWebChat.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAiC;AAGjC,+BAAiE;AA4CjE;;;;;;;;;;GAUG;AACH,MAAa,oBAAoB;IAC/B;;;;;;;;OAQG;IACH,MAAM,CAAC,gBAAgB,CACrB,MAA2B,EAC3B,QAAuC;QAEvC,IAAI,QAAQ,GAAG,CAAC,CAAA;QAChB,IAAI,gBAAyD,CAAA;QAC7D,IAAI,YAA6C,CAAA;QAEjD,MAAM,iBAAiB,GAAG,IAAI,sBAAe,CAAC,CAAC,CAAC,CAAA;QAChD,MAAM,SAAS,GAAG,iBAAU,CAAC,MAAM,CACjC,KAAK,EAAE,QAAqC,EAAE,EAAE;YAC9C,gBAAgB,GAAG,QAAQ,CAAA;YAE3B,IAAI,iBAAiB,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;gBAChC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;gBACzB,OAAM;YACR,CAAC;YAED,YAAY,EAAE,CAAA;YACd,MAAM,QAAQ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CAAuC,CAAC,CAAA;gBAC1D,CAAC;gBAED,OAAO,iBAAU,CAAC,MAAM,CAAC,KAAK,EAAE,QAA0B,EAAE,EAAE;oBAC5D,IAAI,CAAC;wBACH,MAAM,EAAE,GAAG,IAAA,SAAI,GAAE,CAAA;wBAEjB,cAAc,CAAC,EAAE,GAAG,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAA;wBACnC,YAAY,EAAE,CAAA;wBAEd,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAK,CAAC,CAAA;wBAChE,KAAK,MAAM,gBAAgB,IAAI,UAAU,EAAE,CAAC;4BAC1C,cAAc,CAAC,gBAAgB,CAAC,CAAA;wBAClC,CAAC;wBAED,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;wBACjB,QAAQ,CAAC,QAAQ,EAAE,CAAA;oBACrB,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;oBACvB,CAAC;gBACH,CAAC,CAAC,CAAA;YACJ,CAAC;YAED,GAAG;gBACD,iBAAiB,CAAC,QAAQ,EAAE,CAAA;gBAC5B,SAAS,CAAC,QAAQ,EAAE,CAAA;gBACpB,IAAI,gBAAgB,EAAE,CAAC;oBACrB,gBAAgB,CAAC,QAAQ,EAAE,CAAA;oBAC3B,gBAAgB,GAAG,SAAS,CAAA;gBAC9B,CAAC;YACH,CAAC;SACF,CAAA;IACH,CAAC;CACF;AApGD,oDAoGC"}
@@ -1,7 +1,8 @@
1
- export * from './agentType';
2
- export * from './connectionSettings';
3
- export * from './copilotStudioClient';
4
- export * from './directToEngineConnectionSettings';
5
- export * from './executeTurnRequest';
6
- export * from './powerPlatformCloud';
7
- export * from './powerPlatformEnvironment';
1
+ export * from './agentType.js';
2
+ export * from './connectionSettings.js';
3
+ export * from './copilotStudioClient.js';
4
+ export * from './copilotStudioConnectionSettings.js';
5
+ export * from './copilotStudioWebChat.js';
6
+ export * from './executeTurnRequest.js';
7
+ export * from './powerPlatformCloud.js';
8
+ export * from './powerPlatformEnvironment.js';
package/dist/src/index.js CHANGED
@@ -14,11 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./agentType"), exports);
18
- __exportStar(require("./connectionSettings"), exports);
19
- __exportStar(require("./copilotStudioClient"), exports);
20
- __exportStar(require("./directToEngineConnectionSettings"), exports);
21
- __exportStar(require("./executeTurnRequest"), exports);
22
- __exportStar(require("./powerPlatformCloud"), exports);
23
- __exportStar(require("./powerPlatformEnvironment"), exports);
17
+ __exportStar(require("./agentType.js"), exports);
18
+ __exportStar(require("./connectionSettings.js"), exports);
19
+ __exportStar(require("./copilotStudioClient.js"), exports);
20
+ __exportStar(require("./copilotStudioConnectionSettings.js"), exports);
21
+ __exportStar(require("./copilotStudioWebChat.js"), exports);
22
+ __exportStar(require("./executeTurnRequest.js"), exports);
23
+ __exportStar(require("./powerPlatformCloud.js"), exports);
24
+ __exportStar(require("./powerPlatformEnvironment.js"), exports);
24
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,uDAAoC;AACpC,wDAAqC;AACrC,qEAAkD;AAClD,uDAAoC;AACpC,uDAAoC;AACpC,6DAA0C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,0DAAuC;AACvC,2DAAwC;AACxC,uEAAoD;AACpD,4DAAyC;AACzC,0DAAuC;AACvC,0DAAuC;AACvC,gEAA6C"}
@@ -7,7 +7,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.getCopilotStudioConnectionUrl = getCopilotStudioConnectionUrl;
8
8
  const agentType_1 = require("./agentType");
9
9
  const powerPlatformCloud_1 = require("./powerPlatformCloud");
10
- const ApiVersion = '2022-03-01-preview';
10
+ const prebuiltBotStrategy_1 = require("./strategies/prebuiltBotStrategy");
11
+ const publishedBotStrategy_1 = require("./strategies/publishedBotStrategy");
11
12
  /**
12
13
  * Generates the connection URL for Copilot Studio.
13
14
  * @param settings - The connection settings.
@@ -16,17 +17,29 @@ const ApiVersion = '2022-03-01-preview';
16
17
  * @throws Will throw an error if required settings are missing or invalid.
17
18
  */
18
19
  function getCopilotStudioConnectionUrl(settings, conversationId) {
20
+ var _a, _b;
19
21
  let cloudValue = powerPlatformCloud_1.PowerPlatformCloud.Prod;
20
- const isNotEmptyCloud = settings.cloud && settings.cloud.trim() !== '';
22
+ if ((_a = settings.directConnectUrl) === null || _a === void 0 ? void 0 : _a.trim()) {
23
+ if (!isValidUri(settings.directConnectUrl)) {
24
+ throw new Error('directConnectUrl must be a valid URL');
25
+ }
26
+ // FIX for Missing Tenant ID
27
+ if (settings.directConnectUrl.toLocaleLowerCase().includes('tenants/00000000-0000-0000-0000-000000000000')) {
28
+ // Direct connection cannot be used, ejecting and forcing the normal settings flow:
29
+ return getCopilotStudioConnectionUrl({ ...settings, directConnectUrl: '' }, conversationId);
30
+ }
31
+ return createURL(settings.directConnectUrl, conversationId).href;
32
+ }
33
+ const isNotEmptyCloud = settings.cloud && settings.cloud.toString().trim() !== '';
21
34
  const isNotEmptyCustomPowerPlatformCloud = settings.customPowerPlatformCloud !== undefined && settings.customPowerPlatformCloud.trim() !== '';
22
35
  if (isNotEmptyCloud && !Object.values(powerPlatformCloud_1.PowerPlatformCloud).includes(settings.cloud)) {
23
36
  throw new Error('Invalid PowerPlatformCloud enum key');
24
37
  }
25
- const cloudSetting = isNotEmptyCloud ? powerPlatformCloud_1.PowerPlatformCloud[settings.cloud] : powerPlatformCloud_1.PowerPlatformCloud.Unknown;
38
+ const cloudSetting = isNotEmptyCloud ? settings.cloud : powerPlatformCloud_1.PowerPlatformCloud.Unknown;
26
39
  if (cloudSetting === powerPlatformCloud_1.PowerPlatformCloud.Other && isNotEmptyCustomPowerPlatformCloud) {
27
40
  throw new Error('customPowerPlatformCloud must be provided when PowerPlatformCloud is Other');
28
41
  }
29
- if (settings.environmentId.trim() === '') {
42
+ if (!((_b = settings.environmentId) === null || _b === void 0 ? void 0 : _b.trim())) {
30
43
  throw new Error('EnvironmentId must be provided');
31
44
  }
32
45
  if (settings.agentIdentifier === undefined || settings.agentIdentifier.trim() === '') {
@@ -44,12 +57,12 @@ function getCopilotStudioConnectionUrl(settings, conversationId) {
44
57
  }
45
58
  }
46
59
  let agentType;
47
- if (settings.copilotAgentType && settings.copilotAgentType.trim() !== '') {
60
+ if (settings.copilotAgentType && settings.copilotAgentType.toString().trim() !== '') {
48
61
  if (!Object.values(agentType_1.AgentType).includes(settings.copilotAgentType)) {
49
62
  throw new Error('Invalid AgentType enum key');
50
63
  }
51
64
  else {
52
- agentType = agentType_1.AgentType[settings.copilotAgentType];
65
+ agentType = settings.copilotAgentType;
53
66
  }
54
67
  }
55
68
  else {
@@ -57,7 +70,17 @@ function getCopilotStudioConnectionUrl(settings, conversationId) {
57
70
  }
58
71
  settings.customPowerPlatformCloud = isNotEmptyCustomPowerPlatformCloud ? settings.customPowerPlatformCloud : 'api.unknown.powerplatform.com';
59
72
  const host = getEnvironmentEndpoint(cloudValue, settings.environmentId, settings.customPowerPlatformCloud);
60
- return createUri(settings.agentIdentifier, host, agentType, conversationId);
73
+ const strategy = {
74
+ [agentType_1.AgentType.Published]: () => new publishedBotStrategy_1.PublishedBotStrategy({
75
+ host,
76
+ schema: settings.agentIdentifier,
77
+ }),
78
+ [agentType_1.AgentType.Prebuilt]: () => new prebuiltBotStrategy_1.PrebuiltBotStrategy({
79
+ host,
80
+ identifier: settings.agentIdentifier,
81
+ }),
82
+ }[agentType]();
83
+ return strategy.getConversationUrl(conversationId);
61
84
  }
62
85
  function isValidUri(uri) {
63
86
  try {
@@ -68,17 +91,22 @@ function isValidUri(uri) {
68
91
  return false;
69
92
  }
70
93
  }
71
- function createUri(agentIdentifier, host, agentType, conversationId) {
72
- const agentPathName = agentType === agentType_1.AgentType.Published ? 'dataverse-backed' : 'prebuilt';
73
- const url = new URL(`https://${host}`);
74
- url.searchParams.set('api-version', ApiVersion);
75
- if (!conversationId) {
76
- url.pathname = `/copilotstudio/${agentPathName}/authenticated/bots/${agentIdentifier}/conversations`;
94
+ function createURL(base, conversationId) {
95
+ const url = new URL(base);
96
+ if (!url.searchParams.has('api-version')) {
97
+ url.searchParams.append('api-version', '2022-03-01-preview');
77
98
  }
78
- else {
79
- url.pathname = `/copilotstudio/${agentPathName}/authenticated/bots/${agentIdentifier}/conversations/${conversationId}`;
99
+ if (url.pathname.endsWith('/')) {
100
+ url.pathname = url.pathname.slice(0, -1);
101
+ }
102
+ if (url.pathname.includes('/conversations')) {
103
+ url.pathname = url.pathname.substring(0, url.pathname.indexOf('/conversations'));
104
+ }
105
+ url.pathname = `${url.pathname}/conversations`;
106
+ if (conversationId) {
107
+ url.pathname = `${url.pathname}/${conversationId}`;
80
108
  }
81
- return url.toString();
109
+ return url;
82
110
  }
83
111
  function getEnvironmentEndpoint(cloud, environmentId, cloudBaseAddress) {
84
112
  if (cloud === powerPlatformCloud_1.PowerPlatformCloud.Other && (!cloudBaseAddress || !cloudBaseAddress.trim())) {
@@ -89,7 +117,7 @@ function getEnvironmentEndpoint(cloud, environmentId, cloudBaseAddress) {
89
117
  const idSuffixLength = getIdSuffixLength(cloud);
90
118
  const hexPrefix = normalizedResourceId.substring(0, normalizedResourceId.length - idSuffixLength);
91
119
  const hexSuffix = normalizedResourceId.substring(normalizedResourceId.length - idSuffixLength);
92
- return `${hexPrefix}.${hexSuffix}.environment.${getEndpointSuffix(cloud, cloudBaseAddress)}`;
120
+ return new URL(`https://${hexPrefix}.${hexSuffix}.environment.${getEndpointSuffix(cloud, cloudBaseAddress)}`);
93
121
  }
94
122
  function getEndpointSuffix(category, cloudBaseAddress) {
95
123
  switch (category) {