@microsoft/agents-hosting 1.6.0-beta.8.g226709c215 → 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.
Files changed (94) hide show
  1. package/dist/package.json +4 -9
  2. package/dist/src/agent-client/agentClient.js +2 -2
  3. package/dist/src/agent-client/agentClient.js.map +1 -1
  4. package/dist/src/agent-client/agentResponseHandler.js +2 -2
  5. package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
  6. package/dist/src/app/agentApplication.js +28 -2
  7. package/dist/src/app/agentApplication.js.map +1 -1
  8. package/dist/src/app/agentApplicationOptions.d.ts +10 -0
  9. package/dist/src/app/attachmentDownloader.js +5 -10
  10. package/dist/src/app/attachmentDownloader.js.map +1 -1
  11. package/dist/src/app/auth/authorizationManager.d.ts +4 -0
  12. package/dist/src/app/auth/authorizationManager.js +94 -67
  13. package/dist/src/app/auth/authorizationManager.js.map +1 -1
  14. package/dist/src/app/auth/handlers/azureBotAuthorization.js +2 -2
  15. package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -1
  16. package/dist/src/app/proactive/createConversationOptionsBuilder.js +10 -6
  17. package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -1
  18. package/dist/src/app/proactive/proactive.d.ts +1 -0
  19. package/dist/src/app/proactive/proactive.js +30 -15
  20. package/dist/src/app/proactive/proactive.js.map +1 -1
  21. package/dist/src/app/teamsAttachmentDownloader.js +6 -8
  22. package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
  23. package/dist/src/auth/authConfiguration.d.ts +2 -143
  24. package/dist/src/auth/authConfiguration.js +301 -257
  25. package/dist/src/auth/authConfiguration.js.map +1 -1
  26. package/dist/src/auth/jwt-middleware.js +2 -1
  27. package/dist/src/auth/jwt-middleware.js.map +1 -1
  28. package/dist/src/auth/msalConnectionManager.js +27 -14
  29. package/dist/src/auth/msalConnectionManager.js.map +1 -1
  30. package/dist/src/auth/msalTokenProvider.d.ts +7 -0
  31. package/dist/src/auth/msalTokenProvider.js +188 -44
  32. package/dist/src/auth/msalTokenProvider.js.map +1 -1
  33. package/dist/src/auth/settings.d.ts +327 -0
  34. package/dist/src/auth/settings.js +158 -0
  35. package/dist/src/auth/settings.js.map +1 -0
  36. package/dist/src/cloudAdapter.d.ts +58 -1
  37. package/dist/src/cloudAdapter.js +232 -52
  38. package/dist/src/cloudAdapter.js.map +1 -1
  39. package/dist/src/connector-client/connectorClient.d.ts +12 -8
  40. package/dist/src/connector-client/connectorClient.js +99 -82
  41. package/dist/src/connector-client/connectorClient.js.map +1 -1
  42. package/dist/src/errorHelper.js +85 -7
  43. package/dist/src/errorHelper.js.map +1 -1
  44. package/dist/src/getProductInfo.d.ts +23 -0
  45. package/dist/src/getProductInfo.js +71 -1
  46. package/dist/src/getProductInfo.js.map +1 -1
  47. package/dist/src/headerPropagation.d.ts +17 -2
  48. package/dist/src/headerPropagation.js +46 -24
  49. package/dist/src/headerPropagation.js.map +1 -1
  50. package/dist/src/httpClient.d.ts +60 -0
  51. package/dist/src/httpClient.js +173 -0
  52. package/dist/src/httpClient.js.map +1 -0
  53. package/dist/src/index.d.ts +2 -1
  54. package/dist/src/index.js +7 -2
  55. package/dist/src/index.js.map +1 -1
  56. package/dist/src/oauth/userTokenClient.d.ts +5 -4
  57. package/dist/src/oauth/userTokenClient.js +97 -78
  58. package/dist/src/oauth/userTokenClient.js.map +1 -1
  59. package/dist/src/observability/traces.d.ts +11 -4
  60. package/dist/src/observability/traces.js +39 -7
  61. package/dist/src/observability/traces.js.map +1 -1
  62. package/dist/src/utils/env.d.ts +50 -0
  63. package/dist/src/utils/env.js +113 -0
  64. package/dist/src/utils/env.js.map +1 -0
  65. package/dist/src/utils.d.ts +10 -0
  66. package/dist/src/utils.js +18 -0
  67. package/dist/src/utils.js.map +1 -0
  68. package/package.json +4 -9
  69. package/src/agent-client/agentClient.ts +2 -2
  70. package/src/agent-client/agentResponseHandler.ts +2 -2
  71. package/src/app/agentApplication.ts +30 -3
  72. package/src/app/agentApplicationOptions.ts +11 -0
  73. package/src/app/attachmentDownloader.ts +6 -8
  74. package/src/app/auth/authorizationManager.ts +84 -41
  75. package/src/app/auth/handlers/azureBotAuthorization.ts +2 -2
  76. package/src/app/proactive/createConversationOptionsBuilder.ts +8 -4
  77. package/src/app/proactive/proactive.ts +39 -23
  78. package/src/app/teamsAttachmentDownloader.ts +7 -6
  79. package/src/auth/authConfiguration.ts +317 -356
  80. package/src/auth/jwt-middleware.ts +1 -1
  81. package/src/auth/msalConnectionManager.ts +27 -10
  82. package/src/auth/msalTokenProvider.ts +180 -42
  83. package/src/auth/settings.ts +323 -0
  84. package/src/cloudAdapter.ts +291 -12
  85. package/src/connector-client/connectorClient.ts +116 -94
  86. package/src/errorHelper.ts +96 -7
  87. package/src/getProductInfo.ts +79 -1
  88. package/src/headerPropagation.ts +55 -23
  89. package/src/httpClient.ts +223 -0
  90. package/src/index.ts +5 -1
  91. package/src/oauth/userTokenClient.ts +103 -84
  92. package/src/observability/traces.ts +39 -8
  93. package/src/utils/env.ts +105 -0
  94. 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
