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

@s2-dev/mastra-pubsub

v0.1.1

Published

Durable Mastra PubSub backed by S2 streams for Durable Agents

Readme

@s2-dev/mastra-pubsub

Durable Mastra PubSub backed by S2 for Durable Agents.

Each topic maps to one S2 stream. The sequence number S2 assigns to every append becomes the event's index. That index is the same when the event is delivered live and when it is replayed, so Mastra's built-in replay and dedup work without any changes, so streams can work nicely across restarts and can be resumed from any offset.

Demo

Based on Mastra's own durable-agents example with S2 as the stream backend, adapted in examples/durable-agents.

A durable agent handling a browser refresh

Install

npm install @s2-dev/mastra-pubsub @mastra/core @s2-dev/streamstore

@mastra/core is a peer dependency. @s2-dev/streamstore is a direct dependency.

Setup

Create an S2 access token and a basin with create-stream-on-append and create-stream-on-read enabled in the dashboard

import { S2PubSub } from "@s2-dev/mastra-pubsub";

const pubsub = new S2PubSub({
  accessToken: process.env.S2_ACCESS_TOKEN!,
  basin: process.env.S2_BASIN!,
});

Pass it to Mastra wherever a PubSub is accepted.

Configuration

S2PubSubConfig:

| Field | Description | | --- | --- | | client | An existing S2 client. Takes precedence over accessToken. | | accessToken | S2 access token, used to build a client when client is omitted. | | basin | Basin for the durable streams. Enable create-stream-on-append and create-stream-on-read. | | endpoints | Optional endpoint overrides, for example for s2-lite. |

S2PubSubOptions:

| Field | Description | | --- | --- | | inner | Live-delivery transport. Defaults to in-process EventEmitterPubSub. | | streamPrefix | S2 stream-name prefix. Defaults to mastra/durable/. | | topicPrefix | Only topics with this prefix are persisted. Defaults to agent.stream.. | | logger | Optional logger for persistence failures. Falls back to console. |

How it works

  • publish appends the event to its topic's S2 stream, uses the assigned seqNum as the event index, then delivers it live. Topics outside topicPrefix are delivered live only.
  • getHistory replays a topic from an offset by reading the stream. index equals seqNum for every event.
  • clearTopic deletes the stream. With create-on-read enabled, a later read recreates it empty, so replay returns no history.

Testing

The integration test needs an S2 access token:

S2_ACCESS_TOKEN=... npm test

To run against a local s2-lite, set S2_ACCOUNT_ENDPOINT and S2_BASIN_ENDPOINT.

License

MIT