@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
@@ -1 +1 @@
1
- {"version":3,"file":"powerPlatformEnvironment.js","sourceRoot":"","sources":["../../src/powerPlatformEnvironment.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAeH,sEAyDC;AAtED,2CAAuC;AAEvC,6DAAyD;AAEzD,MAAM,UAAU,GAAW,oBAAoB,CAAA;AAE/C;;;;;;GAMG;AACH,SAAgB,6BAA6B,CAC3C,QAA4B,EAC5B,cAAuB;IAEvB,IAAI,UAAU,GAAuB,uCAAkB,CAAC,IAAI,CAAA;IAE5D,MAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAA;IACtE,MAAM,kCAAkC,GAAG,QAAQ,CAAC,wBAAwB,KAAK,SAAS,IAAI,QAAQ,CAAC,wBAAwB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAA;IAE7I,IAAI,eAAe,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,uCAAkB,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACnF,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACxD,CAAC;IAED,MAAM,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,uCAAkB,CAAC,QAAQ,CAAC,KAAwC,CAAC,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,KAAK,EAAE,CAAC;QACd,KAAK,uCAAkB,CAAC,YAAY,CAAC;QACrC,KAAK,uCAAkB,CAAC,IAAI;YAC1B,OAAO,CAAC,CAAA;QACV;YACE,OAAO,CAAC,CAAA;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { Strategy } from './strategy';
6
+ export interface PrebuiltBotStrategySettings {
7
+ readonly host: URL;
8
+ readonly identifier: string;
9
+ }
10
+ export declare class PrebuiltBotStrategy implements Strategy {
11
+ private readonly API_VERSION;
12
+ private baseURL;
13
+ constructor(settings: PrebuiltBotStrategySettings);
14
+ getConversationUrl(conversationId?: string): string;
15
+ }
@@ -0,0 +1,25 @@
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.PrebuiltBotStrategy = void 0;
8
+ class PrebuiltBotStrategy {
9
+ constructor(settings) {
10
+ this.API_VERSION = '2022-03-01-preview';
11
+ const { identifier, host } = settings;
12
+ this.baseURL = new URL(`/copilotstudio/prebuilt/authenticated/bots/${identifier}`, host);
13
+ this.baseURL.searchParams.append('api-version', this.API_VERSION);
14
+ }
15
+ getConversationUrl(conversationId) {
16
+ const conversationUrl = new URL(this.baseURL.href);
17
+ conversationUrl.pathname = `${conversationUrl.pathname}/conversations`;
18
+ if (conversationId) {
19
+ conversationUrl.pathname = `${conversationUrl.pathname}/${conversationId}`;
20
+ }
21
+ return conversationUrl.href;
22
+ }
23
+ }
24
+ exports.PrebuiltBotStrategy = PrebuiltBotStrategy;
25
+ //# sourceMappingURL=prebuiltBotStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prebuiltBotStrategy.js","sourceRoot":"","sources":["../../../src/strategies/prebuiltBotStrategy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,MAAa,mBAAmB;IAI9B,YAAa,QAAqC;QAHjC,gBAAW,GAAG,oBAAoB,CAAA;QAIjD,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAA;QAErC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CACpB,8CAA8C,UAAU,EAAE,EAC1D,IAAI,CACL,CAAA;QACD,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACnE,CAAC;IAEM,kBAAkB,CAAE,cAAuB;QAChD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAClD,eAAe,CAAC,QAAQ,GAAG,GAAG,eAAe,CAAC,QAAQ,gBAAgB,CAAA;QAEtE,IAAI,cAAc,EAAE,CAAC;YACnB,eAAe,CAAC,QAAQ,GAAG,GAAG,eAAe,CAAC,QAAQ,IAAI,cAAc,EAAE,CAAA;QAC5E,CAAC;QAED,OAAO,eAAe,CAAC,IAAI,CAAA;IAC7B,CAAC;CACF;AAxBD,kDAwBC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { Strategy } from './strategy';
6
+ export interface PublishedBotStrategySettings {
7
+ readonly host: URL;
8
+ readonly schema: string;
9
+ }
10
+ export declare class PublishedBotStrategy implements Strategy {
11
+ private readonly API_VERSION;
12
+ private baseURL;
13
+ constructor(settings: PublishedBotStrategySettings);
14
+ getConversationUrl(conversationId?: string): string;
15
+ }
@@ -0,0 +1,25 @@
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.PublishedBotStrategy = void 0;
8
+ class PublishedBotStrategy {
9
+ constructor(settings) {
10
+ this.API_VERSION = '2022-03-01-preview';
11
+ const { schema, host } = settings;
12
+ this.baseURL = new URL(`/copilotstudio/dataverse-backed/authenticated/bots/${schema}`, host);
13
+ this.baseURL.searchParams.append('api-version', this.API_VERSION);
14
+ }
15
+ getConversationUrl(conversationId) {
16
+ const conversationUrl = new URL(this.baseURL.href);
17
+ conversationUrl.pathname = `${conversationUrl.pathname}/conversations`;
18
+ if (conversationId) {
19
+ conversationUrl.pathname = `${conversationUrl.pathname}/${conversationId}`;
20
+ }
21
+ return conversationUrl.href;
22
+ }
23
+ }
24
+ exports.PublishedBotStrategy = PublishedBotStrategy;
25
+ //# sourceMappingURL=publishedBotStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publishedBotStrategy.js","sourceRoot":"","sources":["../../../src/strategies/publishedBotStrategy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,MAAa,oBAAoB;IAI/B,YAAa,QAAsC;QAHlC,gBAAW,GAAG,oBAAoB,CAAA;QAIjD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAA;QAEjC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CACpB,sDAAsD,MAAM,EAAE,EAC9D,IAAI,CACL,CAAA;QACD,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACnE,CAAC;IAEM,kBAAkB,CAAE,cAAuB;QAChD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAClD,eAAe,CAAC,QAAQ,GAAG,GAAG,eAAe,CAAC,QAAQ,gBAAgB,CAAA;QAEtE,IAAI,cAAc,EAAE,CAAC;YACnB,eAAe,CAAC,QAAQ,GAAG,GAAG,eAAe,CAAC,QAAQ,IAAI,cAAc,EAAE,CAAA;QAC5E,CAAC;QAED,OAAO,eAAe,CAAC,IAAI,CAAA;IAC7B,CAAC;CACF;AAxBD,oDAwBC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export interface Strategy {
6
+ getConversationUrl(conversationId?: string): string;
7
+ }
@@ -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=strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../../src/strategies/strategy.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/agents-copilotstudio-client",
3
- "version": "0.5.4-ga4d0401645",
3
+ "version": "0.5.12-g2d752e9b13",
4
4
  "homepage": "https://github.com/microsoft/Agents-for-js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,10 +19,19 @@
19
19
  ],
