@microsoft/agents-hosting 1.6.0-beta.8.g226709c215 → 1.6.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 +4 -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 +28 -2
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +10 -0
- package/dist/src/app/attachmentDownloader.js +5 -10
- package/dist/src/app/attachmentDownloader.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/proactive/proactive.d.ts +1 -0
- package/dist/src/app/proactive/proactive.js +30 -15
- package/dist/src/app/proactive/proactive.js.map +1 -1
- package/dist/src/app/teamsAttachmentDownloader.js +6 -8
- 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 +188 -44
- 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 +58 -1
- package/dist/src/cloudAdapter.js +232 -52
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +12 -8
- package/dist/src/connector-client/connectorClient.js +99 -82
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/errorHelper.js +85 -7
- package/dist/src/errorHelper.js.map +1 -1
- package/dist/src/getProductInfo.d.ts +23 -0
- package/dist/src/getProductInfo.js +71 -1
- package/dist/src/getProductInfo.js.map +1 -1
- package/dist/src/headerPropagation.d.ts +17 -2
- package/dist/src/headerPropagation.js +46 -24
- package/dist/src/headerPropagation.js.map +1 -1
- package/dist/src/httpClient.d.ts +60 -0
- package/dist/src/httpClient.js +173 -0
- package/dist/src/httpClient.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +7 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +5 -4
- package/dist/src/oauth/userTokenClient.js +97 -78
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/observability/traces.d.ts +11 -4
- package/dist/src/observability/traces.js +39 -7
- 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 +4 -9
- package/src/agent-client/agentClient.ts +2 -2
- package/src/agent-client/agentResponseHandler.ts +2 -2
- package/src/app/agentApplication.ts +30 -3
- package/src/app/agentApplicationOptions.ts +11 -0
- package/src/app/attachmentDownloader.ts +6 -8
- 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/proactive/proactive.ts +39 -23
- package/src/app/teamsAttachmentDownloader.ts +7 -6
- 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 +180 -42
- package/src/auth/settings.ts +323 -0
- package/src/cloudAdapter.ts +291 -12
- package/src/connector-client/connectorClient.ts +116 -94
- package/src/errorHelper.ts +96 -7
- package/src/getProductInfo.ts +79 -1
- package/src/headerPropagation.ts +55 -23
- package/src/httpClient.ts +223 -0
- package/src/index.ts +5 -1
- package/src/oauth/userTokenClient.ts +103 -84
- package/src/observability/traces.ts +39 -8
- package/src/utils/env.ts +105 -0
- package/src/utils.ts +14 -0
|
@@ -5,6 +5,7 @@ import { SpanNames, trace } from '@microsoft/agents-telemetry'
|
|
|
5
5
|
import { HostingMetrics } from './metrics'
|
|
6
6
|
import { Activity, ConversationReference } from '@microsoft/agents-activity'
|
|
7
7
|
import { HandlerStorage } from '../app/auth/handlerStorage'
|
|
8
|
+
import type { Storage } from '../storage'
|
|
8
9
|
|
|
9
10
|
export const AgentApplicationTraceDefinitions = {
|
|
10
11
|
run: trace.define({
|
|
@@ -121,13 +122,13 @@ export const AdapterTraceDefinitions = {
|
|
|
121
122
|
name: SpanNames.ADAPTER_CREATE_CONNECTOR_CLIENT,
|
|
122
123
|
record: {
|
|
123
124
|
serviceUrl: '',
|
|
124
|
-
|
|
125
|
+
scopes: [] as string[],
|
|
125
126
|
activityIsAgentic: false,
|
|
126
127
|
},
|
|
127
128
|
end ({ span, record }) {
|
|
128
129
|
span.setAttributes({
|
|
129
130
|
service_url: record.serviceUrl ?? 'unknown',
|
|
130
|
-
'auth.
|
|
131
|
+
'auth.scopes': record.scopes ?? 'unknown',
|
|
131
132
|
})
|
|
132
133
|
|
|
133
134
|
if (record.activityIsAgentic !== undefined) {
|
|
@@ -259,6 +260,12 @@ export const ProactiveTraceDefinitions = {
|
|
|
259
260
|
record: {
|
|
260
261
|
conversationId: '',
|
|
261
262
|
},
|
|
263
|
+
actions: ({ span }) => ({
|
|
264
|
+
async link (storage: Storage, key: string) {
|
|
265
|
+
const item = (await storage.read([key]))?.[key] ?? {}
|
|
266
|
+
return link(span, item)
|
|
267
|
+
}
|
|
268
|
+
}),
|
|
262
269
|
end ({ span, record }) {
|
|
263
270
|
span.setAttributes({
|
|
264
271
|
'activity.conversation_id': record.conversationId ?? 'unknown',
|
|
@@ -307,6 +314,12 @@ export const ProactiveTraceDefinitions = {
|
|
|
307
314
|
channelId: '',
|
|
308
315
|
activityType: '',
|
|
309
316
|
},
|
|
317
|
+
actions: ({ span }) => ({
|
|
318
|
+
async link (storage: Storage, key: string) {
|
|
319
|
+
const item = (await storage.read([key]))?.[key] ?? {}
|
|
320
|
+
link(span, item)
|
|
321
|
+
}
|
|
322
|
+
}),
|
|
310
323
|
end ({ span, record, duration, error }) {
|
|
311
324
|
const attributes = {
|
|
312
325
|
'activity.channel_id': record.channelId ?? 'unknown',
|
|
@@ -335,6 +348,12 @@ export const ProactiveTraceDefinitions = {
|
|
|
335
348
|
channelId: '',
|
|
336
349
|
hasAutoSignIn: false,
|
|
337
350
|
},
|
|
351
|
+
actions: ({ span }) => ({
|
|
352
|
+
async link (storage: Storage, key: string) {
|
|
353
|
+
const item = (await storage.read([key]))?.[key] ?? {}
|
|
354
|
+
link(span, item)
|
|
355
|
+
}
|
|
356
|
+
}),
|
|
338
357
|
end ({ span, record, duration, error }) {
|
|
339
358
|
const attributes = {
|
|
340
359
|
'activity.channel_id': record.channelId ?? 'unknown',
|
|
@@ -783,12 +802,7 @@ export const AuthorizationTraceDefinitions = {
|
|
|
783
802
|
return
|
|
784
803
|
}
|
|
785
804
|
|
|
786
|
-
|
|
787
|
-
span.addLink({ context: active.__link })
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
active.__link = span.spanContext()
|
|
791
|
-
await storage.write(active)
|
|
805
|
+
await storage.write(link(span, active))
|
|
792
806
|
}
|
|
793
807
|
}),
|
|
794
808
|
end ({ span, record }) {
|
|
@@ -986,3 +1000,20 @@ export const UserTokenClientTraceDefinitions = {
|
|
|
986
1000
|
}
|
|
987
1001
|
}),
|
|
988
1002
|
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Adds a link to the span in the item and returns the updated item with the new link context.
|
|
1006
|
+
* @remarks
|
|
1007
|
+
* - **Parent to child**: use the returned item to 'link' future child spans.
|
|
1008
|
+
* - **Parent to children**: use the original item to 'link' future child spans. Ignore the returned item.
|
|
1009
|
+
*/
|
|
1010
|
+
function link <T extends { __link?: unknown }> (span: any, item?: T) {
|
|
1011
|
+
if (item?.__link) {
|
|
1012
|
+
span.addLink({ context: item.__link })
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
return {
|
|
1016
|
+
...(item ?? {}),
|
|
1017
|
+
__link: span.spanContext()
|
|
1018
|
+
} as T
|
|
1019
|
+
}
|
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
|
+
}
|