feat(webhooks): public to_wire_dict() serialization seam#602
Merged
Conversation
Adopters wrapping create_a2a_webhook_payload (a2a-sdk 1.0+ protobuf Task / TaskStatusUpdateEvent) and create_mcp_webhook_payload (dict / McpWebhookPayload) had to write per-shape isinstance dispatch in every webhook send path. A future a2a-sdk that swaps protobuf for a Pydantic facade would silently change which branch runs. to_wire_dict centralizes that dispatch: - protobuf -> MessageToDict(preserving_proto_field_name=False), with the existing 1.0 -> 0.3 enum normalization (TASK_STATE_COMPLETED -> completed, ROLE_AGENT -> agent) so 0.3 buyer receivers keep parsing - Pydantic -> model_dump(mode="json", exclude_none=True) - Mapping -> dict() passthrough (legacy callers that hand-build the wire body) - anything else -> TypeError with a directional message Re-exports the seam from adcp.webhooks and the adcp package root. Internal _payload_to_dict (used by deliver()) is replaced with to_wire_dict; behaviour is unchanged for the supported types. Refs: #601 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 May 9, 2026
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.
Closes #601.
Summary
adcp.webhooks.to_wire_dict(payload)collapses the per-shapeisinstancedispatch every adopter was writing aroundcreate_a2a_webhook_payload/create_mcp_webhook_payload. Re-exported from theadcppackage root.Task/TaskStatusUpdateEvent→MessageToDict(preserving_proto_field_name=False)plus the existing 1.0→0.3 enum normalization (TASK_STATE_COMPLETED→completed,ROLE_AGENT→agent) so 0.3 buyer receivers keep parsing.model_dump(mode="json", exclude_none=True).Mapping→dict()passthrough; anything else →TypeErrorwith a directional message._payload_to_dict(the existingdeliver()helper) is folded intoto_wire_dict; behaviour for supported types is unchanged.The optional bonus from the issue — making
create_mcp_webhook_payloadreturnMcpWebhookPayload— is intentionally deferred. Withto_wire_dictin place, adopters that want the typed shape can callMcpWebhookPayload.model_validate(create_mcp_webhook_payload(...))today, and a follow-up can flip the return type behind a deprecation cycle without re-touching the seam.Test plan
pytest tests/test_webhooks_to_wire_dict.py— 6 new round-trip tests (A2ATask→ camelCaseid/contextId/artifactId, A2ATaskStatusUpdateEvent→ camelCasetaskId, MCP dict → snake_casetask_id/task_type, MCP Pydantic → snake_case +exclude_none, dict passthrough is a defensive copy, unsupported types raiseTypeError).pytest tests/test_webhooks_deliver.py tests/test_webhook_handling.py— 136 passed, no regressions from refactoring_payload_to_dictintoto_wire_dict.ruff check+mypy src/adcp/webhooks.pyclean.🤖 Generated with Claude Code