20
20
  "main": "dist/src/index.js",
21
21
  "types": "dist/src/index.d.ts",
22
+ "browser": {
23
+ "os": "./src/browser/os.ts",
24
+ "crypto": "./src/browser/crypto.ts"
25
+ },
26
+ "scripts": {
27
+ "build:browser": "esbuild --platform=browser --target=es2019 --format=esm --bundle --sourcemap --minify --outfile=dist/src/browser.mjs src/index.ts"
28
+ },
22
29
  "dependencies": {
23
- "@microsoft/agents-activity": "0.5.4-ga4d0401645",
30
+ "@microsoft/agents-activity": "0.5.12-g2d752e9b13",
24
31
  "axios": "^1.9.0",
25
- "debug": "^4.3.7"
32
+ "debug": "^4.3.7",
33
+ "rxjs": "5.5.12",
34
+ "uuid": "^11.1.0"
26
35
  },
27
36
  "license": "MIT",
28
37
  "files": [
@@ -32,8 +41,13 @@
32
41
  ],
33
42
  "exports": {
34
43
  ".": {
35
- "import": "./dist/src/index.js",
36
- "require": "./dist/src/index.js"
44
+ "import": {
45
+ "browser": "./dist/src/browser.mjs",
46
+ "default": "./dist/src/index.js"
47
+ },
48
+ "require": {
49
+ "default": "./dist/src/index.js"
50
+ }
37
51
  },
38
52
  "./package.json": "./package.json"
39
53
  },
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type * as osTypes from 'os'
7
+
8
+ export default {} as typeof osTypes
@@ -3,10 +3,14 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { AgentType } from './agentType'
7
+ import { CopilotStudioConnectionSettings } from './copilotStudioConnectionSettings'
8
+ import { PowerPlatformCloud } from './powerPlatformCloud'
9
+
6
10
  /**
7
11
  * Represents the settings required to establish a connection to Copilot Studio.
8
12
  */
