npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@animastor/web-generator-sse

v0.1.0

Published

SSE stream orchestration for Animastor generation progress. Manages the reconnect loop, epoch-guarded event routing, and error handling. The host owns the AbortController and SSE connection; this package consumes the stream and routes events through @anim

Readme

@animastor/web-generator-sse

SSE stream orchestration for Animastor generation progress — the reconnect loop with exponential backoff, epoch-guarded stale-session detection, and event routing through the @animastor/web-generator domain router.

Scope — Pure domain logic. This package contains no UI components, no signals, no JSX, and no SSE transport. The host owns the AbortController, the SSE connection, the epoch counter, and the host signals; this package consumes the stream as an async iterable and routes events. It imports only @animastor/web-generator and never touches host stores, api/client, or @preact/signals.

Install

npm install @animastor/web-generator-sse

Runtime dependency: @animastor/web-generator (^0.1.0).

Usage

import {
  runSseStream,
  handleProgressEvent,
  type SseStreamPort,
} from '@animastor/web-generator-sse';

// Host owns the actual SSE connection and AbortController
const streamPort: SseStreamPort = {
  start: (bookId) => api.startProgressStream(bookId), // AsyncIterable<SseEvent>
  stop: () => abortController.abort(),
};

await runSseStream(
  streamPort,
  () => epoch.value,                 // host bumps epoch on cancel/new generation
  progressEventSink,                 // host signal bridge
  progressTracking,                  // host-owned tracking state
  bookId.value,
  { initialDelayMs: 1000, maxDelayMs: 15000, maxExponent: 4 }, // optional
);

Reconnect triggers: normal stream close and stream error — both retry with exponential backoff (1s → 2s → 4s → 8s → 15s cap by default). Exit condition: epoch mismatch (host bumped epoch → cancel / new generation).

For manual event dispatch (testing or one-off routing):

handleProgressEvent(sink, tracking, rawData);

Public API

| Export | Kind | Purpose | |---|---|---| | runSseStream | function | Reconnect loop: iterate the host stream, route events, backoff-reconnect, exit on epoch mismatch | | handleProgressEvent | function | Route a single SSE payload through the domain router (convenience wrapper) | | SseStreamPort | interface | Host stream capabilities — start(bookId) → AsyncIterable<SseEvent>, stop() | | SseEvent | interface | Minimal SSE event shape — { data: string } | | SseStreamConfig | interface | Tuning: initialDelayMs, maxDelayMs, maxExponent | | ProgressEventSink / ProgressTrackingState | types | Re-exported from @animastor/web-generator |

Package boundary

  • Runtime dependency: @animastor/web-generator ONLY (for routeProgressEvent, ProgressEventSink, ProgressTrackingState).
  • Host stores, api/client, app/*, pages/*, @preact/signals, and other @animastor/* packages are forbidden inside the package (enforced by architecture guard tests).
  • The host owns the AbortController + SSE connection, the epoch counter, host signals, and ProgressTrackingState; the package owns the reconnect loop, epoch checking, and event routing.
  • @animastor/web-generator-sse → host = forbidden; host → @animastor/web-generator-sse = allowed through the public entry point only.

Place in the Animastor architecture

Part of the web-generator package family extracted from the generation-progress contour of the Animastor web frontend:

  • @animastor/web-generator — analysis state machine, progress rows, SSE event routing, timer
  • @animastor/web-generator-config — layer-config load/persist
  • @animastor/web-generator-vbook — VBook agent lifecycle orchestration
  • @animastor/web-generator-sse — SSE reconnect loop and epoch-guarded event routing (this package)

The host's startProgressStream arrives as the startStream lifecycle callback of @animastor/web-generator-vbook; the VBook lifecycle starts the stream, this package runs it.

Development

npm install
npm run typecheck   # tsc --noEmit
npm run test        # vitest (domain unit tests)
npm run build       # tsup → dist/ (ESM + d.ts + sourcemaps)

License

MIT