@microsoft/agents-hosting 0.2.10-g3ac88ff25e → 0.3.5

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 (128) hide show
  1. package/README.md +17 -1
  2. package/dist/src/activityHandler.d.ts +304 -46
  3. package/dist/src/activityHandler.js +298 -45
  4. package/dist/src/activityHandler.js.map +1 -1
  5. package/dist/src/agent-client/agentClient.d.ts +50 -0
  6. package/dist/src/agent-client/agentClient.js +28 -0
  7. package/dist/src/agent-client/agentClient.js.map +1 -1
  8. package/dist/src/app/agentApplication.d.ts +272 -7
  9. package/dist/src/app/agentApplication.js +278 -12
  10. package/dist/src/app/agentApplication.js.map +1 -1
  11. package/dist/src/app/agentApplicationBuilder.d.ts +34 -3
  12. package/dist/src/app/agentApplicationBuilder.js +38 -6
  13. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  14. package/dist/src/app/agentApplicationOptions.d.ts +26 -2
  15. package/dist/src/app/appMemory.d.ts +34 -0
  16. package/dist/src/app/{memory.js → appMemory.js} +1 -1
  17. package/dist/src/app/appMemory.js.map +1 -0
  18. package/dist/src/app/appRoute.d.ts +6 -0
  19. package/dist/src/app/attachmentDownloader.d.ts +18 -0
  20. package/dist/src/app/attachmentDownloader.js +18 -0
  21. package/dist/src/app/attachmentDownloader.js.map +1 -1
  22. package/dist/src/app/conversationUpdateEvents.d.ts +6 -0
  23. package/dist/src/app/index.d.ts +4 -1
  24. package/dist/src/app/index.js +4 -1
  25. package/dist/src/app/index.js.map +1 -1
  26. package/dist/src/app/inputFileDownloader.d.ts +22 -0
  27. package/dist/src/app/oauth/authorization.d.ts +87 -0
  28. package/dist/src/app/oauth/authorization.js +135 -0
  29. package/dist/src/app/oauth/authorization.js.map +1 -0
  30. package/dist/src/app/routeHandler.d.ts +8 -0
  31. package/dist/src/app/routeSelector.d.ts +9 -0
  32. package/dist/src/app/turnEvents.d.ts +6 -0
  33. package/dist/src/app/turnState.d.ts +152 -2
  34. package/dist/src/app/turnState.js +125 -0
  35. package/dist/src/app/turnState.js.map +1 -1
  36. package/dist/src/app/turnStateEntry.d.ts +32 -0
  37. package/dist/src/app/turnStateEntry.js +32 -0
  38. package/dist/src/app/turnStateEntry.js.map +1 -1
  39. package/dist/src/auth/authConfiguration.d.ts +24 -0
  40. package/dist/src/auth/authConfiguration.js.map +1 -1
  41. package/dist/src/auth/request.d.ts +12 -0
  42. package/dist/src/baseAdapter.d.ts +17 -0
  43. package/dist/src/baseAdapter.js +17 -0
  44. package/dist/src/baseAdapter.js.map +1 -1
  45. package/dist/src/cards/cardFactory.d.ts +3 -0
  46. package/dist/src/cards/cardFactory.js +3 -0
  47. package/dist/src/cards/cardFactory.js.map +1 -1
  48. package/dist/src/cards/index.d.ts +1 -0
  49. package/dist/src/cards/index.js +1 -0
  50. package/dist/src/cards/index.js.map +1 -1
  51. package/dist/src/cards/o365ConnectorCardActionBase.d.ts +8 -0
  52. package/dist/src/cloudAdapter.d.ts +25 -3
  53. package/dist/src/cloudAdapter.js +25 -3
  54. package/dist/src/cloudAdapter.js.map +1 -1
  55. package/dist/src/getProductInfo.d.ts +6 -0
  56. package/dist/src/getProductInfo.js +6 -0
  57. package/dist/src/getProductInfo.js.map +1 -1
  58. package/dist/src/logger.d.ts +34 -2
  59. package/dist/src/logger.js +35 -0
  60. package/dist/src/logger.js.map +1 -1
  61. package/dist/src/oauth/oAuthFlow.d.ts +32 -3
  62. package/dist/src/oauth/oAuthFlow.js +38 -14
  63. package/dist/src/oauth/oAuthFlow.js.map +1 -1
  64. package/dist/src/oauth/userTokenClient.d.ts +2 -2
  65. package/dist/src/oauth/userTokenClient.js +3 -3
  66. package/dist/src/oauth/userTokenClient.js.map +1 -1
  67. package/dist/src/state/agentState.d.ts +79 -27
  68. package/dist/src/state/agentState.js +58 -27
  69. package/dist/src/state/agentState.js.map +1 -1
  70. package/dist/src/state/agentStatePropertyAccesor.d.ts +67 -11
  71. package/dist/src/state/agentStatePropertyAccesor.js +58 -11
  72. package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
  73. package/dist/src/statusCodes.d.ts +39 -0
  74. package/dist/src/statusCodes.js +39 -0
  75. package/dist/src/statusCodes.js.map +1 -1
  76. package/dist/src/storage/memoryStorage.d.ts +48 -14
  77. package/dist/src/storage/memoryStorage.js +48 -14
  78. package/dist/src/storage/memoryStorage.js.map +1 -1
  79. package/dist/src/storage/storage.d.ts +43 -13
  80. package/dist/src/tokenResponseEventName.d.ts +3 -0
  81. package/dist/src/tokenResponseEventName.js +3 -0
  82. package/dist/src/tokenResponseEventName.js.map +1 -1
  83. package/dist/src/turnContext.d.ts +142 -56
  84. package/dist/src/turnContext.js +123 -53
  85. package/dist/src/turnContext.js.map +1 -1
  86. package/package.json +6 -6
  87. package/src/activityHandler.ts +304 -46
  88. package/src/agent-client/agentClient.ts +55 -5
  89. package/src/app/agentApplication.ts +283 -15
  90. package/src/app/agentApplicationBuilder.ts +39 -7
  91. package/src/app/agentApplicationOptions.ts +33 -2
  92. package/src/app/appMemory.ts +38 -0
  93. package/src/app/appRoute.ts +7 -0
  94. package/src/app/attachmentDownloader.ts +18 -0
  95. package/src/app/conversationUpdateEvents.ts +6 -0
  96. package/src/app/index.ts +4 -1
  97. package/src/app/inputFileDownloader.ts +24 -0
  98. package/src/app/oauth/authorization.ts +162 -0
  99. package/src/app/routeHandler.ts +8 -0
  100. package/src/app/routeSelector.ts +9 -0
  101. package/src/app/turnEvents.ts +6 -0
  102. package/src/app/turnState.ts +153 -3
  103. package/src/app/turnStateEntry.ts +32 -0
  104. package/src/auth/authConfiguration.ts +32 -1
  105. package/src/auth/request.ts +15 -0
  106. package/src/baseAdapter.ts +18 -0
  107. package/src/cards/cardFactory.ts +3 -0
  108. package/src/cards/index.ts +1 -0
  109. package/src/cards/o365ConnectorCardActionBase.ts +8 -0
  110. package/src/cloudAdapter.ts +28 -3
  111. package/src/getProductInfo.ts +7 -0
  112. package/src/logger.ts +34 -1
  113. package/src/oauth/oAuthFlow.ts +59 -18
  114. package/src/oauth/userTokenClient.ts +4 -4
  115. package/src/state/agentState.ts +81 -29
  116. package/src/state/agentStatePropertyAccesor.ts +67 -11
  117. package/src/statusCodes.ts +51 -0
  118. package/src/storage/memoryStorage.ts +48 -14
  119. package/src/storage/storage.ts +51 -18
  120. package/src/tokenResponseEventName.ts +3 -0
  121. package/src/turnContext.ts +142 -56
  122. package/dist/src/app/memory.d.ts +0 -10
  123. package/dist/src/app/memory.js.map +0 -1
  124. package/dist/src/app/oauth/userIdentity.d.ts +0 -43
  125. package/dist/src/app/oauth/userIdentity.js +0 -54
  126. package/dist/src/app/oauth/userIdentity.js.map +0 -1
  127. package/src/app/memory.ts +0 -14
  128. package/src/app/oauth/userIdentity.ts +0 -78
