@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.
- package/README.md +19 -3
- package/bin/adcp-fuzz.js +3 -1
- package/dist/lib/adapters/content-standards-adapter.d.mts +9 -9
- package/dist/lib/adapters/content-standards-adapter.d.ts +9 -9
- package/dist/lib/adapters/content-standards-adapter.d.ts.map +1 -1
- package/dist/lib/adapters/content-standards-adapter.js +22 -22
- package/dist/lib/adapters/content-standards-adapter.js.map +1 -1
- package/dist/lib/adapters/content-standards-adapter.mjs +18 -18
- package/dist/lib/adapters/content-standards-adapter.mjs.map +1 -1
- package/dist/lib/adapters/index.d.mts +2 -2
- package/dist/lib/adapters/index.d.ts +2 -2
- package/dist/lib/adapters/index.d.ts.map +1 -1
- package/dist/lib/adapters/index.js +10 -10
- package/dist/lib/adapters/index.js.map +1 -1
- package/dist/lib/adapters/index.mjs +9 -9
- package/dist/lib/adapters/index.mjs.map +1 -1
- package/dist/lib/auth/oauth/authorization-required.d.mts +3 -0
- package/dist/lib/auth/oauth/authorization-required.d.ts +3 -0
- package/dist/lib/auth/oauth/authorization-required.d.ts.map +1 -1
- package/dist/lib/auth/oauth/authorization-required.js +12 -9
- package/dist/lib/auth/oauth/authorization-required.js.map +1 -1
- package/dist/lib/auth/oauth/authorization-required.mjs +12 -9
- package/dist/lib/auth/oauth/authorization-required.mjs.map +1 -1
- package/dist/lib/auth/oauth/provider-cache.d.mts +7 -0
- package/dist/lib/auth/oauth/provider-cache.d.ts +8 -0
- package/dist/lib/auth/oauth/provider-cache.d.ts.map +1 -0
- package/dist/lib/auth/oauth/provider-cache.js +44 -0
- package/dist/lib/auth/oauth/provider-cache.js.map +1 -0
- package/dist/lib/auth/oauth/provider-cache.mjs +19 -0
- package/dist/lib/auth/oauth/provider-cache.mjs.map +1 -0
- package/dist/lib/conformance/invariants/uniformError.js +1 -1
- package/dist/lib/conformance/invariants/uniformError.js.map +1 -1
- package/dist/lib/conformance/invariants/uniformError.mjs +1 -1
- package/dist/lib/conformance/invariants/uniformError.mjs.map +1 -1
- package/dist/lib/conformance/runners.js +1 -1
- package/dist/lib/conformance/runners.js.map +1 -1
- package/dist/lib/conformance/runners.mjs +1 -1
- package/dist/lib/conformance/runners.mjs.map +1 -1
- package/dist/lib/conformance/seeder.js +5 -5
- package/dist/lib/conformance/seeder.js.map +1 -1
- package/dist/lib/conformance/seeder.mjs +5 -5
- package/dist/lib/conformance/seeder.mjs.map +1 -1
- package/dist/lib/core/ADCPMultiAgentClient.d.mts +26 -29
- package/dist/lib/core/ADCPMultiAgentClient.d.ts +26 -29
- package/dist/lib/core/ADCPMultiAgentClient.d.ts.map +1 -1
- package/dist/lib/core/ADCPMultiAgentClient.js +27 -19
- package/dist/lib/core/ADCPMultiAgentClient.js.map +1 -1
- package/dist/lib/core/ADCPMultiAgentClient.mjs +27 -19
- package/dist/lib/core/ADCPMultiAgentClient.mjs.map +1 -1
- package/dist/lib/core/AgentClient.d.mts +148 -138
- package/dist/lib/core/AgentClient.d.ts +148 -138
- package/dist/lib/core/AgentClient.d.ts.map +1 -1
- package/dist/lib/core/AgentClient.js +174 -85
- package/dist/lib/core/AgentClient.js.map +1 -1
- package/dist/lib/core/AgentClient.mjs +174 -85
- package/dist/lib/core/AgentClient.mjs.map +1 -1
- package/dist/lib/core/AsyncHandler.d.mts +18 -16
- package/dist/lib/core/AsyncHandler.d.ts +18 -16
- package/dist/lib/core/AsyncHandler.d.ts.map +1 -1
- package/dist/lib/core/AsyncHandler.js +22 -1
- package/dist/lib/core/AsyncHandler.js.map +1 -1
- package/dist/lib/core/AsyncHandler.mjs +22 -1
- package/dist/lib/core/AsyncHandler.mjs.map +1 -1
- package/dist/lib/core/ConversationTypes.d.mts +6 -2
- package/dist/lib/core/ConversationTypes.d.ts +6 -2
- package/dist/lib/core/ConversationTypes.d.ts.map +1 -1
- package/dist/lib/core/ConversationTypes.js.map +1 -1
- package/dist/lib/core/CreativeAgentClient.d.mts +41 -17
- package/dist/lib/core/CreativeAgentClient.d.ts +41 -17
- package/dist/lib/core/CreativeAgentClient.d.ts.map +1 -1
- package/dist/lib/core/CreativeAgentClient.js +39 -12
- package/dist/lib/core/CreativeAgentClient.js.map +1 -1
- package/dist/lib/core/CreativeAgentClient.mjs +39 -12
- package/dist/lib/core/CreativeAgentClient.mjs.map +1 -1
- package/dist/lib/core/SingleAgentClient.d.mts +129 -52
- package/dist/lib/core/SingleAgentClient.d.ts +129 -52
- package/dist/lib/core/SingleAgentClient.d.ts.map +1 -1
- package/dist/lib/core/SingleAgentClient.js +1748 -218
- package/dist/lib/core/SingleAgentClient.js.map +1 -1
- package/dist/lib/core/SingleAgentClient.mjs +1758 -218
- package/dist/lib/core/SingleAgentClient.mjs.map +1 -1
- package/dist/lib/core/TaskExecutor.d.mts +9 -0
- package/dist/lib/core/TaskExecutor.d.ts +9 -0
- package/dist/lib/core/TaskExecutor.d.ts.map +1 -1
- package/dist/lib/core/TaskExecutor.js +137 -44
- package/dist/lib/core/TaskExecutor.js.map +1 -1
- package/dist/lib/core/TaskExecutor.mjs +137 -44
- package/dist/lib/core/TaskExecutor.mjs.map +1 -1
- package/dist/lib/index.d.mts +111 -17
- package/dist/lib/index.d.ts +111 -17
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +94 -94
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +93 -94
- package/dist/lib/index.mjs.map +1 -1
- package/dist/lib/net/ssrf-fetch.d.mts +13 -1
- package/dist/lib/net/ssrf-fetch.d.ts +13 -1
- package/dist/lib/net/ssrf-fetch.d.ts.map +1 -1
- package/dist/lib/net/ssrf-fetch.js +14 -7
- package/dist/lib/net/ssrf-fetch.js.map +1 -1
- package/dist/lib/net/ssrf-fetch.mjs +14 -7
- package/dist/lib/net/ssrf-fetch.mjs.map +1 -1
- package/dist/lib/protocols/a2a.d.mts +2 -2
- package/dist/lib/protocols/a2a.d.ts +2 -2
- package/dist/lib/protocols/a2a.d.ts.map +1 -1
- package/dist/lib/protocols/a2a.js +14 -9
- package/dist/lib/protocols/a2a.js.map +1 -1
- package/dist/lib/protocols/a2a.mjs +14 -9
- package/dist/lib/protocols/a2a.mjs.map +1 -1
- package/dist/lib/protocols/index.d.mts +20 -3
- package/dist/lib/protocols/index.d.ts +20 -3
- package/dist/lib/protocols/index.d.ts.map +1 -1
- package/dist/lib/protocols/index.js +44 -31
- package/dist/lib/protocols/index.js.map +1 -1
- package/dist/lib/protocols/index.mjs +44 -32
- package/dist/lib/protocols/index.mjs.map +1 -1
- package/dist/lib/protocols/mcp-modern.d.ts.map +1 -1
- package/dist/lib/protocols/mcp-modern.js +87 -12
- package/dist/lib/protocols/mcp-modern.js.map +1 -1
- package/dist/lib/protocols/mcp-modern.mjs +89 -12
- package/dist/lib/protocols/mcp-modern.mjs.map +1 -1
- package/dist/lib/protocols/mcp-tasks.d.mts +3 -0
- package/dist/lib/protocols/mcp-tasks.d.ts +3 -0
- package/dist/lib/protocols/mcp-tasks.d.ts.map +1 -1
- package/dist/lib/protocols/mcp-tasks.js +21 -11
- package/dist/lib/protocols/mcp-tasks.js.map +1 -1
- package/dist/lib/protocols/mcp-tasks.mjs +21 -11
- package/dist/lib/protocols/mcp-tasks.mjs.map +1 -1
- package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
- package/dist/lib/server/create-adcp-server.d.mts +6 -0
- package/dist/lib/server/create-adcp-server.d.ts +6 -0
- package/dist/lib/server/create-adcp-server.d.ts.map +1 -1
- package/dist/lib/server/create-adcp-server.js +295 -48
- package/dist/lib/server/create-adcp-server.js.map +1 -1
- package/dist/lib/server/create-adcp-server.mjs +301 -50
- package/dist/lib/server/create-adcp-server.mjs.map +1 -1
- package/dist/lib/server/decisioning/assembly-helpers.d.mts +27 -13
- package/dist/lib/server/decisioning/assembly-helpers.d.ts +27 -13
- package/dist/lib/server/decisioning/assembly-helpers.d.ts.map +1 -1
- package/dist/lib/server/decisioning/assembly-helpers.js +136 -14
- package/dist/lib/server/decisioning/assembly-helpers.js.map +1 -1
- package/dist/lib/server/decisioning/assembly-helpers.mjs +134 -13
- package/dist/lib/server/decisioning/assembly-helpers.mjs.map +1 -1
- package/dist/lib/server/decisioning/index.d.mts +13 -12
- package/dist/lib/server/decisioning/index.d.ts +13 -12
- package/dist/lib/server/decisioning/index.d.ts.map +1 -1
- package/dist/lib/server/decisioning/index.js +6 -0
- package/dist/lib/server/decisioning/index.js.map +1 -1
- package/dist/lib/server/decisioning/index.mjs +9 -3
- package/dist/lib/server/decisioning/index.mjs.map +1 -1
- package/dist/lib/server/decisioning/list-helpers.d.mts +13 -3
- package/dist/lib/server/decisioning/list-helpers.d.ts +13 -3
- package/dist/lib/server/decisioning/list-helpers.d.ts.map +1 -1
- package/dist/lib/server/decisioning/list-helpers.js +13 -3
- package/dist/lib/server/decisioning/list-helpers.js.map +1 -1
- package/dist/lib/server/decisioning/list-helpers.mjs +11 -2
- package/dist/lib/server/decisioning/list-helpers.mjs.map +1 -1
- package/dist/lib/server/decisioning/manifest-helpers.d.mts +5 -3
- package/dist/lib/server/decisioning/manifest-helpers.d.ts +5 -3
- package/dist/lib/server/decisioning/manifest-helpers.d.ts.map +1 -1
- package/dist/lib/server/decisioning/manifest-helpers.js.map +1 -1
- package/dist/lib/server/decisioning/manifest-helpers.mjs.map +1 -1
- package/dist/lib/server/decisioning/proposal/dispatch.d.mts +2 -2
- package/dist/lib/server/decisioning/proposal/dispatch.d.ts +2 -2
- package/dist/lib/server/decisioning/proposal/dispatch.d.ts.map +1 -1
- package/dist/lib/server/decisioning/proposal/dispatch.js.map +1 -1
- package/dist/lib/server/decisioning/proposal/dispatch.mjs.map +1 -1
- package/dist/lib/server/decisioning/proposal/index.d.mts +1 -1
- package/dist/lib/server/decisioning/proposal/index.d.ts +1 -1
- package/dist/lib/server/decisioning/proposal/index.d.ts.map +1 -1
- package/dist/lib/server/decisioning/proposal/index.js.map +1 -1
- package/dist/lib/server/decisioning/proposal/index.mjs.map +1 -1
- package/dist/lib/server/decisioning/proposal/lifecycle.d.mts +3 -2
- package/dist/lib/server/decisioning/proposal/lifecycle.d.ts +3 -2
- package/dist/lib/server/decisioning/proposal/lifecycle.d.ts.map +1 -1
- package/dist/lib/server/decisioning/proposal/lifecycle.js.map +1 -1
- package/dist/lib/server/decisioning/proposal/lifecycle.mjs.map +1 -1
- package/dist/lib/server/decisioning/proposal/mock-manager.d.mts +3 -3
- package/dist/lib/server/decisioning/proposal/mock-manager.d.ts +3 -3
- package/dist/lib/server/decisioning/proposal/mock-manager.d.ts.map +1 -1
- package/dist/lib/server/decisioning/proposal/mock-manager.js.map +1 -1
- package/dist/lib/server/decisioning/proposal/mock-manager.mjs.map +1 -1
- package/dist/lib/server/decisioning/proposal/types.d.mts +10 -6
- package/dist/lib/server/decisioning/proposal/types.d.ts +10 -6
- package/dist/lib/server/decisioning/proposal/types.d.ts.map +1 -1
- package/dist/lib/server/decisioning/proposal/types.js.map +1 -1
- package/dist/lib/server/decisioning/proposal/types.mjs.map +1 -1
- package/dist/lib/server/decisioning/runtime/from-platform.d.mts +21 -2
- package/dist/lib/server/decisioning/runtime/from-platform.d.ts +21 -2
- package/dist/lib/server/decisioning/runtime/from-platform.d.ts.map +1 -1
- package/dist/lib/server/decisioning/runtime/from-platform.js +754 -81
- package/dist/lib/server/decisioning/runtime/from-platform.js.map +1 -1
- package/dist/lib/server/decisioning/runtime/from-platform.mjs +763 -81
- package/dist/lib/server/decisioning/runtime/from-platform.mjs.map +1 -1
- package/dist/lib/server/decisioning/specialisms/brand-rights.d.mts +9 -9
- package/dist/lib/server/decisioning/specialisms/brand-rights.d.ts +9 -9
- package/dist/lib/server/decisioning/specialisms/brand-rights.d.ts.map +1 -1
- package/dist/lib/server/decisioning/specialisms/brand-rights.js.map +1 -1
- package/dist/lib/server/decisioning/specialisms/content-standards.d.mts +16 -16
- package/dist/lib/server/decisioning/specialisms/content-standards.d.ts +16 -16
- package/dist/lib/server/decisioning/specialisms/content-standards.d.ts.map +1 -1
- package/dist/lib/server/decisioning/specialisms/content-standards.js.map +1 -1
- package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.mts +15 -13
- package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.ts +15 -13
- package/dist/lib/server/decisioning/specialisms/creative-ad-server.d.ts.map +1 -1
- package/dist/lib/server/decisioning/specialisms/creative-ad-server.js.map +1 -1
- package/dist/lib/server/decisioning/specialisms/creative.d.mts +12 -11
- package/dist/lib/server/decisioning/specialisms/creative.d.ts +12 -11
- package/dist/lib/server/decisioning/specialisms/creative.d.ts.map +1 -1
- package/dist/lib/server/decisioning/specialisms/creative.js.map +1 -1
- package/dist/lib/server/decisioning/specialisms/sales.d.mts +25 -15
- package/dist/lib/server/decisioning/specialisms/sales.d.ts +25 -15
- package/dist/lib/server/decisioning/specialisms/sales.d.ts.map +1 -1
- package/dist/lib/server/decisioning/specialisms/sales.js.map +1 -1
- package/dist/lib/server/index.d.mts +3 -3
- package/dist/lib/server/index.d.ts +3 -3
- package/dist/lib/server/index.d.ts.map +1 -1
- package/dist/lib/server/index.js +72 -72
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/server/index.mjs +36 -36
- package/dist/lib/server/index.mjs.map +1 -1
- package/dist/lib/server/legacy/v5/index.d.mts +1 -0
- package/dist/lib/server/legacy/v5/index.d.ts +1 -0
- package/dist/lib/server/legacy/v5/index.d.ts.map +1 -1
- package/dist/lib/server/legacy/v5/index.js +74 -1
- package/dist/lib/server/legacy/v5/index.js.map +1 -1
- package/dist/lib/server/legacy/v5/index.mjs +75 -1
- package/dist/lib/server/legacy/v5/index.mjs.map +1 -1
- package/dist/lib/server/responses.d.mts +2 -2
- package/dist/lib/server/responses.d.ts +2 -2
- package/dist/lib/server/responses.js.map +1 -1
- package/dist/lib/server/responses.mjs.map +1 -1
- package/dist/lib/testing/client.d.ts.map +1 -1
- package/dist/lib/testing/client.js +13 -5
- package/dist/lib/testing/client.js.map +1 -1
- package/dist/lib/testing/client.mjs +13 -5
- package/dist/lib/testing/client.mjs.map +1 -1
- package/dist/lib/testing/compliance/comply.d.mts +1 -1
- package/dist/lib/testing/compliance/comply.d.ts +1 -1
- package/dist/lib/testing/compliance/comply.d.ts.map +1 -1
- package/dist/lib/testing/compliance/comply.js +16 -6
- package/dist/lib/testing/compliance/comply.js.map +1 -1
- package/dist/lib/testing/compliance/comply.mjs +16 -6
- package/dist/lib/testing/compliance/comply.mjs.map +1 -1
- package/dist/lib/testing/scenarios/brand-rights.js +6 -6
- package/dist/lib/testing/scenarios/brand-rights.js.map +1 -1
- package/dist/lib/testing/scenarios/brand-rights.mjs +6 -6
- package/dist/lib/testing/scenarios/brand-rights.mjs.map +1 -1
- package/dist/lib/testing/scenarios/creative.js +7 -7
- package/dist/lib/testing/scenarios/creative.js.map +1 -1
- package/dist/lib/testing/scenarios/creative.mjs +7 -7
- package/dist/lib/testing/scenarios/creative.mjs.map +1 -1
- package/dist/lib/testing/scenarios/discovery.js +2 -2
- package/dist/lib/testing/scenarios/discovery.js.map +1 -1
- package/dist/lib/testing/scenarios/discovery.mjs +2 -2
- package/dist/lib/testing/scenarios/discovery.mjs.map +1 -1
- package/dist/lib/testing/scenarios/edge-cases.js +11 -11
- package/dist/lib/testing/scenarios/edge-cases.js.map +1 -1
- package/dist/lib/testing/scenarios/edge-cases.mjs +11 -11
- package/dist/lib/testing/scenarios/edge-cases.mjs.map +1 -1
- package/dist/lib/testing/scenarios/governance.d.ts.map +1 -1
- package/dist/lib/testing/scenarios/governance.js +16 -22
- package/dist/lib/testing/scenarios/governance.js.map +1 -1
- package/dist/lib/testing/scenarios/governance.mjs +16 -22
- package/dist/lib/testing/scenarios/governance.mjs.map +1 -1
- package/dist/lib/testing/scenarios/media-buy.js +5 -5
- package/dist/lib/testing/scenarios/media-buy.js.map +1 -1
- package/dist/lib/testing/scenarios/media-buy.mjs +5 -5
- package/dist/lib/testing/scenarios/media-buy.mjs.map +1 -1
- package/dist/lib/testing/scenarios/schema-compliance.js +1 -1
- package/dist/lib/testing/scenarios/schema-compliance.js.map +1 -1
- package/dist/lib/testing/scenarios/schema-compliance.mjs +1 -1
- package/dist/lib/testing/scenarios/schema-compliance.mjs.map +1 -1
- package/dist/lib/testing/scenarios/trusted-match.d.ts.map +1 -1
- package/dist/lib/testing/scenarios/trusted-match.js +4 -3
- package/dist/lib/testing/scenarios/trusted-match.js.map +1 -1
- package/dist/lib/testing/scenarios/trusted-match.mjs +4 -3
- package/dist/lib/testing/scenarios/trusted-match.mjs.map +1 -1
- package/dist/lib/testing/storyboard/probes.d.mts +6 -0
- package/dist/lib/testing/storyboard/probes.d.ts +6 -0
- package/dist/lib/testing/storyboard/probes.d.ts.map +1 -1
- package/dist/lib/testing/storyboard/probes.js +16 -5
- package/dist/lib/testing/storyboard/probes.js.map +1 -1
- package/dist/lib/testing/storyboard/probes.mjs +16 -5
- package/dist/lib/testing/storyboard/probes.mjs.map +1 -1
- package/dist/lib/testing/storyboard/runner.d.ts.map +1 -1
- package/dist/lib/testing/storyboard/runner.js +6 -2
- package/dist/lib/testing/storyboard/runner.js.map +1 -1
- package/dist/lib/testing/storyboard/runner.mjs +6 -2
- package/dist/lib/testing/storyboard/runner.mjs.map +1 -1
- package/dist/lib/testing/storyboard/shape-drift-hints.d.mts +3 -4
- package/dist/lib/testing/storyboard/shape-drift-hints.d.ts +3 -4
- package/dist/lib/testing/storyboard/shape-drift-hints.d.ts.map +1 -1
- package/dist/lib/testing/storyboard/shape-drift-hints.js +27 -27
- package/dist/lib/testing/storyboard/shape-drift-hints.js.map +1 -1
- package/dist/lib/testing/storyboard/shape-drift-hints.mjs +27 -27
- package/dist/lib/testing/storyboard/shape-drift-hints.mjs.map +1 -1
- package/dist/lib/testing/storyboard/task-map.d.ts.map +1 -1
- package/dist/lib/testing/storyboard/task-map.js +43 -5
- package/dist/lib/testing/storyboard/task-map.js.map +1 -1
- package/dist/lib/testing/storyboard/task-map.mjs +43 -5
- package/dist/lib/testing/storyboard/task-map.mjs.map +1 -1
- package/dist/lib/testing/test-helpers.d.mts +2 -2
- package/dist/lib/testing/test-helpers.d.ts +2 -2
- package/dist/lib/testing/test-helpers.js.map +1 -1
- package/dist/lib/testing/test-helpers.mjs.map +1 -1
- package/dist/lib/testing/types.d.mts +7 -1
- package/dist/lib/testing/types.d.ts +7 -1
- package/dist/lib/testing/types.d.ts.map +1 -1
- package/dist/lib/testing/types.js.map +1 -1
- package/dist/lib/types/adcp.d.mts +14 -14
- package/dist/lib/types/adcp.d.ts +14 -14
- package/dist/lib/types/adcp.d.ts.map +1 -1
- package/dist/lib/types/adcp.js.map +1 -1
- package/dist/lib/types/adcp.mjs.map +1 -1
- package/dist/lib/types/index.d.mts +2 -2
- package/dist/lib/types/index.d.ts +2 -2
- package/dist/lib/types/index.d.ts.map +1 -1
- package/dist/lib/types/index.js.map +1 -1
- package/dist/lib/types/index.mjs.map +1 -1
- package/dist/lib/utils/capabilities.d.mts +6 -0
- package/dist/lib/utils/capabilities.d.ts +6 -0
- package/dist/lib/utils/capabilities.d.ts.map +1 -1
- package/dist/lib/utils/capabilities.js +4 -0
- package/dist/lib/utils/capabilities.js.map +1 -1
- package/dist/lib/utils/capabilities.mjs +4 -0
- package/dist/lib/utils/capabilities.mjs.map +1 -1
- package/dist/lib/utils/creative-delivery.d.mts +52 -10
- package/dist/lib/utils/creative-delivery.d.ts +52 -10
- package/dist/lib/utils/creative-delivery.d.ts.map +1 -1
- package/dist/lib/utils/creative-delivery.js +104 -9
- package/dist/lib/utils/creative-delivery.js.map +1 -1
- package/dist/lib/utils/creative-delivery.mjs +104 -8
- package/dist/lib/utils/creative-delivery.mjs.map +1 -1
- package/dist/lib/utils/format-assets.d.mts +41 -38
- package/dist/lib/utils/format-assets.d.ts +41 -38
- package/dist/lib/utils/format-assets.d.ts.map +1 -1
- package/dist/lib/utils/format-assets.js +3 -1
- package/dist/lib/utils/format-assets.js.map +1 -1
- package/dist/lib/utils/format-assets.mjs +3 -1
- package/dist/lib/utils/format-assets.mjs.map +1 -1
- package/dist/lib/utils/index.d.mts +8 -8
- package/dist/lib/utils/index.d.ts +8 -8
- package/dist/lib/utils/index.d.ts.map +1 -1
- package/dist/lib/utils/index.js +11 -9
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/index.mjs +9 -8
- package/dist/lib/utils/index.mjs.map +1 -1
- package/dist/lib/utils/preview-utils.d.mts +11 -8
- package/dist/lib/utils/preview-utils.d.ts +11 -8
- package/dist/lib/utils/preview-utils.d.ts.map +1 -1
- package/dist/lib/utils/preview-utils.js +4 -4
- package/dist/lib/utils/preview-utils.js.map +1 -1
- package/dist/lib/utils/preview-utils.mjs +3 -3
- package/dist/lib/utils/preview-utils.mjs.map +1 -1
- package/dist/lib/utils/tool-request-schemas.d.mts +2 -2
- package/dist/lib/utils/tool-request-schemas.d.ts +2 -2
- package/dist/lib/v2/projection/aao-reference-formats.json +492 -0
- package/dist/lib/v2/projection/augment-response.d.mts +31 -11
- package/dist/lib/v2/projection/augment-response.d.ts +31 -11
- package/dist/lib/v2/projection/augment-response.d.ts.map +1 -1
- package/dist/lib/v2/projection/augment-response.js +233 -27
- package/dist/lib/v2/projection/augment-response.js.map +1 -1
- package/dist/lib/v2/projection/augment-response.mjs +232 -27
- package/dist/lib/v2/projection/augment-response.mjs.map +1 -1
- package/dist/lib/v2/projection/builders.d.mts +7 -6
- package/dist/lib/v2/projection/builders.d.ts +7 -6
- package/dist/lib/v2/projection/builders.d.ts.map +1 -1
- package/dist/lib/v2/projection/builders.js +11 -8
- package/dist/lib/v2/projection/builders.js.map +1 -1
- package/dist/lib/v2/projection/builders.mjs +9 -6
- package/dist/lib/v2/projection/builders.mjs.map +1 -1
- package/dist/lib/v2/projection/catalog-snapshot.d.mts +47 -0
- package/dist/lib/v2/projection/catalog-snapshot.d.ts +48 -0
- package/dist/lib/v2/projection/catalog-snapshot.d.ts.map +1 -0
- package/dist/lib/v2/projection/catalog-snapshot.js +291 -0
- package/dist/lib/v2/projection/catalog-snapshot.js.map +1 -0
- package/dist/lib/v2/projection/catalog-snapshot.mjs +265 -0
- package/dist/lib/v2/projection/catalog-snapshot.mjs.map +1 -0
- package/dist/lib/v2/projection/catalog.d.mts +23 -2
- package/dist/lib/v2/projection/catalog.d.ts +23 -2
- package/dist/lib/v2/projection/catalog.d.ts.map +1 -1
- package/dist/lib/v2/projection/catalog.js +34 -10
- package/dist/lib/v2/projection/catalog.js.map +1 -1
- package/dist/lib/v2/projection/catalog.mjs +33 -10
- package/dist/lib/v2/projection/catalog.mjs.map +1 -1
- package/dist/lib/v2/projection/creative-delivery.d.mts +157 -0
- package/dist/lib/v2/projection/creative-delivery.d.ts +158 -0
- package/dist/lib/v2/projection/creative-delivery.d.ts.map +1 -0
- package/dist/lib/v2/projection/creative-delivery.js +967 -0
- package/dist/lib/v2/projection/creative-delivery.js.map +1 -0
- package/dist/lib/v2/projection/creative-delivery.mjs +941 -0
- package/dist/lib/v2/projection/creative-delivery.mjs.map +1 -0
- package/dist/lib/v2/projection/index.d.mts +8 -6
- package/dist/lib/v2/projection/index.d.ts +8 -6
- package/dist/lib/v2/projection/index.d.ts.map +1 -1
- package/dist/lib/v2/projection/index.js +26 -4
- package/dist/lib/v2/projection/index.js.map +1 -1
- package/dist/lib/v2/projection/index.mjs +28 -4
- package/dist/lib/v2/projection/index.mjs.map +1 -1
- package/dist/lib/v2/projection/legacy-metadata.d.mts +21 -0
- package/dist/lib/v2/projection/legacy-metadata.d.ts +22 -0
- package/dist/lib/v2/projection/legacy-metadata.d.ts.map +1 -0
- package/dist/lib/v2/projection/legacy-metadata.js +73 -0
- package/dist/lib/v2/projection/legacy-metadata.js.map +1 -0
- package/dist/lib/v2/projection/legacy-metadata.mjs +45 -0
- package/dist/lib/v2/projection/legacy-metadata.mjs.map +1 -0
- package/dist/lib/v2/projection/types.d.mts +29 -23
- package/dist/lib/v2/projection/types.d.ts +29 -23
- package/dist/lib/v2/projection/types.d.ts.map +1 -1
- package/dist/lib/v2/projection/types.js.map +1 -1
- package/dist/lib/v2/projection/v1-to-v2.d.mts +29 -6
- package/dist/lib/v2/projection/v1-to-v2.d.ts +29 -6
- package/dist/lib/v2/projection/v1-to-v2.d.ts.map +1 -1
- package/dist/lib/v2/projection/v1-to-v2.js +218 -9
- package/dist/lib/v2/projection/v1-to-v2.js.map +1 -1
- package/dist/lib/v2/projection/v1-to-v2.mjs +219 -10
- package/dist/lib/v2/projection/v1-to-v2.mjs.map +1 -1
- package/dist/lib/v2/projection/v2-to-v1.d.mts +31 -2
- package/dist/lib/v2/projection/v2-to-v1.d.ts +31 -2
- package/dist/lib/v2/projection/v2-to-v1.d.ts.map +1 -1
- package/dist/lib/v2/projection/v2-to-v1.js +138 -7
- package/dist/lib/v2/projection/v2-to-v1.js.map +1 -1
- package/dist/lib/v2/projection/v2-to-v1.mjs +135 -6
- package/dist/lib/v2/projection/v2-to-v1.mjs.map +1 -1
- package/dist/lib/v2/projection/write-side.d.mts +12 -13
- package/dist/lib/v2/projection/write-side.d.ts +12 -13
- package/dist/lib/v2/projection/write-side.d.ts.map +1 -1
- package/dist/lib/v2/projection/write-side.js +16 -12
- package/dist/lib/v2/projection/write-side.js.map +1 -1
- package/dist/lib/v2/projection/write-side.mjs +16 -12
- package/dist/lib/v2/projection/write-side.mjs.map +1 -1
- package/dist/lib/version.d.mts +3 -3
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.d.ts.map +1 -1
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.js.map +1 -1
- package/dist/lib/version.mjs +3 -3
- package/dist/lib/version.mjs.map +1 -1
- package/docs/guides/BUILD-AN-AGENT.md +7 -2
- package/docs/guides/PREVIEW-ASSET-DURABILITY.md +6 -2
- package/docs/llms.txt +1 -0
- package/examples/README.md +1 -1
- package/examples/batch-preview-test.ts +3 -3
- package/examples/conversation-client.ts +2 -2
- package/examples/debug-preview-response.ts +1 -1
- package/examples/decisioning-platform-broadcast-tv.ts +10 -4
- package/examples/decisioning-platform-mock-seller.ts +16 -9
- package/examples/decisioning-platform-programmatic.ts +18 -7
- package/examples/error-compliant-server.ts +26 -16
- package/examples/generative-creative-demo.ts +7 -19
- package/examples/hello_creative_adapter_ad_server.ts +37 -16
- package/examples/hello_creative_adapter_template.ts +12 -10
- package/examples/hello_seller_adapter_guaranteed.ts +52 -23
- package/examples/hello_seller_adapter_multi_tenant.ts +6 -3
- package/examples/hello_seller_adapter_non_guaranteed.ts +54 -26
- package/examples/hello_seller_adapter_proposal_mode.ts +40 -14
- package/examples/hello_seller_adapter_social.ts +2 -7
- package/examples/inspect-card-formats.ts +1 -1
- package/examples/simple-getting-started.ts +1 -1
- package/examples/test-helpers-demo.ts +1 -1
- package/package.json +2 -2
- package/skills/build-decisioning-creative-template/SKILL.md +11 -11
- 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,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,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":[]}
|
|
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;AAC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Ac;AAC3F,gBAAM,YAAY,QAAQ;AAE1B,cAAI,YAAY;AACd,oBAAQ,KAAK;AAAA,cACX,MAAM,IAAI;AAAA,cACV;AAAA,cACA;AAAA,YACF,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
|
|
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.
|
|
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
|
-
|
|
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,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,cACA,UACA,YACA,WACA,WACe;AACf,QAAM,aAAa,IAAI,UAAU;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,KAAK,IAAI;AAAA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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":"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,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,iBAC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AA,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":[]}
|
|
@@ -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").
|
|
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").
|
|
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("..").
|
|
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("..").
|
|
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>>;
|