feat(sdk): address 5.15.0 DX feedback on handler types, error shape, extraction#874
Merged
Conversation
…extraction
Five user-reported DX issues on @adcp/client 5.15.0:
- Root re-exports for every *Response union's Success / Error / Submitted arms
(SyncCreativesSuccess, SyncAudiencesSuccess, etc.), so handlers no longer need
`as any` when narrowing.
- Dual-export createIdempotencyStore / memoryBackend / pgBackend (and related
types) from the root, matching createAdcpServer's treatment.
- Widened DomainHandler to accept Success | full Response union | McpToolResponse.
Dispatcher narrows Submitted (status: 'submitted' + task_id) and Error arms
({errors, context, ext, success, conflicting_standards_id}) at runtime so
the response builder only applies Success-shape defaults (revision,
confirmed_at, ...) to actual Success payloads. Adapter patterns returning
`Result<CreateMediaBuyResponse, ...>` type-check without casts.
- extractResult<T>(result) helper — prefers structuredContent, falls back to
JSON-parsing content[0].text, returns undefined. Lightweight companion to
unwrapProtocolResponse (which throws and schema-validates).
- VALIDATION_ERROR.issues now surfaced at the top level of adcp_error so
operators see JSON Pointers on first render. Same list mirrored at
details.issues for spec-convention compatibility — existing readers
continue to work, no migration required. Request-side schemaPath gating
now threads exposeSchemaPath the same way response-side does (previously
stripped even in dev).
Also: lightweight spec-shape warning on handler-returned Error arms whose
errors[] items are missing `code` or `message`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 24, 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.
Summary
Addresses five user-reported DX issues on @adcp/client 5.15.0 (full feedback here). All changes additive on the wire; no breaking migrations required.
*Responseunion (SyncCreativesSuccess,SyncAudiencesSuccess,CreateMediaBuySuccess,BuildCreativeSuccess,BuildCreativeMultiSuccess,ActivateSignalSuccess,SyncAccountsSuccess,SyncGovernanceSuccess,UpdateContentStandardsSuccess,ProvidePerformanceFeedbackSuccess,SyncEventSourcesSuccess,LogEventSuccess, etc., plus Error and Submitted variants) —AdcpServerhandler returns no longer needas any.createIdempotencyStore,memoryBackend,pgBackend, plus types) from@adcp/clientroot, matchingcreateAdcpServer.DomainHandlerreturn type to acceptPromise<Success | FullResponseUnion | McpToolResponse>. The dispatcher narrows Submitted (status: 'submitted' && task_id) and Error arms ({errors, context, ext, success, conflicting_standards_id}) at runtime so success-arm response builders only run on actual Success payloads. Adapter patterns returningResult<CreateMediaBuyResponse, ...>type-check without casts.extractResult<T>(result)helper — prefersstructuredContent, falls back to JSON-parsingcontent[0].text, returnsundefined. Lightweight companion tounwrapProtocolResponse(which throws and schema-validates).VALIDATION_ERROR.issuessurfaced at top level ofadcp_errorso operators see JSON Pointers immediately. Same list mirrored atdetails.issuesfor spec-convention compatibility. Request-sideschemaPathgating now threadsexposeSchemaPaththe same way response-side does.Also: lightweight dev-log warning on handler-returned Error arms whose
errors[]items violate the spec (missingcode/message).Changes
src/lib/index.ts— root re-exports (types + idempotency helpers)src/lib/server/create-adcp-server.ts—AdcpToolMapgainsresponsefield;DomainHandlerwidened; newisSubmittedEnvelope/isErrorArm/wrapSubmittedEnvelope/wrapErrorArm; aligned schemaPath gatingsrc/lib/server/errors.ts—AdcpErrorOptions/AdcpErrorPayloadgain top-levelissuessrc/lib/validation/schema-errors.ts— emitsissuesat both top-level anddetails.issuessrc/lib/utils/extract-result.ts— new helperdocs/guides/BUILD-AN-AGENT.md— response-union narrowing, extractor asymmetry, Error-arm vsadcpErrorguidancedocs/migration-4.x-to-5.x.md— refresh the threedetails.issuescalloutsReview
Addressed feedback from code-reviewer, security-reviewer, ad-tech-protocol-expert, dx-expert, and nodejs-testing-expert. Key decisions:
adcpError('CODE', ...). Documented side-by-side in BUILD-AN-AGENT.issues(which would have broken buyers readingdetails.issues), added a top-level copy AND kept thedetails.issuesmirror. Additive, not breaking.Test plan
tsc --noEmitcleannpm run buildcleancontext/extsiblings, emptyerrors[], unknown-key fallthrough,adcpError()on non-VALIDATION_ERROR code not emittingissues, and dual-locationissueson the wire🤖 Generated with Claude Code