@adcp/sdk 12.1.1 → 13.0.0-rc.0

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 (410) hide show
  1. package/README.md +19 -3
  2. package/bin/adcp-fuzz.js +3 -1
  3. package/dist/lib/adapters/content-standards-adapter.d.mts +9 -9
  4. package/dist/lib/adapters/content-standards-adapter.d.ts +9 -9
  5. package/dist/lib/adapters/content-standards-adapter.d.ts.map +1 -1
  6. package/dist/lib/adapters/content-standards-adapter.js +22 -22
  7. package/dist/lib/adapters/content-standards-adapter.js.map +1 -1
  8. package/dist/lib/adapters/content-standards-adapter.mjs +18 -18
  9. package/dist/lib/adapters/content-standards-adapter.mjs.map +1 -1
  10. package/dist/lib/adapters/index.d.mts +2 -2
  11. package/dist/lib/adapters/index.d.ts +2 -2
  12. package/dist/lib/adapters/index.d.ts.map +1 -1
  13. package/dist/lib/adapters/index.js +10 -10
  14. package/dist/lib/adapters/index.js.map +1 -1
  15. package/dist/lib/adapters/index.mjs +9 -9
  16. package/dist/lib/adapters/index.mjs.map +1 -1
  17. package/dist/lib/auth/oauth/provider-cache.d.mts +7 -0
  18. package/dist/lib/auth/oauth/provider-cache.d.ts +8 -0
  19. package/dist/lib/auth/oauth/provider-cache.d.ts.map +1 -0
  20. package/dist/lib/auth/oauth/provider-cache.js +44 -0
  21. package/dist/lib/auth/oauth/provider-cache.js.map +1 -0
  22. package/dist/lib/auth/oauth/provider-cache.mjs +19 -0
  23. package/dist/lib/auth/oauth/provider-cache.mjs.map +1 -0
  24. package/dist/lib/conformance/invariants/uniformError.js +1 -1
  25. package/dist/lib/conformance/invariants/uniformError.js.map +1 -1
  26. package/dist/lib/conformance/invariants/uniformError.mjs +1 -1
  27. package/dist/lib/conformance/invariants/uniformError.mjs.map +1 -1
  28. package/dist/lib/conformance/runners.js +1 -1
  29. package/dist/lib/conformance/runners.js.map +1 -1
  30. package/dist/lib/conformance/runners.mjs +1 -1
  31. package/dist/lib/conformance/runners.mjs.map +1 -1
  32. package/dist/lib/conformance/seeder.js +5 -5
  33. package/dist/lib/conformance/seeder.js.map +1 -1
  34. package/dist/lib/conformance/seeder.mjs +5 -5
  35. package/dist/lib/conformance/seeder.mjs.map +1 -1
  36. package/dist/lib/core/ADCPMultiAgentClient.d.mts +26 -29
  37. package/dist/lib/core/ADCPMultiAgentClient.d.ts +26 -29
  38. package/dist/lib/core/ADCPMultiAgentClient.d.ts.map +1 -1
  39. package/dist/lib/core/ADCPMultiAgentClient.js +27 -19
  40. package/dist/lib/core/ADCPMultiAgentClient.js.map +1 -1
  41. package/dist/lib/core/ADCPMultiAgentClient.mjs +27 -19
  42. package/dist/lib/core/ADCPMultiAgentClient.mjs.map +1 -1
  43. package/dist/lib/core/AgentClient.d.mts +148 -138
  44. package/dist/lib/core/AgentClient.d.ts +148 -138
  45. package/dist/lib/core/AgentClient.d.ts.map +1 -1
  46. package/dist/lib/core/AgentClient.js +174 -85
  47. package/dist/lib/core/AgentClient.js.map +1 -1
  48. package/dist/lib/core/AgentClient.mjs +174 -85
  49. package/dist/lib/core/AgentClient.mjs.map +1 -1
  50. package/dist/lib/core/AsyncHandler.d.mts +18 -16
  51. package/dist/lib/core/AsyncHandler.d.ts +18 -16
  52. package/dist/lib/core/AsyncHandler.d.ts.map +1 -1
  53. package/dist/lib/core/AsyncHandler.js +22 -1
  54. package/dist/lib/core/AsyncHandler.js.map +1 -1
  55. package/dist/lib/core/AsyncHandler.mjs +22 -1
  56. package/dist/lib/core/AsyncHandler.mjs.map +1 -1
  57. package/dist/lib/core/ConversationTypes.d.mts +6 -2
  58. package/dist/lib/core/ConversationTypes.d.ts +6 -2
  59. package/dist/lib/core/ConversationTypes.d.ts.map +1 -1
  60. package/dist/lib/core/ConversationTypes.js.map +1 -1
  61. package/dist/lib/core/CreativeAgentClient.d.mts +41 -17
  62. package/dist/lib/core/CreativeAgentClient.d.ts +41 -17
  63. package/dist/lib/core/CreativeAgentClient.d.ts.map +1 -1
  64. package/dist/lib/core/CreativeAgentClient.js +39 -12
  65. package/dist/lib/core/CreativeAgentClient.js.map +1 -1
  66. package/dist/lib/core/CreativeAgentClient.mjs +39 -12
  67. package/dist/lib/core/CreativeAgentClient.mjs.map +1 -1
  68. package/dist/lib/core/SingleAgentClient.d.mts +127 -50
  69. package/dist/lib/core/SingleAgentClient.d.ts +127 -50
  70. package/dist/lib/core/SingleAgentClient.d.ts.map +1 -1
  71. package/dist/lib/core/SingleAgentClient.js +1617 -177
  72. package/dist/lib/core/SingleAgentClient.js.map +1 -1
  73. package/dist/lib/core/SingleAgentClient.mjs +1627 -177
  74. package/dist/lib/core/SingleAgentClient.mjs.map +1 -1
  75. package/dist/lib/core/TaskExecutor.d.mts +9 -0
  76. package/dist/lib/core/TaskExecutor.d.ts +9 -0
  77. package/dist/lib/core/TaskExecutor.d.ts.map +1 -1
  78. package/dist/lib/core/TaskExecutor.js +136 -43
  79. package/dist/lib/core/TaskExecutor.js.map +1 -1
  80. package/dist/lib/core/TaskExecutor.mjs +136 -43
  81. package/dist/lib/core/TaskExecutor.mjs.map +1 -1
  82. package/dist/lib/index.d.mts +111 -17
  83. package/dist/lib/index.d.ts +111 -17
  84. package/dist/lib/index.d.ts.map +1 -1
  85. package/dist/lib/index.js +94 -94
  86. package/dist/lib/index.js.map +1 -1
  87. package/dist/lib/index.mjs +93 -94
  88. package/dist/lib/index.mjs.map +1 -1
  89. package/dist/lib/protocols/index.d.ts.map +1 -1
  90. package/dist/lib/protocols/index.js +6 -15
  91. package/dist/lib/protocols/index.js.map +1 -1
  92. package/dist/lib/protocols/index.mjs +6 -16
  93. package/dist/lib/protocols/index.mjs.map +1 -1
  94. package/dist/lib/protocols/mcp-modern.d.ts.map +1 -1
  95. package/dist/lib/protocols/mcp-modern.js +87 -12
  96. package/dist/lib/protocols/mcp-modern.js.map +1 -1
  97. package/dist/lib/protocols/mcp-modern.mjs +89 -12
  98. package/dist/lib/protocols/mcp-modern.mjs.map +1 -1
  99. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  100. package/dist/lib/server/create-adcp-server.d.mts +6 -0
  101. package/dist/lib/server/create-adcp-server.d.ts +6 -0
  102. package/dist/lib/server/create-adcp-server.d.ts.map +1 -1
  103. package/dist/lib/server/create-adcp-server.js +295 -48
  104. package/dist/lib/server/create-adcp-server.js.map +1 -1
  105. package/dist/lib/server/create-adcp-server.mjs +301 -50
  106. package/dist/lib/server/create-adcp-server.mjs.map +1 -1
  107. package/dist/lib/server/decisioning/assembly-helpers.d.mts +27 -13
  108. package/dist/lib/server/decisioning/assembly-helpers.d.ts +27 -13
  109. package/dist/lib/server/decisioning/assembly-helpers.d.ts.map +1 -1
  110. package/dist/lib/server/decisioning/assembly-helpers.js +136 -14
  111. package/dist/lib/server/decisioning/assembly-helpers.js.map +1 -1
  112. package/dist/lib/server/decisioning/assembly-helpers.mjs +134 -13
  113. package/dist/lib/server/decisioning/assembly-helpers.mjs.map +1 -1
  114. package/dist/lib/server/decisioning/index.d.mts +13 -12
  115. package/dist/lib/server/decisioning/index.d.ts +13 -12
  116. package/dist/lib/server/decisioning/index.d.ts.map +1 -1
  117. package/dist/lib/server/decisioning/index.js +6 -0
  118. package/dist/lib/server/decisioning/index.js.map +1 -1
  119. package/dist/lib/server/decisioning/index.mjs +9 -3
  120. package/dist/lib/server/decisioning/index.mjs.map +1 -1
  121. package/dist/lib/server/decisioning/list-helpers.d.mts +13 -3
  122. package/dist/lib/server/decisioning/list-helpers.d.ts +13 -3
  123. package/dist/lib/server/decisioning/list-helpers.d.ts.map +1 -1
  124. package/dist/lib/server/decisioning/list-helpers.js +13 -3
  125. package/dist/lib/server/decisioning/list-helpers.js.map +1 -1
  126. package/dist/lib/server/decisioning/list-helpers.mjs +11 -2
  127. package/dist/lib/server/decisioning/list-helpers.mjs.map +1 -1
  128. package/dist/lib/server/decisioning/manifest-helpers.d.mts +5 -3
  129. package/dist/lib/server/decisioning/manifest-helpers.d.ts +5 -3
  130. package/dist/lib/server/decisioning/manifest-helpers.d.ts.map +1 -1
  131. package/dist/lib/server/decisioning/manifest-helpers.js.map +1 -1
  132. package/dist/lib/server/decisioning/manifest-helpers.mjs.map +1 -1
  133. package/dist/lib/server/decisioning/proposal/dispatch.d.mts +2 -2
  134. package/dist/lib/server/decisioning/proposal/dispatch.d.ts +2 -2
  135. package/dist/lib/server/decisioning/proposal/dispatch.d.ts.map +1 -1
  136. package/dist/lib/server/decisioning/proposal/dispatch.js.map +1 -1
  137. package/dist/lib/server/decisioning/proposal/dispatch.mjs.map +1 -1
  138. package/dist/lib/server/decisioning/proposal/index.d.mts +1 -1
  139. package/dist/lib/server/decisioning/proposal/index.d.ts +1 -1
  140. package/dist/lib/server/decisioning/proposal/index.d.ts.map +1 -1
  141. package/dist/lib/server/decisioning/proposal/index.js.map +1 -1
  142. package/dist/lib/server/decisioning/proposal/index.mjs.map +1 -1
  143. package/dist/lib/server/decisioning/proposal/lifecycle.d.mts +3 -2
  144. package/dist/lib/server/decisioning/proposal/lifecycle.d.ts +3 -2
  145. package/dist/lib/server/decisioning/proposal/lifecycle.d.ts.map +1 -1
  146. package/dist/lib/server/decisioning/proposal/lifecycle.js.map +1 -1
  147. package/dist/lib/server/decisioning/proposal/lifecycle.mjs.map +1 -1
  148. package/dist/lib/server/decisioning/proposal/mock-manager.d.mts +3 -3
  149. package/dist/lib/server/decisioning/proposal/mock-manager.d.ts +3 -3
  150. package/dist/lib/server/decisioning/proposal/mock-manager.d.ts.map +1 -1
  151. package/dist/lib/server/decisioning/proposal/mock-manager.js.map +1 -1
  152. package/dist/lib/server/decisioning/proposal/mock-manager.mjs.map +1 -1
  153. package/dist/lib/server/decisioning/proposal/types.d.mts +10 -6
  154. package/dist/lib/server/decisioning/proposal/types.d.ts +10 -6
  155. package/dist/lib/server/decisioning/proposal/types.d.ts.map +1 -1
  156. package/dist/lib/server/decisioning/proposal/types.js.map +1 -1
  157. package/dist/lib/server/decisioning/proposal/types.mjs.map +1 -1
  158. package/dist/lib/server/decisioning/runtime/from-platform.d.mts +21 -2
  159. package/dist/lib/server/decisioning/runtime/from-platform.d.ts +21 -2
  160. package/dist/lib/server/decisioning/runtime/from-platform.d.ts.map +1 -1
  161. package/dist/lib/server/decisioning/runtime/from-platform.js +754 -81
  162. package/dist/lib/server/decisioning/runtime/from-platform.js.map +1 -1
  163. package/dist/lib/server/decisioning/runtime/from-platform.mjs +763 -81
  164. package/dist/lib/server/decisioning/runtime/from-platform.mjs.map +1 -1
  165. package/dist/lib/server/decisioning/specialisms/brand-rights.d.mts +9 -9
  166. package/dist/lib/server/decisioning/specialisms/brand-rights.d.ts +9 -9
  167. package/dist/lib/server/decisioning/specialisms/brand-rights.d.ts.map +1 -1
  168. package/dist/lib/server/decisioning/specialisms/brand-rights.js.map +1 -1
  169. package/dist/lib/server/decisioning/specialisms/content-standards.d.mts +16 -16
  170. package/dist/lib/server/decisioning/specialisms/content-standards.d.ts +16 -16
  171. package/dist/lib/server/decisioning/specialisms/content-standards.d.ts.map +1 -1
  172. package/dist/lib/server/decisioning/specialisms/content-standards.js.map +1 -1
  173. package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.mts +15 -13
  174. package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.ts +15 -13
  175. package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.ts.map +1 -1
  176. package/dist/lib/server/decisioning/specialisms/creative-ad-server.js.map +1 -1
  177. package/dist/lib/server/decisioning/specialisms/creative.d.mts +12 -11
  178. package/dist/lib/server/decisioning/specialisms/creative.d.ts +12 -11
  179. package/dist/lib/server/decisioning/specialisms/creative.d.ts.map +1 -1
  180. package/dist/lib/server/decisioning/specialisms/creative.js.map +1 -1
  181. package/dist/lib/server/decisioning/specialisms/sales.d.mts +25 -15
  182. package/dist/lib/server/decisioning/specialisms/sales.d.ts +25 -15
  183. package/dist/lib/server/decisioning/specialisms/sales.d.ts.map +1 -1
  184. package/dist/lib/server/decisioning/specialisms/sales.js.map +1 -1
  185. package/dist/lib/server/index.d.mts +3 -3
  186. package/dist/lib/server/index.d.ts +3 -3
  187. package/dist/lib/server/index.d.ts.map +1 -1
  188. package/dist/lib/server/index.js +72 -72
  189. package/dist/lib/server/index.js.map +1 -1
  190. package/dist/lib/server/index.mjs +36 -36
  191. package/dist/lib/server/index.mjs.map +1 -1
  192. package/dist/lib/server/legacy/v5/index.d.mts +1 -0
  193. package/dist/lib/server/legacy/v5/index.d.ts +1 -0
  194. package/dist/lib/server/legacy/v5/index.d.ts.map +1 -1
  195. package/dist/lib/server/legacy/v5/index.js +74 -1
  196. package/dist/lib/server/legacy/v5/index.js.map +1 -1
  197. package/dist/lib/server/legacy/v5/index.mjs +75 -1
  198. package/dist/lib/server/legacy/v5/index.mjs.map +1 -1
  199. package/dist/lib/server/responses.d.mts +2 -2
  200. package/dist/lib/server/responses.d.ts +2 -2
  201. package/dist/lib/server/responses.js.map +1 -1
  202. package/dist/lib/server/responses.mjs.map +1 -1
  203. package/dist/lib/testing/client.js +1 -1
  204. package/dist/lib/testing/client.js.map +1 -1
  205. package/dist/lib/testing/client.mjs +1 -1
  206. package/dist/lib/testing/client.mjs.map +1 -1
  207. package/dist/lib/testing/scenarios/brand-rights.js +6 -6
  208. package/dist/lib/testing/scenarios/brand-rights.js.map +1 -1
  209. package/dist/lib/testing/scenarios/brand-rights.mjs +6 -6
  210. package/dist/lib/testing/scenarios/brand-rights.mjs.map +1 -1
  211. package/dist/lib/testing/scenarios/creative.js +7 -7
  212. package/dist/lib/testing/scenarios/creative.js.map +1 -1
  213. package/dist/lib/testing/scenarios/creative.mjs +7 -7
  214. package/dist/lib/testing/scenarios/creative.mjs.map +1 -1
  215. package/dist/lib/testing/scenarios/discovery.js +2 -2
  216. package/dist/lib/testing/scenarios/discovery.js.map +1 -1
  217. package/dist/lib/testing/scenarios/discovery.mjs +2 -2
  218. package/dist/lib/testing/scenarios/discovery.mjs.map +1 -1
  219. package/dist/lib/testing/scenarios/edge-cases.js +11 -11
  220. package/dist/lib/testing/scenarios/edge-cases.js.map +1 -1
  221. package/dist/lib/testing/scenarios/edge-cases.mjs +11 -11
  222. package/dist/lib/testing/scenarios/edge-cases.mjs.map +1 -1
  223. package/dist/lib/testing/scenarios/governance.d.ts.map +1 -1
  224. package/dist/lib/testing/scenarios/governance.js +16 -22
  225. package/dist/lib/testing/scenarios/governance.js.map +1 -1
  226. package/dist/lib/testing/scenarios/governance.mjs +16 -22
  227. package/dist/lib/testing/scenarios/governance.mjs.map +1 -1
  228. package/dist/lib/testing/scenarios/media-buy.js +5 -5
  229. package/dist/lib/testing/scenarios/media-buy.js.map +1 -1
  230. package/dist/lib/testing/scenarios/media-buy.mjs +5 -5
  231. package/dist/lib/testing/scenarios/media-buy.mjs.map +1 -1
  232. package/dist/lib/testing/scenarios/schema-compliance.js +1 -1
  233. package/dist/lib/testing/scenarios/schema-compliance.js.map +1 -1
  234. package/dist/lib/testing/scenarios/schema-compliance.mjs +1 -1
  235. package/dist/lib/testing/scenarios/schema-compliance.mjs.map +1 -1
  236. package/dist/lib/testing/scenarios/trusted-match.d.ts.map +1 -1
  237. package/dist/lib/testing/scenarios/trusted-match.js +4 -3
  238. package/dist/lib/testing/scenarios/trusted-match.js.map +1 -1
  239. package/dist/lib/testing/scenarios/trusted-match.mjs +4 -3
  240. package/dist/lib/testing/scenarios/trusted-match.mjs.map +1 -1
  241. package/dist/lib/testing/storyboard/shape-drift-hints.d.mts +3 -4
  242. package/dist/lib/testing/storyboard/shape-drift-hints.d.ts +3 -4
  243. package/dist/lib/testing/storyboard/shape-drift-hints.d.ts.map +1 -1
  244. package/dist/lib/testing/storyboard/shape-drift-hints.js +27 -27
  245. package/dist/lib/testing/storyboard/shape-drift-hints.js.map +1 -1
  246. package/dist/lib/testing/storyboard/shape-drift-hints.mjs +27 -27
  247. package/dist/lib/testing/storyboard/shape-drift-hints.mjs.map +1 -1
  248. package/dist/lib/testing/storyboard/task-map.d.ts.map +1 -1
  249. package/dist/lib/testing/storyboard/task-map.js +43 -5
  250. package/dist/lib/testing/storyboard/task-map.js.map +1 -1
  251. package/dist/lib/testing/storyboard/task-map.mjs +43 -5
  252. package/dist/lib/testing/storyboard/task-map.mjs.map +1 -1
  253. package/dist/lib/testing/test-helpers.d.mts +2 -2
  254. package/dist/lib/testing/test-helpers.d.ts +2 -2
  255. package/dist/lib/testing/test-helpers.js.map +1 -1
  256. package/dist/lib/testing/test-helpers.mjs.map +1 -1
  257. package/dist/lib/types/adcp.d.mts +14 -14
  258. package/dist/lib/types/adcp.d.ts +14 -14
  259. package/dist/lib/types/adcp.d.ts.map +1 -1
  260. package/dist/lib/types/adcp.js.map +1 -1
  261. package/dist/lib/types/adcp.mjs.map +1 -1
  262. package/dist/lib/types/index.d.mts +2 -2
  263. package/dist/lib/types/index.d.ts +2 -2
  264. package/dist/lib/types/index.d.ts.map +1 -1
  265. package/dist/lib/types/index.js.map +1 -1
  266. package/dist/lib/types/index.mjs.map +1 -1
  267. package/dist/lib/utils/capabilities.d.mts +6 -0
  268. package/dist/lib/utils/capabilities.d.ts +6 -0
  269. package/dist/lib/utils/capabilities.d.ts.map +1 -1
  270. package/dist/lib/utils/capabilities.js +4 -0
  271. package/dist/lib/utils/capabilities.js.map +1 -1
  272. package/dist/lib/utils/capabilities.mjs +4 -0
  273. package/dist/lib/utils/capabilities.mjs.map +1 -1
  274. package/dist/lib/utils/creative-delivery.d.mts +52 -10
  275. package/dist/lib/utils/creative-delivery.d.ts +52 -10
  276. package/dist/lib/utils/creative-delivery.d.ts.map +1 -1
  277. package/dist/lib/utils/creative-delivery.js +104 -9
  278. package/dist/lib/utils/creative-delivery.js.map +1 -1
  279. package/dist/lib/utils/creative-delivery.mjs +104 -8
  280. package/dist/lib/utils/creative-delivery.mjs.map +1 -1
  281. package/dist/lib/utils/format-assets.d.mts +41 -38
  282. package/dist/lib/utils/format-assets.d.ts +41 -38
  283. package/dist/lib/utils/format-assets.d.ts.map +1 -1
  284. package/dist/lib/utils/format-assets.js +3 -1
  285. package/dist/lib/utils/format-assets.js.map +1 -1
  286. package/dist/lib/utils/format-assets.mjs +3 -1
  287. package/dist/lib/utils/format-assets.mjs.map +1 -1
  288. package/dist/lib/utils/index.d.mts +8 -8
  289. package/dist/lib/utils/index.d.ts +8 -8
  290. package/dist/lib/utils/index.d.ts.map +1 -1
  291. package/dist/lib/utils/index.js +11 -9
  292. package/dist/lib/utils/index.js.map +1 -1
  293. package/dist/lib/utils/index.mjs +9 -8
  294. package/dist/lib/utils/index.mjs.map +1 -1
  295. package/dist/lib/utils/preview-utils.d.mts +11 -8
  296. package/dist/lib/utils/preview-utils.d.ts +11 -8
  297. package/dist/lib/utils/preview-utils.d.ts.map +1 -1
  298. package/dist/lib/utils/preview-utils.js +4 -4
  299. package/dist/lib/utils/preview-utils.js.map +1 -1
  300. package/dist/lib/utils/preview-utils.mjs +3 -3
  301. package/dist/lib/utils/preview-utils.mjs.map +1 -1
  302. package/dist/lib/utils/tool-request-schemas.d.mts +2 -2
  303. package/dist/lib/utils/tool-request-schemas.d.ts +2 -2
  304. package/dist/lib/v2/projection/aao-reference-formats.json +492 -0
  305. package/dist/lib/v2/projection/augment-response.d.mts +31 -11
  306. package/dist/lib/v2/projection/augment-response.d.ts +31 -11
  307. package/dist/lib/v2/projection/augment-response.d.ts.map +1 -1
  308. package/dist/lib/v2/projection/augment-response.js +233 -27
  309. package/dist/lib/v2/projection/augment-response.js.map +1 -1
  310. package/dist/lib/v2/projection/augment-response.mjs +232 -27
  311. package/dist/lib/v2/projection/augment-response.mjs.map +1 -1
  312. package/dist/lib/v2/projection/builders.d.mts +7 -6
  313. package/dist/lib/v2/projection/builders.d.ts +7 -6
  314. package/dist/lib/v2/projection/builders.d.ts.map +1 -1
  315. package/dist/lib/v2/projection/builders.js +11 -8
  316. package/dist/lib/v2/projection/builders.js.map +1 -1
  317. package/dist/lib/v2/projection/builders.mjs +9 -6
  318. package/dist/lib/v2/projection/builders.mjs.map +1 -1
  319. package/dist/lib/v2/projection/catalog-snapshot.d.mts +47 -0
  320. package/dist/lib/v2/projection/catalog-snapshot.d.ts +48 -0
  321. package/dist/lib/v2/projection/catalog-snapshot.d.ts.map +1 -0
  322. package/dist/lib/v2/projection/catalog-snapshot.js +291 -0
  323. package/dist/lib/v2/projection/catalog-snapshot.js.map +1 -0
  324. package/dist/lib/v2/projection/catalog-snapshot.mjs +265 -0
  325. package/dist/lib/v2/projection/catalog-snapshot.mjs.map +1 -0
  326. package/dist/lib/v2/projection/catalog.d.mts +23 -2
  327. package/dist/lib/v2/projection/catalog.d.ts +23 -2
  328. package/dist/lib/v2/projection/catalog.d.ts.map +1 -1
  329. package/dist/lib/v2/projection/catalog.js +34 -10
  330. package/dist/lib/v2/projection/catalog.js.map +1 -1
  331. package/dist/lib/v2/projection/catalog.mjs +33 -10
  332. package/dist/lib/v2/projection/catalog.mjs.map +1 -1
  333. package/dist/lib/v2/projection/creative-delivery.d.mts +157 -0
  334. package/dist/lib/v2/projection/creative-delivery.d.ts +158 -0
  335. package/dist/lib/v2/projection/creative-delivery.d.ts.map +1 -0
  336. package/dist/lib/v2/projection/creative-delivery.js +967 -0
  337. package/dist/lib/v2/projection/creative-delivery.js.map +1 -0
  338. package/dist/lib/v2/projection/creative-delivery.mjs +941 -0
  339. package/dist/lib/v2/projection/creative-delivery.mjs.map +1 -0
  340. package/dist/lib/v2/projection/index.d.mts +8 -6
  341. package/dist/lib/v2/projection/index.d.ts +8 -6
  342. package/dist/lib/v2/projection/index.d.ts.map +1 -1
  343. package/dist/lib/v2/projection/index.js +26 -4
  344. package/dist/lib/v2/projection/index.js.map +1 -1
  345. package/dist/lib/v2/projection/index.mjs +28 -4
  346. package/dist/lib/v2/projection/index.mjs.map +1 -1
  347. package/dist/lib/v2/projection/legacy-metadata.d.mts +21 -0
  348. package/dist/lib/v2/projection/legacy-metadata.d.ts +22 -0
  349. package/dist/lib/v2/projection/legacy-metadata.d.ts.map +1 -0
  350. package/dist/lib/v2/projection/legacy-metadata.js +73 -0
  351. package/dist/lib/v2/projection/legacy-metadata.js.map +1 -0
  352. package/dist/lib/v2/projection/legacy-metadata.mjs +45 -0
  353. package/dist/lib/v2/projection/legacy-metadata.mjs.map +1 -0
  354. package/dist/lib/v2/projection/types.d.mts +29 -23
  355. package/dist/lib/v2/projection/types.d.ts +29 -23
  356. package/dist/lib/v2/projection/types.d.ts.map +1 -1
  357. package/dist/lib/v2/projection/types.js.map +1 -1
  358. package/dist/lib/v2/projection/v1-to-v2.d.mts +29 -6
  359. package/dist/lib/v2/projection/v1-to-v2.d.ts +29 -6
  360. package/dist/lib/v2/projection/v1-to-v2.d.ts.map +1 -1
  361. package/dist/lib/v2/projection/v1-to-v2.js +218 -9
  362. package/dist/lib/v2/projection/v1-to-v2.js.map +1 -1
  363. package/dist/lib/v2/projection/v1-to-v2.mjs +219 -10
  364. package/dist/lib/v2/projection/v1-to-v2.mjs.map +1 -1
  365. package/dist/lib/v2/projection/v2-to-v1.d.mts +31 -2
  366. package/dist/lib/v2/projection/v2-to-v1.d.ts +31 -2
  367. package/dist/lib/v2/projection/v2-to-v1.d.ts.map +1 -1
  368. package/dist/lib/v2/projection/v2-to-v1.js +138 -7
  369. package/dist/lib/v2/projection/v2-to-v1.js.map +1 -1
  370. package/dist/lib/v2/projection/v2-to-v1.mjs +135 -6
  371. package/dist/lib/v2/projection/v2-to-v1.mjs.map +1 -1
  372. package/dist/lib/v2/projection/write-side.d.mts +12 -13
  373. package/dist/lib/v2/projection/write-side.d.ts +12 -13
  374. package/dist/lib/v2/projection/write-side.d.ts.map +1 -1
  375. package/dist/lib/v2/projection/write-side.js +16 -12
  376. package/dist/lib/v2/projection/write-side.js.map +1 -1
  377. package/dist/lib/v2/projection/write-side.mjs +16 -12
  378. package/dist/lib/v2/projection/write-side.mjs.map +1 -1
  379. package/dist/lib/version.d.mts +3 -3
  380. package/dist/lib/version.d.ts +3 -3
  381. package/dist/lib/version.d.ts.map +1 -1
  382. package/dist/lib/version.js +3 -3
  383. package/dist/lib/version.js.map +1 -1
  384. package/dist/lib/version.mjs +3 -3
  385. package/dist/lib/version.mjs.map +1 -1
  386. package/docs/guides/BUILD-AN-AGENT.md +7 -2
  387. package/docs/guides/PREVIEW-ASSET-DURABILITY.md +6 -2
  388. package/docs/llms.txt +1 -0
  389. package/examples/README.md +1 -1
  390. package/examples/batch-preview-test.ts +3 -3
  391. package/examples/conversation-client.ts +2 -2
  392. package/examples/debug-preview-response.ts +1 -1
  393. package/examples/decisioning-platform-broadcast-tv.ts +10 -4
  394. package/examples/decisioning-platform-mock-seller.ts +16 -9
  395. package/examples/decisioning-platform-programmatic.ts +18 -7
  396. package/examples/error-compliant-server.ts +26 -16
  397. package/examples/generative-creative-demo.ts +7 -19
  398. package/examples/hello_creative_adapter_ad_server.ts +37 -16
  399. package/examples/hello_creative_adapter_template.ts +12 -10
  400. package/examples/hello_seller_adapter_guaranteed.ts +52 -23
  401. package/examples/hello_seller_adapter_multi_tenant.ts +6 -3
  402. package/examples/hello_seller_adapter_non_guaranteed.ts +54 -26
  403. package/examples/hello_seller_adapter_proposal_mode.ts +40 -14
  404. package/examples/hello_seller_adapter_social.ts +2 -7
  405. package/examples/inspect-card-formats.ts +1 -1
  406. package/examples/simple-getting-started.ts +1 -1
  407. package/examples/test-helpers-demo.ts +1 -1
  408. package/package.json +2 -2
  409. package/skills/build-decisioning-creative-template/SKILL.md +11 -11
  410. package/skills/build-decisioning-platform/advanced/REFERENCE.md +8 -2
