sse-stream
Overview
sse-stream is the TypeScript implementation of the streaming toolkit, built specifically for modern runtimes (Deno, Bun, Cloudflare Workers). It leverages the Web Streams API to provide a low-level TransformerStream that can be plugged directly into fetch responses. Unlike heavy wrappers, sse-stream focuses on spec-compliance (CRLF rules, BOM handling) and includes an incremental JSON parser for rendering structured output as it arrives from the model.
Architecture & Design
Built as a Web Streams API native implementation. It uses a functional approach to state accumulation and is verified by a 100+ test suite with ~95% statement coverage.
Technical Capabilities
- 01
Incremental JSON: Parse and render valid partial objects before the final chunk arrives—critical for tool-use UIs.
- 02
Web Streams Native: Direct pipeThrough(streamChat()) support for zero-copy efficiency and backpressure.
- 03
Spec Compatibility: Strict adherence to WHATWG SSE rules including line-splitting and multi-line data fields.
- 04
Isomorphic Design: Zero-dependency runtime (pure standard library) works in browsers, Edge, and Node.js.
- 05
Type-Safe Accumulators: Full TypeScript support for evolving schemas from OpenAI, Anthropic, and Gemini.