@microsoft/agents-hosting 0.6.1 → 0.6.11

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 (142) hide show
  1. package/dist/src/activityHandler.d.ts +29 -5
  2. package/dist/src/activityHandler.js +30 -6
  3. package/dist/src/activityHandler.js.map +1 -1
  4. package/dist/src/agent-client/agentClient.js +1 -1
  5. package/dist/src/agent-client/agentClient.js.map +1 -1
  6. package/dist/src/agent-client/agentResponseHandler.d.ts +34 -0
  7. package/dist/src/agent-client/agentResponseHandler.js +35 -1
  8. package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
  9. package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +23 -2
  10. package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -1
  11. package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.d.ts +1 -1
  12. package/dist/src/app/agentApplication.d.ts +46 -34
  13. package/dist/src/app/agentApplication.js +64 -40
  14. package/dist/src/app/agentApplication.js.map +1 -1
  15. package/dist/src/app/agentApplicationOptions.d.ts +74 -13
  16. package/dist/src/app/appRoute.d.ts +56 -2
  17. package/dist/src/app/attachmentDownloader.d.ts +1 -0
  18. package/dist/src/app/attachmentDownloader.js +2 -1
  19. package/dist/src/app/attachmentDownloader.js.map +1 -1
  20. package/dist/src/app/authorization.d.ts +1 -1
  21. package/dist/src/app/authorization.js +1 -1
  22. package/dist/src/app/authorization.js.map +1 -1
  23. package/dist/src/app/extensions.d.ts +37 -1
  24. package/dist/src/app/extensions.js +38 -2
  25. package/dist/src/app/extensions.js.map +1 -1
  26. package/dist/src/app/index.d.ts +2 -0
  27. package/dist/src/app/index.js +2 -0
  28. package/dist/src/app/index.js.map +1 -1
  29. package/dist/src/app/routeList.d.ts +13 -0
  30. package/dist/src/app/routeList.js +30 -0
  31. package/dist/src/app/routeList.js.map +1 -0
  32. package/dist/src/app/routeRank.d.ts +51 -0
  33. package/dist/src/app/routeRank.js +56 -0
  34. package/dist/src/app/routeRank.js.map +1 -0
  35. package/dist/src/app/streaming/streamingResponse.js +29 -41
  36. package/dist/src/app/streaming/streamingResponse.js.map +1 -1
  37. package/dist/src/app/turnState.d.ts +2 -0
  38. package/dist/src/app/turnState.js +3 -1
  39. package/dist/src/app/turnState.js.map +1 -1
  40. package/dist/src/auth/authConfiguration.d.ts +4 -0
  41. package/dist/src/auth/authConfiguration.js +4 -0
  42. package/dist/src/auth/authConfiguration.js.map +1 -1
  43. package/dist/src/auth/authProvider.d.ts +1 -1
  44. package/dist/src/auth/jwt-middleware.js +1 -1
  45. package/dist/src/auth/jwt-middleware.js.map +1 -1
  46. package/dist/src/auth/msalTokenCredential.d.ts +14 -0
  47. package/dist/src/auth/msalTokenCredential.js +14 -0
  48. package/dist/src/auth/msalTokenCredential.js.map +1 -1
  49. package/dist/src/auth/msalTokenProvider.js +4 -2
  50. package/dist/src/auth/msalTokenProvider.js.map +1 -1
  51. package/dist/src/baseAdapter.d.ts +22 -1
  52. package/dist/src/baseAdapter.js +23 -2
  53. package/dist/src/baseAdapter.js.map +1 -1
  54. package/dist/src/cards/adaptiveCard.d.ts +2 -0
  55. package/dist/src/cards/animationCard.d.ts +1 -1
  56. package/dist/src/cards/audioCard.d.ts +1 -1
  57. package/dist/src/cards/cardImage.d.ts +1 -1
  58. package/dist/src/cards/fact.d.ts +1 -1
  59. package/dist/src/cards/heroCard.d.ts +1 -1
  60. package/dist/src/cards/o365ConnectorCardSection.d.ts +5 -0
  61. package/dist/src/cloudAdapter.d.ts +11 -0
  62. package/dist/src/cloudAdapter.js +33 -4
  63. package/dist/src/cloudAdapter.js.map +1 -1
  64. package/dist/src/connector-client/connectorClient.js +1 -1
  65. package/dist/src/connector-client/connectorClient.js.map +1 -1
  66. package/dist/src/index.d.ts +0 -2
  67. package/dist/src/index.js +0 -2
  68. package/dist/src/index.js.map +1 -1
  69. package/dist/src/middlewareSet.js +1 -1
  70. package/dist/src/middlewareSet.js.map +1 -1
  71. package/dist/src/oauth/oAuthFlow.js +1 -1
  72. package/dist/src/oauth/oAuthFlow.js.map +1 -1
  73. package/dist/src/oauth/userTokenClient.js +1 -1
  74. package/dist/src/oauth/userTokenClient.js.map +1 -1
  75. package/dist/src/state/agentState.js +1 -1
  76. package/dist/src/state/agentState.js.map +1 -1
  77. package/dist/src/state/agentStatePropertyAccesor.d.ts +269 -38
  78. package/dist/src/state/agentStatePropertyAccesor.js +269 -38
  79. package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
  80. package/dist/src/statusCodes.d.ts +30 -0
  81. package/dist/src/statusCodes.js +30 -0
  82. package/dist/src/statusCodes.js.map +1 -1
  83. package/dist/src/storage/fileStorage.d.ts +97 -0
  84. package/dist/src/storage/fileStorage.js +97 -0
  85. package/dist/src/storage/fileStorage.js.map +1 -1
  86. package/dist/src/storage/memoryStorage.d.ts +2 -1
  87. package/dist/src/storage/memoryStorage.js +3 -2
  88. package/dist/src/storage/memoryStorage.js.map +1 -1
  89. package/dist/src/storage/storage.d.ts +1 -0
  90. package/dist/src/transcript/transcriptLoggerMiddleware.js +1 -1
  91. package/dist/src/transcript/transcriptLoggerMiddleware.js.map +1 -1
  92. package/dist/src/turnContext.d.ts +1 -0
  93. package/dist/src/turnContext.js +1 -0
  94. package/dist/src/turnContext.js.map +1 -1
  95. package/package.json +4 -5
  96. package/src/activityHandler.ts +30 -6
  97. package/src/agent-client/agentClient.ts +1 -1
  98. package/src/agent-client/agentResponseHandler.ts +35 -1
  99. package/src/app/adaptiveCards/adaptiveCardsActions.ts +23 -2
  100. package/src/app/adaptiveCards/adaptiveCardsSearchParams.ts +1 -1
  101. package/src/app/agentApplication.ts +70 -41
  102. package/src/app/agentApplicationOptions.ts +75 -13
  103. package/src/app/appRoute.ts +57 -2
  104. package/src/app/attachmentDownloader.ts +2 -1
  105. package/src/app/authorization.ts +2 -2
  106. package/src/app/extensions.ts +45 -2
  107. package/src/app/index.ts +2 -0
  108. package/src/app/routeList.ts +37 -0
  109. package/src/app/routeRank.ts +54 -0
  110. package/src/app/streaming/streamingResponse.ts +22 -69
  111. package/src/app/turnState.ts +3 -1
  112. package/src/auth/authConfiguration.ts +4 -0
  113. package/src/auth/authProvider.ts +1 -1
  114. package/src/auth/jwt-middleware.ts +1 -1
  115. package/src/auth/msalTokenCredential.ts +15 -0
  116. package/src/auth/msalTokenProvider.ts +4 -2
  117. package/src/baseAdapter.ts +25 -2
  118. package/src/cards/adaptiveCard.ts +2 -0
  119. package/src/cards/animationCard.ts +1 -1
  120. package/src/cards/audioCard.ts +1 -1
  121. package/src/cards/cardImage.ts +1 -1
  122. package/src/cards/fact.ts +1 -1
  123. package/src/cards/heroCard.ts +1 -1
  124. package/src/cards/o365ConnectorCardSection.ts +5 -0
  125. package/src/cloudAdapter.ts +36 -4
  126. package/src/connector-client/connectorClient.ts +1 -1
  127. package/src/index.ts +0 -2
  128. package/src/middlewareSet.ts +1 -1
  129. package/src/oauth/oAuthFlow.ts +1 -1
  130. package/src/oauth/userTokenClient.ts +1 -1
  131. package/src/state/agentState.ts +1 -1
  132. package/src/state/agentStatePropertyAccesor.ts +269 -38
  133. package/src/statusCodes.ts +30 -0
  134. package/src/storage/fileStorage.ts +99 -0
  135. package/src/storage/memoryStorage.ts +3 -2
  136. package/src/storage/storage.ts +1 -0
  137. package/src/transcript/transcriptLoggerMiddleware.ts +1 -1
  138. package/src/turnContext.ts +1 -0
  139. package/dist/src/logger.d.ts +0 -44
  140. package/dist/src/logger.js +0 -77
  141. package/dist/src/logger.js.map +0 -1
  142. package/src/logger.ts +0 -76
