Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/a2a/client/transports/http_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ async def parse_sse_stream(
elif key == 'data':
payload_chunks.append(val)

if payload_chunks:
yield event_name, '\n'.join(payload_chunks)


async def send_http_stream_request(
httpx_client: httpx.AsyncClient,
Expand Down
12 changes: 12 additions & 0 deletions tests/client/transports/test_http_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ async def mock_aiter_lines():
]


@pytest.mark.asyncio
async def test_parse_sse_stream_flushes_last_event_without_blank_line():
async def mock_aiter_lines():
yield 'data: {"task":{"id":"t1"}}\n'

response = httpx.Response(200)
response.aiter_lines = mock_aiter_lines # type: ignore

events = [e async for e in parse_sse_stream(response)]
assert events == [('message', '{"task":{"id":"t1"}}')]


@pytest.mark.asyncio
async def test_send_http_stream_request_non_sse(mocker):
client = httpx.AsyncClient()
Expand Down
Loading