@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
@@ -21,8 +21,25 @@ import { MemoryStorage } from '../storage'
21
21
  const logger = debug('agents:agent-application')
22
22
 
23
23
  const TYPING_TIMER_DELAY = 1000
24
- type ApplicationEventHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<boolean>
24
+ export type ApplicationEventHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<boolean>
25
25
 
26
+ /**
27
+ * Executes the application logic for a given turn context.
28
+ *
29
+ * @param turnContext - The context for the current turn of the conversation.
30
+ * @returns A promise that resolves when the application logic has completed.
31
+ *
32
+ * @remarks
33
+ * This method is the entry point for processing a turn in the conversation.
34
+ * It delegates the actual processing to the `runInternal` method, which handles
35
+ * the core logic for routing and executing handlers.
36
+ *
37
+ * Example usage:
38
+ * ```typescript
39
+ * const app = new AgentApplication();
40
+ * await app.run(turnContext);
41
+ * ```
42
+ */
26
43
  export class AgentApplication<TState extends TurnState> {
27
44
  protected readonly _options: AgentApplicationOptions<TState>
28
45
  protected readonly _routes: AppRoute<TState>[] = []
@@ -79,6 +96,24 @@ export class AgentApplication<TState extends TurnState> {
79
96
  return this._options
80
97
  }
81
98
 
99
+ /**
100
+ * Sets an error handler for the application.
101
+ *
102
+ * @param handler - The error handler function to be called when an error occurs.
103
+ * @returns The current instance of the application.
104
+ *
105
+ * @remarks
106
+ * This method allows you to handle any errors that occur during turn processing.
107
+ * The handler will receive the turn context and the error that occurred.
108
+ *
109
+ * Example usage:
110
+ * ```typescript
111
+ * app.error(async (context, error) => {
112
+ * console.error(`An error occurred: ${error.message}`);
113
+ * await context.sendActivity('Sorry, something went wrong!');
114
+ * });
115
+ * ```
116
+ */
82
117
  public error (handler: (context: TurnContext, error: Error) => Promise<void>): this {
83
118
  if (this._adapter) {
84
119
  this._adapter.onTurnError = handler
@@ -87,11 +122,49 @@ export class AgentApplication<TState extends TurnState> {
87
122
  return this
88
123
  }
89
124
 
125
+ /**
126
+ * Adds a new route to the application for handling activities.
127
+ *
128
+ * @param selector - The selector function that determines if a route should handle the current activity.
129
+ * @param handler - The handler function that will be called if the selector returns true.
130
+ * @returns The current instance of the application.
131
+ *
132
+ * @remarks
133
+ * Routes are evaluated in the order they are added. The first route with a selector that returns true will be used.
134
+ *
135
+ * Example usage:
136
+ * ```typescript
137
+ * app.addRoute(
138
+ * async (context) => context.activity.type === ActivityTypes.Message,
139
+ * async (context, state) => {
140
+ * await context.sendActivity('I received your message');
141
+ * }
142
+ * );
143
+ * ```
144
+ */
90
145
  public addRoute (selector: RouteSelector, handler: RouteHandler<TState>): this {
91
146
  this._routes.push({ selector, handler })
92
147
  return this
93
148
  }
94
149
 
150
+ /**
151
+ * Adds a handler for specific activity types.
152
+ *
153
+ * @param type - The activity type(s) to handle. Can be a string, RegExp, RouteSelector, or array of these types.
154
+ * @param handler - The handler function that will be called when the specified activity type is received.
155
+ * @returns The current instance of the application.
156
+ *
157
+ * @remarks
158
+ * This method allows you to register handlers for specific activity types such as 'message', 'conversationUpdate', etc.
159
+ * You can specify multiple activity types by passing an array.
160
+ *
161
+ * Example usage:
162
+ * ```typescript
163
+ * app.activity(ActivityTypes.Message, async (context, state) => {
164
+ * await context.sendActivity('I received your message');
165
+ * });
166
+ * ```
167
+ */
95
168
  public activity (
96
169
  type: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[],
97
170
  handler: (context: TurnContext, state: TState) => Promise<void>
@@ -103,6 +176,29 @@ export class AgentApplication<TState extends TurnState> {
103
176
  return this
104
177
  }
105
178
 
179
+ /**
180
+ * Adds a handler for conversation update events.
181
+ *
182
+ * @param event - The conversation update event to handle (e.g., 'membersAdded', 'membersRemoved').
183
+ * @param handler - The handler function that will be called when the specified event occurs.
184
+ * @returns The current instance of the application.
185
+ * @throws Error if the handler is not a function.
186
+ *
187
+ * @remarks
188
+ * Conversation update events occur when the state of a conversation changes, such as when members join or leave.
189
+ *
190
+ * Example usage:
191
+ * ```typescript
192
+ * app.conversationUpdate('membersAdded', async (context, state) => {
193
+ * const membersAdded = context.activity.membersAdded;
194
+ * for (const member of membersAdded) {
195
+ * if (member.id !== context.activity.recipient.id) {
196
+ * await context.sendActivity('Hello and welcome!');
197
+ * }
198
+ * }
199
+ * });
200
+ * ```
201
+ */
106
202
  public conversationUpdate (
107
203
  event: ConversationUpdateEvents,
108
204
  handler: (context: TurnContext, state: TState) => Promise<void>
@@ -118,6 +214,13 @@ export class AgentApplication<TState extends TurnState> {
118
214
  return this
119
215
  }
120
216
 
217
+ /**
218
+ * Continues a conversation asynchronously.
219
+ * @param conversationReferenceOrContext - The conversation reference or turn context.
220
+ * @param logic - The logic to execute during the conversation.
221
+ * @returns A promise that resolves when the conversation logic has completed.
222
+ * @throws Error if the adapter is not configured.
223
+ */
121
224
  protected async continueConversationAsync (
122
225
  conversationReferenceOrContext: ConversationReference | TurnContext,
123
226
  logic: (context: TurnContext) => Promise<void>
@@ -143,6 +246,31 @@ export class AgentApplication<TState extends TurnState> {
143
246
  await this._adapter.continueConversation(reference, logic)
144
247
  }
145
248
 
249
+ /**
250
+ * Adds a handler for message activities that match the specified keyword or pattern.
251
+ *
252
+ * @param keyword - The keyword, pattern, or selector function to match against message text.
253
+ * Can be a string, RegExp, RouteSelector, or array of these types.
254
+ * @param handler - The handler function that will be called when a matching message is received.
255
+ * @returns The current instance of the application.
256
+ *
257
+ * @remarks
258
+ * This method allows you to register handlers for specific message patterns.
259
+ * If keyword is a string, it matches messages containing that string.
260
+ * If keyword is a RegExp, it tests the message text against the regular expression.
261
+ * If keyword is a function, it calls the function with the context to determine if the message matches.
262
+ *
263
+ * Example usage:
264
+ * ```typescript
265
+ * app.message('hello', async (context, state) => {
266
+ * await context.sendActivity('Hello there!');
267
+ * });
268
+ *
269
+ * app.message(/help., async (context, state) => {
270
+ * await context.sendActivity('How can I help you?');
271
+ * });
272
+ * ```
273
+ */
146
274
  public message (
147
275
  keyword: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[],
148
276
  handler: (context: TurnContext, state: TState) => Promise<void>
@@ -154,6 +282,24 @@ export class AgentApplication<TState extends TurnState> {
154
282
  return this
155
283
  }
156
284
 
285
+ /**
286
+ * Sets a handler to be called when a user successfully signs in.
287
+ *
288
+ * @param handler - The handler function to be called after successful sign-in.
289
+ * @returns The current instance of the application.
290
+ * @throws Error if authentication options were not configured.
291
+ *
292
+ * @remarks
293
+ * This method allows you to perform actions after a user has successfully authenticated.
294
+ * The handler will receive the turn context and state.
295
+ *
296
+ * Example usage:
297
+ * ```typescript
298
+ * app.onSignInSuccess(async (context, state) => {
299
+ * await context.sendActivity('You have successfully signed in!');
300
+ * });
301
+ * ```
302
+ */
157
303
  public onSignInSuccess (handler: (context: TurnContext, state: TurnState) => void): this {
158
304
  if (this._userIdentity) {
159
305
  this._userIdentity.onSignInSuccess(handler)
@@ -165,7 +311,38 @@ export class AgentApplication<TState extends TurnState> {
165
311
  return this
166
312
  }
167
313
 
168
- public async run (turnContext: TurnContext): Promise<boolean> {
314
+ /**
315
+ * Executes the application logic for a given turn context.
316
+ *
317
+ * @param turnContext - The context for the current turn of the conversation.
318
+ * @returns A promise that resolves when the application logic has completed.
319
+ *
320
+ * @remarks
321
+ * This method is the entry point for processing a turn in the conversation.
322
+ * It delegates the actual processing to the `runInternal` method, which handles
323
+ * the core logic for routing and executing handlers.
324
+ *
325
+ * Example usage:
326
+ * ```typescript
327
+ * const app = new AgentApplication();
328
+ * await app.run(turnContext);
329
+ * ```
330
+ */
331
+ public async run (turnContext:TurnContext): Promise<void> {
332
+ await this.runInternal(turnContext)
333
+ }
334
+
335
+ /**
336
+ * Executes the application logic for a given turn context.
337
+ * @private
338
+ * @param turnContext - The context for the current turn of the conversation.
339
+ * @returns A promise that resolves to true if a handler was executed, false otherwise.
340
+ *
341
+ * @remarks
342
+ * This method is the core logic for processing a turn in the conversation.
343
+ * It handles routing and executing handlers based on the activity type and content.
344
+ */
345
+ public async runInternal (turnContext: TurnContext): Promise<boolean> {
169
346
  return await this.startLongRunningCall(turnContext, async (context) => {
170
347
  this.startTypingTimer(context)
171
348
  try {
@@ -222,6 +399,27 @@ export class AgentApplication<TState extends TurnState> {
222
399
  })
223
400
  }
224
401
 
402
+ /**
403
+ * Sends a proactive message to a conversation.
404
+ *
405
+ * @param context - The turn context or conversation reference to use.
406
+ * @param activityOrText - The activity or text to send.
407
+ * @param speak - Optional text to be spoken by the bot on a speech-enabled channel.
408
+ * @param inputHint - Optional input hint for the activity.
409
+ * @returns A promise that resolves to the resource response from sending the activity.
410
+ *
411
+ * @remarks
412
+ * This method allows you to send messages proactively to a conversation, outside the normal turn flow.
413
+ *
414
+ * Example usage:
415
+ * ```typescript
416
+ * // With conversation reference
417
+ * await app.sendProactiveActivity(conversationReference, 'Important notification!');
418
+ *
419
+ * // From an existing context
420
+ * await app.sendProactiveActivity(turnContext, 'Important notification!');
421
+ * ```
422
+ */
225
423
  public async sendProactiveActivity (
226
424
  context: TurnContext | ConversationReference,
227
425
  activityOrText: string | Activity,
@@ -236,6 +434,28 @@ export class AgentApplication<TState extends TurnState> {
236
434
  return response
237
435
  }
238
436
 
437
+ /**
438
+ * Starts a typing indicator timer for the current turn context.
439
+ *
440
+ * @param context - The turn context for the current conversation.
441
+ * @returns void
442
+ *
443
+ * @remarks
444
+ * This method starts a timer that sends typing activity indicators to the user
445
+ * at regular intervals. The typing indicator continues until a message is sent
446
+ * or the timer is explicitly stopped.
447
+ *
448
+ * The typing indicator helps provide feedback to users that the agent is processing
449
+ * their message, especially when responses might take time to generate.
450
+ *
451
+ * Example usage:
452
+ * ```typescript
453
+ * app.startTypingTimer(turnContext);
454
+ * // Do some processing...
455
+ * await turnContext.sendActivity('Response after processing');
456
+ * // Typing timer automatically stops when sending a message
457
+ * ```
458
+ */
239
459
  public startTypingTimer (context: TurnContext): void {
240
460
  if (context.activity.type === ActivityTypes.Message && !this._typingTimer) {
241
461
  let timerRunning = true
@@ -274,6 +494,23 @@ export class AgentApplication<TState extends TurnState> {
274
494
  }
275
495
  }
276
496
 
497
+ /**
498
+ * Stops the typing indicator timer if it's currently running.
499
+ *
500
+ * @returns void
501
+ *
502
+ * @remarks
503
+ * This method clears the typing indicator timer to prevent further typing indicators
504
+ * from being sent. It's typically called automatically when a message is sent, but
505
+ * can also be called manually to stop the typing indicator.
506
+ *
507
+ * Example usage:
508
+ * ```typescript
509
+ * app.startTypingTimer(turnContext);
510
+ * // Do some processing...
511
+ * app.stopTypingTimer(); // Manually stop the typing indicator
512
+ * ```
513
+ */
277
514
  public stopTypingTimer (): void {
278
515
  if (this._typingTimer) {
279
516
  clearTimeout(this._typingTimer)
@@ -281,6 +518,26 @@ export class AgentApplication<TState extends TurnState> {
281
518
  }
282
519
  }
283
520
 
521
+ /**
522
+ * Adds an event handler for specified turn events.
523
+ *
524
+ * @param event - The turn event(s) to handle. Can be 'beforeTurn', 'afterTurn', or other custom events.
525
+ * @param handler - The handler function that will be called when the event occurs.
526
+ * @returns The current instance of the application.
527
+ *
528
+ * @remarks
529
+ * Turn events allow you to execute logic before or after the main turn processing.
530
+ * Handlers added for 'beforeTurn' are executed before routing logic.
531
+ * Handlers added for 'afterTurn' are executed after routing logic.
532
+ *
533
+ * Example usage:
534
+ * ```typescript
535
+ * app.turn('beforeTurn', async (context, state) => {
536
+ * console.log('Processing before turn');
537
+ * return true; // Continue execution
538
+ * });
539
+ * ```
540
+ */
284
541
  public turn (
285
542
  event: TurnEvents | TurnEvents[],
286
543
  handler: (context: TurnContext, state: TState) => Promise<boolean>
@@ -9,33 +9,65 @@ import { TurnState } from './turnState'
9
9
  import { Storage } from '../storage'
10
10
  import { UserIdentityOptions } from './oauth/userIdentity'
11
11
 
12
+ /**
13
+ * Builder class for creating and configuring AgentApplication instances.
14
+ * @template TState Type extending TurnState that will be used by the application
15
+ */
12
16
  export class AgentApplicationBuilder<TState extends TurnState = TurnState> {
13
17
  protected _options: Partial<AgentApplicationOptions<TState>> = {}
14
18
 
19
+ /**
20
+ * Gets the current options for the AgentApplication being built.
21
+ * @returns The current options object
22
+ */
15
23
  protected get options () {
16
24
  return this._options
17
25
  }
18
26
 
27
+ /**
28
+ * Sets the storage provider for the AgentApplication.
29
+ * @param storage The storage implementation to use
30
+ * @returns This builder instance for chaining
31
+ */
19
32
  public withStorage (storage: Storage): this {
20
33
  this._options.storage = storage
21
34
  return this
22
35
  }
23
36
 
37
+ /**
38
+ * Sets the factory function to create new TurnState instances.
39
+ * @param turnStateFactory Function that creates a new TurnState
40
+ * @returns This builder instance for chaining
41
+ */
24
42
  public withTurnStateFactory (turnStateFactory: () => TState): this {
25
43
  this._options.turnStateFactory = turnStateFactory
26
44
  return this
27
45
  }
28
46
 
47
+ /**
48
+ * Configures whether the agent should display typing indicators.
49
+ * @param startTypingTimer Whether to show typing indicators
50
+ * @returns This builder instance for chaining
51
+ */
29
52
  public setStartTypingTimer (startTypingTimer: boolean): this {
30
53
  this._options.startTypingTimer = startTypingTimer
31
54
  return this
32
55
  }
33
56
 
57
+ /**
58
+ * Sets authentication options for the AgentApplication.
59
+ * @param authenticationOptions The user identity authentication options
60
+ * @returns This builder instance for chaining
61
+ */
34
62
  public withAuthentication (authenticationOptions: UserIdentityOptions): this {
35
63
  this._options.authentication = authenticationOptions
36
64
  return this
37
65
  }
38
66
 
67
+ /**
68
+ * Builds and returns a new AgentApplication instance configured with the provided options.
69
+ * @returns A new AgentApplication instance
70
+ */
39
71
  public build (): AgentApplication<TState> {
40
72
  return new AgentApplication(this._options)
41
73
  }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * Interface for memory operations that provides a way to store and retrieve values by path.
8
+ * Allows components to persist state data during a conversation.
9
+ */
10
+ export interface AppMemory {
11
+ /**
12
+ * Deletes a value at the specified path.
13
+ * @param path The path to the value to delete
14
+ */
15
+ deleteValue(path: string): void;
16
+
17
+ /**
18
+ * Checks if a value exists at the specified path.
19
+ * @param path The path to check
20
+ * @returns True if a value exists at the path, false otherwise
21
+ */
22
+ hasValue(path: string): boolean;
23
+
24
+ /**
25
+ * Gets a value from the specified path.
26
+ * @template TValue The expected type of the value
27
+ * @param path The path to get the value from
28
+ * @returns The value at the specified path cast to type TValue
29
+ */
30
+ getValue<TValue = unknown>(path: string): TValue;
31
+
32
+ /**
33
+ * Sets a value at the specified path.
34
+ * @param path The path where the value should be stored
35
+ * @param value The value to store
36
+ */
37
+ setValue(path: string, value: unknown): void;
38
+ }
package/src/app/index.ts CHANGED
@@ -8,4 +8,7 @@ export * from './conversationUpdateEvents'
8
8
  export * from './routeHandler'
9
9
  export * from './routeSelector'
10
10
  export * from './turnState'
11
+ export * from './turnEvents'
12
+ export * from './turnStateEntry'
11
13
  export * from './inputFileDownloader'
14
+ export * from './appMemory'
@@ -3,4 +3,10 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ /**
7
+ * Represents the types of events that can occur during a turn in the application.
8
+ *
9
+ * - `beforeTurn`: Triggered before the turn starts.
10
+ * - `afterTurn`: Triggered after the turn ends.
11
+ */
6
12
  export type TurnEvents = 'beforeTurn' | 'afterTurn'
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { Storage, StoreItems } from '../storage'
7
- import { Memory } from './memory'
7
+ import { AppMemory } from './appMemory'
8
8
  import { InputFile } from './inputFileDownloader'
9
9
  import { TurnStateEntry } from './turnStateEntry'
10
10
  import { TurnContext } from '../turnContext'
@@ -74,7 +74,7 @@ export class TurnState<
74
74
  TUserState = DefaultUserState,
75
75
  TTempState = DefaultTempState,
76
76
  TSSOState = DefaultSSOState
77
- > implements Memory {
77
+ > implements AppMemory {
78
78
  private _scopes: Record<string, TurnStateEntry> = {}
79
79
  private _isLoaded = false
80
80
  private _loadingPromise?: Promise<boolean>
@@ -3,26 +3,47 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ /**
7
+ * Represents an entry in the turn state that can be tracked for changes and stored.
8
+ */
6
9
  export class TurnStateEntry {
7
10
  private _value: Record<string, unknown>
8
11
  private _storageKey?: string
9
12
  private _deleted = false
10
13
  private _hash: string
11
14
 
15
+ /**
16
+ * Creates a new instance of TurnStateEntry.
17
+ * @param value - The initial value for the entry.
18
+ * @param storageKey - Optional storage key used to persist the entry.
19
+ */
12
20
  public constructor (value?: Record<string, unknown>, storageKey?: string) {
13
21
  this._value = value || {}
14
22
  this._storageKey = storageKey
15
23
  this._hash = JSON.stringify(this._value)
16
24
  }
17
25
 
26
+ /**
27
+ * Gets whether the entry value has changed since its creation or last update.
28
+ * @returns True if the value has changed, otherwise false.
29
+ */
18
30
  public get hasChanged (): boolean {
19
31
  return JSON.stringify(this._value) !== this._hash
20
32
  }
21
33
 
34
+ /**
35
+ * Gets whether the entry has been marked for deletion.
36
+ * @returns True if the entry is marked for deletion, otherwise false.
37
+ */
22
38
  public get isDeleted (): boolean {
23
39
  return this._deleted
24
40
  }
25
41
 
42
+ /**
43
+ * Gets the current value of the entry. If the entry was marked for deletion,
44
+ * it will be reset to an empty object and marked as not deleted.
45
+ * @returns The current value of the entry.
46
+ */
26
47
  public get value (): Record<string, unknown> {
27
48
  if (this.isDeleted) {
28
49
  this._value = {}
@@ -32,14 +53,25 @@ export class TurnStateEntry {
32
53
  return this._value
33
54
  }
34
55
 
56
+ /**
57
+ * Gets the storage key associated with this entry.
58
+ * @returns The storage key, or undefined if no storage key was specified.
59
+ */
35
60
  public get storageKey (): string | undefined {
36
61
  return this._storageKey
37
62
  }
38
63
 
64
+ /**
65
+ * Marks the entry for deletion.
66
+ */
39
67
  public delete (): void {
40
68
  this._deleted = true
41
69
  }
42
70
 
71
+ /**
72
+ * Replaces the current value with a new value.
73
+ * @param value - The new value to set. If undefined, an empty object will be used.
74
+ */
43
75
  public replace (value?: Record<string, unknown>): void {
44
76
  this._value = value || {}
45
77
  }
@@ -15,3 +15,4 @@ export * from './receiptItem'
15
15
  export * from './taskModuleAction'
16
16
  export * from './thumbnailCard'
17
17
  export * from './videoCard'
18
+ export * from './thumbnailUrl'
@@ -25,15 +25,23 @@ import { normalizeIncomingActivity } from './activityWireCompat'
25
25
  const logger = debug('agents:cloud-adapter')
26
26
 
27
27
  /**
28
- * Adapter for handling agent interactions.
28
+ * Adapter for handling agent interactions with various channels through cloud-based services.
29
+ *
30
+ * CloudAdapter processes incoming HTTP requests from Microsoft Bot Framework channels,
31
+ * authenticates them, and generates outgoing responses. It manages the communication
32
+ * flow between agents and users across different channels, handling activities, attachments,
33
+ * and conversation continuations.
29
34
  */
30
35
  export class CloudAdapter extends BaseAdapter {
36
+ /**
37
+ * Client for connecting to the Bot Framework Connector service
38
+ */
31
39
  public connectorClient!: ConnectorClient
32
40
 
33
41
  /**
34
42
  * Creates an instance of CloudAdapter.
35
- * @param authConfig - The authentication configuration.
36
- * @param authProvider - The authentication provider.
43
+ * @param authConfig - The authentication configuration for securing communications
44
+ * @param authProvider - Optional custom authentication provider. If not specified, a default MsalTokenProvider will be used
37
45
  */
38
46
  constructor (authConfig: AuthConfiguration, authProvider?: AuthProvider) {
39
47
  super()
@@ -47,6 +55,14 @@ export class CloudAdapter extends BaseAdapter {
47
55
  }
48
56
  }
49
57
 
58
+ /**
59
+ * Creates a connector client for a specific service URL and scope.
60
+ *
61
+ * @param serviceUrl - The URL of the service to connect to
62
+ * @param scope - The authentication scope to use
63
+ * @returns A promise that resolves to a ConnectorClient instance
64
+ * @protected
65
+ */
50
66
  protected async createConnectorClient (
51
67
  serviceUrl: string,
52
68
  scope: string
@@ -59,6 +75,12 @@ export class CloudAdapter extends BaseAdapter {
59
75
  )
60
76
  }
61
77
 
78
+ /**
79
+ * Sets the connector client on the turn context.
80
+ *
81
+ * @param context - The current turn context
82
+ * @protected
83
+ */
62
84
  protected setConnectorClient (
63
85
  context: TurnContext
64
86
  ) {
@@ -164,6 +186,9 @@ export class CloudAdapter extends BaseAdapter {
164
186
  }
165
187
  res.end()
166
188
  }
189
+ if (!request.body) {
190
+ throw new TypeError('`request.body` parameter required, make sure express.json() is used as middleware')
191
+ }
167
192
  const incoming = normalizeIncomingActivity(request.body!)
168
193
  const activity = Activity.fromObject(incoming)
169
194
  logger.info(`--> Processing incoming activity, type:${activity.type} channel:${activity.channelId}`)
@@ -1,3 +1,10 @@
1
1
  import pjson from '@microsoft/agents-hosting/package.json'
2
2
  import os from 'os'
3
+
4
+ /**
5
+ * Generates a string containing information about the SDK version and runtime environment.
6
+ * This is used for telemetry and User-Agent headers in HTTP requests.
7
+ *
8
+ * @returns A formatted string containing the SDK version, Node.js version, and OS details
9
+ */
3
10
  export const getProductInfo = () : string => `agents-sdk-js/${pjson.version} nodejs/${process.version} ${os.platform()}-${os.arch()}/${os.release()}`