9
- export class ConnectionSettings {
13
+ export class ConnectionSettings implements CopilotStudioConnectionSettings {
10
14
  /** The client ID of the application. */
11
15
  public appClientId: string = ''
12
16
  /** The tenant ID of the application. */
@@ -14,13 +18,17 @@ export class ConnectionSettings {
14
18
  /** The environment ID of the application. */
15
19
  public environmentId: string = ''
16
20
  /** The cloud environment of the application. */
17
- public cloud: string = ''
21
+ public cloud?: PowerPlatformCloud
18
22
  /** The custom Power Platform cloud URL, if any. */
19
23
  public customPowerPlatformCloud?: string
20
24
  /** The identifier of the agent. */
21
25
  public agentIdentifier?: string
22
26
  /** The type of the Copilot agent. */
23
- public copilotAgentType?: string
27
+ public copilotAgentType?: AgentType
28
+ /** The URL to connect directly to Copilot Studio endpoint */
29
+ public directConnectUrl?: string
30
+ /** Flag to use the experimental endpoint if available */
31
+ public useExperimentalEndpoint?: boolean = false
24
32
  }
25
33
 
26
34
  /**
@@ -28,13 +36,18 @@ export class ConnectionSettings {
28
36
  * @returns The connection settings.
29
37
  */
30
38
  export const loadCopilotStudioConnectionSettingsFromEnv: () => ConnectionSettings = () => {
39
+ const cloudStr = process.env.cloud as keyof typeof PowerPlatformCloud | undefined
40
+ const agentStr = process.env.copilotAgentType as keyof typeof AgentType | undefined
41
+
31
42
  return {
32
43
  appClientId: process.env.appClientId ?? '',
33
44
  tenantId: process.env.tenantId ?? '',
34
45
  environmentId: process.env.environmentId ?? '',
35
- cloud: process.env.cloud,
46
+ cloud: cloudStr ? PowerPlatformCloud[cloudStr] : undefined,
36
47
  customPowerPlatformCloud: process.env.customPowerPlatformCloud,
37
48
  agentIdentifier: process.env.agentIdentifier,
38
- copilotAgentType: process.env.copilotAgentType
39
- } as ConnectionSettings
49
+ copilotAgentType: agentStr ? AgentType[agentStr] : undefined,
50
+ directConnectUrl: process.env.directConnectUrl,
51
+ useExperimentalEndpoint: process.env.useExperimentalEndpoint?.toLocaleLowerCase() === 'true'
52
+ } satisfies ConnectionSettings
40
53
  }
@@ -18,6 +18,11 @@ interface streamRead {
18
18
  }
19
19
 
20
20
  export class CopilotStudioClient {
21
+ /** Header key for conversation ID. */
22
+ private static readonly conversationIdHeaderKey: string = 'x-ms-conversationid'
23
+ /** Island Header key */
24
+ private static readonly islandExperimentalUrlHeaderKey: string = 'x-ms-d2e-experimental'
25
+
21
26
  /** The ID of the current conversation. */
22
27
  private conversationId: string = ''
23
28
  /** The connection settings for the client. */
@@ -36,12 +41,34 @@ export class CopilotStudioClient {
36
41
  this.settings = settings
37
42
  this.client = axios.create()
38
43
  this.client.defaults.headers.common.Authorization = `Bearer ${token}`
44
+ this.client.defaults.headers.common['User-Agent'] = CopilotStudioClient.getProductInfo()
39
45
  this.logger = createDebug('copilot-studio-client')
40
46
  }
41
47
 
42
48
  private async postRequestAsync (axiosConfig: AxiosRequestConfig): Promise<Activity[]> {
43
49
  const activities: Activity[] = []
50
+
51
+ this.logger(`>>> SEND TO ${axiosConfig.url}`)
52
+
44
53
  const response = await this.client(axiosConfig)
54
+
55
+ if (this.settings.useExperimentalEndpoint && !this.settings.directConnectUrl?.trim()) {
56
+ const islandExperimentalUrl = response.headers?.[CopilotStudioClient.islandExperimentalUrlHeaderKey]
57
+ if (islandExperimentalUrl) {
58
+ this.settings.directConnectUrl = islandExperimentalUrl
59
+ this.logger(`Island Experimental URL: ${islandExperimentalUrl}`)
60
+ }
61
+ }
62
+
63
+ this.conversationId = response.headers?.[CopilotStudioClient.conversationIdHeaderKey] ?? ''
64
+ if (this.conversationId) {
65
+ this.logger(`Conversation ID: ${this.conversationId}`)
66
+ }
67
+
68
+ this.logger('=====================================================')
69
+ this.logger(`Headers: ${JSON.stringify(response.headers, null, 2)}`)
70
+ this.logger('=====================================================')
71
+
45
72
  const stream = response.data
46
73
  const reader = stream.pipeThrough(new TextDecoderStream()).getReader()
47
74
  let result: string = ''
@@ -70,6 +97,11 @@ export class CopilotStudioClient {
70
97
  const act = Activity.fromJson(ve.substring(5, ve.length))
71
98
  if (act.type === ActivityTypes.Message) {
72
99
  activities.push(act)
100
+ if (!this.conversationId.trim()) {
101
+ // Did not get it from the header.
102
+ this.conversationId = act.conversation?.id ?? ''
103
+ this.logger(`Conversation ID: ${this.conversationId}`)
104
+ }
73
105
  } else {
74
106
  this.logger('Activity type: ', act.type)
75
107
  }
@@ -82,8 +114,20 @@ export class CopilotStudioClient {
82
114
  return activities
83
115
  }
84
116
 
117
+ /**
118
+ * Appends this package.json version to the User-Agent header.
119
+ * - For browser environments, it includes the user agent of the browser.
120
+ * - For Node.js environments, it includes the Node.js version, platform, architecture, and release.
121
+ * @returns A string containing the product information, including version and user agent.
122
+ */
85
123
  private static getProductInfo (): string {
86
- return `CopilotStudioClient.agents-sdk-js/${pjson.version} nodejs/${process.version} ${os.platform()}-${os.arch()}/${os.release()}`
124
+ const version = `CopilotStudioClient.agents-sdk-js/${pjson.version}`
125
+
126
+ if (typeof window !== 'undefined' && window.navigator) {
127
+ return `${version} ${navigator.userAgent}`
128
+ }
129
+
130
+ return `${version} nodejs/${process.version} ${os.platform()}-${os.arch()}/${os.release()}`
87
131
  }
88
132
 
89
133
  /**
@@ -101,7 +145,6 @@ export class CopilotStudioClient {
101
145
  headers: {
102
146
  Accept: 'text/event-stream',
103
147
  'Content-Type': 'application/json',
104
- 'User-Agent': CopilotStudioClient.getProductInfo(),
105
148
  },
106
149
  data: body,
107
150
  responseType: 'stream',
@@ -110,7 +153,6 @@ export class CopilotStudioClient {
110
153
 
111
154
  const values = await this.postRequestAsync(config)
112
155
  const act = values[0]
113
- this.conversationId = act.conversation?.id!
114
156
  return act
115
157
  }
116
158
 
@@ -140,7 +182,7 @@ export class CopilotStudioClient {
140
182
  url: uriExecute,
141
183
  headers: {
142
184
  Accept: 'text/event-stream',
143
- 'Content-Type': 'application/json'
185
+ 'Content-Type': 'application/json',
144
186
  },
145
187
  data: qbody,
146
188
  responseType: 'stream',
@@ -9,15 +9,25 @@ import { PowerPlatformCloud } from './powerPlatformCloud'
9
9
  /**
10
10
  * Represents the settings required to establish a direct connection to the engine.
11
11
  */
12
- export interface DirectToEngineConnectionSettings {
12
+ export interface CopilotStudioConnectionSettings {
13
13
  /** The identifier of the agent. */
14
- agentIdentifier: string
14
+ agentIdentifier?: string
15
+
15
16
  /** The custom Power Platform cloud URL. */
16
- customPowerPlatformCloud: string
17
+ customPowerPlatformCloud?: string
18
+
17
19
  /** The environment ID of the application. */
18
- environmentId: string
20
+ environmentId?: string
21
+
19
22
  /** The cloud environment of the application. */
20
- cloud: PowerPlatformCloud
23
+ cloud?: PowerPlatformCloud
24
+
21
25
  /** The type of the Copilot agent. */
22
- copilotAgentType: AgentType
26
+ copilotAgentType?: AgentType
27
+
28
+ /** URL provided to connect directly to Copilot Studio endpoint. When provided all other settings are ignored. */
29
+ directConnectUrl?: string
30
+
31
+ /** Directs Copilot Studio Client to use the experimental endpoint if available. */
32
+ useExperimentalEndpoint?: boolean
23
33
  }
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { v4 as uuid } from 'uuid'
7
+
8
+ import { Activity, ConversationAccount } from '@microsoft/agents-activity'
9
+ import { Observable, BehaviorSubject, type Observer } from 'rxjs'
10
+
11
+ import { CopilotStudioClient } from './copilotStudioClient'
12
+
13
+ export interface CopilotStudioWebChatSettings {
14
+ /**
15
+ * Whether to show typing indicators in the WebChat.
16
+ * Defaults to false.
17
+ */
18
+ showTyping?: boolean;
19
+ }
20
+
21
+ export interface CopilotStudioWebChatConnection {
22
+ /**
23
+ * An observable that emits the connection status.
24
+ * 0 - Disconnected
25
+ * 1 - Connecting
26
+ * 2 - Connected
27
+ */
28
+ connectionStatus$: BehaviorSubject<number>;
29
+
30
+ /**
31
+ * An observable that emits incoming activities.
32
+ * The emitted activities will have a 'webchat:sequence-id' in their channelData.
33
+ */
34
+ activity$: Observable<Partial<Activity>>;
35
+
36
+ /**
37
+ * Posts an activity to the Copilot Studio service.
38
+ * The activity must have a non-empty text field.
39
+ * Returns an observable that emits the activity ID once the activity is posted.
40
+ *
41
+ * @param activity - The activity to post.
42
+ * @returns An observable that emits the activity ID.
43
+ */
44
+ postActivity(activity: Activity): Observable<string>;
45
+
46
+ /**
47
+ * Ends the connection.
48
+ * This will complete the connectionStatus$ and activity$ observables.
49
+ */
50
+ end(): void;
51
+ }
52
+
53
+ /**
54
+ * This class is intended to be used in WebChat applications to connect to the Copilot Studio service.
55
+ *
56
+ * example usage:
57
+ * ```javascript
58
+ * const client = new CopilotStudioClient(...)
59
+ * window.WebChat.renderWebChat({
60
+ * directLine: CopilotStudioWebChat.createConnection(client)
61
+ * })
62
+ * ```
63
+ */
64
+ export class CopilotStudioWebChat {
65
+ /**
66
+ * Creates a new DirectLine-Like connection to WebChat.
67
+ * When an activity is posted in WebChat, the connection will send it to the Copilot Studio service, awaiting response.
68
+ * After a response is received, it will emit the incoming activity back to WebChat.
69
+ *
70
+ * @param client - The Copilot Studio client instance.
71
+ * @param settings - Optional settings for the WebChat connection.
72
+ * @returns A new instance of CopilotStudioWebChatConnection.
73
+ */
74
+ static createConnection (
75
+ client: CopilotStudioClient,
76
+ settings?: CopilotStudioWebChatSettings
77
+ ):CopilotStudioWebChatConnection {
78
+ let sequence = 0
79
+ let activityObserver: Observer<Partial<Activity>> | undefined
80
+ let conversation: ConversationAccount | undefined
81
+
82
+ const connectionStatus$ = new BehaviorSubject(0)
83
+ const activity$ = Observable.create(
84
+ async (observer: Observer<Partial<Activity>>) => {
85
+ activityObserver = observer
86
+
87
+ if (connectionStatus$.value < 2) {
88
+ connectionStatus$.next(2)
89
+ return
90
+ }
91
+
92
+ notifyTyping()
93
+ const activity = await client.startConversationAsync()
94
+ conversation = activity.conversation
95
+ sequence = 0
96
+ notifyActivity(activity)
97
+ }
98
+ )
99
+
100
+ const notifyActivity = (activity: Partial<Activity>) => {
101
+ activityObserver?.next({
102
+ ...activity,
103
+ timestamp: new Date().toISOString(),
104
+ channelData: {
105
+ ...activity.channelData,
106
+ 'webchat:sequence-id': sequence++,
107
+ },
108
+ })
109
+ }
110
+
111
+ const notifyTyping = () => {
112
+ if (!settings?.showTyping) {
113
+ return
114
+ }
115
+
116
+ const from = conversation
117
+ ? { id: conversation.id, name: conversation.name }
118
+ : { id: 'agent', name: 'Agent' }
119
+ notifyActivity({ type: 'typing', from })
120
+ }
121
+
122
+ return {
123
+ connectionStatus$,
124
+ activity$,
125
+ postActivity (activity: Activity) {
126
+ if (!activity.text?.trim()) {
127
+ throw new Error('Activity text cannot be empty.')
128
+ }
129
+
130
+ if (!activityObserver) {
131
+ throw new Error('Activity observer is not initialized.')
132
+ }
133
+
134
+ return Observable.create(async (observer: Observer<string>) => {
135
+ try {
136
+ const id = uuid()
137
+
138
+ notifyActivity({ ...activity, id })
139
+ notifyTyping()
140
+
141
+ const activities = await client.askQuestionAsync(activity.text!)
142
+ for (const responseActivity of activities) {
143
+ notifyActivity(responseActivity)
144
+ }
145
+
146
+ observer.next(id)
147
+ observer.complete()
148
+ } catch (error) {
149
+ observer.error(error)
150
+ }
151
+ })
152
+ },
153
+
154
+ end () {
155
+ connectionStatus$.complete()
156
+ activity$.complete()
157
+ if (activityObserver) {
158
+ activityObserver.complete()
159
+ activityObserver = undefined
160
+ }
161
+ },
162
+ }
163
+ }
164
+ }
package/src/index.ts CHANGED
@@ -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'