@microsoft/agents-hosting 0.2.9-g361635b71c → 0.2.14

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 (70) hide show
  1. package/dist/src/activityHandler.d.ts +304 -46
  2. package/dist/src/activityHandler.js +298 -45
  3. package/dist/src/activityHandler.js.map +1 -1
  4. package/dist/src/agent-client/agentClient.d.ts +50 -0
  5. package/dist/src/agent-client/agentClient.js +28 -0
  6. package/dist/src/agent-client/agentClient.js.map +1 -1
  7. package/dist/src/app/agentApplication.d.ts +256 -3
  8. package/dist/src/app/agentApplication.js +256 -0
  9. package/dist/src/app/agentApplication.js.map +1 -1
  10. package/dist/src/app/agentApplicationBuilder.d.ts +32 -0
  11. package/dist/src/app/agentApplicationBuilder.js +32 -0
  12. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  13. package/dist/src/app/appMemory.d.ts +34 -0
  14. package/dist/src/app/{memory.js → appMemory.js} +1 -1
  15. package/dist/src/app/appMemory.js.map +1 -0
  16. package/dist/src/app/index.d.ts +3 -0
  17. package/dist/src/app/index.js +3 -0
  18. package/dist/src/app/index.js.map +1 -1
  19. package/dist/src/app/turnEvents.d.ts +6 -0
  20. package/dist/src/app/turnState.d.ts +2 -2
  21. package/dist/src/app/turnStateEntry.d.ts +32 -0
  22. package/dist/src/app/turnStateEntry.js +32 -0
  23. package/dist/src/app/turnStateEntry.js.map +1 -1
  24. package/dist/src/cards/index.d.ts +1 -0
  25. package/dist/src/cards/index.js +1 -0
  26. package/dist/src/cards/index.js.map +1 -1
  27. package/dist/src/cloudAdapter.d.ts +25 -3
  28. package/dist/src/cloudAdapter.js +25 -3
  29. package/dist/src/cloudAdapter.js.map +1 -1
  30. package/dist/src/getProductInfo.d.ts +6 -0
  31. package/dist/src/getProductInfo.js +6 -0
  32. package/dist/src/getProductInfo.js.map +1 -1
  33. package/dist/src/logger.d.ts +34 -2
  34. package/dist/src/logger.js +35 -0
  35. package/dist/src/logger.js.map +1 -1
  36. package/dist/src/state/agentState.d.ts +79 -27
  37. package/dist/src/state/agentState.js +58 -27
  38. package/dist/src/state/agentState.js.map +1 -1
  39. package/dist/src/state/agentStatePropertyAccesor.d.ts +67 -11
  40. package/dist/src/state/agentStatePropertyAccesor.js +58 -11
  41. package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
  42. package/dist/src/storage/memoryStorage.d.ts +48 -14
  43. package/dist/src/storage/memoryStorage.js +48 -14
  44. package/dist/src/storage/memoryStorage.js.map +1 -1
  45. package/dist/src/storage/storage.d.ts +43 -13
  46. package/dist/src/turnContext.d.ts +142 -56
  47. package/dist/src/turnContext.js +123 -53
  48. package/dist/src/turnContext.js.map +1 -1
  49. package/package.json +5 -5
  50. package/src/activityHandler.ts +304 -46
  51. package/src/agent-client/agentClient.ts +55 -5
  52. package/src/app/agentApplication.ts +259 -2
  53. package/src/app/agentApplicationBuilder.ts +32 -0
  54. package/src/app/appMemory.ts +38 -0
  55. package/src/app/index.ts +3 -0
  56. package/src/app/turnEvents.ts +6 -0
  57. package/src/app/turnState.ts +2 -2
  58. package/src/app/turnStateEntry.ts +32 -0
  59. package/src/cards/index.ts +1 -0
  60. package/src/cloudAdapter.ts +28 -3
  61. package/src/getProductInfo.ts +7 -0
  62. package/src/logger.ts +34 -1
  63. package/src/state/agentState.ts +81 -29
  64. package/src/state/agentStatePropertyAccesor.ts +67 -11
  65. package/src/storage/memoryStorage.ts +48 -14
  66. package/src/storage/storage.ts +51 -18
  67. package/src/turnContext.ts +142 -56
  68. package/dist/src/app/memory.d.ts +0 -10
  69. package/dist/src/app/memory.js.map +0 -1
  70. package/src/app/memory.ts +0 -14
