@microsoft/agents-hosting 1.5.0-beta.2.gf6783d691c → 1.5.0-beta.26.gaab35a7b76
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 +10 -9
- package/dist/src/activityHandler.js +2 -2
- package/dist/src/activityHandler.js.map +1 -1
- package/dist/src/agent-client/agentClient.js +49 -40
- package/dist/src/agent-client/agentClient.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.js +2 -2
- package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
- package/dist/src/app/agentApplication.d.ts +53 -19
- package/dist/src/app/agentApplication.js +201 -117
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +15 -0
- package/dist/src/app/agentApplicationBuilder.js +22 -4
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +38 -0
- package/dist/src/app/attachmentDownloader.js +2 -2
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/auth/authorization.js +12 -9
- package/dist/src/app/auth/authorization.js.map +1 -1
- package/dist/src/app/auth/authorizationManager.d.ts +22 -5
- package/dist/src/app/auth/authorizationManager.js +268 -54
- package/dist/src/app/auth/authorizationManager.js.map +1 -1
- package/dist/src/app/auth/handlerStorage.js +3 -1
- package/dist/src/app/auth/handlerStorage.js.map +1 -1
- package/dist/src/app/auth/handlers/agenticAuthorization.d.ts +19 -16
- package/dist/src/app/auth/handlers/agenticAuthorization.js +46 -52
- package/dist/src/app/auth/handlers/agenticAuthorization.js.map +1 -1
- package/dist/src/app/auth/handlers/azureBotAuthorization.d.ts +51 -75
- package/dist/src/app/auth/handlers/azureBotAuthorization.js +217 -192
- package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -1
- package/dist/src/app/auth/types.d.ts +100 -1
- package/dist/src/app/auth/utils.d.ts +10 -0
- package/dist/src/app/auth/utils.js +21 -0
- package/dist/src/app/auth/utils.js.map +1 -0
- package/dist/src/app/index.d.ts +1 -0
- package/dist/src/app/index.js +1 -0
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/proactive/conversation.d.ts +43 -0
- package/dist/src/app/proactive/conversation.js +67 -0
- package/dist/src/app/proactive/conversation.js.map +1 -0
- package/dist/src/app/proactive/conversationBuilder.d.ts +54 -0
- package/dist/src/app/proactive/conversationBuilder.js +110 -0
- package/dist/src/app/proactive/conversationBuilder.js.map +1 -0
- package/dist/src/app/proactive/conversationReferenceBuilder.d.ts +68 -0
- package/dist/src/app/proactive/conversationReferenceBuilder.js +125 -0
- package/dist/src/app/proactive/conversationReferenceBuilder.js.map +1 -0
- package/dist/src/app/proactive/createConversationOptions.d.ts +30 -0
- package/dist/src/app/proactive/createConversationOptions.js +10 -0
- package/dist/src/app/proactive/createConversationOptions.js.map +1 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.d.ts +69 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.js +141 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -0
- package/dist/src/app/proactive/index.d.ts +7 -0
- package/dist/src/app/proactive/index.js +26 -0
- package/dist/src/app/proactive/index.js.map +1 -0
- package/dist/src/app/proactive/proactive.d.ts +248 -0
- package/dist/src/app/proactive/proactive.js +310 -0
- package/dist/src/app/proactive/proactive.js.map +1 -0
- package/dist/src/app/proactive/proactiveOptions.d.ts +19 -0
- package/dist/src/app/proactive/proactiveOptions.js +5 -0
- package/dist/src/app/proactive/proactiveOptions.js.map +1 -0
- package/dist/src/app/streaming/streamingResponse.js +2 -2
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/app/teamsAttachmentDownloader.js +2 -2
- package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
- package/dist/src/app/turnState.js +2 -2
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +61 -0
- package/dist/src/auth/authConfiguration.js +52 -3
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +2 -2
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalConnectionManager.js +20 -0
- package/dist/src/auth/msalConnectionManager.js.map +1 -1
- package/dist/src/auth/msalTokenCredential.js +3 -0
- package/dist/src/auth/msalTokenCredential.js.map +1 -1
- package/dist/src/auth/msalTokenProvider.js +136 -110
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/baseAdapter.js +2 -2
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cloudAdapter.js +201 -154
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.js +176 -127
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/errorHelper.js +108 -0
- package/dist/src/errorHelper.js.map +1 -1
- package/dist/src/middlewareSet.js +2 -2
- package/dist/src/middlewareSet.js.map +1 -1
- package/dist/src/oauth/userTokenClient.js +78 -48
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/observability/index.d.ts +2 -0
- package/dist/src/observability/index.js +21 -0
- package/dist/src/observability/index.js.map +1 -0
- package/dist/src/observability/metrics.d.ts +21 -0
- package/dist/src/observability/metrics.js +87 -0
- package/dist/src/observability/metrics.js.map +1 -0
- package/dist/src/observability/traces.d.ts +234 -0
- package/dist/src/observability/traces.js +962 -0
- package/dist/src/observability/traces.js.map +1 -0
- package/dist/src/state/agentState.js +2 -2
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/storage/fileStorage.js +38 -28
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/memoryStorage.js +41 -30
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/transcript/fileTranscriptLogger.js +2 -2
- package/dist/src/transcript/fileTranscriptLogger.js.map +1 -1
- package/dist/src/transcript/transcriptLoggerMiddleware.js +2 -2
- package/dist/src/transcript/transcriptLoggerMiddleware.js.map +1 -1
- package/dist/src/turnContext.js +55 -43
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +10 -9
- package/src/activityHandler.ts +1 -1
- package/src/agent-client/agentClient.ts +53 -42
- package/src/agent-client/agentResponseHandler.ts +1 -1
- package/src/app/agentApplication.ts +248 -104
- package/src/app/agentApplicationBuilder.ts +26 -4
- package/src/app/agentApplicationOptions.ts +43 -0
- package/src/app/attachmentDownloader.ts +1 -1
- package/src/app/auth/authorization.ts +11 -8
- package/src/app/auth/authorizationManager.ts +311 -54
- package/src/app/auth/handlerStorage.ts +3 -1
- package/src/app/auth/handlers/agenticAuthorization.ts +68 -72
- package/src/app/auth/handlers/azureBotAuthorization.ts +260 -264
- package/src/app/auth/types.ts +102 -1
- package/src/app/auth/utils.ts +22 -0
- package/src/app/index.ts +1 -0
- package/src/app/proactive/conversation.ts +87 -0
- package/src/app/proactive/conversationBuilder.ts +139 -0
- package/src/app/proactive/conversationReferenceBuilder.ts +161 -0
- package/src/app/proactive/createConversationOptions.ts +35 -0
- package/src/app/proactive/createConversationOptionsBuilder.ts +181 -0
- package/src/app/proactive/index.ts +10 -0
- package/src/app/proactive/proactive.ts +524 -0
- package/src/app/proactive/proactiveOptions.ts +24 -0
- package/src/app/streaming/streamingResponse.ts +1 -1
- package/src/app/teamsAttachmentDownloader.ts +1 -1
- package/src/app/turnState.ts +1 -1
- package/src/auth/authConfiguration.ts +58 -1
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/auth/msalConnectionManager.ts +22 -0
- package/src/auth/msalTokenCredential.ts +4 -0
- package/src/auth/msalTokenProvider.ts +138 -107
- package/src/baseAdapter.ts +1 -1
- package/src/cloudAdapter.ts +239 -184
- package/src/connector-client/connectorClient.ts +169 -126
- package/src/errorHelper.ts +124 -0
- package/src/middlewareSet.ts +1 -1
- package/src/oauth/userTokenClient.ts +70 -46
- package/src/observability/index.ts +5 -0
- package/src/observability/metrics.ts +103 -0
- package/src/observability/traces.ts +988 -0
- package/src/state/agentState.ts +1 -1
- package/src/storage/fileStorage.ts +36 -26
- package/src/storage/memoryStorage.ts +40 -29
- package/src/transcript/fileTranscriptLogger.ts +1 -1
- package/src/transcript/transcriptLoggerMiddleware.ts +1 -1
- package/src/turnContext.ts +53 -42
|
@@ -11,6 +11,33 @@ import { TurnState } from './turnState';
|
|
|
11
11
|
import { HeaderPropagationDefinition } from '../headerPropagation';
|
|
12
12
|
import { AuthorizationOptions } from './auth/types';
|
|
13
13
|
import { Connections } from '../auth/connections';
|
|
14
|
+
import { ProactiveOptions } from './proactive';
|
|
15
|
+
/**
|
|
16
|
+
* Typing timer settings for a specific channel or the global default.
|
|
17
|
+
*/
|
|
18
|
+
export interface TypingTimingOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Delay in milliseconds before the first typing indicator is sent.
|
|
21
|
+
*
|
|
22
|
+
* @default 0
|
|
23
|
+
*/
|
|
24
|
+
initialDelayMs?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Delay in milliseconds between subsequent typing indicators.
|
|
27
|
+
*
|
|
28
|
+
* @default 4000
|
|
29
|
+
*/
|
|
30
|
+
intervalMs?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options for automatic typing indicators.
|
|
34
|
+
*/
|
|
35
|
+
export interface TypingOptions extends TypingTimingOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Optional channel-specific timing overrides keyed by channel ID.
|
|
38
|
+
*/
|
|
39
|
+
channelStrategies?: Record<string, TypingTimingOptions>;
|
|
40
|
+
}
|
|
14
41
|
/**
|
|
15
42
|
* Configuration options for creating and initializing an Agent Application.
|
|
16
43
|
* This interface defines all the configurable aspects of an agent's behavior,
|
|
@@ -53,6 +80,12 @@ export interface AgentApplicationOptions<TState extends TurnState> {
|
|
|
53
80
|
* @default false
|
|
54
81
|
*/
|
|
55
82
|
startTypingTimer: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Optional timing settings for automatic typing indicators.
|
|
85
|
+
*
|
|
86
|
+
* @default undefined
|
|
87
|
+
*/
|
|
88
|
+
typing?: TypingOptions;
|
|
56
89
|
/**
|
|
57
90
|
* Whether to enable support for long-running message processing operations.
|
|
58
91
|
* When enabled, the agent can handle operations that take longer than the typical
|
|
@@ -132,4 +165,9 @@ export interface AgentApplicationOptions<TState extends TurnState> {
|
|
|
132
165
|
* identity providers.
|
|
133
166
|
*/
|
|
134
167
|
connections?: Connections;
|
|
168
|
+
/**
|
|
169
|
+
* Optional. Configuration for the proactive messaging subsystem.
|
|
170
|
+
* When provided, `app.proactive` will be available.
|
|
171
|
+
*/
|
|
172
|
+
proactive?: ProactiveOptions;
|
|
135
173
|
}
|
|
@@ -9,9 +9,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.AttachmentDownloader = void 0;
|
|
11
11
|
const axios_1 = __importDefault(require("axios"));
|
|
12
|
-
const
|
|
12
|
+
const agents_telemetry_1 = require("@microsoft/agents-telemetry");
|
|
13
13
|
const auth_1 = require("../auth");
|
|
14
|
-
const logger = (0,
|
|
14
|
+
const logger = (0, agents_telemetry_1.debug)('agents:attachmentDownloader');
|
|
15
15
|
/**
|
|
16
16
|
* A utility class for downloading input files from activity attachments.
|
|
17
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachmentDownloader.js","sourceRoot":"","sources":["../../../src/app/attachmentDownloader.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,kDAA4C;AAM5C,
|
|
1
|
+
{"version":3,"file":"attachmentDownloader.js","sourceRoot":"","sources":["../../../src/app/attachmentDownloader.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,kDAA4C;AAM5C,kEAAmD;AACnD,kCAAkE;AAElE,MAAM,MAAM,GAAG,IAAA,wBAAK,EAAC,6BAA6B,CAAC,CAAA;AAEnD;;;;;;;;;GASG;AACH,MAAa,oBAAoB;IAI/B;;;;;OAKG;IACH,YAAoB,WAAmB,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"__esModule", { value: true });
|
|
7
7
|
exports.UserAuthorization = void 0;
|
|
8
|
-
const
|
|
8
|
+
const agents_telemetry_1 = require("@microsoft/agents-telemetry");
|
|
9
|
+
const agents_activity_1 = require("@microsoft/agents-activity");
|
|
9
10
|
const turnState_1 = require("../turnState");
|
|
10
|
-
const
|
|
11
|
+
const errorHelper_1 = require("../../errorHelper");
|
|
12
|
+
const logger = (0, agents_telemetry_1.debug)('agents:authorization');
|
|
11
13
|
/**
|
|
12
14
|
* Class responsible for managing authorization and OAuth flows.
|
|
13
15
|
* Handles multiple OAuth providers and manages the complete authentication lifecycle.
|
|
@@ -76,7 +78,7 @@ class UserAuthorization {
|
|
|
76
78
|
const { token } = await handler.token(context, options);
|
|
77
79
|
return { token };
|
|
78
80
|
}
|
|
79
|
-
throw
|
|
81
|
+
throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.InvalidExchangeTokenParameters);
|
|
80
82
|
}
|
|
81
83
|
/**
|
|
82
84
|
* Signs out the current user.
|
|
@@ -108,7 +110,7 @@ class UserAuthorization {
|
|
|
108
110
|
await this.getHandler(authHandlerId).signout(context);
|
|
109
111
|
}
|
|
110
112
|
else {
|
|
111
|
-
for (const handler of
|
|
113
|
+
for (const handler of this.manager.handlers) {
|
|
112
114
|
await handler.signout(context);
|
|
113
115
|
}
|
|
114
116
|
}
|
|
@@ -134,7 +136,7 @@ class UserAuthorization {
|
|
|
134
136
|
* @public
|
|
135
137
|
*/
|
|
136
138
|
onSignInSuccess(handler) {
|
|
137
|
-
for (const authHandler of
|
|
139
|
+
for (const authHandler of this.manager.handlers) {
|
|
138
140
|
authHandler.onSuccess((context) => handler(context, new turnState_1.TurnState(), authHandler.id));
|
|
139
141
|
}
|
|
140
142
|
}
|
|
@@ -165,7 +167,7 @@ class UserAuthorization {
|
|
|
165
167
|
* @public
|
|
166
168
|
*/
|
|
167
169
|
onSignInFailure(handler) {
|
|
168
|
-
for (const authHandler of
|
|
170
|
+
for (const authHandler of this.manager.handlers) {
|
|
169
171
|
authHandler.onFailure((context, reason) => handler(context, new turnState_1.TurnState(), authHandler.id, reason));
|
|
170
172
|
}
|
|
171
173
|
}
|
|
@@ -178,10 +180,11 @@ class UserAuthorization {
|
|
|
178
180
|
* @private
|
|
179
181
|
*/
|
|
180
182
|
getHandler(id) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
const handler = this.manager.handlers.find(e => e.id.toLowerCase() === id.toLowerCase());
|
|
184
|
+
if (!handler) {
|
|
185
|
+
throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.AuthHandlerNotFound, undefined, { handlerId: id });
|
|
183
186
|
}
|
|
184
|
-
return
|
|
187
|
+
return handler;
|
|
185
188
|
}
|
|
186
189
|
}
|
|
187
190
|
exports.UserAuthorization = UserAuthorization;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../../src/app/auth/authorization.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../../src/app/auth/authorization.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAmD;AACnD,gEAA4D;AAG5D,4CAAwC;AAGxC,mDAA0C;AAE1C,MAAM,MAAM,GAAG,IAAA,wBAAK,EAAC,sBAAsB,CAAC,CAAA;AAW5C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,iBAAiB;IAC5B;;;OAGG;IACH,YAAqB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAEtD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,KAAK,CAAC,QAAQ,CAAE,OAAoB,EAAE,aAAqB;QAChE,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;QAC9C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QA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IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACI,eAAe,CAAE,OAA0F;QAChH,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAChD,WAAW,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,qBAAS,EAAE,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,CAAA;QACvF,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,eAAe,CAAE,OAAiH;QACvI,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAChD,WAAW,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,qBAAS,EAAE,EAAE,WAAW,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAA;QACvG,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,UAAU,CAAE,EAAU;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA;QACxF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,iCAAe,CAAC,iBAAiB,CAAC,KAAK,EAAE,oBAAM,CAAC,mBAAmB,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAA;QAC1G,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AA7ND,8CA6NC"}
|
|
@@ -15,6 +15,10 @@ interface AuthorizationManagerProcessResult {
|
|
|
15
15
|
* Indicates whether the authorization was successful.
|
|
16
16
|
*/
|
|
17
17
|
authorized: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The context associated with the authorization process.
|
|
20
|
+
*/
|
|
21
|
+
context: TurnContext;
|
|
18
22
|
}
|
|
19
23
|
/**
|
|
20
24
|
* Function to retrieve handler IDs for the current activity.
|
|
@@ -30,21 +34,26 @@ type GetHandlerIds = (activity: Activity) => string[] | Promise<string[]>;
|
|
|
30
34
|
*/
|
|
31
35
|
export declare class AuthorizationManager {
|
|
32
36
|
private app;
|
|
37
|
+
private connections;
|
|
33
38
|
private _handlers;
|
|
39
|
+
/**
|
|
40
|
+
* Environment variable configuration for the latest format.
|
|
41
|
+
*/
|
|
42
|
+
private _envLatest;
|
|
43
|
+
/**
|
|
44
|
+
* Environment variable configuration for the legacy format.
|
|
45
|
+
*/
|
|
46
|
+
private _envLegacy;
|
|
34
47
|
/**
|
|
35
48
|
* Creates an instance of the AuthorizationManager.
|
|
36
49
|
* @param app The agent application instance.
|
|
37
50
|
*/
|
|
38
51
|
constructor(app: AgentApplication<any>, connections: Connections);
|
|
39
|
-
/**
|
|
40
|
-
* Loads and validates the authorization handler options.
|
|
41
|
-
*/
|
|
42
|
-
private loadOptions;
|
|
43
52
|
/**
|
|
44
53
|
* Gets the registered authorization handlers.
|
|
45
54
|
* @returns A record of authorization handlers by their IDs.
|
|
46
55
|
*/
|
|
47
|
-
get handlers():
|
|
56
|
+
get handlers(): AuthorizationHandler[];
|
|
48
57
|
/**
|
|
49
58
|
* Processes an authorization request.
|
|
50
59
|
* @param context The turn context.
|
|
@@ -68,5 +77,13 @@ export declare class AuthorizationManager {
|
|
|
68
77
|
* Prefixes a message with the handler ID.
|
|
69
78
|
*/
|
|
70
79
|
private prefix;
|
|
80
|
+
/**
|
|
81
|
+
* Creates authorization handlers based on the application configuration and environment variables.
|
|
82
|
+
*/
|
|
83
|
+
private createHandlers;
|
|
84
|
+
/**
|
|
85
|
+
* Fixes the handler type based on the provided type string, supporting both latest and legacy formats.
|
|
86
|
+
*/
|
|
87
|
+
private fixType;
|
|
71
88
|
}
|
|
72
89
|
export {};
|
|
@@ -6,10 +6,18 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.AuthorizationManager = void 0;
|
|
8
8
|
const agents_activity_1 = require("@microsoft/agents-activity");
|
|
9
|
+
const agents_telemetry_1 = require("@microsoft/agents-telemetry");
|
|
9
10
|
const handlers_1 = require("./handlers");
|
|
11
|
+
const turnContext_1 = require("../../turnContext");
|
|
10
12
|
const handlerStorage_1 = require("./handlerStorage");
|
|
13
|
+
const errorHelper_1 = require("../../errorHelper");
|
|
11
14
|
const types_1 = require("./types");
|
|
12
|
-
const
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
const auth_1 = require("../../auth");
|
|
17
|
+
const logger = (0, agents_telemetry_1.debug)('agents:authorization:manager');
|
|
18
|
+
const AGENTIC = 'AgenticUserAuthorization';
|
|
19
|
+
const AGENTIC_LEGACY = 'agentic';
|
|
20
|
+
const AZURE_BOT = 'AzureBotUserAuthorization';
|
|
13
21
|
/**
|
|
14
22
|
* Manages multiple authorization handlers and their interactions.
|
|
15
23
|
* Processes authorization requests and maintains handler states.
|
|
@@ -25,46 +33,101 @@ class AuthorizationManager {
|
|
|
25
33
|
*/
|
|
26
34
|
constructor(app, connections) {
|
|
27
35
|
this.app = app;
|
|
36
|
+
this.connections = connections;
|
|
28
37
|
this._handlers = {};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Environment variable configuration for the latest format.
|
|
40
|
+
*/
|
|
41
|
+
this._envLatest = {
|
|
42
|
+
key: {
|
|
43
|
+
prefix: 'AgentApplication__UserAuthorization__Handlers__',
|
|
44
|
+
separator: '__Settings__',
|
|
45
|
+
create(id, prop) {
|
|
46
|
+
return `${this.prefix}${id}${this.separator}${prop}`;
|
|
47
|
+
},
|
|
48
|
+
extract(envKey) {
|
|
49
|
+
// Substring: AgentApplication__UserAuthorization__Handlers__<id>__Settings__<prop>
|
|
50
|
+
// position —————————————————————————————————————————> start^ ^end ^prop
|
|
51
|
+
const start = this.prefix.length;
|
|
52
|
+
const end = envKey.toUpperCase().indexOf(this.separator.toUpperCase());
|
|
53
|
+
if (end === -1) {
|
|
54
|
+
return { id: undefined, prop: undefined };
|
|
55
|
+
}
|
|
56
|
+
const id = envKey.substring(start, end);
|
|
57
|
+
const prop = envKey.substring(end + this.separator.length);
|
|
58
|
+
return { id, prop };
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
parser: (0, auth_1.envParser)({
|
|
62
|
+
// Common
|
|
63
|
+
type: auth_1.envParserUtils.bypass,
|
|
64
|
+
// Azure Bot
|
|
65
|
+
azureBotOAuthConnectionName: auth_1.envParserUtils.bypass,
|
|
66
|
+
title: auth_1.envParserUtils.bypass,
|
|
67
|
+
text: auth_1.envParserUtils.bypass,
|
|
68
|
+
invalidSignInRetryMessage: auth_1.envParserUtils.bypass,
|
|
69
|
+
invalidSignInRetryMessageFormat: auth_1.envParserUtils.bypass,
|
|
70
|
+
invalidSignInRetryMaxExceededMessage: auth_1.envParserUtils.bypass,
|
|
71
|
+
oboConnectionName: auth_1.envParserUtils.bypass,
|
|
72
|
+
enableSso(value) {
|
|
73
|
+
return { value: value !== 'false' };
|
|
74
|
+
},
|
|
75
|
+
invalidSignInRetryMax(value) {
|
|
76
|
+
return { value: parseInt(value) };
|
|
77
|
+
},
|
|
78
|
+
oboScopes(value) {
|
|
79
|
+
return this.scopes(value);
|
|
80
|
+
},
|
|
81
|
+
// Agentic
|
|
82
|
+
altBlueprintConnectionName: auth_1.envParserUtils.bypass,
|
|
83
|
+
scopes(value) {
|
|
84
|
+
if (value.includes(',')) {
|
|
85
|
+
return { value: value.split(',').map(s => s.trim()).filter(Boolean) };
|
|
86
|
+
}
|
|
87
|
+
return { value: value.split(/\s+/).filter(Boolean) };
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Environment variable configuration for the legacy format.
|
|
93
|
+
*/
|
|
94
|
+
this._envLegacy = {
|
|
95
|
+
key: {
|
|
96
|
+
separator: '_',
|
|
97
|
+
},
|
|
98
|
+
parser: (0, auth_1.envParser)({
|
|
99
|
+
// Common
|
|
100
|
+
type: auth_1.envParserUtils.redirect(this._envLatest.parser, 'type'),
|
|
101
|
+
// Azure Bot
|
|
102
|
+
connectionName: auth_1.envParserUtils.redirect(this._envLatest.parser, 'azureBotOAuthConnectionName'),
|
|
103
|
+
connectionTitle: auth_1.envParserUtils.redirect(this._envLatest.parser, 'title'),
|
|
104
|
+
connectionText: auth_1.envParserUtils.redirect(this._envLatest.parser, 'text'),
|
|
105
|
+
maxAttempts: auth_1.envParserUtils.redirect(this._envLatest.parser, 'invalidSignInRetryMax'),
|
|
106
|
+
messages_invalidCode: auth_1.envParserUtils.redirect(this._envLatest.parser, 'invalidSignInRetryMessage'),
|
|
107
|
+
messages_invalidCodeFormat: auth_1.envParserUtils.redirect(this._envLatest.parser, 'invalidSignInRetryMessageFormat'),
|
|
108
|
+
messages_maxAttemptsExceeded: auth_1.envParserUtils.redirect(this._envLatest.parser, 'invalidSignInRetryMaxExceededMessage'),
|
|
109
|
+
obo_connection: auth_1.envParserUtils.redirect(this._envLatest.parser, 'oboConnectionName'),
|
|
110
|
+
obo_scopes: auth_1.envParserUtils.redirect(this._envLatest.parser, 'oboScopes'),
|
|
111
|
+
enableSso: auth_1.envParserUtils.redirect(this._envLatest.parser, 'enableSso'),
|
|
112
|
+
// Agentic
|
|
113
|
+
scopes: auth_1.envParserUtils.redirect(this._envLatest.parser, 'scopes'),
|
|
114
|
+
altBlueprintConnectionName: auth_1.envParserUtils.redirect(this._envLatest.parser, 'altBlueprintConnectionName')
|
|
115
|
+
})
|
|
54
116
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
117
|
+
this.createHandlers();
|
|
118
|
+
if (this.handlers.length === 0 && app.options.authorization !== undefined) {
|
|
119
|
+
throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.NoAuthHandlersConfigured);
|
|
120
|
+
}
|
|
121
|
+
for (const [id, handler] of Object.entries(this._handlers)) {
|
|
122
|
+
logger.debug('auth handler "%s" type=%s scopes=%o', id, handler.type, handler.scopes);
|
|
59
123
|
}
|
|
60
|
-
return result;
|
|
61
124
|
}
|
|
62
125
|
/**
|
|
63
126
|
* Gets the registered authorization handlers.
|
|
64
127
|
* @returns A record of authorization handlers by their IDs.
|
|
65
128
|
*/
|
|
66
129
|
get handlers() {
|
|
67
|
-
return this._handlers;
|
|
130
|
+
return Object.values(this._handlers);
|
|
68
131
|
}
|
|
69
132
|
/**
|
|
70
133
|
* Processes an authorization request.
|
|
@@ -73,45 +136,64 @@ class AuthorizationManager {
|
|
|
73
136
|
* @returns The result of the authorization process.
|
|
74
137
|
*/
|
|
75
138
|
async process(context, getHandlerIds) {
|
|
76
|
-
var _a, _b, _c, _d, _e;
|
|
139
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
140
|
+
const activity = context.activity;
|
|
141
|
+
if (this.handlers.length === 0) {
|
|
142
|
+
return { authorized: true, context };
|
|
143
|
+
}
|
|
77
144
|
const storage = new handlerStorage_1.HandlerStorage(this.app.options.storage, context);
|
|
78
145
|
let active = await this.active(storage, getHandlerIds);
|
|
79
|
-
if (active
|
|
146
|
+
if (!active && ((_a = activity.name) === null || _a === void 0 ? void 0 : _a.startsWith('signin/'))) {
|
|
147
|
+
const reason = `Received '${activity.name}' but no active sign-in flow exists for user '${(_b = activity.from) === null || _b === void 0 ? void 0 : _b.id}'.`;
|
|
148
|
+
logger.warn(reason, activity);
|
|
149
|
+
await (0, utils_1.sendInvokeResponse)(context, {
|
|
150
|
+
status: 400,
|
|
151
|
+
body: { failureDetail: reason }
|
|
152
|
+
});
|
|
153
|
+
return { authorized: false, context };
|
|
154
|
+
}
|
|
155
|
+
if (active !== undefined && ((_c = active === null || active === void 0 ? void 0 : active.data.activity.conversation) === null || _c === void 0 ? void 0 : _c.id) !== ((_d = activity.conversation) === null || _d === void 0 ? void 0 : _d.id)) {
|
|
80
156
|
logger.warn('Discarding the active session due to the conversation has changed during an active sign-in process', active === null || active === void 0 ? void 0 : active.data.activity);
|
|
81
157
|
await storage.delete();
|
|
82
|
-
return { authorized: true };
|
|
158
|
+
return { authorized: true, context };
|
|
83
159
|
}
|
|
84
|
-
const handlers = (
|
|
160
|
+
const handlers = (_g = (_e = active === null || active === void 0 ? void 0 : active.handlers) !== null && _e !== void 0 ? _e : this.mapHandlers((_f = await getHandlerIds(activity)) !== null && _f !== void 0 ? _f : [])) !== null && _g !== void 0 ? _g : [];
|
|
161
|
+
// Create a shallow copy to modify the activity, since the signin process depends on it and we want to ensure the next handler depends on the initial activity, not the modified one.
|
|
162
|
+
const sharedContext = new turnContext_1.TurnContext(context);
|
|
85
163
|
for (const handler of handlers) {
|
|
86
|
-
|
|
87
|
-
|
|
164
|
+
if ((_h = handler.scopes) === null || _h === void 0 ? void 0 : _h.length) {
|
|
165
|
+
logger.debug('invoking auth handler "%s" scopes=[%s]', handler.id, handler.scopes.join(','));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
logger.debug('invoking auth handler "%s"', handler.id);
|
|
169
|
+
}
|
|
170
|
+
const status = await this.signin(storage, handler, sharedContext, active === null || active === void 0 ? void 0 : active.data);
|
|
171
|
+
logger.debug('auth handler "%s" sign-in status=%s', handler.id, status);
|
|
88
172
|
if (status === types_1.AuthorizationHandlerStatus.IGNORED) {
|
|
89
173
|
await storage.delete();
|
|
90
174
|
continue;
|
|
91
175
|
}
|
|
92
176
|
if (status === types_1.AuthorizationHandlerStatus.PENDING) {
|
|
93
|
-
return { authorized: false };
|
|
177
|
+
return { authorized: false, context: sharedContext };
|
|
94
178
|
}
|
|
95
179
|
if (status === types_1.AuthorizationHandlerStatus.REJECTED) {
|
|
96
180
|
await storage.delete();
|
|
97
|
-
return { authorized: false };
|
|
181
|
+
return { authorized: false, context: sharedContext };
|
|
98
182
|
}
|
|
99
183
|
if (status === types_1.AuthorizationHandlerStatus.REVALIDATE) {
|
|
100
184
|
await storage.delete();
|
|
101
|
-
return this.process(
|
|
185
|
+
return this.process(sharedContext, getHandlerIds);
|
|
102
186
|
}
|
|
103
187
|
if (status !== types_1.AuthorizationHandlerStatus.APPROVED) {
|
|
104
|
-
throw
|
|
188
|
+
throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.UnexpectedRegistrationStatus, undefined, { status });
|
|
105
189
|
}
|
|
106
190
|
await storage.delete();
|
|
107
191
|
if (active) {
|
|
108
|
-
|
|
109
|
-
// This is done like this to avoid losing data that may be set in the turn context.
|
|
110
|
-
context._activity = agents_activity_1.Activity.fromObject(active.data.activity);
|
|
192
|
+
sharedContext._activity = agents_activity_1.Activity.fromObject(active.data.activity);
|
|
111
193
|
active = undefined;
|
|
112
194
|
}
|
|
113
195
|
}
|
|
114
|
-
return { authorized: true };
|
|
196
|
+
return { authorized: true, context: sharedContext };
|
|
115
197
|
}
|
|
116
198
|
/**
|
|
117
199
|
* Gets the active handler session from storage.
|
|
@@ -145,22 +227,23 @@ class AuthorizationManager {
|
|
|
145
227
|
}
|
|
146
228
|
catch (cause) {
|
|
147
229
|
await storage.delete();
|
|
148
|
-
throw
|
|
230
|
+
throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.FailedToSignIn, cause);
|
|
149
231
|
}
|
|
150
232
|
}
|
|
151
233
|
/**
|
|
152
234
|
* Maps an array of handler IDs to their corresponding handler instances.
|
|
153
235
|
*/
|
|
154
236
|
mapHandlers(ids) {
|
|
155
|
-
|
|
237
|
+
const unknownHandlers = [];
|
|
156
238
|
const handlers = ids.map(id => {
|
|
157
|
-
|
|
158
|
-
|
|
239
|
+
const handler = this.handlers.find(e => e.id.toLowerCase() === id.toLowerCase());
|
|
240
|
+
if (!handler) {
|
|
241
|
+
unknownHandlers.push(id);
|
|
159
242
|
}
|
|
160
|
-
return
|
|
161
|
-
});
|
|
162
|
-
if (unknownHandlers) {
|
|
163
|
-
throw
|
|
243
|
+
return handler;
|
|
244
|
+
}).filter((handler) => handler !== undefined);
|
|
245
|
+
if (unknownHandlers.length > 0) {
|
|
246
|
+
throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.AuthHandlersNotFound, undefined, { handlerIds: unknownHandlers.join(', ') });
|
|
164
247
|
}
|
|
165
248
|
return handlers;
|
|
166
249
|
}
|
|
@@ -170,6 +253,137 @@ class AuthorizationManager {
|
|
|
170
253
|
prefix(id, message) {
|
|
171
254
|
return `[handler:${id}] ${message}`;
|
|
172
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Creates authorization handlers based on the application configuration and environment variables.
|
|
258
|
+
*/
|
|
259
|
+
createHandlers() {
|
|
260
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
261
|
+
var _w, _x;
|
|
262
|
+
let legacyMessage = '';
|
|
263
|
+
const settings = { storage: this.app.options.storage, connections: this.connections };
|
|
264
|
+
let runtimeEntries = Object.entries((_a = this.app.options.authorization) !== null && _a !== void 0 ? _a : {});
|
|
265
|
+
const result = { latest: {}, legacy: {} };
|
|
266
|
+
for (const [envKey, envValue] of Object.entries(process.env)) {
|
|
267
|
+
if (!(envValue === null || envValue === void 0 ? void 0 : envValue.trim())) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const upperEnvKey = envKey.toUpperCase();
|
|
271
|
+
// Legacy: extract handler ID, handler options key and its value, and assign it to the correct runtime handler ID.
|
|
272
|
+
if (!upperEnvKey.startsWith(this._envLatest.key.prefix.toUpperCase())) {
|
|
273
|
+
const [id] = (_b = runtimeEntries.find(([id]) => upperEnvKey.startsWith(`${id.toUpperCase()}${this._envLegacy.key.separator}`))) !== null && _b !== void 0 ? _b : [];
|
|
274
|
+
if (!id) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const prop = envKey.substring(id.length + this._envLegacy.key.separator.length);
|
|
278
|
+
if (!prop) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const { key, value } = this._envLegacy.parser.parse(prop, envValue);
|
|
282
|
+
if (!key) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
legacyMessage += ` ${envKey}= # Use ${this._envLatest.key.create(id, key)} instead.\n`;
|
|
286
|
+
(_c = (_w = result.legacy)[id]) !== null && _c !== void 0 ? _c : (_w[id] = {});
|
|
287
|
+
result.legacy[id][key] = value;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
// Latest: extract handler ID, handler options key and its value, and assign it to the correct latest handler ID.
|
|
291
|
+
const { id, prop } = this._envLatest.key.extract(envKey);
|
|
292
|
+
if (!id || !prop) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const { key, value } = this._envLatest.parser.parse(prop, envValue);
|
|
296
|
+
if (!key) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
// Find existing handler ID case-insensitively to avoid duplicates, but keep the original casing for later processing.
|
|
300
|
+
// This allows users to specify environment variables in a case-insensitive way, while ensuring that the handler IDs are treated in a case-sensitive way internally, to avoid issues when referencing them later.
|
|
301
|
+
// For example, if the user specifies AGENTAPPLICATION__USERAUTHORIZATION__HANDLERS__GRAPH__SETTINGS__AZUREBOTOAUTHCONNECTIONNAME and agentapplication__userauthorization__handlers__graph__settings__azurebotoauthconnectionname, we want to treat them as the same handler ID "graph", and not create two separate handlers "GRAPH" and "graph".
|
|
302
|
+
// Note: the first environment variable that is processed will determine the casing of the handler ID, and any subsequent environment variable that matches the same handler ID case-insensitively will be treated as referring to the same handler, regardless of its casing.
|
|
303
|
+
const existingId = id in result.latest ? id : Object.keys(result.latest).find(e => e.toLowerCase() === id.toLowerCase());
|
|
304
|
+
const realId = existingId !== null && existingId !== void 0 ? existingId : id;
|
|
305
|
+
(_d = (_x = result.latest)[realId]) !== null && _d !== void 0 ? _d : (_x[realId] = {});
|
|
306
|
+
result.latest[realId][key] = value;
|
|
307
|
+
}
|
|
308
|
+
if (legacyMessage.length > 0) {
|
|
309
|
+
logger.warn('Deprecated environment variables detected, update to the latest format: (case-insensitive)', `[\n${legacyMessage}]`);
|
|
310
|
+
}
|
|
311
|
+
// Fix types
|
|
312
|
+
const fixTypes = (entries) => entries
|
|
313
|
+
.map(([id, options]) => [id, { ...options, type: this.fixType(id, options === null || options === void 0 ? void 0 : options.type) }]);
|
|
314
|
+
runtimeEntries = fixTypes(runtimeEntries);
|
|
315
|
+
const latestEntries = fixTypes(Object.entries(result.latest));
|
|
316
|
+
const legacyEntries = fixTypes(Object.entries(result.legacy));
|
|
317
|
+
const registeredHandlers = new Set();
|
|
318
|
+
for (const [id] of [...runtimeEntries, ...latestEntries]) {
|
|
319
|
+
if (registeredHandlers.has(id.toLowerCase())) {
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
// Find entries case-insensitively for later processing
|
|
323
|
+
const [, runtime] = (_e = runtimeEntries.find(([key]) => key.toLowerCase() === id.toLowerCase())) !== null && _e !== void 0 ? _e : [];
|
|
324
|
+
const [, latest] = (_f = latestEntries.find(([key]) => key.toLowerCase() === id.toLowerCase())) !== null && _f !== void 0 ? _f : [];
|
|
325
|
+
const [, legacy] = (_g = legacyEntries.find(([key]) => key.toLowerCase() === id.toLowerCase())) !== null && _g !== void 0 ? _g : [];
|
|
326
|
+
if (runtime !== undefined && latest !== undefined) {
|
|
327
|
+
logger.warn(this.prefix(id, 'Both runtime and latest environment variable configurations detected. Runtime configuration will take precedence over latest environment variables.'));
|
|
328
|
+
}
|
|
329
|
+
// Normalize runtime legacy options to latest format
|
|
330
|
+
if ((runtime === null || runtime === void 0 ? void 0 : runtime.type) === AZURE_BOT) {
|
|
331
|
+
(_h = runtime.azureBotOAuthConnectionName) !== null && _h !== void 0 ? _h : (runtime.azureBotOAuthConnectionName = runtime.name);
|
|
332
|
+
(_j = runtime.invalidSignInRetryMax) !== null && _j !== void 0 ? _j : (runtime.invalidSignInRetryMax = runtime.maxAttempts);
|
|
333
|
+
(_k = runtime.invalidSignInRetryMessage) !== null && _k !== void 0 ? _k : (runtime.invalidSignInRetryMessage = (_l = runtime.messages) === null || _l === void 0 ? void 0 : _l.invalidCode);
|
|
334
|
+
(_m = runtime.invalidSignInRetryMessageFormat) !== null && _m !== void 0 ? _m : (runtime.invalidSignInRetryMessageFormat = (_o = runtime.messages) === null || _o === void 0 ? void 0 : _o.invalidCodeFormat);
|
|
335
|
+
(_p = runtime.invalidSignInRetryMaxExceededMessage) !== null && _p !== void 0 ? _p : (runtime.invalidSignInRetryMaxExceededMessage = (_q = runtime.messages) === null || _q === void 0 ? void 0 : _q.maxAttemptsExceeded);
|
|
336
|
+
(_r = runtime.oboConnectionName) !== null && _r !== void 0 ? _r : (runtime.oboConnectionName = (_s = runtime.obo) === null || _s === void 0 ? void 0 : _s.connection);
|
|
337
|
+
(_t = runtime.oboScopes) !== null && _t !== void 0 ? _t : (runtime.oboScopes = (_u = runtime.obo) === null || _u === void 0 ? void 0 : _u.scopes);
|
|
338
|
+
delete runtime.name;
|
|
339
|
+
delete runtime.maxAttempts;
|
|
340
|
+
delete runtime.messages;
|
|
341
|
+
delete runtime.obo;
|
|
342
|
+
}
|
|
343
|
+
// Helper to remove undefined options
|
|
344
|
+
const prune = (obj) => {
|
|
345
|
+
const entries = Object.entries(obj).filter(([, e]) => e !== undefined);
|
|
346
|
+
return Object.fromEntries(entries);
|
|
347
|
+
};
|
|
348
|
+
// Priority: runtime > latest > legacy
|
|
349
|
+
// Pruning done individually to avoid overwriting with undefined when merging.
|
|
350
|
+
const options = runtime ? { ...prune(legacy || {}), ...prune(runtime) } : prune(latest || {});
|
|
351
|
+
if (!settings.storage) {
|
|
352
|
+
throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.StorageRequiredForAuthorization);
|
|
353
|
+
}
|
|
354
|
+
if (options.type === AGENTIC) {
|
|
355
|
+
this._handlers[id] = new handlers_1.AgenticAuthorization(id, options, settings);
|
|
356
|
+
}
|
|
357
|
+
else if (options.type === AZURE_BOT) {
|
|
358
|
+
// Set default values if not provided
|
|
359
|
+
options.title || (options.title = 'Sign-in');
|
|
360
|
+
options.text || (options.text = 'Please sign-in to continue');
|
|
361
|
+
(_v = options.oboScopes) !== null && _v !== void 0 ? _v : (options.oboScopes = []);
|
|
362
|
+
options.enableSso = options.enableSso !== false; // default value is true if undefined.
|
|
363
|
+
this._handlers[id] = new handlers_1.AzureBotAuthorization(id, options, settings);
|
|
364
|
+
}
|
|
365
|
+
registeredHandlers.add(id.toLowerCase());
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Fixes the handler type based on the provided type string, supporting both latest and legacy formats.
|
|
370
|
+
*/
|
|
371
|
+
fixType(handlerId, type) {
|
|
372
|
+
if (!type) {
|
|
373
|
+
return AZURE_BOT;
|
|
374
|
+
}
|
|
375
|
+
if (type.toLowerCase() === AGENTIC_LEGACY.toLowerCase()) {
|
|
376
|
+
logger.warn(this.prefix(handlerId, 'The \'agentic\' type is deprecated. Please use \'AgenticUserAuthorization\' instead.'));
|
|
377
|
+
return AGENTIC;
|
|
378
|
+
}
|
|
379
|
+
if (type.toLowerCase() === AGENTIC.toLowerCase()) {
|
|
380
|
+
return AGENTIC;
|
|
381
|
+
}
|
|
382
|
+
if (type.toLowerCase() === AZURE_BOT.toLowerCase()) {
|
|
383
|
+
return AZURE_BOT;
|
|
384
|
+
}
|
|
385
|
+
throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.UnsupportedAuthHandlerType, undefined, { handlerType: type });
|
|
386
|
+
}
|
|
173
387
|
}
|
|
174
388
|
exports.AuthorizationManager = AuthorizationManager;
|
|
175
389
|
//# sourceMappingURL=authorizationManager.js.map
|