@adcp/sdk 12.1.0 → 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 (464) 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/authorization-required.d.mts +3 -0
  18. package/dist/lib/auth/oauth/authorization-required.d.ts +3 -0
  19. package/dist/lib/auth/oauth/authorization-required.d.ts.map +1 -1
  20. package/dist/lib/auth/oauth/authorization-required.js +12 -9
  21. package/dist/lib/auth/oauth/authorization-required.js.map +1 -1
  22. package/dist/lib/auth/oauth/authorization-required.mjs +12 -9
  23. package/dist/lib/auth/oauth/authorization-required.mjs.map +1 -1
  24. package/dist/lib/auth/oauth/provider-cache.d.mts +7 -0
  25. package/dist/lib/auth/oauth/provider-cache.d.ts +8 -0
  26. package/dist/lib/auth/oauth/provider-cache.d.ts.map +1 -0
  27. package/dist/lib/auth/oauth/provider-cache.js +44 -0
  28. package/dist/lib/auth/oauth/provider-cache.js.map +1 -0
  29. package/dist/lib/auth/oauth/provider-cache.mjs +19 -0
  30. package/dist/lib/auth/oauth/provider-cache.mjs.map +1 -0
  31. package/dist/lib/conformance/invariants/uniformError.js +1 -1
  32. package/dist/lib/conformance/invariants/uniformError.js.map +1 -1
  33. package/dist/lib/conformance/invariants/uniformError.mjs +1 -1
  34. package/dist/lib/conformance/invariants/uniformError.mjs.map +1 -1
  35. package/dist/lib/conformance/runners.js +1 -1
  36. package/dist/lib/conformance/runners.js.map +1 -1
  37. package/dist/lib/conformance/runners.mjs +1 -1
  38. package/dist/lib/conformance/runners.mjs.map +1 -1
  39. package/dist/lib/conformance/seeder.js +5 -5
  40. package/dist/lib/conformance/seeder.js.map +1 -1
  41. package/dist/lib/conformance/seeder.mjs +5 -5
  42. package/dist/lib/conformance/seeder.mjs.map +1 -1
  43. package/dist/lib/core/ADCPMultiAgentClient.d.mts +26 -29
  44. package/dist/lib/core/ADCPMultiAgentClient.d.ts +26 -29
  45. package/dist/lib/core/ADCPMultiAgentClient.d.ts.map +1 -1
  46. package/dist/lib/core/ADCPMultiAgentClient.js +27 -19
  47. package/dist/lib/core/ADCPMultiAgentClient.js.map +1 -1
  48. package/dist/lib/core/ADCPMultiAgentClient.mjs +27 -19
  49. package/dist/lib/core/ADCPMultiAgentClient.mjs.map +1 -1
  50. package/dist/lib/core/AgentClient.d.mts +148 -138
  51. package/dist/lib/core/AgentClient.d.ts +148 -138
  52. package/dist/lib/core/AgentClient.d.ts.map +1 -1
  53. package/dist/lib/core/AgentClient.js +174 -85
  54. package/dist/lib/core/AgentClient.js.map +1 -1
  55. package/dist/lib/core/AgentClient.mjs +174 -85
  56. package/dist/lib/core/AgentClient.mjs.map +1 -1
  57. package/dist/lib/core/AsyncHandler.d.mts +18 -16
  58. package/dist/lib/core/AsyncHandler.d.ts +18 -16
  59. package/dist/lib/core/AsyncHandler.d.ts.map +1 -1
  60. package/dist/lib/core/AsyncHandler.js +22 -1
  61. package/dist/lib/core/AsyncHandler.js.map +1 -1
  62. package/dist/lib/core/AsyncHandler.mjs +22 -1
  63. package/dist/lib/core/AsyncHandler.mjs.map +1 -1
  64. package/dist/lib/core/ConversationTypes.d.mts +6 -2
  65. package/dist/lib/core/ConversationTypes.d.ts +6 -2
  66. package/dist/lib/core/ConversationTypes.d.ts.map +1 -1
  67. package/dist/lib/core/ConversationTypes.js.map +1 -1
  68. package/dist/lib/core/CreativeAgentClient.d.mts +41 -17
  69. package/dist/lib/core/CreativeAgentClient.d.ts +41 -17
  70. package/dist/lib/core/CreativeAgentClient.d.ts.map +1 -1
  71. package/dist/lib/core/CreativeAgentClient.js +39 -12
  72. package/dist/lib/core/CreativeAgentClient.js.map +1 -1
  73. package/dist/lib/core/CreativeAgentClient.mjs +39 -12
  74. package/dist/lib/core/CreativeAgentClient.mjs.map +1 -1
  75. package/dist/lib/core/SingleAgentClient.d.mts +129 -52
  76. package/dist/lib/core/SingleAgentClient.d.ts +129 -52
  77. package/dist/lib/core/SingleAgentClient.d.ts.map +1 -1
  78. package/dist/lib/core/SingleAgentClient.js +1748 -218
  79. package/dist/lib/core/SingleAgentClient.js.map +1 -1
  80. package/dist/lib/core/SingleAgentClient.mjs +1758 -218
  81. package/dist/lib/core/SingleAgentClient.mjs.map +1 -1
  82. package/dist/lib/core/TaskExecutor.d.mts +9 -0
  83. package/dist/lib/core/TaskExecutor.d.ts +9 -0
  84. package/dist/lib/core/TaskExecutor.d.ts.map +1 -1
  85. package/dist/lib/core/TaskExecutor.js +137 -44
  86. package/dist/lib/core/TaskExecutor.js.map +1 -1
  87. package/dist/lib/core/TaskExecutor.mjs +137 -44
  88. package/dist/lib/core/TaskExecutor.mjs.map +1 -1
  89. package/dist/lib/index.d.mts +111 -17
  90. package/dist/lib/index.d.ts +111 -17
  91. package/dist/lib/index.d.ts.map +1 -1
  92. package/dist/lib/index.js +94 -94
  93. package/dist/lib/index.js.map +1 -1
  94. package/dist/lib/index.mjs +93 -94
  95. package/dist/lib/index.mjs.map +1 -1
  96. package/dist/lib/net/ssrf-fetch.d.mts +13 -1
  97. package/dist/lib/net/ssrf-fetch.d.ts +13 -1
  98. package/dist/lib/net/ssrf-fetch.d.ts.map +1 -1
  99. package/dist/lib/net/ssrf-fetch.js +14 -7
  100. package/dist/lib/net/ssrf-fetch.js.map +1 -1
  101. package/dist/lib/net/ssrf-fetch.mjs +14 -7
  102. package/dist/lib/net/ssrf-fetch.mjs.map +1 -1
  103. package/dist/lib/protocols/a2a.d.mts +2 -2
  104. package/dist/lib/protocols/a2a.d.ts +2 -2
  105. package/dist/lib/protocols/a2a.d.ts.map +1 -1
  106. package/dist/lib/protocols/a2a.js +14 -9
  107. package/dist/lib/protocols/a2a.js.map +1 -1
  108. package/dist/lib/protocols/a2a.mjs +14 -9
  109. package/dist/lib/protocols/a2a.mjs.map +1 -1
  110. package/dist/lib/protocols/index.d.mts +20 -3
  111. package/dist/lib/protocols/index.d.ts +20 -3
  112. package/dist/lib/protocols/index.d.ts.map +1 -1
  113. package/dist/lib/protocols/index.js +44 -31
  114. package/dist/lib/protocols/index.js.map +1 -1
  115. package/dist/lib/protocols/index.mjs +44 -32
  116. package/dist/lib/protocols/index.mjs.map +1 -1
  117. package/dist/lib/protocols/mcp-modern.d.ts.map +1 -1
  118. package/dist/lib/protocols/mcp-modern.js +87 -12
  119. package/dist/lib/protocols/mcp-modern.js.map +1 -1
  120. package/dist/lib/protocols/mcp-modern.mjs +89 -12
  121. package/dist/lib/protocols/mcp-modern.mjs.map +1 -1
  122. package/dist/lib/protocols/mcp-tasks.d.mts +3 -0
  123. package/dist/lib/protocols/mcp-tasks.d.ts +3 -0
  124. package/dist/lib/protocols/mcp-tasks.d.ts.map +1 -1
  125. package/dist/lib/protocols/mcp-tasks.js +21 -11
  126. package/dist/lib/protocols/mcp-tasks.js.map +1 -1
  127. package/dist/lib/protocols/mcp-tasks.mjs +21 -11
  128. package/dist/lib/protocols/mcp-tasks.mjs.map +1 -1
  129. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  130. package/dist/lib/server/create-adcp-server.d.mts +6 -0
  131. package/dist/lib/server/create-adcp-server.d.ts +6 -0
  132. package/dist/lib/server/create-adcp-server.d.ts.map +1 -1
  133. package/dist/lib/server/create-adcp-server.js +295 -48
  134. package/dist/lib/server/create-adcp-server.js.map +1 -1
  135. package/dist/lib/server/create-adcp-server.mjs +301 -50
  136. package/dist/lib/server/create-adcp-server.mjs.map +1 -1
  137. package/dist/lib/server/decisioning/assembly-helpers.d.mts +27 -13
  138. package/dist/lib/server/decisioning/assembly-helpers.d.ts +27 -13
  139. package/dist/lib/server/decisioning/assembly-helpers.d.ts.map +1 -1
  140. package/dist/lib/server/decisioning/assembly-helpers.js +136 -14
  141. package/dist/lib/server/decisioning/assembly-helpers.js.map +1 -1
  142. package/dist/lib/server/decisioning/assembly-helpers.mjs +134 -13
  143. package/dist/lib/server/decisioning/assembly-helpers.mjs.map +1 -1
  144. package/dist/lib/server/decisioning/index.d.mts +13 -12
  145. package/dist/lib/server/decisioning/index.d.ts +13 -12
  146. package/dist/lib/server/decisioning/index.d.ts.map +1 -1
  147. package/dist/lib/server/decisioning/index.js +6 -0
  148. package/dist/lib/server/decisioning/index.js.map +1 -1
  149. package/dist/lib/server/decisioning/index.mjs +9 -3
  150. package/dist/lib/server/decisioning/index.mjs.map +1 -1
  151. package/dist/lib/server/decisioning/list-helpers.d.mts +13 -3
  152. package/dist/lib/server/decisioning/list-helpers.d.ts +13 -3
  153. package/dist/lib/server/decisioning/list-helpers.d.ts.map +1 -1
  154. package/dist/lib/server/decisioning/list-helpers.js +13 -3
  155. package/dist/lib/server/decisioning/list-helpers.js.map +1 -1
  156. package/dist/lib/server/decisioning/list-helpers.mjs +11 -2
  157. package/dist/lib/server/decisioning/list-helpers.mjs.map +1 -1
  158. package/dist/lib/server/decisioning/manifest-helpers.d.mts +5 -3
  159. package/dist/lib/server/decisioning/manifest-helpers.d.ts +5 -3
  160. package/dist/lib/server/decisioning/manifest-helpers.d.ts.map +1 -1
  161. package/dist/lib/server/decisioning/manifest-helpers.js.map +1 -1
  162. package/dist/lib/server/decisioning/manifest-helpers.mjs.map +1 -1
  163. package/dist/lib/server/decisioning/proposal/dispatch.d.mts +2 -2
  164. package/dist/lib/server/decisioning/proposal/dispatch.d.ts +2 -2
  165. package/dist/lib/server/decisioning/proposal/dispatch.d.ts.map +1 -1
  166. package/dist/lib/server/decisioning/proposal/dispatch.js.map +1 -1
  167. package/dist/lib/server/decisioning/proposal/dispatch.mjs.map +1 -1
  168. package/dist/lib/server/decisioning/proposal/index.d.mts +1 -1
  169. package/dist/lib/server/decisioning/proposal/index.d.ts +1 -1
  170. package/dist/lib/server/decisioning/proposal/index.d.ts.map +1 -1
  171. package/dist/lib/server/decisioning/proposal/index.js.map +1 -1
  172. package/dist/lib/server/decisioning/proposal/index.mjs.map +1 -1
  173. package/dist/lib/server/decisioning/proposal/lifecycle.d.mts +3 -2
  174. package/dist/lib/server/decisioning/proposal/lifecycle.d.ts +3 -2
  175. package/dist/lib/server/decisioning/proposal/lifecycle.d.ts.map +1 -1
  176. package/dist/lib/server/decisioning/proposal/lifecycle.js.map +1 -1
  177. package/dist/lib/server/decisioning/proposal/lifecycle.mjs.map +1 -1
  178. package/dist/lib/server/decisioning/proposal/mock-manager.d.mts +3 -3
  179. package/dist/lib/server/decisioning/proposal/mock-manager.d.ts +3 -3
  180. package/dist/lib/server/decisioning/proposal/mock-manager.d.ts.map +1 -1
  181. package/dist/lib/server/decisioning/proposal/mock-manager.js.map +1 -1
  182. package/dist/lib/server/decisioning/proposal/mock-manager.mjs.map +1 -1
  183. package/dist/lib/server/decisioning/proposal/types.d.mts +10 -6
  184. package/dist/lib/server/decisioning/proposal/types.d.ts +10 -6
  185. package/dist/lib/server/decisioning/proposal/types.d.ts.map +1 -1
  186. package/dist/lib/server/decisioning/proposal/types.js.map +1 -1
  187. package/dist/lib/server/decisioning/proposal/types.mjs.map +1 -1
  188. package/dist/lib/server/decisioning/runtime/from-platform.d.mts +21 -2
  189. package/dist/lib/server/decisioning/runtime/from-platform.d.ts +21 -2
  190. package/dist/lib/server/decisioning/runtime/from-platform.d.ts.map +1 -1
  191. package/dist/lib/server/decisioning/runtime/from-platform.js +754 -81
  192. package/dist/lib/server/decisioning/runtime/from-platform.js.map +1 -1
  193. package/dist/lib/server/decisioning/runtime/from-platform.mjs +763 -81
  194. package/dist/lib/server/decisioning/runtime/from-platform.mjs.map +1 -1
  195. package/dist/lib/server/decisioning/specialisms/brand-rights.d.mts +9 -9
  196. package/dist/lib/server/decisioning/specialisms/brand-rights.d.ts +9 -9
  197. package/dist/lib/server/decisioning/specialisms/brand-rights.d.ts.map +1 -1
  198. package/dist/lib/server/decisioning/specialisms/brand-rights.js.map +1 -1
  199. package/dist/lib/server/decisioning/specialisms/content-standards.d.mts +16 -16
  200. package/dist/lib/server/decisioning/specialisms/content-standards.d.ts +16 -16
  201. package/dist/lib/server/decisioning/specialisms/content-standards.d.ts.map +1 -1
  202. package/dist/lib/server/decisioning/specialisms/content-standards.js.map +1 -1
  203. package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.mts +15 -13
  204. package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.ts +15 -13
  205. package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.ts.map +1 -1
  206. package/dist/lib/server/decisioning/specialisms/creative-ad-server.js.map +1 -1
  207. package/dist/lib/server/decisioning/specialisms/creative.d.mts +12 -11
  208. package/dist/lib/server/decisioning/specialisms/creative.d.ts +12 -11
  209. package/dist/lib/server/decisioning/specialisms/creative.d.ts.map +1 -1
  210. package/dist/lib/server/decisioning/specialisms/creative.js.map +1 -1
  211. package/dist/lib/server/decisioning/specialisms/sales.d.mts +25 -15
  212. package/dist/lib/server/decisioning/specialisms/sales.d.ts +25 -15
  213. package/dist/lib/server/decisioning/specialisms/sales.d.ts.map +1 -1
  214. package/dist/lib/server/decisioning/specialisms/sales.js.map +1 -1
  215. package/dist/lib/server/index.d.mts +3 -3
  216. package/dist/lib/server/index.d.ts +3 -3
  217. package/dist/lib/server/index.d.ts.map +1 -1
  218. package/dist/lib/server/index.js +72 -72
  219. package/dist/lib/server/index.js.map +1 -1
  220. package/dist/lib/server/index.mjs +36 -36
  221. package/dist/lib/server/index.mjs.map +1 -1
  222. package/dist/lib/server/legacy/v5/index.d.mts +1 -0
  223. package/dist/lib/server/legacy/v5/index.d.ts +1 -0
  224. package/dist/lib/server/legacy/v5/index.d.ts.map +1 -1
  225. package/dist/lib/server/legacy/v5/index.js +74 -1
  226. package/dist/lib/server/legacy/v5/index.js.map +1 -1
  227. package/dist/lib/server/legacy/v5/index.mjs +75 -1
  228. package/dist/lib/server/legacy/v5/index.mjs.map +1 -1
  229. package/dist/lib/server/responses.d.mts +2 -2
  230. package/dist/lib/server/responses.d.ts +2 -2
  231. package/dist/lib/server/responses.js.map +1 -1
  232. package/dist/lib/server/responses.mjs.map +1 -1
  233. package/dist/lib/testing/client.d.ts.map +1 -1
  234. package/dist/lib/testing/client.js +13 -5
  235. package/dist/lib/testing/client.js.map +1 -1
  236. package/dist/lib/testing/client.mjs +13 -5
  237. package/dist/lib/testing/client.mjs.map +1 -1
  238. package/dist/lib/testing/compliance/comply.d.mts +1 -1
  239. package/dist/lib/testing/compliance/comply.d.ts +1 -1
  240. package/dist/lib/testing/compliance/comply.d.ts.map +1 -1
  241. package/dist/lib/testing/compliance/comply.js +16 -6
  242. package/dist/lib/testing/compliance/comply.js.map +1 -1
  243. package/dist/lib/testing/compliance/comply.mjs +16 -6
  244. package/dist/lib/testing/compliance/comply.mjs.map +1 -1
  245. package/dist/lib/testing/scenarios/brand-rights.js +6 -6
  246. package/dist/lib/testing/scenarios/brand-rights.js.map +1 -1
  247. package/dist/lib/testing/scenarios/brand-rights.mjs +6 -6
  248. package/dist/lib/testing/scenarios/brand-rights.mjs.map +1 -1
  249. package/dist/lib/testing/scenarios/creative.js +7 -7
  250. package/dist/lib/testing/scenarios/creative.js.map +1 -1
  251. package/dist/lib/testing/scenarios/creative.mjs +7 -7
  252. package/dist/lib/testing/scenarios/creative.mjs.map +1 -1
  253. package/dist/lib/testing/scenarios/discovery.js +2 -2
  254. package/dist/lib/testing/scenarios/discovery.js.map +1 -1
  255. package/dist/lib/testing/scenarios/discovery.mjs +2 -2
  256. package/dist/lib/testing/scenarios/discovery.mjs.map +1 -1
  257. package/dist/lib/testing/scenarios/edge-cases.js +11 -11
  258. package/dist/lib/testing/scenarios/edge-cases.js.map +1 -1
  259. package/dist/lib/testing/scenarios/edge-cases.mjs +11 -11
  260. package/dist/lib/testing/scenarios/edge-cases.mjs.map +1 -1
  261. package/dist/lib/testing/scenarios/governance.d.ts.map +1 -1
  262. package/dist/lib/testing/scenarios/governance.js +16 -22
  263. package/dist/lib/testing/scenarios/governance.js.map +1 -1
  264. package/dist/lib/testing/scenarios/governance.mjs +16 -22
  265. package/dist/lib/testing/scenarios/governance.mjs.map +1 -1
  266. package/dist/lib/testing/scenarios/media-buy.js +5 -5
  267. package/dist/lib/testing/scenarios/media-buy.js.map +1 -1
  268. package/dist/lib/testing/scenarios/media-buy.mjs +5 -5
  269. package/dist/lib/testing/scenarios/media-buy.mjs.map +1 -1
  270. package/dist/lib/testing/scenarios/schema-compliance.js +1 -1
  271. package/dist/lib/testing/scenarios/schema-compliance.js.map +1 -1
  272. package/dist/lib/testing/scenarios/schema-compliance.mjs +1 -1
  273. package/dist/lib/testing/scenarios/schema-compliance.mjs.map +1 -1
  274. package/dist/lib/testing/scenarios/trusted-match.d.ts.map +1 -1
  275. package/dist/lib/testing/scenarios/trusted-match.js +4 -3
  276. package/dist/lib/testing/scenarios/trusted-match.js.map +1 -1
  277. package/dist/lib/testing/scenarios/trusted-match.mjs +4 -3
  278. package/dist/lib/testing/scenarios/trusted-match.mjs.map +1 -1
  279. package/dist/lib/testing/storyboard/probes.d.mts +6 -0
  280. package/dist/lib/testing/storyboard/probes.d.ts +6 -0
  281. package/dist/lib/testing/storyboard/probes.d.ts.map +1 -1
  282. package/dist/lib/testing/storyboard/probes.js +16 -5
  283. package/dist/lib/testing/storyboard/probes.js.map +1 -1
  284. package/dist/lib/testing/storyboard/probes.mjs +16 -5
  285. package/dist/lib/testing/storyboard/probes.mjs.map +1 -1
  286. package/dist/lib/testing/storyboard/runner.d.ts.map +1 -1
  287. package/dist/lib/testing/storyboard/runner.js +6 -2
  288. package/dist/lib/testing/storyboard/runner.js.map +1 -1
  289. package/dist/lib/testing/storyboard/runner.mjs +6 -2
  290. package/dist/lib/testing/storyboard/runner.mjs.map +1 -1
  291. package/dist/lib/testing/storyboard/shape-drift-hints.d.mts +3 -4
  292. package/dist/lib/testing/storyboard/shape-drift-hints.d.ts +3 -4
  293. package/dist/lib/testing/storyboard/shape-drift-hints.d.ts.map +1 -1
  294. package/dist/lib/testing/storyboard/shape-drift-hints.js +27 -27
  295. package/dist/lib/testing/storyboard/shape-drift-hints.js.map +1 -1
  296. package/dist/lib/testing/storyboard/shape-drift-hints.mjs +27 -27
  297. package/dist/lib/testing/storyboard/shape-drift-hints.mjs.map +1 -1
  298. package/dist/lib/testing/storyboard/task-map.d.ts.map +1 -1
  299. package/dist/lib/testing/storyboard/task-map.js +43 -5
  300. package/dist/lib/testing/storyboard/task-map.js.map +1 -1
  301. package/dist/lib/testing/storyboard/task-map.mjs +43 -5
  302. package/dist/lib/testing/storyboard/task-map.mjs.map +1 -1
  303. package/dist/lib/testing/test-helpers.d.mts +2 -2
  304. package/dist/lib/testing/test-helpers.d.ts +2 -2
  305. package/dist/lib/testing/test-helpers.js.map +1 -1
  306. package/dist/lib/testing/test-helpers.mjs.map +1 -1
  307. package/dist/lib/testing/types.d.mts +7 -1
  308. package/dist/lib/testing/types.d.ts +7 -1
  309. package/dist/lib/testing/types.d.ts.map +1 -1
  310. package/dist/lib/testing/types.js.map +1 -1
  311. package/dist/lib/types/adcp.d.mts +14 -14
  312. package/dist/lib/types/adcp.d.ts +14 -14
  313. package/dist/lib/types/adcp.d.ts.map +1 -1
  314. package/dist/lib/types/adcp.js.map +1 -1
  315. package/dist/lib/types/adcp.mjs.map +1 -1
  316. package/dist/lib/types/index.d.mts +2 -2
  317. package/dist/lib/types/index.d.ts +2 -2
  318. package/dist/lib/types/index.d.ts.map +1 -1
  319. package/dist/lib/types/index.js.map +1 -1
  320. package/dist/lib/types/index.mjs.map +1 -1
  321. package/dist/lib/utils/capabilities.d.mts +6 -0
  322. package/dist/lib/utils/capabilities.d.ts +6 -0
  323. package/dist/lib/utils/capabilities.d.ts.map +1 -1
  324. package/dist/lib/utils/capabilities.js +4 -0
  325. package/dist/lib/utils/capabilities.js.map +1 -1
  326. package/dist/lib/utils/capabilities.mjs +4 -0
  327. package/dist/lib/utils/capabilities.mjs.map +1 -1
  328. package/dist/lib/utils/creative-delivery.d.mts +52 -10
  329. package/dist/lib/utils/creative-delivery.d.ts +52 -10
  330. package/dist/lib/utils/creative-delivery.d.ts.map +1 -1
  331. package/dist/lib/utils/creative-delivery.js +104 -9
  332. package/dist/lib/utils/creative-delivery.js.map +1 -1
  333. package/dist/lib/utils/creative-delivery.mjs +104 -8
  334. package/dist/lib/utils/creative-delivery.mjs.map +1 -1
  335. package/dist/lib/utils/format-assets.d.mts +41 -38
  336. package/dist/lib/utils/format-assets.d.ts +41 -38
  337. package/dist/lib/utils/format-assets.d.ts.map +1 -1
  338. package/dist/lib/utils/format-assets.js +3 -1
  339. package/dist/lib/utils/format-assets.js.map +1 -1
  340. package/dist/lib/utils/format-assets.mjs +3 -1
  341. package/dist/lib/utils/format-assets.mjs.map +1 -1
  342. package/dist/lib/utils/index.d.mts +8 -8
  343. package/dist/lib/utils/index.d.ts +8 -8
  344. package/dist/lib/utils/index.d.ts.map +1 -1
  345. package/dist/lib/utils/index.js +11 -9
  346. package/dist/lib/utils/index.js.map +1 -1
  347. package/dist/lib/utils/index.mjs +9 -8
  348. package/dist/lib/utils/index.mjs.map +1 -1
  349. package/dist/lib/utils/preview-utils.d.mts +11 -8
  350. package/dist/lib/utils/preview-utils.d.ts +11 -8
  351. package/dist/lib/utils/preview-utils.d.ts.map +1 -1
  352. package/dist/lib/utils/preview-utils.js +4 -4
  353. package/dist/lib/utils/preview-utils.js.map +1 -1
  354. package/dist/lib/utils/preview-utils.mjs +3 -3
  355. package/dist/lib/utils/preview-utils.mjs.map +1 -1
  356. package/dist/lib/utils/tool-request-schemas.d.mts +2 -2
  357. package/dist/lib/utils/tool-request-schemas.d.ts +2 -2
  358. package/dist/lib/v2/projection/aao-reference-formats.json +492 -0
  359. package/dist/lib/v2/projection/augment-response.d.mts +31 -11
  360. package/dist/lib/v2/projection/augment-response.d.ts +31 -11
  361. package/dist/lib/v2/projection/augment-response.d.ts.map +1 -1
  362. package/dist/lib/v2/projection/augment-response.js +233 -27
  363. package/dist/lib/v2/projection/augment-response.js.map +1 -1
  364. package/dist/lib/v2/projection/augment-response.mjs +232 -27
  365. package/dist/lib/v2/projection/augment-response.mjs.map +1 -1
  366. package/dist/lib/v2/projection/builders.d.mts +7 -6
  367. package/dist/lib/v2/projection/builders.d.ts +7 -6
  368. package/dist/lib/v2/projection/builders.d.ts.map +1 -1
  369. package/dist/lib/v2/projection/builders.js +11 -8
  370. package/dist/lib/v2/projection/builders.js.map +1 -1
  371. package/dist/lib/v2/projection/builders.mjs +9 -6
  372. package/dist/lib/v2/projection/builders.mjs.map +1 -1
  373. package/dist/lib/v2/projection/catalog-snapshot.d.mts +47 -0
  374. package/dist/lib/v2/projection/catalog-snapshot.d.ts +48 -0
  375. package/dist/lib/v2/projection/catalog-snapshot.d.ts.map +1 -0
  376. package/dist/lib/v2/projection/catalog-snapshot.js +291 -0
  377. package/dist/lib/v2/projection/catalog-snapshot.js.map +1 -0
  378. package/dist/lib/v2/projection/catalog-snapshot.mjs +265 -0
  379. package/dist/lib/v2/projection/catalog-snapshot.mjs.map +1 -0
  380. package/dist/lib/v2/projection/catalog.d.mts +23 -2
  381. package/dist/lib/v2/projection/catalog.d.ts +23 -2
  382. package/dist/lib/v2/projection/catalog.d.ts.map +1 -1
  383. package/dist/lib/v2/projection/catalog.js +34 -10
  384. package/dist/lib/v2/projection/catalog.js.map +1 -1
  385. package/dist/lib/v2/projection/catalog.mjs +33 -10
  386. package/dist/lib/v2/projection/catalog.mjs.map +1 -1
  387. package/dist/lib/v2/projection/creative-delivery.d.mts +157 -0
  388. package/dist/lib/v2/projection/creative-delivery.d.ts +158 -0
  389. package/dist/lib/v2/projection/creative-delivery.d.ts.map +1 -0
  390. package/dist/lib/v2/projection/creative-delivery.js +967 -0
  391. package/dist/lib/v2/projection/creative-delivery.js.map +1 -0
  392. package/dist/lib/v2/projection/creative-delivery.mjs +941 -0
  393. package/dist/lib/v2/projection/creative-delivery.mjs.map +1 -0
  394. package/dist/lib/v2/projection/index.d.mts +8 -6
  395. package/dist/lib/v2/projection/index.d.ts +8 -6
  396. package/dist/lib/v2/projection/index.d.ts.map +1 -1
  397. package/dist/lib/v2/projection/index.js +26 -4
  398. package/dist/lib/v2/projection/index.js.map +1 -1
  399. package/dist/lib/v2/projection/index.mjs +28 -4
  400. package/dist/lib/v2/projection/index.mjs.map +1 -1
  401. package/dist/lib/v2/projection/legacy-metadata.d.mts +21 -0
  402. package/dist/lib/v2/projection/legacy-metadata.d.ts +22 -0
  403. package/dist/lib/v2/projection/legacy-metadata.d.ts.map +1 -0
  404. package/dist/lib/v2/projection/legacy-metadata.js +73 -0
  405. package/dist/lib/v2/projection/legacy-metadata.js.map +1 -0
  406. package/dist/lib/v2/projection/legacy-metadata.mjs +45 -0
  407. package/dist/lib/v2/projection/legacy-metadata.mjs.map +1 -0
  408. package/dist/lib/v2/projection/types.d.mts +29 -23
  409. package/dist/lib/v2/projection/types.d.ts +29 -23
  410. package/dist/lib/v2/projection/types.d.ts.map +1 -1
  411. package/dist/lib/v2/projection/types.js.map +1 -1
  412. package/dist/lib/v2/projection/v1-to-v2.d.mts +29 -6
  413. package/dist/lib/v2/projection/v1-to-v2.d.ts +29 -6
  414. package/dist/lib/v2/projection/v1-to-v2.d.ts.map +1 -1
  415. package/dist/lib/v2/projection/v1-to-v2.js +218 -9
  416. package/dist/lib/v2/projection/v1-to-v2.js.map +1 -1
  417. package/dist/lib/v2/projection/v1-to-v2.mjs +219 -10
  418. package/dist/lib/v2/projection/v1-to-v2.mjs.map +1 -1
  419. package/dist/lib/v2/projection/v2-to-v1.d.mts +31 -2
  420. package/dist/lib/v2/projection/v2-to-v1.d.ts +31 -2
  421. package/dist/lib/v2/projection/v2-to-v1.d.ts.map +1 -1
  422. package/dist/lib/v2/projection/v2-to-v1.js +138 -7
  423. package/dist/lib/v2/projection/v2-to-v1.js.map +1 -1
  424. package/dist/lib/v2/projection/v2-to-v1.mjs +135 -6
  425. package/dist/lib/v2/projection/v2-to-v1.mjs.map +1 -1
  426. package/dist/lib/v2/projection/write-side.d.mts +12 -13
  427. package/dist/lib/v2/projection/write-side.d.ts +12 -13
  428. package/dist/lib/v2/projection/write-side.d.ts.map +1 -1
  429. package/dist/lib/v2/projection/write-side.js +16 -12
  430. package/dist/lib/v2/projection/write-side.js.map +1 -1
  431. package/dist/lib/v2/projection/write-side.mjs +16 -12
  432. package/dist/lib/v2/projection/write-side.mjs.map +1 -1
  433. package/dist/lib/version.d.mts +3 -3
  434. package/dist/lib/version.d.ts +3 -3
  435. package/dist/lib/version.d.ts.map +1 -1
  436. package/dist/lib/version.js +3 -3
  437. package/dist/lib/version.js.map +1 -1
  438. package/dist/lib/version.mjs +3 -3
  439. package/dist/lib/version.mjs.map +1 -1
  440. package/docs/guides/BUILD-AN-AGENT.md +7 -2
  441. package/docs/guides/PREVIEW-ASSET-DURABILITY.md +6 -2
  442. package/docs/llms.txt +1 -0
  443. package/examples/README.md +1 -1
  444. package/examples/batch-preview-test.ts +3 -3
  445. package/examples/conversation-client.ts +2 -2
  446. package/examples/debug-preview-response.ts +1 -1
  447. package/examples/decisioning-platform-broadcast-tv.ts +10 -4
  448. package/examples/decisioning-platform-mock-seller.ts +16 -9
  449. package/examples/decisioning-platform-programmatic.ts +18 -7
  450. package/examples/error-compliant-server.ts +26 -16
  451. package/examples/generative-creative-demo.ts +7 -19
  452. package/examples/hello_creative_adapter_ad_server.ts +37 -16
  453. package/examples/hello_creative_adapter_template.ts +12 -10
  454. package/examples/hello_seller_adapter_guaranteed.ts +52 -23
  455. package/examples/hello_seller_adapter_multi_tenant.ts +6 -3
  456. package/examples/hello_seller_adapter_non_guaranteed.ts +54 -26
  457. package/examples/hello_seller_adapter_proposal_mode.ts +40 -14
  458. package/examples/hello_seller_adapter_social.ts +2 -7
  459. package/examples/inspect-card-formats.ts +1 -1
  460. package/examples/simple-getting-started.ts +1 -1
  461. package/examples/test-helpers-demo.ts +1 -1
  462. package/package.json +2 -2
  463. package/skills/build-decisioning-creative-template/SKILL.md +11 -11
  464. package/skills/build-decisioning-platform/advanced/REFERENCE.md +8 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/utils/preview-utils.ts"],"sourcesContent":["// Preview utilities for rendering product/format cards with creative agent\n\nimport type { SingleAgentClient } from '../core/SingleAgentClient';\nimport type { Format, Product, FormatReferenceStructuredObject as FormatID } from '../types/tools.generated';\nimport type { PreviewCreativeRequest, PreviewCreativeResponse } from '../types/tools.generated';\n\n/**\n * Preview result for a single item (product or format)\n */\nexport interface PreviewResult {\n /** The item being previewed (Product or Format) */\n item: Product | Format;\n /** Preview URL for the rendered card */\n previewUrl?: string;\n /** Preview ID from the creative agent */\n previewId?: string;\n /** Error message if preview failed */\n error?: string;\n}\n\n/**\n * Options for batch preview generation\n */\nexport interface BatchPreviewOptions {\n /** Cache TTL in milliseconds (defaults to 1 hour) */\n cacheTtl?: number;\n /** Whether to skip cache and force fresh previews (defaults to false) */\n skipCache?: boolean;\n /**\n * Cache backend for preview results.\n *\n * The default backend is process-local memory. It is safe for tests,\n * local development, and single-process CLIs, but it is not shared\n * across pods and does not survive restarts. Production services that\n * cache preview URLs should provide a shared backend such as Redis or\n * Postgres, and the cached URL itself must still resolve to durable\n * storage rather than process-local assets.\n */\n cacheBackend?: PreviewCacheBackend;\n}\n\n/**\n * Cache entry for preview results\n */\nexport interface PreviewCacheEntry {\n previewUrl: string;\n previewId: string;\n timestamp: number;\n /** ISO 8601 timestamp from `preview_creative.expires_at`, when provided. */\n expiresAt?: string;\n}\n\n/**\n * Pluggable cache backend for preview results.\n *\n * This cache stores references returned by `preview_creative`; it is not\n * an asset store. Preview URLs placed in any cache must already be\n * durable across load-balancer hops, pod restarts, and later refinement\n * calls.\n */\nexport interface PreviewCacheBackend {\n get(cacheKey: string): PreviewCacheEntry | null | undefined | Promise<PreviewCacheEntry | null | undefined>;\n set(cacheKey: string, entry: PreviewCacheEntry): void | Promise<void>;\n delete?(cacheKey: string): void | Promise<void>;\n clear?(): void | Promise<void>;\n}\n\n/**\n * Process-local in-memory cache for preview results.\n *\n * Development-only default: this map is not multi-pod-safe and does not\n * survive process restarts. It must not be used as the backing store for\n * MCPUI preview assets in production.\n *\n * Key format: `${formatId.agent_url}:${formatId.id}:${manifestHash}`\n */\nconst previewCache = new Map<string, PreviewCacheEntry>();\n\nconst defaultPreviewCacheBackend: PreviewCacheBackend = {\n get(cacheKey) {\n return previewCache.get(cacheKey);\n },\n set(cacheKey, entry) {\n previewCache.set(cacheKey, entry);\n },\n delete(cacheKey) {\n previewCache.delete(cacheKey);\n },\n clear() {\n previewCache.clear();\n },\n};\n\n/**\n * Generate a cache key for a preview request\n */\nfunction getCacheKey(formatId: FormatID, manifest: any): string {\n // Simple hash of manifest for cache key\n const manifestStr = JSON.stringify(manifest);\n const manifestHash = Array.from(manifestStr)\n .reduce((hash, char) => (hash << 5) - hash + char.charCodeAt(0), 0)\n .toString(36);\n\n return `${formatId.agent_url}:${formatId.id}:${manifestHash}`;\n}\n\nfunction hasExpiredAt(expiresAt: string | undefined, now: number): boolean {\n if (!expiresAt) return false;\n const expiresAtMs = Date.parse(expiresAt);\n return Number.isNaN(expiresAtMs) ? false : expiresAtMs <= now;\n}\n\n/**\n * Get cached preview if available and not expired\n */\nasync function getCachedPreview(\n cacheBackend: PreviewCacheBackend,\n cacheKey: string,\n ttl: number\n): Promise<PreviewCacheEntry | null> {\n const entry = await cacheBackend.get(cacheKey);\n if (!entry) return null;\n\n const now = Date.now();\n if (now - entry.timestamp > ttl || hasExpiredAt(entry.expiresAt, now)) {\n await cacheBackend.delete?.(cacheKey);\n return null;\n }\n\n return entry;\n}\n\n/**\n * Set cached preview\n */\nasync function setCachedPreview(\n cacheBackend: PreviewCacheBackend,\n cacheKey: string,\n previewUrl: string,\n previewId: string,\n expiresAt?: string\n): Promise<void> {\n await cacheBackend.set(cacheKey, {\n previewUrl,\n previewId,\n expiresAt,\n timestamp: Date.now(),\n });\n}\n\n/**\n * Clear all previews from the default process-local cache.\n */\nexport function clearPreviewCache(): void {\n defaultPreviewCacheBackend.clear?.();\n}\n\n/**\n * Extract preview URLs from products' `product_card` fields.\n *\n * AdCP 3.1.0-beta.2 changed `product_card` from a creative-agent-rendered\n * shape (`{ format_id, manifest }`) to a self-contained visual card\n * (`{ image, title, description, price_label, cta_label }`). The card IS\n * the preview — no creative-agent round-trip required. This function now\n * extracts the image URL directly from the inline card.\n *\n * Products with no `product_card`, or with a card that lacks an `image.url`,\n * return a result with no `previewUrl`. The function preserves its\n * `Promise<PreviewResult[]>` return shape so existing adopters' code paths\n * keep compiling and behaving correctly.\n *\n * @param products - Array of products to extract previews from\n * @param creativeAgentClient - Retained for signature compatibility; unused\n * under 3.1.0-beta.2's self-rendering card model. Will be removed in\n * 8.0 final (or 9.0 at the latest) — pass any value through during the\n * beta cycle.\n * @param options - Retained for signature compatibility. Cache fields\n * (`cacheTtl`, `skipCache`) are unused — there's no expensive call to\n * cache. Will be removed alongside `creativeAgentClient`.\n * @returns Array of preview results matching input products by index.\n *\n * @example\n * ```typescript\n * const previews = await batchPreviewProducts(products, creativeAgent);\n * previews.forEach(p => {\n * if (p.previewUrl) {\n * console.log(`${p.item.name}: ${p.previewUrl}`);\n * }\n * });\n * ```\n *\n * @deprecated Use `product.product_card?.image?.url` directly. This wrapper\n * only exists for 8.0-beta migration ergonomics and will be removed.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport async function batchPreviewProducts(\n products: Product[],\n _creativeAgentClient: SingleAgentClient,\n _options: BatchPreviewOptions = {}\n): Promise<PreviewResult[]> {\n return products.map(product => {\n const imageUrl = product.product_card?.image?.url;\n if (imageUrl) {\n return { item: product, previewUrl: imageUrl };\n }\n return { item: product };\n });\n}\n\n/**\n * Generate batch previews for formats with format_card manifests\n *\n * Formats with format_card fields will have their cards rendered via the creative agent.\n * Formats without format_card will be returned with no preview.\n *\n * @param formats - Array of formats to preview\n * @param creativeAgentClient - ADCP client configured for creative agent\n * @param options - Preview generation options\n * @returns Array of preview results matching input formats\n *\n * @example\n * ```typescript\n * const creativeAgent = new SingleAgentClient({\n * id: 'creative',\n * name: 'Creative Agent',\n * agent_uri: 'https://creative.adcontextprotocol.org/mcp',\n * protocol: 'mcp'\n * });\n *\n * const previews = await batchPreviewFormats(formats, creativeAgent);\n * previews.forEach(p => {\n * if (p.previewUrl) {\n * console.log(`${(p.item as Format).name}: ${p.previewUrl}`);\n * }\n * });\n * ```\n */\nexport async function batchPreviewFormats(\n formats: Format[],\n creativeAgentClient: SingleAgentClient,\n options: BatchPreviewOptions = {}\n): Promise<PreviewResult[]> {\n const cacheTtl = options.cacheTtl ?? 3600000; // 1 hour default\n const skipCache = options.skipCache ?? false;\n const cacheBackend = options.cacheBackend ?? defaultPreviewCacheBackend;\n\n // Collect all formats that have format_card manifests\n const previewRequests: {\n format: Format;\n formatId: FormatID;\n manifest: any;\n cacheKey: string;\n inputName: string;\n }[] = [];\n\n const results: PreviewResult[] = [];\n\n for (const format of formats) {\n if (format.format_card) {\n const cacheKey = getCacheKey(format.format_card.format_id, format.format_card.manifest);\n\n // Check cache first\n if (!skipCache) {\n let cached: PreviewCacheEntry | null = null;\n try {\n cached = await getCachedPreview(cacheBackend, cacheKey, cacheTtl);\n } catch {\n cached = null;\n }\n if (cached) {\n results.push({\n item: format,\n previewUrl: cached.previewUrl,\n previewId: cached.previewId,\n });\n continue;\n }\n }\n\n previewRequests.push({\n format,\n formatId: format.format_card.format_id,\n manifest: format.format_card.manifest,\n cacheKey,\n inputName: format.name || 'Format Card',\n });\n } else {\n // No format_card, return format with no preview\n results.push({\n item: format,\n });\n }\n }\n\n // If all were cached or none have format_card, return early\n if (previewRequests.length === 0) {\n return results;\n }\n\n // Batch preview using preview_creative with inputs array\n // Group by format_id since preview_creative takes one format_id\n const groupedByFormat = new Map<string, typeof previewRequests>();\n\n previewRequests.forEach(req => {\n const formatKey = `${req.formatId.agent_url}:${req.formatId.id}`;\n if (!groupedByFormat.has(formatKey)) {\n groupedByFormat.set(formatKey, []);\n }\n groupedByFormat.get(formatKey)!.push(req);\n });\n\n // Process each format individually\n // Note: Each format has different manifest data, so we can't truly batch them\n // We process them sequentially but could parallelize in the future\n for (const req of previewRequests) {\n try {\n // Build preview_creative request for this format\n // For format cards, the manifest typically contains the format object as JSON\n const previewRequest: PreviewCreativeRequest = {\n request_type: 'single',\n format_id: req.formatId,\n creative_manifest: {\n format_id: req.formatId,\n assets: req.manifest, // manifest contains the asset map (format, etc)\n },\n };\n\n // Call preview_creative\n const response = await creativeAgentClient.previewCreative(previewRequest);\n\n // Check for data even if validation failed (response.success may be false due to schema warnings)\n // Handle both single request (previews) and batch request (results) response formats\n const responseData = response.data;\n if (responseData && 'previews' in responseData && responseData.previews && responseData.previews.length > 0) {\n const preview = responseData.previews[0]!;\n if (preview.renders && preview.renders.length > 0) {\n const render = preview.renders[0]!;\n const previewUrl =\n render.output_format === 'url' || render.output_format === 'both' ? render.preview_url : undefined;\n const previewId = preview.preview_id;\n\n if (previewUrl) {\n results.push({\n item: req.format,\n previewUrl,\n previewId,\n });\n try {\n await setCachedPreview(cacheBackend, req.cacheKey, previewUrl, previewId, responseData.expires_at);\n } catch {\n // Preview cache is an accelerator; successful previews should still return on cache write failures.\n }\n } else {\n results.push({\n item: req.format,\n error: 'Preview render has no URL',\n });\n }\n } else {\n results.push({\n item: req.format,\n error: 'No renders in preview response',\n });\n }\n } else {\n // Only treat as error if we have no data at all\n results.push({\n item: req.format,\n error: response.error || 'Preview generation failed',\n });\n }\n } catch (error) {\n results.push({\n item: req.format,\n error: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n return results;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4EA,MAAM,eAAe,oBAAI,IAA+B;AAExD,MAAM,6BAAkD;AAAA,EACtD,IAAI,UAAU;AACZ,WAAO,aAAa,IAAI,QAAQ;AAAA,EAClC;AAAA,EACA,IAAI,UAAU,OAAO;AACnB,iBAAa,IAAI,UAAU,KAAK;AAAA,EAClC;AAAA,EACA,OAAO,UAAU;AACf,iBAAa,OAAO,QAAQ;AAAA,EAC9B;AAAA,EACA,QAAQ;AACN,iBAAa,MAAM;AAAA,EACrB;AACF;AAKA,SAAS,YAAY,UAAoB,UAAuB;AAE9D,QAAM,cAAc,KAAK,UAAU,QAAQ;AAC3C,QAAM,eAAe,MAAM,KAAK,WAAW,EACxC,OAAO,CAAC,MAAM,UAAU,QAAQ,KAAK,OAAO,KAAK,WAAW,CAAC,GAAG,CAAC,EACjE,SAAS,EAAE;AAEd,SAAO,GAAG,SAAS,SAAS,IAAI,SAAS,EAAE,IAAI,YAAY;AAC7D;AAEA,SAAS,aAAa,WAA+B,KAAsB;AACzE,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,cAAc,KAAK,MAAM,SAAS;AACxC,SAAO,OAAO,MAAM,WAAW,IAAI,QAAQ,eAAe;AAC5D;AAKA,eAAe,iBACb,cACA,UACA,KACmC;AACnC,QAAM,QAAQ,MAAM,aAAa,IAAI,QAAQ;AAC7C,MAAI,CAAC,MAAO,QAAO;AAEnB,QAAM,MAAM,KAAK,IAAI;AACrB,MAAI,MAAM,MAAM,YAAY,OAAO,aAAa,MAAM,WAAW,GAAG,GAAG;AACrE,UAAM,aAAa,SAAS,QAAQ;AACpC,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKA,eAAe,iBACb,cAC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ACV,OAAO;AAAA,YACT,CAAC;AAAA,UACH;AAAA,QACF,OAAO;AACL,kBAAQ,KAAK;AAAA,YACX,MAAM,IAAI;AAAA,YACV,OAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF,OAAO;AAEL,gBAAQ,KAAK;AAAA,UACX,MAAM,IAAI;AAAA,UACV,OAAO,SAAS,SAAS;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,KAAK;AAAA,QACX,MAAM,IAAI;AAAA,QACV,OAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/lib/utils/preview-utils.ts"],"sourcesContent":["// Preview utilities for rendering product/format cards with creative agent\n\nimport type { SingleAgentClient } from '../core/SingleAgentClient';\nimport type { Format, Product, FormatReferenceStructuredObject as FormatID } from '../types/tools.generated';\nimport type { PreviewCreativeRequest, PreviewCreativeResponse } from '../types/tools.generated';\nimport type { CanonicalProduct } from '../v2/projection/creative-delivery';\n\n/**\n * Preview result for a single canonical item.\n */\nexport interface PreviewResult<TItem = CanonicalProduct> {\n /** The item being previewed. */\n item: TItem;\n /** Preview URL for the rendered card */\n previewUrl?: string;\n /** Preview ID from the creative agent */\n previewId?: string;\n /** Error message if preview failed */\n error?: string;\n}\n\n/** Raw named-format preview result for explicit migration tooling. */\nexport type LegacyPreviewResult = PreviewResult<Product | Format>;\n\n/**\n * Options for batch preview generation\n */\nexport interface BatchPreviewOptions {\n /** Cache TTL in milliseconds (defaults to 1 hour) */\n cacheTtl?: number;\n /** Whether to skip cache and force fresh previews (defaults to false) */\n skipCache?: boolean;\n /**\n * Cache backend for preview results.\n *\n * The default backend is process-local memory. It is safe for tests,\n * local development, and single-process CLIs, but it is not shared\n * across pods and does not survive restarts. Production services that\n * cache preview URLs should provide a shared backend such as Redis or\n * Postgres, and the cached URL itself must still resolve to durable\n * storage rather than process-local assets.\n */\n cacheBackend?: PreviewCacheBackend;\n}\n\n/**\n * Cache entry for preview results\n */\nexport interface PreviewCacheEntry {\n previewUrl: string;\n previewId: string;\n timestamp: number;\n /** ISO 8601 timestamp from `preview_creative.expires_at`, when provided. */\n expiresAt?: string;\n}\n\n/**\n * Pluggable cache backend for preview results.\n *\n * This cache stores references returned by `preview_creative`; it is not\n * an asset store. Preview URLs placed in any cache must already be\n * durable across load-balancer hops, pod restarts, and later refinement\n * calls.\n */\nexport interface PreviewCacheBackend {\n get(cacheKey: string): PreviewCacheEntry | null | undefined | Promise<PreviewCacheEntry | null | undefined>;\n set(cacheKey: string, entry: PreviewCacheEntry): void | Promise<void>;\n delete?(cacheKey: string): void | Promise<void>;\n clear?(): void | Promise<void>;\n}\n\n/**\n * Process-local in-memory cache for preview results.\n *\n * Development-only default: this map is not multi-pod-safe and does not\n * survive process restarts. It must not be used as the backing store for\n * MCPUI preview assets in production.\n *\n * Key format: `${formatId.agent_url}:${formatId.id}:${manifestHash}`\n */\nconst previewCache = new Map<string, PreviewCacheEntry>();\n\nconst defaultPreviewCacheBackend: PreviewCacheBackend = {\n get(cacheKey) {\n return previewCache.get(cacheKey);\n },\n set(cacheKey, entry) {\n previewCache.set(cacheKey, entry);\n },\n delete(cacheKey) {\n previewCache.delete(cacheKey);\n },\n clear() {\n previewCache.clear();\n },\n};\n\n/**\n * Generate a cache key for a preview request\n */\nfunction getCacheKey(formatId: FormatID, manifest: any): string {\n // Simple hash of manifest for cache key\n const manifestStr = JSON.stringify(manifest);\n const manifestHash = Array.from(manifestStr)\n .reduce((hash, char) => (hash << 5) - hash + char.charCodeAt(0), 0)\n .toString(36);\n\n return `${formatId.agent_url}:${formatId.id}:${manifestHash}`;\n}\n\nfunction hasExpiredAt(expiresAt: string | undefined, now: number): boolean {\n if (!expiresAt) return false;\n const expiresAtMs = Date.parse(expiresAt);\n return Number.isNaN(expiresAtMs) ? false : expiresAtMs <= now;\n}\n\n/**\n * Get cached preview if available and not expired\n */\nasync function getCachedPreview(\n cacheBackend: PreviewCacheBackend,\n cacheKey: string,\n ttl: number\n): Promise<PreviewCacheEntry | null> {\n const entry = await cacheBackend.get(cacheKey);\n if (!entry) return null;\n\n const now = Date.now();\n if (now - entry.timestamp > ttl || hasExpiredAt(entry.expiresAt, now)) {\n await cacheBackend.delete?.(cacheKey);\n return null;\n }\n\n return entry;\n}\n\n/**\n * Set cached preview\n */\nasync function setCachedPreview(\n cacheBackend: PreviewCacheBackend,\n cacheKey: string,\n previewUrl: string,\n previewId: string,\n expiresAt?: string\n): Promise<void> {\n await cacheBackend.set(cacheKey, {\n previewUrl,\n previewId,\n expiresAt,\n timestamp: Date.now(),\n });\n}\n\n/**\n * Clear all previews from the default process-local cache.\n */\nexport function clearPreviewCache(): void {\n defaultPreviewCacheBackend.clear?.();\n}\n\n/**\n * Extract preview URLs from products' `product_card` fields.\n *\n * AdCP 3.1.0-beta.2 changed `product_card` from a creative-agent-rendered\n * shape (`{ format_id, manifest }`) to a self-contained visual card\n * (`{ image, title, description, price_label, cta_label }`). The card IS\n * the preview — no creative-agent round-trip required. This function now\n * extracts the image URL directly from the inline card.\n *\n * Products with no `product_card`, or with a card that lacks an `image.url`,\n * return a result with no `previewUrl`. The function preserves its\n * `Promise<PreviewResult[]>` return shape so existing adopters' code paths\n * keep compiling and behaving correctly.\n *\n * @param products - Array of products to extract previews from\n * @param creativeAgentClient - Retained for signature compatibility; unused\n * under 3.1.0-beta.2's self-rendering card model. Will be removed in\n * 8.0 final (or 9.0 at the latest) — pass any value through during the\n * beta cycle.\n * @param options - Retained for signature compatibility. Cache fields\n * (`cacheTtl`, `skipCache`) are unused — there's no expensive call to\n * cache. Will be removed alongside `creativeAgentClient`.\n * @returns Array of preview results matching input products by index.\n *\n * @example\n * ```typescript\n * const previews = await batchPreviewProducts(products, creativeAgent);\n * previews.forEach(p => {\n * if (p.previewUrl) {\n * console.log(`${p.item.name}: ${p.previewUrl}`);\n * }\n * });\n * ```\n *\n * @deprecated Use `product.product_card?.image?.url` directly. This wrapper\n * only exists for 8.0-beta migration ergonomics and will be removed.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport async function batchPreviewProducts(\n products: CanonicalProduct[],\n _creativeAgentClient: SingleAgentClient,\n _options: BatchPreviewOptions = {}\n): Promise<PreviewResult[]> {\n return products.map(product => {\n const imageUrl = (product.product_card as { image?: { url?: string } } | undefined)?.image?.url;\n if (imageUrl) {\n return { item: product, previewUrl: imageUrl };\n }\n return { item: product };\n });\n}\n\n/**\n * Generate batch previews for legacy named formats with format_card manifests.\n *\n * Formats with format_card fields will have their cards rendered via the creative agent.\n * Formats without format_card will be returned with no preview.\n *\n * @param formats - Array of formats to preview\n * @param creativeAgentClient - ADCP client configured for creative agent\n * @param options - Preview generation options\n * @returns Array of preview results matching input formats\n *\n * @example\n * ```typescript\n * const creativeAgent = new SingleAgentClient({\n * id: 'creative',\n * name: 'Creative Agent',\n * agent_uri: 'https://creative.adcontextprotocol.org/mcp',\n * protocol: 'mcp'\n * });\n *\n * const previews = await batchPreviewFormatsLegacy(formats, creativeAgent);\n * previews.forEach(p => {\n * if (p.previewUrl) {\n * console.log(`${(p.item as Format).name}: ${p.previewUrl}`);\n * }\n * });\n * ```\n */\nexport async function batchPreviewFormatsLegacy(\n formats: Format[],\n creativeAgentClient: SingleAgentClient,\n options: BatchPreviewOptions = {}\n): Promise<LegacyPreviewResult[]> {\n const cacheTtl = options.cacheTtl ?? 3600000; // 1 hour default\n const skipCache = options.skipCache ?? false;\n const cacheBackend = options.cacheBackend ?? defaultPreviewCacheBackend;\n\n // Collect all formats that have format_card manifests\n const previewRequests: {\n format: Format;\n formatId: FormatID;\n manifest: any;\n cacheKey: string;\n inputName: string;\n }[] = [];\n\n const results: LegacyPreviewResult[] = [];\n\n for (const format of formats) {\n if (format.format_card) {\n const cacheKey = getCacheKey(format.format_card.format_id, format.format_card.manifest);\n\n // Check cache first\n if (!skipCache) {\n let cached: PreviewCacheEntry | null = null;\n try {\n cached = await getCachedPreview(cacheBackend, cacheKey, cacheTtl);\n } catch {\n cached = null;\n }\n if (cached) {\n results.push({\n item: format,\n previewUrl: cached.previewUrl,\n previewId: cached.previewId,\n });\n continue;\n }\n }\n\n previewRequests.push({\n format,\n formatId: format.format_card.format_id,\n manifest: format.format_card.manifest,\n cacheKey,\n inputName: format.name || 'Format Card',\n });\n } else {\n // No format_card, return format with no preview\n results.push({\n item: format,\n });\n }\n }\n\n // If all were cached or none have format_card, return early\n if (previewRequests.length === 0) {\n return results;\n }\n\n // Batch preview using preview_creative with inputs array\n // Group by format_id since preview_creative takes one format_id\n const groupedByFormat = new Map<string, typeof previewRequests>();\n\n previewRequests.forEach(req => {\n const formatKey = `${req.formatId.agent_url}:${req.formatId.id}`;\n if (!groupedByFormat.has(formatKey)) {\n groupedByFormat.set(formatKey, []);\n }\n groupedByFormat.get(formatKey)!.push(req);\n });\n\n // Process each format individually\n // Note: Each format has different manifest data, so we can't truly batch them\n // We process them sequentially but could parallelize in the future\n for (const req of previewRequests) {\n try {\n // Build preview_creative request for this format\n // For format cards, the manifest typically contains the format object as JSON\n const previewRequest: PreviewCreativeRequest = {\n request_type: 'single',\n format_id: req.formatId,\n creative_manifest: {\n format_id: req.formatId,\n assets: req.manifest, // manifest contains the asset map (format, etc)\n },\n };\n\n // Call preview_creative\n const response = await creativeAgentClient.previewCreativeLegacy(previewRequest);\n\n // Check for data even if validation failed (response.success may be false due to schema warnings)\n // Handle both single request (previews) and batch request (results) response formats\n const responseData = response.data;\n if (responseData && 'previews' in responseData && responseData.previews && responseData.previews.length > 0) {\n const preview = responseData.previews[0]!;\n if (preview.renders && preview.renders.length > 0) {\n const render = preview.renders[0]!;\n const previewUrl =\n render.output_format === 'url' || render.output_format === 'both' ? render.preview_url : undefined;\n const previewId = preview.preview_id;\n\n if (previewUrl) {\n results.push({\n item: req.format,\n previewUrl,\n previewId,\n });\n try {\n await setCachedPreview(cacheBackend, req.cacheKey, previewUrl, previewId, responseData.expires_at);\n } catch {\n // Preview cache is an accelerator; successful previews should still return on cache write failures.\n }\n } else {\n results.push({\n item: req.format,\n error: 'Preview render has no URL',\n });\n }\n } else {\n results.push({\n item: req.format,\n error: 'No renders in preview response',\n });\n }\n } else {\n // Only treat as error if we have no data at all\n results.push({\n item: req.format,\n error: response.error || 'Preview generation failed',\n });\n }\n } catch (error) {\n results.push({\n item: req.format,\n error: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n return results;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgFA,MAAM,eAAe,oBAAI,IAA+B;AAExD,MAAM,6BAAkD;AAAA,EACtD,IAAI,UAAU;AACZ,WAAO,aAAa,IAAI,QAAQ;AAAA,EAClC;AAAA,EACA,IAAI,UAAU,OAAO;AACnB,iBAAa,IAAI,UAAU,KAAK;AAAA,EAClC;AAAA,EACA,OAAO,UAAU;AACf,iBAAa,OAAO,QAAQ;AAAA,EAC9B;AAAA,EACA,QAAQ;AACN,iBAAa,MAAM;AAAA,EACrB;AACF;AAKA,SAAS,YAAY,UAAoB,UAAuB;AAE9D,QAAM,cAAc,KAAK,UAAU,QAAQ;AAC3C,QAAM,eAAe,MAAM,KAAK,WAAW,EACxC,OAAO,CAAC,MAAM,UAAU,QAAQ,KAAK,OAAO,KAAK,WAAW,CAAC,GAAG,CAAC,EACjE,SAAS,EAAE;AAEd,SAAO,GAAG,SAAS,SAAS,IAAI,SAAS,EAAE,IAAI,YAAY;AAC7D;AAEA,SAAS,aAAa,WAA+B,KAAsB;AACzE,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,cAAc,KAAK,MAAM,SAAS;AACxC,SAAO,OAAO,MAAM,WAAW,IAAI,QAAQ,eAAe;AAC5D;AAKA,eAAe,iBACb,cACA,UACA,KACmC;AACnC,QAAM,QAAQ,MAAM,aAAa,IAAI,QAAQ;AAC7C,MAAI,CAAC,MAAO,QAAO;AAEnB,QA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F,CAAC;AACD,gBAAI;AACF,oBAAM,iBAAiB,cAAc,IAAI,UAAU,YAAY,WAAW,aAAa,UAAU;AAAA,YACnG,QAAQ;AAAA,YAER;AAAA,UACF,OAAO;AACL,oBAAQ,KAAK;AAAA,cACX,MAAM,IAAI;AAAA,cACV,OAAO;AAAA,YACT,CAAC;AAAA,UACH;AAAA,QACF,OAAO;AACL,kBAAQ,KAAK;AAAA,YACX,MAAM,IAAI;AAAA,YACV,OAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF,OAAO;AAEL,gBAAQ,KAAK;AAAA,UACX,MAAM,IAAI;AAAA,UACV,OAAO,SAAS,SAAS;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,KAAK;AAAA,QACX,MAAM,IAAI;AAAA,QACV,OAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -53,7 +53,7 @@ async function batchPreviewProducts(products, _creativeAgentClient, _options = {
