Skip to content

feat(client): typed asset builders for discriminator injection#771

Merged
bokelley merged 1 commit intomainfrom
bokelley/asset-type-defaults
Apr 22, 2026
Merged

feat(client): typed asset builders for discriminator injection#771
bokelley merged 1 commit intomainfrom
bokelley/asset-type-defaults

Conversation

@bokelley
Copy link
Copy Markdown
Contributor

Summary

  • Adds ten typed factory helpers that inject the asset_type literal when constructing creative assets: imageAsset, videoAsset, audioAsset, textAsset, urlAsset, htmlAsset, javascriptAsset, cssAsset, markdownAsset, webhookAsset.
  • Adds a grouped Asset.* namespace over the same functions for assets-by-role manifests. Prefer the named exports; use Asset.image({...}) when building several types together.
  • Return type is Omit<T, 'asset_type'> & { asset_type: '<literal>' } so the helpers compile regardless of whether the generated types currently carry the discriminator — stable across schema regenerations.
  • Discriminator is spread last in the returned object so a runtime cast cannot overwrite the canonical tag.
  • Refactors examples/generative-creative-demo.ts to use the helpers — nine call sites, each { asset_type: 'image', url, ... } literal becomes imageAsset({ url, ... }).

Test plan

  • npx tsc --noEmit clean
  • npm run build:lib succeeds
  • npm run test:lib — 4351 passing, 0 failing (5 new sub-tests under asset builders)
  • Prettier clean on all touched files
  • Three independent expert reviews (code-reviewer, dx-expert, javascript-protocol-expert) — all cleared

🤖 Generated with Claude Code

Add ten factory helpers that inject the asset_type discriminator
when constructing creative assets: imageAsset, videoAsset, audioAsset,
textAsset, urlAsset, htmlAsset, javascriptAsset, cssAsset,
markdownAsset, webhookAsset, plus a grouped Asset.* namespace.
Replaces hand-authored {asset_type: 'image', ...} literals at every
construction site with imageAsset({url, width, height}). Return type
is Omit<T, 'asset_type'> & {asset_type: '<literal>'} so the helpers
compile against the committed generated types whether or not they
currently carry the discriminator.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bokelley bokelley merged commit 740f609 into main Apr 22, 2026
9 checks passed
bokelley added a commit that referenced this pull request Apr 22, 2026
#772)

* feat(client): typed render builders for preview_creative discriminator

Adds urlRender / htmlRender / bothRender factory helpers + a grouped
Render namespace. Each helper takes the render payload without
output_format and returns the tagged object — urlRender({ render_id,
preview_url, role }) can't be called without preview_url because the
input type omits output_format and requires the sibling field the url
variant needs.

Mirrors the asset-builder pattern (#771). PreviewRender is a oneOf on
output_format with three variants; matrix runs kept catching renders
that dropped the discriminator or its required sibling. These helpers
make the wrong shape syntactically harder to express.

Return type is Omit<Variant, 'output_format'> & { output_format: <literal> }
for regen-stability. Discriminator spread last so a runtime cast can't
overwrite the canonical tag.

Skill pitfall callouts in build-creative-agent and
build-generative-seller-agent now recommend the render helpers alongside
the asset helpers.

* docs: regenerate llms.txt + TYPE-SUMMARY for v5.10.0 version header
@github-actions github-actions Bot mentioned this pull request Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant