@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,"file":"augment-response.d.ts","sourceRoot":"","sources":["../../../../src/lib/v2/projection/augment-response.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAMvG;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG;IACtC,cAAc,EAAE,0BAA0B,EAAE,CAAC;CAC9C,CAAC;AAEF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B,GAChC;IAAE,QAAQ,EAAE,CAAC,GAAG;QAAE,QAAQ,EAAE,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAA;KAAE,CAAC;IAAC,WAAW,EAAE,oBAAoB,EAAE,CAAA;CAAE,CAkBtG;AAED;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG;IAC5D,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,cAAc,EAAE,0BAA0B,EAAE,CAAC;CAC9C,CAAC;AA2DF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,SAAS,EACxD,OAAO,EAAE,CAAC,EACV,OAAO,CAAC,EAAE,uBAAuB,GAChC;IAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAAC,WAAW,EAAE,oBAAoB,EAAE,CAAA;CAAE,CA+E3E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAA;CAAE,EAC1E,QAAQ,EAAE,CAAC,EACX,OAAO,CAAC,EAAE,uBAAuB,GAChC;IACD,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG;QAAE,QAAQ,EAAE,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC;IACpG,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACrC,CA8DA"}
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var augment_response_exports = {};
20
20
  __export(augment_response_exports, {
21
21
  augmentProductWithFormatOptions: () => augmentProductWithFormatOptions,
22
+ projectionDiagnosticToError: () => projectionDiagnosticToError,
22
23
  toCanonicalOnlyProduct: () => toCanonicalOnlyProduct,
23
24
  toCanonicalOnlyResponse: () => toCanonicalOnlyResponse,
24
25
  withFormatOptions: () => withFormatOptions
@@ -26,8 +27,135 @@ __export(augment_response_exports, {
26
27
  module.exports = __toCommonJS(augment_response_exports);
27
28
  var import_v1_to_v2 = require('./v1-to-v2.js');
28
29
  var import_version = require('../../version.js');
30
+ var import_jcs = require('../../utils/jcs.js');
31
+ var import_legacy_metadata = require('./legacy-metadata.js');
29
32
  const SDK_ID = `@adcp/sdk@${import_version.LIBRARY_VERSION}`;
30
- function augmentProductWithFormatOptions(product) {
33
+ function canonicalDiagnostic(diagnostic) {
34
+ return {
35
+ ...diagnostic,
36
+ // A source `format_ids[i]` index is not an index into the projected
37
+ // `format_options[]`: earlier source refs may have failed while later refs
38
+ // projected successfully. Point at the canonical collection instead of
39
+ // claiming that a successful projected option is the failing value.
40
+ field: diagnostic.field.replace(/\.format_ids\[\d+\]/g, ".format_options")
41
+ };
42
+ }
43
+ function projectionErrorMessage(code) {
44
+ switch (code) {
45
+ case "CANONICAL_PRODUCT_FORMATS_UNAVAILABLE":
46
+ return "Product has no format declaration representable on the canonical-only surface";
47
+ case "FORMAT_PROJECTION_FAILED":
48
+ return "Legacy creative format could not be projected to a canonical declaration";
49
+ case "FORMAT_DECLARATION_V1_AMBIGUOUS":
50
+ return "Canonical creative format has no unambiguous legacy declaration";
51
+ case "FORMAT_DECLARATION_V1_NOT_APPLICABLE":
52
+ return "Canonical-only creative format cannot be represented on a legacy format path";
53
+ case "CANONICAL_NOT_V1_TRANSLATABLE":
54
+ return "Canonical creative format has no legacy representation";
55
+ case "FORMAT_DECLARATION_V1_LOSSY_MULTI_SIZE":
56
+ return "Canonical multi-size format has incomplete legacy coverage";
57
+ case "LEGACY_FORMAT_ID_DROPPED_UNMAPPED":
58
+ return "Redundant legacy creative identity has no canonical counterpart";
59
+ }
60
+ }
61
+ function projectionDiagnosticToError(diagnostic) {
62
+ return {
63
+ code: diagnostic.code,
64
+ message: projectionErrorMessage(diagnostic.code),
65
+ field: diagnostic.field,
66
+ recovery: "correctable",
67
+ source: diagnostic.source,
68
+ sdk_id: diagnostic.sdk_id,
69
+ details: diagnostic.error.details
70
+ };
71
+ }
72
+ function canonicalFormatsUnavailableForProduct(product, reason) {
73
+ return {
74
+ source: "sdk",
75
+ sdk_id: SDK_ID,
76
+ field: `products[${product.product_id}].format_options`,
77
+ code: "CANONICAL_PRODUCT_FORMATS_UNAVAILABLE",
78
+ error: {
79
+ details: {
80
+ product_id: product.product_id,
81
+ reason
82
+ }
83
+ }
84
+ };
85
+ }
86
+ function errorIdentity(value) {
87
+ if (typeof value.code !== "string" || typeof value.field !== "string") return void 0;
88
+ try {
89
+ return `${value.code}\0${value.field}\0${(0, import_jcs.canonicalize)(value.details ?? null)}`;
90
+ } catch {
91
+ return void 0;
92
+ }
93
+ }
94
+ function mergeProjectionErrors(existing, diagnostics) {
95
+ const merged = Array.isArray(existing) ? [...existing] : [];
96
+ const seen = /* @__PURE__ */ new Set();
97
+ for (const value of merged) {
98
+ if (!value || typeof value !== "object" || Array.isArray(value)) continue;
99
+ const record = value;
100
+ const key = errorIdentity(record);
101
+ if (key) seen.add(key);
102
+ }
103
+ for (const diagnostic of diagnostics) {
104
+ const error = projectionDiagnosticToError(diagnostic);
105
+ const key = errorIdentity(error);
106
+ if (seen.has(key)) continue;
107
+ seen.add(key);
108
+ merged.push(error);
109
+ }
110
+ return merged;
111
+ }
112
+ function remapExistingProductErrors(existing, originalToOutputIndex, products) {
113
+ if (!Array.isArray(existing)) return existing;
114
+ return existing.map((value) => {
115
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
116
+ const record = value;
117
+ let issuesChanged = false;
118
+ const issues = Array.isArray(record.issues) ? record.issues.map((issue) => {
119
+ if (!issue || typeof issue !== "object" || Array.isArray(issue)) return issue;
120
+ const issueRecord = issue;
121
+ if (typeof issueRecord.pointer !== "string") return issue;
122
+ const pointerMatch = /^\/products\/(\d+)(\/.*)?$/.exec(issueRecord.pointer);
123
+ if (!pointerMatch) return issue;
124
+ const originalIssueIndex = Number(pointerMatch[1]);
125
+ if (!originalToOutputIndex.has(originalIssueIndex)) return issue;
126
+ const outputIssueIndex = originalToOutputIndex.get(originalIssueIndex);
127
+ issuesChanged = true;
128
+ return {
129
+ ...issueRecord,
130
+ pointer: outputIssueIndex === void 0 ? "/products" : `/products/${outputIssueIndex}${pointerMatch[2] ?? ""}`
131
+ };
132
+ }) : record.issues;
133
+ const withIssues = issuesChanged ? { ...record, issues } : record;
134
+ if (typeof record.field !== "string") return issuesChanged ? withIssues : value;
135
+ const match = /^products\[(\d+)\](.*)$/.exec(record.field);
136
+ if (!match) return issuesChanged ? withIssues : value;
137
+ const originalIndex = Number(match[1]);
138
+ if (!originalToOutputIndex.has(originalIndex)) return issuesChanged ? withIssues : value;
139
+ const outputIndex = originalToOutputIndex.get(originalIndex);
140
+ if (outputIndex !== void 0) {
141
+ return { ...withIssues, field: `products[${outputIndex}]${match[2] ?? ""}` };
142
+ }
143
+ const productId = products[originalIndex]?.product_id;
144
+ const details = record.details && typeof record.details === "object" && !Array.isArray(record.details) ? { ...record.details } : {};
145
+ if (typeof productId === "string" && details.product_id === void 0) details.product_id = productId;
146
+ return { ...withIssues, field: "products", ...Object.keys(details).length > 0 ? { details } : {} };
147
+ });
148
+ }
149
+ function hasEmptyPlacementFormatOptions(product) {
150
+ const placements = product.placements;
151
+ if (!Array.isArray(placements)) return false;
152
+ return placements.some((value) => {
153
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
154
+ const options = value.format_options;
155
+ return Array.isArray(options) && options.length === 0;
156
+ });
157
+ }
158
+ function augmentProductWithFormatOptions(product, options) {
31
159
  const existing = product.format_options;
32
160
  if (Array.isArray(existing)) {
33
161
  return {
@@ -41,7 +169,7 @@ function augmentProductWithFormatOptions(product) {
41
169
  diagnostics: []
42
170
  };
43
171
  }
44
- const { v2, diagnostics } = (0, import_v1_to_v2.projectV1ProductToV2)(product);
172
+ const { v2, diagnostics } = (0, import_v1_to_v2.projectV1ProductToV2)(product, options);
45
173
  return {
46
174
  product: {
47
175
  ...product,
@@ -50,7 +178,7 @@ function augmentProductWithFormatOptions(product) {
50
178
  diagnostics
51
179
  };
52
180
  }
53
- function withFormatOptions(response) {
181
+ function withFormatOptions(response, options) {
54
182
  if (!Array.isArray(response?.products)) {
55
183
  return {
56
184
  response: { ...response, products: [] },
@@ -60,7 +188,7 @@ function withFormatOptions(response) {
60
188
  const out = [];
61
189
  const diagnostics = [];
62
190
  for (const p of response.products) {
63
- const { product, diagnostics: d } = augmentProductWithFormatOptions(p);
191
+ const { product, diagnostics: d } = augmentProductWithFormatOptions(p, options);
64
192
  out.push(product);
65
193
  diagnostics.push(...d);
66
194
  }
@@ -69,15 +197,50 @@ function withFormatOptions(response) {
69
197
  diagnostics
70
198
  };
71
199
  }
200
+ function canonicalDeclarations(values) {
201
+ return values.map((value) => (0, import_legacy_metadata.concealLegacyFormatRefs)(value));
202
+ }
203
+ function canonicalPlacements(product, options, diagnostics) {
204
+ if (!Array.isArray(product.placements)) return product.placements;
205
+ return product.placements.map((value, placementIndex) => {
206
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
207
+ const placement = value;
208
+ const { format_ids: _drop, ...rest } = placement;
209
+ void _drop;
210
+ const hasLegacyFormats = Array.isArray(placement.format_ids);
211
+ const hasCanonicalFormats = Array.isArray(placement.format_options);
212
+ if (!hasLegacyFormats && !hasCanonicalFormats) return rest;
213
+ const productId = typeof product.product_id === "string" ? product.product_id : "(unknown)";
214
+ const placementId = typeof placement.placement_id === "string" ? placement.placement_id : String(placementIndex);
215
+ const pseudoProduct = {
216
+ product_id: `${productId}:placement:${placementId}`,
217
+ name: typeof placement.name === "string" ? placement.name : placementId,
218
+ description: `Nested placement ${placementId}`,
219
+ ...hasLegacyFormats ? { format_ids: placement.format_ids } : {},
220
+ ...hasCanonicalFormats ? { format_options: placement.format_options } : {}
221
+ };
222
+ const projected = toCanonicalOnlyProduct(pseudoProduct, options);
223
+ for (const diagnostic of projected.diagnostics) {
224
+ diagnostics.push({
225
+ ...diagnostic,
226
+ field: diagnostic.field.replace(/^products\[[^\]]+\]/, `products[${productId}].placements[${placementIndex}]`)
227
+ });
228
+ }
229
+ return {
230
+ ...rest,
231
+ format_options: projected.product.format_options
232
+ };
233
+ });
234
+ }
72
235
  function formatRefCoverageKey(ref) {
73
236
  const url = ref.agent_url && !ref.agent_url.endsWith("/") ? ref.agent_url + "/" : ref.agent_url;
74
237
  return `${url}::${ref.id}::${ref.width ?? ""}x${ref.height ?? ""}::${ref.duration_ms ?? ""}`;
75
238
  }
76
- function toCanonicalOnlyProduct(product) {
239
+ function toCanonicalOnlyProduct(product, options) {
77
240
  const existing = product.format_options;
78
241
  if (Array.isArray(existing)) {
79
242
  const formatOptions = existing;
80
- const diagnostics = [];
243
+ const diagnostics2 = [];
81
244
  const inputIds = Array.isArray(product.format_ids) ? product.format_ids : [];
82
245
  if (inputIds.length > 0) {
83
246
  const covered = /* @__PURE__ */ new Set();
@@ -88,22 +251,15 @@ function toCanonicalOnlyProduct(product) {
88
251
  for (let k = 0; k < inputIds.length; k++) {
89
252
  const fid = inputIds[k];
90
253
  if (!covered.has(formatRefCoverageKey(fid))) {
91
- const dropped_format_id = { agent_url: fid.agent_url, id: fid.id };
92
- if (typeof fid.width === "number") dropped_format_id.width = fid.width;
93
- if (typeof fid.height === "number") dropped_format_id.height = fid.height;
94
- if (typeof fid.duration_ms === "number") dropped_format_id.duration_ms = fid.duration_ms;
95
- diagnostics.push({
254
+ diagnostics2.push({
96
255
  source: "sdk",
97
256
  sdk_id: SDK_ID,
98
- // Indexed to match the v1→v2 projection path's
99
- // `products[id].format_ids[K]` so consumers correlate diagnostics
100
- // by `field` shape across both paths.
101
- field: `products[${product.product_id}].format_ids[${k}]`,
257
+ field: `products[${product.product_id}].format_options`,
102
258
  code: "LEGACY_FORMAT_ID_DROPPED_UNMAPPED",
103
259
  error: {
104
260
  details: {
105
261
  product_id: product.product_id,
106
- dropped_format_id
262
+ resolution_failure: "unmapped_legacy_format"
107
263
  }
108
264
  }
109
265
  });
@@ -112,25 +268,41 @@ function toCanonicalOnlyProduct(product) {
112
268
  }
113
269
  const { format_ids: _dropV2, ...rest2 } = product;
114
270
  void _dropV2;
115
- return { product: rest2, diagnostics };
271
+ return {
272
+ product: {
273
+ ...rest2,
274
+ format_options: canonicalDeclarations(formatOptions),
275
+ ...Array.isArray(product.placements) ? { placements: canonicalPlacements(product, options, diagnostics2) } : {}
276
+ },
277
+ diagnostics: diagnostics2.map(canonicalDiagnostic)
278
+ };
116
279
  }
117
280
  if (Array.isArray(product.format_ids)) {
118
- const { v2, diagnostics } = (0, import_v1_to_v2.projectV1ProductToV2)(product);
281
+ const { v2, diagnostics: diagnostics2 } = (0, import_v1_to_v2.projectV1ProductToV2)(product, options);
119
282
  const { format_ids: _dropV1, ...rest2 } = product;
120
283
  void _dropV1;
121
284
  return {
122
- product: { ...rest2, format_options: v2.format_options },
123
- diagnostics
285
+ product: {
286
+ ...rest2,
287
+ format_options: canonicalDeclarations(v2.format_options),
288
+ ...Array.isArray(product.placements) ? { placements: canonicalPlacements(product, options, diagnostics2) } : {}
289
+ },
290
+ diagnostics: diagnostics2.map(canonicalDiagnostic)
124
291
  };
125
292
  }
126
293
  const { format_ids: _dropNone, ...rest } = product;
127
294
  void _dropNone;
295
+ const diagnostics = [];
128
296
  return {
129
- product: { ...rest, format_options: [] },
130
- diagnostics: []
297
+ product: {
298
+ ...rest,
299
+ format_options: [],
300
+ ...Array.isArray(product.placements) ? { placements: canonicalPlacements(product, options, diagnostics) } : {}
301
+ },
302
+ diagnostics: diagnostics.map(canonicalDiagnostic)
131
303
  };
132
304
  }
133
- function toCanonicalOnlyResponse(response) {
305
+ function toCanonicalOnlyResponse(response, options) {
134
306
  if (!Array.isArray(response?.products)) {
135
307
  return {
136
308
  response: { ...response, products: [] },
@@ -139,19 +311,53 @@ function toCanonicalOnlyResponse(response) {
139
311
  }
140
312
  const out = [];
141
313
  const diagnostics = [];
142
- for (const p of response.products) {
143
- const { product, diagnostics: d } = toCanonicalOnlyProduct(p);
144
- out.push(product);
314
+ const originalToOutputIndex = /* @__PURE__ */ new Map();
315
+ for (let productIndex = 0; productIndex < response.products.length; productIndex++) {
316
+ const p = response.products[productIndex];
317
+ const { product, diagnostics: rawDiagnostics } = toCanonicalOnlyProduct(p, options);
318
+ const hasEmptyPlacement = hasEmptyPlacementFormatOptions(product);
319
+ const keep = product.format_options.length > 0 && !hasEmptyPlacement;
320
+ const outputIndex = keep ? out.length : void 0;
321
+ originalToOutputIndex.set(productIndex, outputIndex);
322
+ const d = rawDiagnostics.map((diagnostic) => ({
323
+ ...diagnostic,
324
+ field: keep ? diagnostic.field.replace(/^products\[[^\]]+\]/, `products[${outputIndex}]`) : "products",
325
+ error: keep ? diagnostic.error : {
326
+ details: {
327
+ ...diagnostic.error.details,
328
+ product_id: p.product_id
329
+ }
330
+ }
331
+ }));
332
+ if (!keep && d.length === 0) {
333
+ const reason = hasEmptyPlacement ? "nested_placement_format_list_empty" : Array.isArray(p.format_options) ? "canonical_format_list_empty" : Array.isArray(p.format_ids) ? "legacy_format_list_empty" : "missing_format_declaration";
334
+ d.push({
335
+ ...canonicalFormatsUnavailableForProduct(p, reason),
336
+ field: "products"
337
+ });
338
+ }
145
339
  diagnostics.push(...d);
340
+ if (keep) out.push(product);
146
341
  }
342
+ const remappedExistingErrors = remapExistingProductErrors(
343
+ response.errors,
344
+ originalToOutputIndex,
345
+ response.products
346
+ );
347
+ const errors = mergeProjectionErrors(remappedExistingErrors, diagnostics);
147
348
  return {
148
- response: { ...response, products: out },
349
+ response: {
350
+ ...response,
351
+ products: out,
352
+ ...errors.length > 0 ? { errors } : {}
353
+ },
149
354
  diagnostics
150
355
  };
151
356
  }
152
357
  // Annotate the CommonJS export names for ESM import in node:
153
358
  0 && (module.exports = {
154
359
  augmentProductWithFormatOptions,
360
+ projectionDiagnosticToError,
155
361
  toCanonicalOnlyProduct,
156
362
  toCanonicalOnlyResponse,
157
363
  withFormatOptions
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/v2/projection/augment-response.ts"],"sourcesContent":["/**\n * Buyer-side helpers that augment a v1-shaped agent response with v2\n * `format_options[]` derived from the existing `format_ids[]` on each\n * Product.\n *\n * Buyers who want the canonical creative-format model call\n * `withFormatOptions(response)` and read `format_options` instead of\n * relying only on legacy `format_ids`.\n *\n * The SDK also auto-projects compatible `AgentClient.getProducts()`\n * responses; this helper remains useful for cached responses, fixtures,\n * upstream seller/storefront composition, and explicit migration code.\n *\n * Pure functions — no IO, no caching. Each Product is projected\n * independently; diagnostics aggregate so a multi-product response\n * surfaces every projection issue at once. The helpers preserve the\n * input shape verbatim and add `format_options[]` (additive). They do\n * NOT drop `format_ids[]` — that's the 8.0 narrowing. To DROP\n * `format_ids[]` once a consumer has fully migrated, use\n * `toCanonicalOnlyProduct` / `toCanonicalOnlyResponse`.\n */\n\nimport type { V1Product, V1FormatId, V2ProductFormatDeclaration, ProjectionDiagnostic } from './types';\nimport { projectV1ProductToV2 } from './v1-to-v2';\nimport { LIBRARY_VERSION } from '../../version';\n\nconst SDK_ID = `@adcp/sdk@${LIBRARY_VERSION}`;\n\n/**\n * A Product that has been augmented with `format_options[]` while\n * preserving the original `format_ids[]`. Carries the projection\n * diagnostics that were generated mapping each `format_id` so the\n * buyer can see what (if anything) didn't project cleanly.\n *\n * **Write-side bridge.** After picking a `format_options[i]` entry,\n * use {@link formatIdsFromOptions} (from `@adcp/sdk/v2/projection`)\n * to extract the `format_ids[]` value for a `create_media_buy`\n * package. Inlining `decl.v1_format_ref` works but bypasses the\n * fail-closed semantics (canonical_formats_only / inherently-v2\n * canonical → throw). The spec gap that forces this bridge is tracked\n * at adcontextprotocol/adcp#4842.\n *\n * @see formatIdsFromOptions\n * @see formatIdsForCapability\n */\nexport type V2AugmentedProduct<P> = P & {\n format_options: V2ProductFormatDeclaration[];\n};\n\n/**\n * Augment a single Product. Idempotent — when `format_options[]` is\n * already present (the seller is v2-native), passes the Product\n * through unchanged. Otherwise projects from `format_ids[]`.\n *\n * Returns `{ product, diagnostics }`. `diagnostics` is empty for a\n * clean projection; populated when individual format_ids don't have\n * a v2 mapping (catalog gap, structural unreachability, etc.).\n *\n * @see toCanonicalOnlyProduct — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function augmentProductWithFormatOptions<P extends V1Product>(\n product: P\n): { product: V2AugmentedProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n // Already v2-shaped (seller sent format_options directly) — pass through.\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n if (Array.isArray(existing)) {\n return {\n product: product as V2AugmentedProduct<P>,\n diagnostics: [],\n };\n }\n // v1 shape — project to add format_options[].\n if (!Array.isArray(product.format_ids)) {\n // Neither shape — nothing to project. Return as-is with an empty\n // format_options so the buyer doesn't have to special-case.\n return {\n product: { ...product, format_options: [] },\n diagnostics: [],\n };\n }\n const { v2, diagnostics } = projectV1ProductToV2(product);\n // Preserve the original product shape (especially format_ids); just\n // add format_options.\n return {\n product: {\n ...product,\n format_options: v2.format_options,\n },\n diagnostics,\n };\n}\n\n/**\n * Augment every Product in a `get_products` response with\n * `format_options[]`. Returns `{ response, diagnostics }` so callers\n * can surface projection diagnostics alongside the response's existing\n * `errors[]` array (or filter by `source: 'sdk'` to distinguish SDK\n * diagnostics from seller-emitted errors).\n *\n * Idempotent: if the seller is v2-native and every Product already\n * carries `format_options[]`, returns the response verbatim with no\n * diagnostics.\n *\n * @see toCanonicalOnlyResponse — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function withFormatOptions<R extends { products?: V1Product[] }>(\n response: R\n): { response: R & { products: V2AugmentedProduct<V1Product>[] }; diagnostics: ProjectionDiagnostic[] } {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics: [],\n };\n }\n const out: V2AugmentedProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n for (const p of response.products) {\n const { product, diagnostics: d } = augmentProductWithFormatOptions(p);\n out.push(product);\n diagnostics.push(...d);\n }\n return {\n response: { ...response, products: out } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics,\n };\n}\n\n/**\n * A Product reduced to the canonical creative-format surface:\n * `format_options[]` only, with the legacy `format_ids[]` removed. The\n * read-side counterpart to a fully-migrated consumer — naive downstream\n * code can no longer fall back to the stale `{ agent_url, id }` shape and\n * silently bypass the canonical model.\n */\nexport type CanonicalOnlyProduct<P> = Omit<P, 'format_ids'> & {\n format_options: V2ProductFormatDeclaration[];\n};\n\n/**\n * Identity key for a `format_id` ref used by the coverage check.\n * Trailing-slash-insensitive on `agent_url` (folds the AAO host's slash /\n * no-slash forms, per `catalog.ts`'s `normalizeAgentUrl`), and includes the\n * dimensional discriminators so multi-size declarations sharing one\n * `{ agent_url, id }` but differing by size/duration are NOT collapsed —\n * the same key shape `write-side.ts` uses for v1 ref de-dup. Without the\n * size half, a `format_ids[]` entry for a size no `v1_format_ref` covers\n * would read as covered and be dropped silently.\n */\nfunction formatRefCoverageKey(ref: V1FormatId): string {\n const url = ref.agent_url && !ref.agent_url.endsWith('/') ? ref.agent_url + '/' : ref.agent_url;\n return `${url}::${ref.id}::${ref.width ?? ''}x${ref.height ?? ''}::${ref.duration_ms ?? ''}`;\n}\n\n/**\n * Project a single Product to the canonical-only shape: `format_options[]`\n * present, `format_ids[]` dropped.\n *\n * **Dropping legacy never silently loses a format.** Every input\n * `format_id` is either represented in the returned `format_options[]` or\n * surfaced in `diagnostics` — never discarded without a trace:\n *\n * - **v1-shaped input** (`format_ids[]`, no `format_options[]`): runs the\n * v1 → v2 projection. Mapped refs become `format_options[]`; any ref\n * the projection can't map is surfaced as `FORMAT_PROJECTION_FAILED`.\n * - **v2-native input** (`format_options[]` already present): keeps the\n * seller's canonical surface and drops the redundant v1 fallback. If a\n * `format_ids[]` entry exists that no `format_options[].v1_format_ref`\n * covers, it surfaces as `LEGACY_FORMAT_ID_DROPPED_UNMAPPED` — the gap\n * the projection path can't see.\n * - **neither shape**: returns `format_options: []`; there is nothing to\n * project and nothing to lose.\n *\n * Pure and subtractive: unlike {@link augmentProductWithFormatOptions}\n * (which preserves `format_ids[]`), this drops it — the opt-in narrowing for\n * a consumer that has fully migrated. Complements the write-side\n * non-invertibility tracked at adcontextprotocol/adcp#4842 — this is the\n * read-side transparency half.\n */\nexport function toCanonicalOnlyProduct<P extends V1Product>(\n product: P\n): { product: CanonicalOnlyProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n\n // v2-native: the seller already sent format_options[]. Drop the\n // redundant v1 fallback, but flag any legacy ref no v1_format_ref covers.\n if (Array.isArray(existing)) {\n const formatOptions = existing as V2ProductFormatDeclaration[];\n const diagnostics: ProjectionDiagnostic[] = [];\n const inputIds = Array.isArray(product.format_ids) ? product.format_ids : [];\n if (inputIds.length > 0) {\n const covered = new Set<string>();\n for (const opt of formatOptions) {\n const refs = Array.isArray(opt?.v1_format_ref) ? opt.v1_format_ref : [];\n for (const ref of refs) covered.add(formatRefCoverageKey(ref));\n }\n for (let k = 0; k < inputIds.length; k++) {\n const fid = inputIds[k]!;\n if (!covered.has(formatRefCoverageKey(fid))) {\n // Echo the full ref the SDK saw — including dimensions — so a\n // buyer can tell WHICH variant was dropped (matches the\n // FORMAT_DECLARATION_V1_LOSSY_MULTI_SIZE size-in-details contract).\n const dropped_format_id: {\n agent_url: string;\n id: string;\n width?: number;\n height?: number;\n duration_ms?: number;\n } = { agent_url: fid.agent_url, id: fid.id };\n if (typeof fid.width === 'number') dropped_format_id.width = fid.width;\n if (typeof fid.height === 'number') dropped_format_id.height = fid.height;\n if (typeof fid.duration_ms === 'number') dropped_format_id.duration_ms = fid.duration_ms;\n diagnostics.push({\n source: 'sdk',\n sdk_id: SDK_ID,\n // Indexed to match the v1→v2 projection path's\n // `products[id].format_ids[K]` so consumers correlate diagnostics\n // by `field` shape across both paths.\n field: `products[${product.product_id}].format_ids[${k}]`,\n code: 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED',\n error: {\n details: {\n product_id: product.product_id,\n dropped_format_id,\n },\n },\n });\n }\n }\n }\n const { format_ids: _dropV2, ...rest } = product as P & { format_ids?: unknown };\n void _dropV2;\n return { product: rest as CanonicalOnlyProduct<P>, diagnostics };\n }\n\n // v1 shape: project. projectV1ProductToV2 already omits format_ids and\n // emits a diagnostic for every ref it couldn't map.\n if (Array.isArray(product.format_ids)) {\n const { v2, diagnostics } = projectV1ProductToV2(product);\n const { format_ids: _dropV1, ...rest } = product as P & { format_ids?: unknown };\n void _dropV1;\n return {\n product: { ...(rest as Omit<P, 'format_ids'>), format_options: v2.format_options } as CanonicalOnlyProduct<P>,\n diagnostics,\n };\n }\n\n // Neither shape — nothing to project, nothing to lose.\n const { format_ids: _dropNone, ...rest } = product as P & { format_ids?: unknown };\n void _dropNone;\n return {\n product: { ...(rest as Omit<P, 'format_ids'>), format_options: [] } as CanonicalOnlyProduct<P>,\n diagnostics: [],\n };\n}\n\n/**\n * Reduce every Product in a `get_products` response to the canonical-only\n * shape — `format_options[]` present, `format_ids[]` dropped. Returns\n * `{ response, diagnostics }` so callers surface projection diagnostics\n * alongside the response's existing `errors[]`.\n *\n * Response-level counterpart to {@link toCanonicalOnlyProduct}; same\n * never-silently-lose-a-format guarantee, aggregated across products. The\n * canonical-only sibling of {@link withFormatOptions} (which is additive\n * and preserves `format_ids[]`).\n */\nexport function toCanonicalOnlyResponse<R extends { products?: V1Product[] }>(\n response: R\n): {\n response: Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[] };\n diagnostics: ProjectionDiagnostic[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[] },\n diagnostics: [],\n };\n }\n const out: CanonicalOnlyProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n for (const p of response.products) {\n const { product, diagnostics: d } = toCanonicalOnlyProduct(p);\n out.push(product);\n diagnostics.push(...d);\n }\n return {\n response: { ...response, products: out } as Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[] },\n diagnostics,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,sBAAqC;AACrC,qBAAgC;AAEhC,MAAM,SAAS,aAAa,8BAAe;AAmCpC,SAAS,gCACd,SACyE;AAEzE,QAAM,WAAY,QAAoD;AACtE,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,WAAO;AAAA,MACL;AAAA,MACA,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,CAAC,MAAM,QAAQ,QAAQ,UAAU,GAAG;AAGtC,WAAO;AAAA,MACL,SAAS,EAAE,GAAG,SAAS,gBAAgB,CAAC,EAAE;AAAA,MAC1C,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AACA,QAAM,EAAE,IAAI,YAAY,QAAI,sCAAqB,OAAO;AAGxD,SAAO;AAAA,IACL,SAAS;AAAA,MACP,GAAG;AAAA,MACH,gBAAgB,GAAG;AAAA,IACrB;AAAA,IACA;AAAA,EACF;AACF;AAgBO,SAAS,kBACd,UACsG;AACtG,MAAI,CAAC,MAAM,QAAQ,UAAU,QAAQ,GAAG;AACtC,WAAO;AAAA,MACL,UAAU,EAAE,GAAG,UAAU,UAAU,CAAC,EAAE;AAAA,MACtC,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AACA,QAAM,MAAuC,CAAC;AAC9C,QAAM,cAAsC,CAAC;AAC7C,aAAW,KAAK,SAAS,UAAU;AACjC,UAAM,EAAE,SAAS,aAAa,EAAE,IAAI,gCAAgC,CAAC;AACrE,QAAI,KAAK,OAAO;AAChB,gBAAY,KAAK,GAAG,CAAC;AAAA,EACvB;AACA,SAAO;AAAA,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/v2/projection/augment-response.ts"],"sourcesContent":["/**\n * Buyer-side helpers that augment a v1-shaped agent response with v2\n * `format_options[]` derived from the existing `format_ids[]` on each\n * Product.\n *\n * Buyers who want the canonical creative-format model call\n * `withFormatOptions(response)` and read `format_options` instead of\n * relying only on legacy `format_ids`.\n *\n * The SDK also auto-projects compatible `AgentClient.getProducts()`\n * responses; this helper remains useful for cached responses, fixtures,\n * upstream seller/storefront composition, and explicit migration code.\n *\n * Pure functions — no IO, no caching. Each Product is projected\n * independently; diagnostics aggregate so a multi-product response\n * surfaces every projection issue at once. The helpers preserve the\n * input shape verbatim and add `format_options[]` (additive). They do\n * NOT drop `format_ids[]` — that's the 8.0 narrowing. To DROP\n * `format_ids[]` once a consumer has fully migrated, use\n * `toCanonicalOnlyProduct` / `toCanonicalOnlyResponse`.\n */\n\nimport type { V1Product, V1FormatId, V2ProductFormatDeclaration, ProjectionDiagnostic } from './types';\nimport { projectV1ProductToV2 } from './v1-to-v2';\nimport type { V1ToV2ProjectionOptions } from './v1-to-v2';\nimport { LIBRARY_VERSION } from '../../version';\nimport { canonicalize as canonicalizeJson } from '../../utils/jcs';\nimport { concealLegacyFormatRefs } from './legacy-metadata';\nimport type { CanonicalFormatDeclaration } from './legacy-metadata';\n\nconst SDK_ID = `@adcp/sdk@${LIBRARY_VERSION}`;\n\nfunction canonicalDiagnostic(diagnostic: ProjectionDiagnostic): ProjectionDiagnostic {\n return {\n ...diagnostic,\n // A source `format_ids[i]` index is not an index into the projected\n // `format_options[]`: earlier source refs may have failed while later refs\n // projected successfully. Point at the canonical collection instead of\n // claiming that a successful projected option is the failing value.\n field: diagnostic.field.replace(/\\.format_ids\\[\\d+\\]/g, '.format_options'),\n };\n}\n\n/** Protocol Error shape used for portable response-level projection advisories. */\nexport interface CanonicalProjectionError {\n code: ProjectionDiagnostic['code'];\n message: string;\n field: string;\n recovery: 'correctable';\n source: 'sdk';\n sdk_id: string;\n details: ProjectionDiagnostic['error']['details'];\n}\n\nfunction projectionErrorMessage(code: ProjectionDiagnostic['code']): string {\n switch (code) {\n case 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE':\n return 'Product has no format declaration representable on the canonical-only surface';\n case 'FORMAT_PROJECTION_FAILED':\n return 'Legacy creative format could not be projected to a canonical declaration';\n case 'FORMAT_DECLARATION_V1_AMBIGUOUS':\n return 'Canonical creative format has no unambiguous legacy declaration';\n case 'FORMAT_DECLARATION_V1_NOT_APPLICABLE':\n return 'Canonical-only creative format cannot be represented on a legacy format path';\n case 'CANONICAL_NOT_V1_TRANSLATABLE':\n return 'Canonical creative format has no legacy representation';\n case 'FORMAT_DECLARATION_V1_LOSSY_MULTI_SIZE':\n return 'Canonical multi-size format has incomplete legacy coverage';\n case 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED':\n return 'Redundant legacy creative identity has no canonical counterpart';\n }\n}\n\n/** Flatten the projector's internal diagnostic into the protocol `Error` shape. */\nexport function projectionDiagnosticToError(diagnostic: ProjectionDiagnostic): CanonicalProjectionError {\n return {\n code: diagnostic.code,\n message: projectionErrorMessage(diagnostic.code),\n field: diagnostic.field,\n recovery: 'correctable',\n source: diagnostic.source,\n sdk_id: diagnostic.sdk_id,\n details: diagnostic.error.details,\n } as CanonicalProjectionError;\n}\n\nfunction canonicalFormatsUnavailableForProduct(\n product: V1Product,\n reason: Extract<ProjectionDiagnostic, { code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE' }>['error']['details']['reason']\n): ProjectionDiagnostic {\n return {\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE',\n error: {\n details: {\n product_id: product.product_id,\n reason,\n },\n },\n };\n}\n\nfunction errorIdentity(value: Record<string, unknown>): string | undefined {\n if (typeof value.code !== 'string' || typeof value.field !== 'string') return undefined;\n try {\n return `${value.code}\\u0000${value.field}\\u0000${canonicalizeJson(value.details ?? null)}`;\n } catch {\n // Preserve unreadable third-party errors instead of falsely deduplicating.\n return undefined;\n }\n}\n\nfunction mergeProjectionErrors(existing: unknown, diagnostics: readonly ProjectionDiagnostic[]): unknown[] {\n const merged = Array.isArray(existing) ? [...existing] : [];\n const seen = new Set<string>();\n for (const value of merged) {\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue;\n const record = value as Record<string, unknown>;\n const key = errorIdentity(record);\n if (key) seen.add(key);\n }\n for (const diagnostic of diagnostics) {\n const error = projectionDiagnosticToError(diagnostic) as unknown as Record<string, unknown>;\n const key = errorIdentity(error)!;\n if (seen.has(key)) continue;\n seen.add(key);\n merged.push(error);\n }\n return merged;\n}\n\nfunction remapExistingProductErrors(\n existing: unknown,\n originalToOutputIndex: ReadonlyMap<number, number | undefined>,\n products: readonly V1Product[]\n): unknown {\n if (!Array.isArray(existing)) return existing;\n return existing.map(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const record = value as Record<string, unknown>;\n let issuesChanged = false;\n const issues = Array.isArray(record.issues)\n ? record.issues.map(issue => {\n if (!issue || typeof issue !== 'object' || Array.isArray(issue)) return issue;\n const issueRecord = issue as Record<string, unknown>;\n if (typeof issueRecord.pointer !== 'string') return issue;\n const pointerMatch = /^\\/products\\/(\\d+)(\\/.*)?$/.exec(issueRecord.pointer);\n if (!pointerMatch) return issue;\n const originalIssueIndex = Number(pointerMatch[1]);\n if (!originalToOutputIndex.has(originalIssueIndex)) return issue;\n const outputIssueIndex = originalToOutputIndex.get(originalIssueIndex);\n issuesChanged = true;\n return {\n ...issueRecord,\n pointer:\n outputIssueIndex === undefined ? '/products' : `/products/${outputIssueIndex}${pointerMatch[2] ?? ''}`,\n };\n })\n : record.issues;\n const withIssues = issuesChanged ? { ...record, issues } : record;\n if (typeof record.field !== 'string') return issuesChanged ? withIssues : value;\n const match = /^products\\[(\\d+)\\](.*)$/.exec(record.field);\n if (!match) return issuesChanged ? withIssues : value;\n const originalIndex = Number(match[1]);\n if (!originalToOutputIndex.has(originalIndex)) return issuesChanged ? withIssues : value;\n const outputIndex = originalToOutputIndex.get(originalIndex);\n if (outputIndex !== undefined) {\n return { ...withIssues, field: `products[${outputIndex}]${match[2] ?? ''}` };\n }\n const productId = products[originalIndex]?.product_id;\n const details =\n record.details && typeof record.details === 'object' && !Array.isArray(record.details)\n ? { ...(record.details as Record<string, unknown>) }\n : {};\n if (typeof productId === 'string' && details.product_id === undefined) details.product_id = productId;\n return { ...withIssues, field: 'products', ...(Object.keys(details).length > 0 ? { details } : {}) };\n });\n}\n\nfunction hasEmptyPlacementFormatOptions(product: CanonicalOnlyProduct<V1Product>): boolean {\n const placements = (product as Record<string, unknown>).placements;\n if (!Array.isArray(placements)) return false;\n return placements.some(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const options = (value as Record<string, unknown>).format_options;\n return Array.isArray(options) && options.length === 0;\n });\n}\n\n/**\n * A Product that has been augmented with `format_options[]` while\n * preserving the original `format_ids[]`. Carries the projection\n * diagnostics that were generated mapping each `format_id` so the\n * buyer can see what (if anything) didn't project cleanly.\n *\n * **Write-side bridge.** After picking a `format_options[i]` entry,\n * use {@link formatIdsFromOptions} (from `@adcp/sdk/v2/projection`)\n * to extract the `format_ids[]` value for a `create_media_buy`\n * package. Inlining `decl.v1_format_ref` works but bypasses the\n * fail-closed semantics (canonical_formats_only / inherently-v2\n * canonical → throw). The spec gap that forces this bridge is tracked\n * at adcontextprotocol/adcp#4842.\n *\n * @see formatIdsFromOptions\n * @see formatIdsForCapability\n */\nexport type V2AugmentedProduct<P> = P & {\n format_options: V2ProductFormatDeclaration[];\n};\n\n/**\n * Augment a single Product. Idempotent — when `format_options[]` is\n * already present (the seller is v2-native), passes the Product\n * through unchanged. Otherwise projects from `format_ids[]`.\n *\n * Returns `{ product, diagnostics }`. `diagnostics` is empty for a\n * clean projection; populated when individual format_ids don't have\n * a v2 mapping (catalog gap, structural unreachability, etc.).\n *\n * @see toCanonicalOnlyProduct — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function augmentProductWithFormatOptions<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: V2AugmentedProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n // Already v2-shaped (seller sent format_options directly) — pass through.\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n if (Array.isArray(existing)) {\n return {\n product: product as V2AugmentedProduct<P>,\n diagnostics: [],\n };\n }\n // v1 shape — project to add format_options[].\n if (!Array.isArray(product.format_ids)) {\n // Neither shape — nothing to project. Return as-is with an empty\n // format_options so the buyer doesn't have to special-case.\n return {\n product: { ...product, format_options: [] },\n diagnostics: [],\n };\n }\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n // Preserve the original product shape (especially format_ids); just\n // add format_options.\n return {\n product: {\n ...product,\n format_options: v2.format_options,\n },\n diagnostics,\n };\n}\n\n/**\n * Augment every Product in a `get_products` response with\n * `format_options[]`. Returns `{ response, diagnostics }` so callers\n * can surface projection diagnostics alongside the response's existing\n * `errors[]` array (or filter by `source: 'sdk'` to distinguish SDK\n * diagnostics from seller-emitted errors).\n *\n * Idempotent: if the seller is v2-native and every Product already\n * carries `format_options[]`, returns the response verbatim with no\n * diagnostics.\n *\n * @see toCanonicalOnlyResponse — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function withFormatOptions<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): { response: R & { products: V2AugmentedProduct<V1Product>[] }; diagnostics: ProjectionDiagnostic[] } {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics: [],\n };\n }\n const out: V2AugmentedProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n for (const p of response.products) {\n const { product, diagnostics: d } = augmentProductWithFormatOptions(p, options);\n out.push(product);\n diagnostics.push(...d);\n }\n return {\n response: { ...response, products: out } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics,\n };\n}\n\n/**\n * A Product reduced to the canonical creative-format surface:\n * `format_options[]` only, with the legacy `format_ids[]` removed. The\n * read-side counterpart to a fully-migrated consumer — naive downstream\n * code can no longer fall back to the stale `{ agent_url, id }` shape and\n * silently bypass the canonical model.\n */\nexport type CanonicalOnlyProduct<P> = Omit<P, 'format_ids'> & {\n format_ids?: never;\n format_options: CanonicalFormatDeclaration[];\n};\n\nfunction canonicalDeclarations(values: readonly V2ProductFormatDeclaration[]): CanonicalFormatDeclaration[] {\n return values.map(value => concealLegacyFormatRefs(value));\n}\n\nfunction canonicalPlacements(\n product: Record<string, unknown>,\n options: V1ToV2ProjectionOptions | undefined,\n diagnostics: ProjectionDiagnostic[]\n): unknown {\n if (!Array.isArray(product.placements)) return product.placements;\n return product.placements.map((value, placementIndex) => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const placement = value as Record<string, unknown>;\n const { format_ids: _drop, ...rest } = placement;\n void _drop;\n const hasLegacyFormats = Array.isArray(placement.format_ids);\n const hasCanonicalFormats = Array.isArray(placement.format_options);\n if (!hasLegacyFormats && !hasCanonicalFormats) return rest;\n\n const productId = typeof product.product_id === 'string' ? product.product_id : '(unknown)';\n const placementId = typeof placement.placement_id === 'string' ? placement.placement_id : String(placementIndex);\n const pseudoProduct = {\n product_id: `${productId}:placement:${placementId}`,\n name: typeof placement.name === 'string' ? placement.name : placementId,\n description: `Nested placement ${placementId}`,\n ...(hasLegacyFormats ? { format_ids: placement.format_ids } : {}),\n ...(hasCanonicalFormats ? { format_options: placement.format_options } : {}),\n } as unknown as V1Product;\n const projected = toCanonicalOnlyProduct(pseudoProduct, options);\n for (const diagnostic of projected.diagnostics) {\n diagnostics.push({\n ...diagnostic,\n field: diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${productId}].placements[${placementIndex}]`),\n });\n }\n return {\n ...rest,\n format_options: projected.product.format_options,\n };\n });\n}\n\n/**\n * Identity key for a `format_id` ref used by the coverage check.\n * Trailing-slash-insensitive on `agent_url` (folds the AAO host's slash /\n * no-slash forms, per `catalog.ts`'s `normalizeAgentUrl`), and includes the\n * dimensional discriminators so multi-size declarations sharing one\n * `{ agent_url, id }` but differing by size/duration are NOT collapsed —\n * the same key shape `write-side.ts` uses for v1 ref de-dup. Without the\n * size half, a `format_ids[]` entry for a size no `v1_format_ref` covers\n * would read as covered and be dropped silently.\n */\nfunction formatRefCoverageKey(ref: V1FormatId): string {\n const url = ref.agent_url && !ref.agent_url.endsWith('/') ? ref.agent_url + '/' : ref.agent_url;\n return `${url}::${ref.id}::${ref.width ?? ''}x${ref.height ?? ''}::${ref.duration_ms ?? ''}`;\n}\n\n/**\n * Project a single Product to the canonical-only shape: `format_options[]`\n * present, `format_ids[]` dropped.\n *\n * **Dropping legacy never silently loses a format.** Every input\n * `format_id` is either represented in the returned `format_options[]` or\n * surfaced in `diagnostics` — never discarded without a trace:\n *\n * - **v1-shaped input** (`format_ids[]`, no `format_options[]`): runs the\n * v1 → v2 projection. Mapped refs become `format_options[]`; any ref\n * the projection can't map is surfaced as `FORMAT_PROJECTION_FAILED`.\n * - **v2-native input** (`format_options[]` already present): keeps the\n * seller's canonical surface and drops the redundant v1 fallback. If a\n * legacy routing entry exists that no canonical option covers, it\n * surfaces a canonical-safe `LEGACY_FORMAT_ID_DROPPED_UNMAPPED`\n * diagnostic without echoing the routing identifier.\n * - **neither shape**: returns `format_options: []`; there is nothing to\n * project and nothing to lose.\n *\n * Pure and subtractive: unlike {@link augmentProductWithFormatOptions}\n * (which preserves `format_ids[]`), this drops it — the opt-in narrowing for\n * a consumer that has fully migrated. Complements the write-side\n * non-invertibility tracked at adcontextprotocol/adcp#4842 — this is the\n * read-side transparency half.\n */\nexport function toCanonicalOnlyProduct<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: CanonicalOnlyProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n\n // v2-native: the seller already sent format_options[]. Drop the\n // redundant v1 fallback, but flag any legacy ref no v1_format_ref covers.\n if (Array.isArray(existing)) {\n const formatOptions = existing as V2ProductFormatDeclaration[];\n const diagnostics: ProjectionDiagnostic[] = [];\n const inputIds = Array.isArray(product.format_ids) ? product.format_ids : [];\n if (inputIds.length > 0) {\n const covered = new Set<string>();\n for (const opt of formatOptions) {\n const refs = Array.isArray(opt?.v1_format_ref) ? opt.v1_format_ref : [];\n for (const ref of refs) covered.add(formatRefCoverageKey(ref));\n }\n for (let k = 0; k < inputIds.length; k++) {\n const fid = inputIds[k]!;\n if (!covered.has(formatRefCoverageKey(fid))) {\n diagnostics.push({\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED',\n error: {\n details: {\n product_id: product.product_id,\n resolution_failure: 'unmapped_legacy_format',\n },\n },\n });\n }\n }\n }\n const { format_ids: _dropV2, ...rest } = product as P & { format_ids?: unknown };\n void _dropV2;\n return {\n product: {\n ...rest,\n format_options: canonicalDeclarations(formatOptions),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // v1 shape: project. projectV1ProductToV2 already omits format_ids and\n // emits a diagnostic for every ref it couldn't map.\n if (Array.isArray(product.format_ids)) {\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n const { format_ids: _dropV1, ...rest } = product as P & { format_ids?: unknown };\n void _dropV1;\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: canonicalDeclarations(v2.format_options),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // Neither shape — nothing to project, nothing to lose.\n const { format_ids: _dropNone, ...rest } = product as P & { format_ids?: unknown };\n void _dropNone;\n const diagnostics: ProjectionDiagnostic[] = [];\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: [],\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n}\n\n/**\n * Reduce every Product in a `get_products` response to the canonical-only\n * shape — `format_options[]` present, `format_ids[]` dropped. Returns\n * `{ response, diagnostics }` so callers surface projection diagnostics\n * alongside the response's existing `errors[]`.\n *\n * Response-level counterpart to {@link toCanonicalOnlyProduct}; same\n * fail-closed guarantee, aggregated across products. A wholly unmappable\n * legacy product cannot be represented as a canonical Product because the\n * protocol requires `format_options` to contain at least one declaration. It\n * is therefore omitted from the canonical list and surfaced through the\n * response's portable `errors[]` plus the SDK convenience diagnostics. A\n * partially mappable product remains with its mapped options and advisories\n * for the refs that could not be projected.\n */\nexport function toCanonicalOnlyResponse<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): {\n response: Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] };\n diagnostics: ProjectionDiagnostic[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & {\n products: CanonicalOnlyProduct<V1Product>[];\n errors?: unknown[];\n },\n diagnostics: [],\n };\n }\n const out: CanonicalOnlyProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n const originalToOutputIndex = new Map<number, number | undefined>();\n for (let productIndex = 0; productIndex < response.products.length; productIndex++) {\n const p = response.products[productIndex]!;\n const { product, diagnostics: rawDiagnostics } = toCanonicalOnlyProduct(p, options);\n const hasEmptyPlacement = hasEmptyPlacementFormatOptions(product);\n const keep = product.format_options.length > 0 && !hasEmptyPlacement;\n const outputIndex = keep ? out.length : undefined;\n originalToOutputIndex.set(productIndex, outputIndex);\n const d = rawDiagnostics.map(diagnostic => ({\n ...diagnostic,\n field: keep ? diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${outputIndex}]`) : 'products',\n error: keep\n ? diagnostic.error\n : {\n details: {\n ...diagnostic.error.details,\n product_id: p.product_id,\n },\n },\n })) as ProjectionDiagnostic[];\n if (!keep && d.length === 0) {\n const reason = hasEmptyPlacement\n ? 'nested_placement_format_list_empty'\n : Array.isArray((p as Record<string, unknown>).format_options)\n ? 'canonical_format_list_empty'\n : Array.isArray(p.format_ids)\n ? 'legacy_format_list_empty'\n : 'missing_format_declaration';\n d.push({\n ...canonicalFormatsUnavailableForProduct(p, reason),\n field: 'products',\n });\n }\n diagnostics.push(...d);\n if (keep) out.push(product);\n }\n const remappedExistingErrors = remapExistingProductErrors(\n (response as { errors?: unknown }).errors,\n originalToOutputIndex,\n response.products\n );\n const errors = mergeProjectionErrors(remappedExistingErrors, diagnostics);\n return {\n response: {\n ...response,\n products: out,\n ...(errors.length > 0 ? { errors } : {}),\n } as Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] },\n diagnostics,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,sBAAqC;AAErC,qBAAgC;AAChC,iBAAiD;AACjD,6BAAwC;AAGxC,MAAM,SAAS,aAAa,8BAAe;AAE3C,SAAS,oBAAoB,YAAwD;AACnF,SAAO;AAAA,IACL,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,IAKH,OAAO,WAAW,MAAM,QAAQ,wBAAwB,iBAAiB;AAAA,EAC3E;AACF;AAaA,SAAS,uBAAuB,MAA4C;AAC1E,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAA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