@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.
- package/README.md +92 -15
- package/dist/src/browser/os.d.ts +7 -0
- package/dist/src/{directToEngineConnectionSettings.js → browser/os.js} +2 -1
- package/dist/src/browser/os.js.map +1 -0
- package/dist/src/browser.mjs +10 -0
- package/dist/src/browser.mjs.map +7 -0
- package/dist/src/connectionSettings.d.ts +10 -3
- package/dist/src/connectionSettings.js +11 -5
- package/dist/src/connectionSettings.js.map +1 -1
- package/dist/src/copilotStudioClient.d.ts +10 -0
- package/dist/src/copilotStudioClient.js +39 -5
- package/dist/src/copilotStudioClient.js.map +1 -1
- package/dist/src/{directToEngineConnectionSettings.d.ts → copilotStudioConnectionSettings.d.ts} +10 -6
- package/dist/src/copilotStudioConnectionSettings.js +7 -0
- package/dist/src/copilotStudioConnectionSettings.js.map +1 -0
- package/dist/src/copilotStudioWebChat.d.ts +65 -0
- package/dist/src/copilotStudioWebChat.js +107 -0
- package/dist/src/copilotStudioWebChat.js.map +1 -0
- package/dist/src/index.d.ts +8 -7
- package/dist/src/index.js +8 -7
- package/dist/src/index.js.map +1 -1
- package/dist/src/powerPlatformEnvironment.js +45 -17
- package/dist/src/powerPlatformEnvironment.js.map +1 -1
- package/dist/src/strategies/prebuiltBotStrategy.d.ts +15 -0
- package/dist/src/strategies/prebuiltBotStrategy.js +25 -0
- package/dist/src/strategies/prebuiltBotStrategy.js.map +1 -0
- package/dist/src/strategies/publishedBotStrategy.d.ts +15 -0
- package/dist/src/strategies/publishedBotStrategy.js +25 -0
- package/dist/src/strategies/publishedBotStrategy.js.map +1 -0
- package/dist/src/strategies/strategy.d.ts +7 -0
- package/dist/src/strategies/strategy.js +7 -0
- package/dist/src/strategies/strategy.js.map +1 -0
- package/package.json +19 -5
- package/src/browser/os.ts +8 -0
- package/src/connectionSettings.ts +19 -6
- package/src/copilotStudioClient.ts +46 -4
- package/src/{directToEngineConnectionSettings.ts → copilotStudioConnectionSettings.ts} +16 -6
- package/src/copilotStudioWebChat.ts +164 -0
- package/src/index.ts +8 -7
- package/src/powerPlatformEnvironment.ts +55 -26
- package/src/strategies/prebuiltBotStrategy.ts +37 -0
- package/src/strategies/publishedBotStrategy.ts +37 -0
- package/src/strategies/strategy.ts +8 -0
- package/dist/src/directToEngineConnectionSettings.js.map +0 -1
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
import { AgentType } from './agentType'
|
|
7
7
|
import { ConnectionSettings } from './connectionSettings'
|
|
8
8
|
import { PowerPlatformCloud } from './powerPlatformCloud'
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import { PrebuiltBotStrategy } from './strategies/prebuiltBotStrategy'
|
|
10
|
+
import { PublishedBotStrategy } from './strategies/publishedBotStrategy'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Generates the connection URL for Copilot Studio.
|
|
@@ -22,20 +22,34 @@ export function getCopilotStudioConnectionUrl (
|
|
|
22
22
|
): string {
|
|
23
23
|
let cloudValue: PowerPlatformCloud = PowerPlatformCloud.Prod
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
if (settings.directConnectUrl?.trim()) {
|
|
26
|
+
if (!isValidUri(settings.directConnectUrl)) {
|
|
27
|
+
throw new Error('directConnectUrl must be a valid URL')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// FIX for Missing Tenant ID
|
|
31
|
+
if (settings.directConnectUrl.toLocaleLowerCase().includes('tenants/00000000-0000-0000-0000-000000000000')) {
|
|
32
|
+
// Direct connection cannot be used, ejecting and forcing the normal settings flow:
|
|
33
|
+
return getCopilotStudioConnectionUrl({ ...settings, directConnectUrl: '' }, conversationId)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return createURL(settings.directConnectUrl, conversationId).href
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const isNotEmptyCloud = settings.cloud && settings.cloud.toString().trim() !== ''
|
|
26
40
|
const isNotEmptyCustomPowerPlatformCloud = settings.customPowerPlatformCloud !== undefined && settings.customPowerPlatformCloud.trim() !== ''
|
|
27
41
|
|
|
28
|
-
if (isNotEmptyCloud && !Object.values(PowerPlatformCloud).includes(settings.cloud)) {
|
|
42
|
+
if (isNotEmptyCloud && !Object.values(PowerPlatformCloud).includes(settings.cloud!)) {
|
|
29
43
|
throw new Error('Invalid PowerPlatformCloud enum key')
|
|
30
44
|
}
|
|
31
45
|
|
|
32
|
-
const cloudSetting = isNotEmptyCloud ?
|
|
46
|
+
const cloudSetting = isNotEmptyCloud ? settings.cloud! : PowerPlatformCloud.Unknown
|
|
33
47
|
|
|
34
48
|
if (cloudSetting === PowerPlatformCloud.Other && isNotEmptyCustomPowerPlatformCloud) {
|
|
35
49
|
throw new Error('customPowerPlatformCloud must be provided when PowerPlatformCloud is Other')
|
|
36
50
|
}
|
|
37
51
|
|
|
38
|
-
if (settings.environmentId
|
|
52
|
+
if (!settings.environmentId?.trim()) {
|
|
39
53
|
throw new Error('EnvironmentId must be provided')
|
|
40
54
|
}
|
|
41
55
|
|
|
@@ -59,11 +73,11 @@ export function getCopilotStudioConnectionUrl (
|
|
|
59
73
|
|
|
60
74
|
let agentType: AgentType
|
|
61
75
|
|
|
62
|
-
if (settings.copilotAgentType && settings.copilotAgentType.trim() !== '') {
|
|
63
|
-
if (!Object.values(AgentType).includes(settings.copilotAgentType
|
|
76
|
+
if (settings.copilotAgentType && settings.copilotAgentType.toString().trim() !== '') {
|
|
77
|
+
if (!Object.values(AgentType).includes(settings.copilotAgentType)) {
|
|
64
78
|
throw new Error('Invalid AgentType enum key')
|
|
65
79
|
} else {
|
|
66
|
-
agentType =
|
|
80
|
+
agentType = settings.copilotAgentType
|
|
67
81
|
}
|
|
68
82
|
} else {
|
|
69
83
|
agentType = AgentType.Published
|
|
@@ -72,7 +86,19 @@ export function getCopilotStudioConnectionUrl (
|
|
|
72
86
|
settings.customPowerPlatformCloud = isNotEmptyCustomPowerPlatformCloud ? settings.customPowerPlatformCloud : 'api.unknown.powerplatform.com'
|
|
73
87
|
|
|
74
88
|
const host = getEnvironmentEndpoint(cloudValue, settings.environmentId, settings.customPowerPlatformCloud)
|
|
75
|
-
|
|
89
|
+
|
|
90
|
+
const strategy = {
|
|
91
|
+
[AgentType.Published]: () => new PublishedBotStrategy({
|
|
92
|
+
host,
|
|
93
|
+
schema: settings.agentIdentifier!,
|
|
94
|
+
}),
|
|
95
|
+
[AgentType.Prebuilt]: () => new PrebuiltBotStrategy({
|
|
96
|
+
host,
|
|
97
|
+
identifier: settings.agentIdentifier!,
|
|
98
|
+
}),
|
|
99
|
+
}[agentType]()
|
|
100
|
+
|
|
101
|
+
return strategy.getConversationUrl(conversationId)
|
|
76
102
|
}
|
|
77
103
|
|
|
78
104
|
function isValidUri (uri: string): boolean {
|
|
@@ -84,31 +110,34 @@ function isValidUri (uri: string): boolean {
|
|
|
84
110
|
}
|
|
85
111
|
}
|
|
86
112
|
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
host: string,
|
|
90
|
-
agentType: AgentType,
|
|
91
|
-
conversationId?: string
|
|
92
|
-
): string {
|
|
93
|
-
const agentPathName = agentType === AgentType.Published ? 'dataverse-backed' : 'prebuilt'
|
|
113
|
+
function createURL (base: string, conversationId?: string): URL {
|
|
114
|
+
const url = new URL(base)
|
|
94
115
|
|
|
95
|
-
|
|
96
|
-
|
|
116
|
+
if (!url.searchParams.has('api-version')) {
|
|
117
|
+
url.searchParams.append('api-version', '2022-03-01-preview')
|
|
118
|
+
}
|
|
97
119
|
|
|
98
|
-
if (
|
|
99
|
-
url.pathname =
|
|
100
|
-
}
|
|
101
|
-
|
|
120
|
+
if (url.pathname.endsWith('/')) {
|
|
121
|
+
url.pathname = url.pathname.slice(0, -1)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (url.pathname.includes('/conversations')) {
|
|
125
|
+
url.pathname = url.pathname.substring(0, url.pathname.indexOf('/conversations'))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
url.pathname = `${url.pathname}/conversations`
|
|
129
|
+
if (conversationId) {
|
|
130
|
+
url.pathname = `${url.pathname}/${conversationId}`
|
|
102
131
|
}
|
|
103
132
|
|
|
104
|
-
return url
|
|
133
|
+
return url
|
|
105
134
|
}
|
|
106
135
|
|
|
107
136
|
function getEnvironmentEndpoint (
|
|
108
137
|
cloud: PowerPlatformCloud,
|
|
109
138
|
environmentId: string,
|
|
110
139
|
cloudBaseAddress?: string
|
|
111
|
-
):
|
|
140
|
+
): URL {
|
|
112
141
|
if (cloud === PowerPlatformCloud.Other && (!cloudBaseAddress || !cloudBaseAddress.trim())) {
|
|
113
142
|
throw new Error('cloudBaseAddress must be provided when PowerPlatformCloud is Other')
|
|
114
143
|
}
|
|
@@ -120,7 +149,7 @@ function getEnvironmentEndpoint (
|
|
|
120
149
|
const hexPrefix = normalizedResourceId.substring(0, normalizedResourceId.length - idSuffixLength)
|
|
121
150
|
const hexSuffix = normalizedResourceId.substring(normalizedResourceId.length - idSuffixLength)
|
|
122
151
|
|
|
123
|
-
return
|
|
152
|
+
return new URL(`https://${hexPrefix}.${hexSuffix}.environment.${getEndpointSuffix(cloud, cloudBaseAddress)}`)
|
|
124
153
|
}
|
|
125
154
|
|
|
126
155
|
function getEndpointSuffix (
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Strategy } from './strategy'
|
|
7
|
+
|
|
8
|
+
export interface PrebuiltBotStrategySettings {
|
|
9
|
+
readonly host: URL;
|
|
10
|
+
readonly identifier: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class PrebuiltBotStrategy implements Strategy {
|
|
14
|
+
private readonly API_VERSION = '2022-03-01-preview'
|
|
15
|
+
private baseURL: URL
|
|
16
|
+
|
|
17
|
+
constructor (settings: PrebuiltBotStrategySettings) {
|
|
18
|
+
const { identifier, host } = settings
|
|
19
|
+
|
|
20
|
+
this.baseURL = new URL(
|
|
21
|
+
`/copilotstudio/prebuilt/authenticated/bots/${identifier}`,
|
|
22
|
+
host
|
|
23
|
+
)
|
|
24
|
+
this.baseURL.searchParams.append('api-version', this.API_VERSION)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public getConversationUrl (conversationId?: string): string {
|
|
28
|
+
const conversationUrl = new URL(this.baseURL.href)
|
|
29
|
+
conversationUrl.pathname = `${conversationUrl.pathname}/conversations`
|
|
30
|
+
|
|
31
|
+
if (conversationId) {
|
|
32
|
+
conversationUrl.pathname = `${conversationUrl.pathname}/${conversationId}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return conversationUrl.href
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Strategy } from './strategy'
|
|
7
|
+
|
|
8
|
+
export interface PublishedBotStrategySettings {
|
|
9
|
+
readonly host: URL;
|
|
10
|
+
readonly schema: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class PublishedBotStrategy implements Strategy {
|
|
14
|
+
private readonly API_VERSION = '2022-03-01-preview'
|
|
15
|
+
private baseURL: URL
|
|
16
|
+
|
|
17
|
+
constructor (settings: PublishedBotStrategySettings) {
|
|
18
|
+
const { schema, host } = settings
|
|
19
|
+
|
|
20
|
+
this.baseURL = new URL(
|
|
21
|
+
`/copilotstudio/dataverse-backed/authenticated/bots/${schema}`,
|
|
22
|
+
host
|
|
23
|
+
)
|
|
24
|
+
this.baseURL.searchParams.append('api-version', this.API_VERSION)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public getConversationUrl (conversationId?: string): string {
|
|
28
|
+
const conversationUrl = new URL(this.baseURL.href)
|
|
29
|
+
conversationUrl.pathname = `${conversationUrl.pathname}/conversations`
|
|
30
|
+
|
|
31
|
+
if (conversationId) {
|
|
32
|
+
conversationUrl.pathname = `${conversationUrl.pathname}/${conversationId}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return conversationUrl.href
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"directToEngineConnectionSettings.js","sourceRoot":"","sources":["../../src/directToEngineConnectionSettings.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|