53
53
  return { item: product };
54
54
  });
55
55
  }
56
- async function batchPreviewFormats(formats, creativeAgentClient, options = {}) {
56
+ async function batchPreviewFormatsLegacy(formats, creativeAgentClient, options = {}) {
57
57
  const cacheTtl = options.cacheTtl ?? 36e5;
58
58
  const skipCache = options.skipCache ?? false;
59
59
  const cacheBackend = options.cacheBackend ?? defaultPreviewCacheBackend;
@@ -113,7 +113,7 @@ async function batchPreviewFormats(formats, creativeAgentClient, options = {}) {
113
113
  // manifest contains the asset map (format, etc)
114
114
  }
115
115
  };
116
- const response = await creativeAgentClient.previewCreative(previewRequest);
116
+ const response = await creativeAgentClient.previewCreativeLegacy(previewRequest);
117
117
  const responseData = response.data;
118
118
  if (responseData && "previews" in responseData && responseData.previews && responseData.previews.length > 0) {
119
119
  const preview = responseData.previews[0];
@@ -159,7 +159,7 @@ async function batchPreviewFormats(formats, creativeAgentClient, options = {}) {
159
159
  return results;
160
160
  }
161
161
  export {
162
- batchPreviewFormats,
162
+ batchPreviewFormatsLegacy,
163
163
  batchPreviewProducts,
164
164
  clearPreviewCache
165
165
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/utils/preview-utils.ts"],"sourcesContent":["// Preview utilities for rendering product/format cards with creative agent\n\nimport type { SingleAgentClient } from '../core/SingleAgentClient';\nimport type { Format, Product, FormatReferenceStructuredObject as FormatID } from '../types/tools.generated';\nimport type { PreviewCreativeRequest, PreviewCreativeResponse } from '../types/tools.generated';\n\n/**\n * Preview result for a single item (product or format)\n */\nexport interface PreviewResult {\n /** The item being previewed (Product or Format) */\n item: Product | Format;\n /** Preview URL for the rendered card */\n previewUrl?: string;\n /** Preview ID from the creative agent */\n previewId?: string;\n /** Error message if preview failed */\n error?: string;\n}\n\n/**\n * Options for batch preview generation\n */\nexport interface BatchPreviewOptions {\n /** Cache TTL in milliseconds (defaults to 1 hour) */\n cacheTtl?: number;\n /** Whether to skip cache and force fresh previews (defaults to false) */\n skipCache?: boolean;\n /**\n * Cache backend for preview results.\n *\n * The default backend is process-local memory. It is safe for tests,\n * local development, and single-process CLIs, but it is not shared\n * across pods and does not survive restarts. Production services that\n * cache preview URLs should provide a shared backend such as Redis or\n * Postgres, and the cached URL itself must still resolve to durable\n * storage rather than process-local assets.\n */\n cacheBackend?: PreviewCacheBackend;\n}\n\n/**\n * Cache entry for preview results\n */\nexport interface PreviewCacheEntry {\n previewUrl: string;\n previewId: string;\n timestamp: number;\n /** ISO 8601 timestamp from `preview_creative.expires_at`, when provided. */\n expiresAt?: string;\n}\n\n/**\n * Pluggable cache backend for preview results.\n *\n * This cache stores references returned by `preview_creative`; it is not\n * an asset store. Preview URLs placed in any cache must already be\n * durable across load-balancer hops, pod restarts, and later refinement\n * calls.\n */\nexport interface PreviewCacheBackend {\n get(cacheKey: string): PreviewCacheEntry | null | undefined | Promise<PreviewCacheEntry | null | undefined>;\n set(cacheKey: string, entry: PreviewCacheEntry): void | Promise<void>;\n delete?(cacheKey: string): void | Promise<void>;\n clear?(): void | Promise<void>;\n}\n\n/**\n * Process-local in-memory cache for preview results.\n *\n * Development-only default: this map is not multi-pod-safe and does not\n * survive process restarts. It must not be used as the backing store for\n * MCPUI preview assets in production.\n *\n * Key format: `${formatId.agent_url}:${formatId.id}:${manifestHash}`\n */\nconst previewCache = new Map<string, PreviewCacheEntry>();\n\nconst defaultPreviewCacheBackend: PreviewCacheBackend = {\n get(cacheKey) {\n return previewCache.get(cacheKey);\n },\n set(cacheKey, entry) {\n previewCache.set(cacheKey, entry);\n },\n delete(cacheKey) {\n previewCache.delete(cacheKey);\n },\n clear() {\n previewCache.clear();\n },\n};\n\n/**\n * Generate a cache key for a preview request\n */\nfunction getCacheKey(formatId: FormatID, manifest: any): string {\n // Simple hash of manifest for cache key\n const manifestStr = JSON.stringify(manifest);\n const manifestHash = Array.from(manifestStr)\n .reduce((hash, char) => (hash << 5) - hash + char.charCodeAt(0), 0)\n .toString(36);\n\n return `${formatId.agent_url}:${formatId.id}:${manifestHash}`;\n}\n\nfunction hasExpiredAt(expiresAt: string | undefined, now: number): boolean {\n if (!expiresAt) return false;\n const expiresAtMs = Date.parse(expiresAt);\n return Number.isNaN(expiresAtMs) ? false : expiresAtMs <= now;\n}\n\n/**\n * Get cached preview if available and not expired\n */\nasync function getCachedPreview(\n cacheBackend: PreviewCacheBackend,\n cacheKey: string,\n ttl: number\n): Promise<PreviewCacheEntry | null> {\n const entry = await cacheBackend.get(cacheKey);\n if (!entry) return null;\n\n const now = Date.now();\n if (now - entry.timestamp > ttl || hasExpiredAt(entry.expiresAt, now)) {\n await cacheBackend.delete?.(cacheKey);\n return null;\n }\n\n return entry;\n}\n\n/**\n * Set cached preview\n */\nasync function setCachedPreview(\n cacheBackend: PreviewCacheBackend,\n cacheKey: string,\n previewUrl: string,\n previewId: string,\n expiresAt?: string\n): Promise<void> {\n await cacheBackend.set(cacheKey, {\n previewUrl,\n previewId,\n expiresAt,\n timestamp: Date.now(),\n });\n}\n\n/**\n * Clear all previews from the default process-local cache.\n */\nexport function clearPreviewCache(): void {\n defaultPreviewCacheBackend.clear?.();\n}\n\n/**\n * Extract preview URLs from products' `product_card` fields.\n *\n * AdCP 3.1.0-beta.2 changed `product_card` from a creative-agent-rendered\n * shape (`{ format_id, manifest }`) to a self-contained visual card\n * (`{ image, title, description, price_label, cta_label }`). The card IS\n * the preview — no creative-agent round-trip required. This function now\n * extracts the image URL directly from the inline card.\n *\n * Products with no `product_card`, or with a card that lacks an `image.url`,\n * return a result with no `previewUrl`. The function preserves its\n * `Promise<PreviewResult[]>` return shape so existing adopters' code paths\n * keep compiling and behaving correctly.\n *\n * @param products - Array of products to extract previews from\n * @param creativeAgentClient - Retained for signature compatibility; unused\n * under 3.1.0-beta.2's self-rendering card model. Will be removed in\n * 8.0 final (or 9.0 at the latest) — pass any value through during the\n * beta cycle.\n * @param options - Retained for signature compatibility. Cache fields\n * (`cacheTtl`, `skipCache`) are unused — there's no expensive call to\n * cache. Will be removed alongside `creativeAgentClient`.\n * @returns Array of preview results matching input products by index.\n *\n * @example\n * ```typescript\n * const previews = await batchPreviewProducts(products, creativeAgent);\n * previews.forEach(p => {\n * if (p.previewUrl) {\n * console.log(`${p.item.name}: ${p.previewUrl}`);\n * }\n * });\n * ```\n *\n * @deprecated Use `product.product_card?.image?.url` directly. This wrapper\n * only exists for 8.0-beta migration ergonomics and will be removed.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport async function batchPreviewProducts(\n products: Product[],\n _creativeAgentClient: SingleAgentClient,\n _options: BatchPreviewOptions = {}\n): Promise<PreviewResult[]> {\n return products.map(product => {\n const imageUrl = product.product_card?.image?.url;\n if (imageUrl) {\n return { item: product, previewUrl: imageUrl };\n }\n return { item: product };\n });\n}\n\n/**\n * Generate batch previews for formats with format_card manifests\n *\n * Formats with format_card fields will have their cards rendered via the creative agent.\n * Formats without format_card will be returned with no preview.\n *\n * @param formats - Array of formats to preview\n * @param creativeAgentClient - ADCP client configured for creative agent\n * @param options - Preview generation options\n * @returns Array of preview results matching input formats\n *\n * @example\n * ```typescript\n * const creativeAgent = new SingleAgentClient({\n * id: 'creative',\n * name: 'Creative Agent',\n * agent_uri: 'https://creative.adcontextprotocol.org/mcp',\n * protocol: 'mcp'\n * });\n *\n * const previews = await batchPreviewFormats(formats, creativeAgent);\n * previews.forEach(p => {\n * if (p.previewUrl) {\n * console.log(`${(p.item as Format).name}: ${p.previewUrl}`);\n * }\n * });\n * ```\n */\nexport async function batchPreviewFormats(\n formats: Format[],\n creativeAgentClient: SingleAgentClient,\n options: BatchPreviewOptions = {}\n): Promise<PreviewResult[]> {\n const cacheTtl = options.cacheTtl ?? 3600000; // 1 hour default\n const skipCache = options.skipCache ?? false;\n const cacheBackend = options.cacheBackend ?? defaultPreviewCacheBackend;\n\n // Collect all formats that have format_card manifests\n const previewRequests: {\n format: Format;\n formatId: FormatID;\n manifest: any;\n cacheKey: string;\n inputName: string;\n }[] = [];\n\n const results: PreviewResult[] = [];\n\n for (const format of formats) {\n if (format.format_card) {\n const cacheKey = getCacheKey(format.format_card.format_id, format.format_card.manifest);\n\n // Check cache first\n if (!skipCache) {\n let cached: PreviewCacheEntry | null = null;\n try {\n cached = await getCachedPreview(cacheBackend, cacheKey, cacheTtl);\n } catch {\n cached = null;\n }\n if (cached) {\n results.push({\n item: format,\n previewUrl: cached.previewUrl,\n previewId: cached.previewId,\n });\n continue;\n }\n }\n\n previewRequests.push({\n format,\n formatId: format.format_card.format_id,\n manifest: format.format_card.manifest,\n cacheKey,\n inputName: format.name || 'Format Card',\n });\n } else {\n // No format_card, return format with no preview\n results.push({\n item: format,\n });\n }\n }\n\n // If all were cached or none have format_card, return early\n if (previewRequests.length === 0) {\n return results;\n }\n\n // Batch preview using preview_creative with inputs array\n // Group by format_id since preview_creative takes one format_id\n const groupedByFormat = new Map<string, typeof previewRequests>();\n\n previewRequests.forEach(req => {\n const formatKey = `${req.formatId.agent_url}:${req.formatId.id}`;\n if (!groupedByFormat.has(formatKey)) {\n groupedByFormat.set(formatKey, []);\n }\n groupedByFormat.get(formatKey)!.push(req);\n });\n\n // Process each format individually\n // Note: Each format has different manifest data, so we can't truly batch them\n // We process them sequentially but could parallelize in the future\n for (const req of previewRequests) {\n try {\n // Build preview_creative request for this format\n // For format cards, the manifest typically contains the format object as JSON\n const previewRequest: PreviewCreativeRequest = {\n request_type: 'single',\n format_id: req.formatId,\n creative_manifest: {\n format_id: req.formatId,\n assets: req.manifest, // manifest contains the asset map (format, etc)\n },\n };\n\n // Call preview_creative\n const response = await creativeAgentClient.previewCreative(previewRequest);\n\n // Check for data even if validation failed (response.success may be false due to schema warnings)\n // Handle both single request (previews) and batch request (results) response formats\n const responseData = response.data;\n if (responseData && 'previews' in responseData && responseData.previews && responseData.previews.length > 0) {\n const preview = responseData.previews[0]!;\n if (preview.renders && preview.renders.length > 0) {\n const render = preview.renders[0]!;\n const previewUrl =\n render.output_format === 'url' || render.output_format === 'both' ? render.preview_url : undefined;\n const previewId = preview.preview_id;\n\n if (previewUrl) {\n results.push({\n item: req.format,\n previewUrl,\n previewId,\n });\n try {\n await setCachedPreview(cacheBackend, req.cacheKey, previewUrl, previewId, responseData.expires_at);\n } catch {\n // Preview cache is an accelerator; successful previews should still return on cache write failures.\n }\n } else {\n results.push({\n item: req.format,\n error: 'Preview render has no URL',\n });\n }\n } else {\n results.push({\n item: req.format,\n error: 'No renders in preview response',\n });\n }\n } else {\n // Only treat as error if we have no data at all\n results.push({\n item: req.format,\n error: response.error || 'Preview generation failed',\n });\n }\n } catch (error) {\n results.push({\n item: req.format,\n error: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n return results;\n}\n"],"mappings":"AA4EA,MAAM,eAAe,oBAAI,IAA+B;AAExD,MAAM,6BAAkD;AAAA,EACtD,IAAI,UAAU;AACZ,WAAO,aAAa,IAAI,QAAQ;AAAA,EAClC;AAAA,EACA,IAAI,UAAU,OAAO;AACnB,iBAAa,IAAI,UAAU,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,MAClD,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/lib/utils/preview-utils.ts"],"sourcesContent":["// Preview utilities for rendering product/format cards with creative agent\n\nimport type { SingleAgentClient } from '../core/SingleAgentClient';\nimport type { Format, Product, FormatReferenceStructuredObject as FormatID } from '../types/tools.generated';\nimport type { PreviewCreativeRequest, PreviewCreativeResponse } from '../types/tools.generated';\nimport type { CanonicalProduct } from '../v2/projection/creative-delivery';\n\n/**\n * Preview result for a single canonical item.\n */\nexport interface PreviewResult<TItem = CanonicalProduct> {\n /** The item being previewed. */\n item: TItem;\n /** Preview URL for the rendered card */\n previewUrl?: string;\n /** Preview ID from the creative agent */\n previewId?: string;\n /** Error message if preview failed */\n error?: string;\n}\n\n/** Raw named-format preview result for explicit migration tooling. */\nexport type LegacyPreviewResult = PreviewResult<Product | Format>;\n\n/**\n * Options for batch preview generation\n */\nexport interface BatchPreviewOptions {\n /** Cache TTL in milliseconds (defaults to 1 hour) */\n cacheTtl?: number;\n /** Whether to skip cache and force fresh previews (defaults to false) */\n skipCache?: boolean;\n /**\n * Cache backend for preview results.\n *\n * The default backend is process-local memory. It is safe for tests,\n * local development, and single-process CLIs, but it is not shared\n * across pods and does not survive restarts. Production services that\n * cache preview URLs should provide a shared backend such as Redis or\n * Postgres, and the cached URL itself must still resolve to durable\n * storage rather than process-local assets.\n */\n cacheBackend?: PreviewCacheBackend;\n}\n\n/**\n * Cache entry for preview results\n */\nexport interface PreviewCacheEntry {\n previewUrl: string;\n previewId: string;\n timestamp: number;\n /** ISO 8601 timestamp from `preview_creative.expires_at`, when provided. */\n expiresAt?: string;\n}\n\n/**\n * Pluggable cache backend for preview results.\n *\n * This cache stores references returned by `preview_creative`; it is not\n * an asset store. Preview URLs placed in any cache must already be\n * durable across load-balancer hops, pod restarts, and later refinement\n * calls.\n */\nexport interface PreviewCacheBackend {\n get(cacheKey: string): PreviewCacheEntry | null | undefined | Promise<PreviewCacheEntry | null | undefined>;\n set(cacheKey: string, entry: PreviewCacheEntry): void | Promise<void>;\n delete?(cacheKey: string): void | Promise<void>;\n clear?(): void | Promise<void>;\n}\n\n/**\n * Process-local in-memory cache for preview results.\n *\n * Development-only default: this map is not multi-pod-safe and does not\n * survive process restarts. It must not be used as the backing store for\n * MCPUI preview assets in production.\n *\n * Key format: `${formatId.agent_url}:${formatId.id}:${manifestHash}`\n */\nconst previewCache = new Map<string, PreviewCacheEntry>();\n\nconst defaultPreviewCacheBackend: PreviewCacheBackend = {\n get(cacheKey) {\n return previewCache.get(cacheKey);\n },\n set(cacheKey, entry) {\n previewCache.set(cacheKey, entry);\n },\n delete(cacheKey) {\n previewCache.delete(cacheKey);\n },\n clear() {\n previewCache.clear();\n },\n};\n\n/**\n * Generate a cache key for a preview request\n */\nfunction getCacheKey(formatId: FormatID, manifest: any): string {\n // Simple hash of manifest for cache key\n const manifestStr = JSON.stringify(manifest);\n const manifestHash = Array.from(manifestStr)\n .reduce((hash, char) => (hash << 5) - hash + char.charCodeAt(0), 0)\n .toString(36);\n\n return `${formatId.agent_url}:${formatId.id}:${manifestHash}`;\n}\n\nfunction hasExpiredAt(expiresAt: string | undefined, now: number): boolean {\n if (!expiresAt) return false;\n const expiresAtMs = Date.parse(expiresAt);\n return Number.isNaN(expiresAtMs) ? false : expiresAtMs <= now;\n}\n\n/**\n * Get cached preview if available and not expired\n */\nasync function getCachedPreview(\n cacheBackend: PreviewCacheBackend,\n cacheKey: string,\n ttl: number\n): Promise<PreviewCacheEntry | null> {\n const entry = await cacheBackend.get(cacheKey);\n if (!entry) return null;\n\n const now = Date.now();\n if (now - entry.timestamp > ttl || hasExpiredAt(entry.expiresAt, now)) {\n await cacheBackend.delete?.(cacheKey);\n return null;\n }\n\n return entry;\n}\n\n/**\n * Set cached preview\n */\nasync function setCachedPreview(\n cacheBackend: PreviewCacheBackend,\n cacheKey: string,\n previewUrl: string,\n previewId: string,\n expiresAt?: string\n): Promise<void> {\n await cacheBackend.set(cacheKey, {\n previewUrl,\n previewId,\n expiresAt,\n timestamp: Date.now(),\n });\n}\n\n/**\n * Clear all previews from the default process-local cache.\n */\nexport function clearPreviewCache(): void {\n defaultPreviewCacheBackend.clear?.();\n}\n\n/**\n * Extract preview URLs from products' `product_card` fields.\n *\n * AdCP 3.1.0-beta.2 changed `product_card` from a creative-agent-rendered\n * shape (`{ format_id, manifest }`) to a self-contained visual card\n * (`{ image, title, description, price_label, cta_label }`). The card IS\n * the preview — no creative-agent round-trip required. This function now\n * extracts the image URL directly from the inline card.\n *\n * Products with no `product_card`, or with a card that lacks an `image.url`,\n * return a result with no `previewUrl`. The function preserves its\n * `Promise<PreviewResult[]>` return shape so existing adopters' code paths\n * keep compiling and behaving correctly.\n *\n * @param products - Array of products to extract previews from\n * @param creativeAgentClient - Retained for signature compatibility; unused\n * under 3.1.0-beta.2's self-rendering card model. Will be removed in\n * 8.0 final (or 9.0 at the latest) — pass any value through during the\n * beta cycle.\n * @param options - Retained for signature compatibility. Cache fields\n * (`cacheTtl`, `skipCache`) are unused — there's no expensive call to\n * cache. Will be removed alongside `creativeAgentClient`.\n * @returns Array of preview results matching input products by index.\n *\n * @example\n * ```typescript\n * const previews = await batchPreviewProducts(products, creativeAgent);\n * previews.forEach(p => {\n * if (p.previewUrl) {\n * console.log(`${p.item.name}: ${p.previewUrl}`);\n * }\n * });\n * ```\n *\n * @deprecated Use `product.product_card?.image?.url` directly. This wrapper\n * only exists for 8.0-beta migration ergonomics and will be removed.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport async function batchPreviewProducts(\n products: CanonicalProduct[],\n _creativeAgentClient: SingleAgentClient,\n _options: BatchPreviewOptions = {}\n): Promise<PreviewResult[]> {\n return products.map(product => {\n const imageUrl = (product.product_card as { image?: { url?: string } } | undefined)?.image?.url;\n if (imageUrl) {\n return { item: product, previewUrl: imageUrl };\n }\n return { item: product };\n });\n}\n\n/**\n * Generate batch previews for legacy named formats with format_card manifests.\n *\n * Formats with format_card fields will have their cards rendered via the creative agent.\n * Formats without format_card will be returned with no preview.\n *\n * @param formats - Array of formats to preview\n * @param creativeAgentClient - ADCP client configured for creative agent\n * @param options - Preview generation options\n * @returns Array of preview results matching input formats\n *\n * @example\n * ```typescript\n * const creativeAgent = new SingleAgentClient({\n * id: 'creative',\n * name: 'Creative Agent',\n * agent_uri: 'https://creative.adcontextprotocol.org/mcp',\n * protocol: 'mcp'\n * });\n *\n * const previews = await batchPreviewFormatsLegacy(formats, creativeAgent);\n * previews.forEach(p => {\n * if (p.previewUrl) {\n * console.log(`${(p.item as Format).name}: ${p.previewUrl}`);\n * }\n * });\n * ```\n */\nexport async function batchPreviewFormatsLegacy(\n formats: Format[],\n creativeAgentClient: SingleAgentClient,\n options: BatchPreviewOptions = {}\n): Promise<LegacyPreviewResult[]> {\n const cacheTtl = options.cacheTtl ?? 3600000; // 1 hour default\n const skipCache = options.skipCache ?? false;\n const cacheBackend = options.cacheBackend ?? defaultPreviewCacheBackend;\n\n // Collect all formats that have format_card manifests\n const previewRequests: {\n format: Format;\n formatId: FormatID;\n manifest: any;\n cacheKey: string;\n inputName: string;\n }[] = [];\n\n const results: LegacyPreviewResult[] = [];\n\n for (const format of formats) {\n if (format.format_card) {\n const cacheKey = getCacheKey(format.format_card.format_id, format.format_card.manifest);\n\n // Check cache first\n if (!skipCache) {\n let cached: PreviewCacheEntry | null = null;\n try {\n cached = await getCachedPreview(cacheBackend, cacheKey, cacheTtl);\n } catch {\n cached = null;\n }\n if (cached) {\n results.push({\n item: format,\n previewUrl: cached.previewUrl,\n previewId: cached.previewId,\n });\n continue;\n }\n }\n\n previewRequests.push({\n format,\n formatId: format.format_card.format_id,\n manifest: format.format_card.manifest,\n cacheKey,\n inputName: format.name || 'Format Card',\n });\n } else {\n // No format_card, return format with no preview\n results.push({\n item: format,\n });\n }\n }\n\n // If all were cached or none have format_card, return early\n if (previewRequests.length === 0) {\n return results;\n }\n\n // Batch preview using preview_creative with inputs array\n // Group by format_id since preview_creative takes one format_id\n const groupedByFormat = new Map<string, typeof previewRequests>();\n\n previewRequests.forEach(req => {\n const formatKey = `${req.formatId.agent_url}:${req.formatId.id}`;\n if (!groupedByFormat.has(formatKey)) {\n groupedByFormat.set(formatKey, []);\n }\n groupedByFormat.get(formatKey)!.push(req);\n });\n\n // Process each format individually\n // Note: Each format has different manifest data, so we can't truly batch them\n // We process them sequentially but could parallelize in the future\n for (const req of previewRequests) {\n try {\n // Build preview_creative request for this format\n // For format cards, the manifest typically contains the format object as JSON\n const previewRequest: PreviewCreativeRequest = {\n request_type: 'single',\n format_id: req.formatId,\n creative_manifest: {\n format_id: req.formatId,\n assets: req.manifest, // manifest contains the asset map (format, etc)\n },\n };\n\n // Call preview_creative\n const response = await creativeAgentClient.previewCreativeLegacy(previewRequest);\n\n // Check for data even if validation failed (response.success may be false due to schema warnings)\n // Handle both single request (previews) and batch request (results) response formats\n const responseData = response.data;\n if (responseData && 'previews' in responseData && responseData.previews && responseData.previews.length > 0) {\n const preview = responseData.previews[0]!;\n if (preview.renders && preview.renders.length > 0) {\n const render = preview.renders[0]!;\n const previewUrl =\n render.output_format === 'url' || render.output_format === 'both' ? render.preview_url : undefined;\n const previewId = preview.preview_id;\n\n if (previewUrl) {\n results.push({\n item: req.format,\n previewUrl,\n previewId,\n });\n try {\n await setCachedPreview(cacheBackend, req.cacheKey, previewUrl, previewId, responseData.expires_at);\n } catch {\n // Preview cache is an accelerator; successful previews should still return on cache write failures.\n }\n } else {\n results.push({\n item: req.format,\n error: 'Preview render has no URL',\n });\n }\n } else {\n results.push({\n item: req.format,\n error: 'No renders in preview response',\n });\n }\n } else {\n // Only treat as error if we have no data at all\n results.push({\n item: req.format,\n error: response.error || 'Preview generation failed',\n });\n }\n } catch (error) {\n results.push({\n item: req.format,\n error: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n return results;\n}\n"],"mappings":"AAgFA,MAAM,eAAe,oBAAI,IAA+B;AAExD,MAAM,6BAAkD;AAAA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ACH;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,KAAK;AAAA,QACX,MAAM,IAAI;AAAA,QACV,OAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -10400,9 +10400,9 @@ declare const UpdateMediaBuyToolRequestSchema: z.ZodObject<WithOptionalAccountSh
10400
10400
  cancellation_reason: z.ZodType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
10401
10401
  start_time: z.ZodType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
10402
10402
  end_time: z.ZodType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
10403
- packages: z.ZodType<import("../index.mjs").PackageUpdate[] | undefined, import("../index.mjs").PackageUpdate[] | undefined, z.core.$ZodTypeInternals<import("../index.mjs").PackageUpdate[] | undefined, import("../index.mjs").PackageUpdate[] | undefined>>;
10403
+ packages: z.ZodType<import("../index.mjs").LegacyPackageUpdate[] | undefined, import("../index.mjs").LegacyPackageUpdate[] | undefined, z.core.$ZodTypeInternals<import("../index.mjs").LegacyPackageUpdate[] | undefined, import("../index.mjs").LegacyPackageUpdate[] | undefined>>;
10404
10404
  invoice_recipient: z.ZodType<import("../types/tools.generated.mjs").BusinessEntity | undefined, import("../types/tools.generated.mjs").BusinessEntity | undefined, z.core.$ZodTypeInternals<import("../types/tools.generated.mjs").BusinessEntity | undefined, import("../types/tools.generated.mjs").BusinessEntity | undefined>>;
10405
- new_packages: z.ZodType<import("../index.mjs").PackageRequest[] | undefined, import("../index.mjs").PackageRequest[] | undefined, z.core.$ZodTypeInternals<import("../index.mjs").PackageRequest[] | undefined, import("../index.mjs").PackageRequest[] | undefined>>;
10405
+ new_packages: z.ZodType<import("../index.mjs").LegacyPackageRequest[] | undefined, import("../index.mjs").LegacyPackageRequest[] | undefined, z.core.$ZodTypeInternals<import("../index.mjs").LegacyPackageRequest[] | undefined, import("../index.mjs").LegacyPackageRequest[] | undefined>>;
10406
10406
  reporting_webhook: z.ZodType<import("../types/tools.generated.mjs").ReportingWebhook | undefined, import("../types/tools.generated.mjs").ReportingWebhook | undefined, z.core.$ZodTypeInternals<import("../types/tools.generated.mjs").ReportingWebhook | undefined, import("../types/tools.generated.mjs").ReportingWebhook | undefined>>;
10407
10407
  push_notification_config: z.ZodType<import("../types/tools.generated.mjs").PushNotificationConfig | undefined, import("../types/tools.generated.mjs").PushNotificationConfig | undefined, z.core.$ZodTypeInternals<import("../types/tools.generated.mjs").PushNotificationConfig | undefined, import("../types/tools.generated.mjs").PushNotificationConfig | undefined>>;
10408
10408
  idempotency_key: z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
@@ -10400,9 +10400,9 @@ declare const UpdateMediaBuyToolRequestSchema: z.ZodObject<WithOptionalAccountSh
10400
10400
  cancellation_reason: z.ZodType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
10401
10401
  start_time: z.ZodType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
10402
10402
  end_time: z.ZodType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
10403
- packages: z.ZodType<import("..").PackageUpdate[] | undefined, import("..").PackageUpdate[] | undefined, z.core.$ZodTypeInternals<import("..").PackageUpdate[] | undefined, import("..").PackageUpdate[] | undefined>>;
10403
+ packages: z.ZodType<import("..").LegacyPackageUpdate[] | undefined, import("..").LegacyPackageUpdate[] | undefined, z.core.$ZodTypeInternals<import("..").LegacyPackageUpdate[] | undefined, import("..").LegacyPackageUpdate[] | undefined>>;
10404
10404
  invoice_recipient: z.ZodType<import("../types/tools.generated").BusinessEntity | undefined, import("../types/tools.generated").BusinessEntity | undefined, z.core.$ZodTypeInternals<import("../types/tools.generated").BusinessEntity | undefined, import("../types/tools.generated").BusinessEntity | undefined>>;
10405
- new_packages: z.ZodType<import("..").PackageRequest[] | undefined, import("..").PackageRequest[] | undefined, z.core.$ZodTypeInternals<import("..").PackageRequest[] | undefined, import("..").PackageRequest[] | undefined>>;
10405
+ new_packages: z.ZodType<import("..").LegacyPackageRequest[] | undefined, import("..").LegacyPackageRequest[] | undefined, z.core.$ZodTypeInternals<import("..").LegacyPackageRequest[] | undefined, import("..").LegacyPackageRequest[] | undefined>>;
10406
10406
  reporting_webhook: z.ZodType<import("../types/tools.generated").ReportingWebhook | undefined, import("../types/tools.generated").ReportingWebhook | undefined, z.core.$ZodTypeInternals<import("../types/tools.generated").ReportingWebhook | undefined, import("../types/tools.generated").ReportingWebhook | undefined>>;
10407
10407
  push_notification_config: z.ZodType<import("../types/tools.generated").PushNotificationConfig | undefined, import("../types/tools.generated").PushNotificationConfig | undefined, z.core.$ZodTypeInternals<import("../types/tools.generated").PushNotificationConfig | undefined, import("../types/tools.generated").PushNotificationConfig | undefined>>;
10408
10408
  idempotency_key: z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;