@adcp/sdk 13.0.4 → 13.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.
Files changed (235) hide show
  1. package/bin/adcp-grade.js +4 -3
  2. package/bin/adcp.js +18 -0
  3. package/dist/lib/conformance/invariants/uniformError.d.ts.map +1 -1
  4. package/dist/lib/conformance/invariants/uniformError.js +21 -0
  5. package/dist/lib/conformance/invariants/uniformError.js.map +1 -1
  6. package/dist/lib/conformance/invariants/uniformError.mjs +22 -1
  7. package/dist/lib/conformance/invariants/uniformError.mjs.map +1 -1
  8. package/dist/lib/core/AgentClient.d.mts +1 -1
  9. package/dist/lib/core/AgentClient.d.ts +1 -1
  10. package/dist/lib/core/AgentClient.d.ts.map +1 -1
  11. package/dist/lib/core/AgentClient.js +1 -1
  12. package/dist/lib/core/AgentClient.js.map +1 -1
  13. package/dist/lib/core/AgentClient.mjs +1 -1
  14. package/dist/lib/core/AgentClient.mjs.map +1 -1
  15. package/dist/lib/core/SingleAgentClient.d.mts +1 -1
  16. package/dist/lib/core/SingleAgentClient.d.ts +1 -1
  17. package/dist/lib/core/SingleAgentClient.d.ts.map +1 -1
  18. package/dist/lib/core/SingleAgentClient.js +88 -48
  19. package/dist/lib/core/SingleAgentClient.js.map +1 -1
  20. package/dist/lib/core/SingleAgentClient.mjs +88 -48
  21. package/dist/lib/core/SingleAgentClient.mjs.map +1 -1
  22. package/dist/lib/core/TaskExecutor.d.ts.map +1 -1
  23. package/dist/lib/core/TaskExecutor.js +8 -4
  24. package/dist/lib/core/TaskExecutor.js.map +1 -1
  25. package/dist/lib/core/TaskExecutor.mjs +8 -4
  26. package/dist/lib/core/TaskExecutor.mjs.map +1 -1
  27. package/dist/lib/index.d.mts +1 -1
  28. package/dist/lib/index.d.ts +1 -1
  29. package/dist/lib/index.d.ts.map +1 -1
  30. package/dist/lib/index.js.map +1 -1
  31. package/dist/lib/index.mjs.map +1 -1
  32. package/dist/lib/net/agent-transport-fetch.d.mts +15 -0
  33. package/dist/lib/net/agent-transport-fetch.d.ts +15 -0
  34. package/dist/lib/net/agent-transport-fetch.d.ts.map +1 -1
  35. package/dist/lib/net/agent-transport-fetch.js +37 -2
  36. package/dist/lib/net/agent-transport-fetch.js.map +1 -1
  37. package/dist/lib/net/agent-transport-fetch.mjs +37 -2
  38. package/dist/lib/net/agent-transport-fetch.mjs.map +1 -1
  39. package/dist/lib/net/credential-headers.d.mts +1 -0
  40. package/dist/lib/net/credential-headers.d.ts +2 -0
  41. package/dist/lib/net/credential-headers.d.ts.map +1 -0
  42. package/dist/lib/net/credential-headers.js +34 -0
  43. package/dist/lib/net/credential-headers.js.map +1 -0
  44. package/dist/lib/net/credential-headers.mjs +10 -0
  45. package/dist/lib/net/credential-headers.mjs.map +1 -0
  46. package/dist/lib/protocols/a2a-native-v1.d.mts +18 -0
  47. package/dist/lib/protocols/a2a-native-v1.d.ts +19 -0
  48. package/dist/lib/protocols/a2a-native-v1.d.ts.map +1 -0
  49. package/dist/lib/protocols/a2a-native-v1.js +183 -0
  50. package/dist/lib/protocols/a2a-native-v1.js.map +1 -0
  51. package/dist/lib/protocols/a2a-native-v1.mjs +167 -0
  52. package/dist/lib/protocols/a2a-native-v1.mjs.map +1 -0
  53. package/dist/lib/protocols/a2a-push-notification.d.mts +13 -0
  54. package/dist/lib/protocols/a2a-push-notification.d.ts +14 -0
  55. package/dist/lib/protocols/a2a-push-notification.d.ts.map +1 -0
  56. package/dist/lib/protocols/a2a-push-notification.js +42 -0
  57. package/dist/lib/protocols/a2a-push-notification.js.map +1 -0
  58. package/dist/lib/protocols/a2a-push-notification.mjs +23 -0
  59. package/dist/lib/protocols/a2a-push-notification.mjs.map +1 -0
  60. package/dist/lib/protocols/a2a.d.mts +15 -5
  61. package/dist/lib/protocols/a2a.d.ts +15 -5
  62. package/dist/lib/protocols/a2a.d.ts.map +1 -1
  63. package/dist/lib/protocols/a2a.js +102 -13
  64. package/dist/lib/protocols/a2a.js.map +1 -1
  65. package/dist/lib/protocols/a2a.mjs +90 -12
  66. package/dist/lib/protocols/a2a.mjs.map +1 -1
  67. package/dist/lib/protocols/index.d.mts +3 -0
  68. package/dist/lib/protocols/index.d.ts +3 -0
  69. package/dist/lib/protocols/index.d.ts.map +1 -1
  70. package/dist/lib/protocols/index.js +18 -6
  71. package/dist/lib/protocols/index.js.map +1 -1
  72. package/dist/lib/protocols/index.mjs +18 -6
  73. package/dist/lib/protocols/index.mjs.map +1 -1
  74. package/dist/lib/protocols/mcp-modern.d.ts.map +1 -1
  75. package/dist/lib/protocols/mcp-modern.js +3 -1
  76. package/dist/lib/protocols/mcp-modern.js.map +1 -1
  77. package/dist/lib/protocols/mcp-modern.mjs +3 -1
  78. package/dist/lib/protocols/mcp-modern.mjs.map +1 -1
  79. package/dist/lib/protocols/mcp-tasks.d.ts.map +1 -1
  80. package/dist/lib/protocols/mcp-tasks.js +2 -1
  81. package/dist/lib/protocols/mcp-tasks.js.map +1 -1
  82. package/dist/lib/protocols/mcp-tasks.mjs +2 -1
  83. package/dist/lib/protocols/mcp-tasks.mjs.map +1 -1
  84. package/dist/lib/protocols/mcp.d.mts +8 -5
  85. package/dist/lib/protocols/mcp.d.ts +8 -5
  86. package/dist/lib/protocols/mcp.d.ts.map +1 -1
  87. package/dist/lib/protocols/mcp.js +12 -4
  88. package/dist/lib/protocols/mcp.js.map +1 -1
  89. package/dist/lib/protocols/mcp.mjs +12 -4
  90. package/dist/lib/protocols/mcp.mjs.map +1 -1
  91. package/dist/lib/protocols/rawResponseCapture.d.mts +9 -1
  92. package/dist/lib/protocols/rawResponseCapture.d.ts +9 -1
  93. package/dist/lib/protocols/rawResponseCapture.d.ts.map +1 -1
  94. package/dist/lib/protocols/rawResponseCapture.js +153 -10
  95. package/dist/lib/protocols/rawResponseCapture.js.map +1 -1
  96. package/dist/lib/protocols/rawResponseCapture.mjs +153 -10
  97. package/dist/lib/protocols/rawResponseCapture.mjs.map +1 -1
  98. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  99. package/dist/lib/signing/agent-fetch.d.mts +3 -1
  100. package/dist/lib/signing/agent-fetch.d.ts +3 -1
  101. package/dist/lib/signing/agent-fetch.d.ts.map +1 -1
  102. package/dist/lib/signing/agent-fetch.js +4 -2
  103. package/dist/lib/signing/agent-fetch.js.map +1 -1
  104. package/dist/lib/signing/agent-fetch.mjs +4 -2
  105. package/dist/lib/signing/agent-fetch.mjs.map +1 -1
  106. package/dist/lib/signing/protocol-methods.d.mts +24 -0
  107. package/dist/lib/signing/protocol-methods.d.ts +25 -0
  108. package/dist/lib/signing/protocol-methods.d.ts.map +1 -0
  109. package/dist/lib/signing/protocol-methods.js +51 -0
  110. package/dist/lib/signing/protocol-methods.js.map +1 -0
  111. package/dist/lib/signing/protocol-methods.mjs +25 -0
  112. package/dist/lib/signing/protocol-methods.mjs.map +1 -0
  113. package/dist/lib/signing/types.d.mts +2 -0
  114. package/dist/lib/signing/types.d.ts +2 -0
  115. package/dist/lib/signing/types.d.ts.map +1 -1
  116. package/dist/lib/signing/types.js.map +1 -1
  117. package/dist/lib/signing/types.mjs.map +1 -1
  118. package/dist/lib/signing/verifier.d.ts.map +1 -1
  119. package/dist/lib/signing/verifier.js +6 -2
  120. package/dist/lib/signing/verifier.js.map +1 -1
  121. package/dist/lib/signing/verifier.mjs +6 -2
  122. package/dist/lib/signing/verifier.mjs.map +1 -1
  123. package/dist/lib/testing/client.d.ts.map +1 -1
  124. package/dist/lib/testing/client.js +4 -1
  125. package/dist/lib/testing/client.js.map +1 -1
  126. package/dist/lib/testing/client.mjs +4 -1
  127. package/dist/lib/testing/client.mjs.map +1 -1
  128. package/dist/lib/testing/compliance/comply.d.ts.map +1 -1
  129. package/dist/lib/testing/compliance/comply.js +3 -0
  130. package/dist/lib/testing/compliance/comply.js.map +1 -1
  131. package/dist/lib/testing/compliance/comply.mjs +3 -0
  132. package/dist/lib/testing/compliance/comply.mjs.map +1 -1
  133. package/dist/lib/testing/storyboard/agent-routing.d.mts +3 -1
  134. package/dist/lib/testing/storyboard/agent-routing.d.ts +3 -1
  135. package/dist/lib/testing/storyboard/agent-routing.d.ts.map +1 -1
  136. package/dist/lib/testing/storyboard/agent-routing.js +5 -2
  137. package/dist/lib/testing/storyboard/agent-routing.js.map +1 -1
  138. package/dist/lib/testing/storyboard/agent-routing.mjs +4 -2
  139. package/dist/lib/testing/storyboard/agent-routing.mjs.map +1 -1
  140. package/dist/lib/testing/storyboard/compliance.d.mts +1 -1
  141. package/dist/lib/testing/storyboard/compliance.d.ts +1 -1
  142. package/dist/lib/testing/storyboard/compliance.d.ts.map +1 -1
  143. package/dist/lib/testing/storyboard/compliance.js +4 -1
  144. package/dist/lib/testing/storyboard/compliance.js.map +1 -1
  145. package/dist/lib/testing/storyboard/compliance.mjs +4 -1
  146. package/dist/lib/testing/storyboard/compliance.mjs.map +1 -1
  147. package/dist/lib/testing/storyboard/native-a2a-compliance.d.mts +7 -0
  148. package/dist/lib/testing/storyboard/native-a2a-compliance.d.ts +8 -0
  149. package/dist/lib/testing/storyboard/native-a2a-compliance.d.ts.map +1 -0
  150. package/dist/lib/testing/storyboard/native-a2a-compliance.js +45 -0
  151. package/dist/lib/testing/storyboard/native-a2a-compliance.js.map +1 -0
  152. package/dist/lib/testing/storyboard/native-a2a-compliance.mjs +21 -0
  153. package/dist/lib/testing/storyboard/native-a2a-compliance.mjs.map +1 -0
  154. package/dist/lib/testing/storyboard/probes.d.mts +2 -0
  155. package/dist/lib/testing/storyboard/probes.d.ts +2 -0
  156. package/dist/lib/testing/storyboard/probes.d.ts.map +1 -1
  157. package/dist/lib/testing/storyboard/probes.js +3 -2
  158. package/dist/lib/testing/storyboard/probes.js.map +1 -1
  159. package/dist/lib/testing/storyboard/probes.mjs +3 -2
  160. package/dist/lib/testing/storyboard/probes.mjs.map +1 -1
  161. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.d.mts +31 -0
  162. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.d.ts +32 -0
  163. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.d.ts.map +1 -0
  164. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.js +279 -0
  165. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.js.map +1 -0
  166. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.mjs +244 -0
  167. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.mjs.map +1 -0
  168. package/dist/lib/testing/storyboard/request-signing/builder.d.mts +4 -1
  169. package/dist/lib/testing/storyboard/request-signing/builder.d.ts +4 -1
  170. package/dist/lib/testing/storyboard/request-signing/builder.d.ts.map +1 -1
  171. package/dist/lib/testing/storyboard/request-signing/builder.js +19 -0
  172. package/dist/lib/testing/storyboard/request-signing/builder.js.map +1 -1
  173. package/dist/lib/testing/storyboard/request-signing/builder.mjs +19 -0
  174. package/dist/lib/testing/storyboard/request-signing/builder.mjs.map +1 -1
  175. package/dist/lib/testing/storyboard/request-signing/grader.d.mts +5 -6
  176. package/dist/lib/testing/storyboard/request-signing/grader.d.ts +5 -6
  177. package/dist/lib/testing/storyboard/request-signing/grader.d.ts.map +1 -1
  178. package/dist/lib/testing/storyboard/request-signing/grader.js +82 -13
  179. package/dist/lib/testing/storyboard/request-signing/grader.js.map +1 -1
  180. package/dist/lib/testing/storyboard/request-signing/grader.mjs +86 -13
  181. package/dist/lib/testing/storyboard/request-signing/grader.mjs.map +1 -1
  182. package/dist/lib/testing/storyboard/request-signing/index.d.mts +1 -0
  183. package/dist/lib/testing/storyboard/request-signing/index.d.ts +1 -0
  184. package/dist/lib/testing/storyboard/request-signing/index.d.ts.map +1 -1
  185. package/dist/lib/testing/storyboard/request-signing/index.js +7 -0
  186. package/dist/lib/testing/storyboard/request-signing/index.js.map +1 -1
  187. package/dist/lib/testing/storyboard/request-signing/index.mjs +8 -0
  188. package/dist/lib/testing/storyboard/request-signing/index.mjs.map +1 -1
  189. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.d.mts +2 -2
  190. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.d.ts +2 -2
  191. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.d.ts.map +1 -1
  192. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.js +6 -5
  193. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.js.map +1 -1
  194. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.mjs +6 -5
  195. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.mjs.map +1 -1
  196. package/dist/lib/testing/storyboard/request-signing/types.d.mts +1 -0
  197. package/dist/lib/testing/storyboard/request-signing/types.d.ts +1 -0
  198. package/dist/lib/testing/storyboard/request-signing/types.d.ts.map +1 -1
  199. package/dist/lib/testing/storyboard/request-signing/types.js.map +1 -1
  200. package/dist/lib/testing/storyboard/request-signing/types.mjs.map +1 -1
  201. package/dist/lib/testing/storyboard/request-signing/vector-loader.d.ts.map +1 -1
  202. package/dist/lib/testing/storyboard/request-signing/vector-loader.js +1 -0
  203. package/dist/lib/testing/storyboard/request-signing/vector-loader.js.map +1 -1
  204. package/dist/lib/testing/storyboard/request-signing/vector-loader.mjs +1 -0
  205. package/dist/lib/testing/storyboard/request-signing/vector-loader.mjs.map +1 -1
  206. package/dist/lib/testing/storyboard/runner.d.mts +28 -1
  207. package/dist/lib/testing/storyboard/runner.d.ts +28 -1
  208. package/dist/lib/testing/storyboard/runner.d.ts.map +1 -1
  209. package/dist/lib/testing/storyboard/runner.js +251 -55
  210. package/dist/lib/testing/storyboard/runner.js.map +1 -1
  211. package/dist/lib/testing/storyboard/runner.mjs +255 -60
  212. package/dist/lib/testing/storyboard/runner.mjs.map +1 -1
  213. package/dist/lib/testing/storyboard/types.d.mts +4 -2
  214. package/dist/lib/testing/storyboard/types.d.ts +4 -2
  215. package/dist/lib/testing/storyboard/types.d.ts.map +1 -1
  216. package/dist/lib/testing/storyboard/types.js +1 -0
  217. package/dist/lib/testing/storyboard/types.js.map +1 -1
  218. package/dist/lib/testing/storyboard/types.mjs +1 -0
  219. package/dist/lib/testing/storyboard/types.mjs.map +1 -1
  220. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  221. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  222. package/dist/lib/testing/storyboard/validations.d.ts.map +1 -1
  223. package/dist/lib/testing/storyboard/validations.js +97 -22
  224. package/dist/lib/testing/storyboard/validations.js.map +1 -1
  225. package/dist/lib/testing/storyboard/validations.mjs +98 -22
  226. package/dist/lib/testing/storyboard/validations.mjs.map +1 -1
  227. package/dist/lib/version.d.mts +3 -3
  228. package/dist/lib/version.d.ts +3 -3
  229. package/dist/lib/version.js +3 -3
  230. package/dist/lib/version.js.map +1 -1
  231. package/dist/lib/version.mjs +3 -3
  232. package/dist/lib/version.mjs.map +1 -1
  233. package/docs/guides/BUILD-AN-AGENT.md +1 -1
  234. package/docs/llms.txt +5 -3
  235. package/package.json +2 -1