@@ -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 { 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}\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 createNonInteractiveOAuthProvider,\n discoverAuthorizationRequirements,\n NeedsAuthorizationError,\n getAgentStorage,\n ensureClientCredentialsTokens,\n} from '../auth/oauth';\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\nconst nonInteractiveOAuthProviderCache = new WeakMap<\n AgentConfig,\n ReturnType<typeof createNonInteractiveOAuthProvider>\n>();\n\nfunction getNonInteractiveOAuthProvider(agent: AgentConfig): ReturnType<typeof createNonInteractiveOAuthProvider> {\n let provider = nonInteractiveOAuthProviderCache.get(agent);\n if (!provider) {\n const storage = getAgentStorage(agent);\n provider = createNonInteractiveOAuthProvider(agent, {\n agentHint: agent.id,\n storage,\n allowHttp: isLikelyPrivateUrl(agent.agent_uri),\n });\n nonInteractiveOAuthProviderCache.set(agent, provider);\n }\n return provider;\n}\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\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 `fetchFn`\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 * For SSRF-sensitive metadata probes, supplying this function makes it the\n * trusted network boundary: the SDK still validates schemes and resolved\n * addresses, but a custom fetch API cannot accept the SDK's pinned undici\n * dispatcher. The implementation must therefore prevent DNS rebinding (for\n * example with an egress proxy or its own DNS pinning).\n */\n fetchFn?: typeof fetch;\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\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,\n signal,\n onTransportActivity,\n transportActivityContext,\n } = options;\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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 const pushNotificationConfig: PushNotificationConfig | undefined = webhookUrl\n ? {\n url: webhookUrl,\n ...(webhookToken && { token: webhookToken }),\n authentication: {\n schemes: ['HMAC-SHA256'],\n credentials: webhookSecret || 'placeholder_secret_min_32_characters_required',\n },\n }\n : undefined;\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 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?.fetchFn,\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(err, agent.agent_uri, transport?.fetchFn);\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?.fetchFn && { fetchFn: transport.fetchFn }),\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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?.fetchFn && { fetchFn: transport.fetchFn }),\n }\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(retryErr, agent.agent_uri, transport?.fetchFn);\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(err, agent.agent_uri, transport?.fetchFn);\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?.fetchFn\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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?.fetchFn\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(retryErr, agent.agent_uri, transport?.fetchFn);\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(err, agent.agent_uri, transport?.fetchFn);\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(err: unknown, agentUrl: string, fetchFn?: typeof fetch): 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 = 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 });\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 // 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?.fetchFn && { fetchFn: transport.fetchFn }),\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 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?.fetchFn\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;AACA,iBAOO;AAEP,IAAAA,cAAoC;AACpC,iBAAoC;AAcpC,IAAAC,cAA4B;AAC5B,mBAA2C;AAC3C,uBAQO;AAEP,IAAAC,oBAA4D;AAC5D,IAAAF,cAAqC;AACrC,IAAAC,cAA4B;AAG5B,kBAA6B;AAC7B,mBAMO;AACP,oBAA2B;AAC3B,iBAAmC;AACnC,wBAAiC;AACjC,qBAAyB;AACzB,qBAAwE;AACxE,IAAAE,iBAAmC;AACnC,2BAAkF;AAClF,oBAAgF;AAChF,+BAAsC;AACtC,kCAGO;AAEP,IAAAC,+BAKO;AApDP,eAAsB,iBAAiB,WAA0B,OAAsB;AACrF,MAAI,aAAa,OAAO;AACtB,cAAM,iCAAoB;AAAA,EAC5B,OAAO;AACL,wCAAoB;AAAA,EACtB;AACF;AAmDA,MAAM,mCAAmC,oBAAI,QAG3C;AAEF,SAAS,+BAA+B,OAA0E;AAChH,MAAI,WAAW,iCAAiC,IAAI,KAAK;AACzD,MAAI,CAAC,UAAU;AACb,UAAM,cAAU,8BAAgB,KAAK;AACrC,mBAAW,gDAAkC,OAAO;AAAA,MAClD,WAAW,MAAM;AAAA,MACjB;AAAA,MACA,eAAW,+BAAmB,MAAM,SAAS;AAAA,IAC/C,CAAC;AACD,qCAAiC,IAAI,OAAO,QAAQ;AAAA,EACtD;AACA,S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Ae,UAAM,gDAAkC,UAAU,EAAE,gBAAgB,QAAQ,CAAC;AAClG,MAAI,cAAc;AAChB,UAAM,IAAI,qCAAwB,YAAY;AAAA,EAChD;AAEF;AAWO,MAAM,kBAAkB,CAC7B,UACA,WACA,SACA,eACA,aACA,WACA,sBAA2C,WACxC;AAIH,QAAM,kBAAkB,4BAA4B,qBAAqB,aAAa,aAAa;AACnG,SAAO;AAAA,IACL,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,WAAW,EAAE,SAAS,UAAU,QAAQ;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACJ;AACF;AAEO,MAAM,kBAAkB,CAC7B,UACA,WACA,SACA,eACA,aACA,WACA,sBAA2C,WACxC;AACH,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,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 { 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}\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\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 `fetchFn`\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 * For SSRF-sensitive metadata probes, supplying this function makes it the\n * trusted network boundary: the SDK still validates schemes and resolved\n * addresses, but a custom fetch API cannot accept the SDK's pinned undici\n * dispatcher. The implementation must therefore prevent DNS rebinding (for\n * example with an egress proxy or its own DNS pinning).\n */\n fetchFn?: typeof fetch;\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\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,\n signal,\n onTransportActivity,\n transportActivityContext,\n } = options;\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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 const pushNotificationConfig: PushNotificationConfig | undefined = webhookUrl\n ? {\n url: webhookUrl,\n ...(webhookToken && { token: webhookToken }),\n authentication: {\n schemes: ['HMAC-SHA256'],\n credentials: webhookSecret || 'placeholder_secret_min_32_characters_required',\n },\n }\n : undefined;\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?.fetchFn,\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(err, agent.agent_uri, transport?.fetchFn);\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?.fetchFn && { fetchFn: transport.fetchFn }),\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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?.fetchFn && { fetchFn: transport.fetchFn }),\n }\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(retryErr, agent.agent_uri, transport?.fetchFn);\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(err, agent.agent_uri, transport?.fetchFn);\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?.fetchFn\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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?.fetchFn\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(retryErr, agent.agent_uri, transport?.fetchFn);\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(err, agent.agent_uri, transport?.fetchFn);\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(err: unknown, agentUrl: string, fetchFn?: typeof fetch): 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 = 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 });\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 // 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?.fetchFn && { fetchFn: transport.fetchFn }),\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 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?.fetchFn\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;AACA,iBAOO;AAEP,IAAAA,cAAoC;AACpC,iBAAoC;AAcpC,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;AApDP,eAAsB,iBAAiB,WAA0B,OAAsB;AACrF,MAAI,aAAa,OAAO;AACtB,cAAM,iCAAoB;AAAA,EAC5B,OAAO;AACL,wCAAoB;AAAA,EACtB;AACF;AA6DA,SAAS,iBAAiB,aAAyC;AACjE,MAAI,gBAAgB,OAAW,QAAO;AACtC,QAAM,aAAS,sCAAsB,WAAW;AAChD,MAAI,CAAC,OAAO,SAAS,MAAM,GAAG;AAC5B,UAAM,IAAI;AAAA,MACR,eAAe,KAAK,UAAU,WAAW,CAAC;AAAA,MAE1C;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AASO,SAAS,+BAA+B,WAA4B;AACzE,QAAM,YAAQ,sCAAsB,SAAS;AAC7C,MAAI,CAAC,OAAO,SAAS,KAAK,EAAG,QAAO;AACpC,MAAI,QAAQ,E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AAU,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,WAAW,EAAE,SAAS,UAAU,QAAQ;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACJ;AACF;AAEO,MAAM,kBAAkB,CAC7B,UACA,WACA,SACA,eACA,aACA,WACA,sBAA2C,WACxC;AACH,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,MACb;AAAA,IACF;AAAA,EACJ;AACF;","names":["import_mcp","import_a2a","import_mcp_tasks","import_errors","import_transportDiagnostics"]}
@@ -36,12 +36,12 @@ import { callMCPToolWithOAuth as callMCPToolWithOAuth2 } from "./mcp.mjs";
36
36
  import { callA2ATool as callA2ATool2 } from "./a2a.mjs";
