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

@arnilo/prism-session-store-nats

v0.1.5

Published

Optional NATS JetStream AgentEventSource adapter for Prism.

Readme

@arnilo/prism-session-store-nats

Optional NATS JetStream AgentEventSource adapter for Prism (FR-5). Durable consumer, per-subject replay, and at-least-once delivery with stable event IDs over the official @nats-io/transport-node + @nats-io/jetstream clients.

Install

npm install @arnilo/prism-session-store-nats @arnilo/prism @nats-io/transport-node

Usage

import { connect } from "@nats-io/transport-node";
import { createNatsAgentEventSource, createNatsJetStream } from "@arnilo/prism-session-store-nats";

const nc = await connect({ servers: process.env.NATS_URL });
const source = createNatsAgentEventSource({
  connection: await createNatsJetStream(nc),
  stream: "prism_agent_events",
  cursorSecret: process.env.EVENT_CURSOR_SECRET, // reuse across replicas for resumable cursors
});

await source.append({ id: "e1", sessionId, runId, type: "message_delta", timestamp, event, redacted: true, tenantId, ... });
const page = await source.page({ ownership, sessionId, runId, limit: 100 });
for await (const envelope of source.subscribe({ ownership, sessionId, runId })) {
  // at-least-once: dedupe by envelope.record.id
}
await source.close();

Stream provisioning

The host creates the JetStream stream before first use. Required shape:

  • Subjects: prism.agent-events.> (one subject per run: prism.agent-events.<tenant>.<session>.<run>)
  • Retention: limits (e.g. max_age for retention, max_msgs_per_subject per run) — the adapter never auto-purges beyond cleanup()
  • Dedupe window: duplicate_window (default 2 min) — append is idempotent by record.id within this window; a same-id different-content append fails closed

Semantics

  • append allocates the JetStream per-subject sequence as the per-run event sequence; idempotent by record.id within the stream dedupe window.
  • page replays a run's subject from an HMAC-signed cursor (ephemeral consumer, auto-ack).
  • subscribe uses a durable pull consumer with explicit acks: replay from the cursor (or the beginning), then live; unacked messages redeliver after 30s (at-least-once); consumers dedupe by record.id; the iterator ends after a terminal event.
  • cleanup enumerates the tenant's subjects and deletes messages older than before (ownership-scoped, bounded by limit).
  • Ownership scoping matches the Postgres source: tenant in the subject, account/user enforced at read time.
  • Inert on import: no NATS connection until createNatsAgentEventSource is called.

PostgreSQL LISTEN/NOTIFY remains the reference durable implementation (FR-7); this package is a sibling adapter for JetStream backbones. See agent events.

Conformance

Network-free tests use an in-memory fake of the narrow JetStream surface (NatsJetStream); createNatsJetStream adapts the official client to it. Live integration requires a real NATS server with JetStream enabled.