Repository navigation
refactor(adapters): typed v3 → v2.5 registry + central dispatch - #1143
Merged
Merged
Conversation
Consolidates the v3 → v2.5 adapter dispatch into a per-tool registry pattern. Each tool that needs version translation now has its own `AdapterPair<V3Req, V25Req, V25Res, V3Res>` module under `src/lib/adapters/v3-to-v2-5/`. `SingleAgentClient.adaptRequestForServerVersion` and `normalizeResponseToV3` dispatch through `getV3ToV25Adapter(taskName)` instead of carrying tool-specific switch arms. Six pairs: get_products, create_media_buy, update_media_buy, sync_creatives, list_creative_formats, preview_creative. The pairs wrap the existing scattered helpers unchanged — wire-level behavior is identical and pinned by a regression suite that diffs registry output vs direct-helper output for every pair. The underlying logic stays in utils/*-adapter.ts files until each pair gets a focused per-tool refactor (e.g. #1116 for sync_creatives manifest flatten). Adding v2.6 / v3.1 in the future follows the same shape: a sibling v3-to-v2-6/ directory with its own per-tool modules, then a dispatch table keyed by (serverVersion, toolName). Today's single-pair surface is the smallest version of that pattern that lets v3 buyers talk to v2.5 sellers without breaking, plus the type endpoints from @adcp/sdk/types/v2-5 so adapter signatures are compile-time-checked. No public API change. utils/*-adapter.ts exports stay (downstream callers using them directly are unchanged). The registry is a centralized dispatch wrapper, not a migration of the helper code. 5488 lib tests pass / 7 pre-existing skipped / 0 fail. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Two review-driven refinements to the adapter registry: 1. Rename `src/lib/adapters/v3-to-v2-5/` → `src/lib/adapters/legacy/v2-5/`. Per ad-tech-product review: real ad-tech compat layers carry N=1 active legacy shim with a deprecation runway (OpenRTB, Prebid, GAM all behave this way). Encoding `<sdk-version>-to-<seller-version>/` commits the codebase to a matrix nobody will staff. `legacy/v2-5/` reflects "exceptional, time-boxed compat" — when the SDK pin moves from v3 to v4, this directory continues to hold the v2.5 shim and a sibling `legacy/v3/` joins for v3 sellers. getV3ToV25Adapter → getV25Adapter (sdk-version implicit) listV3ToV25AdapterTools → listV25AdapterTools 2. Drop `SingleAgentClient.ts` imports that became unused after the dispatch refactor (adaptCreateMediaBuyRequestForV2, adaptUpdateMediaBuyRequestForV2, normalizeMediaBuyResponse, adaptSyncCreativesRequestForV2, normalizeFormatsResponse, normalizePreviewCreativeResponse, normalizeGetProductsResponse, adaptGetProductsRequestForV2). Code-reviewer flagged as a noUnusedLocals failure waiting to happen. The helpers are still exported from utils/*-adapter.ts for downstream callers using them directly — only the dispatch-site imports go away. 5565 lib tests pass / 7 pre-existing skipped / 0 fail. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley
force-pushed
the
bokelley/v2.5-adapter-registry
branch
from
May 1, 2026 09:12
e7c9ae3 to
eefbacb
Compare
This was referenced May 1, 2026
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.
Stacked on #1134 (TypeScript codegen for v2.5). Will retarget to
mainafter #1134 merges.Consolidates the v3 → v2.5 adapter dispatch into a per-tool registry pattern. Each tool that needs version translation has its own
AdapterPair<V3Req, V25Req, V25Res, V3Res>module undersrc/lib/adapters/v3-to-v2-5/.SingleAgentClient.adaptRequestForServerVersionandnormalizeResponseToV3dispatch throughgetV3ToV25Adapter(taskName)instead of carrying tool-specific switch arms.Why
Per the user's "kludgey code" framing, the four request adapters and four response normalizers were scattered across three files (
pricing-adapter.ts,creative-adapter.ts,sync-creatives-adapter.ts) with two separate switch statements inSingleAgentClientdispatching to them. Adding v2.6 or v3.1 would mean editing all three files plus both switch arms.The registry collapses that to "drop a per-tool file with a typed
AdapterPair, register it once" — a clean (from, to, tool) triple that matches the compatibility-matrix mental model. The TypeScript types (#1134) make adapter signatures compile-time-checked:(req: V3.GetProductsRequest) => V25.GetProductsRequest.What's in this PR
SingleAgentClient.adaptRequestForServerVersion(lines 1216–1226) andnormalizeResponseToV3(lines 1307–1325) lose their switch statements; both now dispatch throughgetV3ToV25Adapter(taskType).What's NOT in this PR (deliberately)
utils/*-adapter.ts— same code, no rename. The registry is a wrapper layer for centralized dispatch, not a migration of the helper logic. Per-tool refactors land independently (e.g.#1116rewritesadaptSyncCreativesRequestForV2as a manifest flattener under the new pattern).adaptGetProductsRequestForV2etc. are still exported fromutils/*-adapter.ts. Downstream callers using them directly are unaffected.Test plan
test/lib/v3-to-v2-5-registry.test.js, 13 tests): every registered pair'sadaptRequestproduces the same output as the underlyingutils/*helper for the same input. Same fornormalizeResponse. Wire-level behavior is identical.listV3ToV25AdapterTools()returns all 6 tools.getV3ToV25Adapter('not_a_real_tool')returnsundefined.npm run test:lib— 5488 pass / 7 pre-existing skipped / 0 fail.Compat-matrix playbook (preview)
Adding v2.6 in the future:
npm run sync-schemas:v2.6→schemas/cache/v2.6/npm run generate-types:v2.6→src/lib/types/v2-6/tools.generated.tssrc/lib/adapters/v3-to-v2-6/mirroring this PR's shape(serverVersion, toolName)lookupadapter-v2-6-conformance.test.jsThe whole point of this refactor is making step 3 a copy-paste-and-rename of the v2-5 directory rather than a rewrite of three files plus two switch statements.
🤖 Generated with Claude Code