@microsoft/agents-hosting 1.9.1 → 1.10.0-beta.14.ge6d1defc27
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/README.md +83 -7
- package/dist/package.json +4 -4
- package/dist/src/activityHandler.js +6 -3
- package/dist/src/activityHandler.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.d.ts +7 -0
- package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
- package/dist/src/agent-client/createAgentResponseHandler.d.ts +2 -0
- package/dist/src/agent-client/createAgentResponseHandler.js.map +1 -1
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +1 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js +1 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -1
- package/dist/src/app/attachmentDownloadHttpClient.d.ts +13 -0
- package/dist/src/app/attachmentDownloadHttpClient.js +80 -0
- package/dist/src/app/attachmentDownloadHttpClient.js.map +1 -0
- package/dist/src/app/attachmentDownloader.d.ts +2 -0
- package/dist/src/app/attachmentDownloader.js +6 -11
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/auth/authorization.d.ts +58 -0
- package/dist/src/app/auth/authorization.js.map +1 -1
- package/dist/src/app/proactive/conversation.d.ts +18 -0
- package/dist/src/app/proactive/conversation.js +6 -0
- package/dist/src/app/proactive/conversation.js.map +1 -1
- package/dist/src/app/proactive/conversationBuilder.js +2 -1
- package/dist/src/app/proactive/conversationBuilder.js.map +1 -1
- package/dist/src/app/proactive/conversationReferenceBuilder.js +8 -4
- package/dist/src/app/proactive/conversationReferenceBuilder.js.map +1 -1
- package/dist/src/app/proactive/createConversationOptionsBuilder.d.ts +1 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.js +2 -1
- package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -1
- package/dist/src/app/proactive/proactive.d.ts +6 -0
- package/dist/src/app/proactive/proactive.js +32 -1
- package/dist/src/app/proactive/proactive.js.map +1 -1
- package/dist/src/app/routeList.d.ts +21 -0
- package/dist/src/app/routeList.js +27 -3
- package/dist/src/app/routeList.js.map +1 -1
- package/dist/src/app/teamsAttachmentDownloader.d.ts +8 -0
- package/dist/src/app/teamsAttachmentDownloader.js +17 -12
- package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +1 -0
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/authConstants.d.ts +7 -0
- package/dist/src/auth/authConstants.js +7 -0
- package/dist/src/auth/authConstants.js.map +1 -1
- package/dist/src/auth/authProvider.d.ts +36 -0
- package/dist/src/auth/connectionManager.js +2 -1
- package/dist/src/auth/connectionManager.js.map +1 -1
- package/dist/src/auth/connections.d.ts +1 -0
- package/dist/src/auth/msal/msalConnectionManager.d.ts +7 -0
- package/dist/src/auth/msal/msalConnectionManager.js +7 -0
- package/dist/src/auth/msal/msalConnectionManager.js.map +1 -1
- package/dist/src/auth/msal/msalTokenProvider.d.ts +44 -0
- package/dist/src/auth/msal/msalTokenProvider.js +43 -0
- package/dist/src/auth/msal/msalTokenProvider.js.map +1 -1
- package/dist/src/auth/settings.d.ts +28 -0
- package/dist/src/auth/settings.js +23 -0
- package/dist/src/auth/settings.js.map +1 -1
- package/dist/src/auth/sidecar/sidecarAuthProvider.d.ts +3 -0
- package/dist/src/auth/sidecar/sidecarAuthProvider.js.map +1 -1
- package/dist/src/auth/sidecar/sidecarHttpClient.d.ts +1 -9
- package/dist/src/auth/sidecar/sidecarHttpClient.js +3 -69
- package/dist/src/auth/sidecar/sidecarHttpClient.js.map +1 -1
- package/dist/src/baseAdapter.d.ts +6 -0
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cards/taskModuleAction.d.ts +6 -0
- package/dist/src/cards/taskModuleAction.js +6 -0
- package/dist/src/cards/taskModuleAction.js.map +1 -1
- package/dist/src/cloudAdapter.d.ts +29 -0
- package/dist/src/cloudAdapter.js +45 -8
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/configuration/configuration.d.ts +1 -0
- package/dist/src/configuration/configuration.js +2 -1
- package/dist/src/configuration/configuration.js.map +1 -1
- package/dist/src/configuration/environmentConfiguration.js +1 -1
- package/dist/src/configuration/environmentConfiguration.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +8 -0
- package/dist/src/connector-client/connectorClient.js +8 -0
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/createCloudAdapter.d.ts +2 -0
- package/dist/src/createCloudAdapter.js.map +1 -1
- package/dist/src/errorHelper.d.ts +1 -0
- package/dist/src/errorHelper.js +9 -0
- package/dist/src/errorHelper.js.map +1 -1
- package/dist/src/headerPropagation.d.ts +38 -0
- package/dist/src/headerPropagation.js +33 -0
- package/dist/src/headerPropagation.js.map +1 -1
- package/dist/src/httpClient.d.ts +58 -0
- package/dist/src/httpClient.js +40 -0
- package/dist/src/httpClient.js.map +1 -1
- package/dist/src/interfaces/webResponse.d.ts +7 -0
- package/dist/src/middlewareSet.d.ts +6 -0
- package/dist/src/middlewareSet.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +6 -0
- package/dist/src/oauth/userTokenClient.js +12 -0
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/outboundHostValidator.d.ts +33 -1
- package/dist/src/outboundHostValidator.js +60 -25
- package/dist/src/outboundHostValidator.js.map +1 -1
- package/dist/src/storage/fileStorage.d.ts +26 -0
- package/dist/src/storage/fileStorage.js +35 -6
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/memoryStorage.d.ts +34 -0
- package/dist/src/storage/memoryStorage.js +41 -4
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/storage/storage.d.ts +20 -0
- package/dist/src/storage/storage.js +7 -0
- package/dist/src/storage/storage.js.map +1 -1
- package/dist/src/storage/storageCompatibility.js +12 -6
- package/dist/src/storage/storageCompatibility.js.map +1 -1
- package/dist/src/storage/storageExpiry.d.ts +7 -0
- package/dist/src/storage/storageExpiry.js +7 -0
- package/dist/src/storage/storageExpiry.js.map +1 -1
- package/dist/src/turnContext.d.ts +10 -0
- package/dist/src/turnContext.js +5 -0
- package/dist/src/turnContext.js.map +1 -1
- package/dist/src/utils/env.js +22 -11
- package/dist/src/utils/env.js.map +1 -1
- package/dist/src/utils/ipAddress.d.ts +6 -0
- package/dist/src/utils/ipAddress.js +64 -0
- package/dist/src/utils/ipAddress.js.map +1 -0
- package/dist/src/utils/outboundUrl.d.ts +7 -0
- package/dist/src/utils/outboundUrl.js +52 -0
- package/dist/src/utils/outboundUrl.js.map +1 -0
- package/dist/src/utils.js +2 -1
- package/dist/src/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/activityHandler.ts +9 -3
- package/src/agent-client/agentResponseHandler.ts +7 -0
- package/src/agent-client/createAgentResponseHandler.ts +2 -0
- package/src/app/adaptiveCards/adaptiveCardsActions.ts +1 -0
- package/src/app/attachmentDownloadHttpClient.ts +80 -0
- package/src/app/attachmentDownloader.ts +6 -9
- package/src/app/auth/authorization.ts +58 -0
- package/src/app/proactive/conversation.ts +24 -0
- package/src/app/proactive/conversationBuilder.ts +3 -1
- package/src/app/proactive/conversationReferenceBuilder.ts +12 -4
- package/src/app/proactive/createConversationOptionsBuilder.ts +5 -1
- package/src/app/proactive/proactive.ts +33 -1
- package/src/app/routeList.ts +30 -3
- package/src/app/teamsAttachmentDownloader.ts +17 -10
- package/src/auth/authConfiguration.ts +1 -0
- package/src/auth/authConstants.ts +7 -0
- package/src/auth/authProvider.ts +36 -0
- package/src/auth/connectionManager.ts +3 -1
- package/src/auth/connections.ts +1 -0
- package/src/auth/msal/msalConnectionManager.ts +7 -0
- package/src/auth/msal/msalTokenProvider.ts +59 -0
- package/src/auth/settings.ts +28 -0
- package/src/auth/sidecar/sidecarAuthProvider.ts +4 -0
- package/src/auth/sidecar/sidecarHttpClient.ts +3 -63
- package/src/baseAdapter.ts +6 -0
- package/src/cards/taskModuleAction.ts +6 -0
- package/src/cloudAdapter.ts +59 -10
- package/src/configuration/configuration.ts +4 -2
- package/src/configuration/environmentConfiguration.ts +7 -1
- package/src/connector-client/connectorClient.ts +8 -0
- package/src/createCloudAdapter.ts +2 -0
- package/src/errorHelper.ts +11 -0
- package/src/headerPropagation.ts +38 -0
- package/src/httpClient.ts +58 -0
- package/src/interfaces/webResponse.ts +7 -0
- package/src/middlewareSet.ts +6 -0
- package/src/oauth/userTokenClient.ts +13 -0
- package/src/outboundHostValidator.ts +84 -23
- package/src/storage/fileStorage.ts +46 -6
- package/src/storage/memoryStorage.ts +45 -4
- package/src/storage/storage.ts +20 -0
- package/src/storage/storageCompatibility.ts +18 -6
- package/src/storage/storageExpiry.ts +7 -0
- package/src/turnContext.ts +11 -0
- package/src/utils/env.ts +33 -11
- package/src/utils/ipAddress.ts +63 -0
- package/src/utils/outboundUrl.ts +50 -0
- package/src/utils.ts +3 -1
package/src/utils/env.ts
CHANGED
|
@@ -87,11 +87,19 @@ export const envParserUtils = {
|
|
|
87
87
|
* unrecognized.
|
|
88
88
|
*/
|
|
89
89
|
export function parseBooleanEnv (value: string | undefined): boolean | undefined {
|
|
90
|
-
if (value === undefined)
|
|
90
|
+
if (value === undefined) {
|
|
91
|
+
return undefined
|
|
92
|
+
}
|
|
91
93
|
const v = value.trim().toLowerCase()
|
|
92
|
-
if (v === 'true' || v === '1')
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
if (v === 'true' || v === '1') {
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
97
|
+
if (v === '') {
|
|
98
|
+
return undefined
|
|
99
|
+
}
|
|
100
|
+
if (v === 'false' || v === '0') {
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
95
103
|
return undefined
|
|
96
104
|
}
|
|
97
105
|
|
|
@@ -104,7 +112,9 @@ export function parseBooleanEnv (value: string | undefined): boolean | undefined
|
|
|
104
112
|
* @returns A finite integer, or `fallback` when the input cannot be parsed.
|
|
105
113
|
*/
|
|
106
114
|
export function parseIntEnv (value: string | undefined, fallback: number): number {
|
|
107
|
-
if (value === undefined || value.trim() === '')
|
|
115
|
+
if (value === undefined || value.trim() === '') {
|
|
116
|
+
return fallback
|
|
117
|
+
}
|
|
108
118
|
const parsed = parseInt(value, 10)
|
|
109
119
|
return Number.isNaN(parsed) ? fallback : parsed
|
|
110
120
|
}
|
|
@@ -132,7 +142,9 @@ export function suggestClosest (
|
|
|
132
142
|
candidates: readonly string[],
|
|
133
143
|
maxDistance = 2
|
|
134
144
|
): string | undefined {
|
|
135
|
-
if (!input)
|
|
145
|
+
if (!input) {
|
|
146
|
+
return undefined
|
|
147
|
+
}
|
|
136
148
|
const a = input.toLowerCase()
|
|
137
149
|
const cutoff = Math.min(maxDistance, Math.max(1, Math.ceil(a.length / 2)))
|
|
138
150
|
let best: { name: string, distance: number } | undefined
|
|
@@ -140,7 +152,9 @@ export function suggestClosest (
|
|
|
140
152
|
const d = levenshtein(a, candidate.toLowerCase())
|
|
141
153
|
if (d <= cutoff && (!best || d < best.distance)) {
|
|
142
154
|
best = { name: candidate, distance: d }
|
|
143
|
-
if (d === 0)
|
|
155
|
+
if (d === 0) {
|
|
156
|
+
break
|
|
157
|
+
}
|
|
144
158
|
}
|
|
145
159
|
}
|
|
146
160
|
return best?.name
|
|
@@ -148,11 +162,19 @@ export function suggestClosest (
|
|
|
148
162
|
|
|
149
163
|
/** Standard Levenshtein edit distance using a single-row dynamic-programming table. */
|
|
150
164
|
function levenshtein (a: string, b: string): number {
|
|
151
|
-
if (a === b)
|
|
152
|
-
|
|
153
|
-
|
|
165
|
+
if (a === b) {
|
|
166
|
+
return 0
|
|
167
|
+
}
|
|
168
|
+
if (a.length === 0) {
|
|
169
|
+
return b.length
|
|
170
|
+
}
|
|
171
|
+
if (b.length === 0) {
|
|
172
|
+
return a.length
|
|
173
|
+
}
|
|
154
174
|
const row = new Array<number>(b.length + 1)
|
|
155
|
-
for (let j = 0; j <= b.length; j++)
|
|
175
|
+
for (let j = 0; j <= b.length; j++) {
|
|
176
|
+
row[j] = j
|
|
177
|
+
}
|
|
156
178
|
for (let i = 1; i <= a.length; i++) {
|
|
157
179
|
let prev = i - 1
|
|
158
180
|
row[0] = i
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isIP } from 'node:net'
|
|
7
|
+
|
|
8
|
+
function normalizeAddress (address: string): string | undefined {
|
|
9
|
+
const unwrapped = address.startsWith('[') && address.endsWith(']') ? address.slice(1, -1) : address
|
|
10
|
+
const version = isIP(unwrapped)
|
|
11
|
+
if (version === 0) {
|
|
12
|
+
return undefined
|
|
13
|
+
}
|
|
14
|
+
return version === 6 ? new URL(`http://[${unwrapped}]`).hostname.slice(1, -1) : unwrapped
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function mappedIPv4 (address: string): string | undefined {
|
|
18
|
+
const match = address.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/)
|
|
19
|
+
if (!match) {
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
22
|
+
const high = parseInt(match[1], 16)
|
|
23
|
+
const low = parseInt(match[2], 16)
|
|
24
|
+
return `${high >> 8}.${high & 0xff}.${low >> 8}.${low & 0xff}`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isPrivateOrLoopbackAddress (address: string): boolean {
|
|
28
|
+
const normalized = normalizeAddress(address)
|
|
29
|
+
if (!normalized) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
const ipv4 = mappedIPv4(normalized) ?? normalized
|
|
33
|
+
if (isIP(ipv4) === 4) {
|
|
34
|
+
const bytes = ipv4.split('.').map(Number)
|
|
35
|
+
return bytes[0] === 127 ||
|
|
36
|
+
bytes[0] === 10 ||
|
|
37
|
+
(bytes[0] === 172 && bytes[1] >= 16 && bytes[1] <= 31) ||
|
|
38
|
+
(bytes[0] === 192 && bytes[1] === 168) ||
|
|
39
|
+
(bytes[0] === 169 && bytes[1] === 254)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (normalized === '::1') {
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
const firstHextet = parseInt(normalized.split(':')[0], 16)
|
|
46
|
+
return (firstHextet & 0xfe00) === 0xfc00 ||
|
|
47
|
+
(firstHextet & 0xffc0) === 0xfe80 ||
|
|
48
|
+
(firstHextet & 0xffc0) === 0xfec0
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isBlockedOutboundAddress (address: string): boolean {
|
|
52
|
+
const normalized = normalizeAddress(address)
|
|
53
|
+
if (!normalized) {
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
const ipv4 = mappedIPv4(normalized) ?? normalized
|
|
57
|
+
const [first, second] = ipv4.split('.').map(Number)
|
|
58
|
+
// RFC 6598 shared space is outbound-only; it must not become trusted sidecar space.
|
|
59
|
+
return normalized === '::' ||
|
|
60
|
+
ipv4 === '0.0.0.0' ||
|
|
61
|
+
(first === 100 && second >= 64 && second <= 127) ||
|
|
62
|
+
isPrivateOrLoopbackAddress(normalized)
|
|
63
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { promises as dns } from 'node:dns'
|
|
7
|
+
import { isIP } from 'node:net'
|
|
8
|
+
import { debug } from '@microsoft/agents-telemetry'
|
|
9
|
+
import { isBlockedOutboundAddress } from './ipAddress'
|
|
10
|
+
|
|
11
|
+
const logger = debug('agents:outboundHostValidator')
|
|
12
|
+
|
|
13
|
+
export function getHttpsUrl (input: string | URL | null | undefined): URL | undefined {
|
|
14
|
+
if (!input) {
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const url = input instanceof URL ? input : new URL(input)
|
|
19
|
+
return url.protocol === 'https:' && !url.username && !url.password ? url : undefined
|
|
20
|
+
} catch {
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isLocalOrBlockedHost (host: string): boolean {
|
|
26
|
+
const unwrapped = host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host
|
|
27
|
+
return host === 'localhost' || host.endsWith('.localhost') ||
|
|
28
|
+
(isIP(unwrapped) !== 0 && isBlockedOutboundAddress(unwrapped))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function hasAllowedOutboundAddresses (url: URL, allowPrivateNetworkAddresses = false): Promise<boolean> {
|
|
32
|
+
if (allowPrivateNetworkAddresses) {
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
const host = url.hostname.replace(/^\[|\]$/g, '').replace(/\.$/, '')
|
|
36
|
+
if (isLocalOrBlockedHost(host)) {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
if (isIP(host) !== 0) {
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const addresses = await dns.lookup(host, { all: true })
|
|
45
|
+
return addresses.length > 0 && addresses.every(({ address }) => !isBlockedOutboundAddress(address))
|
|
46
|
+
} catch {
|
|
47
|
+
logger.warn(`Attachment destination DNS lookup failed. Host='${host}'`)
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -18,7 +18,9 @@ export const mergeDefined = <T extends Record<string, any>>(
|
|
|
18
18
|
): T => {
|
|
19
19
|
const result: Partial<T> = {}
|
|
20
20
|
for (const layer of layers) {
|
|
21
|
-
if (layer)
|
|
21
|
+
if (layer) {
|
|
22
|
+
Object.assign(result, prune(layer))
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
return result as T
|
|
24
26
|
}
|