ChappieStreamingTransportPolicy.
How the default transport works
With the default policy, Chappie opens a WebSocket connection for each streaming request. If the connection drops mid-stream, Chappie attempts to reconnect up to 5 times. If all reconnection attempts fail, Chappie falls back to HTTP/SSE for the remainder of that session. When a reconnect succeeds and the server replays previously delivered text, Chappie suppresses the replayed prefix so your UI does not receive duplicate tokens. If the replayed content diverges from what was already delivered — meaning the server sends different text for an already-emitted prefix — Chappie stops the stream and throwsChappieClientError.streamingTransportReplayDiverged rather than corrupting your conversation output.
Available transport policies
ChappieStreamingTransportPolicy exposes two ready-made static values:
| Policy | prefersWebSocket | maxWebSocketReconnectionAttempts | fallsBackToHTTPSSE |
|---|---|---|---|
.default | true | 5 | true |
.httpSSEOnly | false | 0 | true |
Forcing HTTP/SSE-only transport
Pass.httpSSEOnly when you need deterministic, WebSocket-free transport:
ChappieConfiguration:
The default WebSocket transport typically delivers the first streaming token with lower latency than HTTP/SSE. Switch to
.httpSSEOnly only when WebSocket is unavailable or you need simpler transport semantics for testing.When to use .httpSSEOnly
Use HTTP/SSE-only transport in these situations:
- Environments with WebSocket restrictions — corporate networks, certain VPN configurations, or enterprise MDM policies that block WebSocket upgrades.
- Automated testing — HTTP/SSE removes WebSocket reconnection state from the equation, making test behaviour more predictable.
- Debugging transport issues — isolating whether a problem is WebSocket-specific by confirming the same request works over SSE.
Handling streamingTransportReplayDiverged
ChappieClientError.streamingTransportReplayDiverged means a WebSocket reconnect returned text that contradicts what your UI already displayed. The associated string value contains the partial text that was emitted before the divergence was detected.
When you catch this error, re-render the conversation from scratch or show the user an error prompt asking them to retry: