SSE Streaming Responses
Antigravity Manager converts Gemini’s streaming responses into OpenAI and Claude SSE (Server-Sent Events) formats, enabling real-time token-by-token output.Architecture
OpenAI SSE Format
Location:src-tauri/src/proxy/mappers/openai/streaming.rs
Event Sequence
- Initial chunk with role:
- Content chunks as they arrive:
- Reasoning chunks (for thinking models):
- Tool call chunks:
- Final chunk with usage:
Streaming State Machine
The mapper maintains state across chunks:Heartbeat Mechanism
To prevent connection timeouts, heartbeat pings are sent every 15 seconds:: prefix) that clients ignore but keeps the connection alive.
Buffer Management
Incoming bytes are buffered and processed line-by-line:Claude SSE Format
Location:src-tauri/src/proxy/mappers/claude/streaming.rs
Claude’s streaming format is more complex with explicit content block lifecycle:
Event Types
1. message_startThinking Block Streaming
Thinking content gets separate blocks:Tool Use Streaming
Tool calls are streamed differently than OpenAI: Block start with empty input:State Machine
Signature Management
Signatures are buffered and emitted at block end:Web Search Grounding
Search results are appended as markdown text blocks:Error Handling in Streams
When errors occur mid-stream: OpenAI:MCP XML Bridge
For MCP tool calls, XML syntax is supported:Parameter Remapping
Gemini often uses different parameter names:Fuzzy Tool Matching
For MCP tools, names are fuzzy-matched:- Exact suffix match (
puppeteer_navigate→mcp__puppeteer__puppeteer_navigate) - Substring containment
- Token overlap scoring
Performance Optimizations
Zero-Copy Parsing
SSE lines are parsed without allocations:Async Buffering
Chunks are yielded asynchronously:Early Termination
On error, stream stops immediately:Testing
Stream processing is tested with:See Also
- Request Mapping - Initial transformation
- Response Mapping - Final conversion
- Error Handling - Stream error recovery