Repository navigation
feat(server): response builders for acquire_rights, sync_accounts, sync_governance, report_usage - #725
Merged
Conversation
…nc_governance, report_usage
…report_usage Review-driven follow-ups on PR #725: - acquireRightsResponse now accepts the full AcquireRightsResponse union (including AcquireRightsError). Error payloads pass through as structuredContent + a minimal 'Rights acquisition error' summary. - Same for syncAccountsResponse — accepts SyncAccountsResponse union, error variant passes through. - syncGovernanceResponse already took the full union; no change. - reportUsageResponse drops the accepted: 0 default; throws with an actionable pointer at reportUsageResponse.fromRequest(request) when the handler forgets to set accepted (consistent with the throw-on-missing-required-field stance in the rest of the PR). - acquireRightsResponse now validates revocation_webhook.authentication credentials too, not just approval_webhook. Extracted assertWebhookCredentials helper so future webhook fields get the same ≥32-char check. - Documented .fromRequest shortcut with an @example and explicit 'sets accepted = request.usage?.length ?? 0' jsdoc.
…ication-config spec
…report_usage ack Applies DX-expert feedback on PR #725: 1. Brand-rights skill example credential (line 419) was 31 chars and would trip the builder's own >=32 check. Swap to randomUUID().replace(/-/g,'') (32 hex) and annotate the spec constraint inline. 2. Remove dead revocation_webhook check on acquireRightsResponse — the field is on the request, not the response, and the 'as unknown' cast made that obvious on second read. 3. Per-variant constructors: acquireRightsAcquired, acquireRightsPendingApproval, acquireRightsRejected. Coding agents that type 'acquireRightsAcqu…' get the right variant's required fields directly without reading the 4-variant union. Delegates to acquireRightsResponse so runtime checks still fire. 4. reportUsageResponse.fromRequest renamed to .acceptAll and reshaped to take opts.errors so the shortcut can't silently lie about ingest failures. The 'ack everything from request' case is one call; the 'ack all minus errors' case is one call with an argument; the old fromRequest signature had no way to express honest failures. 5. report_usage error message now names the '@adcp/client/server' import.
Test-agent-team review called out the architecture issue: builders were
doing the schema validator's job (credential length, schemes count,
account_id presence, accepted requiredness, format_id shape). Those are
JSON Schema constraints that belong in wire-level Zod validation
(already available as createAdcpServer({ validation: responses: strict }),
not default yet). Putting them in builders:
1. Only fires for tools whose handlers reach the wrapper.
2. Misses manual-registration paths (server.registerTool).
3. Teaches the next contributor to add a sixth runtime guard instead
of fixing the generator + validator.
Builders now do one job: wrap the domain object in { content,
structuredContent }. Schema enforcement lives one layer up. Per-variant
constructors (acquireRightsAcquired, etc.) stay — they tighten the
type surface, not the runtime.
Follow-ups tracked separately:
- Default validation.responses to warn/strict in dev mode.
- Tighten generated TS discriminated unions so sparse shapes fail tsc.
2 of 3 tasks
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.
Shifts from patching skill examples to fixing the drift class once in the SDK — first step of the 'SDK utilities over hand-rolled skill examples' plan prompted by matrix-v5 findings.
New builders
acquireRightsResponse(data)— typed on theacquired | pending_approval | rejecteddiscriminated union. Runtime-validatesapproval_webhook.authentication.credentialslength (spec: ≥32 chars) with an actionable error message.syncAccountsResponse(data)— asserts everyaccounts[i].account_idis present. Thesync_accountsstoryboard step requires platform-assigned IDs; fresh agents commonly echo request fields without stamping one.syncGovernanceResponse(data)— typed passthrough.reportUsageResponse(data)+reportUsageResponse.fromRequest(request)— auto-defaultsaccepted: 0; the.fromRequest(...)shortcut acknowledges everyusage[]entry as accepted.buildCreativeResponsenow validatescreative_manifest.format_idis{ agent_url, id }(not bare string or undefined). Previously failed downstream with a crypticoneOferror.All four are auto-applied via
createAdcpServer'sTOOL_METAso handlers return domain objects and the framework wraps. Also exported from@adcp/clientand@adcp/client/serverfor manual use.Why
Matrix v5 had four distinct
SERVICE_UNAVAILABLE: Tool X encountered internal errorsignatures — fresh-built agents calling tools that returned objects missing required fields the schema now mandates. Rather than teach every skill reader to hand-roll correct shapes, encode the shape in the SDK once; correct code is the compile-time / first-call-time easy path.Test plan
tsc --noEmitcleannpm run build:libcleannpm run compliance:skill-matrixafter merge — expect the 4 SERVICE_UNAVAILABLE failures to shift to either pass or different signature🤖 Generated with Claude Code