@microsoft/agents-copilotstudio-client 1.5.0-beta.6.ga236d9a19c → 1.5.1
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/package.json +5 -4
- package/dist/src/browser.mjs +6 -6
- package/dist/src/browser.mjs.map +4 -4
- package/dist/src/copilotStudioClient.js +206 -152
- package/dist/src/copilotStudioClient.js.map +1 -1
- package/dist/src/copilotStudioWebChat.js +149 -112
- package/dist/src/copilotStudioWebChat.js.map +1 -1
- package/dist/src/observability/index.d.ts +2 -0
- package/dist/src/observability/index.js +21 -0
- package/dist/src/observability/index.js.map +1 -0
- package/dist/src/observability/metrics.d.ts +13 -0
- package/dist/src/observability/metrics.js +55 -0
- package/dist/src/observability/metrics.js.map +1 -0
- package/dist/src/observability/traces.d.ts +32 -0
- package/dist/src/observability/traces.js +173 -0
- package/dist/src/observability/traces.js.map +1 -0
- package/dist/src/powerPlatformEnvironment.js +2 -2
- package/dist/src/powerPlatformEnvironment.js.map +1 -1
- package/package.json +5 -4
- package/src/copilotStudioClient.ts +205 -160
- package/src/copilotStudioWebChat.ts +149 -117
- package/src/observability/index.ts +5 -0
- package/src/observability/metrics.ts +63 -0
- package/src/observability/traces.ts +171 -0
- package/src/powerPlatformEnvironment.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traces.js","sourceRoot":"","sources":["../../../src/observability/traces.ts"],"names":[],"mappings":";;;AAAA,gEAAqD;AACrD,kEAA8D;AAC9D,uCAAsD;AAGzC,QAAA,mCAAmC,GAAG;IACjD,gBAAgB,EAAE,wBAAK,CAAC,MAAM,CAAC;QAC7B,IAAI,EAAE,4BAAS,CAAC,yBAAyB;QACzC,MAAM,EAAE;YACN,UAAU,EAAE,KAAK;SAClB;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YACtB,mBAAmB,CAAE,QAAkB;;gBACrC,IAAI,CAAC,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AQ,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAA;gBAC3C,oCAA0B,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;YACrE,CAAC;SACF,CAAC;QACF,GAAG,CAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE;;YAC7B,MAAM,UAAU,GAAG;gBACjB,yCAAyC,EAAE,MAAA,MAAM,CAAC,cAAc,mCAAI,SAAS;gBAC7E,gDAAgD,EAAE,MAAA,MAAM,CAAC,mBAAmB,mCAAI,SAAS;aAC1F,CAAA;YACD,MAAM,gBAAgB,GAAG;gBACvB,SAAS,EAAE,gBAAgB;gBAC3B,yBAAyB,EAAE,UAAU,CAAC,yCAAyC,CAAC;gBAChF,gCAAgC,EAAE,UAAU,CAAC,gDAAgD,CAAC;aAC/F,CAAA;YAED,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;YAC9B,oCAA0B,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAA;YACzE,oCAA0B,CAAC,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;QAC9E,CAAC;KACF,CAAC;CACH,CAAA"}
|
|
@@ -8,11 +8,11 @@ exports.getCopilotStudioConnectionUrl = getCopilotStudioConnectionUrl;
|
|
|
8
8
|
exports.getCopilotStudioSubscribeUrl = getCopilotStudioSubscribeUrl;
|
|
9
9
|
exports.getTokenAudience = getTokenAudience;
|
|
10
10
|
const agentType_1 = require("./agentType");
|
|
11
|
-
const
|
|
11
|
+
const agents_telemetry_1 = require("@microsoft/agents-telemetry");
|
|
12
12
|
const powerPlatformCloud_1 = require("./powerPlatformCloud");
|
|
13
13
|
const prebuiltBotStrategy_1 = require("./strategies/prebuiltBotStrategy");
|
|
14
14
|
const publishedBotStrategy_1 = require("./strategies/publishedBotStrategy");
|
|
15
|
-
const logger = (0,
|
|
15
|
+
const logger = (0, agents_telemetry_1.debug)('copilot-studio:power-platform');
|
|
16
16
|
/**
|
|
17
17
|
* Generates the connection URL for Copilot Studio.
|
|
18
18
|
* @param settings - The connection settings.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powerPlatformEnvironment.js","sourceRoot":"","sources":["../../src/powerPlatformEnvironment.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAkBH,sEAoDC;AASD,oEAiBC;AAWD,4CAiDC;AA1JD,2CAAuC;AAEvC,
|
|
1
|
+
{"version":3,"file":"powerPlatformEnvironment.js","sourceRoot":"","sources":["../../src/powerPlatformEnvironment.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAkBH,sEAoDC;AASD,oEAiBC;AAWD,4CAiDC;AA1JD,2CAAuC;AAEvC,kEAAmD;AACnD,6DAAyD;AACzD,0EAAsE;AACtE,4EAAwE;AAExE,MAAM,MAAM,GAAG,IAAA,wBAAK,EAAC,+BAA+B,CAAC,CAAA;AAErD;;;;;;GAMG;AACH,SAAgB,6BAA6B,CAC3C,QAA4B,EAC5B,cAAuB;;IAEvB,MAAM,UAAU,GAAG,CAAA,MAAA,QAAQ,CAAC,UAAU,0CAAE,IAAI,EAAE,MAAI,MAAA,QAAQ,CAAC,eAAe,0CAAE,IAAI,EAAE,CAAA,CAAA;IAClF,IAAI,CAAC,CAAA,MAAA,QAAQ,CAAC,gBAAgB,0CAAE,IAAI,EAAE,CAAA,IAAI,CAAC,CAAC,CAAA,MAAA,QAAQ,CAAC,aAAa,0CAAE,IAAI,EAAE,CAAA,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,EAAE,CAAA,CAAC,EAAE,CAAC;QACnG,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAA;IAClH,CAAC;IAED,IAAI,MAAA,QAAQ,CAAC,gBAAgB,0CAAE,IAAI,EAAE,EAAE,CAAC;QACtC,MAAM,CAAC,KAAK,CAAC,4BAA4B,QAAQ,CAAC,gBAAg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K,oCAAoC;YACvC,OAAO,uCAAkB,CAAC,KAAK,CAAA;QACjC,KAAK,qCAAqC;YACxC,OAAO,uCAAkB,CAAC,IAAI,CAAA;QAChC,KAAK,qBAAqB;YACxB,OAAO,uCAAkB,CAAC,GAAG,CAAA;QAC/B,KAAK,8CAA8C;YACjD,OAAO,uCAAkB,CAAC,QAAQ,CAAA;QACpC;YACE,OAAO,uCAAkB,CAAC,OAAO,CAAA;IACrC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/agents-copilotstudio-client",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"homepage": "https://github.com/microsoft/Agents-for-js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,10 +27,11 @@
|
|
|
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": "1.5.
|
|
31
|
-
"
|
|
30
|
+
"@microsoft/agents-activity": "1.5.1",
|
|
31
|
+
"@microsoft/agents-telemetry": "1.5.1",
|
|
32
|
+
"eventsource-client": "1.2.0",
|
|
32
33
|
"rxjs": "7.8.2",
|
|
33
|
-
"uuid": "
|
|
34
|
+
"uuid": "11.1.0"
|
|
34
35
|
},
|
|
35
36
|
"license": "MIT",
|
|
36
37
|
"files": [
|
|
@@ -8,12 +8,13 @@ import { ConnectionSettings } from './connectionSettings'
|
|
|
8
8
|
import { getCopilotStudioConnectionUrl, getCopilotStudioSubscribeUrl } from './powerPlatformEnvironment'
|
|
9
9
|
import { Activity, ActivityTypes, ConversationAccount } from '@microsoft/agents-activity'
|
|
10
10
|
import { ExecuteTurnRequest } from './executeTurnRequest'
|
|
11
|
-
import { debug } from '@microsoft/agents-
|
|
11
|
+
import { debug, trace } from '@microsoft/agents-telemetry'
|
|
12
12
|
import { UserAgentHelper } from './userAgentHelper'
|
|
13
13
|
import { ScopeHelper } from './scopeHelper'
|
|
14
14
|
import { StartRequest } from './startRequest'
|
|
15
15
|
import { StartResponse, ExecuteTurnResponse, createStartResponse, createExecuteTurnResponse } from './responses'
|
|
16
16
|
import { SubscribeEvent } from './subscribeEvent'
|
|
17
|
+
import { CopilotStudioClientTraceDefinitions } from './observability'
|
|
17
18
|
|
|
18
19
|
const logger = debug('copilot-studio:client')
|
|
19
20
|
|
|
@@ -72,89 +73,99 @@ export class CopilotStudioClient {
|
|
|
72
73
|
* @returns An async generator yielding the Agent's Activities.
|
|
73
74
|
*/
|
|
74
75
|
private async * postRequestAsync (url: string, body?: any, method: string = 'POST'): AsyncGenerator<Activity> {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.logDiagnostic('Request Body:', body ? JSON.stringify(body, null, 2) : 'none')
|
|
78
|
-
|
|
79
|
-
logger.debug(`>>> SEND TO ${url}`)
|
|
80
|
-
|
|
81
|
-
const streamMap = new Map<string, { text: string, sequence: number }[]>()
|
|
82
|
-
|
|
83
|
-
const eventSource: EventSourceClient = createEventSource({
|
|
84
|
-
url,
|
|
85
|
-
headers: {
|
|
86
|
-
Authorization: `Bearer ${this.token}`,
|
|
87
|
-
'User-Agent': UserAgentHelper.getProductInfo(),
|
|
88
|
-
'Content-Type': 'application/json',
|
|
89
|
-
Accept: 'text/event-stream'
|
|
90
|
-
},
|
|
91
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
92
|
-
method,
|
|
93
|
-
fetch: async (url, init) => {
|
|
94
|
-
const response = await fetch(url, init)
|
|
95
|
-
this.processResponseHeaders(response.headers)
|
|
96
|
-
return response
|
|
97
|
-
}
|
|
98
|
-
})
|
|
76
|
+
const managed = trace(CopilotStudioClientTraceDefinitions.postRequest)
|
|
77
|
+
managed.record({ url, method })
|
|
99
78
|
|
|
100
79
|
try {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
80
|
+
this.logDiagnostic(`Request URL: ${url}`)
|
|
81
|
+
this.logDiagnostic(`Request Method: ${method}`)
|
|
82
|
+
this.logDiagnostic('Request Body:', body ? JSON.stringify(body, null, 2) : 'none')
|
|
83
|
+
|
|
84
|
+
logger.debug(`>>> SEND TO ${url}`)
|
|
85
|
+
|
|
86
|
+
const streamMap = new Map<string, { text: string, sequence: number }[]>()
|
|
87
|
+
|
|
88
|
+
const eventSource: EventSourceClient = createEventSource({
|
|
89
|
+
url,
|
|
90
|
+
headers: {
|
|
91
|
+
Authorization: `Bearer ${this.token}`,
|
|
92
|
+
'User-Agent': UserAgentHelper.getProductInfo(),
|
|
93
|
+
'Content-Type': 'application/json',
|
|
94
|
+
Accept: 'text/event-stream'
|
|
95
|
+
},
|
|
96
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
97
|
+
method,
|
|
98
|
+
fetch: async (url, init) => {
|
|
99
|
+
const response = await fetch(url, init)
|
|
100
|
+
this.processResponseHeaders(response.headers)
|
|
101
|
+
return response
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
for await (const { data, event } of eventSource) {
|
|
107
|
+
if (data && event === 'activity') {
|
|
108
|
+
try {
|
|
109
|
+
const activity = Activity.fromJson(data)
|
|
110
|
+
managed.actions.receivedFromCopilot(activity)
|
|
111
|
+
|
|
112
|
+
// check to see if this activity is part of the streamed response, in which case we need to accumulate the text
|
|
113
|
+
const streamingEntity = activity.entities?.find(e => e.type === 'streaminfo' && e.streamType === 'streaming')
|
|
114
|
+
switch (activity.type) {
|
|
115
|
+
case ActivityTypes.Message:
|
|
116
|
+
if (!this.conversationId.trim()) { // Did not get it from the header.
|
|
117
|
+
this.conversationId = activity.conversation?.id ?? ''
|
|
118
|
+
logger.debug(`Conversation ID: ${this.conversationId}`)
|
|
119
|
+
}
|
|
120
|
+
yield activity
|
|
121
|
+
break
|
|
122
|
+
case ActivityTypes.Typing:
|
|
123
|
+
logger.debug(`Activity type: ${activity.type}`)
|
|
124
|
+
// Accumulate the text as it comes in from the stream.
|
|
125
|
+
// This also accounts for the "old style" of streaming where the stream info is in channelData.
|
|
126
|
+
if (streamingEntity || activity.channelData?.streamType === 'streaming') {
|
|
127
|
+
const text = activity.text ?? ''
|
|
128
|
+
const id = (streamingEntity?.streamId ?? activity.channelData?.streamId)
|
|
129
|
+
const sequence = (streamingEntity?.streamSequence ?? activity.channelData?.streamSequence)
|
|
130
|
+
// Accumulate the text chunks based on stream ID and sequence number.
|
|
131
|
+
if (id && sequence) {
|
|
132
|
+
if (streamMap.has(id)) {
|
|
133
|
+
const existing = streamMap.get(id)!
|
|
134
|
+
existing.push({ text, sequence })
|
|
135
|
+
streamMap.set(id, existing)
|
|
136
|
+
} else {
|
|
137
|
+
streamMap.set(id, [{ text, sequence }])
|
|
138
|
+
}
|
|
139
|
+
activity.text = streamMap.get(id)?.sort((a, b) => a.sequence - b.sequence).map(item => item.text).join('') || ''
|
|
132
140
|
}
|
|
133
|
-
activity.text = streamMap.get(id)?.sort((a, b) => a.sequence - b.sequence).map(item => item.text).join('') || ''
|
|
134
141
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
yield activity
|
|
143
|
+
break
|
|
144
|
+
default:
|
|
145
|
+
logger.debug(`Activity type: ${activity.type}`)
|
|
146
|
+
yield activity
|
|
147
|
+
break
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
logger.error('Failed to parse activity:', error)
|
|
142
151
|
}
|
|
143
|
-
}
|
|
144
|
-
logger.
|
|
152
|
+
} else if (event === 'end') {
|
|
153
|
+
logger.debug('Stream complete')
|
|
154
|
+
break
|
|
145
155
|
}
|
|
146
|
-
} else if (event === 'end') {
|
|
147
|
-
logger.debug('Stream complete')
|
|
148
|
-
break
|
|
149
|
-
}
|
|
150
156
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
if (eventSource.readyState === 'closed') {
|
|
158
|
+
logger.debug('Connection closed')
|
|
159
|
+
break
|
|
160
|
+
}
|
|
154
161
|
}
|
|
162
|
+
} finally {
|
|
163
|
+
eventSource.close()
|
|
155
164
|
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
throw managed.fail(error)
|
|
156
167
|
} finally {
|
|
157
|
-
|
|
168
|
+
managed.end()
|
|
158
169
|
}
|
|
159
170
|
}
|
|
160
171
|
|
|
@@ -201,33 +212,42 @@ export class CopilotStudioClient {
|
|
|
201
212
|
public async * startConversationStreaming (
|
|
202
213
|
requestOrFlag?: StartRequest | boolean
|
|
203
214
|
): AsyncGenerator<Activity> {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
215
|
+
const managed = trace(CopilotStudioClientTraceDefinitions.startConversation)
|
|
216
|
+
try {
|
|
217
|
+
// Normalize input to StartRequest
|
|
218
|
+
let request: StartRequest
|
|
219
|
+
|
|
220
|
+
if (typeof requestOrFlag === 'boolean' || requestOrFlag === undefined) {
|
|
221
|
+
// Legacy call: startConversationStreaming(true/false)
|
|
222
|
+
managed.record({ shouldEmitStartEvent: requestOrFlag ?? true })
|
|
223
|
+
request = {
|
|
224
|
+
emitStartConversationEvent: requestOrFlag ?? true
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
// New call: startConversationStreaming({ locale: 'en-US', ... })
|
|
228
|
+
request = requestOrFlag
|
|
229
|
+
managed.record({ shouldEmitStartEvent: request.emitStartConversationEvent ?? true })
|
|
211
230
|
}
|
|
212
|
-
} else {
|
|
213
|
-
// New call: startConversationStreaming({ locale: 'en-US', ... })
|
|
214
|
-
request = requestOrFlag
|
|
215
|
-
}
|
|
216
231
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
232
|
+
const uriStart: string = getCopilotStudioConnectionUrl(this.settings, request.conversationId)
|
|
233
|
+
const body: any = {
|
|
234
|
+
emitStartConversationEvent: request.emitStartConversationEvent ?? true
|
|
235
|
+
}
|
|
221
236
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
237
|
+
// Add locale to body if provided
|
|
238
|
+
if (request.locale) {
|
|
239
|
+
body.locale = request.locale
|
|
240
|
+
}
|
|
226
241
|
|
|
227
|
-
|
|
228
|
-
|
|
242
|
+
logger.info('Starting conversation ...', request)
|
|
243
|
+
this.logDiagnostic('Start conversation request:', body)
|
|
229
244
|
|
|
230
|
-
|
|
245
|
+
yield * this.postRequestAsync(uriStart, body, 'POST')
|
|
246
|
+
} catch (error) {
|
|
247
|
+
throw managed.fail(error)
|
|
248
|
+
} finally {
|
|
249
|
+
managed.end()
|
|
250
|
+
}
|
|
231
251
|
}
|
|
232
252
|
|
|
233
253
|
/**
|
|
@@ -237,12 +257,20 @@ export class CopilotStudioClient {
|
|
|
237
257
|
* @returns An async generator yielding the Agent's Activities.
|
|
238
258
|
*/
|
|
239
259
|
public async * sendActivityStreaming (activity: Activity, conversationId: string = this.conversationId) : AsyncGenerator<Activity> {
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
260
|
+
const managed = trace(CopilotStudioClientTraceDefinitions.sendActivity)
|
|
261
|
+
managed.record({ activity })
|
|
262
|
+
try {
|
|
263
|
+
const localConversationId = activity.conversation?.id ?? conversationId
|
|
264
|
+
const uriExecute = getCopilotStudioConnectionUrl(this.settings, localConversationId)
|
|
265
|
+
const qbody: ExecuteTurnRequest = new ExecuteTurnRequest(activity)
|
|
266
|
+
|
|
267
|
+
logger.info('Sending activity...', activity)
|
|
268
|
+
yield * this.postRequestAsync(uriExecute, qbody, 'POST')
|
|
269
|
+
} catch (error) {
|
|
270
|
+
throw managed.fail(error)
|
|
271
|
+
} finally {
|
|
272
|
+
managed.end()
|
|
273
|
+
}
|
|
246
274
|
}
|
|
247
275
|
|
|
248
276
|
/**
|
|
@@ -257,21 +285,29 @@ export class CopilotStudioClient {
|
|
|
257
285
|
activity: Activity,
|
|
258
286
|
conversationId: string
|
|
259
287
|
): AsyncGenerator<Activity> {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
288
|
+
const managed = trace(CopilotStudioClientTraceDefinitions.executeStreaming)
|
|
289
|
+
managed.record({ activity, conversationId })
|
|
290
|
+
try {
|
|
291
|
+
if (!conversationId || !conversationId.trim()) {
|
|
292
|
+
throw new Error('conversationId is required for executeStreaming')
|
|
293
|
+
}
|
|
263
294
|
|
|
264
|
-
|
|
265
|
-
|
|
295
|
+
const uriExecute = getCopilotStudioConnectionUrl(this.settings, conversationId)
|
|
296
|
+
const request: ExecuteTurnRequest = new ExecuteTurnRequest(activity, conversationId)
|
|
266
297
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
298
|
+
logger.info('Executing turn with conversation ID:', conversationId)
|
|
299
|
+
this.logDiagnostic('Execute turn request:', {
|
|
300
|
+
conversationId,
|
|
301
|
+
activityType: activity.type,
|
|
302
|
+
activityText: activity.text
|
|
303
|
+
})
|
|
273
304
|
|
|
274
|
-
|
|
305
|
+
yield * this.postRequestAsync(uriExecute, request, 'POST')
|
|
306
|
+
} catch (error) {
|
|
307
|
+
throw managed.fail(error)
|
|
308
|
+
} finally {
|
|
309
|
+
managed.end()
|
|
310
|
+
}
|
|
275
311
|
}
|
|
276
312
|
|
|
277
313
|
/**
|
|
@@ -415,60 +451,69 @@ export class CopilotStudioClient {
|
|
|
415
451
|
conversationId: string,
|
|
416
452
|
lastReceivedEventId?: string
|
|
417
453
|
): AsyncGenerator<SubscribeEvent> {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
logger.info('Subscribing to conversation:', conversationId)
|
|
425
|
-
this.logDiagnostic('Subscribe request:', { conversationId, lastReceivedEventId, url })
|
|
426
|
-
|
|
427
|
-
const eventSource: EventSourceClient = createEventSource({
|
|
428
|
-
url,
|
|
429
|
-
headers: {
|
|
430
|
-
Authorization: `Bearer ${this.token}`,
|
|
431
|
-
'User-Agent': UserAgentHelper.getProductInfo(),
|
|
432
|
-
Accept: 'text/event-stream',
|
|
433
|
-
...(lastReceivedEventId && { 'Last-Event-ID': lastReceivedEventId })
|
|
434
|
-
},
|
|
435
|
-
method: 'GET',
|
|
436
|
-
fetch: async (url, init) => {
|
|
437
|
-
const response = await fetch(url, init)
|
|
438
|
-
this.processResponseHeaders(response.headers)
|
|
439
|
-
return response
|
|
454
|
+
const managed = trace(CopilotStudioClientTraceDefinitions.subscribeAsync)
|
|
455
|
+
managed.record({ conversationId, lastReceivedEventId })
|
|
456
|
+
try {
|
|
457
|
+
if (!conversationId || !conversationId.trim()) {
|
|
458
|
+
throw new Error('conversationId is required for subscribeAsync')
|
|
440
459
|
}
|
|
441
|
-
})
|
|
442
460
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
461
|
+
const url = getCopilotStudioSubscribeUrl(this.settings, conversationId)
|
|
462
|
+
|
|
463
|
+
logger.info('Subscribing to conversation:', conversationId)
|
|
464
|
+
this.logDiagnostic('Subscribe request:', { conversationId, lastReceivedEventId, url })
|
|
465
|
+
|
|
466
|
+
const eventSource: EventSourceClient = createEventSource({
|
|
467
|
+
url,
|
|
468
|
+
headers: {
|
|
469
|
+
Authorization: `Bearer ${this.token}`,
|
|
470
|
+
'User-Agent': UserAgentHelper.getProductInfo(),
|
|
471
|
+
Accept: 'text/event-stream',
|
|
472
|
+
...(lastReceivedEventId && { 'Last-Event-ID': lastReceivedEventId })
|
|
473
|
+
},
|
|
474
|
+
method: 'GET',
|
|
475
|
+
fetch: async (url, init) => {
|
|
476
|
+
const response = await fetch(url, init)
|
|
477
|
+
this.processResponseHeaders(response.headers)
|
|
478
|
+
return response
|
|
479
|
+
}
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
try {
|
|
483
|
+
for await (const { data, event, id } of eventSource) {
|
|
484
|
+
if (data && event === 'activity') {
|
|
485
|
+
try {
|
|
486
|
+
const activity = Activity.fromJson(data)
|
|
487
|
+
const subscribeEvent: SubscribeEvent = {
|
|
488
|
+
activity,
|
|
489
|
+
eventId: id
|
|
490
|
+
}
|
|
491
|
+
managed.actions.eventReceivedFromCopilot(subscribeEvent)
|
|
492
|
+
|
|
493
|
+
logger.debug(`Received activity via subscription, event ID: ${id}`)
|
|
494
|
+
this.logDiagnostic('Subscribe event received:', { eventId: id, activityType: activity.type })
|
|
495
|
+
|
|
496
|
+
yield subscribeEvent
|
|
497
|
+
} catch (error) {
|
|
498
|
+
logger.error('Failed to parse activity in subscription:', error)
|
|
451
499
|
}
|
|
452
|
-
|
|
453
|
-
logger.debug(
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
yield subscribeEvent
|
|
457
|
-
} catch (error) {
|
|
458
|
-
logger.error('Failed to parse activity in subscription:', error)
|
|
500
|
+
} else if (event === 'end') {
|
|
501
|
+
logger.debug('Subscription stream complete')
|
|
502
|
+
break
|
|
459
503
|
}
|
|
460
|
-
} else if (event === 'end') {
|
|
461
|
-
logger.debug('Subscription stream complete')
|
|
462
|
-
break
|
|
463
|
-
}
|
|
464
504
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
505
|
+
if (eventSource.readyState === 'closed') {
|
|
506
|
+
logger.debug('Subscription connection closed')
|
|
507
|
+
break
|
|
508
|
+
}
|
|
468
509
|
}
|
|
510
|
+
} finally {
|
|
511
|
+
eventSource.close()
|
|
469
512
|
}
|
|
513
|
+
} catch (error) {
|
|
514
|
+
throw managed.fail(error)
|
|
470
515
|
} finally {
|
|
471
|
-
|
|
516
|
+
managed.end()
|
|
472
517
|
}
|
|
473
518
|
}
|
|
474
519
|
}
|