@adcp/sdk 13.0.0-rc.13 → 13.0.0-rc.14

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 (73) hide show
  1. package/dist/lib/index.d.mts +2 -2
  2. package/dist/lib/index.d.ts +2 -2
  3. package/dist/lib/index.d.ts.map +1 -1
  4. package/dist/lib/index.js +6 -0
  5. package/dist/lib/index.js.map +1 -1
  6. package/dist/lib/index.mjs +6 -0
  7. package/dist/lib/index.mjs.map +1 -1
  8. package/dist/lib/protocols/transportDiagnostics.js +2 -1
  9. package/dist/lib/protocols/transportDiagnostics.js.map +1 -1
  10. package/dist/lib/protocols/transportDiagnostics.mjs +2 -1
  11. package/dist/lib/protocols/transportDiagnostics.mjs.map +1 -1
  12. package/dist/lib/registry/index.d.mts +17 -0
  13. package/dist/lib/registry/index.d.ts +17 -0
  14. package/dist/lib/registry/index.d.ts.map +1 -1
  15. package/dist/lib/registry/index.js +81 -7
  16. package/dist/lib/registry/index.js.map +1 -1
  17. package/dist/lib/registry/index.mjs +79 -7
  18. package/dist/lib/registry/index.mjs.map +1 -1
  19. package/dist/lib/registry/types.generated.d.mts +157 -7
  20. package/dist/lib/registry/types.generated.d.ts +157 -7
  21. package/dist/lib/registry/types.generated.d.ts.map +1 -1
  22. package/dist/lib/registry/types.generated.js.map +1 -1
  23. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  24. package/dist/lib/server/errors.d.mts +10 -2
  25. package/dist/lib/server/errors.d.ts +10 -2
  26. package/dist/lib/server/errors.d.ts.map +1 -1
  27. package/dist/lib/server/errors.js +9 -2
  28. package/dist/lib/server/errors.js.map +1 -1
  29. package/dist/lib/server/errors.mjs +9 -2
  30. package/dist/lib/server/errors.mjs.map +1 -1
  31. package/dist/lib/testing/compliance/comply.d.mts +6 -0
  32. package/dist/lib/testing/compliance/comply.d.ts +6 -0
  33. package/dist/lib/testing/compliance/comply.d.ts.map +1 -1
  34. package/dist/lib/testing/compliance/comply.js +3 -0
  35. package/dist/lib/testing/compliance/comply.js.map +1 -1
  36. package/dist/lib/testing/compliance/comply.mjs +3 -0
  37. package/dist/lib/testing/compliance/comply.mjs.map +1 -1
  38. package/dist/lib/testing/storyboard/runner.d.ts.map +1 -1
  39. package/dist/lib/testing/storyboard/runner.js +31 -5
  40. package/dist/lib/testing/storyboard/runner.js.map +1 -1
  41. package/dist/lib/testing/storyboard/runner.mjs +36 -6
  42. package/dist/lib/testing/storyboard/runner.mjs.map +1 -1
  43. package/dist/lib/testing/storyboard/types.d.mts +16 -5
  44. package/dist/lib/testing/storyboard/types.d.ts +16 -5
  45. package/dist/lib/testing/storyboard/types.d.ts.map +1 -1
  46. package/dist/lib/testing/storyboard/types.js +1 -1
  47. package/dist/lib/testing/storyboard/types.js.map +1 -1
  48. package/dist/lib/testing/storyboard/types.mjs +1 -1
  49. package/dist/lib/testing/storyboard/types.mjs.map +1 -1
  50. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  51. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  52. package/dist/lib/v2/projection/augment-response.d.mts +16 -0
  53. package/dist/lib/v2/projection/augment-response.d.ts +16 -0
  54. package/dist/lib/v2/projection/augment-response.d.ts.map +1 -1
  55. package/dist/lib/v2/projection/augment-response.js +13 -4
  56. package/dist/lib/v2/projection/augment-response.js.map +1 -1
  57. package/dist/lib/v2/projection/augment-response.mjs +12 -4
  58. package/dist/lib/v2/projection/augment-response.mjs.map +1 -1
  59. package/dist/lib/v2/projection/index.d.mts +3 -1
  60. package/dist/lib/v2/projection/index.d.ts +3 -1
  61. package/dist/lib/v2/projection/index.d.ts.map +1 -1
  62. package/dist/lib/v2/projection/index.js +2 -0
  63. package/dist/lib/v2/projection/index.js.map +1 -1
  64. package/dist/lib/v2/projection/index.mjs +2 -0
  65. package/dist/lib/v2/projection/index.mjs.map +1 -1
  66. package/dist/lib/version.d.mts +3 -3
  67. package/dist/lib/version.d.ts +3 -3
  68. package/dist/lib/version.js +3 -3
  69. package/dist/lib/version.js.map +1 -1
  70. package/dist/lib/version.mjs +3 -3
  71. package/dist/lib/version.mjs.map +1 -1
  72. package/examples/error-compliant-server.ts +9 -3
  73. package/package.json +1 -1
