@microsoft/agents-hosting 1.1.0-alpha.9.g154c2c8a32 → 1.1.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 -6
- package/dist/src/activityWireCompat.d.ts +1 -1
- package/dist/src/activityWireCompat.js +11 -3
- package/dist/src/activityWireCompat.js.map +1 -1
- package/dist/src/agent-client/agentClient.js +7 -3
- package/dist/src/agent-client/agentClient.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.js +6 -2
- package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
- package/dist/src/app/agentApplication.d.ts +26 -11
- package/dist/src/app/agentApplication.js +90 -79
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +2 -2
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +9 -2
- package/dist/src/app/appRoute.d.ts +7 -0
- package/dist/src/app/{authorization.d.ts → auth/authorization.d.ts} +41 -139
- package/dist/src/app/auth/authorization.js +188 -0
- package/dist/src/app/auth/authorization.js.map +1 -0
- package/dist/src/app/auth/authorizationManager.d.ts +71 -0
- package/dist/src/app/auth/authorizationManager.js +170 -0
- package/dist/src/app/auth/authorizationManager.js.map +1 -0
- package/dist/src/app/auth/handlerStorage.d.ts +36 -0
- package/dist/src/app/auth/handlerStorage.js +62 -0
- package/dist/src/app/auth/handlerStorage.js.map +1 -0
- package/dist/src/app/auth/handlers/agenticAuthorization.d.ts +93 -0
- package/dist/src/app/auth/handlers/agenticAuthorization.js +134 -0
- package/dist/src/app/auth/handlers/agenticAuthorization.js.map +1 -0
- package/dist/src/app/auth/handlers/azureBotAuthorization.d.ts +226 -0
- package/dist/src/app/auth/handlers/azureBotAuthorization.js +429 -0
- package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -0
- package/dist/src/app/auth/handlers/index.d.ts +2 -0
- package/dist/src/app/auth/handlers/index.js +19 -0
- package/dist/src/app/auth/handlers/index.js.map +1 -0
- package/dist/src/app/auth/index.d.ts +2 -0
- package/dist/src/app/auth/index.js +19 -0
- package/dist/src/app/auth/index.js.map +1 -0
- package/dist/src/app/auth/types.d.ts +104 -0
- package/dist/src/app/auth/types.js +24 -0
- package/dist/src/app/auth/types.js.map +1 -0
- package/dist/src/app/index.d.ts +3 -3
- package/dist/src/app/index.js +2 -3
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/routeList.d.ts +1 -1
- package/dist/src/app/routeList.js +22 -5
- package/dist/src/app/routeList.js.map +1 -1
- package/dist/src/app/streaming/streamingResponse.js +2 -1
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/auth/MemoryCache.d.ts +16 -0
- package/dist/src/auth/MemoryCache.js +58 -0
- package/dist/src/auth/MemoryCache.js.map +1 -0
- package/dist/src/auth/authConfiguration.d.ts +44 -2
- package/dist/src/auth/authConfiguration.js +209 -53
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/authConstants.d.ts +11 -0
- package/dist/src/auth/authConstants.js +15 -0
- package/dist/src/auth/authConstants.js.map +1 -0
- package/dist/src/auth/authProvider.d.ts +26 -0
- package/dist/src/auth/connections.d.ts +41 -0
- package/dist/src/auth/connections.js +7 -0
- package/dist/src/auth/connections.js.map +1 -0
- package/dist/src/auth/index.d.ts +2 -0
- package/dist/src/auth/index.js +2 -0
- package/dist/src/auth/index.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +31 -18
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalConnectionManager.d.ts +64 -0
- package/dist/src/auth/msalConnectionManager.js +148 -0
- package/dist/src/auth/msalConnectionManager.js.map +1 -0
- package/dist/src/auth/msalTokenProvider.d.ts +38 -0
- package/dist/src/auth/msalTokenProvider.js +186 -16
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/baseAdapter.d.ts +10 -25
- package/dist/src/baseAdapter.js +2 -15
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cards/cardFactory.d.ts +2 -1
- package/dist/src/cards/cardFactory.js +3 -2
- package/dist/src/cards/cardFactory.js.map +1 -1
- package/dist/src/cloudAdapter.d.ts +40 -23
- package/dist/src/cloudAdapter.js +143 -63
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +15 -0
- package/dist/src/connector-client/connectorClient.js +49 -15
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/oauth/customUserTokenAPI.d.ts +1 -0
- package/dist/src/oauth/customUserTokenAPI.js +11 -0
- package/dist/src/oauth/customUserTokenAPI.js.map +1 -0
- package/dist/src/oauth/index.d.ts +0 -1
- package/dist/src/oauth/index.js +0 -1
- package/dist/src/oauth/index.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +30 -13
- package/dist/src/oauth/userTokenClient.js +62 -26
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/oauth/userTokenClient.types.d.ts +19 -6
- package/dist/src/transcript/fileTranscriptLogger.d.ts +109 -0
- package/dist/src/transcript/fileTranscriptLogger.js +398 -0
- package/dist/src/transcript/fileTranscriptLogger.js.map +1 -0
- package/dist/src/turnContext.d.ts +7 -1
- package/dist/src/turnContext.js +11 -4
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +10 -6
- package/src/activityWireCompat.ts +12 -4
- package/src/agent-client/agentClient.ts +9 -3
- package/src/agent-client/agentResponseHandler.ts +5 -2
- package/src/app/agentApplication.ts +95 -74
- package/src/app/agentApplicationBuilder.ts +2 -2
- package/src/app/agentApplicationOptions.ts +10 -2
- package/src/app/appRoute.ts +8 -0
- package/src/app/auth/authorization.ts +261 -0
- package/src/app/auth/authorizationManager.ts +213 -0
- package/src/app/auth/handlerStorage.ts +61 -0
- package/src/app/auth/handlers/agenticAuthorization.ts +183 -0
- package/src/app/auth/handlers/azureBotAuthorization.ts +606 -0
- package/src/app/auth/handlers/index.ts +2 -0
- package/src/app/auth/index.ts +2 -0
- package/src/app/auth/types.ts +111 -0
- package/src/app/index.ts +3 -3
- package/src/app/routeList.ts +24 -5
- package/src/app/streaming/streamingResponse.ts +2 -1
- package/src/auth/MemoryCache.ts +59 -0
- package/src/auth/authConfiguration.ts +245 -52
- package/src/auth/authConstants.ts +11 -0
- package/src/auth/authProvider.ts +34 -0
- package/src/auth/connections.ts +47 -0
- package/src/auth/index.ts +2 -0
- package/src/auth/jwt-middleware.ts +38 -21
- package/src/auth/msalConnectionManager.ts +175 -0
- package/src/auth/msalTokenProvider.ts +228 -9
- package/src/baseAdapter.ts +10 -29
- package/src/cards/cardFactory.ts +3 -2
- package/src/cloudAdapter.ts +207 -72
- package/src/connector-client/connectorClient.ts +59 -15
- package/src/index.ts +0 -1
- package/src/oauth/customUserTokenAPI.ts +5 -0
- package/src/oauth/index.ts +0 -1
- package/src/oauth/userTokenClient.ts +76 -22
- package/src/oauth/userTokenClient.types.ts +20 -8
- package/src/transcript/fileTranscriptLogger.ts +409 -0
- package/src/turnContext.ts +16 -5
- package/dist/src/app/authorization.js +0 -387
- package/dist/src/app/authorization.js.map +0 -1
- package/dist/src/claimsIdentity.d.ts +0 -35
- package/dist/src/claimsIdentity.js +0 -43
- package/dist/src/claimsIdentity.js.map +0 -1
- package/dist/src/oauth/oAuthFlow.d.ts +0 -119
- package/dist/src/oauth/oAuthFlow.js +0 -316
- package/dist/src/oauth/oAuthFlow.js.map +0 -1
- package/src/app/authorization.ts +0 -432
- package/src/claimsIdentity.ts +0 -47
- package/src/oauth/oAuthFlow.ts +0 -378
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { debug } from '@microsoft/agents-activity'
|
|
7
|
+
import { TurnContext } from '../../../turnContext'
|
|
8
|
+
import { AuthorizationHandler, AuthorizationHandlerSettings, AuthorizationHandlerStatus, AuthorizationHandlerTokenOptions } from '../types'
|
|
9
|
+
import { TokenResponse } from '../../../oauth'
|
|
10
|
+
import { AuthProvider } from '../../../auth'
|
|
11
|
+
|
|
12
|
+
const logger = debug('agents:authorization:agentic')
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Options for configuring the Agentic authorization handler.
|
|
16
|
+
*/
|
|
17
|
+
export interface AgenticAuthorizationOptions {
|
|
18
|
+
/**
|
|
19
|
+
* The type of authorization handler.
|
|
20
|
+
* @remarks
|
|
21
|
+
* When using environment variables, this can be set using the `${authHandlerId}_type` variable.
|
|
22
|
+
*/
|
|
23
|
+
type: 'agentic'
|
|
24
|
+
/**
|
|
25
|
+
* 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`).
|
|
28
|
+
*/
|
|
29
|
+
scopes?: string[]
|
|
30
|
+
/**
|
|
31
|
+
* (Optional) An alternative connection name to use for the authorization process.
|
|
32
|
+
* @remarks
|
|
33
|
+
* When using environment variables, this can be set using the `${authHandlerId}_altBlueprintConnectionName` variable.
|
|
34
|
+
*/
|
|
35
|
+
altBlueprintConnectionName?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Settings for configuring the Agentic authorization handler.
|
|
40
|
+
*/
|
|
41
|
+
export interface AgenticAuthorizationSettings extends AuthorizationHandlerSettings {}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Authorization handler for Agentic authentication.
|
|
45
|
+
*/
|
|
46
|
+
export class AgenticAuthorization implements AuthorizationHandler {
|
|
47
|
+
private _options: AgenticAuthorizationOptions
|
|
48
|
+
private _onSuccess?: Parameters<AuthorizationHandler['onSuccess']>[0]
|
|
49
|
+
private _onFailure?: Parameters<AuthorizationHandler['onFailure']>[0]
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates an instance of the AgenticAuthorization class.
|
|
53
|
+
* @param id The unique identifier for the authorization handler.
|
|
54
|
+
* @param options The options for configuring the authorization handler.
|
|
55
|
+
* @param settings The settings for the authorization handler.
|
|
56
|
+
*/
|
|
57
|
+
constructor (public readonly id: string, options: AgenticAuthorizationOptions, private settings: AgenticAuthorizationSettings) {
|
|
58
|
+
if (!this.settings.connections) {
|
|
59
|
+
throw new Error(this.prefix('The \'connections\' option is not available in the app options. Ensure that the app is properly configured.'))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this._options = this.loadOptions(options)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Loads and validates the authorization handler options.
|
|
67
|
+
*/
|
|
68
|
+
private loadOptions (settings: AgenticAuthorizationOptions) {
|
|
69
|
+
const result: AgenticAuthorizationOptions = {
|
|
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
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @inheritdoc
|
|
84
|
+
*/
|
|
85
|
+
signin (): Promise<AuthorizationHandlerStatus> {
|
|
86
|
+
return Promise.resolve(AuthorizationHandlerStatus.IGNORED)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @inheritdoc
|
|
91
|
+
*/
|
|
92
|
+
signout (): Promise<boolean> {
|
|
93
|
+
return Promise.resolve(false)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @inheritdoc
|
|
98
|
+
*/
|
|
99
|
+
async token (context: TurnContext, options?: AuthorizationHandlerTokenOptions): Promise<TokenResponse> {
|
|
100
|
+
try {
|
|
101
|
+
const tokenResponse = this.getContext(context)
|
|
102
|
+
if (tokenResponse.token) {
|
|
103
|
+
logger.debug(this.prefix('Using cached Agentic user token'))
|
|
104
|
+
return tokenResponse
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let connection: AuthProvider
|
|
108
|
+
|
|
109
|
+
if (this._options.altBlueprintConnectionName?.trim()) {
|
|
110
|
+
connection = this.settings.connections.getConnection(this._options.altBlueprintConnectionName)
|
|
111
|
+
} else {
|
|
112
|
+
connection = this.settings.connections.getTokenProvider(context.identity, context.activity.serviceUrl ?? '')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const token = await connection.getAgenticUserToken(
|
|
116
|
+
context.activity.getAgenticTenantId() ?? '',
|
|
117
|
+
context.activity.getAgenticInstanceId() ?? '',
|
|
118
|
+
context.activity.getAgenticUser() ?? '',
|
|
119
|
+
options?.scopes || this._options.scopes!
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
this.setContext(context, { token })
|
|
123
|
+
this._onSuccess?.(context)
|
|
124
|
+
return { token }
|
|
125
|
+
} catch (error) {
|
|
126
|
+
const reason = 'Error retrieving Agentic user token'
|
|
127
|
+
logger.error(this.prefix(reason), error)
|
|
128
|
+
this._onFailure?.(context, `${reason}: ${(error as Error).message}`)
|
|
129
|
+
return { token: undefined }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @inheritdoc
|
|
135
|
+
*/
|
|
136
|
+
onSuccess (callback: (context: TurnContext) => void): void {
|
|
137
|
+
this._onSuccess = callback
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @inheritdoc
|
|
142
|
+
*/
|
|
143
|
+
onFailure (callback: (context: TurnContext, reason?: string) => void): void {
|
|
144
|
+
this._onFailure = callback
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Prefixes a message with the handler ID.
|
|
149
|
+
*/
|
|
150
|
+
private prefix (message: string) {
|
|
151
|
+
return `[handler:${this.id}] ${message}`
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private _key = `${AgenticAuthorization.name}/${this.id}`
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Sets the authorization context in the turn state.
|
|
158
|
+
*/
|
|
159
|
+
private setContext (context: TurnContext, data: TokenResponse) {
|
|
160
|
+
return context.turnState.set(this._key, () => data)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Gets the authorization context from the turn state.
|
|
165
|
+
*/
|
|
166
|
+
private getContext (context: TurnContext): TokenResponse {
|
|
167
|
+
const result = context.turnState.get(this._key)
|
|
168
|
+
return result?.() ?? { token: undefined }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Loads the OAuth scopes from the environment variables.
|
|
173
|
+
*/
|
|
174
|
+
private loadScopes (value:string | undefined): string[] {
|
|
175
|
+
return value?.split(',').reduce<string[]>((acc, scope) => {
|
|
176
|
+
const trimmed = scope.trim()
|
|
177
|
+
if (trimmed) {
|
|
178
|
+
acc.push(trimmed)
|
|
179
|
+
}
|
|
180
|
+
return acc
|
|
181
|
+
}, []) ?? []
|
|
182
|
+
}
|
|
183
|
+
}
|