- await this.requireStorage().write({ [`${STORAGE_KEY_PREFIX}${id}`]: { reference: conv.reference, claims: conv.claims } })
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 result = await this.requireStorage().read([`${STORAGE_KEY_PREFIX}${conversationId}`])
138
- const stored = result[`${STORAGE_KEY_PREFIX}${conversationId}`] as { reference: any; claims: any } | undefined
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([`${STORAGE_KEY_PREFIX}${conversationId}`])
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
- typeof conversationOrId === 'string'
237
- ? await this.getConversationOrThrow(conversationOrId)
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: conv.reference.conversation.id,
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
- conv.reference.conversation.id, conv.reference.channelId, conv.reference.serviceUrl)
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', conv.reference.conversation.id, caughtError)
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
- typeof conversationOrId === 'string'
351
- ? await this.getConversationOrThrow(conversationOrId)
352
- : conversationOrId
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: conv.reference.conversation.id,
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
- conv.reference.conversation.id, conv.reference.channelId, conv.reference.serviceUrl)
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
- conv.reference.conversation.id, autoSignInHandlers)
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', conv.reference.conversation.id, caughtError)
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', conv.reference.conversation.id)
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 axios, { AxiosInstance } from 'axios'
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: AxiosInstance
21
+ private _httpClient: HttpClient
22
22
  private _stateKey: string
23
23
 
24
24
  public constructor (stateKey: string = 'inputFiles') {
25
- this._httpClient = axios.create()
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.defaults.headers = connectorClient.axiosInstance.defaults.headers
46
+ this._httpClient.defaultHeaders = { ...connectorClient.httpClient.defaultHeaders }
47
47
 
48
48
  const files: InputFile[] = []
49
49
  for (const attachment of attachments) {
@@ -71,8 +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, 'binary')
75
- const contentType = response.headers['content-type'] || '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'
76
77
  inputFile = { content, contentType, contentUrl: attachment.contentUrl }
77
78
  } catch (error) {
78
79
  logger.error(`Failed to download Teams attachment: ${error}`)