@microsoft/agents-hosting 1.5.0-beta.6.ga236d9a19c → 1.5.1
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 +36 -10
- package/dist/src/app/agentApplication.js +169 -99
- 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 +18 -5
- package/dist/src/app/auth/authorizationManager.js +258 -45
- 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 +48 -42
- 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 +212 -86
- 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 +297 -45
- 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 +47 -41
|
@@ -3,34 +3,43 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { ExceptionHelper } from '@microsoft/agents-activity'
|
|
7
7
|
import { TurnContext } from '../../../turnContext'
|
|
8
|
+
import { trace, debug } from '@microsoft/agents-telemetry'
|
|
8
9
|
import { AuthorizationHandler, AuthorizationHandlerSettings, AuthorizationHandlerStatus, AuthorizationHandlerTokenOptions } from '../types'
|
|
9
10
|
import { TokenResponse } from '../../../oauth'
|
|
10
11
|
import { AuthProvider } from '../../../auth'
|
|
12
|
+
import { AuthorizationTraceDefinitions } from '../../../observability'
|
|
13
|
+
import { Errors } from '../../../errorHelper'
|
|
11
14
|
|
|
12
15
|
const logger = debug('agents:authorization:agentic')
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Options for configuring the Agentic authorization handler.
|
|
19
|
+
* @remarks
|
|
20
|
+
* Properties can be configured via environment variables (case-insensitive).
|
|
21
|
+
* Use the format: `AgentApplication__UserAuthorization__handlers__{handlerId}__settings__{propertyName}`
|
|
22
|
+
* where `{handlerId}` is the handler's unique identifier and `{propertyName}` matches the property name.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```env
|
|
26
|
+
* # For a handler with id "myAuth":
|
|
27
|
+
* AgentApplication__UserAuthorization__handlers__myAuth__settings__type=AgenticUserAuthorization
|
|
28
|
+
* AgentApplication__UserAuthorization__handlers__myAuth__settings__scopes=api://scope1 api://scope2
|
|
29
|
+
* ```
|
|
16
30
|
*/
|
|
17
31
|
export interface AgenticAuthorizationOptions {
|
|
18
32
|
/**
|
|
19
33
|
* The type of authorization handler.
|
|
20
|
-
* @remarks
|
|
21
|
-
* When using environment variables, this can be set using the `${authHandlerId}_type` variable.
|
|
22
34
|
*/
|
|
23
|
-
type: 'agentic'
|
|
35
|
+
type: 'AgenticUserAuthorization' | 'agentic'
|
|
24
36
|
/**
|
|
25
37
|
* The scopes required for the authorization.
|
|
26
|
-
* @remarks
|
|
27
|
-
* When using environment variables, this can be set using the `${authHandlerId}_scopes` variable (comma-separated values, e.g. `scope1,scope2`).
|
|
38
|
+
* @remarks When set via environment variable, use comma or space-separated values (e.g. `scope1,scope2` or `scope1 scope2`).
|
|
28
39
|
*/
|
|
29
40
|
scopes?: string[]
|
|
30
41
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* When using environment variables, this can be set using the `${authHandlerId}_altBlueprintConnectionName` variable.
|
|
42
|
+
* An alternative connection name to use for the authorization process.
|
|
34
43
|
*/
|
|
35
44
|
altBlueprintConnectionName?: string
|
|
36
45
|
}
|
|
@@ -44,39 +53,32 @@ export interface AgenticAuthorizationSettings extends AuthorizationHandlerSettin
|
|
|
44
53
|
* Authorization handler for Agentic authentication.
|
|
45
54
|
*/
|
|
46
55
|
export class AgenticAuthorization implements AuthorizationHandler {
|
|
47
|
-
private _options: AgenticAuthorizationOptions
|
|
48
56
|
private _onSuccess?: Parameters<AuthorizationHandler['onSuccess']>[0]
|
|
49
57
|
private _onFailure?: Parameters<AuthorizationHandler['onFailure']>[0]
|
|
50
58
|
|
|
51
59
|
/**
|
|
52
60
|
* Creates an instance of the AgenticAuthorization class.
|
|
53
61
|
* @param id The unique identifier for the authorization handler.
|
|
54
|
-
* @param options The options for configuring the authorization handler.
|
|
62
|
+
* @param options The options for configuring the authorization handler (must be fully resolved).
|
|
55
63
|
* @param settings The settings for the authorization handler.
|
|
56
64
|
*/
|
|
57
|
-
constructor (public readonly id: string, options: AgenticAuthorizationOptions, private settings: AgenticAuthorizationSettings) {
|
|
65
|
+
constructor (public readonly id: string, private options: AgenticAuthorizationOptions, private settings: AgenticAuthorizationSettings) {
|
|
58
66
|
if (!this.settings.connections) {
|
|
59
|
-
throw
|
|
67
|
+
throw ExceptionHelper.generateException(Error, Errors.ConnectionsOptionNotAvailable)
|
|
60
68
|
}
|
|
61
69
|
|
|
62
|
-
|
|
70
|
+
if (!options.scopes || options.scopes.length === 0) {
|
|
71
|
+
throw ExceptionHelper.generateException(Error, Errors.AtLeastOneScopeRequired)
|
|
72
|
+
}
|
|
63
73
|
}
|
|
64
74
|
|
|
75
|
+
readonly type = 'agentic'
|
|
76
|
+
|
|
65
77
|
/**
|
|
66
|
-
*
|
|
78
|
+
* The scopes configured for this handler.
|
|
67
79
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
type: 'agentic',
|
|
71
|
-
altBlueprintConnectionName: settings.altBlueprintConnectionName ?? (process.env[`${this.id}_altBlueprintConnectionName`]),
|
|
72
|
-
scopes: settings.scopes ?? this.loadScopes(process.env[`${this.id}_scopes`]),
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (!result.scopes || result.scopes.length === 0) {
|
|
76
|
-
throw new Error(this.prefix('At least one scope must be specified for the Agentic authorization handler.'))
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return result
|
|
80
|
+
get scopes (): string[] | undefined {
|
|
81
|
+
return this.options.scopes
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/**
|
|
@@ -97,39 +99,46 @@ export class AgenticAuthorization implements AuthorizationHandler {
|
|
|
97
99
|
* @inheritdoc
|
|
98
100
|
*/
|
|
99
101
|
async token (context: TurnContext, options?: AuthorizationHandlerTokenOptions): Promise<TokenResponse> {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
return trace(AuthorizationTraceDefinitions.agenticToken, async ({ record }) => {
|
|
103
|
+
let connection: AuthProvider | undefined
|
|
104
|
+
const scopes = options?.scopes || this.options.scopes!
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const tokenResponse = this.getContext(context, scopes)
|
|
108
|
+
if (tokenResponse.token) {
|
|
109
|
+
logger.debug(this.prefix('Using cached Agentic user token'))
|
|
110
|
+
return tokenResponse
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (this.options.altBlueprintConnectionName?.trim()) {
|
|
114
|
+
connection = this.settings.connections.getConnection(this.options.altBlueprintConnectionName)
|
|
115
|
+
} else {
|
|
116
|
+
connection = this.settings.connections.getTokenProvider(context.identity, context.activity.serviceUrl ?? '')
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const token = await connection.getAgenticUserToken(
|
|
120
|
+
context.activity.getAgenticTenantId() ?? '',
|
|
121
|
+
context.activity.getAgenticInstanceId() ?? '',
|
|
122
|
+
context.activity.getAgenticUser() ?? '',
|
|
123
|
+
scopes
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
this.setContext(context, scopes, { token })
|
|
127
|
+
this._onSuccess?.(context)
|
|
128
|
+
return { token }
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const reason = 'Error retrieving Agentic user token'
|
|
131
|
+
logger.error(this.prefix(reason), error)
|
|
132
|
+
this._onFailure?.(context, `${reason}: ${(error as Error).message}`)
|
|
133
|
+
return { token: undefined }
|
|
134
|
+
} finally {
|
|
135
|
+
record({
|
|
136
|
+
handlerId: this.id,
|
|
137
|
+
connectionName: connection?.connectionSettings?.connectionName ?? this.options.altBlueprintConnectionName ?? 'unknown',
|
|
138
|
+
authScopes: scopes ?? []
|
|
139
|
+
})
|
|
107
140
|
}
|
|
108
|
-
|
|
109
|
-
let connection: AuthProvider
|
|
110
|
-
|
|
111
|
-
if (this._options.altBlueprintConnectionName?.trim()) {
|
|
112
|
-
connection = this.settings.connections.getConnection(this._options.altBlueprintConnectionName)
|
|
113
|
-
} else {
|
|
114
|
-
connection = this.settings.connections.getTokenProvider(context.identity, context.activity.serviceUrl ?? '')
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const token = await connection.getAgenticUserToken(
|
|
118
|
-
context.activity.getAgenticTenantId() ?? '',
|
|
119
|
-
context.activity.getAgenticInstanceId() ?? '',
|
|
120
|
-
context.activity.getAgenticUser() ?? '',
|
|
121
|
-
scopes
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
this.setContext(context, scopes, { token })
|
|
125
|
-
this._onSuccess?.(context)
|
|
126
|
-
return { token }
|
|
127
|
-
} catch (error) {
|
|
128
|
-
const reason = 'Error retrieving Agentic user token'
|
|
129
|
-
logger.error(this.prefix(reason), error)
|
|
130
|
-
this._onFailure?.(context, `${reason}: ${(error as Error).message}`)
|
|
131
|
-
return { token: undefined }
|
|
132
|
-
}
|
|
141
|
+
})
|
|
133
142
|
}
|
|
134
143
|
|
|
135
144
|
/**
|
|
@@ -173,17 +182,4 @@ export class AgenticAuthorization implements AuthorizationHandler {
|
|
|
173
182
|
const result = context.turnState.get(`${this._key}:${scopes.join(';')}`)
|
|
174
183
|
return result?.() ?? { token: undefined }
|
|
175
184
|
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Loads the OAuth scopes from the environment variables.
|
|
179
|
-
*/
|
|
180
|
-
private loadScopes (value:string | undefined): string[] {
|
|
181
|
-
return value?.split(',').reduce<string[]>((acc, scope) => {
|
|
182
|
-
const trimmed = scope.trim()
|
|
183
|
-
if (trimmed) {
|
|
184
|
-
acc.push(trimmed)
|
|
185
|
-
}
|
|
186
|
-
return acc
|
|
187
|
-
}, []) ?? []
|
|
188
|
-
}
|
|
189
185
|
}
|