@stackline/sse v1.0.1
A resilient event stream moving through checkpoints and branching delivery paths

Server-Sent Events, end to end

@stackline/sse

Parse, encode, reconnect and serve real-time streams with one zero-dependency package.

npm install @stackline/sse

Runs locally in this page

Stream lab

The parser receives this stream in incremental chunks.

Parsed events

No request leaves this page. The playground executes the package browser build directly.

One coherent contract

The full SSE lifecycle

Complete reference
01

Consume

fetchSSE supports POST bodies, auth, abort, resume IDs, retry policy and three timeout phases.

02

Parse

createParser handles split UTF-8, CR, LF, CRLF, comments, retry fields and bounded buffers.

03

Encode

encodeSSE and encodeJSON prevent field injection and preserve multiline payloads.

04

Serve

eventStreamResponse and channels expose backpressure, heartbeats and correct HTTP headers.

AI streaming client Async iteration, cancellation included
import { fetchSSE } from '@stackline/sse';

for await (const event of fetchSSE('/api/generate', {
  method: 'POST',
  body: JSON.stringify({ prompt: 'Hello', stream: true }),
  idleTimeout: 45_000,
  retry: { retries: 3 }
})) {
  if (event.data === '[DONE]') break;
  render(JSON.parse(event.data));
}

Publish once, run broadly

Compatibility without baggage

0 runtime dependencies
BrowserESM + global bundleReady
Node.js14.17 through 24Ready
EdgeWorkers and Web StreamsReady
Deno / BunNative ESMReady
TypeScript3.9 through 7Ready

Bounded by default

Line length
1 MiB
Event size
1 MiB
Queued events
4,096
Feed slice
16 KiB

Oversized or malformed input fails with stable error codes instead of growing memory without a bound.

Start with one dependency

A smaller streaming stack.

ESM, CommonJS, browser bundle and declarations ship from the same tested artifact.