Skip to content

Add streaming SSE client for session channels - #25

Merged
mehmetkr merged 1 commit into
mainfrom
item-18-streaming-client
Dec 1, 2026
Merged

mehmetkr merged 1 commit into
mainfrom
item-18-streaming-client

Conversation

@mehmetkr

@mehmetkr mehmetkr commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds inline SSE parser (_streaming.py): SSEDecoder, ServerSentEvent, Stream[T], AsyncStream[T] implementing the W3C EventSource parsing algorithm
  • Adds channel client (_channels.py): ChannelClient and AsyncChannelClient for session .in/.out endpoints at /realtime/v1/sessions/
  • Adds three new exceptions: StreamingError, SessionClosedError (409), SessionExpiredError (400)
  • Adds DEFAULT_MAX_STREAM_RECONNECTS = 5 for long-lived stream reconnection
  • Exports new exceptions from top-level __init__.py
  • 56 tests (31 streaming + 25 channel), 248 total passing

Design decisions

Per ADR-004: inline SSE parser (no httpx-sse dependency), matching anthropic-sdk-python and openai-python pattern. Last-Event-ID resume support. W3C spec compliant including null-character id rejection.

Test plan

  • SSE parser: simple events, multi-line data, comments, BOM, retry, id persistence, event type reset, null-id rejection
  • Stream/AsyncStream: iteration, context manager, close, last_event_id
  • ChannelClient: send, read (SSE), drain, auth headers, error mapping (409/400/500)
  • AsyncChannelClient: send, read, drain, error mapping, response cleanup on error
  • Exception hierarchy: StreamingError, SessionClosedError, SessionExpiredError
  • All 248 tests passing, ruff/pyright/mypy clean

@mehmetkr
mehmetkr merged commit 7ee59be into main Dec 1, 2026
7 checks passed
@mehmetkr
mehmetkr deleted the item-18-streaming-client branch December 1, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant