Skip to content

Capabilities ​

@anvia/server has one public entry point and a deliberately small responsibility: encode an asynchronous event source and expose it through Fetch-compatible streaming primitives.

CapabilityAPIBehavior
Streaming responsecreateEventStreamWraps any AsyncIterable<T> in a JSONL or SSE Response
UI responsecreateUIStreamResponseSame transport behavior, typed for UIStreamEvent
JSONL encodercreateJsonlStreamEmits one serialized event plus newline per chunk
SSE encodercreateSseStreamEmits JSON data fields with optional event names and retry value
Resumable producercreateResumableStreamPersists numbered event records and yields resume envelopes
Resume consumerresumeStreamEventsReplays after a cursor and tails a running stream
Development storecreateMemoryResumableStreamStoreProcess-local resumable state for tests and local use
Store contractResumableStreamStoreApplication-defined durable/shared persistence boundary

What the package adds ​

Response helpers set transport defaults unless the application already supplied them:

  • Cache-Control: no-cache, no-transform
  • Connection: keep-alive
  • X-Accel-Buffering: no
  • JSONL or SSE Content-Type

Encoder failures become a final { type: 'error', error } event. Native Error values retain name and message but not their stack.

What it does not add ​

Server does not own model execution, cancellation policy, authorization, CORS, CSRF protection, compression, durable storage, reconnecting clients, or background-job lifecycle. A deployment can still buffer or terminate streams despite the response headers.

See the API reference for all option and envelope types.

Built for Anvia.