@@ -6,10 +6,30 @@ const agents_activity_1 = require("@microsoft/agents-activity");
6
6
  const uuid_1 = require("uuid");
7
7
  const logger_1 = require("../logger");
8
8
  const logger = (0, logger_1.debug)('agents:agent-client');
9
+ /**
10
+ * Client for communicating with other agents through HTTP requests.
11
+ * Manages configuration, authentication, and activity exchange with target agents.
12
+ */
9
13
  class AgentClient {
14
+ /**
15
+ * Creates a new instance of the AgentClient class.
16
+ *
17
+ * @param agentConfigKey The name of the agent, used to locate configuration in environment variables
18
+ * @throws Error if required configuration is missing
19
+ */
10
20
  constructor(agentConfigKey) {
11
21
  this.agentClientConfig = this.loadAgentClientConfig(agentConfigKey);
12
22
  }
23
+ /**
24
+ * Sends an activity to another agent and handles the conversation state.
25
+ *
26
+ * @param activity The activity to send to the target agent
27
+ * @param authConfig Authentication configuration used to obtain access tokens
28
+ * @param conversationState State manager to store conversation data
29
+ * @param context The current turn context
30
+ * @returns A promise that resolves to the HTTP status text of the agent response
31
+ * @throws Error if the request to the agent endpoint fails
32
+ */
13
33
  async postActivity(activity, authConfig, conversationState, context) {
14
34
  const activityCopy = activity.clone();
15
35
  activityCopy.serviceUrl = this.agentClientConfig.serviceUrl;
@@ -48,6 +68,14 @@ class AgentClient {
48
68
  }
49
69
  return response.statusText;
50
70
  }
71
+ /**
72
+ * Loads agent configuration from environment variables based on the agent name.
73
+ *
74
+ * @param agentName The name of the agent to load configuration for
75
+ * @returns The agent client configuration
76
+ * @throws Error if any required configuration is missing
77
+ * @private
78
+ */
51
79
  loadAgentClientConfig(agentName) {
52
80
  if (agentName) {
53
81
  if (process.env[`${agentName}_endpoint`] !== undefined &&
@@ -1 +1 @@
1
- {"version":3,"file":"agentClient.js","sourceRoot":"","sources":["../../../src/agent-client/agentClient.ts"],"names":[],"mappings":";;;AAAA,kCAA8D;AAC9D,gEAAuF;AACvF,+BAAyB;AACzB,sCAAiC;AAIjC,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,qBAAqB,CAAC,CAAA;AAa3C,MAAa,WAAW;IAGtB,YAAoB,cAAsB;QACxC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAA;IACrE,CAAC;IAEM,KAAK,CAAC,YAAY,CAAE,QAAkB,EAAE,UAA6B,EAAE,iBAAoC,EAAE,OAAoB;QACtI,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAA;QACrC,YAAY,CAAC,UAAU,GAAG,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAA;QAC3D,YAAY,CAAC,SAAS,GAAG,EAAE,GAAG,YAAY,CAAC,SAAS,EAAE,IAAI,EAAE,2BAAS,CAAC,KAAK,EAAE,CAAA;QAC7E,YAAY,CAAC,SAAS,GAAG;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,UAAU,EAAE,YAAY,CAAC,EAAE;YAC3B,SAAS,EAAE,YAAY,CAAC,SAAU;YAClC,MAAM,EAAE,YAAY,CAAC,MAAM;YAC3B,YAAY,EAAE;gBACZ,EAAE,EAAE,QAAQ,CAAC,YAAa,CAAC,EAAE;gBAC7B,GAAG,YAAY,CAAC,YAAY;aAC7B;SACF,CAAA;QACD,YAAY,CAAC,YAAa,CAAC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iB;QAC9C,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,WAAW,CAAC,KAAK,SAAS;gBACpD,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,WAAW,CAAC,KAAK,SAAS;gBAClD,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,aAAa,CAAC,KAAK,SAAS,EAAE,CAAC;gBACvD,OAAO;oBACL,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,WAAW,CAAE;oBAC/C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,WAAW,CAAE;oBAC/C,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,aAAa,CAAE;iBACpD,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,yCAAyC,SAAS,EAAE,CAAC,CAAA;YACvE,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;QAC3C,CAAC;IACH,CAAC;CACF;AAhGD,kCAgGC"}
@@ -13,31 +13,297 @@ import { TurnEvents } from './turnEvents';
13
13
  import { AppRoute } from './appRoute';
14
14
  import { TurnContext } from '../turnContext';
15
15
  import { ResourceResponse } from '../connector-client';
16
- import { UserIdentity } from './oauth/userIdentity';
17
- type ApplicationEventHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<boolean>;
16
+ import { Authorization } from './oauth/authorization';
17
+ export type ApplicationEventHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<boolean>;
18
+ /**
19
+ * Executes the application logic for a given turn context.
20
+ *
21
+ * @param turnContext - The context for the current turn of the conversation.
22
+ * @returns A promise that resolves when the application logic has completed.
23
+ *
24
+ * @remarks
25
+ * This method is the entry point for processing a turn in the conversation.
26
+ * It delegates the actual processing to the `runInternal` method, which handles
27
+ * the core logic for routing and executing handlers.
28
+ *
29
+ * Example usage:
30
+ * ```typescript
31
+ * const app = new AgentApplication();
32
+ * await app.run(turnContext);
33
+ * ```
34
+ */
18
35
  export declare class AgentApplication<TState extends TurnState> {
19
36
  protected readonly _options: AgentApplicationOptions<TState>;
20
37
  protected readonly _routes: AppRoute<TState>[];
21
38
  protected readonly _beforeTurn: ApplicationEventHandler<TState>[];
22
39
  protected readonly _afterTurn: ApplicationEventHandler<TState>[];
23
40
  private readonly _adapter?;
41
+ private readonly _authorization?;
24
42
  private _typingTimer;
25
- private readonly _userIdentity?;
26
43
  constructor(options?: Partial<AgentApplicationOptions<TState>>);
44
+ /**
45
+ * Gets the adapter associated with the application.
46
+ * @throws Error if the adapter is not configured.
47
+ */
27
48
  get adapter(): BaseAdapter;
28
- get userIdentity(): UserIdentity;
49
+ /**
50
+ * Gets the authorization instance for the application.
51
+ * @throws Error if no authentication options were configured.
52
+ */
53
+ get authorization(): Authorization;
54
+ /**
55
+ * Gets the options used to configure the application.
56
+ * @returns The application options.
57
+ */
29
58
  get options(): AgentApplicationOptions<TState>;
59
+ /**
60
+ * Sets an error handler for the application.
61
+ *
62
+ * @param handler - The error handler function to be called when an error occurs.
63
+ * @returns The current instance of the application.
64
+ *
65
+ * @remarks
66
+ * This method allows you to handle any errors that occur during turn processing.
67
+ * The handler will receive the turn context and the error that occurred.
68
+ *
69
+ * Example usage:
70
+ * ```typescript
71
+ * app.error(async (context, error) => {
72
+ * console.error(`An error occurred: ${error.message}`);
73
+ * await context.sendActivity('Sorry, something went wrong!');
74
+ * });
75
+ * ```
76
+ */
30
77
  error(handler: (context: TurnContext, error: Error) => Promise<void>): this;
78
+ /**
79
+ * Adds a new route to the application for handling activities.
80
+ *
81
+ * @param selector - The selector function that determines if a route should handle the current activity.
82
+ * @param handler - The handler function that will be called if the selector returns true.
83
+ * @returns The current instance of the application.
84
+ *
85
+ * @remarks
86
+ * Routes are evaluated in the order they are added. The first route with a selector that returns true will be used.
87
+ *
88
+ * Example usage:
89
+ * ```typescript
90
+ * app.addRoute(
91
+ * async (context) => context.activity.type === ActivityTypes.Message,
92
+ * async (context, state) => {
93
+ * await context.sendActivity('I received your message');
94
+ * }
95
+ * );
96
+ * ```
97
+ */
31
98
  addRoute(selector: RouteSelector, handler: RouteHandler<TState>): this;
99
+ /**
100
+ * Adds a handler for specific activity types.
101
+ *
102
+ * @param type - The activity type(s) to handle. Can be a string, RegExp, RouteSelector, or array of these types.
103
+ * @param handler - The handler function that will be called when the specified activity type is received.
104
+ * @returns The current instance of the application.
105
+ *
106
+ * @remarks
107
+ * This method allows you to register handlers for specific activity types such as 'message', 'conversationUpdate', etc.
108
+ * You can specify multiple activity types by passing an array.
109
+ *
110
+ * Example usage:
111
+ * ```typescript
112
+ * app.activity(ActivityTypes.Message, async (context, state) => {
113
+ * await context.sendActivity('I received your message');
114
+ * });
115
+ * ```
116
+ */
32
117
  activity(type: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState) => Promise<void>): this;
118
+ /**
119
+ * Adds a handler for conversation update events.
120
+ *
121
+ * @param event - The conversation update event to handle (e.g., 'membersAdded', 'membersRemoved').
122
+ * @param handler - The handler function that will be called when the specified event occurs.
123
+ * @returns The current instance of the application.
124
+ * @throws Error if the handler is not a function.
125
+ *
126
+ * @remarks
127
+ * Conversation update events occur when the state of a conversation changes, such as when members join or leave.
128
+ *
129
+ * Example usage:
130
+ * ```typescript
131
+ * app.conversationUpdate('membersAdded', async (context, state) => {
132
+ * const membersAdded = context.activity.membersAdded;
133
+ * for (const member of membersAdded) {
134
+ * if (member.id !== context.activity.recipient.id) {
135
+ * await context.sendActivity('Hello and welcome!');
136
+ * }
137
+ * }
138
+ * });
139
+ * ```
140
+ */
33
141
  conversationUpdate(event: ConversationUpdateEvents, handler: (context: TurnContext, state: TState) => Promise<void>): this;
142
+ /**
143
+ * Continues a conversation asynchronously.
144
+ * @param conversationReferenceOrContext - The conversation reference or turn context.
145
+ * @param logic - The logic to execute during the conversation.
146
+ * @returns A promise that resolves when the conversation logic has completed.
147
+ * @throws Error if the adapter is not configured.
148
+ */
34
149
  protected continueConversationAsync(conversationReferenceOrContext: ConversationReference | TurnContext, logic: (context: TurnContext) => Promise<void>): Promise<void>;
150
+ /**
151
+ * Adds a handler for message activities that match the specified keyword or pattern.
152
+ *
153
+ * @param keyword - The keyword, pattern, or selector function to match against message text.
154
+ * Can be a string, RegExp, RouteSelector, or array of these types.
155
+ * @param handler - The handler function that will be called when a matching message is received.
156
+ * @returns The current instance of the application.
157
+ *
158
+ * @remarks
159
+ * This method allows you to register handlers for specific message patterns.
160
+ * If keyword is a string, it matches messages containing that string.
161
+ * If keyword is a RegExp, it tests the message text against the regular expression.
162
+ * If keyword is a function, it calls the function with the context to determine if the message matches.
163
+ *
164
+ * Example usage:
165
+ * ```typescript
166
+ * app.message('hello', async (context, state) => {
167
+ * await context.sendActivity('Hello there!');
168
+ * });
169
+ *
170
+ * app.message(/help., async (context, state) => {
171
+ * await context.sendActivity('How can I help you?');
172
+ * });
173
+ * ```
174
+ */
35
175
  message(keyword: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState) => Promise<void>): this;
36
- onSignInSuccess(handler: (context: TurnContext, state: TurnState) => void): this;
37
- run(turnContext: TurnContext): Promise<boolean>;
176
+ /**
177
+ * Sets a handler to be called when a user successfully signs in.
178
+ *
179
+ * @param handler - The handler function to be called after successful sign-in.
180
+ * @returns The current instance of the application.
181
+ * @throws Error if authentication options were not configured.
182
+ *
183
+ * @remarks
184
+ * This method allows you to perform actions after a user has successfully authenticated.
185
+ * The handler will receive the turn context and state.
186
+ *
187
+ * Example usage:
188
+ * ```typescript
189
+ * app.onSignInSuccess(async (context, state) => {
190
+ * await context.sendActivity('You have successfully signed in!');
191
+ * });
192
+ * ```
193
+ */
194
+ onSignInSuccess(handler: (context: TurnContext, state: TurnState, id?: string) => void): this;
195
+ /**
196
+ * Executes the application logic for a given turn context.
197
+ *
198
+ * @param turnContext - The context for the current turn of the conversation.
199
+ * @returns A promise that resolves when the application logic has completed.
200
+ *
201
+ * @remarks
202
+ * This method is the entry point for processing a turn in the conversation.
203
+ * It delegates the actual processing to the `runInternal` method, which handles
204
+ * the core logic for routing and executing handlers.
205
+ *
206
+ * Example usage:
207
+ * ```typescript
208
+ * const app = new AgentApplication();
209
+ * await app.run(turnContext);
210
+ * ```
211
+ */
212
+ run(turnContext: TurnContext): Promise<void>;
213
+ /**
214
+ * Executes the application logic for a given turn context.
215
+ * @private
216
+ * @param turnContext - The context for the current turn of the conversation.
217
+ * @returns A promise that resolves to true if a handler was executed, false otherwise.
218
+ *
219
+ * @remarks
220
+ * This method is the core logic for processing a turn in the conversation.
221
+ * It handles routing and executing handlers based on the activity type and content.
222
+ */
223
+ runInternal(turnContext: TurnContext): Promise<boolean>;
224
+ /**
225
+ * Sends a proactive message to a conversation.
226
+ *
227
+ * @param context - The turn context or conversation reference to use.
228
+ * @param activityOrText - The activity or text to send.
229
+ * @param speak - Optional text to be spoken by the bot on a speech-enabled channel.
230
+ * @param inputHint - Optional input hint for the activity.
231
+ * @returns A promise that resolves to the resource response from sending the activity.
232
+ *
233
+ * @remarks
234
+ * This method allows you to send messages proactively to a conversation, outside the normal turn flow.
235
+ *
236
+ * Example usage:
237
+ * ```typescript
238
+ * // With conversation reference
239
+ * await app.sendProactiveActivity(conversationReference, 'Important notification!');
240
+ *
241
+ * // From an existing context
242
+ * await app.sendProactiveActivity(turnContext, 'Important notification!');
243
+ * ```
244
+ */
38
245
  sendProactiveActivity(context: TurnContext | ConversationReference, activityOrText: string | Activity, speak?: string, inputHint?: string): Promise<ResourceResponse | undefined>;
246
+ /**
247
+ * Starts a typing indicator timer for the current turn context.
248
+ *
249
+ * @param context - The turn context for the current conversation.
250
+ * @returns void
251
+ *
252
+ * @remarks
253
+ * This method starts a timer that sends typing activity indicators to the user
254
+ * at regular intervals. The typing indicator continues until a message is sent
255
+ * or the timer is explicitly stopped.
256
+ *
257
+ * The typing indicator helps provide feedback to users that the agent is processing
258
+ * their message, especially when responses might take time to generate.
259
+ *
260
+ * Example usage:
261
+ * ```typescript
262
+ * app.startTypingTimer(turnContext);
263
+ * // Do some processing...
264
+ * await turnContext.sendActivity('Response after processing');
265
+ * // Typing timer automatically stops when sending a message
266
+ * ```
267
+ */
39
268
  startTypingTimer(context: TurnContext): void;
269
+ /**
270
+ * Stops the typing indicator timer if it's currently running.
271
+ *
272
+ * @returns void
273
+ *
274
+ * @remarks
275
+ * This method clears the typing indicator timer to prevent further typing indicators
276
+ * from being sent. It's typically called automatically when a message is sent, but
277
+ * can also be called manually to stop the typing indicator.
278
+ *
279
+ * Example usage:
280
+ * ```typescript
281
+ * app.startTypingTimer(turnContext);
282
+ * // Do some processing...
283
+ * app.stopTypingTimer(); // Manually stop the typing indicator
284
+ * ```
285
+ */
40
286
  stopTypingTimer(): void;
287
+ /**
288
+ * Adds an event handler for specified turn events.
289
+ *
290
+ * @param event - The turn event(s) to handle. Can be 'beforeTurn', 'afterTurn', or other custom events.
291
+ * @param handler - The handler function that will be called when the event occurs.
292
+ * @returns The current instance of the application.
293
+ *
294
+ * @remarks
295
+ * Turn events allow you to execute logic before or after the main turn processing.
296
+ * Handlers added for 'beforeTurn' are executed before routing logic.
297
+ * Handlers added for 'afterTurn' are executed after routing logic.
298
+ *
299
+ * Example usage:
300
+ * ```typescript
301
+ * app.turn('beforeTurn', async (context, state) => {
302
+ * console.log('Processing before turn');
303
+ * return true; // Continue execution
304
+ * });
305
+ * ```
306
+ */
41
307
  turn(event: TurnEvents | TurnEvents[], handler: (context: TurnContext, state: TState) => Promise<boolean>): this;
42
308
  protected callEventHandlers(context: TurnContext, state: TState, handlers: ApplicationEventHandler<TState>[]): Promise<boolean>;
43
309
  protected startLongRunningCall(context: TurnContext, handler: (context: TurnContext) => Promise<boolean>): Promise<boolean>;
@@ -45,4 +311,3 @@ export declare class AgentApplication<TState extends TurnState> {
45
311
  private createConversationUpdateSelector;
46
312
  private createMessageSelector;
47
313
  }
48
- export {};