@microsoft/agents-hosting 1.0.0 → 1.0.7-g73d3d58001
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/package.json +3 -3
- package/dist/src/activityHandler.d.ts +0 -1
- package/dist/src/activityHandler.js +0 -1
- package/dist/src/activityHandler.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.d.ts +6 -6
- package/dist/src/agent-client/agentResponseHandler.js +6 -6
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +12 -4
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js +5 -1
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -1
- package/dist/src/app/adaptiveCards/index.d.ts +2 -0
- package/dist/src/app/adaptiveCards/index.js +2 -0
- package/dist/src/app/adaptiveCards/index.js.map +1 -1
- package/dist/src/app/agentApplication.d.ts +24 -7
- package/dist/src/app/agentApplication.js +24 -7
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +1 -1
- package/dist/src/app/appRoute.d.ts +8 -4
- package/dist/src/app/attachmentDownloader.d.ts +3 -1
- package/dist/src/app/attachmentDownloader.js +3 -1
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/authorization.d.ts +26 -18
- package/dist/src/app/authorization.js +26 -18
- package/dist/src/app/authorization.js.map +1 -1
- package/dist/src/app/index.d.ts +2 -0
- package/dist/src/app/index.js +2 -0
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/routeRank.d.ts +10 -3
- package/dist/src/app/routeRank.js +10 -3
- package/dist/src/app/routeRank.js.map +1 -1
- package/dist/src/app/streaming/streamingResponse.d.ts +23 -2
- package/dist/src/app/streaming/streamingResponse.js +23 -2
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/app/turnState.d.ts +69 -19
- package/dist/src/app/turnState.js +69 -19
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +16 -9
- package/dist/src/auth/authConfiguration.js +11 -6
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +26 -18
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/cards/adaptiveCard.d.ts +1 -1
- package/dist/src/cloudAdapter.js +1 -0
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/headerPropagation.d.ts +18 -6
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +2 -2
- package/dist/src/oauth/userTokenClient.js +2 -2
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/state/agentState.d.ts +23 -7
- package/dist/src/state/agentState.js +19 -7
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/state/agentStatePropertyAccesor.d.ts +63 -41
- package/dist/src/state/agentStatePropertyAccesor.js +43 -32
- package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
- package/dist/src/storage/fileStorage.d.ts +8 -6
- package/dist/src/storage/fileStorage.js +8 -6
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/memoryStorage.d.ts +12 -7
- package/dist/src/storage/memoryStorage.js +12 -7
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/storage/storage.d.ts +18 -1
- package/dist/src/turnContext.d.ts +31 -25
- package/dist/src/turnContext.js +31 -20
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +3 -3
- package/src/activityHandler.ts +0 -1
- package/src/agent-client/agentResponseHandler.ts +6 -6
- package/src/app/adaptiveCards/adaptiveCardsActions.ts +12 -4
- package/src/app/adaptiveCards/index.ts +2 -0
- package/src/app/agentApplication.ts +24 -7
- package/src/app/agentApplicationOptions.ts +1 -1
- package/src/app/appRoute.ts +8 -4
- package/src/app/attachmentDownloader.ts +3 -1
- package/src/app/authorization.ts +26 -18
- package/src/app/index.ts +2 -0
- package/src/app/routeRank.ts +10 -3
- package/src/app/streaming/streamingResponse.ts +23 -2
- package/src/app/turnState.ts +69 -19
- package/src/auth/authConfiguration.ts +16 -9
- package/src/auth/jwt-middleware.ts +24 -17
- package/src/cards/adaptiveCard.ts +1 -1
- package/src/cloudAdapter.ts +2 -0
- package/src/headerPropagation.ts +18 -6
- package/src/index.ts +1 -0
- package/src/oauth/userTokenClient.ts +2 -2
- package/src/state/agentState.ts +23 -7
- package/src/state/agentStatePropertyAccesor.ts +63 -41
- package/src/storage/fileStorage.ts +8 -6
- package/src/storage/memoryStorage.ts +12 -7
- package/src/storage/storage.ts +18 -1
- package/src/turnContext.ts +31 -25
|
@@ -36,7 +36,9 @@ const TYPING_TIMER_DELAY = 1000
|
|
|
36
36
|
export type ApplicationEventHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<boolean>
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Main application class for handling agent conversations and routing.
|
|
40
|
+
*
|
|
41
|
+
* @typeParam TState - The state type extending TurnState.
|
|
40
42
|
*
|
|
41
43
|
* @remarks
|
|
42
44
|
* The AgentApplication class provides a framework for building conversational agents.
|
|
@@ -65,7 +67,6 @@ export type ApplicationEventHandler<TState extends TurnState> = (context: TurnCo
|
|
|
65
67
|
* await app.run(turnContext);
|
|
66
68
|
* ```
|
|
67
69
|
*
|
|
68
|
-
* @typeParam TState - The state type extending TurnState.
|
|
69
70
|
*/
|
|
70
71
|
export class AgentApplication<TState extends TurnState> {
|
|
71
72
|
protected readonly _options: AgentApplicationOptions<TState>
|
|
@@ -79,7 +80,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
79
80
|
private readonly _adaptiveCards: AdaptiveCardsActions<TState>
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
|
-
*
|
|
83
|
+
* Creates a new instance of AgentApplication.
|
|
83
84
|
*
|
|
84
85
|
* @param options - Optional configuration options for the application.
|
|
85
86
|
*
|
|
@@ -142,7 +143,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
/**
|
|
145
|
-
*
|
|
146
|
+
* Gets the authorization instance for the application.
|
|
146
147
|
*
|
|
147
148
|
* @returns The authorization instance.
|
|
148
149
|
* @throws Error if no authentication options were configured.
|
|
@@ -155,7 +156,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
/**
|
|
158
|
-
*
|
|
159
|
+
* Gets the options used to configure the application.
|
|
159
160
|
*
|
|
160
161
|
* @returns The application options.
|
|
161
162
|
*/
|
|
@@ -164,7 +165,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
/**
|
|
167
|
-
*
|
|
168
|
+
* Gets the adapter used by the application.
|
|
168
169
|
*
|
|
169
170
|
* @returns The adapter instance.
|
|
170
171
|
*/
|
|
@@ -173,7 +174,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
/**
|
|
176
|
-
*
|
|
177
|
+
* Gets the adaptive cards actions handler for the application.
|
|
177
178
|
*
|
|
178
179
|
* @returns The adaptive cards actions instance.
|
|
179
180
|
*
|
|
@@ -209,6 +210,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
209
210
|
* await context.sendActivity('Sorry, something went wrong!');
|
|
210
211
|
* });
|
|
211
212
|
* ```
|
|
213
|
+
*
|
|
212
214
|
*/
|
|
213
215
|
public onError (handler: (context: TurnContext, error: Error) => Promise<void>): this {
|
|
214
216
|
if (this._adapter) {
|
|
@@ -243,6 +245,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
243
245
|
* RouteRank.First // rank
|
|
244
246
|
* );
|
|
245
247
|
* ```
|
|
248
|
+
*
|
|
246
249
|
*/
|
|
247
250
|
public addRoute (selector: RouteSelector, handler: RouteHandler<TState>, isInvokeRoute: boolean = false, rank: number = RouteRank.Unspecified, authHandlers: string[] = []): this {
|
|
248
251
|
this._routes.addRoute(selector, handler, isInvokeRoute, rank, authHandlers)
|
|
@@ -268,6 +271,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
268
271
|
* await context.sendActivity('I received your message');
|
|
269
272
|
* });
|
|
270
273
|
* ```
|
|
274
|
+
*
|
|
271
275
|
*/
|
|
272
276
|
public onActivity (
|
|
273
277
|
type: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[],
|
|
@@ -306,6 +310,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
306
310
|
* }
|
|
307
311
|
* });
|
|
308
312
|
* ```
|
|
313
|
+
*
|
|
309
314
|
*/
|
|
310
315
|
public onConversationUpdate (
|
|
311
316
|
event: ConversationUpdateEvents,
|
|
@@ -383,6 +388,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
383
388
|
* await context.sendActivity('How can I help you?');
|
|
384
389
|
* });
|
|
385
390
|
* ```
|
|
391
|
+
*
|
|
386
392
|
*/
|
|
387
393
|
public onMessage (
|
|
388
394
|
keyword: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[],
|
|
@@ -414,6 +420,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
414
420
|
* await context.sendActivity('You have successfully signed in!');
|
|
415
421
|
* });
|
|
416
422
|
* ```
|
|
423
|
+
*
|
|
417
424
|
*/
|
|
418
425
|
public onSignInSuccess (handler: (context: TurnContext, state: TurnState, id?: string) => Promise<void>): this {
|
|
419
426
|
if (this.options.authorization) {
|
|
@@ -443,6 +450,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
443
450
|
* await context.sendActivity('Sign-in failed. Please try again.');
|
|
444
451
|
* });
|
|
445
452
|
* ```
|
|
453
|
+
*
|
|
446
454
|
*/
|
|
447
455
|
public onSignInFailure (handler: (context: TurnContext, state: TurnState, id?: string) => Promise<void>): this {
|
|
448
456
|
if (this.options.authorization) {
|
|
@@ -475,6 +483,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
475
483
|
* }
|
|
476
484
|
* });
|
|
477
485
|
* ```
|
|
486
|
+
*
|
|
478
487
|
*/
|
|
479
488
|
public onMessageReactionAdded (
|
|
480
489
|
handler: (context: TurnContext, state: TState) => Promise<void>,
|
|
@@ -509,6 +518,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
509
518
|
* }
|
|
510
519
|
* });
|
|
511
520
|
* ```
|
|
521
|
+
*
|
|
512
522
|
*/
|
|
513
523
|
public onMessageReactionRemoved (
|
|
514
524
|
handler: (context: TurnContext, state: TState) => Promise<void>,
|
|
@@ -539,6 +549,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
539
549
|
* const app = new AgentApplication();
|
|
540
550
|
* await app.run(turnContext);
|
|
541
551
|
* ```
|
|
552
|
+
*
|
|
542
553
|
*/
|
|
543
554
|
public async run (turnContext:TurnContext): Promise<void> {
|
|
544
555
|
await this.runInternal(turnContext)
|
|
@@ -573,6 +584,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
573
584
|
* console.log('No handler matched the activity');
|
|
574
585
|
* }
|
|
575
586
|
* ```
|
|
587
|
+
*
|
|
576
588
|
*/
|
|
577
589
|
public async runInternal (turnContext: TurnContext): Promise<boolean> {
|
|
578
590
|
logger.info('Running application with activity:', turnContext.activity.id!)
|
|
@@ -688,6 +700,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
688
700
|
* // From an existing context
|
|
689
701
|
* await app.sendProactiveActivity(turnContext, 'Important notification!');
|
|
690
702
|
* ```
|
|
703
|
+
*
|
|
691
704
|
*/
|
|
692
705
|
public async sendProactiveActivity (
|
|
693
706
|
context: TurnContext | ConversationReference,
|
|
@@ -724,6 +737,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
724
737
|
* await turnContext.sendActivity('Response after processing');
|
|
725
738
|
* // Typing timer automatically stops when sending a message
|
|
726
739
|
* ```
|
|
740
|
+
*
|
|
727
741
|
*/
|
|
728
742
|
public startTypingTimer (context: TurnContext): void {
|
|
729
743
|
if (context.activity.type === ActivityTypes.Message && !this._typingTimer) {
|
|
@@ -782,6 +796,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
782
796
|
* console.log('Extension registered:', ext.name);
|
|
783
797
|
* });
|
|
784
798
|
* ```
|
|
799
|
+
*
|
|
785
800
|
*/
|
|
786
801
|
public registerExtension<T extends AgentExtension<TState>> (extension: T, regcb : (ext:T) => void): void {
|
|
787
802
|
if (this._extensions.includes(extension)) {
|
|
@@ -807,6 +822,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
807
822
|
* // Do some processing...
|
|
808
823
|
* app.stopTypingTimer(); // Manually stop the typing indicator
|
|
809
824
|
* ```
|
|
825
|
+
*
|
|
810
826
|
*/
|
|
811
827
|
public stopTypingTimer (): void {
|
|
812
828
|
if (this._typingTimer) {
|
|
@@ -834,6 +850,7 @@ export class AgentApplication<TState extends TurnState> {
|
|
|
834
850
|
* return true; // Continue execution
|
|
835
851
|
* });
|
|
836
852
|
* ```
|
|
853
|
+
*
|
|
837
854
|
*/
|
|
838
855
|
public onTurn (
|
|
839
856
|
event: TurnEvents | TurnEvents[],
|
|
@@ -120,7 +120,7 @@ export interface AgentApplicationOptions<TState extends TurnState> {
|
|
|
120
120
|
* Whether to automatically normalize mentions in incoming messages.
|
|
121
121
|
* When enabled, user mentions and other entity mentions in messages will be
|
|
122
122
|
* standardized to a consistent format, making them easier to process and understand.
|
|
123
|
-
* This includes formatting
|
|
123
|
+
* This includes formatting mentions and channel references consistently.
|
|
124
124
|
*
|
|
125
125
|
* @default true
|
|
126
126
|
*/
|
package/src/app/appRoute.ts
CHANGED
|
@@ -10,14 +10,14 @@ import { TurnState } from './turnState'
|
|
|
10
10
|
/**
|
|
11
11
|
* Represents a route configuration for handling bot activities within an application.
|
|
12
12
|
*
|
|
13
|
+
* @typeParam TState - The type of turn state that extends TurnState, allowing for
|
|
14
|
+
* type-safe access to custom state properties within route handlers
|
|
15
|
+
*
|
|
13
16
|
* @remarks
|
|
14
17
|
* An AppRoute defines how incoming activities are matched and processed by combining
|
|
15
18
|
* a selector function that determines when the route should be activated with a handler
|
|
16
19
|
* function that processes the matched activities.
|
|
17
20
|
*
|
|
18
|
-
* @typeParam TState - The type of turn state that extends TurnState, allowing for
|
|
19
|
-
* type-safe access to custom state properties within route handlers
|
|
20
|
-
*
|
|
21
21
|
* @example
|
|
22
22
|
* ```typescript
|
|
23
23
|
* const echoRoute: AppRoute<MyTurnState> = {
|
|
@@ -27,6 +27,7 @@ import { TurnState } from './turnState'
|
|
|
27
27
|
* }
|
|
28
28
|
* };
|
|
29
29
|
* ```
|
|
30
|
+
*
|
|
30
31
|
*/
|
|
31
32
|
export interface AppRoute<TState extends TurnState> {
|
|
32
33
|
/**
|
|
@@ -53,18 +54,20 @@ export interface AppRoute<TState extends TurnState> {
|
|
|
53
54
|
/**
|
|
54
55
|
* Indicates whether this route is an invoke route.
|
|
55
56
|
*
|
|
57
|
+
* @default false
|
|
58
|
+
*
|
|
56
59
|
* @remarks
|
|
57
60
|
* Invoke routes are used for specific types of activities, such as messaging extensions,
|
|
58
61
|
* adaptive card actions, or other invoke-based interactions. When set to true, this route
|
|
59
62
|
* will be processed differently than regular message routes, typically with special
|
|
60
63
|
* handling for invoke responses.
|
|
61
64
|
*
|
|
62
|
-
* @default false
|
|
63
65
|
*/
|
|
64
66
|
isInvokeRoute?: boolean;
|
|
65
67
|
|
|
66
68
|
/**
|
|
67
69
|
* Optional rank of the route, used to determine the order in which routes are evaluated.
|
|
70
|
+
*
|
|
68
71
|
* 0 - number.MAX_VALUE. Ranks of the same value are evaluated in order of addition.
|
|
69
72
|
*/
|
|
70
73
|
rank?: number;
|
|
@@ -82,6 +85,7 @@ export interface AppRoute<TState extends TurnState> {
|
|
|
82
85
|
* ```typescript
|
|
83
86
|
* authHandlers: ['oauth', 'admin-only']
|
|
84
87
|
* ```
|
|
88
|
+
*
|
|
85
89
|
*/
|
|
86
90
|
authHandlers?: string[]
|
|
87
91
|
}
|
|
@@ -17,11 +17,12 @@ const logger = debug('agents:attachmentDownloader')
|
|
|
17
17
|
/**
|
|
18
18
|
* A utility class for downloading input files from activity attachments.
|
|
19
19
|
*
|
|
20
|
+
* @typeParam TState - The type of the turn state used in the application.
|
|
21
|
+
*
|
|
20
22
|
* @remarks
|
|
21
23
|
* This class provides functionality to filter and download attachments from a turn context,
|
|
22
24
|
* supporting various content types and handling authentication for secure URLs.
|
|
23
25
|
*
|
|
24
|
-
* @typeParam TState - The type of the turn state used in the application.
|
|
25
26
|
*/
|
|
26
27
|
export class AttachmentDownloader<TState extends TurnState = TurnState> implements InputFileDownloader<TState> {
|
|
27
28
|
private _httpClient: AxiosInstance
|
|
@@ -36,6 +37,7 @@ export class AttachmentDownloader<TState extends TurnState = TurnState> implemen
|
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* Downloads files from the attachments in the current turn context.
|
|
40
|
+
*
|
|
39
41
|
* @param context The turn context containing the activity with attachments.
|
|
40
42
|
* @param state The turn state for the current conversation.
|
|
41
43
|
* @returns A promise that resolves to an array of downloaded input files.
|
package/src/app/authorization.ts
CHANGED
|
@@ -67,7 +67,7 @@ export interface AuthorizationHandlers extends Record<string, AuthHandler> {}
|
|
|
67
67
|
* - Sign-in success/failure event handling
|
|
68
68
|
* - Automatic configuration from environment variables
|
|
69
69
|
*
|
|
70
|
-
*
|
|
70
|
+
* @example
|
|
71
71
|
* ```typescript
|
|
72
72
|
* const auth = new Authorization(storage, {
|
|
73
73
|
* 'microsoft': {
|
|
@@ -81,6 +81,7 @@ export interface AuthorizationHandlers extends Record<string, AuthHandler> {}
|
|
|
81
81
|
* await context.sendActivity('Welcome! You are now signed in.');
|
|
82
82
|
* });
|
|
83
83
|
* ```
|
|
84
|
+
*
|
|
84
85
|
*/
|
|
85
86
|
export class Authorization {
|
|
86
87
|
/**
|
|
@@ -92,10 +93,6 @@ export class Authorization {
|
|
|
92
93
|
/**
|
|
93
94
|
* Creates a new instance of Authorization.
|
|
94
95
|
*
|
|
95
|
-
* @param storage - The storage system to use for state management.
|
|
96
|
-
* @param authHandlers - Configuration for OAuth providers.
|
|
97
|
-
* @throws {Error} If storage is null/undefined or no auth handlers are provided.
|
|
98
|
-
*
|
|
99
96
|
* @remarks
|
|
100
97
|
* The constructor initializes all configured auth handlers and sets up OAuth flows.
|
|
101
98
|
* It automatically configures handler properties from environment variables if not provided:
|
|
@@ -103,7 +100,7 @@ export class Authorization {
|
|
|
103
100
|
* - Connection title: {handlerId}_connectionTitle
|
|
104
101
|
* - Connection text: {handlerId}_connectionText
|
|
105
102
|
*
|
|
106
|
-
*
|
|
103
|
+
* @example
|
|
107
104
|
* ```typescript
|
|
108
105
|
* const auth = new Authorization(storage, {
|
|
109
106
|
* 'microsoft': {
|
|
@@ -115,6 +112,11 @@ export class Authorization {
|
|
|
115
112
|
* }
|
|
116
113
|
* });
|
|
117
114
|
* ```
|
|
115
|
+
*
|
|
116
|
+
* @param storage - The storage system to use for state management.
|
|
117
|
+
* @param authHandlers - Configuration for OAuth providers.
|
|
118
|
+
* @throws {Error} If storage is null/undefined or no auth handlers are provided.
|
|
119
|
+
*
|
|
118
120
|
*/
|
|
119
121
|
constructor (private storage: Storage, authHandlers: AuthorizationHandlers, userTokenClient: UserTokenClient) {
|
|
120
122
|
if (storage === undefined || storage === null) {
|
|
@@ -145,19 +147,20 @@ export class Authorization {
|
|
|
145
147
|
* @param authHandlerId - ID of the auth handler to use.
|
|
146
148
|
* @returns A promise that resolves to the token response from the OAuth provider.
|
|
147
149
|
* @throws {Error} If the auth handler is not configured.
|
|
148
|
-
* @public
|
|
149
150
|
*
|
|
150
151
|
* @remarks
|
|
151
152
|
* This method retrieves an existing token for the specified auth handler.
|
|
152
153
|
* The token may be cached and will be retrieved from the OAuth provider if needed.
|
|
153
154
|
*
|
|
154
|
-
*
|
|
155
|
+
* @example
|
|
155
156
|
* ```typescript
|
|
156
157
|
* const tokenResponse = await auth.getToken(context, 'microsoft');
|
|
157
158
|
* if (tokenResponse.token) {
|
|
158
159
|
* console.log('User is authenticated');
|
|
159
160
|
* }
|
|
160
161
|
* ```
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
161
164
|
*/
|
|
162
165
|
public async getToken (context: TurnContext, authHandlerId: string): Promise<TokenResponse> {
|
|
163
166
|
logger.info('getToken from user token service for authHandlerId:', authHandlerId)
|
|
@@ -188,14 +191,13 @@ export class Authorization {
|
|
|
188
191
|
* @param authHandlerId - ID of the auth handler to use.
|
|
189
192
|
* @returns A promise that resolves to the exchanged token response.
|
|
190
193
|
* @throws {Error} If the auth handler is not configured.
|
|
191
|
-
* @public
|
|
192
194
|
*
|
|
193
195
|
* @remarks
|
|
194
196
|
* This method handles token exchange scenarios, particularly for on-behalf-of (OBO) flows.
|
|
195
197
|
* It checks if the current token is exchangeable (e.g., has audience starting with 'api://')
|
|
196
198
|
* and performs the appropriate token exchange using MSAL.
|
|
197
199
|
*
|
|
198
|
-
*
|
|
200
|
+
* @example
|
|
199
201
|
* ```typescript
|
|
200
202
|
* const exchangedToken = await auth.exchangeToken(
|
|
201
203
|
* context,
|
|
@@ -203,6 +205,8 @@ export class Authorization {
|
|
|
203
205
|
* 'microsoft'
|
|
204
206
|
* );
|
|
205
207
|
* ```
|
|
208
|
+
*
|
|
209
|
+
* @public
|
|
206
210
|
*/
|
|
207
211
|
public async exchangeToken (context: TurnContext, scopes: string[], authHandlerId: string): Promise<TokenResponse> {
|
|
208
212
|
logger.info('exchangeToken from user token service for authHandlerId:', authHandlerId)
|
|
@@ -256,7 +260,6 @@ export class Authorization {
|
|
|
256
260
|
* @param authHandlerId - ID of the auth handler to use.
|
|
257
261
|
* @returns A promise that resolves to the token response from the OAuth provider.
|
|
258
262
|
* @throws {Error} If the auth handler is not configured.
|
|
259
|
-
* @public
|
|
260
263
|
*
|
|
261
264
|
* @remarks
|
|
262
265
|
* This method manages the complete OAuth authentication flow:
|
|
@@ -267,7 +270,7 @@ export class Authorization {
|
|
|
267
270
|
* The method automatically manages the sign-in state and continuation activities,
|
|
268
271
|
* allowing the conversation to resume after successful authentication.
|
|
269
272
|
*
|
|
270
|
-
*
|
|
273
|
+
* @example
|
|
271
274
|
* ```typescript
|
|
272
275
|
* const tokenResponse = await auth.beginOrContinueFlow(context, state, 'microsoft');
|
|
273
276
|
* if (tokenResponse && tokenResponse.token) {
|
|
@@ -275,6 +278,8 @@ export class Authorization {
|
|
|
275
278
|
* await context.sendActivity('Authentication successful!');
|
|
276
279
|
* }
|
|
277
280
|
* ```
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
278
283
|
*/
|
|
279
284
|
public async beginOrContinueFlow (context: TurnContext, state: TurnState, authHandlerId: string, secRoute: boolean = true) : Promise<TokenResponse> {
|
|
280
285
|
const authHandler = this.getAuthHandlerOrThrow(authHandlerId)
|
|
@@ -329,14 +334,13 @@ export class Authorization {
|
|
|
329
334
|
* @param authHandlerId - Optional ID of the auth handler to use for sign out. If not provided, signs out from all handlers.
|
|
330
335
|
* @returns A promise that resolves when sign out is complete.
|
|
331
336
|
* @throws {Error} If the specified auth handler is not configured.
|
|
332
|
-
* @public
|
|
333
337
|
*
|
|
334
338
|
* @remarks
|
|
335
339
|
* This method clears the user's token and resets the authentication state.
|
|
336
340
|
* If no specific authHandlerId is provided, it signs out from all configured handlers.
|
|
337
341
|
* This ensures complete cleanup of authentication state across all providers.
|
|
338
342
|
*
|
|
339
|
-
*
|
|
343
|
+
* @example
|
|
340
344
|
* ```typescript
|
|
341
345
|
* // Sign out from specific handler
|
|
342
346
|
* await auth.signOut(context, state, 'microsoft');
|
|
@@ -344,6 +348,8 @@ export class Authorization {
|
|
|
344
348
|
* // Sign out from all handlers
|
|
345
349
|
* await auth.signOut(context, state);
|
|
346
350
|
* ```
|
|
351
|
+
*
|
|
352
|
+
* @public
|
|
347
353
|
*/
|
|
348
354
|
async signOut (context: TurnContext, state: TurnState, authHandlerId?: string) : Promise<void> {
|
|
349
355
|
logger.info('signOut for authHandlerId:', authHandlerId)
|
|
@@ -368,20 +374,21 @@ export class Authorization {
|
|
|
368
374
|
* Sets a handler to be called when sign-in is successfully completed.
|
|
369
375
|
*
|
|
370
376
|
* @param handler - The handler function to call on successful sign-in.
|
|
371
|
-
* @public
|
|
372
377
|
*
|
|
373
378
|
* @remarks
|
|
374
379
|
* This method allows you to register a callback that will be invoked whenever
|
|
375
380
|
* a user successfully completes the authentication process. The handler receives
|
|
376
381
|
* the turn context, state, and the ID of the auth handler that was used.
|
|
377
382
|
*
|
|
378
|
-
*
|
|
383
|
+
* @example
|
|
379
384
|
* ```typescript
|
|
380
385
|
* auth.onSignInSuccess(async (context, state, authHandlerId) => {
|
|
381
386
|
* await context.sendActivity(`Welcome! You signed in using ${authHandlerId}.`);
|
|
382
387
|
* // Perform any post-authentication setup
|
|
383
388
|
* });
|
|
384
389
|
* ```
|
|
390
|
+
*
|
|
391
|
+
* @public
|
|
385
392
|
*/
|
|
386
393
|
public onSignInSuccess (handler: (context: TurnContext, state: TurnState, authHandlerId?: string) => Promise<void>) {
|
|
387
394
|
this._signInSuccessHandler = handler
|
|
@@ -397,7 +404,6 @@ export class Authorization {
|
|
|
397
404
|
* Sets a handler to be called when sign-in fails.
|
|
398
405
|
*
|
|
399
406
|
* @param handler - The handler function to call on sign-in failure.
|
|
400
|
-
* @public
|
|
401
407
|
*
|
|
402
408
|
* @remarks
|
|
403
409
|
* This method allows you to register a callback that will be invoked whenever
|
|
@@ -410,13 +416,15 @@ export class Authorization {
|
|
|
410
416
|
* - Network connectivity issues
|
|
411
417
|
* - OAuth provider errors
|
|
412
418
|
*
|
|
413
|
-
*
|
|
419
|
+
* @example
|
|
414
420
|
* ```typescript
|
|
415
421
|
* auth.onSignInFailure(async (context, state, authHandlerId, errorMessage) => {
|
|
416
422
|
* await context.sendActivity(`Sign-in failed: ${errorMessage || 'Unknown error'}`);
|
|
417
423
|
* await context.sendActivity('Please try signing in again.');
|
|
418
424
|
* });
|
|
419
425
|
* ```
|
|
426
|
+
*
|
|
427
|
+
* @public
|
|
420
428
|
*/
|
|
421
429
|
public onSignInFailure (handler: (context: TurnContext, state: TurnState, authHandlerId?: string, errorMessage?: string) => Promise<void>) {
|
|
422
430
|
this._signInFailureHandler = handler
|
package/src/app/index.ts
CHANGED
package/src/app/routeRank.ts
CHANGED
|
@@ -26,10 +26,13 @@
|
|
|
26
26
|
* this.onMessage('dupText', handler1, undefined, RouteRank.Last);
|
|
27
27
|
* this.onMessage('dupText', handler2, undefined, RouteRank.First); // This executes first
|
|
28
28
|
* ```
|
|
29
|
+
*
|
|
29
30
|
*/
|
|
30
31
|
export enum RouteRank {
|
|
31
32
|
/**
|
|
32
|
-
* Highest priority rank (value: 0).
|
|
33
|
+
* Highest priority rank (value: 0).
|
|
34
|
+
*
|
|
35
|
+
* Routes with this rank are evaluated
|
|
33
36
|
* before any other routes. Use this for critical routes that must take precedence
|
|
34
37
|
* over all others, such as high-priority message handlers or override handlers
|
|
35
38
|
* that should execute before any other matching routes.
|
|
@@ -37,7 +40,9 @@ export enum RouteRank {
|
|
|
37
40
|
First = 0,
|
|
38
41
|
|
|
39
42
|
/**
|
|
40
|
-
* Lowest priority rank (value: Number.MAX_VALUE).
|
|
43
|
+
* Lowest priority rank (value: Number.MAX_VALUE).
|
|
44
|
+
*
|
|
45
|
+
* Routes with this rank are
|
|
41
46
|
* evaluated last, after all other routes have been considered. Ideal for
|
|
42
47
|
* catch-all message handlers, fallback activity handlers, or default responses
|
|
43
48
|
* that should only match when no other routes apply.
|
|
@@ -45,7 +50,9 @@ export enum RouteRank {
|
|
|
45
50
|
Last = Number.MAX_VALUE,
|
|
46
51
|
|
|
47
52
|
/**
|
|
48
|
-
* Default priority rank (value: Number.MAX_VALUE / 2).
|
|
53
|
+
* Default priority rank (value: Number.MAX_VALUE / 2).
|
|
54
|
+
*
|
|
55
|
+
* This is the standard
|
|
49
56
|
* rank for most routes that don't require special ordering. Routes with this
|
|
50
57
|
* rank are evaluated after high-priority routes but before low-priority ones.
|
|
51
58
|
* Use this when you don't need to specify a particular evaluation order.
|
|
@@ -13,6 +13,7 @@ const logger = debug('agents:streamingResponse')
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* A helper class for streaming responses to the client.
|
|
16
|
+
*
|
|
16
17
|
* @remarks
|
|
17
18
|
* This class is used to send a series of updates to the client in a single response. The expected
|
|
18
19
|
* sequence of calls is:
|
|
@@ -43,6 +44,7 @@ export class StreamingResponse {
|
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* Creates a new StreamingResponse instance.
|
|
47
|
+
*
|
|
46
48
|
* @param {TurnContext} context - Context for the current turn of conversation with the user.
|
|
47
49
|
* @returns {TurnContext} - The context for the current turn of conversation with the user.
|
|
48
50
|
*/
|
|
@@ -52,7 +54,9 @@ export class StreamingResponse {
|
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* Gets the stream ID of the current response.
|
|
57
|
+
*
|
|
55
58
|
* @returns {string | undefined} - The stream ID of the current response.
|
|
59
|
+
*
|
|
56
60
|
* @remarks
|
|
57
61
|
* Assigned after the initial update is sent.
|
|
58
62
|
*/
|
|
@@ -69,6 +73,7 @@ export class StreamingResponse {
|
|
|
69
73
|
|
|
70
74
|
/**
|
|
71
75
|
* Gets the number of updates sent for the stream.
|
|
76
|
+
*
|
|
72
77
|
* @returns {number} - The number of updates sent for the stream.
|
|
73
78
|
*/
|
|
74
79
|
public get updatesSent (): number {
|
|
@@ -77,6 +82,7 @@ export class StreamingResponse {
|
|
|
77
82
|
|
|
78
83
|
/**
|
|
79
84
|
* Queues an informative update to be sent to the client.
|
|
85
|
+
*
|
|
80
86
|
* @param {string} text Text of the update to send.
|
|
81
87
|
*/
|
|
82
88
|
public queueInformativeUpdate (text: string): void {
|
|
@@ -98,11 +104,14 @@ export class StreamingResponse {
|
|
|
98
104
|
|
|
99
105
|
/**
|
|
100
106
|
* Queues a chunk of partial message text to be sent to the client
|
|
107
|
+
*
|
|
108
|
+
* @param {string} text Partial text of the message to send.
|
|
109
|
+
* @param {Citation[]} citations Citations to be included in the message.
|
|
110
|
+
*
|
|
101
111
|
* @remarks
|
|
102
112
|
* The text we be sent as quickly as possible to the client. Chunks may be combined before
|
|
103
113
|
* delivery to the client.
|
|
104
|
-
*
|
|
105
|
-
* @param {Citation[]} citations Citations to be included in the message.
|
|
114
|
+
*
|
|
106
115
|
*/
|
|
107
116
|
public queueTextChunk (text: string, citations?: Citation[]): void {
|
|
108
117
|
if (this._ended) {
|
|
@@ -121,6 +130,7 @@ export class StreamingResponse {
|
|
|
121
130
|
|
|
122
131
|
/**
|
|
123
132
|
* Ends the stream by sending the final message to the client.
|
|
133
|
+
*
|
|
124
134
|
* @returns {Promise<void>} - A promise representing the async operation
|
|
125
135
|
*/
|
|
126
136
|
public endStream (): Promise<void> {
|
|
@@ -138,6 +148,7 @@ export class StreamingResponse {
|
|
|
138
148
|
|
|
139
149
|
/**
|
|
140
150
|
* Sets the attachments to attach to the final chunk.
|
|
151
|
+
*
|
|
141
152
|
* @param attachments List of attachments.
|
|
142
153
|
*/
|
|
143
154
|
public setAttachments (attachments: Attachment[]): void {
|
|
@@ -146,6 +157,7 @@ export class StreamingResponse {
|
|
|
146
157
|
|
|
147
158
|
/**
|
|
148
159
|
* Sets the sensitivity label to attach to the final chunk.
|
|
160
|
+
*
|
|
149
161
|
* @param sensitivityLabel The sensitivty label.
|
|
150
162
|
*/
|
|
151
163
|
public setSensitivityLabel (sensitivityLabel: SensitivityUsageInfo): void {
|
|
@@ -154,6 +166,7 @@ export class StreamingResponse {
|
|
|
154
166
|
|
|
155
167
|
/**
|
|
156
168
|
* Sets the citations for the full message.
|
|
169
|
+
*
|
|
157
170
|
* @param {Citation[]} citations Citations to be included in the message.
|
|
158
171
|
*/
|
|
159
172
|
public setCitations (citations: Citation[]): void {
|
|
@@ -183,6 +196,7 @@ export class StreamingResponse {
|
|
|
183
196
|
* Sets the Feedback Loop in Teams that allows a user to
|
|
184
197
|
* give thumbs up or down to a response.
|
|
185
198
|
* Default is `false`.
|
|
199
|
+
*
|
|
186
200
|
* @param enableFeedbackLoop If true, the feedback loop is enabled.
|
|
187
201
|
*/
|
|
188
202
|
public setFeedbackLoop (enableFeedbackLoop: boolean): void {
|
|
@@ -191,6 +205,7 @@ export class StreamingResponse {
|
|
|
191
205
|
|
|
192
206
|
/**
|
|
193
207
|
* Sets the type of UI to use for the feedback loop.
|
|
208
|
+
*
|
|
194
209
|
* @param feedbackLoopType The type of the feedback loop.
|
|
195
210
|
*/
|
|
196
211
|
public setFeedbackLoopType (feedbackLoopType: 'default' | 'custom'): void {
|
|
@@ -200,6 +215,7 @@ export class StreamingResponse {
|
|
|
200
215
|
/**
|
|
201
216
|
* Sets the the Generated by AI label in Teams
|
|
202
217
|
* Default is `false`.
|
|
218
|
+
*
|
|
203
219
|
* @param enableGeneratedByAILabel If true, the label is added.
|
|
204
220
|
*/
|
|
205
221
|
public setGeneratedByAILabel (enableGeneratedByAILabel: boolean): void {
|
|
@@ -208,6 +224,7 @@ export class StreamingResponse {
|
|
|
208
224
|
|
|
209
225
|
/**
|
|
210
226
|
* Returns the most recently streamed message.
|
|
227
|
+
*
|
|
211
228
|
* @returns The streamed message.
|
|
212
229
|
*/
|
|
213
230
|
public getMessage (): string {
|
|
@@ -216,6 +233,7 @@ export class StreamingResponse {
|
|
|
216
233
|
|
|
217
234
|
/**
|
|
218
235
|
* Waits for the outgoing activity queue to be empty.
|
|
236
|
+
*
|
|
219
237
|
* @returns {Promise<void>} - A promise representing the async operation.
|
|
220
238
|
*/
|
|
221
239
|
public waitForQueue (): Promise<void> {
|
|
@@ -224,6 +242,7 @@ export class StreamingResponse {
|
|
|
224
242
|
|
|
225
243
|
/**
|
|
226
244
|
* Queues the next chunk of text to be sent to the client.
|
|
245
|
+
*
|
|
227
246
|
* @private
|
|
228
247
|
*/
|
|
229
248
|
private queueNextChunk (): void {
|
|
@@ -280,6 +299,7 @@ export class StreamingResponse {
|
|
|
280
299
|
|
|
281
300
|
/**
|
|
282
301
|
* Sends any queued activities to the client until the queue is empty.
|
|
302
|
+
*
|
|
283
303
|
* @returns {Promise<void>} - A promise that will be resolved once the queue is empty.
|
|
284
304
|
* @private
|
|
285
305
|
*/
|
|
@@ -305,6 +325,7 @@ export class StreamingResponse {
|
|
|
305
325
|
|
|
306
326
|
/**
|
|
307
327
|
* Sends an activity to the client and saves the stream ID returned.
|
|
328
|
+
*
|
|
308
329
|
* @param {Activity} activity - The activity to send.
|
|
309
330
|
* @returns {Promise<void>} - A promise representing the async operation.
|
|
310
331
|
* @private
|