@microsoft/agents-hosting 0.5.12-g2d752e9b13 → 0.5.16-g6bdf69cc43
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.
- package/dist/src/app/agentApplication.d.ts +186 -20
- package/dist/src/app/agentApplication.js +234 -32
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +1 -1
- package/dist/src/app/appRoute.d.ts +5 -0
- package/dist/src/app/authorization.d.ts +293 -0
- package/dist/src/app/authorization.js +375 -0
- package/dist/src/app/authorization.js.map +1 -0
- package/dist/src/app/index.d.ts +1 -1
- package/dist/src/app/index.js +1 -1
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/auth/index.d.ts +1 -0
- package/dist/src/auth/index.js +1 -0
- package/dist/src/auth/index.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalTokenCredential.d.ts +10 -0
- package/dist/src/auth/msalTokenCredential.js +19 -0
- package/dist/src/auth/msalTokenCredential.js.map +1 -0
- package/dist/src/auth/msalTokenProvider.d.ts +1 -0
- package/dist/src/auth/msalTokenProvider.js +15 -0
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/oauth/oAuthFlow.d.ts +53 -9
- package/dist/src/oauth/oAuthFlow.js +164 -35
- package/dist/src/oauth/oAuthFlow.js.map +1 -1
- package/package.json +4 -3
- package/src/app/agentApplication.ts +247 -32
- package/src/app/agentApplicationBuilder.ts +1 -1
- package/src/app/agentApplicationOptions.ts +1 -1
- package/src/app/appRoute.ts +6 -0
- package/src/app/authorization.ts +418 -0
- package/src/app/index.ts +1 -1
- package/src/auth/index.ts +1 -0
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/auth/msalTokenCredential.ts +14 -0
- package/src/auth/msalTokenProvider.ts +17 -1
- package/src/oauth/oAuthFlow.ts +196 -34
- package/dist/src/app/oauth/authorization.d.ts +0 -88
- package/dist/src/app/oauth/authorization.js +0 -134
- package/dist/src/app/oauth/authorization.js.map +0 -1
- package/src/app/oauth/authorization.ts +0 -160
|
@@ -11,26 +11,48 @@ import { AgentApplicationOptions } from './agentApplicationOptions';
|
|
|
11
11
|
import { AppRoute } from './appRoute';
|
|
12
12
|
import { ConversationUpdateEvents } from './conversationUpdateEvents';
|
|
13
13
|
import { AgentExtension } from './extensions';
|
|
14
|
-
import { Authorization } from './
|
|
14
|
+
import { Authorization } from './authorization';
|
|
15
15
|
import { RouteHandler } from './routeHandler';
|
|
16
16
|
import { RouteSelector } from './routeSelector';
|
|
17
17
|
import { TurnEvents } from './turnEvents';
|
|
18
18
|
import { TurnState } from './turnState';
|
|
19
|
+
/**
|
|
20
|
+
* Event handler function type for application events.
|
|
21
|
+
* @template TState - The state type extending TurnState.
|
|
22
|
+
* @param context - The turn context containing activity information.
|
|
23
|
+
* @param state - The current turn state.
|
|
24
|
+
* @returns A promise that resolves to a boolean indicating whether to continue execution.
|
|
25
|
+
*/
|
|
19
26
|
export type ApplicationEventHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<boolean>;
|
|
20
27
|
/**
|
|
21
|
-
*
|
|
28
|
+
* Main application class for handling agent conversations and routing.
|
|
22
29
|
*
|
|
23
|
-
* @
|
|
24
|
-
* @returns A promise that resolves when the application logic has completed.
|
|
30
|
+
* @template TState - The state type extending TurnState.
|
|
25
31
|
*
|
|
26
32
|
* @remarks
|
|
27
|
-
*
|
|
28
|
-
* It
|
|
29
|
-
*
|
|
33
|
+
* The AgentApplication class provides a framework for building conversational agents.
|
|
34
|
+
* It handles routing activities to appropriate handlers, manages conversation state,
|
|
35
|
+
* supports authentication flows, and provides various event handling capabilities.
|
|
36
|
+
*
|
|
37
|
+
* Key features:
|
|
38
|
+
* - Activity routing based on type, content, or custom selectors
|
|
39
|
+
* - State management with automatic load/save
|
|
40
|
+
* - OAuth authentication support
|
|
41
|
+
* - Typing indicators and long-running message support
|
|
42
|
+
* - Extensible architecture with custom extensions
|
|
43
|
+
* - Event handlers for before/after turn processing
|
|
30
44
|
*
|
|
31
45
|
* Example usage:
|
|
32
46
|
* ```typescript
|
|
33
|
-
* const app = new AgentApplication(
|
|
47
|
+
* const app = new AgentApplication<MyState>({
|
|
48
|
+
* storage: myStorage,
|
|
49
|
+
* adapter: myAdapter
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* app.onMessage('hello', async (context, state) => {
|
|
53
|
+
* await context.sendActivity('Hello there!');
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
34
56
|
* await app.run(turnContext);
|
|
35
57
|
* ```
|
|
36
58
|
*/
|
|
@@ -44,22 +66,68 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
44
66
|
private _typingTimer;
|
|
45
67
|
protected readonly _extensions: AgentExtension<TState>[];
|
|
46
68
|
private readonly _adaptiveCards;
|
|
47
|
-
constructor(options?: Partial<AgentApplicationOptions<TState>>);
|
|
48
69
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
70
|
+
* Creates a new instance of AgentApplication.
|
|
71
|
+
*
|
|
72
|
+
* @param options - Optional configuration options for the application.
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* The constructor initializes the application with default settings and applies
|
|
76
|
+
* any provided options. It sets up the adapter, authorization, and other core
|
|
77
|
+
* components based on the configuration.
|
|
78
|
+
*
|
|
79
|
+
* Default options:
|
|
80
|
+
* - startTypingTimer: false
|
|
81
|
+
* - longRunningMessages: false
|
|
82
|
+
* - removeRecipientMention: true
|
|
83
|
+
* - turnStateFactory: Creates a new TurnState instance
|
|
84
|
+
*
|
|
85
|
+
* Example usage:
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const app = new AgentApplication({
|
|
88
|
+
* storage: myStorage,
|
|
89
|
+
* adapter: myAdapter,
|
|
90
|
+
* startTypingTimer: true,
|
|
91
|
+
* authorization: { connectionName: 'oauth' }
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
51
94
|
*/
|
|
52
|
-
|
|
95
|
+
constructor(options?: Partial<AgentApplicationOptions<TState>>);
|
|
53
96
|
/**
|
|
54
97
|
* Gets the authorization instance for the application.
|
|
98
|
+
*
|
|
99
|
+
* @returns The authorization instance.
|
|
55
100
|
* @throws Error if no authentication options were configured.
|
|
56
101
|
*/
|
|
57
102
|
get authorization(): Authorization;
|
|
58
103
|
/**
|
|
59
104
|
* Gets the options used to configure the application.
|
|
105
|
+
*
|
|
60
106
|
* @returns The application options.
|
|
61
107
|
*/
|
|
62
108
|
get options(): AgentApplicationOptions<TState>;
|
|
109
|
+
/**
|
|
110
|
+
* Gets the adapter used by the application.
|
|
111
|
+
*
|
|
112
|
+
* @returns The adapter instance.
|
|
113
|
+
*/
|
|
114
|
+
get adapter(): BaseAdapter;
|
|
115
|
+
/**
|
|
116
|
+
* Gets the adaptive cards actions handler for the application.
|
|
117
|
+
*
|
|
118
|
+
* @returns The adaptive cards actions instance.
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* The adaptive cards actions handler provides functionality for handling
|
|
122
|
+
* adaptive card interactions, such as submit actions and other card-based events.
|
|
123
|
+
*
|
|
124
|
+
* Example usage:
|
|
125
|
+
* ```typescript
|
|
126
|
+
* app.adaptiveCards.onSubmit('myCardId', async (context, state, data) => {
|
|
127
|
+
* await context.sendActivity(`Received data: ${JSON.stringify(data)}`);
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
63
131
|
get adaptiveCards(): AdaptiveCardsActions<TState>;
|
|
64
132
|
/**
|
|
65
133
|
* Sets an error handler for the application.
|
|
@@ -85,6 +153,8 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
85
153
|
*
|
|
86
154
|
* @param selector - The selector function that determines if a route should handle the current activity.
|
|
87
155
|
* @param handler - The handler function that will be called if the selector returns true.
|
|
156
|
+
* @param isInvokeRoute - Whether this route is for invoke activities. Defaults to false.
|
|
157
|
+
* @param authHandlers - Array of authentication handler names for this route. Defaults to empty array.
|
|
88
158
|
* @returns The current instance of the application.
|
|
89
159
|
*
|
|
90
160
|
* @remarks
|
|
@@ -100,12 +170,13 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
100
170
|
* );
|
|
101
171
|
* ```
|
|
102
172
|
*/
|
|
103
|
-
addRoute(selector: RouteSelector, handler: RouteHandler<TState>, isInvokeRoute?: boolean): this;
|
|
173
|
+
addRoute(selector: RouteSelector, handler: RouteHandler<TState>, isInvokeRoute?: boolean, authHandlers?: string[]): this;
|
|
104
174
|
/**
|
|
105
175
|
* Adds a handler for specific activity types.
|
|
106
176
|
*
|
|
107
177
|
* @param type - The activity type(s) to handle. Can be a string, RegExp, RouteSelector, or array of these types.
|
|
108
178
|
* @param handler - The handler function that will be called when the specified activity type is received.
|
|
179
|
+
* @param authHandlers - Array of authentication handler names for this activity. Defaults to empty array.
|
|
109
180
|
* @returns The current instance of the application.
|
|
110
181
|
*
|
|
111
182
|
* @remarks
|
|
@@ -119,12 +190,13 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
119
190
|
* });
|
|
120
191
|
* ```
|
|
121
192
|
*/
|
|
122
|
-
onActivity(type: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState) => Promise<void
|
|
193
|
+
onActivity(type: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState) => Promise<void>, authHandlers?: string[]): this;
|
|
123
194
|
/**
|
|
124
195
|
* Adds a handler for conversation update events.
|
|
125
196
|
*
|
|
126
197
|
* @param event - The conversation update event to handle (e.g., 'membersAdded', 'membersRemoved').
|
|
127
198
|
* @param handler - The handler function that will be called when the specified event occurs.
|
|
199
|
+
* @param authHandlers - Array of authentication handler names for this event. Defaults to empty array.
|
|
128
200
|
* @returns The current instance of the application.
|
|
129
201
|
* @throws Error if the handler is not a function.
|
|
130
202
|
*
|
|
@@ -143,9 +215,10 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
143
215
|
* });
|
|
144
216
|
* ```
|
|
145
217
|
*/
|
|
146
|
-
onConversationUpdate(event: ConversationUpdateEvents, handler: (context: TurnContext, state: TState) => Promise<void
|
|
218
|
+
onConversationUpdate(event: ConversationUpdateEvents, handler: (context: TurnContext, state: TState) => Promise<void>, authHandlers?: string[]): this;
|
|
147
219
|
/**
|
|
148
220
|
* Continues a conversation asynchronously.
|
|
221
|
+
*
|
|
149
222
|
* @param conversationReferenceOrContext - The conversation reference or turn context.
|
|
150
223
|
* @param logic - The logic to execute during the conversation.
|
|
151
224
|
* @returns A promise that resolves when the conversation logic has completed.
|
|
@@ -158,6 +231,7 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
158
231
|
* @param keyword - The keyword, pattern, or selector function to match against message text.
|
|
159
232
|
* Can be a string, RegExp, RouteSelector, or array of these types.
|
|
160
233
|
* @param handler - The handler function that will be called when a matching message is received.
|
|
234
|
+
* @param authHandlers - Array of authentication handler names for this message handler. Defaults to empty array.
|
|
161
235
|
* @returns The current instance of the application.
|
|
162
236
|
*
|
|
163
237
|
* @remarks
|
|
@@ -172,12 +246,12 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
172
246
|
* await context.sendActivity('Hello there!');
|
|
173
247
|
* });
|
|
174
248
|
*
|
|
175
|
-
* app.onMessage(/help
|
|
249
|
+
* app.onMessage(/help/, async (context, state) => {
|
|
176
250
|
* await context.sendActivity('How can I help you?');
|
|
177
251
|
* });
|
|
178
252
|
* ```
|
|
179
253
|
*/
|
|
180
|
-
onMessage(keyword: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState) => Promise<void
|
|
254
|
+
onMessage(keyword: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState) => Promise<void>, authHandlers?: string[]): this;
|
|
181
255
|
/**
|
|
182
256
|
* Sets a handler to be called when a user successfully signs in.
|
|
183
257
|
*
|
|
@@ -196,7 +270,26 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
196
270
|
* });
|
|
197
271
|
* ```
|
|
198
272
|
*/
|
|
199
|
-
onSignInSuccess(handler: (context: TurnContext, state: TurnState, id?: string) => void): this;
|
|
273
|
+
onSignInSuccess(handler: (context: TurnContext, state: TurnState, id?: string) => Promise<void>): this;
|
|
274
|
+
/**
|
|
275
|
+
* Sets a handler to be called when a sign-in attempt fails.
|
|
276
|
+
*
|
|
277
|
+
* @param handler - The handler function to be called after a failed sign-in attempt.
|
|
278
|
+
* @returns The current instance of the application.
|
|
279
|
+
* @throws Error if authentication options were not configured.
|
|
280
|
+
*
|
|
281
|
+
* @remarks
|
|
282
|
+
* This method allows you to handle cases where a user fails to authenticate,
|
|
283
|
+
* such as when they cancel the sign-in process or an error occurs.
|
|
284
|
+
*
|
|
285
|
+
* Example usage:
|
|
286
|
+
* ```typescript
|
|
287
|
+
* app.onSignInFailure(async (context, state) => {
|
|
288
|
+
* await context.sendActivity('Sign-in failed. Please try again.');
|
|
289
|
+
* });
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
onSignInFailure(handler: (context: TurnContext, state: TurnState, id?: string) => Promise<void>): this;
|
|
200
293
|
/**
|
|
201
294
|
* Adds a handler for message reaction added events.
|
|
202
295
|
*
|
|
@@ -259,13 +352,33 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
259
352
|
run(turnContext: TurnContext): Promise<void>;
|
|
260
353
|
/**
|
|
261
354
|
* Executes the application logic for a given turn context.
|
|
262
|
-
*
|
|
355
|
+
*
|
|
263
356
|
* @param turnContext - The context for the current turn of the conversation.
|
|
264
357
|
* @returns A promise that resolves to true if a handler was executed, false otherwise.
|
|
265
358
|
*
|
|
266
359
|
* @remarks
|
|
267
|
-
* This
|
|
360
|
+
* This is the core internal method that processes a turn in the conversation.
|
|
268
361
|
* It handles routing and executing handlers based on the activity type and content.
|
|
362
|
+
* While this method is public, it's typically called internally by the `run` method.
|
|
363
|
+
*
|
|
364
|
+
* The method performs the following operations:
|
|
365
|
+
* 1. Starts typing timer if configured
|
|
366
|
+
* 2. Processes mentions if configured
|
|
367
|
+
* 3. Loads turn state
|
|
368
|
+
* 4. Handles authentication flows
|
|
369
|
+
* 5. Executes before-turn event handlers
|
|
370
|
+
* 6. Downloads files if file downloaders are configured
|
|
371
|
+
* 7. Routes to appropriate handlers
|
|
372
|
+
* 8. Executes after-turn event handlers
|
|
373
|
+
* 9. Saves turn state
|
|
374
|
+
*
|
|
375
|
+
* Example usage:
|
|
376
|
+
* ```typescript
|
|
377
|
+
* const handled = await app.runInternal(turnContext);
|
|
378
|
+
* if (!handled) {
|
|
379
|
+
* console.log('No handler matched the activity');
|
|
380
|
+
* }
|
|
381
|
+
* ```
|
|
269
382
|
*/
|
|
270
383
|
runInternal(turnContext: TurnContext): Promise<boolean>;
|
|
271
384
|
/**
|
|
@@ -313,6 +426,26 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
313
426
|
* ```
|
|
314
427
|
*/
|
|
315
428
|
startTypingTimer(context: TurnContext): void;
|
|
429
|
+
/**
|
|
430
|
+
* Registers an extension with the application.
|
|
431
|
+
*
|
|
432
|
+
* @template T - The extension type extending AgentExtension.
|
|
433
|
+
* @param extension - The extension instance to register.
|
|
434
|
+
* @param regcb - Callback function called after successful registration.
|
|
435
|
+
* @throws Error if the extension is already registered.
|
|
436
|
+
*
|
|
437
|
+
* @remarks
|
|
438
|
+
* Extensions provide a way to add custom functionality to the application.
|
|
439
|
+
* Each extension can only be registered once to prevent conflicts.
|
|
440
|
+
*
|
|
441
|
+
* Example usage:
|
|
442
|
+
* ```typescript
|
|
443
|
+
* const myExtension = new MyCustomExtension();
|
|
444
|
+
* app.registerExtension(myExtension, (ext) => {
|
|
445
|
+
* console.log('Extension registered:', ext.name);
|
|
446
|
+
* });
|
|
447
|
+
* ```
|
|
448
|
+
*/
|
|
316
449
|
registerExtension<T extends AgentExtension<TState>>(extension: T, regcb: (ext: T) => void): void;
|
|
317
450
|
/**
|
|
318
451
|
* Stops the typing indicator timer if it's currently running.
|
|
@@ -353,9 +486,42 @@ export declare class AgentApplication<TState extends TurnState> {
|
|
|
353
486
|
* ```
|
|
354
487
|
*/
|
|
355
488
|
onTurn(event: TurnEvents | TurnEvents[], handler: (context: TurnContext, state: TState) => Promise<boolean>): this;
|
|
489
|
+
/**
|
|
490
|
+
* Calls a series of event handlers in sequence.
|
|
491
|
+
*
|
|
492
|
+
* @param context - The turn context for the current conversation.
|
|
493
|
+
* @param state - The current turn state.
|
|
494
|
+
* @param handlers - Array of event handlers to call.
|
|
495
|
+
* @returns A promise that resolves to true if all handlers returned true, false otherwise.
|
|
496
|
+
*/
|
|
356
497
|
protected callEventHandlers(context: TurnContext, state: TState, handlers: ApplicationEventHandler<TState>[]): Promise<boolean>;
|
|
498
|
+
/**
|
|
499
|
+
* Starts a long-running call, potentially in a new conversation context.
|
|
500
|
+
*
|
|
501
|
+
* @param context - The turn context for the current conversation.
|
|
502
|
+
* @param handler - The handler function to execute.
|
|
503
|
+
* @returns A promise that resolves to the result of the handler.
|
|
504
|
+
*/
|
|
357
505
|
protected startLongRunningCall(context: TurnContext, handler: (context: TurnContext) => Promise<boolean>): Promise<boolean>;
|
|
506
|
+
/**
|
|
507
|
+
* Creates a selector function for activity types.
|
|
508
|
+
*
|
|
509
|
+
* @param type - The activity type to match. Can be a string, RegExp, or RouteSelector function.
|
|
510
|
+
* @returns A RouteSelector function that matches the specified activity type.
|
|
511
|
+
*/
|
|
358
512
|
private createActivitySelector;
|
|
513
|
+
/**
|
|
514
|
+
* Creates a selector function for conversation update events.
|
|
515
|
+
*
|
|
516
|
+
* @param event - The conversation update event to match.
|
|
517
|
+
* @returns A RouteSelector function that matches the specified conversation update event.
|
|
518
|
+
*/
|
|
359
519
|
private createConversationUpdateSelector;
|
|
520
|
+
/**
|
|
521
|
+
* Creates a selector function for message content matching.
|
|
522
|
+
*
|
|
523
|
+
* @param keyword - The keyword, pattern, or selector function to match against message text.
|
|
524
|
+
* @returns A RouteSelector function that matches messages based on the specified keyword.
|
|
525
|
+
*/
|
|
360
526
|
private createMessageSelector;
|
|
361
527
|
}
|