AI Assistant Streaming Protocol & Budget Lifeline

AI Assistant Streaming Protocol & Budget Lifeline A sequence diagram generated by Archify. Submit question (e.g. 3Sum pointers) POST /api/chat (guide context + history) Evaluate sliding-window rate limit Quota approved (or synthetic 429) Allocate budget (52s wall guard) 15s tool reserve reserved Chat completion (stream: true) SSE heartbeat (: ping every 10s) Upstream chunks: data: {choices:[...]} Forward raw SSE byte-for-byte stableSplit() at last blank line paintReveal() stable prefix markdown Update live tail via raw textContent Stream termination data: [DONE] Close SSE channel cleanly renderMermaid() & KaTeX on settled DOM Handshake & Security Policy Streaming & Heartbeat Keepalive Stable Split Reveal & Settled Formatting Learner · Browser Session · Sequence participant Learner Browser Session Chat Widget · docs/chat-widget.js · Sequence participant Chat Widget docs/chat-widget.js API Route · api/chat.mjs (Vercel) · Sequence participant API Route api/chat.mjs (Vercel) Rate Limiter · Upstash Redis · Sequence participant Rate Limiter Upstash Redis Budget Guard · 15s Reserve Ceiling · Sequence participant Budget Guard 15s Reserve Ceiling OpenAI / LLM · GPT-4o Stream · Sequence participant OpenAI / LLM GPT-4o Stream Render Pipeline · Mermaid & KaTeX · Sequence participant Render Pipeline Mermaid & KaTeX Legend main request return security async trace message