@@ -108,6 +108,8 @@ export interface TransportOptions {
108
108
  * Set to `0` to disable the SDK-imposed discovery timeout.
109
109
  */
110
110
  requestTimeoutMs?: number;
111
+ /** A2A-only compatibility policy. Compliance uses `{ enabled: false }` for native 1.0 grading. */
112
+ legacyCompat?: import('./a2a').A2ALegacyCompatOptions;
111
113
  }
112
114
  /**
113
115
  * Options for {@link ProtocolClient.callTool}. All fields are optional.
@@ -207,4 +209,5 @@ export declare const createMCPClient: (agentUrl: string, authToken?: string, hea
207
209
  export declare const createA2AClient: (agentUrl: string, authToken?: string, headers?: Record<string, string>, serverVersion?: "v2" | "v3", adcpVersion?: string, transport?: TransportOptions, versionEnvelopeMode?: VersionEnvelopeMode) => {
208
210
  callTool: (toolName: string, parameters: Record<string, unknown>, debugLogs?: DebugLogEntry[]) => Promise<unknown>;
209
211
  };
212
+ export type { A2ALegacyCompatOptions } from './a2a';
210
213
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/protocols/index.ts"],"names":[],"mappings":"AACA,OAAO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Q,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,OAAO,CAAC;CAwYpB;AAoCD;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,MAAM,EAChB,YAAY,MAAM,EAClB,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,gBAAgB,IAAI,GAAG,IAAI,EAC3B,cAAc,MAAM,EACpB,YAAY,gBAAgB,EAC5B,sBAAqB,mBAA4B;yBAQ1B,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,aAAa,EAAE;CAiB1F,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,UAAU,MAAM,EAChB,YAAY,MAAM,EAClB,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,gBAAgB,IAAI,GAAG,IAAI,EAC3B,cAAc,MAAM,EACpB,YAAY,gBAAgB,EAC5B,sBAAqB,mBAA4B;yBAK1B,MAAM,cAAc,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,aAAa,EAAE;CAoBhG,CAAC;AAEF,YAAY,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC"}
@@ -236,11 +236,14 @@ class ProtocolClient {
236
236
  );
237
237
  }
238
238
  const argsWithVersion = applyVersionEnvelope(args, versionEnvelope);
239
- const pushNotificationConfig = (() => {
239
+ const generatedPushNotificationConfig = (() => {
240
240
  if (!webhookUrl) return void 0;
241
241
  if (webhookSecret) {
242
242
  return {
243
243
  url: webhookUrl,
244
+ ...transportActivityContext?.operationId && {
245
+ operation_id: transportActivityContext.operationId
246
+ },
244
247
  ...webhookToken && { token: webhookToken },
245
248
  authentication: {
246
249
  schemes: ["HMAC-SHA256"],
@@ -254,9 +257,14 @@ class ProtocolClient {
254
257
  }
255
258
  return {
256
259
  url: webhookUrl,
260
+ ...transportActivityContext?.operationId && {
261
+ operation_id: transportActivityContext.operationId
262
+ },
257
263
  ...webhookToken && { token: webhookToken }
258
264
  };
259
265
  })();
266
+ const explicitNativePushNotificationConfig = transport?.legacyCompat?.enabled === false && argsWithVersion.push_notification_config !== null && typeof argsWithVersion.push_notification_config === "object" && !Array.isArray(argsWithVersion.push_notification_config) ? argsWithVersion.push_notification_config : void 0;
267
+ const pushNotificationConfig = generatedPushNotificationConfig ?? explicitNativePushNotificationConfig;
260
268
  if (agent.protocol === "mcp") {
261
269
  const argsWithWebhook = pushNotificationConfig ? { ...argsWithVersion, push_notification_config: pushNotificationConfig } : argsWithVersion;
262
270
  if (agent.oauth_tokens && !agent.oauth_client_credentials) {
@@ -361,11 +369,12 @@ class ProtocolClient {
361
369
  throw err;
362
370
  }
363
371
  } else if (agent.protocol === "a2a") {
372
+ const a2aParameters = transport?.legacyCompat?.enabled === false && pushNotificationConfig ? { ...argsWithVersion, push_notification_config: pushNotificationConfig } : argsWithVersion;
364
373
  try {
365
374
  return await (0, import_a2a3.callA2ATool)(
366
375
  agent.agent_uri,
367
376
  toolName,
368
- argsWithVersion,
377
+ a2aParameters,
369
378
  authToken,
370
379
  debugLogs,
371
380
  pushNotificationConfig,
@@ -375,7 +384,8 @@ class ProtocolClient {
375
384
  signal,
376
385
  transport?.requestTimeoutMs,
377
386
  transport?.trustedFetchFn,
378
- transport?.allowPrivateIp
387
+ transport?.allowPrivateIp,
388
+ transport?.legacyCompat
379
389
  );
380
390
  } catch (err) {
381
391
  if (agent.oauth_client_credentials && (0, import_errors.is401Error)(err)) {
@@ -393,7 +403,7 @@ class ProtocolClient {
393
403
  return await (0, import_a2a3.callA2ATool)(
394
404
  agent.agent_uri,
395
405
  toolName,
396
- argsWithVersion,
406
+ a2aParameters,
397
407
  retryAuthToken,
398
408
  debugLogs,
399
409
  pushNotificationConfig,
@@ -403,7 +413,8 @@ class ProtocolClient {
403
413
  signal,
404
414
  transport?.requestTimeoutMs,
405
415
  transport?.trustedFetchFn,
406
- transport?.allowPrivateIp
416
+ transport?.allowPrivateIp,
417
+ transport?.legacyCompat
407
418
  );
408
419
  } catch (retryErr) {
409
420
  await rethrowAsNeedsAuthorization(
@@ -484,7 +495,8 @@ const createA2AClient = (agentUrl, authToken, headers, serverVersion, adcpVersio
484
495
  void 0,
485
496
  transport?.requestTimeoutMs,
486
497
  transport?.trustedFetchFn,
487
- transport?.allowPrivateIp
498
+ transport?.allowPrivateIp,
499
+ transport?.legacyCompat
488
500
  )
489
501
  )
490
502
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/protocols/index.ts"],"sourcesContent":["// Unified Protocol Interface for AdCP\nexport {\n callMCPTool,\n callMCPToolWithOAuth,\n connectMCP,\n closeMCPConnections,\n closeOAuthConnections,\n UnauthorizedError,\n} from './mcp';\n\nimport { closeMCPConnections } from './mcp';\nimport { closeCurrentMCPConnectionScope, withMCPConnectionScope } from './mcp-scope';\nimport { closeA2AConnections } from './a2a';\n\n/**\n * Close protocol connections for the given protocol.\n * MCP closes persistent HTTP transports; A2A clears the agent-card client cache.\n */\nexport async function closeConnections(protocol: 'mcp' | 'a2a' = 'mcp'): Promise<void> {\n if (protocol === 'mcp') {\n await closeMCPConnections();\n } else {\n closeA2AConnections();\n }\n}\n\n/** Close only the current runner's MCP scope; fall back to legacy global cleanup. */\nexport async function closeScopedConnections(protocol: 'mcp' | 'a2a' = 'mcp'): Promise<void> {\n if (protocol === 'mcp') {\n if (!(await closeCurrentMCPConnectionScope())) await closeMCPConnections();\n } else {\n closeA2AConnections();\n }\n}\n\nexport { withMCPConnectionScope };\nexport type { MCPCallOptions, MCPConnectionResult } from './mcp';\nexport { callA2ATool } from './a2a';\nexport { DEFAULT_REQUEST_TIMEOUT_MS } from './abort';\nexport {\n callMCPToolWithTasks,\n getMCPTaskStatus,\n getMCPTaskResult,\n listMCPTasks,\n cancelMCPTask,\n mapMCPTaskStatus,\n serverSupportsTasks,\n} from './mcp-tasks';\n\nimport { callMCPToolWithTasks, callMCPToolWithClient } from './mcp-tasks';\nimport { callMCPToolWithOAuth } from './mcp';\nimport { callA2ATool } from './a2a';\nimport type { AgentConfig, DebugLogEntry } from '../types';\nimport type { PushNotificationConfig } from '../types/tools.generated';\nimport { getAuthToken } from '../auth';\nimport {\n discoverAuthorizationRequirements,\n NeedsAuthorizationError,\n getAgentStorage,\n ensureClientCredentialsTokens,\n} from '../auth/oauth';\nimport { getNonInteractiveOAuthProvider } from '../auth/oauth/provider-cache';\nimport { is401Error } from '../errors';\nimport { isLikelyPrivateUrl } from '../net';\nimport { validateAgentUrl } from '../validation';\nimport { withSpan } from '../observability/tracing';\nimport { ADCP_MAJOR_VERSION, ADCP_VERSION, parseAdcpMajorVersion } from '../version';\nimport { ConfigurationError } from '../errors';\nimport { resolveBundleKey, toReleasePrecisionWire, validateAdcpVersionWire } from '../validation/schema-loader';\nimport { buildAgentSigningContext, CAPABILITY_OP, ensureCapabilityLoaded } from '../signing/client';\nimport { withResponseSizeLimit } from './responseSizeLimit';\nimport {\n withTransportDiagnostics,\n type TransportActivityHandler as TransportActivityHandlerFn,\n} from './transportDiagnostics';\n\nexport {\n sanitizeTransportHeaders,\n sanitizeTransportUrl,\n withTransportDiagnostics,\n wrapFetchWithTransportDiagnostics,\n} from './transportDiagnostics';\nexport type { TransportActivity, TransportActivityContext, TransportActivityHandler } from './transportDiagnostics';\n\nexport type VersionEnvelopeMode = 'auto' | 'none' | 'major-only';\n\n/**\n * Derive the wire-level `adcp_major_version` integer from a caller-supplied\n * pin. Returns the SDK default when no pin is provided; throws on a pin\n * that doesn't parse so misuse surfaces at the factory boundary instead\n * of silently emitting the SDK's major.\n *\n * Throws `ConfigurationError` (not a plain `Error`) so a typo'd pin\n * surfaces with the same error class as the construction-time gate in\n * `resolveAdcpVersion` — one shape for all pin-misuse paths.\n */\nfunction resolveWireMajor(adcpVersion: string | undefined): number {\n if (adcpVersion === undefined) return ADCP_MAJOR_VERSION;\n const parsed = parseAdcpMajorVersion(adcpVersion);\n if (!Number.isFinite(parsed)) {\n throw new ConfigurationError(\n `adcpVersion ${JSON.stringify(adcpVersion)} is not a valid AdCP version. ` +\n `Expected a semver string (e.g. '3.0.1', '3.1.0-beta.1') or a legacy alias (e.g. 'v3').`,\n 'adcpVersion'\n );\n }\n return parsed;\n}\n\n/**\n * Returns true when the AdCP release that `bundleKey` identifies declares the\n * top-level `adcp_version` envelope field. The field landed in AdCP 3.1 per\n * spec PR `adcontextprotocol/adcp#3493` — 3.0 (any patch / prerelease) does\n * not carry it; 3.1+ does. Used to gate dual-emit on the wire so a 3.0-pinned\n * client doesn't emit a field its target schema doesn't define.\n */\nexport function bundleSupportsAdcpVersionField(bundleKey: string): boolean {\n const major = parseAdcpMajorVersion(bundleKey);\n if (!Number.isFinite(major)) return false;\n if (major < 3) return false;\n if (major > 3) return true;\n // Major 3 — only 3.1+ has the field. Bundle key shape is normalized by\n // `resolveBundleKey`: `'3.0'` / `'3.1'` for stable; `'3.0.0-beta.1'` /\n // `'3.1.0-beta.1'` for prereleases. Match the minor.\n const minorMatch = bundleKey.match(/^\\d+\\.(\\d+)/);\n if (!minorMatch) return false;\n return parseInt(minorMatch[1]!, 10) >= 1;\n}\n\n/**\n * Build the wire-level version envelope to merge into outgoing request args.\n *\n * Per AdCP 3.1 (spec PR `adcontextprotocol/adcp#3493`), 3.1+ requests carry\n * BOTH the integer `adcp_major_version` (deprecated through 3.x, removed in\n * 4.0) AND the release-precision string `adcp_version`. 3.0 schemas don't\n * define the string field, so a 3.0-pinned client emits the integer only —\n * matches the 3.0 spec exactly.\n *\n * Wire string is release-precision (MAJOR.MINOR with optional prerelease tag),\n * per `core/version-envelope.json`'s pattern `^\\d+\\.\\d+(-[a-zA-Z0-9.-]+)?$`.\n * Full-semver bundle keys (`'3.1.0-beta.1'`) are collapsed via\n * `toReleasePrecisionWire` to `'3.1-beta.1'` before emit — meta-field shapes\n * are explicitly NOT valid wire values per the envelope schema's own\n * normalization rule.\n *\n * Returns `{}` for v2 callers (predates the major-version field entirely).\n */\nfunction buildVersionEnvelope(\n adcpVersion: string | undefined,\n serverVersion: 'v2' | 'v3' | undefined\n): Record<string, unknown> {\n if (serverVersion === 'v2') return {};\n const wireMajor = resolveWireMajor(adcpVersion);\n const bundleKey = resolveBundleKey(adcpVersion ?? ADCP_VERSION);\n if (!bundleSupportsAdcpVersionField(bundleKey)) {\n return { adcp_major_version: wireMajor };\n }\n const wireValue = toReleasePrecisionWire(bundleKey);\n // Defensive postcondition — should never throw in well-formed code, but\n // if a future refactor breaks the normalization the error message tells\n // the developer to call `toReleasePrecisionWire` instead of silently\n // emitting a non-spec wire string.\n validateAdcpVersionWire(wireValue);\n return { adcp_major_version: wireMajor, adcp_version: wireValue };\n}\n\nlet hasWarnedAboutV2PushNotificationSecret = false;\n\n/**\n * Warn once when an async webhook registration is suppressed for a v2 seller.\n *\n * v2.5's `push-notification-config.json` requires `authentication`, and unlike\n * 3.x it has no RFC 9421 selector semantics — so omitting the block produces a\n * schema-invalid request rather than choosing a signing mode. Without a\n * configured secret there is no honest value to send, and the previous\n * behaviour (a hardcoded placeholder credential) told the seller the channel\n * was authenticated by a constant published in this package.\n */\nfunction warnV2PushNotificationNeedsSecret(): void {\n if (hasWarnedAboutV2PushNotificationSecret) return;\n hasWarnedAboutV2PushNotificationSecret = true;\n console.warn(\n '[adcp] Suppressing push_notification_config for a v2 seller: AdCP 2.5 requires an ' +\n '`authentication` block and no `webhookSecret` is configured. Set `webhookSecret` to register ' +\n 'async task-status webhooks with this agent, or move the agent to an AdCP 3.x pin, where the ' +\n 'RFC 9421 webhook profile needs no shared secret.'\n );\n}\n\nfunction buildVersionEnvelopeForMode(\n mode: VersionEnvelopeMode,\n adcpVersion: string | undefined,\n serverVersion: 'v2' | 'v3' | undefined\n): Record<string, unknown> {\n if (mode === 'none' || serverVersion === 'v2') return {};\n if (mode === 'major-only') return { adcp_major_version: resolveWireMajor(adcpVersion) };\n return buildVersionEnvelope(adcpVersion, serverVersion);\n}\n\n/**\n * Merge the wire-level version envelope into a caller-supplied args object.\n * Caller args win: an explicit `adcp_major_version` / `adcp_version` in\n * `args` (e.g. a conformance harness probing `VERSION_UNSUPPORTED`) passes\n * through unchanged. The envelope only fills fields the caller didn't set.\n *\n * Single chokepoint for all four wire-injection sites so a future refactor\n * can't silently flip the spread order on one branch and leave the others\n * intact. Stale dual-field drift is caught at the server boundary by\n * `createAdcpServer`'s field-disagreement check (spec PR\n * `adcontextprotocol/adcp#3493`).\n *\n * @internal\n */\nexport function applyVersionEnvelope(\n args: Record<string, unknown>,\n envelope: Record<string, unknown>\n): Record<string, unknown> {\n return { ...envelope, ...args };\n}\n\n/**\n * Transport-level safeguards applied to a call.\n *\n * Wired into the SDK's internal fetch chain via AsyncLocalStorage, so the\n * cap takes effect even when the underlying transport's connection cache\n * reuses a fetch that was created on an earlier call with different limits.\n */\nexport interface TransportOptions {\n /**\n * Maximum response body size (in octets) the SDK will read before aborting\n * with `ResponseTooLargeError`. When unset, the SDK does not impose a cap —\n * matches the underlying MCP / A2A transport defaults.\n *\n * Set this when crawling **untrusted** agents (registries, federated\n * discovery layers, monitoring tools) to prevent a hostile vendor from\n * buffering a large reply before any application-layer schema validation\n * runs. Counted across response chunks; pre-cancels when `Content-Length`\n * exceeds the cap. Applies to A2A agent-card discovery\n * (`/.well-known/agent.json`) on the same call as well.\n *\n * Per-call override (`TaskOptions.transport.maxResponseBytes`) beats the\n * value set on the client constructor (`SingleAgentClientConfig.transport`).\n *\n * @remarks\n * **Safe to set on all calls.** SSE responses (`text/event-stream`) are\n * passed through unchanged — a single tool call legitimately emits N status\n * frames + a final result, bounded by protocol-level framing rather than\n * cumulative byte counts. The cap applies to one-shot JSON responses\n * (`get_adcp_capabilities`, agent-card lookup, tool result payloads on\n * non-streaming transports) where the body is bounded by definition.\n *\n * @remarks\n * **Hostile-peer note:** A peer can opt itself out of this cap by responding\n * with `Content-Type: text/event-stream`. SSE is bypassed because cumulative\n * event-frame bytes are unbounded by spec — MCP and A2A both stream tool\n * responses this way. The MCP/A2A SDKs consume SSE incrementally and frame\n * termination bounds memory in practice, so this is not a memory-bomb risk\n * for well-formed transports. Adopters relying on `maxResponseBytes` as a\n * hostile-server defense should treat it as best-effort for non-SSE\n * responses only.\n *\n * @remarks\n * Future hardening knobs (DNS-rebind defense, scheme allow-list, request\n * timeout overrides) will land here as additional fields. When `trustedFetchFn`\n * is supplied, the SDK composes it inside its signing, capture, size-limit,\n * timeout, and diagnostics wrappers so callers do not have to reproduce\n * that non-obvious ordering themselves.\n */\n maxResponseBytes?: number;\n /**\n * Scoped fetch implementation for all outbound HTTP performed on behalf of\n * this client or call, including endpoint/card discovery, tool listing,\n * OAuth discovery and token refresh, and MCP/A2A tool requests.\n *\n * The function is runtime-only configuration and is never serialized into\n * agent records, storyboard artifacts, or compliance output. When unset,\n * the SDK uses the global `fetch` implementation.\n *\n * Supplying this function makes it the trusted network boundary: the SDK\n * still validates URL schemes, redirect behavior, timeouts, and body limits,\n * but delegates DNS resolution and address policy to the implementation.\n * It must prevent DNS rebinding and unsafe private-address access itself (for\n * example with an egress proxy or its own DNS pinning).\n */\n trustedFetchFn?: typeof fetch;\n /**\n * @deprecated Rename to `trustedFetchFn`. Supplying this legacy alias is\n * treated as an explicit assertion that the implementation pins DNS.\n */\n fetchFn?: typeof fetch;\n /**\n * Permit this client to connect to private DNS answers. Localhost and an\n * initial private IP literal are allowed automatically only on their exact\n * origin; use this for private-DNS enterprise agents.\n */\n allowPrivateIp?: boolean;\n /**\n * Timeout in milliseconds for bounded one-shot transport requests such as\n * A2A agent-card discovery and MCP read-path probes. Defaults to 60 seconds\n * for A2A discovery so an unresponsive card endpoint cannot hang forever.\n * Set to `0` to disable the SDK-imposed discovery timeout.\n */\n requestTimeoutMs?: number;\n}\n\nlet warnedLegacyTransportFetch = false;\n\n/** @internal Normalize the pre-GA fetch hook rename without silently dropping JS callers. */\nexport function normalizeTransportOptions(transport?: TransportOptions): TransportOptions | undefined {\n if (!transport?.fetchFn) return transport;\n if (transport.trustedFetchFn && transport.trustedFetchFn !== transport.fetchFn) {\n throw new TypeError('TransportOptions cannot set different fetchFn and trustedFetchFn implementations');\n }\n if (!warnedLegacyTransportFetch) {\n warnedLegacyTransportFetch = true;\n console.warn(\n '[adcp] TransportOptions.fetchFn is deprecated; rename it to trustedFetchFn. ' +\n 'Custom fetch implementations must provide connect-time DNS pinning.'\n );\n }\n return { ...transport, trustedFetchFn: transport.trustedFetchFn ?? transport.fetchFn };\n}\n\n/**\n * Options for {@link ProtocolClient.callTool}. All fields are optional.\n *\n * `webhookUrl` / `webhookSecret` / `webhookToken` are for ASYNC TASK STATUS\n * notifications (push_notification_config). For reporting webhooks\n * (reporting_webhook), include them directly in `args` — they stay in skill\n * parameters and are sent verbatim to the agent.\n */\nexport interface CallToolOptions {\n /** Debug log array. Mutated in place by the protocol layer. */\n debugLogs?: DebugLogEntry[];\n /** URL for async task status notifications. */\n webhookUrl?: string;\n /** HMAC-SHA256 secret for push_notification_config authentication. */\n webhookSecret?: string;\n /** Bearer token for push_notification_config validation. */\n webhookToken?: string;\n /** Pinned protocol generation when the agent advertises both v2 and v3. */\n serverVersion?: 'v2' | 'v3';\n /** A2A session continuity (contextId carries conversation, taskId resumes a task). */\n session?: { contextId?: string; taskId?: string };\n /**\n * AdCP version pin from the calling client/server instance. Sets the\n * wire-level `adcp_major_version` field per-call instead of from the\n * SDK-pinned `ADCP_MAJOR_VERSION` constant. Default falls back to the\n * constant so call sites that don't plumb a per-instance version keep\n * their existing behavior. An explicit `adcp_major_version` /\n * `adcp_version` in `args` overrides this — conformance harnesses use\n * that path to probe seller version negotiation.\n */\n adcpVersion?: string;\n /**\n * Optional wire-only version override. Schema selection and client\n * construction can remain pinned to `adcpVersion`; the request envelope is\n * emitted for this release-precision line.\n */\n wireAdcpVersion?: string;\n /**\n * Controls whether the SDK injects AdCP version envelope fields into the\n * outgoing request. Defaults to `auto`. 3.0 pins emit only the legacy\n * `adcp_major_version`; 3.1+ pins emit both the legacy major and exact\n * `adcp_version` marker. `major-only` forces the legacy integer marker\n * without the 3.1 string marker for strict pre-3.1 peers discovered at\n * runtime.\n */\n versionEnvelope?: VersionEnvelopeMode;\n /**\n * Transport-level safeguards (size caps, etc.). Per-call override of any\n * matching field on the client constructor's `transport` option.\n */\n transport?: TransportOptions;\n /** Caller-owned cancellation signal for the in-flight protocol call. */\n signal?: AbortSignal;\n /** Transport-level diagnostics callback for outbound HTTP requests. */\n onTransportActivity?: TransportActivityHandlerFn;\n /**\n * Correlation metadata attached to transport diagnostics events emitted\n * while this protocol call is active.\n */\n transportActivityContext?: {\n operationId?: string;\n taskId?: string;\n contextId?: string;\n idempotencyKey?: string;\n };\n}\n\n/**\n * Universal protocol client - automatically routes to the correct protocol implementation\n */\nexport class ProtocolClient {\n /**\n * Call a tool on an agent using the appropriate protocol.\n *\n * @param agent - Agent configuration\n * @param toolName - Name of the tool/skill to call\n * @param args - Tool arguments (includes reporting_webhook if needed - NOT removed)\n * @param options - Optional call-level configuration. See {@link CallToolOptions}.\n */\n static async callTool(\n agent: AgentConfig,\n toolName: string,\n args: Record<string, unknown>,\n options: CallToolOptions = {}\n ): Promise<unknown> {\n const {\n debugLogs = [],\n webhookUrl,\n webhookSecret,\n webhookToken,\n serverVersion,\n session,\n adcpVersion,\n wireAdcpVersion,\n versionEnvelope: versionEnvelopeMode = 'auto',\n transport: requestedTransport,\n signal,\n onTransportActivity,\n transportActivityContext,\n } = options;\n const transport = normalizeTransportOptions(requestedTransport);\n // Per-instance version envelope. Throws on unparseable pins via\n // `resolveWireMajor`; construction-time `resolveAdcpVersion` is the\n // primary gate but this is the failsafe for callers reaching\n // `ProtocolClient.callTool` directly (test harnesses, the in-process\n // MCP path). Returns `{ adcp_major_version }` for 3.0 pins and\n // `{ adcp_major_version, adcp_version }` for 3.1+ pins.\n const versionEnvelope = buildVersionEnvelopeForMode(\n versionEnvelopeMode,\n wireAdcpVersion ?? adcpVersion,\n serverVersion\n );\n // Enter the response-size-limit ALS slot once for this call. The slot is\n // read by `wrapFetchWithSizeLimit` in both protocol transports, so the\n // cap applies regardless of which path (MCP / A2A / OAuth refresh) the\n // call ends up taking. No-op when the cap is unset or non-positive.\n return withResponseSizeLimit(transport?.maxResponseBytes, () =>\n withTransportDiagnostics(\n {\n agentId: agent.id,\n protocol: agent.protocol,\n tool: toolName,\n taskType: toolName,\n ...transportActivityContext,\n onTransportActivity,\n },\n () =>\n withSpan(\n `adcp.${agent.protocol}.call_tool`,\n {\n 'adcp.agent_id': agent.id,\n 'adcp.protocol': agent.protocol,\n 'adcp.tool': toolName,\n 'http.url': agent.agent_uri,\n },\n async () => {\n // In-process MCP path: pre-connected client, no HTTP transport.\n // Idempotency injection, schema validation, and governance middleware all\n // still apply (they run in SingleAgentClient above this call). We skip\n // URL validation, OAuth refresh, and signing — none apply in-process.\n if (agent.protocol === 'mcp' && agent._inProcessMcpClient) {\n const inProcArgs = applyVersionEnvelope(args, versionEnvelope);\n return callMCPToolWithClient(agent._inProcessMcpClient, toolName, inProcArgs, debugLogs, {\n ...(signal && { signal }),\n ...(transport?.requestTimeoutMs !== undefined && { requestTimeoutMs: transport.requestTimeoutMs }),\n });\n }\n\n validateAgentUrl(agent.agent_uri);\n\n // OAuth 2.0 client credentials (RFC 6749 §4.4): re-exchange the\n // secret for a fresh access token whenever the cached one is within\n // its expiration skew. Runs before every call so mid-session expiry\n // can't leave the caller with a stale bearer. No-op if the agent\n // doesn't declare client credentials. Cheap on warm cache (single\n // `Date.now()` compare); a single POST to the token endpoint on miss.\n //\n // `allowPrivateIp` inherits the trust the caller already placed in\n // `agent.agent_uri` — if they're making a call to a private-IP agent,\n // they've authorized this process to talk to private-IP hosts, so\n // the token endpoint on the same network is reachable too. Public\n // agent URLs with private-IP token endpoints still require an\n // explicit opt-in via the library API.\n if (agent.oauth_client_credentials) {\n const ccStorage = getAgentStorage(agent);\n const allowPrivateIp = transport?.allowPrivateIp ?? isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n allowPrivateIp,\n fetch: transport?.trustedFetchFn,\n signal,\n });\n }\n\n const authToken = getAuthToken(agent);\n\n // RFC 9421 signing context. Built once per call and passed through\n // to each protocol-layer entry (`callMCPToolWithTasks`, `callA2ATool`,\n // `callMCPToolWithOAuth`) — those entries seed `signingContextStorage`\n // (AsyncLocalStorage) so the internal transport helpers read it\n // without an explicit parameter. Keep the explicit arg here: it's the\n // ALS seed, not incidental plumbing. `get_adcp_capabilities` is\n // exempt from signing (it's the discovery call itself) and also\n // triggers cache priming for any other op on agents with\n // `request_signing` configured.\n const signingContext = buildAgentSigningContext(agent);\n if (signingContext && toolName !== CAPABILITY_OP) {\n await ensureCapabilityLoaded(agent, signingContext, primeArgs =>\n ProtocolClient.callTool(agent, CAPABILITY_OP, primeArgs, {\n debugLogs,\n serverVersion,\n adcpVersion,\n ...(versionEnvelopeMode !== 'auto' && { versionEnvelope: versionEnvelopeMode }),\n transport,\n signal,\n ...(transport?.requestTimeoutMs !== undefined && { requestTimeoutMs: transport.requestTimeoutMs }),\n onTransportActivity,\n transportActivityContext,\n })\n );\n }\n\n // Inject the version envelope on every request so sellers can validate\n // compatibility. Skip for v2 servers — they don't recognise the\n // version fields and strict-schema agents reject them. The envelope\n // shape is per-pin: 3.0 pins get the integer `adcp_major_version`\n // alone; 3.1+ pins get both that and the release-precision string\n // `adcp_version` (`'3.1'` / `'3.1.0-beta.1'`) per spec PR\n // `adcontextprotocol/adcp#3493`.\n const argsWithVersion = applyVersionEnvelope(args, versionEnvelope);\n\n // Build push_notification_config for ASYNC TASK STATUS notifications\n // (NOT for reporting_webhook - that stays in args)\n // Schema: https://adcontextprotocol.org/schemas/v1/core/push-notification-config.json\n // `authentication` is a scheme SELECTOR, not a fallback: from AdCP\n // 3.0 on, push-notification-config.json makes its presence opt the\n // seller into legacy HMAC-SHA256 and its absence select the RFC\n // 9421 webhook profile, with `required: [\"url\"]` only. Emitting it\n // with a placeholder credential would therefore downgrade every\n // webhook to legacy HMAC keyed by a constant that ships in this\n // file, so the block is omitted unless a real secret backs it.\n //\n // v2.5 predates the selector: there `required` is\n // `[\"url\", \"authentication\"]` and there is no 9421 path, so an\n // omitted block is schema-invalid rather than a mode selection.\n // With no secret there is nothing honest to send a v2 seller, so\n // suppress the registration instead of fabricating a credential.\n const pushNotificationConfig: PushNotificationConfig | undefined = (():\n | PushNotificationConfig\n | undefined => {\n if (!webhookUrl) return undefined;\n if (webhookSecret) {\n return {\n url: webhookUrl,\n ...(webhookToken && { token: webhookToken }),\n authentication: {\n schemes: ['HMAC-SHA256' as const],\n credentials: webhookSecret,\n },\n };\n }\n if (serverVersion === 'v2') {\n warnV2PushNotificationNeedsSecret();\n return undefined;\n }\n return {\n url: webhookUrl,\n ...(webhookToken && { token: webhookToken }),\n };\n })();\n\n if (agent.protocol === 'mcp') {\n // For MCP, include push_notification_config in tool arguments (MCP spec)\n const argsWithWebhook = pushNotificationConfig\n ? { ...argsWithVersion, push_notification_config: pushNotificationConfig }\n : argsWithVersion;\n\n // If the agent config carries authorization-code OAuth tokens,\n // route through the OAuth provider path so the MCP SDK can refresh\n // on 401 instead of hard-failing. Excludes client-credentials\n // agents: they have a cached access token but no refresh_token,\n // and their refresh path is a secret re-exchange (handled above),\n // not the SDK's refresh_token grant.\n if (agent.oauth_tokens && !agent.oauth_client_credentials) {\n const authProvider = getNonInteractiveOAuthProvider(agent, {\n agentHint: agent.id,\n storage: getAgentStorage(agent),\n allowHttp: isLikelyPrivateUrl(agent.agent_uri),\n });\n try {\n return await callMCPToolWithOAuth({\n agentUrl: agent.agent_uri,\n toolName,\n args: argsWithWebhook,\n authProvider,\n debugLogs,\n customHeaders: agent.headers,\n signingContext,\n signal,\n requestTimeoutMs: transport?.requestTimeoutMs,\n fetchFn: transport?.trustedFetchFn,\n allowPrivateIp: transport?.allowPrivateIp,\n });\n } catch (err) {\n // Refresh failed or server rejected the refreshed token — walk the\n // discovery chain so the caller can distinguish \"re-auth needed\"\n // from other failure modes.\n await rethrowAsNeedsAuthorization(\n err,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw err;\n }\n }\n\n // Use callMCPToolWithTasks which auto-detects server tasks capability\n // and falls back to standard callTool when tasks are not supported\n try {\n return await callMCPToolWithTasks(\n agent.agent_uri,\n toolName,\n argsWithWebhook,\n authToken,\n debugLogs,\n agent.headers,\n {\n ...(signingContext && { signingContext }),\n ...(signal && { signal }),\n ...(transport?.requestTimeoutMs !== undefined && {\n requestTimeoutMs: transport.requestTimeoutMs,\n }),\n ...(transport?.trustedFetchFn && { fetchFn: transport.trustedFetchFn }),\n ...(transport?.allowPrivateIp !== undefined && { allowPrivateIp: transport.allowPrivateIp }),\n }\n );\n } catch (err) {\n // Client-credentials agents: on 401, the AS may have rotated\n // something out-of-band. Force a fresh exchange and retry once\n // before surfacing the error. Bounded (single retry) so we don't\n // loop if the credentials are genuinely wrong.\n if (agent.oauth_client_credentials && is401Error(err)) {\n const ccStorage = getAgentStorage(agent);\n const allowPrivateIp = transport?.allowPrivateIp ?? isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.trustedFetchFn,\n signal,\n });\n const retryAuthToken = agent.oauth_tokens?.access_token ?? authToken;\n try {\n return await callMCPToolWithTasks(\n agent.agent_uri,\n toolName,\n argsWithWebhook,\n retryAuthToken,\n debugLogs,\n agent.headers,\n {\n ...(signingContext && { signingContext }),\n ...(signal && { signal }),\n ...(transport?.requestTimeoutMs !== undefined && {\n requestTimeoutMs: transport.requestTimeoutMs,\n }),\n ...(transport?.trustedFetchFn && { fetchFn: transport.trustedFetchFn }),\n ...(transport?.allowPrivateIp !== undefined && {\n allowPrivateIp: transport.allowPrivateIp,\n }),\n }\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(\n retryErr,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(\n err,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw err;\n }\n } else if (agent.protocol === 'a2a') {\n // For A2A, pass pushNotificationConfig separately (not in skill parameters)\n try {\n return await callA2ATool(\n agent.agent_uri,\n toolName,\n argsWithVersion,\n authToken,\n debugLogs,\n pushNotificationConfig,\n agent.headers,\n signingContext,\n session,\n signal,\n transport?.requestTimeoutMs,\n transport?.trustedFetchFn,\n transport?.allowPrivateIp\n );\n } catch (err) {\n // Same single-retry-on-401 for client-credentials agents as the\n // MCP path above. Kept symmetric so A2A CC agents aren't a\n // second-class experience — including the NeedsAuthorizationError\n // rewrap on a retry that still 401s.\n if (agent.oauth_client_credentials && is401Error(err)) {\n const ccStorage = getAgentStorage(agent);\n const allowPrivateIp = transport?.allowPrivateIp ?? isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.trustedFetchFn,\n signal,\n });\n const retryAuthToken = agent.oauth_tokens?.access_token ?? authToken;\n try {\n return await callA2ATool(\n agent.agent_uri,\n toolName,\n argsWithVersion,\n retryAuthToken,\n debugLogs,\n pushNotificationConfig,\n agent.headers,\n signingContext,\n session,\n signal,\n transport?.requestTimeoutMs,\n transport?.trustedFetchFn,\n transport?.allowPrivateIp\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(\n retryErr,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(\n err,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw err;\n }\n } else {\n throw new Error(`Unsupported protocol: ${agent.protocol}`);\n }\n }\n )\n )\n );\n }\n}\n\n/**\n * If `err` looks like a 401 from the MCP transport, probe the agent for a\n * Bearer challenge and throw a {@link NeedsAuthorizationError} carrying\n * walked discovery metadata. If the error isn't a 401 or we can't build a\n * requirements record, return silently so the caller re-throws the original.\n *\n * Keeping this off the hot path: we only probe on error, and the probe is\n * a single unauthenticated `tools/list` POST — no retries, no DNS rebind.\n */\nasync function rethrowAsNeedsAuthorization(\n err: unknown,\n agentUrl: string,\n fetchFn?: typeof fetch,\n signal?: AbortSignal,\n configuredAllowPrivateIp?: boolean\n): Promise<void> {\n if (err instanceof NeedsAuthorizationError) throw err;\n if (!is401Error(err)) return;\n\n // If the caller has already connected to the agent URL, they've implicitly\n // trusted it — inherit that trust for the discovery probe so loopback /\n // private-IP development agents work the same way as public ones.\n const allowPrivateIp = configuredAllowPrivateIp ?? isLikelyPrivateUrl(agentUrl);\n\n // discoverAuthorizationRequirements internally catches network failures and\n // returns null rather than throwing — anything that escapes is a genuine\n // bug we want to surface rather than mask the 401 with.\n const requirements = await discoverAuthorizationRequirements(agentUrl, { allowPrivateIp, fetchFn, signal });\n if (requirements) {\n throw new NeedsAuthorizationError(requirements);\n }\n // No requirements walked; let the caller re-throw the original error.\n}\n\n/**\n * Simple factory functions for protocol-specific clients.\n *\n * Both factories accept a `transport` argument that flows through to the\n * size-cap surface so callers reaching the factory exports honor the same\n * `maxResponseBytes` contract as `ProtocolClient.callTool`. Without it,\n * the factories would silently bypass the cap, which the public API\n * (`TransportOptions`) implies they honor.\n */\nexport const createMCPClient = (\n agentUrl: string,\n authToken?: string,\n headers?: Record<string, string>,\n serverVersion?: 'v2' | 'v3',\n adcpVersion?: string,\n transport?: TransportOptions,\n versionEnvelopeMode: VersionEnvelopeMode = 'auto'\n) => {\n transport = normalizeTransportOptions(transport);\n // Validate the pin at factory time so a typo surfaces here rather than at\n // first call. `buildVersionEnvelope` throws via `resolveWireMajor` on bad\n // input — call it once to surface, then close over the envelope.\n const versionEnvelope = buildVersionEnvelopeForMode(versionEnvelopeMode, adcpVersion, serverVersion);\n return {\n callTool: (toolName: string, args: Record<string, unknown>, debugLogs?: DebugLogEntry[]) =>\n withResponseSizeLimit(transport?.maxResponseBytes, () =>\n callMCPToolWithTasks(\n agentUrl,\n toolName,\n applyVersionEnvelope(args, versionEnvelope),\n authToken,\n debugLogs,\n headers,\n {\n ...(transport?.requestTimeoutMs !== undefined && { requestTimeoutMs: transport.requestTimeoutMs }),\n ...(transport?.trustedFetchFn && { fetchFn: transport.trustedFetchFn }),\n ...(transport?.allowPrivateIp !== undefined && { allowPrivateIp: transport.allowPrivateIp }),\n }\n )\n ),\n };\n};\n\nexport const createA2AClient = (\n agentUrl: string,\n authToken?: string,\n headers?: Record<string, string>,\n serverVersion?: 'v2' | 'v3',\n adcpVersion?: string,\n transport?: TransportOptions,\n versionEnvelopeMode: VersionEnvelopeMode = 'auto'\n) => {\n transport = normalizeTransportOptions(transport);\n const versionEnvelope = buildVersionEnvelopeForMode(versionEnvelopeMode, adcpVersion, serverVersion);\n return {\n callTool: (toolName: string, parameters: Record<string, unknown>, debugLogs?: DebugLogEntry[]) =>\n withResponseSizeLimit(transport?.maxResponseBytes, () =>\n callA2ATool(\n agentUrl,\n toolName,\n applyVersionEnvelope(parameters, versionEnvelope),\n authToken,\n debugLogs,\n undefined,\n headers,\n undefined,\n undefined,\n undefined,\n transport?.requestTimeoutMs,\n transport?.trustedFetchFn,\n transport?.allowPrivateIp\n )\n ),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAOO;AAEP,IAAAA,cAAoC;AACpC,uBAAuE;AACvE,iBAAoC;AAyBpC,IAAAC,cAA4B;AAC5B,mBAA2C;AAC3C,uBAQO;AAEP,IAAAC,oBAA4D;AAC5D,IAAAF,cAAqC;AACrC,IAAAC,cAA4B;AAG5B,kB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I,WAAW,kBAAkB,EAAE,SAAS,UAAU,eAAe;AAAA,UACrE,GAAI,WAAW,mBAAmB,UAAa,EAAE,gBAAgB,UAAU,eAAe;AAAA,QAC5F;AAAA,MACF;AAAA,IACF;AAAA,EACJ;AACF;AAEO,MAAM,kBAAkB,CAC7B,UACA,WACA,SACA,eACA,aACA,WACA,sBAA2C,WACxC;AACH,cAAY,0BAA0B,SAAS;AAC/C,QAAM,kBAAkB,4BAA4B,qBAAqB,aAAa,aAAa;AACnG,SAAO;AAAA,IACL,UAAU,CAAC,UAAkB,YAAqC,kBAChE;AAAA,MAAsB,WAAW;AAAA,MAAkB,UACjD;AAAA,QACE;AAAA,QACA;AAAA,QACA,qBAAqB,YAAY,eAAe;AAAA,QAChD;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW;AAAA,QACX,WAAW;AAAA,QACX,WAAW;AAAA,MACb;AAAA,IACF;AAAA,EACJ;AACF;","names":["import_mcp","import_a2a","import_mcp_tasks","import_errors","import_transportDiagnostics"]}
1
+ {"version":3,"sources":["../../../src/lib/protocols/index.ts"],"sourcesContent":["// Unified Protocol Interface for AdCP\nexport {\n callMCPTool,\n callMCPToolWithOAuth,\n connectMCP,\n closeMCPConnections,\n closeOAuthConnections,\n UnauthorizedError,\n} from './mcp';\n\nimport { closeMCPConnections } from './mcp';\nimport { closeCurrentMCPConnectionScope, withMCPConnectionScope } from './mcp-scope';\nimport { closeA2AConnections } from './a2a';\n\n/**\n * Close protocol connections for the given protocol.\n * MCP closes persistent HTTP transports; A2A clears the agent-card client cache.\n */\nexport async function closeConnections(protocol: 'mcp' | 'a2a' = 'mcp'): Promise<void> {\n if (protocol === 'mcp') {\n await closeMCPConnections();\n } else {\n closeA2AConnections();\n }\n}\n\n/** Close only the current runner's MCP scope; fall back to legacy global cleanup. */\nexport async function closeScopedConnections(protocol: 'mcp' | 'a2a' = 'mcp'): Promise<void> {\n if (protocol === 'mcp') {\n if (!(await closeCurrentMCPConnectionScope())) await closeMCPConnections();\n } else {\n closeA2AConnections();\n }\n}\n\nexport { withMCPConnectionScope };\nexport type { MCPCallOptions, MCPConnectionResult } from './mcp';\nexport { callA2ATool } from './a2a';\nexport { DEFAULT_REQUEST_TIMEOUT_MS } from './abort';\nexport {\n callMCPToolWithTasks,\n getMCPTaskStatus,\n getMCPTaskResult,\n listMCPTasks,\n cancelMCPTask,\n mapMCPTaskStatus,\n serverSupportsTasks,\n} from './mcp-tasks';\n\nimport { callMCPToolWithTasks, callMCPToolWithClient } from './mcp-tasks';\nimport { callMCPToolWithOAuth } from './mcp';\nimport { callA2ATool } from './a2a';\nimport type { AgentConfig, DebugLogEntry } from '../types';\nimport type { PushNotificationConfig } from '../types/tools.generated';\nimport { getAuthToken } from '../auth';\nimport {\n discoverAuthorizationRequirements,\n NeedsAuthorizationError,\n getAgentStorage,\n ensureClientCredentialsTokens,\n} from '../auth/oauth';\nimport { getNonInteractiveOAuthProvider } from '../auth/oauth/provider-cache';\nimport { is401Error } from '../errors';\nimport { isLikelyPrivateUrl } from '../net';\nimport { validateAgentUrl } from '../validation';\nimport { withSpan } from '../observability/tracing';\nimport { ADCP_MAJOR_VERSION, ADCP_VERSION, parseAdcpMajorVersion } from '../version';\nimport { ConfigurationError } from '../errors';\nimport { resolveBundleKey, toReleasePrecisionWire, validateAdcpVersionWire } from '../validation/schema-loader';\nimport { buildAgentSigningContext, CAPABILITY_OP, ensureCapabilityLoaded } from '../signing/client';\nimport { withResponseSizeLimit } from './responseSizeLimit';\nimport {\n withTransportDiagnostics,\n type TransportActivityHandler as TransportActivityHandlerFn,\n} from './transportDiagnostics';\n\nexport {\n sanitizeTransportHeaders,\n sanitizeTransportUrl,\n withTransportDiagnostics,\n wrapFetchWithTransportDiagnostics,\n} from './transportDiagnostics';\nexport type { TransportActivity, TransportActivityContext, TransportActivityHandler } from './transportDiagnostics';\n\nexport type VersionEnvelopeMode = 'auto' | 'none' | 'major-only';\n\n/**\n * Derive the wire-level `adcp_major_version` integer from a caller-supplied\n * pin. Returns the SDK default when no pin is provided; throws on a pin\n * that doesn't parse so misuse surfaces at the factory boundary instead\n * of silently emitting the SDK's major.\n *\n * Throws `ConfigurationError` (not a plain `Error`) so a typo'd pin\n * surfaces with the same error class as the construction-time gate in\n * `resolveAdcpVersion` — one shape for all pin-misuse paths.\n */\nfunction resolveWireMajor(adcpVersion: string | undefined): number {\n if (adcpVersion === undefined) return ADCP_MAJOR_VERSION;\n const parsed = parseAdcpMajorVersion(adcpVersion);\n if (!Number.isFinite(parsed)) {\n throw new ConfigurationError(\n `adcpVersion ${JSON.stringify(adcpVersion)} is not a valid AdCP version. ` +\n `Expected a semver string (e.g. '3.0.1', '3.1.0-beta.1') or a legacy alias (e.g. 'v3').`,\n 'adcpVersion'\n );\n }\n return parsed;\n}\n\n/**\n * Returns true when the AdCP release that `bundleKey` identifies declares the\n * top-level `adcp_version` envelope field. The field landed in AdCP 3.1 per\n * spec PR `adcontextprotocol/adcp#3493` — 3.0 (any patch / prerelease) does\n * not carry it; 3.1+ does. Used to gate dual-emit on the wire so a 3.0-pinned\n * client doesn't emit a field its target schema doesn't define.\n */\nexport function bundleSupportsAdcpVersionField(bundleKey: string): boolean {\n const major = parseAdcpMajorVersion(bundleKey);\n if (!Number.isFinite(major)) return false;\n if (major < 3) return false;\n if (major > 3) return true;\n // Major 3 — only 3.1+ has the field. Bundle key shape is normalized by\n // `resolveBundleKey`: `'3.0'` / `'3.1'` for stable; `'3.0.0-beta.1'` /\n // `'3.1.0-beta.1'` for prereleases. Match the minor.\n const minorMatch = bundleKey.match(/^\\d+\\.(\\d+)/);\n if (!minorMatch) return false;\n return parseInt(minorMatch[1]!, 10) >= 1;\n}\n\n/**\n * Build the wire-level version envelope to merge into outgoing request args.\n *\n * Per AdCP 3.1 (spec PR `adcontextprotocol/adcp#3493`), 3.1+ requests carry\n * BOTH the integer `adcp_major_version` (deprecated through 3.x, removed in\n * 4.0) AND the release-precision string `adcp_version`. 3.0 schemas don't\n * define the string field, so a 3.0-pinned client emits the integer only —\n * matches the 3.0 spec exactly.\n *\n * Wire string is release-precision (MAJOR.MINOR with optional prerelease tag),\n * per `core/version-envelope.json`'s pattern `^\\d+\\.\\d+(-[a-zA-Z0-9.-]+)?$`.\n * Full-semver bundle keys (`'3.1.0-beta.1'`) are collapsed via\n * `toReleasePrecisionWire` to `'3.1-beta.1'` before emit — meta-field shapes\n * are explicitly NOT valid wire values per the envelope schema's own\n * normalization rule.\n *\n * Returns `{}` for v2 callers (predates the major-version field entirely).\n */\nfunction buildVersionEnvelope(\n adcpVersion: string | undefined,\n serverVersion: 'v2' | 'v3' | undefined\n): Record<string, unknown> {\n if (serverVersion === 'v2') return {};\n const wireMajor = resolveWireMajor(adcpVersion);\n const bundleKey = resolveBundleKey(adcpVersion ?? ADCP_VERSION);\n if (!bundleSupportsAdcpVersionField(bundleKey)) {\n return { adcp_major_version: wireMajor };\n }\n const wireValue = toReleasePrecisionWire(bundleKey);\n // Defensive postcondition — should never throw in well-formed code, but\n // if a future refactor breaks the normalization the error message tells\n // the developer to call `toReleasePrecisionWire` instead of silently\n // emitting a non-spec wire string.\n validateAdcpVersionWire(wireValue);\n return { adcp_major_version: wireMajor, adcp_version: wireValue };\n}\n\nlet hasWarnedAboutV2PushNotificationSecret = false;\n\n/**\n * Warn once when an async webhook registration is suppressed for a v2 seller.\n *\n * v2.5's `push-notification-config.json` requires `authentication`, and unlike\n * 3.x it has no RFC 9421 selector semantics — so omitting the block produces a\n * schema-invalid request rather than choosing a signing mode. Without a\n * configured secret there is no honest value to send, and the previous\n * behaviour (a hardcoded placeholder credential) told the seller the channel\n * was authenticated by a constant published in this package.\n */\nfunction warnV2PushNotificationNeedsSecret(): void {\n if (hasWarnedAboutV2PushNotificationSecret) return;\n hasWarnedAboutV2PushNotificationSecret = true;\n console.warn(\n '[adcp] Suppressing push_notification_config for a v2 seller: AdCP 2.5 requires an ' +\n '`authentication` block and no `webhookSecret` is configured. Set `webhookSecret` to register ' +\n 'async task-status webhooks with this agent, or move the agent to an AdCP 3.x pin, where the ' +\n 'RFC 9421 webhook profile needs no shared secret.'\n );\n}\n\nfunction buildVersionEnvelopeForMode(\n mode: VersionEnvelopeMode,\n adcpVersion: string | undefined,\n serverVersion: 'v2' | 'v3' | undefined\n): Record<string, unknown> {\n if (mode === 'none' || serverVersion === 'v2') return {};\n if (mode === 'major-only') return { adcp_major_version: resolveWireMajor(adcpVersion) };\n return buildVersionEnvelope(adcpVersion, serverVersion);\n}\n\n/**\n * Merge the wire-level version envelope into a caller-supplied args object.\n * Caller args win: an explicit `adcp_major_version` / `adcp_version` in\n * `args` (e.g. a conformance harness probing `VERSION_UNSUPPORTED`) passes\n * through unchanged. The envelope only fills fields the caller didn't set.\n *\n * Single chokepoint for all four wire-injection sites so a future refactor\n * can't silently flip the spread order on one branch and leave the others\n * intact. Stale dual-field drift is caught at the server boundary by\n * `createAdcpServer`'s field-disagreement check (spec PR\n * `adcontextprotocol/adcp#3493`).\n *\n * @internal\n */\nexport function applyVersionEnvelope(\n args: Record<string, unknown>,\n envelope: Record<string, unknown>\n): Record<string, unknown> {\n return { ...envelope, ...args };\n}\n\n/**\n * Transport-level safeguards applied to a call.\n *\n * Wired into the SDK's internal fetch chain via AsyncLocalStorage, so the\n * cap takes effect even when the underlying transport's connection cache\n * reuses a fetch that was created on an earlier call with different limits.\n */\nexport interface TransportOptions {\n /**\n * Maximum response body size (in octets) the SDK will read before aborting\n * with `ResponseTooLargeError`. When unset, the SDK does not impose a cap —\n * matches the underlying MCP / A2A transport defaults.\n *\n * Set this when crawling **untrusted** agents (registries, federated\n * discovery layers, monitoring tools) to prevent a hostile vendor from\n * buffering a large reply before any application-layer schema validation\n * runs. Counted across response chunks; pre-cancels when `Content-Length`\n * exceeds the cap. Applies to A2A agent-card discovery\n * (`/.well-known/agent.json`) on the same call as well.\n *\n * Per-call override (`TaskOptions.transport.maxResponseBytes`) beats the\n * value set on the client constructor (`SingleAgentClientConfig.transport`).\n *\n * @remarks\n * **Safe to set on all calls.** SSE responses (`text/event-stream`) are\n * passed through unchanged — a single tool call legitimately emits N status\n * frames + a final result, bounded by protocol-level framing rather than\n * cumulative byte counts. The cap applies to one-shot JSON responses\n * (`get_adcp_capabilities`, agent-card lookup, tool result payloads on\n * non-streaming transports) where the body is bounded by definition.\n *\n * @remarks\n * **Hostile-peer note:** A peer can opt itself out of this cap by responding\n * with `Content-Type: text/event-stream`. SSE is bypassed because cumulative\n * event-frame bytes are unbounded by spec — MCP and A2A both stream tool\n * responses this way. The MCP/A2A SDKs consume SSE incrementally and frame\n * termination bounds memory in practice, so this is not a memory-bomb risk\n * for well-formed transports. Adopters relying on `maxResponseBytes` as a\n * hostile-server defense should treat it as best-effort for non-SSE\n * responses only.\n *\n * @remarks\n * Future hardening knobs (DNS-rebind defense, scheme allow-list, request\n * timeout overrides) will land here as additional fields. When `trustedFetchFn`\n * is supplied, the SDK composes it inside its signing, capture, size-limit,\n * timeout, and diagnostics wrappers so callers do not have to reproduce\n * that non-obvious ordering themselves.\n */\n maxResponseBytes?: number;\n /**\n * Scoped fetch implementation for all outbound HTTP performed on behalf of\n * this client or call, including endpoint/card discovery, tool listing,\n * OAuth discovery and token refresh, and MCP/A2A tool requests.\n *\n * The function is runtime-only configuration and is never serialized into\n * agent records, storyboard artifacts, or compliance output. When unset,\n * the SDK uses the global `fetch` implementation.\n *\n * Supplying this function makes it the trusted network boundary: the SDK\n * still validates URL schemes, redirect behavior, timeouts, and body limits,\n * but delegates DNS resolution and address policy to the implementation.\n * It must prevent DNS rebinding and unsafe private-address access itself (for\n * example with an egress proxy or its own DNS pinning).\n */\n trustedFetchFn?: typeof fetch;\n /**\n * @deprecated Rename to `trustedFetchFn`. Supplying this legacy alias is\n * treated as an explicit assertion that the implementation pins DNS.\n */\n fetchFn?: typeof fetch;\n /**\n * Permit this client to connect to private DNS answers. Localhost and an\n * initial private IP literal are allowed automatically only on their exact\n * origin; use this for private-DNS enterprise agents.\n */\n allowPrivateIp?: boolean;\n /**\n * Timeout in milliseconds for bounded one-shot transport requests such as\n * A2A agent-card discovery and MCP read-path probes. Defaults to 60 seconds\n * for A2A discovery so an unresponsive card endpoint cannot hang forever.\n * Set to `0` to disable the SDK-imposed discovery timeout.\n */\n requestTimeoutMs?: number;\n /** A2A-only compatibility policy. Compliance uses `{ enabled: false }` for native 1.0 grading. */\n legacyCompat?: import('./a2a').A2ALegacyCompatOptions;\n}\n\nlet warnedLegacyTransportFetch = false;\n\n/** @internal Normalize the pre-GA fetch hook rename without silently dropping JS callers. */\nexport function normalizeTransportOptions(transport?: TransportOptions): TransportOptions | undefined {\n if (!transport?.fetchFn) return transport;\n if (transport.trustedFetchFn && transport.trustedFetchFn !== transport.fetchFn) {\n throw new TypeError('TransportOptions cannot set different fetchFn and trustedFetchFn implementations');\n }\n if (!warnedLegacyTransportFetch) {\n warnedLegacyTransportFetch = true;\n console.warn(\n '[adcp] TransportOptions.fetchFn is deprecated; rename it to trustedFetchFn. ' +\n 'Custom fetch implementations must provide connect-time DNS pinning.'\n );\n }\n return { ...transport, trustedFetchFn: transport.trustedFetchFn ?? transport.fetchFn };\n}\n\n/**\n * Options for {@link ProtocolClient.callTool}. All fields are optional.\n *\n * `webhookUrl` / `webhookSecret` / `webhookToken` are for ASYNC TASK STATUS\n * notifications (push_notification_config). For reporting webhooks\n * (reporting_webhook), include them directly in `args` — they stay in skill\n * parameters and are sent verbatim to the agent.\n */\nexport interface CallToolOptions {\n /** Debug log array. Mutated in place by the protocol layer. */\n debugLogs?: DebugLogEntry[];\n /** URL for async task status notifications. */\n webhookUrl?: string;\n /** HMAC-SHA256 secret for push_notification_config authentication. */\n webhookSecret?: string;\n /** Bearer token for push_notification_config validation. */\n webhookToken?: string;\n /** Pinned protocol generation when the agent advertises both v2 and v3. */\n serverVersion?: 'v2' | 'v3';\n /** A2A session continuity (contextId carries conversation, taskId resumes a task). */\n session?: { contextId?: string; taskId?: string };\n /**\n * AdCP version pin from the calling client/server instance. Sets the\n * wire-level `adcp_major_version` field per-call instead of from the\n * SDK-pinned `ADCP_MAJOR_VERSION` constant. Default falls back to the\n * constant so call sites that don't plumb a per-instance version keep\n * their existing behavior. An explicit `adcp_major_version` /\n * `adcp_version` in `args` overrides this — conformance harnesses use\n * that path to probe seller version negotiation.\n */\n adcpVersion?: string;\n /**\n * Optional wire-only version override. Schema selection and client\n * construction can remain pinned to `adcpVersion`; the request envelope is\n * emitted for this release-precision line.\n */\n wireAdcpVersion?: string;\n /**\n * Controls whether the SDK injects AdCP version envelope fields into the\n * outgoing request. Defaults to `auto`. 3.0 pins emit only the legacy\n * `adcp_major_version`; 3.1+ pins emit both the legacy major and exact\n * `adcp_version` marker. `major-only` forces the legacy integer marker\n * without the 3.1 string marker for strict pre-3.1 peers discovered at\n * runtime.\n */\n versionEnvelope?: VersionEnvelopeMode;\n /**\n * Transport-level safeguards (size caps, etc.). Per-call override of any\n * matching field on the client constructor's `transport` option.\n */\n transport?: TransportOptions;\n /** Caller-owned cancellation signal for the in-flight protocol call. */\n signal?: AbortSignal;\n /** Transport-level diagnostics callback for outbound HTTP requests. */\n onTransportActivity?: TransportActivityHandlerFn;\n /**\n * Correlation metadata attached to transport diagnostics events emitted\n * while this protocol call is active.\n */\n transportActivityContext?: {\n operationId?: string;\n taskId?: string;\n contextId?: string;\n idempotencyKey?: string;\n };\n}\n\n/**\n * Universal protocol client - automatically routes to the correct protocol implementation\n */\nexport class ProtocolClient {\n /**\n * Call a tool on an agent using the appropriate protocol.\n *\n * @param agent - Agent configuration\n * @param toolName - Name of the tool/skill to call\n * @param args - Tool arguments (includes reporting_webhook if needed - NOT removed)\n * @param options - Optional call-level configuration. See {@link CallToolOptions}.\n */\n static async callTool(\n agent: AgentConfig,\n toolName: string,\n args: Record<string, unknown>,\n options: CallToolOptions = {}\n ): Promise<unknown> {\n const {\n debugLogs = [],\n webhookUrl,\n webhookSecret,\n webhookToken,\n serverVersion,\n session,\n adcpVersion,\n wireAdcpVersion,\n versionEnvelope: versionEnvelopeMode = 'auto',\n transport: requestedTransport,\n signal,\n onTransportActivity,\n transportActivityContext,\n } = options;\n const transport = normalizeTransportOptions(requestedTransport);\n // Per-instance version envelope. Throws on unparseable pins via\n // `resolveWireMajor`; construction-time `resolveAdcpVersion` is the\n // primary gate but this is the failsafe for callers reaching\n // `ProtocolClient.callTool` directly (test harnesses, the in-process\n // MCP path). Returns `{ adcp_major_version }` for 3.0 pins and\n // `{ adcp_major_version, adcp_version }` for 3.1+ pins.\n const versionEnvelope = buildVersionEnvelopeForMode(\n versionEnvelopeMode,\n wireAdcpVersion ?? adcpVersion,\n serverVersion\n );\n // Enter the response-size-limit ALS slot once for this call. The slot is\n // read by `wrapFetchWithSizeLimit` in both protocol transports, so the\n // cap applies regardless of which path (MCP / A2A / OAuth refresh) the\n // call ends up taking. No-op when the cap is unset or non-positive.\n return withResponseSizeLimit(transport?.maxResponseBytes, () =>\n withTransportDiagnostics(\n {\n agentId: agent.id,\n protocol: agent.protocol,\n tool: toolName,\n taskType: toolName,\n ...transportActivityContext,\n onTransportActivity,\n },\n () =>\n withSpan(\n `adcp.${agent.protocol}.call_tool`,\n {\n 'adcp.agent_id': agent.id,\n 'adcp.protocol': agent.protocol,\n 'adcp.tool': toolName,\n 'http.url': agent.agent_uri,\n },\n async () => {\n // In-process MCP path: pre-connected client, no HTTP transport.\n // Idempotency injection, schema validation, and governance middleware all\n // still apply (they run in SingleAgentClient above this call). We skip\n // URL validation, OAuth refresh, and signing — none apply in-process.\n if (agent.protocol === 'mcp' && agent._inProcessMcpClient) {\n const inProcArgs = applyVersionEnvelope(args, versionEnvelope);\n return callMCPToolWithClient(agent._inProcessMcpClient, toolName, inProcArgs, debugLogs, {\n ...(signal && { signal }),\n ...(transport?.requestTimeoutMs !== undefined && { requestTimeoutMs: transport.requestTimeoutMs }),\n });\n }\n\n validateAgentUrl(agent.agent_uri);\n\n // OAuth 2.0 client credentials (RFC 6749 §4.4): re-exchange the\n // secret for a fresh access token whenever the cached one is within\n // its expiration skew. Runs before every call so mid-session expiry\n // can't leave the caller with a stale bearer. No-op if the agent\n // doesn't declare client credentials. Cheap on warm cache (single\n // `Date.now()` compare); a single POST to the token endpoint on miss.\n //\n // `allowPrivateIp` inherits the trust the caller already placed in\n // `agent.agent_uri` — if they're making a call to a private-IP agent,\n // they've authorized this process to talk to private-IP hosts, so\n // the token endpoint on the same network is reachable too. Public\n // agent URLs with private-IP token endpoints still require an\n // explicit opt-in via the library API.\n if (agent.oauth_client_credentials) {\n const ccStorage = getAgentStorage(agent);\n const allowPrivateIp = transport?.allowPrivateIp ?? isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n allowPrivateIp,\n fetch: transport?.trustedFetchFn,\n signal,\n });\n }\n\n const authToken = getAuthToken(agent);\n\n // RFC 9421 signing context. Built once per call and passed through\n // to each protocol-layer entry (`callMCPToolWithTasks`, `callA2ATool`,\n // `callMCPToolWithOAuth`) — those entries seed `signingContextStorage`\n // (AsyncLocalStorage) so the internal transport helpers read it\n // without an explicit parameter. Keep the explicit arg here: it's the\n // ALS seed, not incidental plumbing. `get_adcp_capabilities` is\n // exempt from signing (it's the discovery call itself) and also\n // triggers cache priming for any other op on agents with\n // `request_signing` configured.\n const signingContext = buildAgentSigningContext(agent);\n if (signingContext && toolName !== CAPABILITY_OP) {\n await ensureCapabilityLoaded(agent, signingContext, primeArgs =>\n ProtocolClient.callTool(agent, CAPABILITY_OP, primeArgs, {\n debugLogs,\n serverVersion,\n adcpVersion,\n ...(versionEnvelopeMode !== 'auto' && { versionEnvelope: versionEnvelopeMode }),\n transport,\n signal,\n ...(transport?.requestTimeoutMs !== undefined && { requestTimeoutMs: transport.requestTimeoutMs }),\n onTransportActivity,\n transportActivityContext,\n })\n );\n }\n\n // Inject the version envelope on every request so sellers can validate\n // compatibility. Skip for v2 servers — they don't recognise the\n // version fields and strict-schema agents reject them. The envelope\n // shape is per-pin: 3.0 pins get the integer `adcp_major_version`\n // alone; 3.1+ pins get both that and the release-precision string\n // `adcp_version` (`'3.1'` / `'3.1.0-beta.1'`) per spec PR\n // `adcontextprotocol/adcp#3493`.\n const argsWithVersion = applyVersionEnvelope(args, versionEnvelope);\n\n // Build push_notification_config for ASYNC TASK STATUS notifications\n // (NOT for reporting_webhook - that stays in args)\n // Schema: https://adcontextprotocol.org/schemas/v1/core/push-notification-config.json\n // `authentication` is a scheme SELECTOR, not a fallback: from AdCP\n // 3.0 on, push-notification-config.json makes its presence opt the\n // seller into legacy HMAC-SHA256 and its absence select the RFC\n // 9421 webhook profile, with `required: [\"url\"]` only. Emitting it\n // with a placeholder credential would therefore downgrade every\n // webhook to legacy HMAC keyed by a constant that ships in this\n // file, so the block is omitted unless a real secret backs it.\n //\n // v2.5 predates the selector: there `required` is\n // `[\"url\", \"authentication\"]` and there is no 9421 path, so an\n // omitted block is schema-invalid rather than a mode selection.\n // With no secret there is nothing honest to send a v2 seller, so\n // suppress the registration instead of fabricating a credential.\n const generatedPushNotificationConfig: PushNotificationConfig | undefined = (():\n | PushNotificationConfig\n | undefined => {\n if (!webhookUrl) return undefined;\n if (webhookSecret) {\n return {\n url: webhookUrl,\n ...(transportActivityContext?.operationId && {\n operation_id: transportActivityContext.operationId,\n }),\n ...(webhookToken && { token: webhookToken }),\n authentication: {\n schemes: ['HMAC-SHA256' as const],\n credentials: webhookSecret,\n },\n };\n }\n if (serverVersion === 'v2') {\n warnV2PushNotificationNeedsSecret();\n return undefined;\n }\n return {\n url: webhookUrl,\n ...(transportActivityContext?.operationId && {\n operation_id: transportActivityContext.operationId,\n }),\n ...(webhookToken && { token: webhookToken }),\n };\n })();\n const explicitNativePushNotificationConfig =\n transport?.legacyCompat?.enabled === false &&\n argsWithVersion.push_notification_config !== null &&\n typeof argsWithVersion.push_notification_config === 'object' &&\n !Array.isArray(argsWithVersion.push_notification_config)\n ? (argsWithVersion.push_notification_config as PushNotificationConfig)\n : undefined;\n const pushNotificationConfig = generatedPushNotificationConfig ?? explicitNativePushNotificationConfig;\n\n if (agent.protocol === 'mcp') {\n // For MCP, include push_notification_config in tool arguments (MCP spec)\n const argsWithWebhook = pushNotificationConfig\n ? { ...argsWithVersion, push_notification_config: pushNotificationConfig }\n : argsWithVersion;\n\n // If the agent config carries authorization-code OAuth tokens,\n // route through the OAuth provider path so the MCP SDK can refresh\n // on 401 instead of hard-failing. Excludes client-credentials\n // agents: they have a cached access token but no refresh_token,\n // and their refresh path is a secret re-exchange (handled above),\n // not the SDK's refresh_token grant.\n if (agent.oauth_tokens && !agent.oauth_client_credentials) {\n const authProvider = getNonInteractiveOAuthProvider(agent, {\n agentHint: agent.id,\n storage: getAgentStorage(agent),\n allowHttp: isLikelyPrivateUrl(agent.agent_uri),\n });\n try {\n return await callMCPToolWithOAuth({\n agentUrl: agent.agent_uri,\n toolName,\n args: argsWithWebhook,\n authProvider,\n debugLogs,\n customHeaders: agent.headers,\n signingContext,\n signal,\n requestTimeoutMs: transport?.requestTimeoutMs,\n fetchFn: transport?.trustedFetchFn,\n allowPrivateIp: transport?.allowPrivateIp,\n });\n } catch (err) {\n // Refresh failed or server rejected the refreshed token — walk the\n // discovery chain so the caller can distinguish \"re-auth needed\"\n // from other failure modes.\n await rethrowAsNeedsAuthorization(\n err,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw err;\n }\n }\n\n // Use callMCPToolWithTasks which auto-detects server tasks capability\n // and falls back to standard callTool when tasks are not supported\n try {\n return await callMCPToolWithTasks(\n agent.agent_uri,\n toolName,\n argsWithWebhook,\n authToken,\n debugLogs,\n agent.headers,\n {\n ...(signingContext && { signingContext }),\n ...(signal && { signal }),\n ...(transport?.requestTimeoutMs !== undefined && {\n requestTimeoutMs: transport.requestTimeoutMs,\n }),\n ...(transport?.trustedFetchFn && { fetchFn: transport.trustedFetchFn }),\n ...(transport?.allowPrivateIp !== undefined && { allowPrivateIp: transport.allowPrivateIp }),\n }\n );\n } catch (err) {\n // Client-credentials agents: on 401, the AS may have rotated\n // something out-of-band. Force a fresh exchange and retry once\n // before surfacing the error. Bounded (single retry) so we don't\n // loop if the credentials are genuinely wrong.\n if (agent.oauth_client_credentials && is401Error(err)) {\n const ccStorage = getAgentStorage(agent);\n const allowPrivateIp = transport?.allowPrivateIp ?? isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.trustedFetchFn,\n signal,\n });\n const retryAuthToken = agent.oauth_tokens?.access_token ?? authToken;\n try {\n return await callMCPToolWithTasks(\n agent.agent_uri,\n toolName,\n argsWithWebhook,\n retryAuthToken,\n debugLogs,\n agent.headers,\n {\n ...(signingContext && { signingContext }),\n ...(signal && { signal }),\n ...(transport?.requestTimeoutMs !== undefined && {\n requestTimeoutMs: transport.requestTimeoutMs,\n }),\n ...(transport?.trustedFetchFn && { fetchFn: transport.trustedFetchFn }),\n ...(transport?.allowPrivateIp !== undefined && {\n allowPrivateIp: transport.allowPrivateIp,\n }),\n }\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(\n retryErr,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(\n err,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw err;\n }\n } else if (agent.protocol === 'a2a') {\n // Native A2A has two distinct registration surfaces. The\n // official protocol configuration gets the representable\n // transport fields, while the complete AdCP application\n // object (including operation_id) remains in skill input.\n // Preserve the stable 0.3 wire shape outside native mode.\n const a2aParameters =\n transport?.legacyCompat?.enabled === false && pushNotificationConfig\n ? { ...argsWithVersion, push_notification_config: pushNotificationConfig }\n : argsWithVersion;\n try {\n return await callA2ATool(\n agent.agent_uri,\n toolName,\n a2aParameters,\n authToken,\n debugLogs,\n pushNotificationConfig,\n agent.headers,\n signingContext,\n session,\n signal,\n transport?.requestTimeoutMs,\n transport?.trustedFetchFn,\n transport?.allowPrivateIp,\n transport?.legacyCompat\n );\n } catch (err) {\n // Same single-retry-on-401 for client-credentials agents as the\n // MCP path above. Kept symmetric so A2A CC agents aren't a\n // second-class experience — including the NeedsAuthorizationError\n // rewrap on a retry that still 401s.\n if (agent.oauth_client_credentials && is401Error(err)) {\n const ccStorage = getAgentStorage(agent);\n const allowPrivateIp = transport?.allowPrivateIp ?? isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.trustedFetchFn,\n signal,\n });\n const retryAuthToken = agent.oauth_tokens?.access_token ?? authToken;\n try {\n return await callA2ATool(\n agent.agent_uri,\n toolName,\n a2aParameters,\n retryAuthToken,\n debugLogs,\n pushNotificationConfig,\n agent.headers,\n signingContext,\n session,\n signal,\n transport?.requestTimeoutMs,\n transport?.trustedFetchFn,\n transport?.allowPrivateIp,\n transport?.legacyCompat\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(\n retryErr,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(\n err,\n agent.agent_uri,\n transport?.trustedFetchFn,\n signal,\n transport?.allowPrivateIp\n );\n throw err;\n }\n } else {\n throw new Error(`Unsupported protocol: ${agent.protocol}`);\n }\n }\n )\n )\n );\n }\n}\n\n/**\n * If `err` looks like a 401 from the MCP transport, probe the agent for a\n * Bearer challenge and throw a {@link NeedsAuthorizationError} carrying\n * walked discovery metadata. If the error isn't a 401 or we can't build a\n * requirements record, return silently so the caller re-throws the original.\n *\n * Keeping this off the hot path: we only probe on error, and the probe is\n * a single unauthenticated `tools/list` POST — no retries, no DNS rebind.\n */\nasync function rethrowAsNeedsAuthorization(\n err: unknown,\n agentUrl: string,\n fetchFn?: typeof fetch,\n signal?: AbortSignal,\n configuredAllowPrivateIp?: boolean\n): Promise<void> {\n if (err instanceof NeedsAuthorizationError) throw err;\n if (!is401Error(err)) return;\n\n // If the caller has already connected to the agent URL, they've implicitly\n // trusted it — inherit that trust for the discovery probe so loopback /\n // private-IP development agents work the same way as public ones.\n const allowPrivateIp = configuredAllowPrivateIp ?? isLikelyPrivateUrl(agentUrl);\n\n // discoverAuthorizationRequirements internally catches network failures and\n // returns null rather than throwing — anything that escapes is a genuine\n // bug we want to surface rather than mask the 401 with.\n const requirements = await discoverAuthorizationRequirements(agentUrl, { allowPrivateIp, fetchFn, signal });\n if (requirements) {\n throw new NeedsAuthorizationError(requirements);\n }\n // No requirements walked; let the caller re-throw the original error.\n}\n\n/**\n * Simple factory functions for protocol-specific clients.\n *\n * Both factories accept a `transport` argument that flows through to the\n * size-cap surface so callers reaching the factory exports honor the same\n * `maxResponseBytes` contract as `ProtocolClient.callTool`. Without it,\n * the factories would silently bypass the cap, which the public API\n * (`TransportOptions`) implies they honor.\n */\nexport const createMCPClient = (\n agentUrl: string,\n authToken?: string,\n headers?: Record<string, string>,\n serverVersion?: 'v2' | 'v3',\n adcpVersion?: string,\n transport?: TransportOptions,\n versionEnvelopeMode: VersionEnvelopeMode = 'auto'\n) => {\n transport = normalizeTransportOptions(transport);\n // Validate the pin at factory time so a typo surfaces here rather than at\n // first call. `buildVersionEnvelope` throws via `resolveWireMajor` on bad\n // input — call it once to surface, then close over the envelope.\n const versionEnvelope = buildVersionEnvelopeForMode(versionEnvelopeMode, adcpVersion, serverVersion);\n return {\n callTool: (toolName: string, args: Record<string, unknown>, debugLogs?: DebugLogEntry[]) =>\n withResponseSizeLimit(transport?.maxResponseBytes, () =>\n callMCPToolWithTasks(\n agentUrl,\n toolName,\n applyVersionEnvelope(args, versionEnvelope),\n authToken,\n debugLogs,\n headers,\n {\n ...(transport?.requestTimeoutMs !== undefined && { requestTimeoutMs: transport.requestTimeoutMs }),\n ...(transport?.trustedFetchFn && { fetchFn: transport.trustedFetchFn }),\n ...(transport?.allowPrivateIp !== undefined && { allowPrivateIp: transport.allowPrivateIp }),\n }\n )\n ),\n };\n};\n\nexport const createA2AClient = (\n agentUrl: string,\n authToken?: string,\n headers?: Record<string, string>,\n serverVersion?: 'v2' | 'v3',\n adcpVersion?: string,\n transport?: TransportOptions,\n versionEnvelopeMode: VersionEnvelopeMode = 'auto'\n) => {\n transport = normalizeTransportOptions(transport);\n const versionEnvelope = buildVersionEnvelopeForMode(versionEnvelopeMode, adcpVersion, serverVersion);\n return {\n callTool: (toolName: string, parameters: Record<string, unknown>, debugLogs?: DebugLogEntry[]) =>\n withResponseSizeLimit(transport?.maxResponseBytes, () =>\n callA2ATool(\n agentUrl,\n toolName,\n applyVersionEnvelope(parameters, versionEnvelope),\n authToken,\n debugLogs,\n undefined,\n headers,\n undefined,\n undefined,\n undefined,\n transport?.requestTimeoutMs,\n transport?.trustedFetchFn,\n transport?.allowPrivateIp,\n transport?.legacyCompat\n )\n ),\n };\n};\n\nexport type { A2ALegacyCompatOptions } from './a2a';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAOO;AAEP,IAAAA,cAAoC;AACpC,uBAAuE;AACvE,iBAAoC;AAyBpC,IAAAC,cAA4B;AAC5B,mBAA2C;AAC3C,uBAQO;AAEP,IAAAC,oBAA4D;AAC5D,IAAAF,cAAqC;AACrC,IAAAC,cAA4B;AAG5B,kBAA6B;AAC7B,mBAKO;AACP,4BAA+C;AAC/C,oBAA2B;AAC3B,iBAAmC;AACnC,wBAAiC;AACjC,qBAAyB;AACzB,qBAAwE;AACxE,IAAAE,iBAAmC;AACnC,2BAAkF;AAClF,oBAAgF;AAChF,+BAAsC;AACtC,kCAGO;AAEP,IAAAC,+BAKO;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L,UAAU,CAAC,UAAkB,MAA+B,kBAC1D;AAAA,MAAsB,WAAW;AAAA,MAAkB,UACjD;AAAA,QACE;AAAA,QACA;AAAA,QACA,qBAAqB,MAAM,eAAe;AAAA,QAC1C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,UACE,GAAI,WAAW,qBAAqB,UAAa,EAAE,kBAAkB,UAAU,iBAAiB;AAAA,UAChG,GAAI,WAAW,kBAAkB,EAAE,SAAS,UAAU,eAAe;AAAA,UACrE,GAAI,WAAW,mBAAmB,UAAa,EAAE,gBAAgB,UAAU,eAAe;AAAA,QAC5F;AAAA,MACF;AAAA,IACF;AAAA,EACJ;AACF;AAEO,MAAM,kBAAkB,CAC7B,UACA,WACA,SACA,eACA,aACA,WACA,sBAA2C,WACxC;AACH,cAAY,0BAA0B,SAAS;AAC/C,QAAM,kBAAkB,4BAA4B,qBAAqB,aAAa,aAAa;AACnG,SAAO;AAAA,IACL,UAAU,CAAC,UAAkB,YAAqC,kBAChE;AAAA,MAAsB,WAAW;AAAA,MAAkB,UACjD;AAAA,QACE;AAAA,QACA;AAAA,QACA,qBAAqB,YAAY,eAAe;AAAA,QAChD;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW;AAAA,QACX,WAAW;AAAA,QACX,WAAW;AAAA,QACX,WAAW;AAAA,MACb;AAAA,IACF;AAAA,EACJ;AACF;","names":["import_mcp","import_a2a","import_mcp_tasks","import_errors","import_transportDiagnostics"]}
@@ -218,11 +218,14 @@ class ProtocolClient {
218
218
  );
219
219
  }
220
220
  const argsWithVersion = applyVersionEnvelope(args, versionEnvelope);
221
- const pushNotificationConfig = (() => {
221
+ const generatedPushNotificationConfig = (() => {
222
222
  if (!webhookUrl) return void 0;
223
223
  if (webhookSecret) {
224
224
  return {
225
225
  url: webhookUrl,
226
+ ...transportActivityContext?.operationId && {
227
+ operation_id: transportActivityContext.operationId
228
+ },
226
229
  ...webhookToken && { token: webhookToken },
227
230
  authentication: {
228
231
  schemes: ["HMAC-SHA256"],
@@ -236,9 +239,14 @@ class ProtocolClient {
236
239
  }
237
240
  return {
238
241
  url: webhookUrl,
242
+ ...transportActivityContext?.operationId && {
243
+ operation_id: transportActivityContext.operationId
244
+ },
239
245
  ...webhookToken && { token: webhookToken }
240
246
  };
241
247
  })();
248
+ const explicitNativePushNotificationConfig = transport?.legacyCompat?.enabled === false && argsWithVersion.push_notification_config !== null && typeof argsWithVersion.push_notification_config === "object" && !Array.isArray(argsWithVersion.push_notification_config) ? argsWithVersion.push_notification_config : void 0;
249
+ const pushNotificationConfig = generatedPushNotificationConfig ?? explicitNativePushNotificationConfig;
242
250
  if (agent.protocol === "mcp") {
243
251
  const argsWithWebhook = pushNotificationConfig ? { ...argsWithVersion, push_notification_config: pushNotificationConfig } : argsWithVersion;
244
252
  if (agent.oauth_tokens && !agent.oauth_client_credentials) {
@@ -343,11 +351,12 @@ class ProtocolClient {
343
351
  throw err;
344
352
  }
345
353
  } else if (agent.protocol === "a2a") {
354
+ const a2aParameters = transport?.legacyCompat?.enabled === false && pushNotificationConfig ? { ...argsWithVersion, push_notification_config: pushNotificationConfig } : argsWithVersion;
346
355
  try {
347
356
  return await callA2ATool2(
348
357
  agent.agent_uri,
349
358
  toolName,
350
- argsWithVersion,
359
+ a2aParameters,
351
360
  authToken,
352
361
  debugLogs,
353
362
  pushNotificationConfig,
@@ -357,7 +366,8 @@ class ProtocolClient {
357
366
  signal,
358
367
  transport?.requestTimeoutMs,
359
368
  transport?.trustedFetchFn,
360
- transport?.allowPrivateIp
369
+ transport?.allowPrivateIp,
370
+ transport?.legacyCompat
361
371
  );
362
372
  } catch (err) {
363
373
  if (agent.oauth_client_credentials && is401Error(err)) {
@@ -375,7 +385,7 @@ class ProtocolClient {
375
385
  return await callA2ATool2(
376
386
  agent.agent_uri,
377
387
  toolName,
378
- argsWithVersion,
388
+ a2aParameters,
379
389
  retryAuthToken,
380
390
  debugLogs,
381
391
  pushNotificationConfig,
@@ -385,7 +395,8 @@ class ProtocolClient {
385
395
  signal,
386
396
  transport?.requestTimeoutMs,
387
397
  transport?.trustedFetchFn,
388
- transport?.allowPrivateIp
398
+ transport?.allowPrivateIp,
399
+ transport?.legacyCompat
389
400
  );
390
401
  } catch (retryErr) {
391
402
  await rethrowAsNeedsAuthorization(
@@ -466,7 +477,8 @@ const createA2AClient = (agentUrl, authToken, headers, serverVersion, adcpVersio
466
477
  void 0,
467
478
  transport?.requestTimeoutMs,
468
479
  transport?.trustedFetchFn,
469
- transport?.allowPrivateIp
480
+ transport?.allowPrivateIp,
481
+ transport?.legacyCompat
470
482
  )
471
483
  )
472
484
  };