@@ -6,11 +6,10 @@
6
6
  import { Activity, ActivityTypes, ConversationReference } from '@microsoft/agents-activity'
7
7
  import { BaseAdapter } from '../baseAdapter'
8
8
  import { ResourceResponse } from '../connector-client'
9
- import { debug } from '../logger'
9
+ import { debug } from '@microsoft/agents-activity/src/logger'
10
10
  import { TurnContext } from '../turnContext'
11
11
  import { AdaptiveCardsActions } from './adaptiveCards'
12
12
  import { AgentApplicationOptions } from './agentApplicationOptions'
13
- import { AppRoute } from './appRoute'
14
13
  import { ConversationUpdateEvents } from './conversationUpdateEvents'
15
14
  import { AgentExtension } from './extensions'
16
15
  import { Authorization, SignInState } from './authorization'
@@ -18,6 +17,9 @@ import { RouteHandler } from './routeHandler'
18
17
  import { RouteSelector } from './routeSelector'
19
18
  import { TurnEvents } from './turnEvents'
20
19
  import { TurnState } from './turnState'
20
+ import { RouteRank } from './routeRank'
21
+ import { RouteList } from './routeList'
22
+ import { TranscriptLoggerMiddleware } from '../transcript'
21
23
 
22
24
  const logger = debug('agents:app')