37
37
  import { getAuthToken } from "../auth/index.mjs";
38
38
  import {
39
- createNonInteractiveOAuthProvider,
40
39
  discoverAuthorizationRequirements,
41
40
  NeedsAuthorizationError,
42
41
  getAgentStorage,
43
42
  ensureClientCredentialsTokens
44
43
  } from "../auth/oauth/index.mjs";
44
+ import { getNonInteractiveOAuthProvider } from "../auth/oauth/provider-cache.mjs";
45
45
  import { is401Error } from "../errors/index.mjs";
46
46
  import { isLikelyPrivateUrl } from "../net/index.mjs";
47
47
  import { validateAgentUrl } from "../validation/index.mjs";
@@ -60,20 +60,6 @@ import {
60
60
  withTransportDiagnostics as withTransportDiagnostics2,
61
61
  wrapFetchWithTransportDiagnostics
62
62
  } from "./transportDiagnostics.mjs";
63
- const nonInteractiveOAuthProviderCache = /* @__PURE__ */ new WeakMap();
64
- function getNonInteractiveOAuthProvider(agent) {
65
- let provider = nonInteractiveOAuthProviderCache.get(agent);
66
- if (!provider) {
67
- const storage = getAgentStorage(agent);
68
- provider = createNonInteractiveOAuthProvider(agent, {
69
- agentHint: agent.id,
70
- storage,
71
- allowHttp: isLikelyPrivateUrl(agent.agent_uri)
72
- });
73
- nonInteractiveOAuthProviderCache.set(agent, provider);
74
- }
75
- return provider;
76
- }
77
63
  function resolveWireMajor(adcpVersion) {
78
64
  if (adcpVersion === void 0) return ADCP_MAJOR_VERSION;
79
65
  const parsed = parseAdcpMajorVersion(adcpVersion);
@@ -211,7 +197,11 @@ class ProtocolClient {
211
197
  if (agent.protocol === "mcp") {
212
198
  const argsWithWebhook = pushNotificationConfig ? { ...argsWithVersion, push_notification_config: pushNotificationConfig } : argsWithVersion;
213
199
  if (agent.oauth_tokens && !agent.oauth_client_credentials) {
214
- const authProvider = getNonInteractiveOAuthProvider(agent);
200
+ const authProvider = getNonInteractiveOAuthProvider(agent, {
201
+ agentHint: agent.id,
202
+ storage: getAgentStorage(agent),
203
+ allowHttp: isLikelyPrivateUrl(agent.agent_uri)
204
+ });
215
205
  try {
216
206
  return await callMCPToolWithOAuth2({
217
207
  agentUrl: agent.agent_uri,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/protocols/index.ts"],"sourcesContent":["import { fileURLToPath as __adcpFileURLToPath } from 'node:url';\nimport { dirname as __adcpDirname } from 'node:path';\nimport { createRequire as __adcpCreateRequire } from 'node:module';\nconst __dirname = __adcpDirname(__adcpFileURLToPath(import.meta.url));\nconst require = __adcpCreateRequire(import.meta.url);\n// 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 { 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}\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 createNonInteractiveOAuthProvider,\n discoverAuthorizationRequirements,\n NeedsAuthorizationError,\n getAgentStorage,\n ensureClientCredentialsTokens,\n} from '../auth/oauth';\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\nconst nonInteractiveOAuthProviderCache = new WeakMap<\n AgentConfig,\n ReturnType<typeof createNonInteractiveOAuthProvider>\n>();\n\nfunction getNonInteractiveOAuthProvider(agent: AgentConfig): ReturnType<typeof createNonInteractiveOAuthProvider> {\n let provider = nonInteractiveOAuthProviderCache.get(agent);\n if (!provider) {\n const storage = getAgentStorage(agent);\n provider = createNonInteractiveOAuthProvider(agent, {\n agentHint: agent.id,\n storage,\n allowHttp: isLikelyPrivateUrl(agent.agent_uri),\n });\n nonInteractiveOAuthProviderCache.set(agent, provider);\n }\n return provider;\n}\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\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 `fetchFn`\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 * For SSRF-sensitive metadata probes, supplying this function makes it the\n * trusted network boundary: the SDK still validates schemes and resolved\n * addresses, but a custom fetch API cannot accept the SDK's pinned undici\n * dispatcher. The implementation must therefore prevent DNS rebinding (for\n * example with an egress proxy or its own DNS pinning).\n */\n fetchFn?: typeof fetch;\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\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,\n signal,\n onTransportActivity,\n transportActivityContext,\n } = options;\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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 const pushNotificationConfig: PushNotificationConfig | undefined = webhookUrl\n ? {\n url: webhookUrl,\n ...(webhookToken && { token: webhookToken }),\n authentication: {\n schemes: ['HMAC-SHA256'],\n credentials: webhookSecret || 'placeholder_secret_min_32_characters_required',\n },\n }\n : undefined;\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 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?.fetchFn,\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(err, agent.agent_uri, transport?.fetchFn);\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?.fetchFn && { fetchFn: transport.fetchFn }),\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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?.fetchFn && { fetchFn: transport.fetchFn }),\n }\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(retryErr, agent.agent_uri, transport?.fetchFn);\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(err, agent.agent_uri, transport?.fetchFn);\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?.fetchFn\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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?.fetchFn\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(retryErr, agent.agent_uri, transport?.fetchFn);\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(err, agent.agent_uri, transport?.fetchFn);\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(err: unknown, agentUrl: string, fetchFn?: typeof fetch): 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 = 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 });\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 // 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?.fetchFn && { fetchFn: transport.fetchFn }),\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 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?.fetchFn\n )\n ),\n };\n};\n"],"mappings":"AAAA,SAAS,iBAAiB,2BAA2B;AACrD,SAAS,WAAW,qBAAqB;AACzC,SAAS,iBAAiB,2BAA2B;AACrD,MAAM,YAAY,cAAc,oBAAoB,YAAY,GAAG,CAAC;AACpE,MAAMA,WAAU,oBAAoB,YAAY,GAAG;AAEnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,uBAAAC,4BAA2B;AACpC,SAAS,2BAA2B;AAMpC,eAAsB,iBAAiB,WAA0B,OAAsB;AACrF,MAAI,aAAa,OAAO;AACtB,UAAMA,qBAAoB;AAAA,EAC5B,OAAO;AACL,wBAAoB;AAAA,EACtB;AACF;AAEA,SAAS,mBAAmB;AAC5B,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,wBAAAC,uBAAsB,6BAA6B;AAC5D,SAAS,wBAAAC,6BAA4B;AACrC,SAAS,eAAAC,oBAAmB;AAG5B,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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A,IACF;AAAA,EACJ;AACF;AAEO,MAAM,kBAAkB,CAC7B,UACA,WACA,SACA,eACA,aACA,WACA,sBAA2C,WACxC;AACH,QAAM,kBAAkB,4BAA4B,qBAAqB,aAAa,aAAa;AACnG,SAAO;AAAA,IACL,UAAU,CAAC,UAAkB,YAAqC,cAChE;AAAA,MAAsB,WAAW;AAAA,MAAkB,MACjDE;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,MACb;AAAA,IACF;AAAA,EACJ;AACF;","names":["require","closeMCPConnections","callMCPToolWithTasks","callMCPToolWithOAuth","callA2ATool","withTransportDiagnostics"]}
1
+ {"version":3,"sources":["../../../src/lib/protocols/index.ts"],"sourcesContent":["import { fileURLToPath as __adcpFileURLToPath } from 'node:url';\nimport { dirname as __adcpDirname } from 'node:path';\nimport { createRequire as __adcpCreateRequire } from 'node:module';\nconst __dirname = __adcpDirname(__adcpFileURLToPath(import.meta.url));\nconst require = __adcpCreateRequire(import.meta.url);\n// 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 { 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}\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\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 `fetchFn`\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 * For SSRF-sensitive metadata probes, supplying this function makes it the\n * trusted network boundary: the SDK still validates schemes and resolved\n * addresses, but a custom fetch API cannot accept the SDK's pinned undici\n * dispatcher. The implementation must therefore prevent DNS rebinding (for\n * example with an egress proxy or its own DNS pinning).\n */\n fetchFn?: typeof fetch;\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\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,\n signal,\n onTransportActivity,\n transportActivityContext,\n } = options;\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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 const pushNotificationConfig: PushNotificationConfig | undefined = webhookUrl\n ? {\n url: webhookUrl,\n ...(webhookToken && { token: webhookToken }),\n authentication: {\n schemes: ['HMAC-SHA256'],\n credentials: webhookSecret || 'placeholder_secret_min_32_characters_required',\n },\n }\n : undefined;\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?.fetchFn,\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(err, agent.agent_uri, transport?.fetchFn);\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?.fetchFn && { fetchFn: transport.fetchFn }),\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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?.fetchFn && { fetchFn: transport.fetchFn }),\n }\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(retryErr, agent.agent_uri, transport?.fetchFn);\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(err, agent.agent_uri, transport?.fetchFn);\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?.fetchFn\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 = isLikelyPrivateUrl(agent.agent_uri);\n await ensureClientCredentialsTokens(agent, {\n storage: ccStorage,\n force: true,\n allowPrivateIp,\n fetch: transport?.fetchFn,\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?.fetchFn\n );\n } catch (retryErr) {\n await rethrowAsNeedsAuthorization(retryErr, agent.agent_uri, transport?.fetchFn);\n throw retryErr;\n }\n }\n await rethrowAsNeedsAuthorization(err, agent.agent_uri, transport?.fetchFn);\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(err: unknown, agentUrl: string, fetchFn?: typeof fetch): 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 = 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 });\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 // 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?.fetchFn && { fetchFn: transport.fetchFn }),\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 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?.fetchFn\n )\n ),\n };\n};\n"],"mappings":"AAAA,SAAS,iBAAiB,2BAA2B;AACrD,SAAS,WAAW,qBAAqB;AACzC,SAAS,iBAAiB,2BAA2B;AACrD,MAAM,YAAY,cAAc,oBAAoB,YAAY,GAAG,CAAC;AACpE,MAAMA,WAAU,oBAAoB,YAAY,GAAG;AAEnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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AC,UAAkB,MAA+B,cAC1D;AAAA,MAAsB,WAAW;AAAA,MAAkB,MACjDF;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,WAAW,EAAE,SAAS,UAAU,QAAQ;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACJ;AACF;AAEO,MAAM,kBAAkB,CAC7B,UACA,WACA,SACA,eACA,aACA,WACA,sBAA2C,WACxC;AACH,QAAM,kBAAkB,4BAA4B,qBAAqB,aAAa,aAAa;AACnG,SAAO;AAAA,IACL,UAAU,CAAC,UAAkB,YAAqC,cAChE;AAAA,MAAsB,WAAW;AAAA,MAAkB,MACjDE;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,MACb;AAAA,IACF;AAAA,EACJ;AACF;","names":["require","closeMCPConnections","callMCPToolWithTasks","callMCPToolWithOAuth","callA2ATool","withTransportDiagnostics"]}
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-modern.d.ts","sourceRoot":"","sources":["../../../src/lib/protocols/mcp-modern.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAIL,KAAK,IAAI,EACV,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EAAiD,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC5G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAWnD,KAAK,gBAAgB,GAAG;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EA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