fix: add SSE parameter and content alias for v0.3 compat streaming#1091
fix: add SSE parameter and content alias for v0.3 compat streaming#1091Linux2010 wants to merge 1 commit into
Conversation
Fixes a2aproject#1089 - Response Stream Array-Wrapping Crash 1. Add ?alt=sse parameter to streaming endpoints in rest_transport.py: - /v1/message:stream?alt=sse - /v1/tasks/{id}:subscribe?alt=sse This forces Google A2A API to return SSE format instead of JSON array-wrapped streams that cause protobuf Parse errors. 2. Add AliasChoices for 'content' field in Message class (types.py): - Accepts both 'parts' (v1.0) and 'content' (v0.3) field names - Fixes ValidationError when parsing v0.3 wire format responses Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
🧪 Code Coverage (vs
|
There was a problem hiding this comment.
Code Review
This pull request updates the v0.3 compatibility layer by appending the ?alt=sse query parameter to streaming endpoints in rest_transport.py and adding support for the legacy content field as an alias for parts in the Message model. Corresponding unit tests were added to verify these changes. The reviewer suggested avoiding discarding the results of async list comprehensions in tests, recommending instead to store the events for assertions or consume the generator with a loop.
| req = SendMessageRequest( | ||
| message=Message(message_id='msg-1', role=Role.ROLE_USER) | ||
| ) | ||
| _ = [event async for event in transport.send_message_streaming(req)] |
There was a problem hiding this comment.
Using an asynchronous list comprehension solely to consume an async generator creates an unnecessary list in memory. Consider consuming the generator with a simple loop or storing the list of events to assert on them.
| _ = [event async for event in transport.send_message_streaming(req)] | |
| events = [event async for event in transport.send_message_streaming(req)] |
| # Test subscribe | ||
| captured_paths.clear() | ||
| sub_req = SubscribeToTaskRequest(id='task-123') | ||
| _ = [event async for event in transport.subscribe(sub_req)] |
There was a problem hiding this comment.
Using an asynchronous list comprehension solely to consume an async generator creates an unnecessary list in memory. Consider consuming the generator with a simple loop or storing the list of events to assert on them.
| _ = [event async for event in transport.subscribe(sub_req)] | |
| events = [event async for event in transport.subscribe(sub_req)] |
Summary
Fixes #1089 - Response Stream Array-Wrapping Crash (Transport Layer Mismatch)
Changes
Add
?alt=sseparameter to streaming endpoints (rest_transport.py):/v1/message:stream?alt=sse/v1/tasks/{id}:subscribe?alt=sseThis forces Google A2A API to return SSE format instead of JSON array-wrapped streams that cause
protobuf.json_format.ParseError.Add
AliasChoicesforcontentfield (types.py):Message.partsnow accepts both'parts'(v1.0) and'content'(v0.3) field namesValidationError: parts Field requiredwhen parsing v0.3 wire format responsesTest Plan
test_message_content_aliasto verify content/parts alias mappingtest_compat_rest_transport_stream_url_has_alt_sse_paramto verify SSE URL parameter🤖 Generated with Claude Code