@microsoft/agents-hosting 1.6.0-beta.4.g8ab0e486bc → 1.6.0-beta.41.g36be9b7b46
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 +5 -9
- package/dist/src/agent-client/agentClient.js +2 -2
- 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.js +27 -2
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/auth/authorizationManager.d.ts +4 -0
- package/dist/src/app/auth/authorizationManager.js +94 -67
- package/dist/src/app/auth/authorizationManager.js.map +1 -1
- package/dist/src/app/auth/handlers/azureBotAuthorization.js +2 -2
- package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -1
- package/dist/src/app/proactive/createConversationOptionsBuilder.js +10 -6
- package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -1
- package/dist/src/app/teamsAttachmentDownloader.js +7 -1
- package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +2 -143
- package/dist/src/auth/authConfiguration.js +301 -257
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +2 -1
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalConnectionManager.js +27 -14
- package/dist/src/auth/msalConnectionManager.js.map +1 -1
- package/dist/src/auth/msalTokenProvider.d.ts +7 -0
- package/dist/src/auth/msalTokenProvider.js +156 -38
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/auth/settings.d.ts +327 -0
- package/dist/src/auth/settings.js +158 -0
- package/dist/src/auth/settings.js.map +1 -0
- package/dist/src/cloudAdapter.d.ts +51 -1
- package/dist/src/cloudAdapter.js +219 -50
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +2 -2
- package/dist/src/connector-client/connectorClient.js +7 -8
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/errorHelper.js +50 -0
- package/dist/src/errorHelper.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +6 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/oauth/userTokenClient.js +1 -1
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/observability/traces.d.ts +1 -1
- package/dist/src/observability/traces.js +2 -2
- package/dist/src/observability/traces.js.map +1 -1
- package/dist/src/utils/env.d.ts +50 -0
- package/dist/src/utils/env.js +113 -0
- package/dist/src/utils/env.js.map +1 -0
- package/dist/src/utils.d.ts +10 -0
- package/dist/src/utils.js +18 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +5 -9
- package/src/agent-client/agentClient.ts +2 -2
- package/src/agent-client/agentResponseHandler.ts +2 -2
- package/src/app/agentApplication.ts +28 -3
- package/src/app/auth/authorizationManager.ts +84 -41
- package/src/app/auth/handlers/azureBotAuthorization.ts +2 -2
- package/src/app/proactive/createConversationOptionsBuilder.ts +8 -4
- package/src/app/teamsAttachmentDownloader.ts +6 -1
- package/src/auth/authConfiguration.ts +317 -356
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/auth/msalConnectionManager.ts +27 -10
- package/src/auth/msalTokenProvider.ts +143 -33
- package/src/auth/settings.ts +323 -0
- package/src/cloudAdapter.ts +272 -10
- package/src/connector-client/connectorClient.ts +8 -8
- package/src/errorHelper.ts +57 -0
- package/src/index.ts +4 -1
- package/src/oauth/userTokenClient.ts +1 -1
- package/src/observability/traces.ts +2 -2
- package/src/utils/env.ts +105 -0
- package/src/utils.ts +14 -0
|
@@ -15,6 +15,7 @@ import { getProductInfo } from '../getProductInfo'
|
|
|
15
15
|
import { HeaderPropagation, HeaderPropagationCollection } from '../headerPropagation'
|
|
16
16
|
import { trace } from '@microsoft/agents-telemetry'
|
|
17
17
|
import { ConnectorClientTraceDefinitions } from '../observability'
|
|
18
|
+
import { parseIntEnv } from '../utils/env'
|
|
18
19
|
|
|
19
20
|
const logger = debug('agents:connector-client')
|
|
20
21
|
|
|
@@ -236,20 +237,19 @@ export class ConnectorClient {
|
|
|
236
237
|
}
|
|
237
238
|
|
|
238
239
|
/**
|
|
239
|
-
* Trim the conversationId
|
|
240
|
+
* Trim and sanitize the conversationId when creating the URL for agentic calls in agents channels.
|
|
240
241
|
* @param conversationId The ID of the conversation to potentially truncate.
|
|
241
242
|
* @param activity The activity object used to determine if truncation is necessary.
|
|
242
|
-
* @returns The original
|
|
243
|
+
* @returns The original conversationId for non-agents channels/non-agentic roles, otherwise a trimmed and sanitized value.
|
|
243
244
|
*/
|
|
244
245
|
private conditionallyTruncateConversationId (conversationId: string, activity: Activity): string {
|
|
245
246
|
if (
|
|
246
|
-
|
|
247
|
+
activity.channelIdChannel === Channels.Agents &&
|
|
247
248
|
(activity.from?.role === RoleTypes.AgenticIdentity || activity.from?.role === RoleTypes.AgenticUser)) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
return conversationId.length > maxLength ? conversationId.substring(0, maxLength) : conversationId
|
|
249
|
+
const maxLength = parseIntEnv(process.env.MAX_APX_CONVERSATION_ID_LENGTH, 150)
|
|
250
|
+
const trimmedConversationId = conversationId.length > maxLength ? conversationId.substring(0, maxLength) : conversationId
|
|
251
|
+
|
|
252
|
+
return trimmedConversationId.replace(/[/\\#?]/g, '_')
|
|
253
253
|
} else {
|
|
254
254
|
return conversationId
|
|
255
255
|
}
|
package/src/errorHelper.ts
CHANGED
|
@@ -516,6 +516,54 @@ export const Errors: { [key: string]: AgentErrorDefinition } = {
|
|
|
516
516
|
description: "The current token for the '{connectionName}' AzureBot connection is not exchangeable for an on-behalf-of flow. Ensure the base token audience is for the bot/resource app, such as an App ID URI like 'api://...' or otherwise includes the app's client id."
|
|
517
517
|
},
|
|
518
518
|
|
|
519
|
+
/**
|
|
520
|
+
* Error thrown when an unsupported authentication type is specified in authConfig.
|
|
521
|
+
*/
|
|
522
|
+
UnsupportedAuthType: {
|
|
523
|
+
code: -120593,
|
|
524
|
+
description: 'Unsupported authentication type: {authType}'
|
|
525
|
+
},
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Error thrown when WorkloadIdentity authentication requires `federatedTokenFile` or the deprecated `WIDAssertionFile` to be configured.
|
|
529
|
+
*/
|
|
530
|
+
WorkloadIdentityTokenFileRequired: {
|
|
531
|
+
code: -120594,
|
|
532
|
+
description: 'WorkloadIdentity authentication requires `federatedTokenFile` or the deprecated `WIDAssertionFile` to be configured'
|
|
533
|
+
},
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Error thrown when ClientSecret authentication is specified but `clientSecret` is not configured.
|
|
537
|
+
*/
|
|
538
|
+
ClientSecretRequired: {
|
|
539
|
+
code: -120595,
|
|
540
|
+
description: 'ClientSecret authentication requires `clientSecret` to be configured'
|
|
541
|
+
},
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Error thrown when Certificate authentication is specified but `certPemFile` or `certKeyFile` is not configured.
|
|
545
|
+
*/
|
|
546
|
+
CertificateFilesRequired: {
|
|
547
|
+
code: -120596,
|
|
548
|
+
description: 'Certificate authentication requires both `certPemFile` and `certKeyFile` to be configured'
|
|
549
|
+
},
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Error thrown when FederatedCredentials authentication is specified but `federatedClientId` or the deprecated `FICClientId` is not configured.
|
|
553
|
+
*/
|
|
554
|
+
FICClientIdRequired: {
|
|
555
|
+
code: -120597,
|
|
556
|
+
description: 'FederatedCredentials authentication requires `federatedClientId` or the deprecated `FICClientId` to be configured'
|
|
557
|
+
},
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Error thrown when UserManagedIdentity authentication is specified but `clientId` is not configured.
|
|
561
|
+
*/
|
|
562
|
+
ClientIdRequiredForUserManagedIdentity: {
|
|
563
|
+
code: -120598,
|
|
564
|
+
description: 'UserManagedIdentity authentication requires `clientId` to be configured'
|
|
565
|
+
},
|
|
566
|
+
|
|
519
567
|
// ============================================================================
|
|
520
568
|
// Agent and Client Errors (-120600 to -120630)
|
|
521
569
|
// ============================================================================
|
|
@@ -784,6 +832,15 @@ export const Errors: { [key: string]: AgentErrorDefinition } = {
|
|
|
784
832
|
description: 'This proactive operation requires app storage to load and save TurnState. Set options.storage on AgentApplication.'
|
|
785
833
|
},
|
|
786
834
|
|
|
835
|
+
/**
|
|
836
|
+
* Error thrown when CreateConversationOptionsBuilder.build() is called for a Teams channel
|
|
837
|
+
* conversation (withTeamsChannelId) without an activity set via withActivity().
|
|
838
|
+
*/
|
|
839
|
+
CreateConversationBuilderChannelActivityRequired: {
|
|
840
|
+
code: -120753,
|
|
841
|
+
description: 'CreateConversationOptionsBuilder: Teams channel conversations require an initial activity. Call withActivity() before build().'
|
|
842
|
+
},
|
|
843
|
+
|
|
787
844
|
// ============================================================================
|
|
788
845
|
// General Errors (-120990)
|
|
789
846
|
// ============================================================================
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,10 @@ export * from './transcript'
|
|
|
18
18
|
|
|
19
19
|
export * from './activityHandler'
|
|
20
20
|
export * from './baseAdapter'
|
|
21
|
-
export
|
|
21
|
+
// Note: re-export the public surface of `cloudAdapter` explicitly so the
|
|
22
|
+
// test-only internals (e.g., the per-process warning dedup set) do not leak
|
|
23
|
+
// into the package's public API.
|
|
24
|
+
export { CloudAdapter, type CloudAdapterOptions } from './cloudAdapter'
|
|
22
25
|
export * from './middlewareSet'
|
|
23
26
|
export * from './messageFactory'
|
|
24
27
|
export * from './statusCodes'
|
|
@@ -243,7 +243,7 @@ export class UserTokenClient {
|
|
|
243
243
|
const state = Buffer.from(JSON.stringify({ conversation, relatesTo, connectionName, msAppId: this.msAppId })).toString('base64')
|
|
244
244
|
const params = { userId, connectionName, channelId, state, code, finalRedirect, fwdUrl }
|
|
245
245
|
const response = await this.client.get('/api/usertoken/GetTokenOrSignInResource', { params })
|
|
246
|
-
record({ userId, connectionName, channelId, httpStatusCode: response
|
|
246
|
+
record({ userId, connectionName, channelId, httpStatusCode: response?.status?.toString() })
|
|
247
247
|
return response.data as TokenOrSinginResourceResponse
|
|
248
248
|
})
|
|
249
249
|
}
|
|
@@ -121,13 +121,13 @@ export const AdapterTraceDefinitions = {
|
|
|
121
121
|
name: SpanNames.ADAPTER_CREATE_CONNECTOR_CLIENT,
|
|
122
122
|
record: {
|
|
123
123
|
serviceUrl: '',
|
|
124
|
-
|
|
124
|
+
scopes: [] as string[],
|
|
125
125
|
activityIsAgentic: false,
|
|
126
126
|
},
|
|
127
127
|
end ({ span, record }) {
|
|
128
128
|
span.setAttributes({
|
|
129
129
|
service_url: record.serviceUrl ?? 'unknown',
|
|
130
|
-
'auth.
|
|
130
|
+
'auth.scopes': record.scopes ?? 'unknown',
|
|
131
131
|
})
|
|
132
132
|
|
|
133
133
|
if (record.activityIsAgentic !== undefined) {
|
package/src/utils/env.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Internal helpers for parsing environment-variable strings into typed values.
|
|
6
|
+
*
|
|
7
|
+
* These helpers are intentionally NOT exported from the package's public
|
|
8
|
+
* `index.ts`; they are an internal utility shared between the adapter,
|
|
9
|
+
* authentication, and connector-client modules. Keeping them internal lets us
|
|
10
|
+
* normalize behavior across the package without growing the public API.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Parses an environment-variable string into a boolean.
|
|
15
|
+
*
|
|
16
|
+
* Recognized truthy values (case-insensitive, trimmed): `"true"`, `"1"`.
|
|
17
|
+
* Recognized falsy values (case-insensitive, trimmed): `"false"`, `"0"`.
|
|
18
|
+
* Returns `undefined` for unset (`undefined`), empty strings, or any other
|
|
19
|
+
* value, so callers can distinguish "not specified" from explicit `false`.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The raw environment variable value (typically
|
|
22
|
+
* `process.env.X`).
|
|
23
|
+
* @returns `true`, `false`, or `undefined` when the value is unset or
|
|
24
|
+
* unrecognized.
|
|
25
|
+
*/
|
|
26
|
+
export function parseBooleanEnv (value: string | undefined): boolean | undefined {
|
|
27
|
+
if (value === undefined) return undefined
|
|
28
|
+
const v = value.trim().toLowerCase()
|
|
29
|
+
if (v === 'true' || v === '1') return true
|
|
30
|
+
if (v === '') return undefined
|
|
31
|
+
if (v === 'false' || v === '0') return false
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Parses an environment-variable string into an integer, returning the
|
|
37
|
+
* supplied fallback for unset, empty, or non-numeric values.
|
|
38
|
+
*
|
|
39
|
+
* @param value - The raw environment variable value.
|
|
40
|
+
* @param fallback - The value to return when the input is unset or invalid.
|
|
41
|
+
* @returns A finite integer, or `fallback` when the input cannot be parsed.
|
|
42
|
+
*/
|
|
43
|
+
export function parseIntEnv (value: string | undefined, fallback: number): number {
|
|
44
|
+
if (value === undefined || value.trim() === '') return fallback
|
|
45
|
+
const parsed = parseInt(value, 10)
|
|
46
|
+
return Number.isNaN(parsed) ? fallback : parsed
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns the candidate from `candidates` that is closest to `input` by
|
|
51
|
+
* Levenshtein edit distance, provided the distance is no greater than
|
|
52
|
+
* `maxDistance`. Returns `undefined` when no candidate is close enough or the
|
|
53
|
+
* input is empty.
|
|
54
|
+
*
|
|
55
|
+
* Intended for "did you mean X?" hints on unknown configuration keys.
|
|
56
|
+
* Comparison is case-insensitive so casing differences alone never count as
|
|
57
|
+
* an edit. Ties are broken by the order in which candidates appear.
|
|
58
|
+
*
|
|
59
|
+
* In addition to `maxDistance`, the match must be within 50% of the input
|
|
60
|
+
* length (rounded up). This prevents confident-but-wrong suggestions on
|
|
61
|
+
* short inputs (e.g., a 4-char typo matching a 6-char canonical name).
|
|
62
|
+
*
|
|
63
|
+
* @param input - The unknown name supplied by the user.
|
|
64
|
+
* @param candidates - The set of known valid names.
|
|
65
|
+
* @param maxDistance - Maximum edit distance to consider a match (default 2).
|
|
66
|
+
*/
|
|
67
|
+
export function suggestClosest (
|
|
68
|
+
input: string,
|
|
69
|
+
candidates: readonly string[],
|
|
70
|
+
maxDistance = 2
|
|
71
|
+
): string | undefined {
|
|
72
|
+
if (!input) return undefined
|
|
73
|
+
const a = input.toLowerCase()
|
|
74
|
+
const cutoff = Math.min(maxDistance, Math.max(1, Math.ceil(a.length / 2)))
|
|
75
|
+
let best: { name: string, distance: number } | undefined
|
|
76
|
+
for (const candidate of candidates) {
|
|
77
|
+
const d = levenshtein(a, candidate.toLowerCase())
|
|
78
|
+
if (d <= cutoff && (!best || d < best.distance)) {
|
|
79
|
+
best = { name: candidate, distance: d }
|
|
80
|
+
if (d === 0) break
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return best?.name
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Standard Levenshtein edit distance using a single-row dynamic-programming table. */
|
|
87
|
+
function levenshtein (a: string, b: string): number {
|
|
88
|
+
if (a === b) return 0
|
|
89
|
+
if (a.length === 0) return b.length
|
|
90
|
+
if (b.length === 0) return a.length
|
|
91
|
+
const row = new Array<number>(b.length + 1)
|
|
92
|
+
for (let j = 0; j <= b.length; j++) row[j] = j
|
|
93
|
+
for (let i = 1; i <= a.length; i++) {
|
|
94
|
+
let prev = i - 1
|
|
95
|
+
row[0] = i
|
|
96
|
+
for (let j = 1; j <= b.length; j++) {
|
|
97
|
+
const temp = row[j]
|
|
98
|
+
row[j] = a[i - 1] === b[j - 1]
|
|
99
|
+
? prev
|
|
100
|
+
: 1 + Math.min(prev, row[j - 1], row[j])
|
|
101
|
+
prev = temp
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return row[b.length]
|
|
105
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Utility function to prune undefined values from an object. This is useful for cleaning up configuration objects before logging or processing, ensuring that only defined values are included.
|
|
8
|
+
* @param obj The object to prune
|
|
9
|
+
* @returns A new object with all undefined values removed
|
|
10
|
+
*/
|
|
11
|
+
export const prune = <T extends Record<string, any>>(obj: T) => {
|
|
12
|
+
const entries = Object.entries(obj).filter(([, value]) => value !== undefined)
|
|
13
|
+
return Object.fromEntries(entries) as T
|
|
14
|
+
}
|