Real-time streaming specialist for AI applications — SSE for LLM token delivery, WebSocket for bidirectional chat, ReadableStream API, backpressure handling, and Azure Event Hubs/Kafka stream processing.
Ships in frootai-deploy-infra-skills. Installing the plugin adds it to Claude Code.
Real-time streaming specialist for AI applications. Designs SSE for LLM token delivery, WebSocket for bidirectional chat, ReadableStream API, backpressure handling, and event stream processing patterns.
text/event-stream, event typesTransformStream, pipe chains, TextDecoderStream, chunked processing| Mistake | Why Wrong | Correct Approach |
|---|---|---|
| Returns full LLM response as JSON | User waits 5-10s seeing nothing | SSE: first token in <500ms, progressive display |
| Uses WebSocket for unidirectional streaming | Over-complex — WebSocket needs heartbeat, reconnect logic | SSE: simpler, auto-reconnect built into EventSource browser API |
No Connection: keep-alive | Proxy/LB closes connection during long generation | Headers: Connection: keep-alive, Cache-Control: no-cache |
| Buffers entire stream before sending | Defeats streaming purpose, same as synchronous | flush() after each token/chunk — send immediately |
| No error recovery on stream break | Connection drops = lost response | Client-side: EventSource auto-reconnects, or manual retry with lastEventId |
app.post("/api/chat", async (req, res) => {
res.setHeader("Content-Type", "text/event-stream");
res.setHeader("Cache-Control", "no-cache");
res.setHeader("Connection", "keep-alive");
res.setHeader("X-Accel-Buffering", "no"); // Disable nginx buffering
const stream = await openai.chat.completions.create({
model: "gpt-4o", messages: req.body.messages,
stream: true, stream_options: { include_usage: true }
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) {
res.write(`data: ${JSON.stringify({ token: content })}\n\n`);
}
if (chunk.usage) {
res.write(`data: ${JSON.stringify({ done: true, usage: chunk.usage })}\n\n`);
}
}
res.end();
});
async function streamChat(message: string, onToken: (token: string) => void): Promise<void> {
const response = await fetch("/api/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ messages: [{ role: "user", content: message }] })
});
const reader = response.body!.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = decoder.decode(value, { stream: true });
for (const line of text.split("\n")) {
if (line.startsWith("data: ")) {
const data = JSON.parse(line.slice(6));
if (data.token) onToken(data.token);
if (data.done) return;
}
}
}
}
import { WebSocketServer } from "ws";
const wss = new WebSocketServer({ port: 8080 });
wss.on("connection", (ws) => {
ws.on("message", async (data) => {
const { messages } = JSON.parse(data.toString());
const stream = await openai.chat.completions.create({
model: "gpt-4o", messages, stream: true
});
for await (const chunk of stream) {
if (ws.readyState !== ws.OPEN) break; // Client disconnected
const content = chunk.choices[0]?.delta?.content;
if (content) ws.send(JSON.stringify({ type: "token", data: content }));
}
ws.send(JSON.stringify({ type: "done" }));
});
// Heartbeat
const interval = setInterval(() => ws.ping(), 30000);
ws.on("close", () => clearInterval(interval));
});
// Transform OpenAI stream to SSE format
function createSSEStream(openaiStream: AsyncIterable<any>): ReadableStream {
return new ReadableStream({
async start(controller) {
const encoder = new TextEncoder();
for await (const chunk of openaiStream) {
const content = chunk.choices[0]?.delta?.content;
if (content) {
controller.enqueue(encoder.encode(`data: ${JSON.stringify({ token: content })}\n\n`));
}
}
controller.enqueue(encoder.encode("data: [DONE]\n\n"));
controller.close();
}
});
}
| Feature | SSE | WebSocket |
|---|---|---|
| Direction | Server → Client only | Bidirectional |
| Auto-reconnect | Built-in (EventSource) | Manual implementation |
| Protocol | HTTP/1.1+ | WS protocol (upgrade) |
| Proxy/LB support | Full (standard HTTP) | Needs WS-aware proxy |
| Browser API | EventSource (simple) | WebSocket (more code) |
| Use for LLM streaming | ✅ Recommended | Only if bidirectional needed |
flush() per tokenEventSourceX-Accel-Buffering: noEventSource auto-reconnect or manual retryproxy_buffering off or X-Accel-Buffering: no| Scenario | Use This Agent | Don't Use |
|---|---|---|
| LLM token streaming | ✅ | |
| Real-time chat UI | ✅ | |
| Event stream processing (Event Hubs) | ❌ Use fai-azure-event-hubs-expert | |
| GraphQL subscriptions | ❌ Use fai-graphql-expert |
| Play | How This Agent Helps |
|---|---|
| 01 — Enterprise RAG | SSE streaming for chat responses |
| 04 — Call Center Voice AI | Real-time audio + text streaming |
What the agent file sets; muted values are Claude Code's defaults
real-time-streaming, sse, websocket, backpressure, event-streams, ai-pipelines
7-day visitors to each agent page
@agent-frootai-deploy-infra-skills:FAI Streaming Expertfrom frootai-deploy-infra-skills
npx claudepluginhub frootai/frootai --plugin frootai-deploy-infra-skills327 agents in this plugin
AGENTSAGENTS.md — FrootAI Standalone Agents (Auto-Generated Catalog)> **GENERATED FILE — DO NOT EDIT BY HAND.** Re-run `node scripts/generate-agents-md.js` to refresh.FAI A2A ExpertAgent-to-Agent (A2A) protocol specialist — Google's agent interop standard, AgentCard discovery, task lifecycle, streaming artifacts, push notifications, and multi-agent communication patterns.FAI Accessibility ExpertAccessibility specialist — WCAG 2.2 AA/AAA compliance, ARIA 1.2 patterns, screen reader optimization, keyboard navigation, focus management, and inclusive design for AI chatbots and dashboards.Other plugins' agents for the same job