feat(client): typed asset builders for discriminator injection#771
Merged
feat(client): typed asset builders for discriminator injection#771
Conversation
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>
4 tasks
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
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
asset_typeliteral when constructing creative assets:imageAsset,videoAsset,audioAsset,textAsset,urlAsset,htmlAsset,javascriptAsset,cssAsset,markdownAsset,webhookAsset.Asset.*namespace over the same functions for assets-by-role manifests. Prefer the named exports; useAsset.image({...})when building several types together.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.examples/generative-creative-demo.tsto use the helpers — nine call sites, each{ asset_type: 'image', url, ... }literal becomesimageAsset({ url, ... }).Test plan
npx tsc --noEmitcleannpm run build:libsucceedsnpm run test:lib— 4351 passing, 0 failing (5 new sub-tests underasset builders)🤖 Generated with Claude Code