Skip to content

feat(decisioning): close v6 platform gaps for creative-template adopters (#1324, #1325, #1327) - #1348

Merged
bokelley merged 4 commits into
mainfrom
bokelley/issues-1324-1325-1327
May 2, 2026
Merged

bokelley merged 4 commits into
mainfrom
bokelley/issues-1324-1325-1327

Conversation

@bokelley

@bokelley bokelley commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Three coordinated fixes that surfaced together while building the worked-reference creative-template adapter (#1274 lineage). Each closes a distinct DX gap; they share the no-account / typed-handler / typed-Format surface so they ship as one PR.

Changes

#1324 — listCreativeFormats? on creative platforms

listCreativeFormats?(req, ctx) is now modeled on both CreativeBuilderPlatform and CreativeAdServerPlatform, dispatched through buildCreativeHandlers (from-platform.ts). Pre-fix, every creative-agent adopter that owned a format catalog had to drop down to the v5 escape hatch (opts.creative.listCreativeFormats) — the typed-platform path didn't carry the surface. Adopters who delegate via capabilities.creative_agents continue to omit; framework returns UNSUPPORTED_FEATURE.

#1325 — codegen tightening for Format.renders[]

New flattenMutualExclusiveOneOf preprocess in scripts/generate-types.ts detects the JSON Schema "X xor Y" idiom (oneOf branches with { required: [X], not: { required: [Y] } } and no other keys) and inlines parent properties per branch with the excluded fields removed. The mutual-exclusivity constraint stays enforced at runtime by Ajv against the unstripped schema; the codegen pass only widens what TypeScript can express.

Format.renders[] is now:

renders?: (
  | { role: string; dimensions: { width?: number; height?: number; ... } }
  | { role: string; parameters_from_format_id: true }
)[];

Both branches are closed shapes — displayRender({...}) and parameterizedRender({...}) compose cleanly under strict tsc. Same fix benefits sync_plans plan budget (reallocation_threshold xor reallocation_unlimited), which had the identical loose-arm shape.

RenderDimensions.unit tightened from string to the schema's DimensionUnit enum ('px' | 'dp' | 'inches' | 'cm' | 'mm' | 'pt') — adopters who passed unit: 'feet' or other off-spec strings will now see a TS error.

#1327 — NoAccountCtx<TCtxMeta> for no-account tools

New NoAccountCtx<TCtxMeta> type in account.ts whose account: Account<TCtxMeta> | undefined. Applied to:

  • CreativeBuilderPlatform.previewCreative?
  • CreativeBuilderPlatform.listCreativeFormats? (new)
  • CreativeAdServerPlatform.previewCreative
  • CreativeAdServerPlatform.listCreativeFormats? (new)
  • SalesPlatform.providePerformanceFeedback?
  • SalesPlatform.listCreativeFormats?

Same shape as the definePlatformWithCompliance fix in #1262 — converts a runtime gate (Cannot read properties of undefined (reading 'ctx_metadata') deep in upstream calls) into a compile-time invariant. The runtime dispatch was already passing ctx.account === undefined for these tools whenever accounts.resolve(undefined) returned null; this PR makes the compiler force the narrow at authorship.

Test plan

  • npm test — 7,485 pass, 7 skipped, 0 fail
  • npx tsc --noEmit clean
  • npm run format:check clean
  • New runtime tests in test/server-decisioning-from-platform.test.js cover listCreativeFormats dispatch + UNSUPPORTED_FEATURE
  • New type-only tests in decisioning.type-checks.ts cover (a) displayRender assignability to Format['renders'], (b) positive previewCreative narrow, (c) negative @ts-expect-error regression alarm on unnarrowed ctx.account.ctx_metadata access
  • Reviewed by ad-tech-protocol-expert (sound-with-caveats; nits addressed), code-reviewer (no blockers; must-fix and nits addressed), dx-expert (ship; doc follow-ups noted)

Migration notes

Three changesets included:

  • creative-list-creative-formats.md (minor) — new platform method
  • format-renders-codegen-tighten.md (patch) — codegen + RenderDimensions.unit narrow
  • no-account-ctx-narrow.md (minor) — NoAccountCtx typing change

Adopters of 'derived' resolution stores that always return a singleton are unaffected at runtime, but the compiler will now require if (!ctx.account) ... narrows in previewCreative / listCreativeFormats / providePerformanceFeedback handlers. Migration guidance is in the no-account-ctx-narrow changeset and the NoAccountCtx JSDoc.

Follow-ups (not in this PR)

DX expert flagged skill / migration-doc updates. Out of scope for this PR; will follow:

  • skills/build-creative-agent/SKILL.md — show if (!ctx.account) narrow in cookbook examples
  • skills/build-decisioning-creative-template/SKILL.md — update previewCreative example signature
  • docs/migration-4.x-to-5.x.md — add 5.x → next-minor stanza for the codegen tightening + NoAccountCtx

🤖 Generated with Claude Code

bokelley and others added 4 commits May 2, 2026 16:14
Three coordinated fixes for adcp-client issues #1324, #1325, #1327:

#1324: Add `listCreativeFormats?` to `CreativeBuilderPlatform` and
`CreativeAdServerPlatform`, dispatched through `buildCreativeHandlers`.
Previously every creative-agent adopter that owned a format catalog had
to drop down to the v5 escape hatch (`opts.creative.listCreativeFormats`)
because the typed-platform path didn't carry the surface.

#1325: Tighten codegen for the `Format.renders[]` mutual-exclusivity
oneOf — extract closed-shape branches instead of `{ [k: string]: unknown }`.
A new `flattenMutualExclusiveOneOf` preprocess in `generate-types.ts`
detects the JSON Schema "X xor Y" pattern (`{ required: [X], not: { required: [Y] } }`)
and inlines parent properties per branch with the excluded fields removed.
The SDK's typed render builders (`displayRender`, `parameterizedRender`)
now compose with `Format['renders']` under strict tsc. Same fix benefits
sync_plans plan budget (reallocation_threshold xor reallocation_unlimited).
Also tightens `RenderDimensions.unit` to the schema's `DimensionUnit` enum.

#1327: New `NoAccountCtx<TCtxMeta>` request-context type whose
`account: Account<TCtxMeta> | undefined` is applied to the no-account
tool signatures (`previewCreative`, `listCreativeFormats`,
`providePerformanceFeedback`). Converts the runtime-only gate into a
compile-time invariant — same shape as the `definePlatformWithCompliance`
fix in #1262. Adopters reading `ctx.account.ctx_metadata` without a
narrow now get a TS error at authorship instead of a runtime crash.

Tests added: dispatch + UNSUPPORTED_FEATURE coverage for the new
`listCreativeFormats` path, type-only assertions in
`decisioning.type-checks.ts` for builder assignability and ctx narrowing.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- Drop historical "Pre-#XXXX" comments in decisioning.type-checks.ts per
  CLAUDE.md (no temporal/historical context); rewrite as invariant statements.
- Inline `_previewStub` returns to match the file's existing `({}) as never`
  / inline-cast idiom; drop the hoisted variable.
- `flattenMutualExclusiveOneOf`: filter outer `required` against each
  branch's `not.required` exclusions before merging — prevents a latent
  footgun where a future schema's outer-required + branch-excluded field
  would land as `required: unknown` in TS. (No diff in 3.0.4 generated
  output.) Also document the implicit `additionalProperties: false`
  decision so a future open-branch idiom isn't silently closed.
- Update stale deferred-list JSDoc in `from-platform.ts` — the no-account
  surface is no longer deferred for the creative path; it's now typed via
  `NoAccountCtx`.
- Soften prescriptive language on `CreativeBuilderPlatform.listCreativeFormats?`
  JSDoc to acknowledge per-tenant catalogs (Bannerflow / Celtra) and point at
  the `accounts.resolve(undefined)` synthetic-account pattern.
- Improve `UNSUPPORTED_FEATURE` messages on `previewCreative` /
  `listCreativeFormats` dispatch — name the adopter-side hook and the
  cap-delegation alternative so LLM adopters can self-fix.
- Harden `previewCreative` dispatch check against `{ previewCreative:
  undefined }` shape (matches the new `listCreativeFormats` check).
- Add comment on the `NoAccountCtx` inline type-import explaining why it
  can't be a top-level `import type` (account.ts <-> context.ts cycle).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The v2-5 codegen path uses the same enforceStrictSchema preprocessing as v3,
so the new flattenMutualExclusiveOneOf transform applies — Format.renders[]
now produces closed shapes in v2-5 too. CI 'Validate generated files are in
sync' caught the missed regen.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Two pre-existing baselined errors in build-generative-seller-agent and
build-retail-media-agent SKILL.md examples now report ctx as
`NoAccountCtx<...>` instead of `Ctx<...>` — same underlying issue
(example handlers return non-spec shapes; baselined as known issue),
just the error-message prefix shifted with the signature change.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit 2459665 into main May 2, 2026
10 checks passed
@bokelley
bokelley deleted the bokelley/issues-1324-1325-1327 branch May 2, 2026 20:47
bokelley added a commit that referenced this pull request May 2, 2026
Main shipped #1324 / #1325 / #1327 via PR #1348 with a different (and
more refined) approach than this branch's version:

- #1324 (`listCreativeFormats?` on creative platforms): main wires it
  with `ctx: NoAccountCtx<TCtxMeta>` typing for compile-time narrowing
  of the no-account ctx, and registers the dispatcher unconditionally
  (returns `UNSUPPORTED_FEATURE` internally when the method is absent).
  Take main's version.

- #1325 (`Format.renders[]` codegen): main calls the preprocessor
  `flattenMutualExclusiveOneOf` and additionally tightens
  `RenderDimensions.unit` to the `DimensionUnit` enum. Same idea as my
  `tightenMutualExclusionOneOf`. Take main's.

- #1327 (no-account-tool footgun): main solved with a `NoAccountCtx<TCtxMeta>`
  type narrowing on per-tool ctx (option 1 from the issue). My
  `accountStoreWithNoAccountFallback` + `defineAccountStore` helpers
  (option 2) become redundant. Drop them.

Preserved from this branch:

- #1337 (oneOf near-miss validator hint) — `compactUnionErrors` excludes
  `not`-failure variants from the survivor pick. Untouched in main.
- #1338 (SHAPE-GOTCHAS §6 walled-garden CAPI projection) — pure docs,
  untouched in main.
- #1341 (SalesPlatform split into core + ingestion) — sales.ts methods
  optional, `SalesCorePlatform` / `SalesIngestionPlatform` named subset
  types, `RequiredPlatformsFor<S>` per-specialism mapping,
  `defineSalesCorePlatform` / `defineSalesIngestionPlatform` helpers,
  conditional-spread dispatchers in `from-platform.ts`. The earlier
  follow-up commit (`0f0332e1`) documented the post-#1341 migration
  paths and locked them as type tests; that work is preserved through
  the merge.

Conflict resolution:
- `format-renders-codegen-tighten.md` — kept main's changeset.
- `format-render-builders.ts` — kept main's standalone interface
  declarations (with `unit: DimensionUnit`); dropped my derive-from-
  generated approach.
- `from-platform.ts` createMediaBuy / updateMediaBuy — wrapped main's
  hydrateForTool / routeIfHandoff bodies in this branch's #1341
  conditional spreads (`...(sales.X && {})`), with `sales.X!()`
  non-null assertions inside.
- `from-platform.ts` listCreativeFormats — dropped my conditional
  spread + `creativeListCreativeFormats` lookup in
  `buildCreativeHandlers`; kept main's unconditional registration with
  internal `UNSUPPORTED_FEATURE` check (matches the existing pattern
  for `previewCreative` / `listCreatives` / `getCreativeDelivery` and
  the regression test added in #1348).
- Generated types — taken from main; regenerated locally to confirm
  byte-identity with the merged preprocessor + my #1341 sales.ts
  refactor.

Verified:
- `npx tsc --noEmit` clean
- `npm run format:check` clean
- `npm test` — 7595 pass, 0 fail, 7 skipped
- `test/validation-oneof-cascade.test.js` 6/6 (#1337 regression test
  preserved)
- `test/server-decisioning-from-platform.test.js` 109/109 (main's
  #1324 UNSUPPORTED_FEATURE regression test now passes against the
  conditional-spread + always-register hybrid)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant