Skip to content

feat(types): TypeScript codegen for AdCP v2.5 wire shape - #1134

Merged
bokelley merged 3 commits into
mainfrom
bokelley/v2.5-typescript-codegen
May 1, 2026
Merged

bokelley merged 3 commits into
mainfrom
bokelley/v2.5-typescript-codegen

Conversation

@bokelley

@bokelley bokelley commented May 1, 2026

Copy link
Copy Markdown
Contributor

Adds @adcp/sdk/types/v2-5 — request/response interfaces for every tool in the v2.5 schema bundle (13 tools across media-buy, creative, signals protocols). Foundation for the upcoming adapter-registry refactor where adapter signatures become (V3Request) => V25Request and wire-format bugs become TypeScript errors instead of runtime warnings.

Why

After the foundation PRs (#1121, #1123, #1133) landed, the v2.5 schemas were runtime-loadable for AJV validation but had no compile-time presence. Adapter functions like adaptCreateMediaBuyRequestForV2 still take any and return any. The buyer_ref bug (#1115) that we fixed was a runtime warning catch — TypeScript couldn't have caught it because there was no V25CreateMediaBuyRequest type to match against.

This PR adds that type surface. The next PR (adapter-registry refactor) will retype the adapter functions to use it.

How

scripts/generate-v2-5-types.ts compiles every v2.5 tool as a single mega-schema with shared definitions and runs json-schema-to-typescript once. The mega-schema approach naturally deduplicates shared types (BrandID, FormatID, AssetContentType, etc.) instead of producing per-tool copies that collide at the type level — what tripped up the first attempt with per-tool compilation.

Output: src/lib/types/v2-5/tools.generated.ts (4226 LOC, 164 exports, clean tsc check). Checked in alongside src/lib/types/tools.generated.ts for v3.

Pipeline integration

  • package.json: ./types/v2-5 export entry, typesVersions mapping, generate-types:v2.5 + generate-types:all umbrella scripts.
  • .github/workflows/ci.yml: "Validate generated files in sync" now runs generate-types:v2.5 too. Forgotten regen after a schema refresh fails the build.
  • scripts/generate-types.ts: enforceStrictSchema is now exported so the v2.5 generator can apply the same JSON-Schema preprocessing (strip additionalProperties: true, drop if/then/else conditionals, recurse into combinators). No v3 behavior change.

Consumer surface

// Namespace import
import * as V25 from '@adcp/sdk/types/v2-5';
const req: V25.CreateMediaBuyRequest = ...;

// Named import
import type { CreateMediaBuyRequest } from '@adcp/sdk/types/v2-5';

13 tools × 2 (request, response) = 26 entry-point types, plus the per-tool sub-types (e.g. CreateMediaBuySuccess, CreateMediaBuyError).

Test plan

  • npm run generate-types:v2.5 — produces stable, deterministic output
  • npx tsc --noEmit on the generated file — clean
  • test/lib/v2-5-types-import.test.js — 3/3 pass: dist artifacts present, declarations include all 13 tool pairs, package.json exports ./types/v2-5
  • npm run test:lib — 5555 pass / 7 pre-existing skipped / 0 fail
  • npm run typecheck — clean

Compatibility

Patch-level + new export entry. No existing import path changes. Adopters who don't import from ./types/v2-5 see no diff.

Related

🤖 Generated with Claude Code

Adds @adcp/sdk/types/v2-5 — request/response interfaces for every tool
in the v2.5 schema bundle (13 tools across media-buy, creative, signals
protocols). Foundation for the adapter-registry refactor where adapter
signatures become (V3Request) => V25Request and wire-format bugs
become TypeScript errors instead of runtime warnings.

scripts/generate-v2-5-types.ts compiles every v2.5 tool as a single
mega-schema with shared `definitions` and runs json-schema-to-typescript
once. The mega-schema approach naturally deduplicates shared types
(BrandID, FormatID, AssetContentType, etc) instead of producing
per-tool copies that collide at the type level — what tripped up the
first attempt with per-tool compilation.

Output: src/lib/types/v2-5/tools.generated.ts (4226 LOC, 164 exports,
clean tsc check). Checked in alongside src/lib/types/tools.generated.ts
for v3. CI's "Validate generated files in sync" step runs both v3 and
v2.5 generation, so a forgotten regeneration after a schema refresh
fails the build.

scripts/generate-types.ts: enforceStrictSchema is now exported so the
v2.5 generator can apply the same JSON-Schema preprocessing (strip
additionalProperties:true, drop if/then/else conditionals, recurse
into combinators). No v3 behavior change.

package.json:
  - exports./types/v2-5 → dist/lib/types/v2-5/index
  - typesVersions entry for ./types/v2-5
  - generate-types:v2.5 + generate-types:all umbrella

ci.yml: validate-step now also runs generate-types:v2.5 and diffs the
v2-5 directory.

Test: dist artifacts present, declarations include all 13 tools'
request/response, package.json exports the path. 5555 lib tests pass /
7 pre-existing skipped / 0 fail.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
},
};

async function compileSchema(name: string, schema: any): Promise<string> {
* multi-line union types (`export type Foo =\n | 'a'\n | 'b';`) that
* have no braces but span many lines.
*/
function dedupeExports(allCode: string): string {
The warn-only post-adapter v2.5 validation pass shipped in #1121 ran on
every v2-detected request but its drift entries had nowhere to go —
SingleAgentClient call sites passed no debugLogs array, so the warning
silently dropped on the floor. Adapter regressions could land in
production unnoticed until a v2 seller reported a wire-shape rejection.

Both executeAndHandle and executeTask now collect drift into a local
array, then merge into result.debug_logs after executor.executeTask
returns. Adopters reading result.debug_logs see post-adapter v2.5
warnings alongside the executor's own logs, so a malformed adapted
shape becomes a debuggable signal instead of an invisible bug.

No public API change — executor.validateAdaptedRequestAgainstV2 already
accepted an optional debugLogs parameter; only the call sites changed.

End-to-end test verifies sync_creatives (known-drift, #1116) emits a
warning entry for v2-detected agents, clean payloads emit nothing, and
v3-detected agents never trigger the v2.5 pass.

Closes the observability hole deferred in the v2.5 foundation PR.
Lays groundwork for the broader compatibility-matrix work that needs
reliable drift signal across version pairs.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
json-schema-to-typescript emits Foo, Foo1, Foo2 when the same enum or
type is referenced from multiple places. Reuse the existing
removeNumberedTypeDuplicates pass from generate-types.ts so v2.5 ships
a single canonical export per concept.

32 numbered duplicates collapse — FormatID11 and friends are gone, and
the generated bundle drops ~570 lines of redundant declarations.

Two distinct degenerate fillers (UpdateMediaBuyRequest1 +
ProvidePerformanceFeedbackRequest1) survive because their bodies are
genuinely different from the canonical name; the dedupe pass correctly
preserves them rather than silently merging incompatible types.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit 73fd41c into main May 1, 2026
10 checks passed
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