@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.
Files changed (173) hide show
  1. package/README.md +83 -7
  2. package/dist/package.json +4 -4
  3. package/dist/src/activityHandler.js +6 -3
  4. package/dist/src/activityHandler.js.map +1 -1
  5. package/dist/src/agent-client/agentResponseHandler.d.ts +7 -0
  6. package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
  7. package/dist/src/agent-client/createAgentResponseHandler.d.ts +2 -0
  8. package/dist/src/agent-client/createAgentResponseHandler.js.map +1 -1
  9. package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +1 -0
  10. package/dist/src/app/adaptiveCards/adaptiveCardsActions.js +1 -0
  11. package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -1
  12. package/dist/src/app/attachmentDownloadHttpClient.d.ts +13 -0
  13. package/dist/src/app/attachmentDownloadHttpClient.js +80 -0
  14. package/dist/src/app/attachmentDownloadHttpClient.js.map +1 -0
  15. package/dist/src/app/attachmentDownloader.d.ts +2 -0
  16. package/dist/src/app/attachmentDownloader.js +6 -11
  17. package/dist/src/app/attachmentDownloader.js.map +1 -1
  18. package/dist/src/app/auth/authorization.d.ts +58 -0
  19. package/dist/src/app/auth/authorization.js.map +1 -1
  20. package/dist/src/app/proactive/conversation.d.ts +18 -0
  21. package/dist/src/app/proactive/conversation.js +6 -0
  22. package/dist/src/app/proactive/conversation.js.map +1 -1
  23. package/dist/src/app/proactive/conversationBuilder.js +2 -1
  24. package/dist/src/app/proactive/conversationBuilder.js.map +1 -1
  25. package/dist/src/app/proactive/conversationReferenceBuilder.js +8 -4
  26. package/dist/src/app/proactive/conversationReferenceBuilder.js.map +1 -1
  27. package/dist/src/app/proactive/createConversationOptionsBuilder.d.ts +1 -0
  28. package/dist/src/app/proactive/createConversationOptionsBuilder.js +2 -1
  29. package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -1
  30. package/dist/src/app/proactive/proactive.d.ts +6 -0
  31. package/dist/src/app/proactive/proactive.js +32 -1
  32. package/dist/src/app/proactive/proactive.js.map +1 -1
  33. package/dist/src/app/routeList.d.ts +21 -0
  34. package/dist/src/app/routeList.js +27 -3
  35. package/dist/src/app/routeList.js.map +1 -1
  36. package/dist/src/app/teamsAttachmentDownloader.d.ts +8 -0
  37. package/dist/src/app/teamsAttachmentDownloader.js +17 -12
  38. package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
  39. package/dist/src/auth/authConfiguration.d.ts +1 -0
  40. package/dist/src/auth/authConfiguration.js.map +1 -1
  41. package/dist/src/auth/authConstants.d.ts +7 -0
  42. package/dist/src/auth/authConstants.js +7 -0
  43. package/dist/src/auth/authConstants.js.map +1 -1
  44. package/dist/src/auth/authProvider.d.ts +36 -0
  45. package/dist/src/auth/connectionManager.js +2 -1
  46. package/dist/src/auth/connectionManager.js.map +1 -1
  47. package/dist/src/auth/connections.d.ts +1 -0
  48. package/dist/src/auth/msal/msalConnectionManager.d.ts +7 -0
  49. package/dist/src/auth/msal/msalConnectionManager.js +7 -0
  50. package/dist/src/auth/msal/msalConnectionManager.js.map +1 -1
  51. package/dist/src/auth/msal/msalTokenProvider.d.ts +44 -0
  52. package/dist/src/auth/msal/msalTokenProvider.js +43 -0
  53. package/dist/src/auth/msal/msalTokenProvider.js.map +1 -1
  54. package/dist/src/auth/settings.d.ts +28 -0
  55. package/dist/src/auth/settings.js +23 -0
  56. package/dist/src/auth/settings.js.map +1 -1
  57. package/dist/src/auth/sidecar/sidecarAuthProvider.d.ts +3 -0
  58. package/dist/src/auth/sidecar/sidecarAuthProvider.js.map +1 -1
  59. package/dist/src/auth/sidecar/sidecarHttpClient.d.ts +1 -9
  60. package/dist/src/auth/sidecar/sidecarHttpClient.js +3 -69
  61. package/dist/src/auth/sidecar/sidecarHttpClient.js.map +1 -1
  62. package/dist/src/baseAdapter.d.ts +6 -0
  63. package/dist/src/baseAdapter.js.map +1 -1
  64. package/dist/src/cards/taskModuleAction.d.ts +6 -0
  65. package/dist/src/cards/taskModuleAction.js +6 -0
  66. package/dist/src/cards/taskModuleAction.js.map +1 -1
  67. package/dist/src/cloudAdapter.d.ts +29 -0
  68. package/dist/src/cloudAdapter.js +45 -8
  69. package/dist/src/cloudAdapter.js.map +1 -1
  70. package/dist/src/configuration/configuration.d.ts +1 -0
  71. package/dist/src/configuration/configuration.js +2 -1
  72. package/dist/src/configuration/configuration.js.map +1 -1
  73. package/dist/src/configuration/environmentConfiguration.js +1 -1
  74. package/dist/src/configuration/environmentConfiguration.js.map +1 -1
  75. package/dist/src/connector-client/connectorClient.d.ts +8 -0
  76. package/dist/src/connector-client/connectorClient.js +8 -0
  77. package/dist/src/connector-client/connectorClient.js.map +1 -1
  78. package/dist/src/createCloudAdapter.d.ts +2 -0
  79. package/dist/src/createCloudAdapter.js.map +1 -1
  80. package/dist/src/errorHelper.d.ts +1 -0
  81. package/dist/src/errorHelper.js +9 -0
  82. package/dist/src/errorHelper.js.map +1 -1
  83. package/dist/src/headerPropagation.d.ts +38 -0
  84. package/dist/src/headerPropagation.js +33 -0
  85. package/dist/src/headerPropagation.js.map +1 -1
  86. package/dist/src/httpClient.d.ts +58 -0
  87. package/dist/src/httpClient.js +40 -0
  88. package/dist/src/httpClient.js.map +1 -1
  89. package/dist/src/interfaces/webResponse.d.ts +7 -0
  90. package/dist/src/middlewareSet.d.ts +6 -0
  91. package/dist/src/middlewareSet.js.map +1 -1
  92. package/dist/src/oauth/userTokenClient.d.ts +6 -0
  93. package/dist/src/oauth/userTokenClient.js +12 -0
  94. package/dist/src/oauth/userTokenClient.js.map +1 -1
  95. package/dist/src/outboundHostValidator.d.ts +33 -1
  96. package/dist/src/outboundHostValidator.js +60 -25
  97. package/dist/src/outboundHostValidator.js.map +1 -1
  98. package/dist/src/storage/fileStorage.d.ts +26 -0
  99. package/dist/src/storage/fileStorage.js +35 -6
  100. package/dist/src/storage/fileStorage.js.map +1 -1
  101. package/dist/src/storage/memoryStorage.d.ts +34 -0
  102. package/dist/src/storage/memoryStorage.js +41 -4
  103. package/dist/src/storage/memoryStorage.js.map +1 -1
  104. package/dist/src/storage/storage.d.ts +20 -0
  105. package/dist/src/storage/storage.js +7 -0
  106. package/dist/src/storage/storage.js.map +1 -1
  107. package/dist/src/storage/storageCompatibility.js +12 -6
  108. package/dist/src/storage/storageCompatibility.js.map +1 -1
  109. package/dist/src/storage/storageExpiry.d.ts +7 -0
  110. package/dist/src/storage/storageExpiry.js +7 -0
  111. package/dist/src/storage/storageExpiry.js.map +1 -1
  112. package/dist/src/turnContext.d.ts +10 -0
  113. package/dist/src/turnContext.js +5 -0
  114. package/dist/src/turnContext.js.map +1 -1
  115. package/dist/src/utils/env.js +22 -11
  116. package/dist/src/utils/env.js.map +1 -1
  117. package/dist/src/utils/ipAddress.d.ts +6 -0
  118. package/dist/src/utils/ipAddress.js +64 -0
  119. package/dist/src/utils/ipAddress.js.map +1 -0
  120. package/dist/src/utils/outboundUrl.d.ts +7 -0
  121. package/dist/src/utils/outboundUrl.js +52 -0
  122. package/dist/src/utils/outboundUrl.js.map +1 -0
  123. package/dist/src/utils.js +2 -1
  124. package/dist/src/utils.js.map +1 -1
  125. package/package.json +4 -4
  126. package/src/activityHandler.ts +9 -3
  127. package/src/agent-client/agentResponseHandler.ts +7 -0
  128. package/src/agent-client/createAgentResponseHandler.ts +2 -0
  129. package/src/app/adaptiveCards/adaptiveCardsActions.ts +1 -0
  130. package/src/app/attachmentDownloadHttpClient.ts +80 -0
  131. package/src/app/attachmentDownloader.ts +6 -9
  132. package/src/app/auth/authorization.ts +58 -0
  133. package/src/app/proactive/conversation.ts +24 -0
  134. package/src/app/proactive/conversationBuilder.ts +3 -1
  135. package/src/app/proactive/conversationReferenceBuilder.ts +12 -4
  136. package/src/app/proactive/createConversationOptionsBuilder.ts +5 -1
  137. package/src/app/proactive/proactive.ts +33 -1
  138. package/src/app/routeList.ts +30 -3
  139. package/src/app/teamsAttachmentDownloader.ts +17 -10
  140. package/src/auth/authConfiguration.ts +1 -0
  141. package/src/auth/authConstants.ts +7 -0
  142. package/src/auth/authProvider.ts +36 -0
  143. package/src/auth/connectionManager.ts +3 -1
  144. package/src/auth/connections.ts +1 -0
  145. package/src/auth/msal/msalConnectionManager.ts +7 -0
  146. package/src/auth/msal/msalTokenProvider.ts +59 -0
  147. package/src/auth/settings.ts +28 -0
  148. package/src/auth/sidecar/sidecarAuthProvider.ts +4 -0
  149. package/src/auth/sidecar/sidecarHttpClient.ts +3 -63
  150. package/src/baseAdapter.ts +6 -0
  151. package/src/cards/taskModuleAction.ts +6 -0
  152. package/src/cloudAdapter.ts +59 -10
  153. package/src/configuration/configuration.ts +4 -2
  154. package/src/configuration/environmentConfiguration.ts +7 -1
  155. package/src/connector-client/connectorClient.ts +8 -0
  156. package/src/createCloudAdapter.ts +2 -0
  157. package/src/errorHelper.ts +11 -0
  158. package/src/headerPropagation.ts +38 -0
  159. package/src/httpClient.ts +58 -0
  160. package/src/interfaces/webResponse.ts +7 -0
  161. package/src/middlewareSet.ts +6 -0
  162. package/src/oauth/userTokenClient.ts +13 -0
  163. package/src/outboundHostValidator.ts +84 -23
  164. package/src/storage/fileStorage.ts +46 -6
  165. package/src/storage/memoryStorage.ts +45 -4
  166. package/src/storage/storage.ts +20 -0
  167. package/src/storage/storageCompatibility.ts +18 -6
  168. package/src/storage/storageExpiry.ts +7 -0
  169. package/src/turnContext.ts +11 -0
  170. package/src/utils/env.ts +33 -11
  171. package/src/utils/ipAddress.ts +63 -0
  172. package/src/utils/outboundUrl.ts +50 -0
  173. 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) return undefined
90
+ if (value === undefined) {
91
+ return undefined
92
+ }
91
93
  const v = value.trim().toLowerCase()
92
- if (v === 'true' || v === '1') return true
93
- if (v === '') return undefined
94
- if (v === 'false' || v === '0') return false
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() === '') return fallback
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) return undefined
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) break
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) return 0
152
- if (a.length === 0) return b.length
153
- if (b.length === 0) return a.length
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++) row[j] = 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) Object.assign(result, prune(layer))
21
+ if (layer) {
22
+ Object.assign(result, prune(layer))
23
+ }
22
24
  }
23
25
  return result as T
24
26
  }