Server-Sent Events (SSE) power real-time updates for matchmaking, chat, and state synchronization.
SSE Connection
Clients connect to GET /sse/:sessionId and receive events:
| Event | Description |
|---|---|
match_found |
Matchmaking succeeded, includes groupId and treatment |
match_timeout |
Matchmaking timed out |
chat_message |
New message in chat group |
chat_message_delta |
Streaming agent response (partial text) |
chat_ended |
Chat terminated (via agent end_chat tool) |
state_updated |
User state changed server-side |
Matchmaking Flow
- Client joins pool via
POST /matchmaking/join - Server queues session, applies FIFO matching
- On match: broadcasts
match_foundto all group members, writeschat_group_idto state - On timeout: broadcasts
match_timeout, client navigates totimeoutTarget
Chat Flow
- Client loads history via
GET /chat/:groupId/history - Client subscribes to SSE for live updates
- Messages sent via
POST /chat/:groupId/message - Agent responses stream as
chat_message_deltaevents, finalize aschat_message
Agent Integration
When a chat message arrives:
1. Server loads agents attached to the current page's chat component
2. Each agent receives the full conversation history
3. Agent responses stream in real-time via SSE
4. Tool calls (e.g., end_chat) execute server-side and broadcast state updates