@@ -17,106 +17,219 @@ import { tokenResponseEventName } from './tokenResponseEventName'
17
17
  /** Symbol key for invoke response */
18
18
  export const INVOKE_RESPONSE_KEY = Symbol('invokeResponse')
19
19
 
20
- /** Type definition for agent handler function */
20
+ /**
21
+ * Type definition for agent handler function
22
+ * @param context - The turn context for the current turn of conversation
23
+ * @param next - The function to call to continue to the next middleware or handler
24
+ * @returns A promise representing the asynchronous operation
25
+ */
21
26
  export type AgentHandler = (context: TurnContext, next: () => Promise<void>) => Promise<any>
22
27
 
23
28
  const logger = debug('agents:activity-handler')
24
29
 
25
- /** * Handles various activity types and dispatches them to the appropriate handlers. */
30
+ /**
31
+ * Handles incoming activities from channels and dispatches them to the appropriate handlers.
32
+ *
33
+ * The ActivityHandler provides a foundation for handling different types of activities
34
+ * in an agent application. It processes various activity types such as messages, conversation updates,
35
+ * message reactions, etc., and routes them to the appropriate handler methods.
36
+ *
37
+ * Developers can extend this class to implement custom handlers for specific activity types
38
+ * or override existing ones to customize the behavior.
39
+ */
26
40
  export class ActivityHandler {
41
+ /**
42
+ * Collection of handlers registered for different activity types
43
+ * @protected
44
+ */
27
45
  protected readonly handlers: { [type: string]: AgentHandler[] } = {}
28
46
 
29
- /** * Registers a handler for the Turn activity type. */
47
+ /**
48
+ * Registers a handler for the Turn activity type.
49
+ * This is called for all activities regardless of type.
50
+ * @param handler - The handler to register
51
+ * @returns The current instance for method chaining
52
+ */
30
53
  onTurn (handler: AgentHandler): this {
31
54
  return this.on('Turn', handler)
32
55
  }
33
56
 
34
- /** * Registers a handler for the MembersAdded activity type. */
57
+ /**
58
+ * Registers a handler for the MembersAdded activity type.
59
+ * This is called when new members are added to the conversation.
60
+ * @param handler - The handler to register
61
+ * @returns The current instance for method chaining
62
+ */
35
63
  onMembersAdded (handler: AgentHandler): this {
36
64
  return this.on('MembersAdded', handler)
37
65
  }
38
66
 
39
- /** * Registers a handler for the MembersRemoved activity type. */
67
+ /**
68
+ * Registers a handler for the MembersRemoved activity type.
69
+ * This is called when members are removed from the conversation.
70
+ * @param handler - The handler to register
71
+ * @returns The current instance for method chaining
72
+ */
40
73
  onMembersRemoved (handler: AgentHandler): this {
41
74
  return this.on('MembersRemoved', handler)
42
75
  }
43
76
 
44
- /** * Registers a handler for the Message activity type. */
77
+ /**
78
+ * Registers a handler for the Message activity type.
79
+ * This is called when a message is received from the user.
80
+ * @param handler - The handler to register
81
+ * @returns The current instance for method chaining
82
+ */
45
83
  onMessage (handler: AgentHandler): this {
46
84
  return this.on('Message', handler)
47
85
  }
48
86
 
49
- /** * Registers a handler for the MessageUpdate activity type. */
87
+ /**
88
+ * Registers a handler for the MessageUpdate activity type.
89
+ * This is called when a message is updated.
90
+ * @param handler - The handler to register
91
+ * @returns The current instance for method chaining
92
+ */
50
93
  onMessageUpdate (handler: AgentHandler): this {
51
94
  return this.on('MessageUpdate', handler)
52
95
  }
53
96
 
54
- /** * Registers a handler for the MessageDelete activity type. */
97
+ /**
98
+ * Registers a handler for the MessageDelete activity type.
99
+ * This is called when a message is deleted.
100
+ * @param handler - The handler to register
101
+ * @returns The current instance for method chaining
102
+ */
55
103
  onMessageDelete (handler: AgentHandler): this {
56
104
  return this.on('MessageDelete', handler)
57
105
  }
58
106
 
59
- /** * Registers a handler for the ConversationUpdate activity type. */
107
+ /**
108
+ * Registers a handler for the ConversationUpdate activity type.
109
+ * This is called when the conversation is updated, such as when members are added or removed.
110
+ * @param handler - The handler to register
111
+ * @returns The current instance for method chaining
112
+ */
60
113
  onConversationUpdate (handler: AgentHandler): this {
61
114
  return this.on('ConversationUpdate', handler)
62
115
  }
63
116
 
64
- /** * Registers a handler for the MessageReaction activity type. */
117
+ /**
118
+ * Registers a handler for the MessageReaction activity type.
119
+ * This is called when reactions are added or removed from messages.
120
+ * @param handler - The handler to register
121
+ * @returns The current instance for method chaining
122
+ */
65
123
  onMessageReaction (handler: AgentHandler): this {
66
124
  return this.on('MessageReaction', handler)
67
125
  }
68
126
 
69
- /** * Registers a handler for the ReactionsAdded activity type. */
127
+ /**
128
+ * Registers a handler for the ReactionsAdded activity type.
129
+ * This is called when reactions are added to messages.
130
+ * @param handler - The handler to register
131
+ * @returns The current instance for method chaining
132
+ */
70
133
  onReactionsAdded (handler: AgentHandler): this {
71
134
  return this.on('ReactionsAdded', handler)
72
135
  }
73
136
 
74
- /** * Registers a handler for the ReactionsRemoved activity type. */
137
+ /**
138
+ * Registers a handler for the ReactionsRemoved activity type.
139
+ * This is called when reactions are removed from messages.
140
+ * @param handler - The handler to register
141
+ * @returns The current instance for method chaining
142
+ */
75
143
  onReactionsRemoved (handler: AgentHandler): this {
76
144
  return this.on('ReactionsRemoved', handler)
77
145
  }
78
146
 
79
- /** * Registers a handler for the Typing activity type. */
147
+ /**
148
+ * Registers a handler for the Typing activity type.
149
+ * This is called when a typing indicator is received.
150
+ * @param handler - The handler to register
151
+ * @returns The current instance for method chaining
152
+ */
80
153
  onTyping (handler: AgentHandler): this {
81
154
  return this.on('Typing', handler)
82
155
  }
83
156
 
84
- /** * Registers a handler for the InstallationUpdate activity type. */
157
+ /**
158
+ * Registers a handler for the InstallationUpdate activity type.
159
+ * This is called when an agent is installed or uninstalled.
160
+ * @param handler - The handler to register
161
+ * @returns The current instance for method chaining
162
+ */
85
163
  onInstallationUpdate (handler: AgentHandler): this {
86
164
  return this.on('InstallationUpdate', handler)
87
165
  }
88
166
 
89
- /** * Registers a handler for the InstallationUpdateAdd activity type. */
167
+ /**
168
+ * Registers a handler for the InstallationUpdateAdd activity type.
169
+ * This is called when an agent is installed or upgraded.
170
+ * @param handler - The handler to register
171
+ * @returns The current instance for method chaining
172
+ */
90
173
  onInstallationUpdateAdd (handler: AgentHandler): this {
91
174
  return this.on('InstallationUpdateAdd', handler)
92
175
  }
93
176
 
94
- /** * Registers a handler for the InstallationUpdateRemove activity type. */
177
+ /**
178
+ * Registers a handler for the InstallationUpdateRemove activity type.
179
+ * This is called when an agent is uninstalled or downgraded.
180
+ * @param handler - The handler to register
181
+ * @returns The current instance for method chaining
182
+ */
95
183
  onInstallationUpdateRemove (handler: AgentHandler): this {
96
184
  return this.on('InstallationUpdateRemove', handler)
97
185
  }
98
186
 
99
- /** * Registers a handler for the EndOfConversation activity type. */
187
+ /**
188
+ * Registers a handler for the EndOfConversation activity type.
189
+ * This is called when the conversation ends.
190
+ * @param handler - The handler to register
191
+ * @returns The current instance for method chaining
192
+ */
100
193
  onEndOfConversation (handler: AgentHandler): this {
101
194
  return this.on('EndOfConversation', handler)
102
195
  }
103
196
 
104
- /** * Registers a handler for the SignInInvoke activity type. */
197
+ /**
198
+ * Registers a handler for the SignInInvoke activity type.
199
+ * This is called when a sign-in is requested.
200
+ * @param handler - The handler to register
201
+ * @returns The current instance for method chaining
202
+ */
105
203
  onSignInInvoke (handler: AgentHandler): this {
106
204
  return this.on('SignInInvoke', handler)
107
205
  }
108
206
 
109
- /** * Registers a handler for unrecognized activity types. */
207
+ /**
208
+ * Registers a handler for unrecognized activity types.
209
+ * This is called when an activity type is not recognized.
210
+ * @param handler - The handler to register
211
+ * @returns The current instance for method chaining
212
+ */
110
213
  onUnrecognizedActivityType (handler: AgentHandler): this {
111
214
  return this.on('UnrecognizedActivityType', handler)
112
215
  }
113
216
 
114
- /** * Registers an activity event handler for the _dialog_ event, emitted as the last event for an incoming activity. */
217
+ /**
218
+ * Registers an activity event handler for the _dialog_ event, emitted as the last event for an incoming activity.
219
+ * This handler is called after all other handlers have been processed.
220
+ * @param handler - The handler to register
221
+ * @returns The current instance for method chaining
222
+ */
115
223
  onDialog (handler: AgentHandler): this {
116
224
  return this.on('Default', handler)
117
225
  }
118
226
 
119
- /** * Runs the activity handler pipeline. */
227
+ /**
228
+ * Runs the activity handler pipeline.
229
+ * This method is called to process an incoming activity through the registered handlers.
230
+ * @param context - The turn context for the current turn of conversation
231
+ * @throws Error if context is missing, activity is missing, or activity type is missing
232
+ */
120
233
  async run (context: TurnContext): Promise<void> {
121
234
  if (!context) throw new Error('Missing TurnContext parameter')
122
235
  if (!context.activity) throw new Error('TurnContext does not include an activity')
@@ -125,7 +238,12 @@ export class ActivityHandler {
125
238
  await this.onTurnActivity(context)
126
239
  }
127
240
 
128
- /** * Handles the Turn activity. */
241
+ /**
242
+ * Handles the Turn activity.
243
+ * This method is called for every activity type and dispatches to the appropriate handler.
244
+ * @param context - The turn context for the current turn of conversation
245
+ * @protected
246
+ */
129
247
  protected async onTurnActivity (context: TurnContext): Promise<void> {
130
248
  switch (context.activity.type) {
131
249
  case ActivityTypes.Message:
@@ -167,38 +285,69 @@ export class ActivityHandler {
167
285
  }
168
286
  }
169
287
 
170
- /** * Handles the Message activity. */
288
+ /**
289
+ * Handles the Message activity.
290
+ * This method processes incoming message activities.
291
+ * @param context - The turn context for the current turn of conversation
292
+ * @protected
293
+ */
171
294
  protected async onMessageActivity (context: TurnContext): Promise<void> {
172
295
  await this.handle(context, 'Message', this.defaultNextEvent(context))
173
296
  }
174
297
 
175
- /** * Handles the MessageUpdate activity. */
298
+ /**
299
+ * Handles the MessageUpdate activity.
300
+ * This method processes message update activities.
301
+ * @param context - The turn context for the current turn of conversation
302
+ * @protected
303
+ */
176
304
  protected async onMessageUpdateActivity (context: TurnContext): Promise<void> {
177
305
  await this.handle(context, 'MessageUpdate', async () => {
178
306
  await this.dispatchMessageUpdateActivity(context)
179
307
  })
180
308
  }
181
309
 
182
- /** * Handles the MessageDelete activity. */
310
+ /**
311
+ * Handles the MessageDelete activity.
312
+ * This method processes message deletion activities.
313
+ * @param context - The turn context for the current turn of conversation
314
+ * @protected
315
+ */
183
316
  protected async onMessageDeleteActivity (context: TurnContext): Promise<void> {
184
317
  await this.handle(context, 'MessageDelete', async () => {
185
318
  await this.dispatchMessageDeleteActivity(context)
186
319
  })
187
320
  }
188
321
 
189
- /** * Handles the ConversationUpdate activity. */
322
+ /**
323
+ * Handles the ConversationUpdate activity.
324
+ * This method processes conversation update activities.
325
+ * @param context - The turn context for the current turn of conversation
326
+ * @protected
327
+ */
190
328
  protected async onConversationUpdateActivity (context: TurnContext): Promise<void> {
191
329
  await this.handle(context, 'ConversationUpdate', async () => {
192
330
  await this.dispatchConversationUpdateActivity(context)
193
331
  })
194
332
  }
195
333
 
196
- /** * Handles the SignInInvoke activity. */
334
+ /**
335
+ * Handles the SignInInvoke activity.
336
+ * This method processes sign-in invoke activities.
337
+ * @param context - The turn context for the current turn of conversation
338
+ * @protected
339
+ */
197
340
  protected async onSigninInvokeActivity (context: TurnContext): Promise<void> {
198
341
  await this.handle(context, 'SignInInvoke', this.defaultNextEvent(context))
199
342
  }
200
343
 
201
- /** * Handles the Invoke activity. */
344
+ /**
345
+ * Handles the Invoke activity.
346
+ * This method processes various invoke activities based on their name.
347
+ * @param context - The turn context for the current turn of conversation
348
+ * @returns An invoke response object with status and body
349
+ * @protected
350
+ */
202
351
  protected async onInvokeActivity (context: TurnContext): Promise<InvokeResponse> {
203
352
  try {
204
353
  switch (context.activity.name) {
@@ -233,7 +382,14 @@ export class ActivityHandler {
233
382
  }
234
383
  }
235
384
 
236
- /** * Handles the AdaptiveCardInvoke activity. */
385
+ /**
386
+ * Handles the AdaptiveCardInvoke activity.
387
+ * This method processes adaptive card invoke activities.
388
+ * @param _context - The turn context for the current turn of conversation
389
+ * @param _invokeValue - The adaptive card invoke value
390
+ * @returns A promise that resolves to an adaptive card invoke response
391
+ * @protected
392
+ */
237
393
  protected async onAdaptiveCardInvoke (
238
394
  _context: TurnContext,
239
395
  _invokeValue: AdaptiveCardInvokeValue
@@ -241,12 +397,25 @@ export class ActivityHandler {
241
397
  return await Promise.reject(new InvokeException(StatusCodes.NOT_IMPLEMENTED))
242
398
  }
243
399
 
244
- /** * Handles the SearchInvoke activity. */
400
+ /**
401
+ * Handles the SearchInvoke activity.
402
+ * This method processes search invoke activities.
403
+ * @param _context - The turn context for the current turn of conversation
404
+ * @param _invokeValue - The search invoke value
405
+ * @returns A promise that resolves to a search invoke response
406
+ * @protected
407
+ */
245
408
  protected async onSearchInvoke (_context: TurnContext, _invokeValue: SearchInvokeValue): Promise<SearchInvokeResponse> {
246
409
  return await Promise.reject(new InvokeException(StatusCodes.NOT_IMPLEMENTED))
247
410
  }
248
411
 
249
- /** * Retrieves the SearchInvoke value from the activity. */
412
+ /**
413
+ * Retrieves the SearchInvoke value from the activity.
414
+ * This method extracts and validates the search invoke value from an activity.
415
+ * @param activity - The activity to extract the search invoke value from
416
+ * @returns The validated search invoke value
417
+ * @private
418
+ */
250
419
  private getSearchInvokeValue (activity: Activity): SearchInvokeValue {
251
420
  const value = activity.value as SearchInvokeValue
252
421
  if (!value) {
@@ -280,7 +449,13 @@ export class ActivityHandler {
280
449
  return value
281
450
  }
282
451
 
283
- /** * Retrieves the AdaptiveCardInvoke value from the activity. */
452
+ /**
453
+ * Retrieves the AdaptiveCardInvoke value from the activity.
454
+ * This method extracts and validates the adaptive card invoke value from an activity.
455
+ * @param activity - The activity to extract the adaptive card invoke value from
456
+ * @returns The validated adaptive card invoke value
457
+ * @private
458
+ */
284
459
  private getAdaptiveCardInvokeValue (activity: Activity): AdaptiveCardInvokeValue {
285
460
  const value = activity.value as AdaptiveCardInvokeValue
286
461
  if (!value) {
@@ -318,7 +493,15 @@ export class ActivityHandler {
318
493
  }
319
494
  }
320
495
 
321
- /** * Creates an error response for AdaptiveCardInvoke. */
496
+ /**
497
+ * Creates an error response for AdaptiveCardInvoke.
498
+ * This method creates an error response for adaptive card invoke activities.
499
+ * @param statusCode - The HTTP status code for the response
500
+ * @param code - The error code
501
+ * @param message - The error message
502
+ * @returns An adaptive card invoke error response
503
+ * @private
504
+ */
322
505
  private createAdaptiveCardInvokeErrorResponse (
323
506
  statusCode: StatusCodes,
324
507
  code: string,
@@ -331,24 +514,44 @@ export class ActivityHandler {
331
514
  }
332
515
  }
333
516
 
334
- /** * Handles the MessageReaction activity. */
517
+ /**
518
+ * Handles the MessageReaction activity.
519
+ * This method processes message reaction activities.
520
+ * @param context - The turn context for the current turn of conversation
521
+ * @protected
522
+ */
335
523
  protected async onMessageReactionActivity (context: TurnContext): Promise<void> {
336
524
  await this.handle(context, 'MessageReaction', async () => {
337
525
  await this.dispatchMessageReactionActivity(context)
338
526
  })
339
527
  }
340
528
 
341
- /** * Handles the EndOfConversation activity. */
529
+ /**
530
+ * Handles the EndOfConversation activity.
531
+ * This method processes end of conversation activities.
532
+ * @param context - The turn context for the current turn of conversation
533
+ * @protected
534
+ */
342
535
  protected async onEndOfConversationActivity (context: TurnContext): Promise<void> {
343
536
  await this.handle(context, 'EndOfConversation', this.defaultNextEvent(context))
344
537
  }
345
538
 
346
- /** * Handles the Typing activity. */
539
+ /**
540
+ * Handles the Typing activity.
541
+ * This method processes typing indicator activities.
542
+ * @param context - The turn context for the current turn of conversation
543
+ * @protected
544
+ */
347
545
  protected async onTypingActivity (context: TurnContext): Promise<void> {
348
546
  await this.handle(context, 'Typing', this.defaultNextEvent(context))
349
547
  }
350
548
 
351
- /** * Handles the InstallationUpdate activity. */
549
+ /**
550
+ * Handles the InstallationUpdate activity.
551
+ * This method processes installation update activities.
552
+ * @param context - The turn context for the current turn of conversation
553
+ * @protected
554
+ */
352
555
  protected async onInstallationUpdateActivity (context: TurnContext): Promise<void> {
353
556
  switch (context.activity.action) {
354
557
  case 'add':
@@ -361,12 +564,22 @@ export class ActivityHandler {
361
564
  }
362
565
  }
363
566
 
364
- /** * Handles unrecognized activity types. */
567
+ /**
568
+ * Handles unrecognized activity types.
569
+ * This method processes activities with unrecognized types.
570
+ * @param context - The turn context for the current turn of conversation
571
+ * @protected
572
+ */
365
573
  protected async onUnrecognizedActivity (context: TurnContext): Promise<void> {
366
574
  await this.handle(context, 'UnrecognizedActivityType', this.defaultNextEvent(context))
367
575
  }
368
576
 
369
- /** * Dispatches the ConversationUpdate activity. */
577
+ /**
578
+ * Dispatches the ConversationUpdate activity.
579
+ * This method dispatches conversation update activities to the appropriate handlers.
580
+ * @param context - The turn context for the current turn of conversation
581
+ * @protected
582
+ */
370
583
  protected async dispatchConversationUpdateActivity (context: TurnContext): Promise<void> {
371
584
  if ((context.activity.membersAdded != null) && context.activity.membersAdded.length > 0) {
372
585
  await this.handle(context, 'MembersAdded', this.defaultNextEvent(context))
@@ -377,7 +590,12 @@ export class ActivityHandler {
377
590
  }
378
591
  }
379
592
 
380
- /** * Dispatches the MessageReaction activity. */
593
+ /**
594
+ * Dispatches the MessageReaction activity.
595
+ * This method dispatches message reaction activities to the appropriate handlers.
596
+ * @param context - The turn context for the current turn of conversation
597
+ * @protected
598
+ */
381
599
  protected async dispatchMessageReactionActivity (context: TurnContext): Promise<void> {
382
600
  if ((context.activity.reactionsAdded != null) || (context.activity.reactionsRemoved != null)) {
383
601
  if (context.activity.reactionsAdded?.length) {
@@ -391,18 +609,32 @@ export class ActivityHandler {
391
609
  }
392
610
  }
393
611
 
394
- /** * Dispatches the MessageUpdate activity. */
612
+ /**
613
+ * Dispatches the MessageUpdate activity.
614
+ * This method dispatches message update activities to the appropriate handlers.
615
+ * @param context - The turn context for the current turn of conversation
616
+ * @protected
617
+ */
395
618
  protected async dispatchMessageUpdateActivity (context: TurnContext): Promise<void> {
396
619
  await this.defaultNextEvent(context)()
397
620
  }
398
621
 
399
- /** * Dispatches the MessageDelete activity. */
622
+ /**
623
+ * Dispatches the MessageDelete activity.
624
+ * This method dispatches message delete activities to the appropriate handlers.
625
+ * @param context - The turn context for the current turn of conversation
626
+ * @protected
627
+ */
400
628
  protected async dispatchMessageDeleteActivity (context: TurnContext): Promise<void> {
401
629
  await this.defaultNextEvent(context)()
402
630
  }
403
631
 
404
632
  /**
405
633
  * Returns the default next event handler.
634
+ * This method creates a function that calls the default handler.
635
+ * @param context - The turn context for the current turn of conversation
636
+ * @returns A function that calls the default handler
637
+ * @protected
406
638
  */
407
639
  protected defaultNextEvent (context: TurnContext): () => Promise<void> {
408
640
  const defaultHandler = async (): Promise<void> => {
@@ -413,7 +645,14 @@ export class ActivityHandler {
413
645
  return defaultHandler
414
646
  }
415
647
 
416
- /** * Registers a handler for a specific activity type. */
648
+ /**
649
+ * Registers a handler for a specific activity type.
650
+ * This method adds a handler to the list of handlers for a specific activity type.
651
+ * @param type - The activity type to register the handler for
652
+ * @param handler - The handler to register
653
+ * @returns The current instance for method chaining
654
+ * @protected
655
+ */
417
656
  protected on (type: string, handler: AgentHandler) {
418
657
  if (!this.handlers[type]) {
419
658
  this.handlers[type] = [handler]
@@ -423,7 +662,15 @@ export class ActivityHandler {
423
662
  return this
424
663
  }
425
664
 
426
- /** * Executes the handlers for a specific activity type. */
665
+ /**
666
+ * Executes the handlers for a specific activity type.
667
+ * This method calls each registered handler for the specified activity type.
668
+ * @param context - The turn context for the current turn of conversation
669
+ * @param type - The activity type to handle
670
+ * @param onNext - The function to call when all handlers have been executed
671
+ * @returns The value returned by the last handler
672
+ * @protected
673
+ */
427
674
  protected async handle (context: TurnContext, type: string, onNext: () => Promise<void>): Promise<any> {
428
675
  let returnValue: any = null
429
676
  async function runHandler (index: number): Promise<void> {
@@ -445,12 +692,23 @@ export class ActivityHandler {
445
692
  return returnValue
446
693
  }
447
694
 
448
- /** * Creates an InvokeResponse object. */
695
+ /**
696
+ * Creates an InvokeResponse object.
697
+ * This static method creates an invoke response with the specified body.
698
+ * @param body - The body of the response
699
+ * @returns An invoke response object with status and body
700
+ * @protected
701
+ */
449
702
  protected static createInvokeResponse (body?: any): InvokeResponse {
450
703
  return { status: 200, body }
451
704
  }
452
705
 
453
- /** * Dispatches the Event activity. */
706
+ /**
707
+ * Dispatches the Event activity.
708
+ * This method dispatches event activities to the appropriate handlers.
709
+ * @param context - The turn context for the current turn of conversation
710
+ * @protected
711
+ */
454
712
  protected async dispatchEventActivity (context: TurnContext): Promise<void> {
455
713
  if (context.activity.name === tokenResponseEventName) {
456
714
  await this.handle(context, 'TokenResponseEvent', this.defaultNextEvent(context))
@@ -7,24 +7,66 @@ import { TurnContext } from '../turnContext'
7
7
 
8
8
  const logger = debug('agents:agent-client')
9
9
 
10
+ /**
11
+ * Configuration settings required to connect to an agent endpoint.
12
+ */
10
13
  export interface AgentClientConfig {
11
- endPoint: string
12
- clientId: string
13
- serviceUrl: string
14
+ /**
15
+ * The URL endpoint where activities will be sent to the agent
16
+ */
17
+ endPoint: string;
18
+ /**
19
+ * The client ID of the target agent
20
+ */
21
+ clientId: string;
22
+ /**
23
+ * The service URL used for communication with the agent
24
+ */
25
+ serviceUrl: string;
14
26
  }
15
27
 
28
+ /**
29
+ * Data structure to store conversation state for agent interactions
30
+ */
16
31
  export interface ConversationData {
17
- nameRequested: boolean
18
- conversationReference: ConversationReference
32
+ /**
33
+ * Flag indicating whether a name was requested from the agent
34
+ */
35
+ nameRequested: boolean;
36
+ /**
37
+ * Reference to the conversation for maintaining context across interactions
38
+ */
39
+ conversationReference: ConversationReference;
19
40
  }
20
41
 
42
+ /**
43
+ * Client for communicating with other agents through HTTP requests.
44
+ * Manages configuration, authentication, and activity exchange with target agents.
45
+ */
21
46
  export class AgentClient {
47
+ /** Configuration settings for the agent client */
22
48
  agentClientConfig: AgentClientConfig
23
49
 
50
+ /**
51
+ * Creates a new instance of the AgentClient class.
52
+ *
53
+ * @param agentConfigKey The name of the agent, used to locate configuration in environment variables
54
+ * @throws Error if required configuration is missing
55
+ */
24
56
  public constructor (agentConfigKey: string) {
25
57
  this.agentClientConfig = this.loadAgentClientConfig(agentConfigKey)
26
58
  }
27
59
 
60
+ /**
61
+ * Sends an activity to another agent and handles the conversation state.
62
+ *
63
+ * @param activity The activity to send to the target agent
64
+ * @param authConfig Authentication configuration used to obtain access tokens
65
+ * @param conversationState State manager to store conversation data
66
+ * @param context The current turn context
67
+ * @returns A promise that resolves to the HTTP status text of the agent response
68
+ * @throws Error if the request to the agent endpoint fails
69
+ */
28
70
  public async postActivity (activity: Activity, authConfig: AuthConfiguration, conversationState: ConversationState, context: TurnContext): Promise<string> {
29
71
  const activityCopy = activity.clone()
30
72
  activityCopy.serviceUrl = this.agentClientConfig.serviceUrl
@@ -72,6 +114,14 @@ export class AgentClient {
72
114
  return response.statusText
73
115
  }
74
116
 
117
+ /**
118
+ * Loads agent configuration from environment variables based on the agent name.
119
+ *
120
+ * @param agentName The name of the agent to load configuration for
121
+ * @returns The agent client configuration
122
+ * @throws Error if any required configuration is missing
123
+ * @private
124
+ */
75
125
  private loadAgentClientConfig (agentName: string): AgentClientConfig {
76
126
  if (agentName) {
77
127
  if (process.env[`${agentName}_endpoint`] !== undefined &&