@@ -195,7 +195,7 @@ export interface UpstreamTrafficQueryResult {
195
195
  */
196
196
  export declare function runValidations(validations: StoryboardValidation[], context: ValidationContext): ValidationResult[];
197
197
  /** Capability semver emitted in run summaries and used for advisory expiry. */
198
- export declare const RUNNER_CAPABILITY_VERSION = "13.0.0-rc.13";
198
+ export declare const RUNNER_CAPABILITY_VERSION = "13.0.0-rc.14";
199
199
  /** True when a failed validation contributes to the owning step's grade. */
200
200
  export declare function validationFailsStep(result: ValidationResult): boolean;
201
201
  /**
@@ -195,7 +195,7 @@ export interface UpstreamTrafficQueryResult {
195
195
  */
196
196
  export declare function runValidations(validations: StoryboardValidation[], context: ValidationContext): ValidationResult[];
197
197
  /** Capability semver emitted in run summaries and used for advisory expiry. */
198
- export declare const RUNNER_CAPABILITY_VERSION = "13.0.0-rc.13";
198
+ export declare const RUNNER_CAPABILITY_VERSION = "13.0.0-rc.14";
199
199
  /** True when a failed validation contributes to the owning step's grade. */
200
200
  export declare function validationFailsStep(result: ValidationResult): boolean;
201
201
  /**
@@ -101,6 +101,22 @@ export declare function withFormatOptions<R extends {
101
101
  export type AdditiveCanonicalProduct<P> = Omit<P, 'format_options'> & {
102
102
  format_options: CanonicalFormatDeclaration[];
103
103
  };
104
+ /**
105
+ * Conceal migration-only legacy identities from canonical format declarations
106
+ * while extracting their durable downgrade routes first.
107
+ *
108
+ * This is the declaration-array counterpart to
109
+ * {@link toAdditiveCanonicalProduct}. It is intended for persisted catalogs
110
+ * and other consumers that do not hold a complete Product. The source array
111
+ * and declarations are never mutated.
112
+ *
113
+ * @throws TypeError when a canonical declaration uses a direct legacy identity
114
+ * alias such as `agent_url` or `agentUrl` instead of `v1_format_ref`.
115
+ */
116
+ export declare function toCanonicalFormatOptionsWithRoutes(productId: string, formatOptions: readonly V2ProductFormatDeclaration[]): {
117
+ formatOptions: CanonicalFormatDeclaration[];
118
+ routes: CanonicalFormatLegacyRoute[];
119
+ };
104
120
  /**
105
121
  * Project a Product to an additive, URL-free canonical surface.
106
122
  *
@@ -101,6 +101,22 @@ export declare function withFormatOptions<R extends {
101
101
  export type AdditiveCanonicalProduct<P> = Omit<P, 'format_options'> & {
102
102
  format_options: CanonicalFormatDeclaration[];
103
103
  };
104
+ /**
105
+ * Conceal migration-only legacy identities from canonical format declarations
106
+ * while extracting their durable downgrade routes first.
107
+ *
108
+ * This is the declaration-array counterpart to
109
+ * {@link toAdditiveCanonicalProduct}. It is intended for persisted catalogs
110
+ * and other consumers that do not hold a complete Product. The source array
111
+ * and declarations are never mutated.
112
+ *
113
+ * @throws TypeError when a canonical declaration uses a direct legacy identity
114
+ * alias such as `agent_url` or `agentUrl` instead of `v1_format_ref`.
115
+ */
116
+ export declare function toCanonicalFormatOptionsWithRoutes(productId: string, formatOptions: readonly V2ProductFormatDeclaration[]): {
117
+ formatOptions: CanonicalFormatDeclaration[];
118
+ routes: CanonicalFormatLegacyRoute[];
119
+ };
104
120
  /**
105
121
  * Project a Product to an additive, URL-free canonical surface.
106
122
  *
@@ -1 +1 @@
1
- {"version":3,"file":"augment-response.d.ts","sourceRoot":"","sources":["../../../../src/lib/v2/projection/augment-response.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEvG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAI1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAgBlE,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CA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,QAAQ,EAAE,CAAC,EACX,OAAO,CAAC,EAAE,uBAAuB,GAChC;IACD,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG;QAAE,QAAQ,EAAE,wBAAwB,CAAC,SAAS,CAAC,EAAE,CAAA;KAAE,CAAC;IACpF,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,MAAM,EAAE,0BAA0B,EAAE,CAAC;CACtC,CA0BA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG;IAC5D,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,cAAc,EAAE,0BAA0B,EAAE,CAAC;CAC9C,CAAC;AA2DF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,SAAS,EACxD,OAAO,EAAE,CAAC,EACV,OAAO,CAAC,EAAE,uBAAuB,GAChC;IAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAAC,WAAW,EAAE,oBAAoB,EAAE,CAAA;CAAE,CA+E3E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAA;CAAE,EAC1E,QAAQ,EAAE,CAAC,EACX,OAAO,CAAC,EAAE,uBAAuB,GAChC;IACD,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG;QAAE,QAAQ,EAAE,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC;IACpG,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACrC,CA8DA"}
@@ -21,6 +21,7 @@ __export(augment_response_exports, {
21
21
  augmentProductWithFormatOptions: () => augmentProductWithFormatOptions,
22
22
  projectionDiagnosticToError: () => projectionDiagnosticToError,
23
23
  toAdditiveCanonicalProduct: () => toAdditiveCanonicalProduct,
24
+ toCanonicalFormatOptionsWithRoutes: () => toCanonicalFormatOptionsWithRoutes,
24
25
  toCanonicalOnlyProduct: () => toCanonicalOnlyProduct,
25
26
  toCanonicalOnlyResponse: () => toCanonicalOnlyResponse,
26
27
  withAdditiveCanonicalFormatOptions: () => withAdditiveCanonicalFormatOptions,
@@ -213,17 +214,24 @@ function assertNoDirectLegacyFormatAliases(declarations) {
213
214
  }
214
215
  }
215
216
  }
217
+ function toCanonicalFormatOptionsWithRoutes(productId, formatOptions) {
218
+ assertNoDirectLegacyFormatAliases(formatOptions);
219
+ const routes = (0, import_legacy_routes.legacyRoutesForProduct)(productId, formatOptions);
220
+ return {
221
+ formatOptions: canonicalDeclarations(formatOptions),
222
+ routes
223
+ };
224
+ }
216
225
  function toAdditiveCanonicalProduct(product, options) {
217
226
  const { product: augmented, diagnostics } = augmentProductWithFormatOptions(product, options);
218
- const routes = (0, import_legacy_routes.legacyRoutesForProduct)(product.product_id, augmented.format_options);
219
- assertNoDirectLegacyFormatAliases(augmented.format_options);
227
+ const projected = toCanonicalFormatOptionsWithRoutes(product.product_id, augmented.format_options);
220
228
  return {
221
229
  product: {
222
230
  ...augmented,
223
- format_options: canonicalDeclarations(augmented.format_options)
231
+ format_options: projected.formatOptions
224
232
  },
225
233
  diagnostics,
226
- routes
234
+ routes: projected.routes
227
235
  };
228
236
  }
229
237
  function withAdditiveCanonicalFormatOptions(response, options) {
@@ -411,6 +419,7 @@ function toCanonicalOnlyResponse(response, options) {
411
419
  augmentProductWithFormatOptions,
412
420
  projectionDiagnosticToError,
413
421
  toAdditiveCanonicalProduct,
422
+ toCanonicalFormatOptionsWithRoutes,
414
423
  toCanonicalOnlyProduct,
415
424
  toCanonicalOnlyResponse,
416
425
  withAdditiveCanonicalFormatOptions,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/v2/projection/augment-response.ts"],"sourcesContent":["/**\n * Buyer-side helpers that augment a v1-shaped agent response with v2\n * `format_options[]` derived from the existing `format_ids[]` on each\n * Product.\n *\n * Buyers who want the canonical creative-format model call\n * `withFormatOptions(response)` and read `format_options` instead of\n * relying only on legacy `format_ids`.\n *\n * The SDK also auto-projects compatible `AgentClient.getProducts()`\n * responses; this helper remains useful for cached responses, fixtures,\n * upstream seller/storefront composition, and explicit migration code.\n *\n * Pure functions — no IO, no caching. Each Product is projected\n * independently; diagnostics aggregate so a multi-product response\n * surfaces every projection issue at once. The helpers preserve the\n * input shape verbatim and add `format_options[]` (additive). They do\n * NOT drop `format_ids[]` — that's the 8.0 narrowing. To DROP\n * `format_ids[]` once a consumer has fully migrated, use\n * `toCanonicalOnlyProduct` / `toCanonicalOnlyResponse`.\n */\n\nimport type { V1Product, V1FormatId, V2ProductFormatDeclaration, ProjectionDiagnostic } from './types';\nimport { projectV1ProductToV2 } from './v1-to-v2';\nimport type { V1ToV2ProjectionOptions } from './v1-to-v2';\nimport { LIBRARY_VERSION } from '../../version';\nimport { canonicalize as canonicalizeJson } from '../../utils/jcs';\nimport { concealLegacyFormatRefs } from './legacy-metadata';\nimport type { CanonicalFormatDeclaration } from './legacy-metadata';\nimport { legacyRoutesForProduct } from './legacy-routes';\nimport type { CanonicalFormatLegacyRoute } from './legacy-routes';\n\nconst SDK_ID = `@adcp/sdk@${LIBRARY_VERSION}`;\nconst DIRECT_LEGACY_FORMAT_IDENTITY_KEYS = new Set(['agenturl', 'formatid', 'formatids', 'v1formatref']);\n\nfunction canonicalDiagnostic(diagnostic: ProjectionDiagnostic): ProjectionDiagnostic {\n return {\n ...diagnostic,\n // A source `format_ids[i]` index is not an index into the projected\n // `format_options[]`: earlier source refs may have failed while later refs\n // projected successfully. Point at the canonical collection instead of\n // claiming that a successful projected option is the failing value.\n field: diagnostic.field.replace(/\\.format_ids\\[\\d+\\]/g, '.format_options'),\n };\n}\n\n/** Protocol Error shape used for portable response-level projection advisories. */\nexport interface CanonicalProjectionError {\n code: ProjectionDiagnostic['code'];\n message: string;\n field: string;\n recovery: 'correctable';\n source: 'sdk';\n sdk_id: string;\n details: ProjectionDiagnostic['error']['details'];\n}\n\nfunction projectionErrorMessage(code: ProjectionDiagnostic['code']): string {\n switch (code) {\n case 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE':\n return 'Product has no format declaration representable on the canonical-only surface';\n case 'FORMAT_PROJECTION_FAILED':\n return 'Legacy creative format could not be projected to a canonical declaration';\n case 'FORMAT_DECLARATION_V1_AMBIGUOUS':\n return 'Canonical creative format has no unambiguous legacy declaration';\n case 'FORMAT_DECLARATION_V1_NOT_APPLICABLE':\n return 'Canonical-only creative format cannot be represented on a legacy format path';\n case 'CANONICAL_NOT_V1_TRANSLATABLE':\n return 'Canonical creative format has no legacy representation';\n case 'FORMAT_DECLARATION_V1_LOSSY_MULTI_SIZE':\n return 'Canonical multi-size format has incomplete legacy coverage';\n case 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED':\n return 'Redundant legacy creative identity has no canonical counterpart';\n }\n}\n\n/** Flatten the projector's internal diagnostic into the protocol `Error` shape. */\nexport function projectionDiagnosticToError(diagnostic: ProjectionDiagnostic): CanonicalProjectionError {\n return {\n code: diagnostic.code,\n message: projectionErrorMessage(diagnostic.code),\n field: diagnostic.field,\n recovery: 'correctable',\n source: diagnostic.source,\n sdk_id: diagnostic.sdk_id,\n details: diagnostic.error.details,\n } as CanonicalProjectionError;\n}\n\nfunction canonicalFormatsUnavailableForProduct(\n product: V1Product,\n reason: Extract<ProjectionDiagnostic, { code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE' }>['error']['details']['reason']\n): ProjectionDiagnostic {\n return {\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE',\n error: {\n details: {\n product_id: product.product_id,\n reason,\n },\n },\n };\n}\n\nfunction errorIdentity(value: Record<string, unknown>): string | undefined {\n if (typeof value.code !== 'string' || typeof value.field !== 'string') return undefined;\n try {\n return `${value.code}\\u0000${value.field}\\u0000${canonicalizeJson(value.details ?? null)}`;\n } catch {\n // Preserve unreadable third-party errors instead of falsely deduplicating.\n return undefined;\n }\n}\n\nfunction mergeProjectionErrors(existing: unknown, diagnostics: readonly ProjectionDiagnostic[]): unknown[] {\n const merged = Array.isArray(existing) ? [...existing] : [];\n const seen = new Set<string>();\n for (const value of merged) {\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue;\n const record = value as Record<string, unknown>;\n const key = errorIdentity(record);\n if (key) seen.add(key);\n }\n for (const diagnostic of diagnostics) {\n const error = projectionDiagnosticToError(diagnostic) as unknown as Record<string, unknown>;\n const key = errorIdentity(error)!;\n if (seen.has(key)) continue;\n seen.add(key);\n merged.push(error);\n }\n return merged;\n}\n\nfunction remapExistingProductErrors(\n existing: unknown,\n originalToOutputIndex: ReadonlyMap<number, number | undefined>,\n products: readonly V1Product[]\n): unknown {\n if (!Array.isArray(existing)) return existing;\n return existing.map(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const record = value as Record<string, unknown>;\n let issuesChanged = false;\n const issues = Array.isArray(record.issues)\n ? record.issues.map(issue => {\n if (!issue || typeof issue !== 'object' || Array.isArray(issue)) return issue;\n const issueRecord = issue as Record<string, unknown>;\n if (typeof issueRecord.pointer !== 'string') return issue;\n const pointerMatch = /^\\/products\\/(\\d+)(\\/.*)?$/.exec(issueRecord.pointer);\n if (!pointerMatch) return issue;\n const originalIssueIndex = Number(pointerMatch[1]);\n if (!originalToOutputIndex.has(originalIssueIndex)) return issue;\n const outputIssueIndex = originalToOutputIndex.get(originalIssueIndex);\n issuesChanged = true;\n return {\n ...issueRecord,\n pointer:\n outputIssueIndex === undefined ? '/products' : `/products/${outputIssueIndex}${pointerMatch[2] ?? ''}`,\n };\n })\n : record.issues;\n const withIssues = issuesChanged ? { ...record, issues } : record;\n if (typeof record.field !== 'string') return issuesChanged ? withIssues : value;\n const match = /^products\\[(\\d+)\\](.*)$/.exec(record.field);\n if (!match) return issuesChanged ? withIssues : value;\n const originalIndex = Number(match[1]);\n if (!originalToOutputIndex.has(originalIndex)) return issuesChanged ? withIssues : value;\n const outputIndex = originalToOutputIndex.get(originalIndex);\n if (outputIndex !== undefined) {\n return { ...withIssues, field: `products[${outputIndex}]${match[2] ?? ''}` };\n }\n const productId = products[originalIndex]?.product_id;\n const details =\n record.details && typeof record.details === 'object' && !Array.isArray(record.details)\n ? { ...(record.details as Record<string, unknown>) }\n : {};\n if (typeof productId === 'string' && details.product_id === undefined) details.product_id = productId;\n return { ...withIssues, field: 'products', ...(Object.keys(details).length > 0 ? { details } : {}) };\n });\n}\n\nfunction hasEmptyPlacementFormatOptions(product: CanonicalOnlyProduct<V1Product>): boolean {\n const placements = (product as Record<string, unknown>).placements;\n if (!Array.isArray(placements)) return false;\n return placements.some(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const options = (value as Record<string, unknown>).format_options;\n return Array.isArray(options) && options.length === 0;\n });\n}\n\n/**\n * A Product that has been augmented with `format_options[]` while\n * preserving the original `format_ids[]`. Carries the projection\n * diagnostics that were generated mapping each `format_id` so the\n * buyer can see what (if anything) didn't project cleanly.\n *\n * **Write-side bridge.** After picking a `format_options[i]` entry,\n * use {@link formatIdsFromOptions} (from `@adcp/sdk/v2/projection`)\n * to extract the `format_ids[]` value for a `create_media_buy`\n * package. Inlining `decl.v1_format_ref` works but bypasses the\n * fail-closed semantics (canonical_formats_only / inherently-v2\n * canonical → throw). The spec gap that forces this bridge is tracked\n * at adcontextprotocol/adcp#4842.\n *\n * @see formatIdsFromOptions\n * @see formatIdsForCapability\n */\nexport type V2AugmentedProduct<P> = P & {\n format_options: V2ProductFormatDeclaration[];\n};\n\n/**\n * Augment a single Product. Idempotent — when `format_options[]` is\n * already present (the seller is v2-native), passes the Product\n * through unchanged. Otherwise projects from `format_ids[]`.\n *\n * Returns `{ product, diagnostics }`. `diagnostics` is empty for a\n * clean projection; populated when individual format_ids don't have\n * a v2 mapping (catalog gap, structural unreachability, etc.).\n *\n * @see toCanonicalOnlyProduct — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function augmentProductWithFormatOptions<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: V2AugmentedProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n // Already v2-shaped (seller sent format_options directly) — pass through.\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n if (Array.isArray(existing)) {\n return {\n product: product as V2AugmentedProduct<P>,\n diagnostics: [],\n };\n }\n // v1 shape — project to add format_options[].\n if (!Array.isArray(product.format_ids)) {\n // Neither shape — nothing to project. Return as-is with an empty\n // format_options so the buyer doesn't have to special-case.\n return {\n product: { ...product, format_options: [] },\n diagnostics: [],\n };\n }\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n // Preserve the original product shape (especially format_ids); just\n // add format_options.\n return {\n product: {\n ...product,\n format_options: v2.format_options,\n },\n diagnostics,\n };\n}\n\n/**\n * Augment every Product in a `get_products` response with\n * `format_options[]`. Returns `{ response, diagnostics }` so callers\n * can surface projection diagnostics alongside the response's existing\n * `errors[]` array (or filter by `source: 'sdk'` to distinguish SDK\n * diagnostics from seller-emitted errors).\n *\n * Idempotent: if the seller is v2-native and every Product already\n * carries `format_options[]`, returns the response verbatim with no\n * diagnostics.\n *\n * @see toCanonicalOnlyResponse — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function withFormatOptions<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): { response: R & { products: V2AugmentedProduct<V1Product>[] }; diagnostics: ProjectionDiagnostic[] } {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics: [],\n };\n }\n const out: V2AugmentedProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n for (const p of response.products) {\n const { product, diagnostics: d } = augmentProductWithFormatOptions(p, options);\n out.push(product);\n diagnostics.push(...d);\n }\n return {\n response: { ...response, products: out } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics,\n };\n}\n\n/**\n * An additive canonical Product: canonical declarations contain no legacy\n * routing identity, while the Product's top-level `format_ids[]` remains\n * available to compatibility consumers.\n */\nexport type AdditiveCanonicalProduct<P> = Omit<P, 'format_options'> & {\n format_options: CanonicalFormatDeclaration[];\n};\n\nfunction assertNoDirectLegacyFormatAliases(declarations: readonly V2ProductFormatDeclaration[]): void {\n for (let index = 0; index < declarations.length; index++) {\n const declaration = declarations[index] as unknown as Record<string, unknown>;\n for (const field of Object.keys(declaration)) {\n if (\n field !== 'v1_format_ref' &&\n DIRECT_LEGACY_FORMAT_IDENTITY_KEYS.has(field.replaceAll('_', '').toLowerCase())\n ) {\n throw new TypeError(\n `format_options[${index}] must not use legacy identity field ${field}; use v1_format_ref for migration routing`\n );\n }\n }\n }\n}\n\n/**\n * Project a Product to an additive, URL-free canonical surface.\n *\n * Unlike {@link augmentProductWithFormatOptions}, this always returns fresh\n * `format_options[]` declarations with `v1_format_ref` concealed. Unlike\n * {@link toCanonicalOnlyProduct}, it preserves the Product's top-level\n * `format_ids[]`. Exact canonical-to-legacy downgrade identity is returned\n * separately as JSON-safe {@link CanonicalFormatLegacyRoute} sidecars.\n *\n * Extract `routes` before any JSON round-trip — WeakMap metadata is gone after\n * deserialization. This helper enforces that ordering internally; persist its\n * returned `routes` whenever a canonical selection may cross a process boundary\n * before being forwarded to a legacy seller. Rebuild the write-side resolver\n * with `canonicalFormatLegacyResolverFromRoutes(restoredRoutes)`.\n *\n * @throws TypeError when a canonical declaration uses a direct legacy identity\n * alias such as `agent_url` or `agentUrl` instead of `v1_format_ref`.\n */\nexport function toAdditiveCanonicalProduct<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): {\n product: AdditiveCanonicalProduct<P>;\n diagnostics: ProjectionDiagnostic[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n const { product: augmented, diagnostics } = augmentProductWithFormatOptions(product, options);\n const routes = legacyRoutesForProduct(product.product_id, augmented.format_options);\n assertNoDirectLegacyFormatAliases(augmented.format_options);\n return {\n product: {\n ...augmented,\n format_options: canonicalDeclarations(augmented.format_options),\n } as AdditiveCanonicalProduct<P>,\n diagnostics,\n routes,\n };\n}\n\n/**\n * Response-level companion to {@link toAdditiveCanonicalProduct}. Projects\n * every Product and accumulates its serializable legacy routes.\n */\nexport function withAdditiveCanonicalFormatOptions<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): {\n response: Omit<R, 'products'> & { products: AdditiveCanonicalProduct<V1Product>[] };\n diagnostics: ProjectionDiagnostic[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & {\n products: AdditiveCanonicalProduct<V1Product>[];\n },\n diagnostics: [],\n routes: [],\n };\n }\n const products: AdditiveCanonicalProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n const routes: CanonicalFormatLegacyRoute[] = [];\n for (const sourceProduct of response.products) {\n const projected = toAdditiveCanonicalProduct(sourceProduct, options);\n products.push(projected.product);\n diagnostics.push(...projected.diagnostics);\n routes.push(...projected.routes);\n }\n return {\n response: { ...response, products } as Omit<R, 'products'> & {\n products: AdditiveCanonicalProduct<V1Product>[];\n },\n diagnostics,\n routes,\n };\n}\n\n/**\n * A Product reduced to the canonical creative-format surface:\n * `format_options[]` only, with the legacy `format_ids[]` removed. The\n * read-side counterpart to a fully-migrated consumer — naive downstream\n * code can no longer fall back to the stale `{ agent_url, id }` shape and\n * silently bypass the canonical model.\n */\nexport type CanonicalOnlyProduct<P> = Omit<P, 'format_ids'> & {\n format_ids?: never;\n format_options: CanonicalFormatDeclaration[];\n};\n\nfunction canonicalDeclarations(values: readonly V2ProductFormatDeclaration[]): CanonicalFormatDeclaration[] {\n return values.map(value => concealLegacyFormatRefs(value));\n}\n\nfunction canonicalPlacements(\n product: Record<string, unknown>,\n options: V1ToV2ProjectionOptions | undefined,\n diagnostics: ProjectionDiagnostic[]\n): unknown {\n if (!Array.isArray(product.placements)) return product.placements;\n return product.placements.map((value, placementIndex) => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const placement = value as Record<string, unknown>;\n const { format_ids: _drop, ...rest } = placement;\n void _drop;\n const hasLegacyFormats = Array.isArray(placement.format_ids);\n const hasCanonicalFormats = Array.isArray(placement.format_options);\n if (!hasLegacyFormats && !hasCanonicalFormats) return rest;\n\n const productId = typeof product.product_id === 'string' ? product.product_id : '(unknown)';\n const placementId = typeof placement.placement_id === 'string' ? placement.placement_id : String(placementIndex);\n const pseudoProduct = {\n product_id: `${productId}:placement:${placementId}`,\n name: typeof placement.name === 'string' ? placement.name : placementId,\n description: `Nested placement ${placementId}`,\n ...(hasLegacyFormats ? { format_ids: placement.format_ids } : {}),\n ...(hasCanonicalFormats ? { format_options: placement.format_options } : {}),\n } as unknown as V1Product;\n const projected = toCanonicalOnlyProduct(pseudoProduct, options);\n for (const diagnostic of projected.diagnostics) {\n diagnostics.push({\n ...diagnostic,\n field: diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${productId}].placements[${placementIndex}]`),\n });\n }\n return {\n ...rest,\n format_options: projected.product.format_options,\n };\n });\n}\n\n/**\n * Identity key for a `format_id` ref used by the coverage check.\n * Trailing-slash-insensitive on `agent_url` (folds the AAO host's slash /\n * no-slash forms, per `catalog.ts`'s `normalizeAgentUrl`), and includes the\n * dimensional discriminators so multi-size declarations sharing one\n * `{ agent_url, id }` but differing by size/duration are NOT collapsed —\n * the same key shape `write-side.ts` uses for v1 ref de-dup. Without the\n * size half, a `format_ids[]` entry for a size no `v1_format_ref` covers\n * would read as covered and be dropped silently.\n */\nfunction formatRefCoverageKey(ref: V1FormatId): string {\n const url = ref.agent_url && !ref.agent_url.endsWith('/') ? ref.agent_url + '/' : ref.agent_url;\n return `${url}::${ref.id}::${ref.width ?? ''}x${ref.height ?? ''}::${ref.duration_ms ?? ''}`;\n}\n\n/**\n * Project a single Product to the canonical-only shape: `format_options[]`\n * present, `format_ids[]` dropped.\n *\n * **Dropping legacy never silently loses a format.** Every input\n * `format_id` is either represented in the returned `format_options[]` or\n * surfaced in `diagnostics` — never discarded without a trace:\n *\n * - **v1-shaped input** (`format_ids[]`, no `format_options[]`): runs the\n * v1 → v2 projection. Mapped refs become `format_options[]`; any ref\n * the projection can't map is surfaced as `FORMAT_PROJECTION_FAILED`.\n * - **v2-native input** (`format_options[]` already present): keeps the\n * seller's canonical surface and drops the redundant v1 fallback. If a\n * legacy routing entry exists that no canonical option covers, it\n * surfaces a canonical-safe `LEGACY_FORMAT_ID_DROPPED_UNMAPPED`\n * diagnostic without echoing the routing identifier.\n * - **neither shape**: returns `format_options: []`; there is nothing to\n * project and nothing to lose.\n *\n * Pure and subtractive: unlike {@link augmentProductWithFormatOptions}\n * (which preserves `format_ids[]`), this drops it — the opt-in narrowing for\n * a consumer that has fully migrated. Complements the write-side\n * non-invertibility tracked at adcontextprotocol/adcp#4842 — this is the\n * read-side transparency half.\n */\nexport function toCanonicalOnlyProduct<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: CanonicalOnlyProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n\n // v2-native: the seller already sent format_options[]. Drop the\n // redundant v1 fallback, but flag any legacy ref no v1_format_ref covers.\n if (Array.isArray(existing)) {\n const formatOptions = existing as V2ProductFormatDeclaration[];\n const diagnostics: ProjectionDiagnostic[] = [];\n const inputIds = Array.isArray(product.format_ids) ? product.format_ids : [];\n if (inputIds.length > 0) {\n const covered = new Set<string>();\n for (const opt of formatOptions) {\n const refs = Array.isArray(opt?.v1_format_ref) ? opt.v1_format_ref : [];\n for (const ref of refs) covered.add(formatRefCoverageKey(ref));\n }\n for (let k = 0; k < inputIds.length; k++) {\n const fid = inputIds[k]!;\n if (!covered.has(formatRefCoverageKey(fid))) {\n diagnostics.push({\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED',\n error: {\n details: {\n product_id: product.product_id,\n resolution_failure: 'unmapped_legacy_format',\n },\n },\n });\n }\n }\n }\n const { format_ids: _dropV2, ...rest } = product as P & { format_ids?: unknown };\n void _dropV2;\n return {\n product: {\n ...rest,\n format_options: canonicalDeclarations(formatOptions),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // v1 shape: project. projectV1ProductToV2 already omits format_ids and\n // emits a diagnostic for every ref it couldn't map.\n if (Array.isArray(product.format_ids)) {\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n const { format_ids: _dropV1, ...rest } = product as P & { format_ids?: unknown };\n void _dropV1;\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: canonicalDeclarations(v2.format_options),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // Neither shape — nothing to project, nothing to lose.\n const { format_ids: _dropNone, ...rest } = product as P & { format_ids?: unknown };\n void _dropNone;\n const diagnostics: ProjectionDiagnostic[] = [];\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: [],\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n}\n\n/**\n * Reduce every Product in a `get_products` response to the canonical-only\n * shape — `format_options[]` present, `format_ids[]` dropped. Returns\n * `{ response, diagnostics }` so callers surface projection diagnostics\n * alongside the response's existing `errors[]`.\n *\n * Response-level counterpart to {@link toCanonicalOnlyProduct}; same\n * fail-closed guarantee, aggregated across products. A wholly unmappable\n * legacy product cannot be represented as a canonical Product because the\n * protocol requires `format_options` to contain at least one declaration. It\n * is therefore omitted from the canonical list and surfaced through the\n * response's portable `errors[]` plus the SDK convenience diagnostics. A\n * partially mappable product remains with its mapped options and advisories\n * for the refs that could not be projected.\n */\nexport function toCanonicalOnlyResponse<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): {\n response: Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] };\n diagnostics: ProjectionDiagnostic[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & {\n products: CanonicalOnlyProduct<V1Product>[];\n errors?: unknown[];\n },\n diagnostics: [],\n };\n }\n const out: CanonicalOnlyProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n const originalToOutputIndex = new Map<number, number | undefined>();\n for (let productIndex = 0; productIndex < response.products.length; productIndex++) {\n const p = response.products[productIndex]!;\n const { product, diagnostics: rawDiagnostics } = toCanonicalOnlyProduct(p, options);\n const hasEmptyPlacement = hasEmptyPlacementFormatOptions(product);\n const keep = product.format_options.length > 0 && !hasEmptyPlacement;\n const outputIndex = keep ? out.length : undefined;\n originalToOutputIndex.set(productIndex, outputIndex);\n const d = rawDiagnostics.map(diagnostic => ({\n ...diagnostic,\n field: keep ? diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${outputIndex}]`) : 'products',\n error: keep\n ? diagnostic.error\n : {\n details: {\n ...diagnostic.error.details,\n product_id: p.product_id,\n },\n },\n })) as ProjectionDiagnostic[];\n if (!keep && d.length === 0) {\n const reason = hasEmptyPlacement\n ? 'nested_placement_format_list_empty'\n : Array.isArray((p as Record<string, unknown>).format_options)\n ? 'canonical_format_list_empty'\n : Array.isArray(p.format_ids)\n ? 'legacy_format_list_empty'\n : 'missing_format_declaration';\n d.push({\n ...canonicalFormatsUnavailableForProduct(p, reason),\n field: 'products',\n });\n }\n diagnostics.push(...d);\n if (keep) out.push(product);\n }\n const remappedExistingErrors = remapExistingProductErrors(\n (response as { errors?: unknown }).errors,\n originalToOutputIndex,\n response.products\n );\n const errors = mergeProjectionErrors(remappedExistingErrors, diagnostics);\n return {\n response: {\n ...response,\n products: out,\n ...(errors.length > 0 ? { errors } : {}),\n } as Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] },\n diagnostics,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,sBAAqC;AAErC,qBAAgC;AAChC,iBAAiD;AACjD,6BAAwC;AAExC,2BAAuC;AAGvC,MAAM,SAAS,aAAa,8BAAe;AAC3C,MAAM,qCAAqC,oBAAI,IAAI,CAAC,YAAY,YAAY,aAAa,aAAa,CAAC;AAEvG,SAAS,oBAAoB,YAAwD;AACnF,SAAO;AAAA,IACL,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,IAKH,OAAO,WAAW,MAAM,QAAQ,wBAAwB,iBAAiB;AAAA,EAC3E;AACF;AAaA,SAAS,uBAAuB,MAA4C;AAC1E,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAGO,SAAS,4BAA4B,YAA4D;AACtG,SAAO;AAAA,IACL,MAAM,WAAW;AAAA,IACjB,SAAS,uBAAuB,WAAW,IAAI;AAAA,IAC/C,OAAO,W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H;AACA,gBAAY,KAAK,GAAG,CAAC;AACrB,QAAI,KAAM,KAAI,KAAK,OAAO;AAAA,EAC5B;AACA,QAAM,yBAAyB;AAAA,IAC5B,SAAkC;AAAA,IACnC;AAAA,IACA,SAAS;AAAA,EACX;AACA,QAAM,SAAS,sBAAsB,wBAAwB,WAAW;AACxE,SAAO;AAAA,IACL,UAAU;AAAA,MACR,GAAG;AAAA,MACH,UAAU;AAAA,MACV,GAAI,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AACF;","names":["canonicalizeJson","diagnostics","rest"]}
1
+ {"version":3,"sources":["../../../../src/lib/v2/projection/augment-response.ts"],"sourcesContent":["/**\n * Buyer-side helpers that augment a v1-shaped agent response with v2\n * `format_options[]` derived from the existing `format_ids[]` on each\n * Product.\n *\n * Buyers who want the canonical creative-format model call\n * `withFormatOptions(response)` and read `format_options` instead of\n * relying only on legacy `format_ids`.\n *\n * The SDK also auto-projects compatible `AgentClient.getProducts()`\n * responses; this helper remains useful for cached responses, fixtures,\n * upstream seller/storefront composition, and explicit migration code.\n *\n * Pure functions — no IO, no caching. Each Product is projected\n * independently; diagnostics aggregate so a multi-product response\n * surfaces every projection issue at once. The helpers preserve the\n * input shape verbatim and add `format_options[]` (additive). They do\n * NOT drop `format_ids[]` — that's the 8.0 narrowing. To DROP\n * `format_ids[]` once a consumer has fully migrated, use\n * `toCanonicalOnlyProduct` / `toCanonicalOnlyResponse`.\n */\n\nimport type { V1Product, V1FormatId, V2ProductFormatDeclaration, ProjectionDiagnostic } from './types';\nimport { projectV1ProductToV2 } from './v1-to-v2';\nimport type { V1ToV2ProjectionOptions } from './v1-to-v2';\nimport { LIBRARY_VERSION } from '../../version';\nimport { canonicalize as canonicalizeJson } from '../../utils/jcs';\nimport { concealLegacyFormatRefs } from './legacy-metadata';\nimport type { CanonicalFormatDeclaration } from './legacy-metadata';\nimport { legacyRoutesForProduct } from './legacy-routes';\nimport type { CanonicalFormatLegacyRoute } from './legacy-routes';\n\nconst SDK_ID = `@adcp/sdk@${LIBRARY_VERSION}`;\nconst DIRECT_LEGACY_FORMAT_IDENTITY_KEYS = new Set(['agenturl', 'formatid', 'formatids', 'v1formatref']);\n\nfunction canonicalDiagnostic(diagnostic: ProjectionDiagnostic): ProjectionDiagnostic {\n return {\n ...diagnostic,\n // A source `format_ids[i]` index is not an index into the projected\n // `format_options[]`: earlier source refs may have failed while later refs\n // projected successfully. Point at the canonical collection instead of\n // claiming that a successful projected option is the failing value.\n field: diagnostic.field.replace(/\\.format_ids\\[\\d+\\]/g, '.format_options'),\n };\n}\n\n/** Protocol Error shape used for portable response-level projection advisories. */\nexport interface CanonicalProjectionError {\n code: ProjectionDiagnostic['code'];\n message: string;\n field: string;\n recovery: 'correctable';\n source: 'sdk';\n sdk_id: string;\n details: ProjectionDiagnostic['error']['details'];\n}\n\nfunction projectionErrorMessage(code: ProjectionDiagnostic['code']): string {\n switch (code) {\n case 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE':\n return 'Product has no format declaration representable on the canonical-only surface';\n case 'FORMAT_PROJECTION_FAILED':\n return 'Legacy creative format could not be projected to a canonical declaration';\n case 'FORMAT_DECLARATION_V1_AMBIGUOUS':\n return 'Canonical creative format has no unambiguous legacy declaration';\n case 'FORMAT_DECLARATION_V1_NOT_APPLICABLE':\n return 'Canonical-only creative format cannot be represented on a legacy format path';\n case 'CANONICAL_NOT_V1_TRANSLATABLE':\n return 'Canonical creative format has no legacy representation';\n case 'FORMAT_DECLARATION_V1_LOSSY_MULTI_SIZE':\n return 'Canonical multi-size format has incomplete legacy coverage';\n case 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED':\n return 'Redundant legacy creative identity has no canonical counterpart';\n }\n}\n\n/** Flatten the projector's internal diagnostic into the protocol `Error` shape. */\nexport function projectionDiagnosticToError(diagnostic: ProjectionDiagnostic): CanonicalProjectionError {\n return {\n code: diagnostic.code,\n message: projectionErrorMessage(diagnostic.code),\n field: diagnostic.field,\n recovery: 'correctable',\n source: diagnostic.source,\n sdk_id: diagnostic.sdk_id,\n details: diagnostic.error.details,\n } as CanonicalProjectionError;\n}\n\nfunction canonicalFormatsUnavailableForProduct(\n product: V1Product,\n reason: Extract<ProjectionDiagnostic, { code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE' }>['error']['details']['reason']\n): ProjectionDiagnostic {\n return {\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE',\n error: {\n details: {\n product_id: product.product_id,\n reason,\n },\n },\n };\n}\n\nfunction errorIdentity(value: Record<string, unknown>): string | undefined {\n if (typeof value.code !== 'string' || typeof value.field !== 'string') return undefined;\n try {\n return `${value.code}\\u0000${value.field}\\u0000${canonicalizeJson(value.details ?? null)}`;\n } catch {\n // Preserve unreadable third-party errors instead of falsely deduplicating.\n return undefined;\n }\n}\n\nfunction mergeProjectionErrors(existing: unknown, diagnostics: readonly ProjectionDiagnostic[]): unknown[] {\n const merged = Array.isArray(existing) ? [...existing] : [];\n const seen = new Set<string>();\n for (const value of merged) {\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue;\n const record = value as Record<string, unknown>;\n const key = errorIdentity(record);\n if (key) seen.add(key);\n }\n for (const diagnostic of diagnostics) {\n const error = projectionDiagnosticToError(diagnostic) as unknown as Record<string, unknown>;\n const key = errorIdentity(error)!;\n if (seen.has(key)) continue;\n seen.add(key);\n merged.push(error);\n }\n return merged;\n}\n\nfunction remapExistingProductErrors(\n existing: unknown,\n originalToOutputIndex: ReadonlyMap<number, number | undefined>,\n products: readonly V1Product[]\n): unknown {\n if (!Array.isArray(existing)) return existing;\n return existing.map(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const record = value as Record<string, unknown>;\n let issuesChanged = false;\n const issues = Array.isArray(record.issues)\n ? record.issues.map(issue => {\n if (!issue || typeof issue !== 'object' || Array.isArray(issue)) return issue;\n const issueRecord = issue as Record<string, unknown>;\n if (typeof issueRecord.pointer !== 'string') return issue;\n const pointerMatch = /^\\/products\\/(\\d+)(\\/.*)?$/.exec(issueRecord.pointer);\n if (!pointerMatch) return issue;\n const originalIssueIndex = Number(pointerMatch[1]);\n if (!originalToOutputIndex.has(originalIssueIndex)) return issue;\n const outputIssueIndex = originalToOutputIndex.get(originalIssueIndex);\n issuesChanged = true;\n return {\n ...issueRecord,\n pointer:\n outputIssueIndex === undefined ? '/products' : `/products/${outputIssueIndex}${pointerMatch[2] ?? ''}`,\n };\n })\n : record.issues;\n const withIssues = issuesChanged ? { ...record, issues } : record;\n if (typeof record.field !== 'string') return issuesChanged ? withIssues : value;\n const match = /^products\\[(\\d+)\\](.*)$/.exec(record.field);\n if (!match) return issuesChanged ? withIssues : value;\n const originalIndex = Number(match[1]);\n if (!originalToOutputIndex.has(originalIndex)) return issuesChanged ? withIssues : value;\n const outputIndex = originalToOutputIndex.get(originalIndex);\n if (outputIndex !== undefined) {\n return { ...withIssues, field: `products[${outputIndex}]${match[2] ?? ''}` };\n }\n const productId = products[originalIndex]?.product_id;\n const details =\n record.details && typeof record.details === 'object' && !Array.isArray(record.details)\n ? { ...(record.details as Record<string, unknown>) }\n : {};\n if (typeof productId === 'string' && details.product_id === undefined) details.product_id = productId;\n return { ...withIssues, field: 'products', ...(Object.keys(details).length > 0 ? { details } : {}) };\n });\n}\n\nfunction hasEmptyPlacementFormatOptions(product: CanonicalOnlyProduct<V1Product>): boolean {\n const placements = (product as Record<string, unknown>).placements;\n if (!Array.isArray(placements)) return false;\n return placements.some(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const options = (value as Record<string, unknown>).format_options;\n return Array.isArray(options) && options.length === 0;\n });\n}\n\n/**\n * A Product that has been augmented with `format_options[]` while\n * preserving the original `format_ids[]`. Carries the projection\n * diagnostics that were generated mapping each `format_id` so the\n * buyer can see what (if anything) didn't project cleanly.\n *\n * **Write-side bridge.** After picking a `format_options[i]` entry,\n * use {@link formatIdsFromOptions} (from `@adcp/sdk/v2/projection`)\n * to extract the `format_ids[]` value for a `create_media_buy`\n * package. Inlining `decl.v1_format_ref` works but bypasses the\n * fail-closed semantics (canonical_formats_only / inherently-v2\n * canonical → throw). The spec gap that forces this bridge is tracked\n * at adcontextprotocol/adcp#4842.\n *\n * @see formatIdsFromOptions\n * @see formatIdsForCapability\n */\nexport type V2AugmentedProduct<P> = P & {\n format_options: V2ProductFormatDeclaration[];\n};\n\n/**\n * Augment a single Product. Idempotent — when `format_options[]` is\n * already present (the seller is v2-native), passes the Product\n * through unchanged. Otherwise projects from `format_ids[]`.\n *\n * Returns `{ product, diagnostics }`. `diagnostics` is empty for a\n * clean projection; populated when individual format_ids don't have\n * a v2 mapping (catalog gap, structural unreachability, etc.).\n *\n * @see toCanonicalOnlyProduct — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function augmentProductWithFormatOptions<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: V2AugmentedProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n // Already v2-shaped (seller sent format_options directly) — pass through.\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n if (Array.isArray(existing)) {\n return {\n product: product as V2AugmentedProduct<P>,\n diagnostics: [],\n };\n }\n // v1 shape — project to add format_options[].\n if (!Array.isArray(product.format_ids)) {\n // Neither shape — nothing to project. Return as-is with an empty\n // format_options so the buyer doesn't have to special-case.\n return {\n product: { ...product, format_options: [] },\n diagnostics: [],\n };\n }\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n // Preserve the original product shape (especially format_ids); just\n // add format_options.\n return {\n product: {\n ...product,\n format_options: v2.format_options,\n },\n diagnostics,\n };\n}\n\n/**\n * Augment every Product in a `get_products` response with\n * `format_options[]`. Returns `{ response, diagnostics }` so callers\n * can surface projection diagnostics alongside the response's existing\n * `errors[]` array (or filter by `source: 'sdk'` to distinguish SDK\n * diagnostics from seller-emitted errors).\n *\n * Idempotent: if the seller is v2-native and every Product already\n * carries `format_options[]`, returns the response verbatim with no\n * diagnostics.\n *\n * @see toCanonicalOnlyResponse — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function withFormatOptions<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): { response: R & { products: V2AugmentedProduct<V1Product>[] }; diagnostics: ProjectionDiagnostic[] } {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics: [],\n };\n }\n const out: V2AugmentedProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n for (const p of response.products) {\n const { product, diagnostics: d } = augmentProductWithFormatOptions(p, options);\n out.push(product);\n diagnostics.push(...d);\n }\n return {\n response: { ...response, products: out } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics,\n };\n}\n\n/**\n * An additive canonical Product: canonical declarations contain no legacy\n * routing identity, while the Product's top-level `format_ids[]` remains\n * available to compatibility consumers.\n */\nexport type AdditiveCanonicalProduct<P> = Omit<P, 'format_options'> & {\n format_options: CanonicalFormatDeclaration[];\n};\n\nfunction assertNoDirectLegacyFormatAliases(declarations: readonly V2ProductFormatDeclaration[]): void {\n for (let index = 0; index < declarations.length; index++) {\n const declaration = declarations[index] as unknown as Record<string, unknown>;\n for (const field of Object.keys(declaration)) {\n if (\n field !== 'v1_format_ref' &&\n DIRECT_LEGACY_FORMAT_IDENTITY_KEYS.has(field.replaceAll('_', '').toLowerCase())\n ) {\n throw new TypeError(\n `format_options[${index}] must not use legacy identity field ${field}; use v1_format_ref for migration routing`\n );\n }\n }\n }\n}\n\n/**\n * Conceal migration-only legacy identities from canonical format declarations\n * while extracting their durable downgrade routes first.\n *\n * This is the declaration-array counterpart to\n * {@link toAdditiveCanonicalProduct}. It is intended for persisted catalogs\n * and other consumers that do not hold a complete Product. The source array\n * and declarations are never mutated.\n *\n * @throws TypeError when a canonical declaration uses a direct legacy identity\n * alias such as `agent_url` or `agentUrl` instead of `v1_format_ref`.\n */\nexport function toCanonicalFormatOptionsWithRoutes(\n productId: string,\n formatOptions: readonly V2ProductFormatDeclaration[]\n): {\n formatOptions: CanonicalFormatDeclaration[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n assertNoDirectLegacyFormatAliases(formatOptions);\n const routes = legacyRoutesForProduct(productId, formatOptions);\n return {\n formatOptions: canonicalDeclarations(formatOptions),\n routes,\n };\n}\n\n/**\n * Project a Product to an additive, URL-free canonical surface.\n *\n * Unlike {@link augmentProductWithFormatOptions}, this always returns fresh\n * `format_options[]` declarations with `v1_format_ref` concealed. Unlike\n * {@link toCanonicalOnlyProduct}, it preserves the Product's top-level\n * `format_ids[]`. Exact canonical-to-legacy downgrade identity is returned\n * separately as JSON-safe {@link CanonicalFormatLegacyRoute} sidecars.\n *\n * Extract `routes` before any JSON round-trip — WeakMap metadata is gone after\n * deserialization. This helper enforces that ordering internally; persist its\n * returned `routes` whenever a canonical selection may cross a process boundary\n * before being forwarded to a legacy seller. Rebuild the write-side resolver\n * with `canonicalFormatLegacyResolverFromRoutes(restoredRoutes)`.\n *\n * @throws TypeError when a canonical declaration uses a direct legacy identity\n * alias such as `agent_url` or `agentUrl` instead of `v1_format_ref`.\n */\nexport function toAdditiveCanonicalProduct<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): {\n product: AdditiveCanonicalProduct<P>;\n diagnostics: ProjectionDiagnostic[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n const { product: augmented, diagnostics } = augmentProductWithFormatOptions(product, options);\n const projected = toCanonicalFormatOptionsWithRoutes(product.product_id, augmented.format_options);\n return {\n product: {\n ...augmented,\n format_options: projected.formatOptions,\n } as AdditiveCanonicalProduct<P>,\n diagnostics,\n routes: projected.routes,\n };\n}\n\n/**\n * Response-level companion to {@link toAdditiveCanonicalProduct}. Projects\n * every Product and accumulates its serializable legacy routes.\n */\nexport function withAdditiveCanonicalFormatOptions<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): {\n response: Omit<R, 'products'> & { products: AdditiveCanonicalProduct<V1Product>[] };\n diagnostics: ProjectionDiagnostic[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & {\n products: AdditiveCanonicalProduct<V1Product>[];\n },\n diagnostics: [],\n routes: [],\n };\n }\n const products: AdditiveCanonicalProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n const routes: CanonicalFormatLegacyRoute[] = [];\n for (const sourceProduct of response.products) {\n const projected = toAdditiveCanonicalProduct(sourceProduct, options);\n products.push(projected.product);\n diagnostics.push(...projected.diagnostics);\n routes.push(...projected.routes);\n }\n return {\n response: { ...response, products } as Omit<R, 'products'> & {\n products: AdditiveCanonicalProduct<V1Product>[];\n },\n diagnostics,\n routes,\n };\n}\n\n/**\n * A Product reduced to the canonical creative-format surface:\n * `format_options[]` only, with the legacy `format_ids[]` removed. The\n * read-side counterpart to a fully-migrated consumer — naive downstream\n * code can no longer fall back to the stale `{ agent_url, id }` shape and\n * silently bypass the canonical model.\n */\nexport type CanonicalOnlyProduct<P> = Omit<P, 'format_ids'> & {\n format_ids?: never;\n format_options: CanonicalFormatDeclaration[];\n};\n\nfunction canonicalDeclarations(values: readonly V2ProductFormatDeclaration[]): CanonicalFormatDeclaration[] {\n return values.map(value => concealLegacyFormatRefs(value));\n}\n\nfunction canonicalPlacements(\n product: Record<string, unknown>,\n options: V1ToV2ProjectionOptions | undefined,\n diagnostics: ProjectionDiagnostic[]\n): unknown {\n if (!Array.isArray(product.placements)) return product.placements;\n return product.placements.map((value, placementIndex) => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const placement = value as Record<string, unknown>;\n const { format_ids: _drop, ...rest } = placement;\n void _drop;\n const hasLegacyFormats = Array.isArray(placement.format_ids);\n const hasCanonicalFormats = Array.isArray(placement.format_options);\n if (!hasLegacyFormats && !hasCanonicalFormats) return rest;\n\n const productId = typeof product.product_id === 'string' ? product.product_id : '(unknown)';\n const placementId = typeof placement.placement_id === 'string' ? placement.placement_id : String(placementIndex);\n const pseudoProduct = {\n product_id: `${productId}:placement:${placementId}`,\n name: typeof placement.name === 'string' ? placement.name : placementId,\n description: `Nested placement ${placementId}`,\n ...(hasLegacyFormats ? { format_ids: placement.format_ids } : {}),\n ...(hasCanonicalFormats ? { format_options: placement.format_options } : {}),\n } as unknown as V1Product;\n const projected = toCanonicalOnlyProduct(pseudoProduct, options);\n for (const diagnostic of projected.diagnostics) {\n diagnostics.push({\n ...diagnostic,\n field: diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${productId}].placements[${placementIndex}]`),\n });\n }\n return {\n ...rest,\n format_options: projected.product.format_options,\n };\n });\n}\n\n/**\n * Identity key for a `format_id` ref used by the coverage check.\n * Trailing-slash-insensitive on `agent_url` (folds the AAO host's slash /\n * no-slash forms, per `catalog.ts`'s `normalizeAgentUrl`), and includes the\n * dimensional discriminators so multi-size declarations sharing one\n * `{ agent_url, id }` but differing by size/duration are NOT collapsed —\n * the same key shape `write-side.ts` uses for v1 ref de-dup. Without the\n * size half, a `format_ids[]` entry for a size no `v1_format_ref` covers\n * would read as covered and be dropped silently.\n */\nfunction formatRefCoverageKey(ref: V1FormatId): string {\n const url = ref.agent_url && !ref.agent_url.endsWith('/') ? ref.agent_url + '/' : ref.agent_url;\n return `${url}::${ref.id}::${ref.width ?? ''}x${ref.height ?? ''}::${ref.duration_ms ?? ''}`;\n}\n\n/**\n * Project a single Product to the canonical-only shape: `format_options[]`\n * present, `format_ids[]` dropped.\n *\n * **Dropping legacy never silently loses a format.** Every input\n * `format_id` is either represented in the returned `format_options[]` or\n * surfaced in `diagnostics` — never discarded without a trace:\n *\n * - **v1-shaped input** (`format_ids[]`, no `format_options[]`): runs the\n * v1 → v2 projection. Mapped refs become `format_options[]`; any ref\n * the projection can't map is surfaced as `FORMAT_PROJECTION_FAILED`.\n * - **v2-native input** (`format_options[]` already present): keeps the\n * seller's canonical surface and drops the redundant v1 fallback. If a\n * legacy routing entry exists that no canonical option covers, it\n * surfaces a canonical-safe `LEGACY_FORMAT_ID_DROPPED_UNMAPPED`\n * diagnostic without echoing the routing identifier.\n * - **neither shape**: returns `format_options: []`; there is nothing to\n * project and nothing to lose.\n *\n * Pure and subtractive: unlike {@link augmentProductWithFormatOptions}\n * (which preserves `format_ids[]`), this drops it — the opt-in narrowing for\n * a consumer that has fully migrated. Complements the write-side\n * non-invertibility tracked at adcontextprotocol/adcp#4842 — this is the\n * read-side transparency half.\n */\nexport function toCanonicalOnlyProduct<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: CanonicalOnlyProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n\n // v2-native: the seller already sent format_options[]. Drop the\n // redundant v1 fallback, but flag any legacy ref no v1_format_ref covers.\n if (Array.isArray(existing)) {\n const formatOptions = existing as V2ProductFormatDeclaration[];\n const diagnostics: ProjectionDiagnostic[] = [];\n const inputIds = Array.isArray(product.format_ids) ? product.format_ids : [];\n if (inputIds.length > 0) {\n const covered = new Set<string>();\n for (const opt of formatOptions) {\n const refs = Array.isArray(opt?.v1_format_ref) ? opt.v1_format_ref : [];\n for (const ref of refs) covered.add(formatRefCoverageKey(ref));\n }\n for (let k = 0; k < inputIds.length; k++) {\n const fid = inputIds[k]!;\n if (!covered.has(formatRefCoverageKey(fid))) {\n diagnostics.push({\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED',\n error: {\n details: {\n product_id: product.product_id,\n resolution_failure: 'unmapped_legacy_format',\n },\n },\n });\n }\n }\n }\n const { format_ids: _dropV2, ...rest } = product as P & { format_ids?: unknown };\n void _dropV2;\n return {\n product: {\n ...rest,\n format_options: canonicalDeclarations(formatOptions),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // v1 shape: project. projectV1ProductToV2 already omits format_ids and\n // emits a diagnostic for every ref it couldn't map.\n if (Array.isArray(product.format_ids)) {\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n const { format_ids: _dropV1, ...rest } = product as P & { format_ids?: unknown };\n void _dropV1;\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: canonicalDeclarations(v2.format_options),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // Neither shape — nothing to project, nothing to lose.\n const { format_ids: _dropNone, ...rest } = product as P & { format_ids?: unknown };\n void _dropNone;\n const diagnostics: ProjectionDiagnostic[] = [];\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: [],\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n}\n\n/**\n * Reduce every Product in a `get_products` response to the canonical-only\n * shape — `format_options[]` present, `format_ids[]` dropped. Returns\n * `{ response, diagnostics }` so callers surface projection diagnostics\n * alongside the response's existing `errors[]`.\n *\n * Response-level counterpart to {@link toCanonicalOnlyProduct}; same\n * fail-closed guarantee, aggregated across products. A wholly unmappable\n * legacy product cannot be represented as a canonical Product because the\n * protocol requires `format_options` to contain at least one declaration. It\n * is therefore omitted from the canonical list and surfaced through the\n * response's portable `errors[]` plus the SDK convenience diagnostics. A\n * partially mappable product remains with its mapped options and advisories\n * for the refs that could not be projected.\n */\nexport function toCanonicalOnlyResponse<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): {\n response: Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] };\n diagnostics: ProjectionDiagnostic[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & {\n products: CanonicalOnlyProduct<V1Product>[];\n errors?: unknown[];\n },\n diagnostics: [],\n };\n }\n const out: CanonicalOnlyProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n const originalToOutputIndex = new Map<number, number | undefined>();\n for (let productIndex = 0; productIndex < response.products.length; productIndex++) {\n const p = response.products[productIndex]!;\n const { product, diagnostics: rawDiagnostics } = toCanonicalOnlyProduct(p, options);\n const hasEmptyPlacement = hasEmptyPlacementFormatOptions(product);\n const keep = product.format_options.length > 0 && !hasEmptyPlacement;\n const outputIndex = keep ? out.length : undefined;\n originalToOutputIndex.set(productIndex, outputIndex);\n const d = rawDiagnostics.map(diagnostic => ({\n ...diagnostic,\n field: keep ? diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${outputIndex}]`) : 'products',\n error: keep\n ? diagnostic.error\n : {\n details: {\n ...diagnostic.error.details,\n product_id: p.product_id,\n },\n },\n })) as ProjectionDiagnostic[];\n if (!keep && d.length === 0) {\n const reason = hasEmptyPlacement\n ? 'nested_placement_format_list_empty'\n : Array.isArray((p as Record<string, unknown>).format_options)\n ? 'canonical_format_list_empty'\n : Array.isArray(p.format_ids)\n ? 'legacy_format_list_empty'\n : 'missing_format_declaration';\n d.push({\n ...canonicalFormatsUnavailableForProduct(p, reason),\n field: 'products',\n });\n }\n diagnostics.push(...d);\n if (keep) out.push(product);\n }\n const remappedExistingErrors = remapExistingProductErrors(\n (response as { errors?: unknown }).errors,\n originalToOutputIndex,\n response.products\n );\n const errors = mergeProjectionErrors(remappedExistingErrors, diagnostics);\n return {\n response: {\n ...response,\n products: out,\n ...(errors.length > 0 ? { errors } : {}),\n } as Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] },\n diagnostics,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,sBAAqC;AAErC,qBAAgC;AAChC,iBAAiD;AACjD,6BAAwC;AAExC,2BAAuC;AAGvC,MAAM,SAAS,aAAa,8BAAe;AAC3C,MAAM,qCAAqC,oBAAI,IAAI,CAAC,YAAY,YAAY,aAAa,aAAa,CAAC;AAEvG,SAAS,oBAAoB,YAAwD;AACnF,SAAO;AAAA,IACL,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,IAKH,OAAO,WAAW,MAAM,QAAQ,wBAAwB,iBAAiB;AAAA,EAC3E;AACF;AAaA,SAAS,uBAAuB,MAA4C;AAC1E,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAGO,SAAS,4BAA4B,YAA4D;AACtG,SAAO;AAAA,IACL,MAAM,WAAW;AAAA,IACjB,SAAS,uBAAuB,WAAW,IAAI;AAAA,IAC/C,OAAO,WAAW;AAAA,IAClB,UAAU;AAAA,IACV,QAAQ,WAAW;AAAA,IACnB,QAAQ,WAAW;AAAA,IACnB,SAAS,WAAW,MAAM;AAAA,EAC5B;AACF;AAEA,SAAS,sCACP,SACA,QACsB;AACtB,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO,YAAY,QAAQ,UAAU;AAAA,IACrC,MAAM;AAAA,IACN,OAAO;AAAA,MACL,SAAS;AAAA,QACP,YAAY,QAAQ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AS,sBAAsB,wBAAwB,WAAW;AACxE,SAAO;AAAA,IACL,UAAU;AAAA,MACR,GAAG;AAAA,MACH,UAAU;AAAA,MACV,GAAI,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AACF;","names":["canonicalizeJson","diagnostics","rest"]}
@@ -184,17 +184,24 @@ function assertNoDirectLegacyFormatAliases(declarations) {
184
184
  }
185
185
  }
186
186
  }
187
+ function toCanonicalFormatOptionsWithRoutes(productId, formatOptions) {
188
+ assertNoDirectLegacyFormatAliases(formatOptions);
189
+ const routes = legacyRoutesForProduct(productId, formatOptions);
190
+ return {
191
+ formatOptions: canonicalDeclarations(formatOptions),
192
+ routes
193
+ };
194
+ }
187
195
  function toAdditiveCanonicalProduct(product, options) {
188
196
  const { product: augmented, diagnostics } = augmentProductWithFormatOptions(product, options);
189
- const routes = legacyRoutesForProduct(product.product_id, augmented.format_options);
190
- assertNoDirectLegacyFormatAliases(augmented.format_options);
197
+ const projected = toCanonicalFormatOptionsWithRoutes(product.product_id, augmented.format_options);
191
198
  return {
192
199
  product: {
193
200
  ...augmented,
194
- format_options: canonicalDeclarations(augmented.format_options)
201
+ format_options: projected.formatOptions
195
202
  },
196
203
  diagnostics,
197
- routes
204
+ routes: projected.routes
198
205
  };
199
206
  }
200
207
  function withAdditiveCanonicalFormatOptions(response, options) {
@@ -381,6 +388,7 @@ export {
381
388
  augmentProductWithFormatOptions,
382
389
  projectionDiagnosticToError,
383
390
  toAdditiveCanonicalProduct,
391
+ toCanonicalFormatOptionsWithRoutes,
384
392
  toCanonicalOnlyProduct,
385
393
  toCanonicalOnlyResponse,
386
394
  withAdditiveCanonicalFormatOptions,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/v2/projection/augment-response.ts"],"sourcesContent":["/**\n * Buyer-side helpers that augment a v1-shaped agent response with v2\n * `format_options[]` derived from the existing `format_ids[]` on each\n * Product.\n *\n * Buyers who want the canonical creative-format model call\n * `withFormatOptions(response)` and read `format_options` instead of\n * relying only on legacy `format_ids`.\n *\n * The SDK also auto-projects compatible `AgentClient.getProducts()`\n * responses; this helper remains useful for cached responses, fixtures,\n * upstream seller/storefront composition, and explicit migration code.\n *\n * Pure functions — no IO, no caching. Each Product is projected\n * independently; diagnostics aggregate so a multi-product response\n * surfaces every projection issue at once. The helpers preserve the\n * input shape verbatim and add `format_options[]` (additive). They do\n * NOT drop `format_ids[]` — that's the 8.0 narrowing. To DROP\n * `format_ids[]` once a consumer has fully migrated, use\n * `toCanonicalOnlyProduct` / `toCanonicalOnlyResponse`.\n */\n\nimport type { V1Product, V1FormatId, V2ProductFormatDeclaration, ProjectionDiagnostic } from './types';\nimport { projectV1ProductToV2 } from './v1-to-v2';\nimport type { V1ToV2ProjectionOptions } from './v1-to-v2';\nimport { LIBRARY_VERSION } from '../../version';\nimport { canonicalize as canonicalizeJson } from '../../utils/jcs';\nimport { concealLegacyFormatRefs } from './legacy-metadata';\nimport type { CanonicalFormatDeclaration } from './legacy-metadata';\nimport { legacyRoutesForProduct } from './legacy-routes';\nimport type { CanonicalFormatLegacyRoute } from './legacy-routes';\n\nconst SDK_ID = `@adcp/sdk@${LIBRARY_VERSION}`;\nconst DIRECT_LEGACY_FORMAT_IDENTITY_KEYS = new Set(['agenturl', 'formatid', 'formatids', 'v1formatref']);\n\nfunction canonicalDiagnostic(diagnostic: ProjectionDiagnostic): ProjectionDiagnostic {\n return {\n ...diagnostic,\n // A source `format_ids[i]` index is not an index into the projected\n // `format_options[]`: earlier source refs may have failed while later refs\n // projected successfully. Point at the canonical collection instead of\n // claiming that a successful projected option is the failing value.\n field: diagnostic.field.replace(/\\.format_ids\\[\\d+\\]/g, '.format_options'),\n };\n}\n\n/** Protocol Error shape used for portable response-level projection advisories. */\nexport interface CanonicalProjectionError {\n code: ProjectionDiagnostic['code'];\n message: string;\n field: string;\n recovery: 'correctable';\n source: 'sdk';\n sdk_id: string;\n details: ProjectionDiagnostic['error']['details'];\n}\n\nfunction projectionErrorMessage(code: ProjectionDiagnostic['code']): string {\n switch (code) {\n case 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE':\n return 'Product has no format declaration representable on the canonical-only surface';\n case 'FORMAT_PROJECTION_FAILED':\n return 'Legacy creative format could not be projected to a canonical declaration';\n case 'FORMAT_DECLARATION_V1_AMBIGUOUS':\n return 'Canonical creative format has no unambiguous legacy declaration';\n case 'FORMAT_DECLARATION_V1_NOT_APPLICABLE':\n return 'Canonical-only creative format cannot be represented on a legacy format path';\n case 'CANONICAL_NOT_V1_TRANSLATABLE':\n return 'Canonical creative format has no legacy representation';\n case 'FORMAT_DECLARATION_V1_LOSSY_MULTI_SIZE':\n return 'Canonical multi-size format has incomplete legacy coverage';\n case 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED':\n return 'Redundant legacy creative identity has no canonical counterpart';\n }\n}\n\n/** Flatten the projector's internal diagnostic into the protocol `Error` shape. */\nexport function projectionDiagnosticToError(diagnostic: ProjectionDiagnostic): CanonicalProjectionError {\n return {\n code: diagnostic.code,\n message: projectionErrorMessage(diagnostic.code),\n field: diagnostic.field,\n recovery: 'correctable',\n source: diagnostic.source,\n sdk_id: diagnostic.sdk_id,\n details: diagnostic.error.details,\n } as CanonicalProjectionError;\n}\n\nfunction canonicalFormatsUnavailableForProduct(\n product: V1Product,\n reason: Extract<ProjectionDiagnostic, { code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE' }>['error']['details']['reason']\n): ProjectionDiagnostic {\n return {\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE',\n error: {\n details: {\n product_id: product.product_id,\n reason,\n },\n },\n };\n}\n\nfunction errorIdentity(value: Record<string, unknown>): string | undefined {\n if (typeof value.code !== 'string' || typeof value.field !== 'string') return undefined;\n try {\n return `${value.code}\\u0000${value.field}\\u0000${canonicalizeJson(value.details ?? null)}`;\n } catch {\n // Preserve unreadable third-party errors instead of falsely deduplicating.\n return undefined;\n }\n}\n\nfunction mergeProjectionErrors(existing: unknown, diagnostics: readonly ProjectionDiagnostic[]): unknown[] {\n const merged = Array.isArray(existing) ? [...existing] : [];\n const seen = new Set<string>();\n for (const value of merged) {\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue;\n const record = value as Record<string, unknown>;\n const key = errorIdentity(record);\n if (key) seen.add(key);\n }\n for (const diagnostic of diagnostics) {\n const error = projectionDiagnosticToError(diagnostic) as unknown as Record<string, unknown>;\n const key = errorIdentity(error)!;\n if (seen.has(key)) continue;\n seen.add(key);\n merged.push(error);\n }\n return merged;\n}\n\nfunction remapExistingProductErrors(\n existing: unknown,\n originalToOutputIndex: ReadonlyMap<number, number | undefined>,\n products: readonly V1Product[]\n): unknown {\n if (!Array.isArray(existing)) return existing;\n return existing.map(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const record = value as Record<string, unknown>;\n let issuesChanged = false;\n const issues = Array.isArray(record.issues)\n ? record.issues.map(issue => {\n if (!issue || typeof issue !== 'object' || Array.isArray(issue)) return issue;\n const issueRecord = issue as Record<string, unknown>;\n if (typeof issueRecord.pointer !== 'string') return issue;\n const pointerMatch = /^\\/products\\/(\\d+)(\\/.*)?$/.exec(issueRecord.pointer);\n if (!pointerMatch) return issue;\n const originalIssueIndex = Number(pointerMatch[1]);\n if (!originalToOutputIndex.has(originalIssueIndex)) return issue;\n const outputIssueIndex = originalToOutputIndex.get(originalIssueIndex);\n issuesChanged = true;\n return {\n ...issueRecord,\n pointer:\n outputIssueIndex === undefined ? '/products' : `/products/${outputIssueIndex}${pointerMatch[2] ?? ''}`,\n };\n })\n : record.issues;\n const withIssues = issuesChanged ? { ...record, issues } : record;\n if (typeof record.field !== 'string') return issuesChanged ? withIssues : value;\n const match = /^products\\[(\\d+)\\](.*)$/.exec(record.field);\n if (!match) return issuesChanged ? withIssues : value;\n const originalIndex = Number(match[1]);\n if (!originalToOutputIndex.has(originalIndex)) return issuesChanged ? withIssues : value;\n const outputIndex = originalToOutputIndex.get(originalIndex);\n if (outputIndex !== undefined) {\n return { ...withIssues, field: `products[${outputIndex}]${match[2] ?? ''}` };\n }\n const productId = products[originalIndex]?.product_id;\n const details =\n record.details && typeof record.details === 'object' && !Array.isArray(record.details)\n ? { ...(record.details as Record<string, unknown>) }\n : {};\n if (typeof productId === 'string' && details.product_id === undefined) details.product_id = productId;\n return { ...withIssues, field: 'products', ...(Object.keys(details).length > 0 ? { details } : {}) };\n });\n}\n\nfunction hasEmptyPlacementFormatOptions(product: CanonicalOnlyProduct<V1Product>): boolean {\n const placements = (product as Record<string, unknown>).placements;\n if (!Array.isArray(placements)) return false;\n return placements.some(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const options = (value as Record<string, unknown>).format_options;\n return Array.isArray(options) && options.length === 0;\n });\n}\n\n/**\n * A Product that has been augmented with `format_options[]` while\n * preserving the original `format_ids[]`. Carries the projection\n * diagnostics that were generated mapping each `format_id` so the\n * buyer can see what (if anything) didn't project cleanly.\n *\n * **Write-side bridge.** After picking a `format_options[i]` entry,\n * use {@link formatIdsFromOptions} (from `@adcp/sdk/v2/projection`)\n * to extract the `format_ids[]` value for a `create_media_buy`\n * package. Inlining `decl.v1_format_ref` works but bypasses the\n * fail-closed semantics (canonical_formats_only / inherently-v2\n * canonical → throw). The spec gap that forces this bridge is tracked\n * at adcontextprotocol/adcp#4842.\n *\n * @see formatIdsFromOptions\n * @see formatIdsForCapability\n */\nexport type V2AugmentedProduct<P> = P & {\n format_options: V2ProductFormatDeclaration[];\n};\n\n/**\n * Augment a single Product. Idempotent — when `format_options[]` is\n * already present (the seller is v2-native), passes the Product\n * through unchanged. Otherwise projects from `format_ids[]`.\n *\n * Returns `{ product, diagnostics }`. `diagnostics` is empty for a\n * clean projection; populated when individual format_ids don't have\n * a v2 mapping (catalog gap, structural unreachability, etc.).\n *\n * @see toCanonicalOnlyProduct — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function augmentProductWithFormatOptions<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: V2AugmentedProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n // Already v2-shaped (seller sent format_options directly) — pass through.\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n if (Array.isArray(existing)) {\n return {\n product: product as V2AugmentedProduct<P>,\n diagnostics: [],\n };\n }\n // v1 shape — project to add format_options[].\n if (!Array.isArray(product.format_ids)) {\n // Neither shape — nothing to project. Return as-is with an empty\n // format_options so the buyer doesn't have to special-case.\n return {\n product: { ...product, format_options: [] },\n diagnostics: [],\n };\n }\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n // Preserve the original product shape (especially format_ids); just\n // add format_options.\n return {\n product: {\n ...product,\n format_options: v2.format_options,\n },\n diagnostics,\n };\n}\n\n/**\n * Augment every Product in a `get_products` response with\n * `format_options[]`. Returns `{ response, diagnostics }` so callers\n * can surface projection diagnostics alongside the response's existing\n * `errors[]` array (or filter by `source: 'sdk'` to distinguish SDK\n * diagnostics from seller-emitted errors).\n *\n * Idempotent: if the seller is v2-native and every Product already\n * carries `format_options[]`, returns the response verbatim with no\n * diagnostics.\n *\n * @see toCanonicalOnlyResponse — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function withFormatOptions<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): { response: R & { products: V2AugmentedProduct<V1Product>[] }; diagnostics: ProjectionDiagnostic[] } {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics: [],\n };\n }\n const out: V2AugmentedProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n for (const p of response.products) {\n const { product, diagnostics: d } = augmentProductWithFormatOptions(p, options);\n out.push(product);\n diagnostics.push(...d);\n }\n return {\n response: { ...response, products: out } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics,\n };\n}\n\n/**\n * An additive canonical Product: canonical declarations contain no legacy\n * routing identity, while the Product's top-level `format_ids[]` remains\n * available to compatibility consumers.\n */\nexport type AdditiveCanonicalProduct<P> = Omit<P, 'format_options'> & {\n format_options: CanonicalFormatDeclaration[];\n};\n\nfunction assertNoDirectLegacyFormatAliases(declarations: readonly V2ProductFormatDeclaration[]): void {\n for (let index = 0; index < declarations.length; index++) {\n const declaration = declarations[index] as unknown as Record<string, unknown>;\n for (const field of Object.keys(declaration)) {\n if (\n field !== 'v1_format_ref' &&\n DIRECT_LEGACY_FORMAT_IDENTITY_KEYS.has(field.replaceAll('_', '').toLowerCase())\n ) {\n throw new TypeError(\n `format_options[${index}] must not use legacy identity field ${field}; use v1_format_ref for migration routing`\n );\n }\n }\n }\n}\n\n/**\n * Project a Product to an additive, URL-free canonical surface.\n *\n * Unlike {@link augmentProductWithFormatOptions}, this always returns fresh\n * `format_options[]` declarations with `v1_format_ref` concealed. Unlike\n * {@link toCanonicalOnlyProduct}, it preserves the Product's top-level\n * `format_ids[]`. Exact canonical-to-legacy downgrade identity is returned\n * separately as JSON-safe {@link CanonicalFormatLegacyRoute} sidecars.\n *\n * Extract `routes` before any JSON round-trip — WeakMap metadata is gone after\n * deserialization. This helper enforces that ordering internally; persist its\n * returned `routes` whenever a canonical selection may cross a process boundary\n * before being forwarded to a legacy seller. Rebuild the write-side resolver\n * with `canonicalFormatLegacyResolverFromRoutes(restoredRoutes)`.\n *\n * @throws TypeError when a canonical declaration uses a direct legacy identity\n * alias such as `agent_url` or `agentUrl` instead of `v1_format_ref`.\n */\nexport function toAdditiveCanonicalProduct<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): {\n product: AdditiveCanonicalProduct<P>;\n diagnostics: ProjectionDiagnostic[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n const { product: augmented, diagnostics } = augmentProductWithFormatOptions(product, options);\n const routes = legacyRoutesForProduct(product.product_id, augmented.format_options);\n assertNoDirectLegacyFormatAliases(augmented.format_options);\n return {\n product: {\n ...augmented,\n format_options: canonicalDeclarations(augmented.format_options),\n } as AdditiveCanonicalProduct<P>,\n diagnostics,\n routes,\n };\n}\n\n/**\n * Response-level companion to {@link toAdditiveCanonicalProduct}. Projects\n * every Product and accumulates its serializable legacy routes.\n */\nexport function withAdditiveCanonicalFormatOptions<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): {\n response: Omit<R, 'products'> & { products: AdditiveCanonicalProduct<V1Product>[] };\n diagnostics: ProjectionDiagnostic[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & {\n products: AdditiveCanonicalProduct<V1Product>[];\n },\n diagnostics: [],\n routes: [],\n };\n }\n const products: AdditiveCanonicalProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n const routes: CanonicalFormatLegacyRoute[] = [];\n for (const sourceProduct of response.products) {\n const projected = toAdditiveCanonicalProduct(sourceProduct, options);\n products.push(projected.product);\n diagnostics.push(...projected.diagnostics);\n routes.push(...projected.routes);\n }\n return {\n response: { ...response, products } as Omit<R, 'products'> & {\n products: AdditiveCanonicalProduct<V1Product>[];\n },\n diagnostics,\n routes,\n };\n}\n\n/**\n * A Product reduced to the canonical creative-format surface:\n * `format_options[]` only, with the legacy `format_ids[]` removed. The\n * read-side counterpart to a fully-migrated consumer — naive downstream\n * code can no longer fall back to the stale `{ agent_url, id }` shape and\n * silently bypass the canonical model.\n */\nexport type CanonicalOnlyProduct<P> = Omit<P, 'format_ids'> & {\n format_ids?: never;\n format_options: CanonicalFormatDeclaration[];\n};\n\nfunction canonicalDeclarations(values: readonly V2ProductFormatDeclaration[]): CanonicalFormatDeclaration[] {\n return values.map(value => concealLegacyFormatRefs(value));\n}\n\nfunction canonicalPlacements(\n product: Record<string, unknown>,\n options: V1ToV2ProjectionOptions | undefined,\n diagnostics: ProjectionDiagnostic[]\n): unknown {\n if (!Array.isArray(product.placements)) return product.placements;\n return product.placements.map((value, placementIndex) => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const placement = value as Record<string, unknown>;\n const { format_ids: _drop, ...rest } = placement;\n void _drop;\n const hasLegacyFormats = Array.isArray(placement.format_ids);\n const hasCanonicalFormats = Array.isArray(placement.format_options);\n if (!hasLegacyFormats && !hasCanonicalFormats) return rest;\n\n const productId = typeof product.product_id === 'string' ? product.product_id : '(unknown)';\n const placementId = typeof placement.placement_id === 'string' ? placement.placement_id : String(placementIndex);\n const pseudoProduct = {\n product_id: `${productId}:placement:${placementId}`,\n name: typeof placement.name === 'string' ? placement.name : placementId,\n description: `Nested placement ${placementId}`,\n ...(hasLegacyFormats ? { format_ids: placement.format_ids } : {}),\n ...(hasCanonicalFormats ? { format_options: placement.format_options } : {}),\n } as unknown as V1Product;\n const projected = toCanonicalOnlyProduct(pseudoProduct, options);\n for (const diagnostic of projected.diagnostics) {\n diagnostics.push({\n ...diagnostic,\n field: diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${productId}].placements[${placementIndex}]`),\n });\n }\n return {\n ...rest,\n format_options: projected.product.format_options,\n };\n });\n}\n\n/**\n * Identity key for a `format_id` ref used by the coverage check.\n * Trailing-slash-insensitive on `agent_url` (folds the AAO host's slash /\n * no-slash forms, per `catalog.ts`'s `normalizeAgentUrl`), and includes the\n * dimensional discriminators so multi-size declarations sharing one\n * `{ agent_url, id }` but differing by size/duration are NOT collapsed —\n * the same key shape `write-side.ts` uses for v1 ref de-dup. Without the\n * size half, a `format_ids[]` entry for a size no `v1_format_ref` covers\n * would read as covered and be dropped silently.\n */\nfunction formatRefCoverageKey(ref: V1FormatId): string {\n const url = ref.agent_url && !ref.agent_url.endsWith('/') ? ref.agent_url + '/' : ref.agent_url;\n return `${url}::${ref.id}::${ref.width ?? ''}x${ref.height ?? ''}::${ref.duration_ms ?? ''}`;\n}\n\n/**\n * Project a single Product to the canonical-only shape: `format_options[]`\n * present, `format_ids[]` dropped.\n *\n * **Dropping legacy never silently loses a format.** Every input\n * `format_id` is either represented in the returned `format_options[]` or\n * surfaced in `diagnostics` — never discarded without a trace:\n *\n * - **v1-shaped input** (`format_ids[]`, no `format_options[]`): runs the\n * v1 → v2 projection. Mapped refs become `format_options[]`; any ref\n * the projection can't map is surfaced as `FORMAT_PROJECTION_FAILED`.\n * - **v2-native input** (`format_options[]` already present): keeps the\n * seller's canonical surface and drops the redundant v1 fallback. If a\n * legacy routing entry exists that no canonical option covers, it\n * surfaces a canonical-safe `LEGACY_FORMAT_ID_DROPPED_UNMAPPED`\n * diagnostic without echoing the routing identifier.\n * - **neither shape**: returns `format_options: []`; there is nothing to\n * project and nothing to lose.\n *\n * Pure and subtractive: unlike {@link augmentProductWithFormatOptions}\n * (which preserves `format_ids[]`), this drops it — the opt-in narrowing for\n * a consumer that has fully migrated. Complements the write-side\n * non-invertibility tracked at adcontextprotocol/adcp#4842 — this is the\n * read-side transparency half.\n */\nexport function toCanonicalOnlyProduct<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: CanonicalOnlyProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n\n // v2-native: the seller already sent format_options[]. Drop the\n // redundant v1 fallback, but flag any legacy ref no v1_format_ref covers.\n if (Array.isArray(existing)) {\n const formatOptions = existing as V2ProductFormatDeclaration[];\n const diagnostics: ProjectionDiagnostic[] = [];\n const inputIds = Array.isArray(product.format_ids) ? product.format_ids : [];\n if (inputIds.length > 0) {\n const covered = new Set<string>();\n for (const opt of formatOptions) {\n const refs = Array.isArray(opt?.v1_format_ref) ? opt.v1_format_ref : [];\n for (const ref of refs) covered.add(formatRefCoverageKey(ref));\n }\n for (let k = 0; k < inputIds.length; k++) {\n const fid = inputIds[k]!;\n if (!covered.has(formatRefCoverageKey(fid))) {\n diagnostics.push({\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED',\n error: {\n details: {\n product_id: product.product_id,\n resolution_failure: 'unmapped_legacy_format',\n },\n },\n });\n }\n }\n }\n const { format_ids: _dropV2, ...rest } = product as P & { format_ids?: unknown };\n void _dropV2;\n return {\n product: {\n ...rest,\n format_options: canonicalDeclarations(formatOptions),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // v1 shape: project. projectV1ProductToV2 already omits format_ids and\n // emits a diagnostic for every ref it couldn't map.\n if (Array.isArray(product.format_ids)) {\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n const { format_ids: _dropV1, ...rest } = product as P & { format_ids?: unknown };\n void _dropV1;\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: canonicalDeclarations(v2.format_options),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // Neither shape — nothing to project, nothing to lose.\n const { format_ids: _dropNone, ...rest } = product as P & { format_ids?: unknown };\n void _dropNone;\n const diagnostics: ProjectionDiagnostic[] = [];\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: [],\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n}\n\n/**\n * Reduce every Product in a `get_products` response to the canonical-only\n * shape — `format_options[]` present, `format_ids[]` dropped. Returns\n * `{ response, diagnostics }` so callers surface projection diagnostics\n * alongside the response's existing `errors[]`.\n *\n * Response-level counterpart to {@link toCanonicalOnlyProduct}; same\n * fail-closed guarantee, aggregated across products. A wholly unmappable\n * legacy product cannot be represented as a canonical Product because the\n * protocol requires `format_options` to contain at least one declaration. It\n * is therefore omitted from the canonical list and surfaced through the\n * response's portable `errors[]` plus the SDK convenience diagnostics. A\n * partially mappable product remains with its mapped options and advisories\n * for the refs that could not be projected.\n */\nexport function toCanonicalOnlyResponse<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): {\n response: Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] };\n diagnostics: ProjectionDiagnostic[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & {\n products: CanonicalOnlyProduct<V1Product>[];\n errors?: unknown[];\n },\n diagnostics: [],\n };\n }\n const out: CanonicalOnlyProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n const originalToOutputIndex = new Map<number, number | undefined>();\n for (let productIndex = 0; productIndex < response.products.length; productIndex++) {\n const p = response.products[productIndex]!;\n const { product, diagnostics: rawDiagnostics } = toCanonicalOnlyProduct(p, options);\n const hasEmptyPlacement = hasEmptyPlacementFormatOptions(product);\n const keep = product.format_options.length > 0 && !hasEmptyPlacement;\n const outputIndex = keep ? out.length : undefined;\n originalToOutputIndex.set(productIndex, outputIndex);\n const d = rawDiagnostics.map(diagnostic => ({\n ...diagnostic,\n field: keep ? diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${outputIndex}]`) : 'products',\n error: keep\n ? diagnostic.error\n : {\n details: {\n ...diagnostic.error.details,\n product_id: p.product_id,\n },\n },\n })) as ProjectionDiagnostic[];\n if (!keep && d.length === 0) {\n const reason = hasEmptyPlacement\n ? 'nested_placement_format_list_empty'\n : Array.isArray((p as Record<string, unknown>).format_options)\n ? 'canonical_format_list_empty'\n : Array.isArray(p.format_ids)\n ? 'legacy_format_list_empty'\n : 'missing_format_declaration';\n d.push({\n ...canonicalFormatsUnavailableForProduct(p, reason),\n field: 'products',\n });\n }\n diagnostics.push(...d);\n if (keep) out.push(product);\n }\n const remappedExistingErrors = remapExistingProductErrors(\n (response as { errors?: unknown }).errors,\n originalToOutputIndex,\n response.products\n );\n const errors = mergeProjectionErrors(remappedExistingErrors, diagnostics);\n return {\n response: {\n ...response,\n products: out,\n ...(errors.length > 0 ? { errors } : {}),\n } as Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] },\n diagnostics,\n };\n}\n"],"mappings":"AAuBA,SAAS,4BAA4B;AAErC,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,wBAAwB;AACjD,SAAS,+BAA+B;AAExC,SAAS,8BAA8B;AAGvC,MAAM,SAAS,aAAa,eAAe;AAC3C,MAAM,qCAAqC,oBAAI,IAAI,CAAC,YAAY,YAAY,aAAa,aAAa,CAAC;AAEvG,SAAS,oBAAoB,YAAwD;AACnF,SAAO;AAAA,IACL,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,IAKH,OAAO,WAAW,MAAM,QAAQ,wBAAwB,iBAAiB;AAAA,EAC3E;AACF;AAaA,SAAS,uBAAuB,MAA4C;AAC1E,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAGO,SAAS,4BAA4B,YAA4D;AACtG,SAAO;AAAA,IACL,MAAM,WAAW;AAAA,IACjB,SAAS,uBAAuB,WAAW,IAAI;AAAA,IAC/C,OAAO,WAAW;AAAA,IAClB,UAAU;AAAA,IACV,QAAQ,WAAW;AAAA,IACnB,QAAQ,WAAW;AAAA,IACnB,SAAS,WAAW,MAAM;AAAA,EAC5B;AACF;AAEA,SAAS,sCACP,S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AAS;AAAA,EACX;AACA,QAAM,SAAS,sBAAsB,wBAAwB,WAAW;AACxE,SAAO;AAAA,IACL,UAAU;AAAA,MACR,GAAG;AAAA,MACH,UAAU;AAAA,MACV,GAAI,OAAO,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AACF;","names":["diagnostics","rest"]}
1
+ {"version":3,"sources":["../../../../src/lib/v2/projection/augment-response.ts"],"sourcesContent":["/**\n * Buyer-side helpers that augment a v1-shaped agent response with v2\n * `format_options[]` derived from the existing `format_ids[]` on each\n * Product.\n *\n * Buyers who want the canonical creative-format model call\n * `withFormatOptions(response)` and read `format_options` instead of\n * relying only on legacy `format_ids`.\n *\n * The SDK also auto-projects compatible `AgentClient.getProducts()`\n * responses; this helper remains useful for cached responses, fixtures,\n * upstream seller/storefront composition, and explicit migration code.\n *\n * Pure functions — no IO, no caching. Each Product is projected\n * independently; diagnostics aggregate so a multi-product response\n * surfaces every projection issue at once. The helpers preserve the\n * input shape verbatim and add `format_options[]` (additive). They do\n * NOT drop `format_ids[]` — that's the 8.0 narrowing. To DROP\n * `format_ids[]` once a consumer has fully migrated, use\n * `toCanonicalOnlyProduct` / `toCanonicalOnlyResponse`.\n */\n\nimport type { V1Product, V1FormatId, V2ProductFormatDeclaration, ProjectionDiagnostic } from './types';\nimport { projectV1ProductToV2 } from './v1-to-v2';\nimport type { V1ToV2ProjectionOptions } from './v1-to-v2';\nimport { LIBRARY_VERSION } from '../../version';\nimport { canonicalize as canonicalizeJson } from '../../utils/jcs';\nimport { concealLegacyFormatRefs } from './legacy-metadata';\nimport type { CanonicalFormatDeclaration } from './legacy-metadata';\nimport { legacyRoutesForProduct } from './legacy-routes';\nimport type { CanonicalFormatLegacyRoute } from './legacy-routes';\n\nconst SDK_ID = `@adcp/sdk@${LIBRARY_VERSION}`;\nconst DIRECT_LEGACY_FORMAT_IDENTITY_KEYS = new Set(['agenturl', 'formatid', 'formatids', 'v1formatref']);\n\nfunction canonicalDiagnostic(diagnostic: ProjectionDiagnostic): ProjectionDiagnostic {\n return {\n ...diagnostic,\n // A source `format_ids[i]` index is not an index into the projected\n // `format_options[]`: earlier source refs may have failed while later refs\n // projected successfully. Point at the canonical collection instead of\n // claiming that a successful projected option is the failing value.\n field: diagnostic.field.replace(/\\.format_ids\\[\\d+\\]/g, '.format_options'),\n };\n}\n\n/** Protocol Error shape used for portable response-level projection advisories. */\nexport interface CanonicalProjectionError {\n code: ProjectionDiagnostic['code'];\n message: string;\n field: string;\n recovery: 'correctable';\n source: 'sdk';\n sdk_id: string;\n details: ProjectionDiagnostic['error']['details'];\n}\n\nfunction projectionErrorMessage(code: ProjectionDiagnostic['code']): string {\n switch (code) {\n case 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE':\n return 'Product has no format declaration representable on the canonical-only surface';\n case 'FORMAT_PROJECTION_FAILED':\n return 'Legacy creative format could not be projected to a canonical declaration';\n case 'FORMAT_DECLARATION_V1_AMBIGUOUS':\n return 'Canonical creative format has no unambiguous legacy declaration';\n case 'FORMAT_DECLARATION_V1_NOT_APPLICABLE':\n return 'Canonical-only creative format cannot be represented on a legacy format path';\n case 'CANONICAL_NOT_V1_TRANSLATABLE':\n return 'Canonical creative format has no legacy representation';\n case 'FORMAT_DECLARATION_V1_LOSSY_MULTI_SIZE':\n return 'Canonical multi-size format has incomplete legacy coverage';\n case 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED':\n return 'Redundant legacy creative identity has no canonical counterpart';\n }\n}\n\n/** Flatten the projector's internal diagnostic into the protocol `Error` shape. */\nexport function projectionDiagnosticToError(diagnostic: ProjectionDiagnostic): CanonicalProjectionError {\n return {\n code: diagnostic.code,\n message: projectionErrorMessage(diagnostic.code),\n field: diagnostic.field,\n recovery: 'correctable',\n source: diagnostic.source,\n sdk_id: diagnostic.sdk_id,\n details: diagnostic.error.details,\n } as CanonicalProjectionError;\n}\n\nfunction canonicalFormatsUnavailableForProduct(\n product: V1Product,\n reason: Extract<ProjectionDiagnostic, { code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE' }>['error']['details']['reason']\n): ProjectionDiagnostic {\n return {\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'CANONICAL_PRODUCT_FORMATS_UNAVAILABLE',\n error: {\n details: {\n product_id: product.product_id,\n reason,\n },\n },\n };\n}\n\nfunction errorIdentity(value: Record<string, unknown>): string | undefined {\n if (typeof value.code !== 'string' || typeof value.field !== 'string') return undefined;\n try {\n return `${value.code}\\u0000${value.field}\\u0000${canonicalizeJson(value.details ?? null)}`;\n } catch {\n // Preserve unreadable third-party errors instead of falsely deduplicating.\n return undefined;\n }\n}\n\nfunction mergeProjectionErrors(existing: unknown, diagnostics: readonly ProjectionDiagnostic[]): unknown[] {\n const merged = Array.isArray(existing) ? [...existing] : [];\n const seen = new Set<string>();\n for (const value of merged) {\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue;\n const record = value as Record<string, unknown>;\n const key = errorIdentity(record);\n if (key) seen.add(key);\n }\n for (const diagnostic of diagnostics) {\n const error = projectionDiagnosticToError(diagnostic) as unknown as Record<string, unknown>;\n const key = errorIdentity(error)!;\n if (seen.has(key)) continue;\n seen.add(key);\n merged.push(error);\n }\n return merged;\n}\n\nfunction remapExistingProductErrors(\n existing: unknown,\n originalToOutputIndex: ReadonlyMap<number, number | undefined>,\n products: readonly V1Product[]\n): unknown {\n if (!Array.isArray(existing)) return existing;\n return existing.map(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const record = value as Record<string, unknown>;\n let issuesChanged = false;\n const issues = Array.isArray(record.issues)\n ? record.issues.map(issue => {\n if (!issue || typeof issue !== 'object' || Array.isArray(issue)) return issue;\n const issueRecord = issue as Record<string, unknown>;\n if (typeof issueRecord.pointer !== 'string') return issue;\n const pointerMatch = /^\\/products\\/(\\d+)(\\/.*)?$/.exec(issueRecord.pointer);\n if (!pointerMatch) return issue;\n const originalIssueIndex = Number(pointerMatch[1]);\n if (!originalToOutputIndex.has(originalIssueIndex)) return issue;\n const outputIssueIndex = originalToOutputIndex.get(originalIssueIndex);\n issuesChanged = true;\n return {\n ...issueRecord,\n pointer:\n outputIssueIndex === undefined ? '/products' : `/products/${outputIssueIndex}${pointerMatch[2] ?? ''}`,\n };\n })\n : record.issues;\n const withIssues = issuesChanged ? { ...record, issues } : record;\n if (typeof record.field !== 'string') return issuesChanged ? withIssues : value;\n const match = /^products\\[(\\d+)\\](.*)$/.exec(record.field);\n if (!match) return issuesChanged ? withIssues : value;\n const originalIndex = Number(match[1]);\n if (!originalToOutputIndex.has(originalIndex)) return issuesChanged ? withIssues : value;\n const outputIndex = originalToOutputIndex.get(originalIndex);\n if (outputIndex !== undefined) {\n return { ...withIssues, field: `products[${outputIndex}]${match[2] ?? ''}` };\n }\n const productId = products[originalIndex]?.product_id;\n const details =\n record.details && typeof record.details === 'object' && !Array.isArray(record.details)\n ? { ...(record.details as Record<string, unknown>) }\n : {};\n if (typeof productId === 'string' && details.product_id === undefined) details.product_id = productId;\n return { ...withIssues, field: 'products', ...(Object.keys(details).length > 0 ? { details } : {}) };\n });\n}\n\nfunction hasEmptyPlacementFormatOptions(product: CanonicalOnlyProduct<V1Product>): boolean {\n const placements = (product as Record<string, unknown>).placements;\n if (!Array.isArray(placements)) return false;\n return placements.some(value => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const options = (value as Record<string, unknown>).format_options;\n return Array.isArray(options) && options.length === 0;\n });\n}\n\n/**\n * A Product that has been augmented with `format_options[]` while\n * preserving the original `format_ids[]`. Carries the projection\n * diagnostics that were generated mapping each `format_id` so the\n * buyer can see what (if anything) didn't project cleanly.\n *\n * **Write-side bridge.** After picking a `format_options[i]` entry,\n * use {@link formatIdsFromOptions} (from `@adcp/sdk/v2/projection`)\n * to extract the `format_ids[]` value for a `create_media_buy`\n * package. Inlining `decl.v1_format_ref` works but bypasses the\n * fail-closed semantics (canonical_formats_only / inherently-v2\n * canonical → throw). The spec gap that forces this bridge is tracked\n * at adcontextprotocol/adcp#4842.\n *\n * @see formatIdsFromOptions\n * @see formatIdsForCapability\n */\nexport type V2AugmentedProduct<P> = P & {\n format_options: V2ProductFormatDeclaration[];\n};\n\n/**\n * Augment a single Product. Idempotent — when `format_options[]` is\n * already present (the seller is v2-native), passes the Product\n * through unchanged. Otherwise projects from `format_ids[]`.\n *\n * Returns `{ product, diagnostics }`. `diagnostics` is empty for a\n * clean projection; populated when individual format_ids don't have\n * a v2 mapping (catalog gap, structural unreachability, etc.).\n *\n * @see toCanonicalOnlyProduct — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function augmentProductWithFormatOptions<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: V2AugmentedProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n // Already v2-shaped (seller sent format_options directly) — pass through.\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n if (Array.isArray(existing)) {\n return {\n product: product as V2AugmentedProduct<P>,\n diagnostics: [],\n };\n }\n // v1 shape — project to add format_options[].\n if (!Array.isArray(product.format_ids)) {\n // Neither shape — nothing to project. Return as-is with an empty\n // format_options so the buyer doesn't have to special-case.\n return {\n product: { ...product, format_options: [] },\n diagnostics: [],\n };\n }\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n // Preserve the original product shape (especially format_ids); just\n // add format_options.\n return {\n product: {\n ...product,\n format_options: v2.format_options,\n },\n diagnostics,\n };\n}\n\n/**\n * Augment every Product in a `get_products` response with\n * `format_options[]`. Returns `{ response, diagnostics }` so callers\n * can surface projection diagnostics alongside the response's existing\n * `errors[]` array (or filter by `source: 'sdk'` to distinguish SDK\n * diagnostics from seller-emitted errors).\n *\n * Idempotent: if the seller is v2-native and every Product already\n * carries `format_options[]`, returns the response verbatim with no\n * diagnostics.\n *\n * @see toCanonicalOnlyResponse — the canonical-only counterpart that DROPS\n * `format_ids[]` for a fully-migrated consumer.\n */\nexport function withFormatOptions<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): { response: R & { products: V2AugmentedProduct<V1Product>[] }; diagnostics: ProjectionDiagnostic[] } {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics: [],\n };\n }\n const out: V2AugmentedProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n for (const p of response.products) {\n const { product, diagnostics: d } = augmentProductWithFormatOptions(p, options);\n out.push(product);\n diagnostics.push(...d);\n }\n return {\n response: { ...response, products: out } as R & { products: V2AugmentedProduct<V1Product>[] },\n diagnostics,\n };\n}\n\n/**\n * An additive canonical Product: canonical declarations contain no legacy\n * routing identity, while the Product's top-level `format_ids[]` remains\n * available to compatibility consumers.\n */\nexport type AdditiveCanonicalProduct<P> = Omit<P, 'format_options'> & {\n format_options: CanonicalFormatDeclaration[];\n};\n\nfunction assertNoDirectLegacyFormatAliases(declarations: readonly V2ProductFormatDeclaration[]): void {\n for (let index = 0; index < declarations.length; index++) {\n const declaration = declarations[index] as unknown as Record<string, unknown>;\n for (const field of Object.keys(declaration)) {\n if (\n field !== 'v1_format_ref' &&\n DIRECT_LEGACY_FORMAT_IDENTITY_KEYS.has(field.replaceAll('_', '').toLowerCase())\n ) {\n throw new TypeError(\n `format_options[${index}] must not use legacy identity field ${field}; use v1_format_ref for migration routing`\n );\n }\n }\n }\n}\n\n/**\n * Conceal migration-only legacy identities from canonical format declarations\n * while extracting their durable downgrade routes first.\n *\n * This is the declaration-array counterpart to\n * {@link toAdditiveCanonicalProduct}. It is intended for persisted catalogs\n * and other consumers that do not hold a complete Product. The source array\n * and declarations are never mutated.\n *\n * @throws TypeError when a canonical declaration uses a direct legacy identity\n * alias such as `agent_url` or `agentUrl` instead of `v1_format_ref`.\n */\nexport function toCanonicalFormatOptionsWithRoutes(\n productId: string,\n formatOptions: readonly V2ProductFormatDeclaration[]\n): {\n formatOptions: CanonicalFormatDeclaration[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n assertNoDirectLegacyFormatAliases(formatOptions);\n const routes = legacyRoutesForProduct(productId, formatOptions);\n return {\n formatOptions: canonicalDeclarations(formatOptions),\n routes,\n };\n}\n\n/**\n * Project a Product to an additive, URL-free canonical surface.\n *\n * Unlike {@link augmentProductWithFormatOptions}, this always returns fresh\n * `format_options[]` declarations with `v1_format_ref` concealed. Unlike\n * {@link toCanonicalOnlyProduct}, it preserves the Product's top-level\n * `format_ids[]`. Exact canonical-to-legacy downgrade identity is returned\n * separately as JSON-safe {@link CanonicalFormatLegacyRoute} sidecars.\n *\n * Extract `routes` before any JSON round-trip — WeakMap metadata is gone after\n * deserialization. This helper enforces that ordering internally; persist its\n * returned `routes` whenever a canonical selection may cross a process boundary\n * before being forwarded to a legacy seller. Rebuild the write-side resolver\n * with `canonicalFormatLegacyResolverFromRoutes(restoredRoutes)`.\n *\n * @throws TypeError when a canonical declaration uses a direct legacy identity\n * alias such as `agent_url` or `agentUrl` instead of `v1_format_ref`.\n */\nexport function toAdditiveCanonicalProduct<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): {\n product: AdditiveCanonicalProduct<P>;\n diagnostics: ProjectionDiagnostic[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n const { product: augmented, diagnostics } = augmentProductWithFormatOptions(product, options);\n const projected = toCanonicalFormatOptionsWithRoutes(product.product_id, augmented.format_options);\n return {\n product: {\n ...augmented,\n format_options: projected.formatOptions,\n } as AdditiveCanonicalProduct<P>,\n diagnostics,\n routes: projected.routes,\n };\n}\n\n/**\n * Response-level companion to {@link toAdditiveCanonicalProduct}. Projects\n * every Product and accumulates its serializable legacy routes.\n */\nexport function withAdditiveCanonicalFormatOptions<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): {\n response: Omit<R, 'products'> & { products: AdditiveCanonicalProduct<V1Product>[] };\n diagnostics: ProjectionDiagnostic[];\n routes: CanonicalFormatLegacyRoute[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & {\n products: AdditiveCanonicalProduct<V1Product>[];\n },\n diagnostics: [],\n routes: [],\n };\n }\n const products: AdditiveCanonicalProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n const routes: CanonicalFormatLegacyRoute[] = [];\n for (const sourceProduct of response.products) {\n const projected = toAdditiveCanonicalProduct(sourceProduct, options);\n products.push(projected.product);\n diagnostics.push(...projected.diagnostics);\n routes.push(...projected.routes);\n }\n return {\n response: { ...response, products } as Omit<R, 'products'> & {\n products: AdditiveCanonicalProduct<V1Product>[];\n },\n diagnostics,\n routes,\n };\n}\n\n/**\n * A Product reduced to the canonical creative-format surface:\n * `format_options[]` only, with the legacy `format_ids[]` removed. The\n * read-side counterpart to a fully-migrated consumer — naive downstream\n * code can no longer fall back to the stale `{ agent_url, id }` shape and\n * silently bypass the canonical model.\n */\nexport type CanonicalOnlyProduct<P> = Omit<P, 'format_ids'> & {\n format_ids?: never;\n format_options: CanonicalFormatDeclaration[];\n};\n\nfunction canonicalDeclarations(values: readonly V2ProductFormatDeclaration[]): CanonicalFormatDeclaration[] {\n return values.map(value => concealLegacyFormatRefs(value));\n}\n\nfunction canonicalPlacements(\n product: Record<string, unknown>,\n options: V1ToV2ProjectionOptions | undefined,\n diagnostics: ProjectionDiagnostic[]\n): unknown {\n if (!Array.isArray(product.placements)) return product.placements;\n return product.placements.map((value, placementIndex) => {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value;\n const placement = value as Record<string, unknown>;\n const { format_ids: _drop, ...rest } = placement;\n void _drop;\n const hasLegacyFormats = Array.isArray(placement.format_ids);\n const hasCanonicalFormats = Array.isArray(placement.format_options);\n if (!hasLegacyFormats && !hasCanonicalFormats) return rest;\n\n const productId = typeof product.product_id === 'string' ? product.product_id : '(unknown)';\n const placementId = typeof placement.placement_id === 'string' ? placement.placement_id : String(placementIndex);\n const pseudoProduct = {\n product_id: `${productId}:placement:${placementId}`,\n name: typeof placement.name === 'string' ? placement.name : placementId,\n description: `Nested placement ${placementId}`,\n ...(hasLegacyFormats ? { format_ids: placement.format_ids } : {}),\n ...(hasCanonicalFormats ? { format_options: placement.format_options } : {}),\n } as unknown as V1Product;\n const projected = toCanonicalOnlyProduct(pseudoProduct, options);\n for (const diagnostic of projected.diagnostics) {\n diagnostics.push({\n ...diagnostic,\n field: diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${productId}].placements[${placementIndex}]`),\n });\n }\n return {\n ...rest,\n format_options: projected.product.format_options,\n };\n });\n}\n\n/**\n * Identity key for a `format_id` ref used by the coverage check.\n * Trailing-slash-insensitive on `agent_url` (folds the AAO host's slash /\n * no-slash forms, per `catalog.ts`'s `normalizeAgentUrl`), and includes the\n * dimensional discriminators so multi-size declarations sharing one\n * `{ agent_url, id }` but differing by size/duration are NOT collapsed —\n * the same key shape `write-side.ts` uses for v1 ref de-dup. Without the\n * size half, a `format_ids[]` entry for a size no `v1_format_ref` covers\n * would read as covered and be dropped silently.\n */\nfunction formatRefCoverageKey(ref: V1FormatId): string {\n const url = ref.agent_url && !ref.agent_url.endsWith('/') ? ref.agent_url + '/' : ref.agent_url;\n return `${url}::${ref.id}::${ref.width ?? ''}x${ref.height ?? ''}::${ref.duration_ms ?? ''}`;\n}\n\n/**\n * Project a single Product to the canonical-only shape: `format_options[]`\n * present, `format_ids[]` dropped.\n *\n * **Dropping legacy never silently loses a format.** Every input\n * `format_id` is either represented in the returned `format_options[]` or\n * surfaced in `diagnostics` — never discarded without a trace:\n *\n * - **v1-shaped input** (`format_ids[]`, no `format_options[]`): runs the\n * v1 → v2 projection. Mapped refs become `format_options[]`; any ref\n * the projection can't map is surfaced as `FORMAT_PROJECTION_FAILED`.\n * - **v2-native input** (`format_options[]` already present): keeps the\n * seller's canonical surface and drops the redundant v1 fallback. If a\n * legacy routing entry exists that no canonical option covers, it\n * surfaces a canonical-safe `LEGACY_FORMAT_ID_DROPPED_UNMAPPED`\n * diagnostic without echoing the routing identifier.\n * - **neither shape**: returns `format_options: []`; there is nothing to\n * project and nothing to lose.\n *\n * Pure and subtractive: unlike {@link augmentProductWithFormatOptions}\n * (which preserves `format_ids[]`), this drops it — the opt-in narrowing for\n * a consumer that has fully migrated. Complements the write-side\n * non-invertibility tracked at adcontextprotocol/adcp#4842 — this is the\n * read-side transparency half.\n */\nexport function toCanonicalOnlyProduct<P extends V1Product>(\n product: P,\n options?: V1ToV2ProjectionOptions\n): { product: CanonicalOnlyProduct<P>; diagnostics: ProjectionDiagnostic[] } {\n const existing = (product as unknown as { format_options?: unknown }).format_options;\n\n // v2-native: the seller already sent format_options[]. Drop the\n // redundant v1 fallback, but flag any legacy ref no v1_format_ref covers.\n if (Array.isArray(existing)) {\n const formatOptions = existing as V2ProductFormatDeclaration[];\n const diagnostics: ProjectionDiagnostic[] = [];\n const inputIds = Array.isArray(product.format_ids) ? product.format_ids : [];\n if (inputIds.length > 0) {\n const covered = new Set<string>();\n for (const opt of formatOptions) {\n const refs = Array.isArray(opt?.v1_format_ref) ? opt.v1_format_ref : [];\n for (const ref of refs) covered.add(formatRefCoverageKey(ref));\n }\n for (let k = 0; k < inputIds.length; k++) {\n const fid = inputIds[k]!;\n if (!covered.has(formatRefCoverageKey(fid))) {\n diagnostics.push({\n source: 'sdk',\n sdk_id: SDK_ID,\n field: `products[${product.product_id}].format_options`,\n code: 'LEGACY_FORMAT_ID_DROPPED_UNMAPPED',\n error: {\n details: {\n product_id: product.product_id,\n resolution_failure: 'unmapped_legacy_format',\n },\n },\n });\n }\n }\n }\n const { format_ids: _dropV2, ...rest } = product as P & { format_ids?: unknown };\n void _dropV2;\n return {\n product: {\n ...rest,\n format_options: canonicalDeclarations(formatOptions),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // v1 shape: project. projectV1ProductToV2 already omits format_ids and\n // emits a diagnostic for every ref it couldn't map.\n if (Array.isArray(product.format_ids)) {\n const { v2, diagnostics } = projectV1ProductToV2(product, options);\n const { format_ids: _dropV1, ...rest } = product as P & { format_ids?: unknown };\n void _dropV1;\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: canonicalDeclarations(v2.format_options),\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n }\n\n // Neither shape — nothing to project, nothing to lose.\n const { format_ids: _dropNone, ...rest } = product as P & { format_ids?: unknown };\n void _dropNone;\n const diagnostics: ProjectionDiagnostic[] = [];\n return {\n product: {\n ...(rest as Omit<P, 'format_ids'>),\n format_options: [],\n ...(Array.isArray((product as Record<string, unknown>).placements)\n ? { placements: canonicalPlacements(product as Record<string, unknown>, options, diagnostics) }\n : {}),\n } as CanonicalOnlyProduct<P>,\n diagnostics: diagnostics.map(canonicalDiagnostic),\n };\n}\n\n/**\n * Reduce every Product in a `get_products` response to the canonical-only\n * shape — `format_options[]` present, `format_ids[]` dropped. Returns\n * `{ response, diagnostics }` so callers surface projection diagnostics\n * alongside the response's existing `errors[]`.\n *\n * Response-level counterpart to {@link toCanonicalOnlyProduct}; same\n * fail-closed guarantee, aggregated across products. A wholly unmappable\n * legacy product cannot be represented as a canonical Product because the\n * protocol requires `format_options` to contain at least one declaration. It\n * is therefore omitted from the canonical list and surfaced through the\n * response's portable `errors[]` plus the SDK convenience diagnostics. A\n * partially mappable product remains with its mapped options and advisories\n * for the refs that could not be projected.\n */\nexport function toCanonicalOnlyResponse<R extends { products?: V1Product[] }>(\n response: R,\n options?: V1ToV2ProjectionOptions\n): {\n response: Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] };\n diagnostics: ProjectionDiagnostic[];\n} {\n if (!Array.isArray(response?.products)) {\n return {\n response: { ...response, products: [] } as Omit<R, 'products'> & {\n products: CanonicalOnlyProduct<V1Product>[];\n errors?: unknown[];\n },\n diagnostics: [],\n };\n }\n const out: CanonicalOnlyProduct<V1Product>[] = [];\n const diagnostics: ProjectionDiagnostic[] = [];\n const originalToOutputIndex = new Map<number, number | undefined>();\n for (let productIndex = 0; productIndex < response.products.length; productIndex++) {\n const p = response.products[productIndex]!;\n const { product, diagnostics: rawDiagnostics } = toCanonicalOnlyProduct(p, options);\n const hasEmptyPlacement = hasEmptyPlacementFormatOptions(product);\n const keep = product.format_options.length > 0 && !hasEmptyPlacement;\n const outputIndex = keep ? out.length : undefined;\n originalToOutputIndex.set(productIndex, outputIndex);\n const d = rawDiagnostics.map(diagnostic => ({\n ...diagnostic,\n field: keep ? diagnostic.field.replace(/^products\\[[^\\]]+\\]/, `products[${outputIndex}]`) : 'products',\n error: keep\n ? diagnostic.error\n : {\n details: {\n ...diagnostic.error.details,\n product_id: p.product_id,\n },\n },\n })) as ProjectionDiagnostic[];\n if (!keep && d.length === 0) {\n const reason = hasEmptyPlacement\n ? 'nested_placement_format_list_empty'\n : Array.isArray((p as Record<string, unknown>).format_options)\n ? 'canonical_format_list_empty'\n : Array.isArray(p.format_ids)\n ? 'legacy_format_list_empty'\n : 'missing_format_declaration';\n d.push({\n ...canonicalFormatsUnavailableForProduct(p, reason),\n field: 'products',\n });\n }\n diagnostics.push(...d);\n if (keep) out.push(product);\n }\n const remappedExistingErrors = remapExistingProductErrors(\n (response as { errors?: unknown }).errors,\n originalToOutputIndex,\n response.products\n );\n const errors = mergeProjectionErrors(remappedExistingErrors, diagnostics);\n return {\n response: {\n ...response,\n products: out,\n ...(errors.length > 0 ? { errors } : {}),\n } as Omit<R, 'products'> & { products: CanonicalOnlyProduct<V1Product>[]; errors?: unknown[] },\n diagnostics,\n };\n}\n"],"mappings":"AAuBA,SAAS,4BAA4B;AAErC,SAAS,uB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,8 @@
23
23
  * `format_options[]`, preserved top-level `format_ids[]`, and explicit
24
24
  * serializable legacy-route sidecars for later forwarding.
25
25
  * `withAdditiveCanonicalFormatOptions` is the response-level companion.
26
+ * `toCanonicalFormatOptionsWithRoutes` provides the same safe route-first
27
+ * concealment for callers that hold only a declaration array.
26
28
  *
27
29
  * - `toCanonicalOnlyProduct` / `toCanonicalOnlyResponse` — the
28
30
  * read-side narrowing for a fully-migrated consumer. Returns
@@ -42,7 +44,7 @@ export type { V1ToV2Result, V1ToV2ProjectionOptions, BareFormatIdResolveOptions,
42
44
  export { projectV2ProductToV1 } from './v2-to-v1.mjs';
43
45
  export type { V2ToV1Result, V2ToV1ProjectionOptions, CanonicalFormatLegacyResolver, CanonicalFormatLegacyResolutionContext, CanonicalProductFormatLegacyResolutionContext, CanonicalCreativeFormatLegacyResolutionContext, CanonicalSelectorFormatLegacyResolutionContext, } from './v2-to-v1.mjs';
44
46
  export { canonicalFormatLegacyResolverFromRoutes, legacyRoutesForProduct, type CanonicalFormatLegacyRoute, } from './legacy-routes.mjs';
45
- export { augmentProductWithFormatOptions, withFormatOptions, toAdditiveCanonicalProduct, withAdditiveCanonicalFormatOptions, toCanonicalOnlyProduct, toCanonicalOnlyResponse, type V2AugmentedProduct, type AdditiveCanonicalProduct, type CanonicalOnlyProduct, } from './augment-response.mjs';
47
+ export { augmentProductWithFormatOptions, withFormatOptions, toCanonicalFormatOptionsWithRoutes, toAdditiveCanonicalProduct, withAdditiveCanonicalFormatOptions, toCanonicalOnlyProduct, toCanonicalOnlyResponse, type V2AugmentedProduct, type AdditiveCanonicalProduct, type CanonicalOnlyProduct, } from './augment-response.mjs';
46
48
  export { CanonicalFormat, audioDaastFormatDeclaration, audioHostedFormatDeclaration, agentPlacementFormatDeclaration, canonicalFormatDeclaration, customFormatDeclaration, displayTagFormatDeclaration, legacyFormatRef, legacyFormatRefs, html5FormatDeclaration, imageCarouselFormatDeclaration, imageFormatDeclaration, nativeInFeedFormatDeclaration, productCard, productCardDetailed, responsiveCreativeFormatDeclaration, sponsoredPlacementFormatDeclaration, videoHostedFormatDeclaration, videoVastFormatDeclaration, type CanonicalFormatDeclaration, type CanonicalFormatDeclarationFields, type CanonicalFormatKind, type CanonicalFormatParams, type FormatReferenceInput, type ProductCardDetailedFields, type ProductCardFields, } from './builders.mjs';
47
49
  export { packageRefsForFormatOptions, packageRefsForCapabilities, legacyFormatIdsFromOptions, tryLegacyFormatIdsFromOptions, legacyFormatIdsForFormatOption, legacyFormatIdsForCapability, FormatOptionRefsLookupError, CapabilityIdsLookupError, type PackageFormatRefs, type PackageCapabilityRefs, type FormatOptionRef, type FormatOptionSelector, type FormatOptionRefsLookupErrorCode, type CapabilityIdsLookupErrorCode, } from './write-side.mjs';
48
50
  export type { V1FormatId, V2ProductFormatDeclaration, V2Product, V1Product, ProjectionDiagnostic } from './types.mjs';
@@ -23,6 +23,8 @@
23
23
  * `format_options[]`, preserved top-level `format_ids[]`, and explicit
24
24
  * serializable legacy-route sidecars for later forwarding.
25
25
  * `withAdditiveCanonicalFormatOptions` is the response-level companion.
26
+ * `toCanonicalFormatOptionsWithRoutes` provides the same safe route-first
27
+ * concealment for callers that hold only a declaration array.
26
28
  *
27
29
  * - `toCanonicalOnlyProduct` / `toCanonicalOnlyResponse` — the
28
30
  * read-side narrowing for a fully-migrated consumer. Returns
@@ -42,7 +44,7 @@ export type { V1ToV2Result, V1ToV2ProjectionOptions, BareFormatIdResolveOptions,
42
44
  export { projectV2ProductToV1 } from './v2-to-v1';
43
45
  export type { V2ToV1Result, V2ToV1ProjectionOptions, CanonicalFormatLegacyResolver, CanonicalFormatLegacyResolutionContext, CanonicalProductFormatLegacyResolutionContext, CanonicalCreativeFormatLegacyResolutionContext, CanonicalSelectorFormatLegacyResolutionContext, } from './v2-to-v1';
44
46
  export { canonicalFormatLegacyResolverFromRoutes, legacyRoutesForProduct, type CanonicalFormatLegacyRoute, } from './legacy-routes';
45
- export { augmentProductWithFormatOptions, withFormatOptions, toAdditiveCanonicalProduct, withAdditiveCanonicalFormatOptions, toCanonicalOnlyProduct, toCanonicalOnlyResponse, type V2AugmentedProduct, type AdditiveCanonicalProduct, type CanonicalOnlyProduct, } from './augment-response';
47
+ export { augmentProductWithFormatOptions, withFormatOptions, toCanonicalFormatOptionsWithRoutes, toAdditiveCanonicalProduct, withAdditiveCanonicalFormatOptions, toCanonicalOnlyProduct, toCanonicalOnlyResponse, type V2AugmentedProduct, type AdditiveCanonicalProduct, type CanonicalOnlyProduct, } from './augment-response';
46
48
  export { CanonicalFormat, audioDaastFormatDeclaration, audioHostedFormatDeclaration, agentPlacementFormatDeclaration, canonicalFormatDeclaration, customFormatDeclaration, displayTagFormatDeclaration, legacyFormatRef, legacyFormatRefs, html5FormatDeclaration, imageCarouselFormatDeclaration, imageFormatDeclaration, nativeInFeedFormatDeclaration, productCard, productCardDetailed, responsiveCreativeFormatDeclaration, sponsoredPlacementFormatDeclaration, videoHostedFormatDeclaration, videoVastFormatDeclaration, type CanonicalFormatDeclaration, type CanonicalFormatDeclarationFields, type CanonicalFormatKind, type CanonicalFormatParams, type FormatReferenceInput, type ProductCardDetailedFields, type ProductCardFields, } from './builders';
47
49
  export { packageRefsForFormatOptions, packageRefsForCapabilities, legacyFormatIdsFromOptions, tryLegacyFormatIdsFromOptions, legacyFormatIdsForFormatOption, legacyFormatIdsForCapability, FormatOptionRefsLookupError, CapabilityIdsLookupError, type PackageFormatRefs, type PackageCapabilityRefs, type FormatOptionRef, type FormatOptionSelector, type FormatOptionRefsLookupErrorCode, type CapabilityIdsLookupErrorCode, } from './write-side';
48
50
  export type { V1FormatId, V2ProductFormatDeclaration, V2Product, V1Product, ProjectionDiagnostic } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/v2/projection/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAE,oBAAoB,EAAE,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