23
25
 
@@ -50,10 +52,10 @@ export type ApplicationEventHandler<TState extends TurnState> = (context: TurnCo
50
52
  * - Extensible architecture with custom extensions
51
53
  * - Event handlers for before/after turn processing
52
54
  *
53
- * Example usage:
55
+ * @example
54
56
  * ```typescript
55
57
  * const app = new AgentApplication<MyState>({
56
- * storage: myStorage,
58
+ * storage: new MemoryStorage(),
57
59
  * adapter: myAdapter
58
60
  * });
59
61
  *
@@ -66,7 +68,7 @@ export type ApplicationEventHandler<TState extends TurnState> = (context: TurnCo
66
68
  */
67
69
  export class AgentApplication<TState extends TurnState> {
68
70
  protected readonly _options: AgentApplicationOptions<TState>
69
- protected readonly _routes: AppRoute<TState>[] = []
71
+ protected readonly _routes: RouteList<TState> = new RouteList<TState>()
70
72
  protected readonly _beforeTurn: ApplicationEventHandler<TState>[] = []
71
73
  protected readonly _afterTurn: ApplicationEventHandler<TState>[] = []
72
74
  private readonly _adapter?: BaseAdapter
@@ -91,13 +93,14 @@ export class AgentApplication<TState extends TurnState> {
91
93
  * - removeRecipientMention: true
92
94
  * - turnStateFactory: Creates a new TurnState instance
93
95
  *
94
- * Example usage:
96
+ * @example
95
97
  * ```typescript
96
98
  * const app = new AgentApplication({
97
- * storage: myStorage,
99
+ * storage: new MemoryStorage(),
98
100
  * adapter: myAdapter,
99
101
  * startTypingTimer: true,
100
- * authorization: { connectionName: 'oauth' }
102
+ * authorization: { connectionName: 'oauth' },
103
+ * transcriptLogger: myTranscriptLogger,
101
104
  * });
102
105
  * ```
103
106
  */
@@ -108,6 +111,7 @@ export class AgentApplication<TState extends TurnState> {
108
111
  startTypingTimer: options?.startTypingTimer !== undefined ? options.startTypingTimer : false,
109
112
  longRunningMessages: options?.longRunningMessages !== undefined ? options.longRunningMessages : false,
110
113
  removeRecipientMention: options?.removeRecipientMention !== undefined ? options.removeRecipientMention : true,
114
+ transcriptLogger: options?.transcriptLogger || undefined,
111
115
  }
112
116
 
113
117
  this._adaptiveCards = new AdaptiveCardsActions<TState>(this)
@@ -123,6 +127,14 @@ export class AgentApplication<TState extends TurnState> {
123
127
  if (this._options.longRunningMessages && !this._adapter && !this._options.agentAppId) {
124
128
  throw new Error('The Application.longRunningMessages property is unavailable because no adapter was configured in the app.')
125
129
  }
130
+
131
+ if (this._options.transcriptLogger) {
132
+ if (!this._options.adapter) {
133
+ throw new Error('The Application.transcriptLogger property is unavailable because no adapter was configured in the app.')
134
+ } else {
135
+ this._adapter?.use(new TranscriptLoggerMiddleware(this._options.transcriptLogger))
136
+ }
137
+ }
126
138
  logger.debug('AgentApplication created with options:', this._options)
127
139
  }
128
140
 
@@ -166,9 +178,9 @@ export class AgentApplication<TState extends TurnState> {
166
178
  * The adaptive cards actions handler provides functionality for handling
167
179
  * adaptive card interactions, such as submit actions and other card-based events.
168
180
  *
169
- * Example usage:
181
+ * @example
170
182
  * ```typescript
171
- * app.adaptiveCards.onSubmit('myCardId', async (context, state, data) => {
183
+ * app.adaptiveCards.actionSubmit('doStuff', async (context, state, data) => {
172
184
  * await context.sendActivity(`Received data: ${JSON.stringify(data)}`);
173
185
  * });
174
186
  * ```
@@ -187,7 +199,7 @@ export class AgentApplication<TState extends TurnState> {
187
199
  * This method allows you to handle any errors that occur during turn processing.
188
200
  * The handler will receive the turn context and the error that occurred.
189
201
  *
190
- * Example usage:
202
+ * @example
191
203
  * ```typescript
192
204
  * app.onError(async (context, error) => {
193
205
  * console.error(`An error occurred: ${error.message}`);
@@ -208,24 +220,29 @@ export class AgentApplication<TState extends TurnState> {
208
220
  * @param selector - The selector function that determines if a route should handle the current activity.
209
221
  * @param handler - The handler function that will be called if the selector returns true.
210
222
  * @param isInvokeRoute - Whether this route is for invoke activities. Defaults to false.
223
+ * @param rank - The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
211
224
  * @param authHandlers - Array of authentication handler names for this route. Defaults to empty array.
212
225
  * @returns The current instance of the application.
213
226
  *
214
227
  * @remarks
215
- * Routes are evaluated in the order they are added. The first route with a selector that returns true will be used.
228
+ * Routes are evaluated by rank order (if provided), otherwise, in the order they are added.
229
+ * Invoke-based activities receive special treatment and are matched separately as they typically
230
+ * have shorter execution timeouts.
216
231
  *
217
- * Example usage:
232
+ * @example
218
233
  * ```typescript
219
234
  * app.addRoute(
220
235
  * async (context) => context.activity.type === ActivityTypes.Message,
221
236
  * async (context, state) => {
222
237
  * await context.sendActivity('I received your message');
223
- * }
238
+ * },
239
+ * false, // isInvokeRoute
240
+ * RouteRank.First // rank
224
241
  * );
225
242
  * ```
226
243
  */
227
- public addRoute (selector: RouteSelector, handler: RouteHandler<TState>, isInvokeRoute: boolean = false, authHandlers: string[] = []): this {
228
- this._routes.push({ selector, handler, isInvokeRoute, authHandlers })
244
+ public addRoute (selector: RouteSelector, handler: RouteHandler<TState>, isInvokeRoute: boolean = false, rank: number = RouteRank.Unspecified, authHandlers: string[] = []): this {
245
+ this._routes.addRoute(selector, handler, isInvokeRoute, rank, authHandlers)
229
246
  return this
230
247
  }
231
248
 
@@ -235,13 +252,14 @@ export class AgentApplication<TState extends TurnState> {
235
252
  * @param type - The activity type(s) to handle. Can be a string, RegExp, RouteSelector, or array of these types.
236
253
  * @param handler - The handler function that will be called when the specified activity type is received.
237
254
  * @param authHandlers - Array of authentication handler names for this activity. Defaults to empty array.
255
+ * @param rank - The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
238
256
  * @returns The current instance of the application.
239
257
  *
240
258
  * @remarks
241
259
  * This method allows you to register handlers for specific activity types such as 'message', 'conversationUpdate', etc.
242
260
  * You can specify multiple activity types by passing an array.
243
261
  *
244
- * Example usage:
262
+ * @example
245
263
  * ```typescript
246
264
  * app.onActivity(ActivityTypes.Message, async (context, state) => {
247
265
  * await context.sendActivity('I received your message');
@@ -251,11 +269,12 @@ export class AgentApplication<TState extends TurnState> {
251
269
  public onActivity (
252
270
  type: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[],
253
271
  handler: (context: TurnContext, state: TState) => Promise<void>,
254
- authHandlers: string[] = []
272
+ authHandlers: string[] = [],
273
+ rank: RouteRank = RouteRank.Unspecified
255
274
  ): this {
256
275
  (Array.isArray(type) ? type : [type]).forEach((t) => {
257
276
  const selector = this.createActivitySelector(t)
258
- this.addRoute(selector, handler, false, authHandlers)
277
+ this.addRoute(selector, handler, false, rank, authHandlers)
259
278
  })
260
279
  return this
261
280
  }
@@ -266,13 +285,14 @@ export class AgentApplication<TState extends TurnState> {
266
285
  * @param event - The conversation update event to handle (e.g., 'membersAdded', 'membersRemoved').
267
286
  * @param handler - The handler function that will be called when the specified event occurs.
268
287
  * @param authHandlers - Array of authentication handler names for this event. Defaults to empty array.
288
+ * @param rank - The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
269
289
  * @returns The current instance of the application.
270
290
  * @throws Error if the handler is not a function.
271
291
  *
272
292
  * @remarks
273
293
  * Conversation update events occur when the state of a conversation changes, such as when members join or leave.
274
294
  *
275
- * Example usage:
295
+ * @example
276
296
  * ```typescript
277
297
  * app.onConversationUpdate('membersAdded', async (context, state) => {
278
298
  * const membersAdded = context.activity.membersAdded;
@@ -287,7 +307,8 @@ export class AgentApplication<TState extends TurnState> {
287
307
  public onConversationUpdate (
288
308
  event: ConversationUpdateEvents,
289
309
  handler: (context: TurnContext, state: TState) => Promise<void>,
290
- authHandlers: string[] = []
310
+ authHandlers: string[] = [],
311
+ rank: RouteRank = RouteRank.Unspecified
291
312
  ): this {
292
313
  if (typeof handler !== 'function') {
293
314
  throw new Error(
@@ -296,7 +317,7 @@ export class AgentApplication<TState extends TurnState> {
296
317
  }
297
318
 
298
319
  const selector = this.createConversationUpdateSelector(event)
299
- this.addRoute(selector, handler, false, authHandlers)
320
+ this.addRoute(selector, handler, false, rank, authHandlers)
300
321
  return this
301
322
  }
302
323
 
@@ -340,6 +361,7 @@ export class AgentApplication<TState extends TurnState> {
340
361
  * Can be a string, RegExp, RouteSelector, or array of these types.
341
362
  * @param handler - The handler function that will be called when a matching message is received.
342
363
  * @param authHandlers - Array of authentication handler names for this message handler. Defaults to empty array.
364
+ * @param rank - The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
343
365
  * @returns The current instance of the application.
344
366
  *
345
367
  * @remarks
@@ -348,13 +370,13 @@ export class AgentApplication<TState extends TurnState> {
348
370
  * If keyword is a RegExp, it tests the message text against the regular expression.
349
371
  * If keyword is a function, it calls the function with the context to determine if the message matches.
350
372
  *
351
- * Example usage:
373
+ * @example
352
374
  * ```typescript
353
375
  * app.onMessage('hello', async (context, state) => {
354
376
  * await context.sendActivity('Hello there!');
355
377
  * });
356
378
  *
357
- * app.onMessage(/help/, async (context, state) => {
379
+ * app.onMessage(/help/i, async (context, state) => {
358
380
  * await context.sendActivity('How can I help you?');
359
381
  * });
360
382
  * ```
@@ -362,11 +384,12 @@ export class AgentApplication<TState extends TurnState> {
362
384
  public onMessage (
363
385
  keyword: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[],
364
386
  handler: (context: TurnContext, state: TState) => Promise<void>,
365
- authHandlers: string[] = []
387
+ authHandlers: string[] = [],
388
+ rank: RouteRank = RouteRank.Unspecified
366
389
  ): this {
367
390
  (Array.isArray(keyword) ? keyword : [keyword]).forEach((k) => {
368
391
  const selector = this.createMessageSelector(k)
369
- this.addRoute(selector, handler, false, authHandlers)
392
+ this.addRoute(selector, handler, false, rank, authHandlers)
370
393
  })
371
394
  return this
372
395
  }
@@ -382,7 +405,7 @@ export class AgentApplication<TState extends TurnState> {
382
405
  * This method allows you to perform actions after a user has successfully authenticated.
383
406
  * The handler will receive the turn context and state.
384
407
  *
385
- * Example usage:
408
+ * @example
386
409
  * ```typescript
387
410
  * app.onSignInSuccess(async (context, state) => {
388
411
  * await context.sendActivity('You have successfully signed in!');
@@ -411,7 +434,7 @@ export class AgentApplication<TState extends TurnState> {
411
434
  * This method allows you to handle cases where a user fails to authenticate,
412
435
  * such as when they cancel the sign-in process or an error occurs.
413
436
  *
414
- * Example usage:
437
+ * @example
415
438
  * ```typescript
416
439
  * app.onSignInFailure(async (context, state) => {
417
440
  * await context.sendActivity('Sign-in failed. Please try again.');
@@ -433,13 +456,14 @@ export class AgentApplication<TState extends TurnState> {
433
456
  * Adds a handler for message reaction added events.
434
457
  *
435
458
  * @param handler - The handler function that will be called when a message reaction is added.
459
+ * @param rank - The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
436
460
  * @returns The current instance of the application.
437
461
  *
438
462
  * @remarks
439
463
  * This method registers a handler that will be invoked when a user adds a reaction to a message,
440
464
  * such as a like, heart, or other emoji reaction.
441
465
  *
442
- * Example usage:
466
+ * @example
443
467
  * ```typescript
444
468
  * app.onMessageReactionAdded(async (context, state) => {
445
469
  * const reactionsAdded = context.activity.reactionsAdded;
@@ -449,14 +473,16 @@ export class AgentApplication<TState extends TurnState> {
449
473
  * });
450
474
  * ```
451
475
  */
452
- public onMessageReactionAdded (handler: (context: TurnContext, state: TState) => Promise<void>): this {
476
+ public onMessageReactionAdded (
477
+ handler: (context: TurnContext, state: TState) => Promise<void>,
478
+ rank: RouteRank = RouteRank.Unspecified): this {
453
479
  const selector = async (context: TurnContext): Promise<boolean> => {
454
480
  return context.activity.type === ActivityTypes.MessageReaction &&
455
481
  Array.isArray(context.activity.reactionsAdded) &&
456
482
  context.activity.reactionsAdded.length > 0
457
483
  }
458
484
 
459
- this.addRoute(selector, handler)
485
+ this.addRoute(selector, handler, false, rank)
460
486
  return this
461
487
  }
462
488
 
@@ -464,13 +490,14 @@ export class AgentApplication<TState extends TurnState> {
464
490
  * Adds a handler for message reaction removed events.
465
491
  *
466
492
  * @param handler - The handler function that will be called when a message reaction is removed.
493
+ * @param rank - The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
467
494
  * @returns The current instance of the application.
468
495
  *
469
496
  * @remarks
470
497
  * This method registers a handler that will be invoked when a user removes a reaction from a message,
471
498
  * such as unliking or removing an emoji reaction.
472
499
  *
473
- * Example usage:
500
+ * @example
474
501
  * ```typescript
475
502
  * app.onMessageReactionRemoved(async (context, state) => {
476
503
  * const reactionsRemoved = context.activity.reactionsRemoved;
@@ -480,14 +507,16 @@ export class AgentApplication<TState extends TurnState> {
480
507
  * });
481
508
  * ```
482
509
  */
483
- public onMessageReactionRemoved (handler: (context: TurnContext, state: TState) => Promise<void>): this {
510
+ public onMessageReactionRemoved (
511
+ handler: (context: TurnContext, state: TState) => Promise<void>,
512
+ rank: RouteRank = RouteRank.Unspecified): this {
484
513
  const selector = async (context: TurnContext): Promise<boolean> => {
485
514
  return context.activity.type === ActivityTypes.MessageReaction &&
486
515
  Array.isArray(context.activity.reactionsRemoved) &&
487
516
  context.activity.reactionsRemoved.length > 0
488
517
  }
489
518
 
490
- this.addRoute(selector, handler)
519
+ this.addRoute(selector, handler, false, rank)
491
520
  return this
492
521
  }
493
522
 
@@ -502,7 +531,7 @@ export class AgentApplication<TState extends TurnState> {
502
531
  * It delegates the actual processing to the `runInternal` method, which handles
503
532
  * the core logic for routing and executing handlers.
504
533
  *
505
- * Example usage:
534
+ * @example
506
535
  * ```typescript
507
536
  * const app = new AgentApplication();
508
537
  * await app.run(turnContext);
@@ -534,7 +563,7 @@ export class AgentApplication<TState extends TurnState> {
534
563
  * 8. Executes after-turn event handlers
535
564
  * 9. Saves turn state
536
565
  *
537
- * Example usage:
566
+ * @example
538
567
  * ```typescript
539
568
  * const handled = await app.runInternal(turnContext);
540
569
  * if (!handled) {
@@ -648,7 +677,7 @@ export class AgentApplication<TState extends TurnState> {
648
677
  * @remarks
649
678
  * This method allows you to send messages proactively to a conversation, outside the normal turn flow.
650
679
  *
651
- * Example usage:
680
+ * @example
652
681
  * ```typescript
653
682
  * // With conversation reference
654
683
  * await app.sendProactiveActivity(conversationReference, 'Important notification!');
@@ -685,7 +714,7 @@ export class AgentApplication<TState extends TurnState> {
685
714
  * The typing indicator helps provide feedback to users that the agent is processing
686
715
  * their message, especially when responses might take time to generate.
687
716
  *
688
- * Example usage:
717
+ * @example
689
718
  * ```typescript
690
719
  * app.startTypingTimer(turnContext);
691
720
  * // Do some processing...
@@ -743,7 +772,7 @@ export class AgentApplication<TState extends TurnState> {
743
772
  * Extensions provide a way to add custom functionality to the application.
744
773
  * Each extension can only be registered once to prevent conflicts.
745
774
  *
746
- * Example usage:
775
+ * @example
747
776
  * ```typescript
748
777
  * const myExtension = new MyCustomExtension();
749
778
  * app.registerExtension(myExtension, (ext) => {
@@ -769,7 +798,7 @@ export class AgentApplication<TState extends TurnState> {
769
798
  * from being sent. It's typically called automatically when a message is sent, but
770
799
  * can also be called manually to stop the typing indicator.
771
800
  *
772
- * Example usage:
801
+ * @example
773
802
  * ```typescript
774
803
  * app.startTypingTimer(turnContext);
775
804
  * // Do some processing...
@@ -795,7 +824,7 @@ export class AgentApplication<TState extends TurnState> {
795
824
  * Handlers added for 'beforeTurn' are executed before routing logic.
796
825
  * Handlers added for 'afterTurn' are executed after routing logic.
797
826
  *
798
- * Example usage:
827
+ * @example
799
828
  * ```typescript
800
829
  * app.onTurn('beforeTurn', async (context, state) => {
801
830
  * console.log('Processing before turn');
@@ -5,66 +5,128 @@
5
5
 
6
6
  import { CloudAdapter } from '../cloudAdapter'
7
7
  import { Storage } from '../storage'
8
+ import { TranscriptLogger } from '../transcript'
8
9
  import { AdaptiveCardsOptions } from './adaptiveCards'
9
10
  import { InputFileDownloader } from './inputFileDownloader'
10
11
  import { AuthorizationHandlers } from './authorization'
11
12
  import { TurnState } from './turnState'
12
13
 
14
+ /**
15
+ * Configuration options for creating and initializing an Agent Application.
16
+ * This interface defines all the configurable aspects of an agent's behavior,
17
+ * including adapter settings, storage, authorization, and various feature flags.
18
+ *
19
+ * @template TState - The type of turn state that extends TurnState, allowing for
20
+ * custom state management specific to your agent's needs.
21
+ */
13
22
  export interface AgentApplicationOptions<TState extends TurnState> {
14
23
  /**
15
- * The adapter used for handling bot interactions.
24
+ * The adapter used for handling bot interactions with various messaging platforms.
25
+ * This adapter manages the communication layer between your agent and the Bot Framework.
26
+ * If not provided, a default CloudAdapter will be created automatically.
27
+ *
28
+ * @default undefined (auto-created)
16
29
  */
17
30
  adapter?: CloudAdapter;
18
31
 
19
32
  /**
20
- * The application ID of the agent.
33
+ * The unique application ID of the agent as registered in the Bot Framework.
34
+ * This ID is used to identify your bot in the Azure Bot Service and should match
35
+ * the App ID from your bot registration in the Azure portal.
36
+ *
37
+ * @example "12345678-1234-1234-1234-123456789012"
21
38
  */
22
39
  agentAppId?: string;
23
40
 
24
41
  /**
25
- * The storage mechanism for persisting state.
42
+ * The storage mechanism for persisting conversation and user state across turns.
43
+ * This can be any implementation of the Storage interface, such as memory storage
44
+ * for development or blob storage for production scenarios.
45
+ *
46
+ * @default undefined (no persistence)
26
47
  */
27
48
  storage?: Storage;
28
49
 
29
50
  /**
30
- * Whether to start a typing timer for the bot.
51
+ * Whether to start a typing indicator timer when the bot begins processing a message.
52
+ * When enabled, users will see a typing indicator while the agent is thinking or processing,
53
+ * providing better user experience feedback. The typing indicator will automatically stop
54
+ * when the agent sends a response.
55
+ *
56
+ * @default false
31
57
  */
32
58
  startTypingTimer: boolean;
33
59
 
34
60
  /**
35
- * Whether to enable long-running messages.
61
+ * Whether to enable support for long-running message processing operations.
62
+ * When enabled, the agent can handle operations that take longer than the typical
63
+ * HTTP timeout period without the connection being terminated. This is useful for
64
+ * complex AI operations, file processing, or external API calls that may take time.
65
+ *
66
+ * @default false
36
67
  */
37
68
  longRunningMessages: boolean;
38
69
 
39
70
  /**
40
- * A factory function to create the turn state.
71
+ * A factory function that creates a new instance of the turn state for each conversation turn.
72
+ * This function is called at the beginning of each turn to initialize the state object
73
+ * that will be used throughout the turn's processing lifecycle.
74
+ *
75
+ * @returns A new instance of TState for the current turn
76
+ * @example () => new MyCustomTurnState()
41
77
  */
42
78
  turnStateFactory: () => TState;
43
79
 
44
80
  /**
45
- * An array of file downloaders for handling input files.
81
+ * An array of file downloaders for handling different types of input files from users.
82
+ * Each downloader can handle specific file types or sources (e.g., SharePoint, OneDrive,
83
+ * direct uploads). The agent will use these downloaders to process file attachments
84
+ * sent by users during conversations.
85
+ *
86
+ * @default undefined (no file downloading capability)
46
87
  */
47
88
  fileDownloaders?: InputFileDownloader<TState>[];
48
89
 
49
90
  /**
50
- * Handlers for managing authorization.
91
+ * Handlers for managing user authentication and authorization within the agent.
92
+ * This includes OAuth flows, token management, and permission validation.
93
+ * Use this to implement secure access to protected resources or user-specific data.
94
+ *
95
+ * @default undefined (no authorization required)
51
96
  */
52
97
  authorization?: AuthorizationHandlers;
53
98
 
54
99
  /**
55
- * Options for AdaptiveCard actions.
100
+ * Configuration options for handling Adaptive Card actions and interactions.
101
+ * This controls how the agent processes card submissions, button clicks, and other
102
+ * interactive elements within Adaptive Cards sent to users.
103
+ *
104
+ * @default undefined (default Adaptive Card handling)
56
105
  */
57
106
  adaptiveCardsOptions?: AdaptiveCardsOptions;
58
107
 
59
108
  /**
60
- * Optional. If true, the agent will automatically remove mentions of the bot's name from incoming
61
- * messages. Defaults to true.
109
+ * Whether to automatically remove mentions of the bot's name from incoming messages.
110
+ * When enabled, if a user mentions the bot by name (e.g., "@BotName hello"), the mention
111
+ * will be stripped from the message text before processing, leaving just "hello".
112
+ * This helps create cleaner input for natural language processing.
113
+ *
114
+ * @default true
62
115
  */
63
116
  removeRecipientMention?: boolean;
64
117
 
65
118
  /**
66
- * Optional. If true, the agent will automatically normalize mentions in incoming messages. Defaults to
67
- * true.
119
+ * Whether to automatically normalize mentions in incoming messages.
120
+ * When enabled, user mentions and other entity mentions in messages will be
121
+ * standardized to a consistent format, making them easier to process and understand.
122
+ * This includes formatting @mentions and channel references consistently.
123
+ *
124
+ * @default true
68
125
  */
69
126
  normalizeMentions?: boolean
127
+
128
+ /**
129
+ * Optional. The transcript logger to use for logging conversations. If not provided, no logging will occur.
130
+ */
131
+ transcriptLogger?: TranscriptLogger
70
132
  }
@@ -7,26 +7,81 @@ import { RouteHandler } from './routeHandler'
7
7
  import { RouteSelector } from './routeSelector'
8
8
  import { TurnState } from './turnState'
9
9
 
10
+ /**
11
+ * Represents a route configuration for handling bot activities within an application.
12
+ *
13
+ * @remarks
14
+ * An AppRoute defines how incoming activities are matched and processed by combining
15
+ * a selector function that determines when the route should be activated with a handler
16
+ * function that processes the matched activities.
17
+ *
18
+ * @template TState - The type of turn state that extends TurnState, allowing for
19
+ * type-safe access to custom state properties within route handlers
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const echoRoute: AppRoute<MyTurnState> = {
24
+ * selector: (activity) => activity.type === 'message',
25
+ * handler: async (context, state) => {
26
+ * await context.sendActivity(`You said: ${context.activity.text}`);
27
+ * }
28
+ * };
29
+ * ```
30
+ */
10
31
  export interface AppRoute<TState extends TurnState> {
11
32
  /**
12
33
  * The selector function used to determine if this route should handle the current activity.
34
+ *
35
+ * @remarks
36
+ * This function is called for each incoming activity to determine if the route's handler
37
+ * should be invoked. It receives the activity and returns a boolean indicating whether
38
+ * this route should process the activity.
13
39
  */
14
40
  selector: RouteSelector;
15
41
 
16
42
  /**
17
43
  * The handler function that processes the activity if the selector matches.
44
+ *
45
+ * @remarks
46
+ * This function contains the core logic for handling the matched activity. It receives
47
+ * the turn context and state, allowing it to process the activity and respond appropriately.
48
+ * The handler can be asynchronous and should return a promise that resolves when processing
49
+ * is complete.
18
50
  */
19
51
  handler: RouteHandler<TState>;
20
52
 
21
53
  /**
22
54
  * Indicates whether this route is an invoke route.
23
- * Invoke routes are used for specific types of activities, such as messaging extensions.
55
+ *
56
+ * @remarks
57
+ * Invoke routes are used for specific types of activities, such as messaging extensions,
58
+ * adaptive card actions, or other invoke-based interactions. When set to true, this route
59
+ * will be processed differently than regular message routes, typically with special
60
+ * handling for invoke responses.
61
+ *
62
+ * @default false
24
63
  */
25
64
  isInvokeRoute?: boolean;
26
65
 
66
+ /**
67
+ * Optional rank of the route, used to determine the order in which routes are evaluated.
68
+ * 0 - number.MAX_VALUE. Ranks of the same value are evaluated in order of addition.
69
+ */
70
+ rank?: number;
71
+
27
72
  /**
28
73
  * Optional list of authorization handlers that this route requires.
29
- * If provided, the route will check for these handlers before processing.
74
+ *
75
+ * @remarks
76
+ * If provided, the route will check for these authorization handlers before processing
77
+ * the activity. Each string in the array should correspond to a registered authorization
78
+ * handler name. All specified handlers must pass authorization checks before the route
79
+ * handler is invoked.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * authHandlers: ['oauth', 'admin-only']
84
+ * ```
30
85
  */
31
86
  authHandlers?: string[]
32
87
  }
@@ -9,7 +9,7 @@ import { TurnState } from './turnState'
9
9
  import { TurnContext } from '../turnContext'
10
10
  import { Attachment } from '@microsoft/agents-activity'
11
11
  import { AuthProvider } from '../auth/authProvider'
12
- import { debug } from '../logger'
12
+ import { debug } from '@microsoft/agents-activity/src/logger'
13
13
  import { loadAuthConfigFromEnv, MsalTokenProvider } from '../auth'
14
14
 
15
15
  const logger = debug('agents:attachmentDownloader')
@@ -17,6 +17,7 @@ const logger = debug('agents:attachmentDownloader')
17
17
  /**
18
18
  * A utility class for downloading input files from activity attachments.
19
19
  *
20
+ * @remarks
20
21
  * This class provides functionality to filter and download attachments from a turn context,
21
22
  * supporting various content types and handling authentication for secure URLs.
22
23
  *
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { TurnContext } from '../turnContext'
7
- import { debug } from '../logger'
7
+ import { debug } from '@microsoft/agents-activity/src/logger'
8
8
  import { TurnState } from './turnState'
9
9
  import { Storage } from '../storage'
10
10
  import { OAuthFlow, TokenResponse } from '../oauth'
@@ -15,7 +15,7 @@ import { Activity } from '@microsoft/agents-activity'
15
15
  const logger = debug('agents:authorization')
16
16
 
17
17
  /**
18
- * Interface representing the state of a sign-in process.
18
+ * Represents the state of a sign-in process.
19
19
  * @interface SignInState
20
20
  */
21
21
  export interface SignInState {