@microsoft/agents-hosting 1.6.0-beta.9.gce9d8facd2 → 1.6.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 +4 -9
- package/dist/src/agent-client/agentClient.js +2 -2
- package/dist/src/agent-client/agentClient.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.js +2 -2
- package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
- package/dist/src/app/agentApplication.js +28 -2
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +10 -0
- package/dist/src/app/attachmentDownloader.js +5 -10
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/auth/authorizationManager.d.ts +4 -0
- package/dist/src/app/auth/authorizationManager.js +94 -67
- package/dist/src/app/auth/authorizationManager.js.map +1 -1
- package/dist/src/app/auth/handlers/azureBotAuthorization.js +2 -2
- package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -1
- package/dist/src/app/proactive/createConversationOptionsBuilder.js +10 -6
- package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -1
- package/dist/src/app/proactive/proactive.d.ts +1 -0
- package/dist/src/app/proactive/proactive.js +30 -15
- package/dist/src/app/proactive/proactive.js.map +1 -1
- package/dist/src/app/teamsAttachmentDownloader.js +6 -14
- package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +2 -143
- package/dist/src/auth/authConfiguration.js +301 -257
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +2 -1
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalConnectionManager.js +27 -14
- package/dist/src/auth/msalConnectionManager.js.map +1 -1
- package/dist/src/auth/msalTokenProvider.d.ts +7 -0
- package/dist/src/auth/msalTokenProvider.js +188 -44
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/auth/settings.d.ts +327 -0
- package/dist/src/auth/settings.js +158 -0
- package/dist/src/auth/settings.js.map +1 -0
- package/dist/src/cloudAdapter.d.ts +58 -1
- package/dist/src/cloudAdapter.js +232 -52
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +12 -8
- package/dist/src/connector-client/connectorClient.js +99 -82
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/errorHelper.js +85 -7
- package/dist/src/errorHelper.js.map +1 -1
- package/dist/src/getProductInfo.d.ts +23 -0
- package/dist/src/getProductInfo.js +71 -1
- package/dist/src/getProductInfo.js.map +1 -1
- package/dist/src/headerPropagation.d.ts +17 -2
- package/dist/src/headerPropagation.js +46 -24
- package/dist/src/headerPropagation.js.map +1 -1
- package/dist/src/httpClient.d.ts +60 -0
- package/dist/src/httpClient.js +173 -0
- package/dist/src/httpClient.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +7 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +5 -4
- package/dist/src/oauth/userTokenClient.js +97 -78
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/observability/traces.d.ts +11 -4
- package/dist/src/observability/traces.js +39 -7
- package/dist/src/observability/traces.js.map +1 -1
- package/dist/src/utils/env.d.ts +50 -0
- package/dist/src/utils/env.js +113 -0
- package/dist/src/utils/env.js.map +1 -0
- package/dist/src/utils.d.ts +10 -0
- package/dist/src/utils.js +18 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +4 -9
- package/src/agent-client/agentClient.ts +2 -2
- package/src/agent-client/agentResponseHandler.ts +2 -2
- package/src/app/agentApplication.ts +30 -3
- package/src/app/agentApplicationOptions.ts +11 -0
- package/src/app/attachmentDownloader.ts +6 -8
- package/src/app/auth/authorizationManager.ts +84 -41
- package/src/app/auth/handlers/azureBotAuthorization.ts +2 -2
- package/src/app/proactive/createConversationOptionsBuilder.ts +8 -4
- package/src/app/proactive/proactive.ts +39 -23
- package/src/app/teamsAttachmentDownloader.ts +7 -11
- package/src/auth/authConfiguration.ts +317 -356
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/auth/msalConnectionManager.ts +27 -10
- package/src/auth/msalTokenProvider.ts +180 -42
- package/src/auth/settings.ts +323 -0
- package/src/cloudAdapter.ts +291 -12
- package/src/connector-client/connectorClient.ts +116 -94
- package/src/errorHelper.ts +96 -7
- package/src/getProductInfo.ts +79 -1
- package/src/headerPropagation.ts +55 -23
- package/src/httpClient.ts +223 -0
- package/src/index.ts +5 -1
- package/src/oauth/userTokenClient.ts +103 -84
- package/src/observability/traces.ts +39 -8
- package/src/utils/env.ts +105 -0
- package/src/utils.ts +14 -0
|
@@ -49,6 +49,10 @@ export class Proactive<TState extends TurnState> {
|
|
|
49
49
|
this._storage = options.storage
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
private _storageKey (conversationId: string): string {
|
|
53
|
+
return `${STORAGE_KEY_PREFIX}${conversationId}`
|
|
54
|
+
}
|
|
55
|
+
|
|
52
56
|
private requireStorage (): Storage {
|
|
53
57
|
if (!this._storage) {
|
|
54
58
|
throw ExceptionHelper.generateException(Error, Errors.ProactiveStorageRequired)
|
|
@@ -104,7 +108,7 @@ export class Proactive<TState extends TurnState> {
|
|
|
104
108
|
*/
|
|
105
109
|
storeConversation (conversation: Conversation): Promise<string>
|
|
106
110
|
async storeConversation (contextOrConversation: TurnContext | Conversation): Promise<string> {
|
|
107
|
-
return trace(ProactiveTraceDefinitions.storeConversation, async ({ record }) => {
|
|
111
|
+
return trace(ProactiveTraceDefinitions.storeConversation, async ({ record, actions }) => {
|
|
108
112
|
const conv =
|
|
109
113
|
contextOrConversation instanceof Conversation
|
|
110
114
|
? contextOrConversation
|
|
@@ -112,8 +116,11 @@ export class Proactive<TState extends TurnState> {
|
|
|
112
116
|
|
|
113
117
|
conv.validate()
|
|
114
118
|
const id = conv.reference.conversation.id
|
|
119
|
+
const storage = this.requireStorage()
|
|
120
|
+
const key = this._storageKey(id)
|
|
115
121
|
record({ conversationId: id })
|
|
116
|
-
|
|
122
|
+
const linkedItem = await actions.link(storage, key)
|
|
123
|
+
await storage.write({ [key]: { ...linkedItem, reference: conv.reference, claims: conv.claims } })
|
|
117
124
|
return id
|
|
118
125
|
})
|
|
119
126
|
}
|
|
@@ -134,8 +141,8 @@ export class Proactive<TState extends TurnState> {
|
|
|
134
141
|
async getConversation (conversationId: string): Promise<Conversation | undefined> {
|
|
135
142
|
return trace(ProactiveTraceDefinitions.getConversation, async ({ record }) => {
|
|
136
143
|
record({ conversationId })
|
|
137
|
-
const
|
|
138
|
-
const stored =
|
|
144
|
+
const storageKey = this._storageKey(conversationId)
|
|
145
|
+
const stored = (await this.requireStorage().read([storageKey]))?.[storageKey]
|
|
139
146
|
if (!stored) {
|
|
140
147
|
record({ found: false })
|
|
141
148
|
return undefined
|
|
@@ -186,7 +193,7 @@ export class Proactive<TState extends TurnState> {
|
|
|
186
193
|
async deleteConversation (conversationId: string): Promise<void> {
|
|
187
194
|
return trace(ProactiveTraceDefinitions.deleteConversation, async ({ record }) => {
|
|
188
195
|
record({ conversationId })
|
|
189
|
-
await this.requireStorage().delete([
|
|
196
|
+
await this.requireStorage().delete([this._storageKey(conversationId)])
|
|
190
197
|
})
|
|
191
198
|
}
|
|
192
199
|
|
|
@@ -231,22 +238,26 @@ export class Proactive<TState extends TurnState> {
|
|
|
231
238
|
conversationOrId: Conversation | string,
|
|
232
239
|
activity: Partial<Activity>
|
|
233
240
|
): Promise<ResourceResponse> {
|
|
234
|
-
return trace(ProactiveTraceDefinitions.sendActivity, async ({ record }) => {
|
|
235
|
-
const conv =
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
: conversationOrId
|
|
241
|
+
return trace(ProactiveTraceDefinitions.sendActivity, async ({ record, actions }) => {
|
|
242
|
+
const conv = typeof conversationOrId === 'string'
|
|
243
|
+
? await this.getConversationOrThrow(conversationOrId)
|
|
244
|
+
: conversationOrId
|
|
239
245
|
|
|
246
|
+
const id = conv.reference.conversation.id
|
|
240
247
|
const activityToSend: Partial<Activity> = { type: 'message', ...activity }
|
|
241
248
|
|
|
242
249
|
record({
|
|
243
|
-
conversationId:
|
|
250
|
+
conversationId: id,
|
|
244
251
|
channelId: conv.reference.channelId,
|
|
245
252
|
activityType: activityToSend.type ?? 'message',
|
|
246
253
|
})
|
|
247
254
|
|
|
255
|
+
if (this._storage) {
|
|
256
|
+
await actions.link(this._storage, this._storageKey(id))
|
|
257
|
+
}
|
|
258
|
+
|
|
248
259
|
logger.info('sendActivity: conversation=%s channel=%s serviceUrl=%s',
|
|
249
|
-
|
|
260
|
+
id, conv.reference.channelId, conv.reference.serviceUrl)
|
|
250
261
|
|
|
251
262
|
let response: ResourceResponse | undefined
|
|
252
263
|
let caughtError: unknown
|
|
@@ -261,7 +272,7 @@ export class Proactive<TState extends TurnState> {
|
|
|
261
272
|
})
|
|
262
273
|
|
|
263
274
|
if (caughtError !== undefined) {
|
|
264
|
-
logger.warn('sendActivity: failed for conversation=%s: %s',
|
|
275
|
+
logger.warn('sendActivity: failed for conversation=%s: %s', id, caughtError)
|
|
265
276
|
throw caughtError
|
|
266
277
|
}
|
|
267
278
|
if (response === undefined) throw ExceptionHelper.generateException(Error, Errors.ProactiveSendActivityNoResponse)
|
|
@@ -345,20 +356,25 @@ export class Proactive<TState extends TurnState> {
|
|
|
345
356
|
autoSignInHandlers?: string[],
|
|
346
357
|
continuationActivity?: Partial<Activity>
|
|
347
358
|
): Promise<void> {
|
|
348
|
-
return trace(ProactiveTraceDefinitions.continueConversation, async ({ record }) => {
|
|
349
|
-
const conv =
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
359
|
+
return trace(ProactiveTraceDefinitions.continueConversation, async ({ record, actions }) => {
|
|
360
|
+
const conv = typeof conversationOrId === 'string'
|
|
361
|
+
? await this.getConversationOrThrow(conversationOrId)
|
|
362
|
+
: conversationOrId
|
|
363
|
+
|
|
364
|
+
const id = conv.reference.conversation.id
|
|
353
365
|
|
|
354
366
|
record({
|
|
355
|
-
conversationId:
|
|
367
|
+
conversationId: id,
|
|
356
368
|
channelId: conv.reference.channelId,
|
|
357
369
|
hasAutoSignIn: !!autoSignInHandlers?.length,
|
|
358
370
|
})
|
|
359
371
|
|
|
372
|
+
if (this._storage) {
|
|
373
|
+
await actions.link(this._storage, this._storageKey(id))
|
|
374
|
+
}
|
|
375
|
+
|
|
360
376
|
logger.info('continueConversation: conversation=%s channel=%s serviceUrl=%s',
|
|
361
|
-
|
|
377
|
+
id, conv.reference.channelId, conv.reference.serviceUrl)
|
|
362
378
|
|
|
363
379
|
let caughtError: unknown
|
|
364
380
|
|
|
@@ -384,7 +400,7 @@ export class Proactive<TState extends TurnState> {
|
|
|
384
400
|
const allAcquired = results.every((r) => !!r.token)
|
|
385
401
|
if (!allAcquired) {
|
|
386
402
|
logger.warn('continueConversation: not all tokens acquired for conversation=%s handlers=%o',
|
|
387
|
-
|
|
403
|
+
id, autoSignInHandlers)
|
|
388
404
|
if (this._options.failOnUnsignedInConnections !== false) {
|
|
389
405
|
throw ExceptionHelper.generateException(Error, Errors.ProactiveNotAllTokensAcquired)
|
|
390
406
|
}
|
|
@@ -403,10 +419,10 @@ export class Proactive<TState extends TurnState> {
|
|
|
403
419
|
})
|
|
404
420
|
|
|
405
421
|
if (caughtError !== undefined) {
|
|
406
|
-
logger.warn('continueConversation: failed for conversation=%s: %s',
|
|
422
|
+
logger.warn('continueConversation: failed for conversation=%s: %s', id, caughtError)
|
|
407
423
|
throw caughtError
|
|
408
424
|
}
|
|
409
|
-
logger.debug('continueConversation: complete for conversation=%s',
|
|
425
|
+
logger.debug('continueConversation: complete for conversation=%s', id)
|
|
410
426
|
})
|
|
411
427
|
}
|
|
412
428
|
|
|
@@ -9,7 +9,7 @@ import { ConnectorClient } from '../connector-client'
|
|
|
9
9
|
import { InputFile, InputFileDownloader } from './inputFileDownloader'
|
|
10
10
|
import { TurnContext } from '../turnContext'
|
|
11
11
|
import { TurnState } from './turnState'
|
|
12
|
-
import
|
|
12
|
+
import { HttpClient } from '../httpClient'
|
|
13
13
|
import { z } from 'zod'
|
|
14
14
|
|
|
15
15
|
const logger = debug('agents:M365AttachmentDownloader')
|
|
@@ -18,11 +18,11 @@ const logger = debug('agents:M365AttachmentDownloader')
|
|
|
18
18
|
* Downloads attachments from Teams and M365 using the bots access token.
|
|
19
19
|
*/
|
|
20
20
|
export class M365AttachmentDownloader<TState extends TurnState = TurnState> implements InputFileDownloader<TState> {
|
|
21
|
-
private _httpClient:
|
|
21
|
+
private _httpClient: HttpClient
|
|
22
22
|
private _stateKey: string
|
|
23
23
|
|
|
24
24
|
public constructor (stateKey: string = 'inputFiles') {
|
|
25
|
-
this._httpClient =
|
|
25
|
+
this._httpClient = new HttpClient()
|
|
26
26
|
this._stateKey = stateKey
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -43,7 +43,7 @@ export class M365AttachmentDownloader<TState extends TurnState = TurnState> impl
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const connectorClient : ConnectorClient = context.turnState.get<ConnectorClient>(context.adapter.ConnectorClientKey)
|
|
46
|
-
this._httpClient.
|
|
46
|
+
this._httpClient.defaultHeaders = { ...connectorClient.httpClient.defaultHeaders }
|
|
47
47
|
|
|
48
48
|
const files: InputFile[] = []
|
|
49
49
|
for (const attachment of attachments) {
|
|
@@ -71,13 +71,9 @@ export class M365AttachmentDownloader<TState extends TurnState = TurnState> impl
|
|
|
71
71
|
const downloadUrl = parsed.success ? parsed.data.downloadUrl : attachment.contentUrl
|
|
72
72
|
const response = await this._httpClient.get(downloadUrl, { responseType: 'arraybuffer' })
|
|
73
73
|
|
|
74
|
-
const content = Buffer.from(response.data
|
|
75
|
-
const contentTypeHeader =
|
|
76
|
-
|
|
77
|
-
: response.headers['content-type']
|
|
78
|
-
const contentType = Array.isArray(contentTypeHeader)
|
|
79
|
-
? (contentTypeHeader[0] ?? 'application/octet-stream')
|
|
80
|
-
: (typeof contentTypeHeader === 'string' ? contentTypeHeader : 'application/octet-stream')
|
|
74
|
+
const content = Buffer.from(response.data as ArrayBuffer)
|
|
75
|
+
const contentTypeHeader = response.headers.get('content-type')
|
|
76
|
+
const contentType = typeof contentTypeHeader === 'string' ? contentTypeHeader : 'application/octet-stream'
|
|
81
77
|
inputFile = { content, contentType, contentUrl: attachment.contentUrl }
|
|
82
78
|
} catch (error) {
|
|
83
79
|
logger.error(`Failed to download Teams attachment: ${error}`)
|