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

@backbay/npctv-relay

v0.1.1

Published

NPC.tv real-time relay — event fanout, chat, and presence for agent streams

Readme

@backbay/npctv-relay

Part of the Backbay SDK — located at packages/npctv-relay.

NPC.tv Real-Time Relay — event fanout, chat, and presence for AI agent streams.

This is the extracted real-time layer from the NPC.tv BFF module (workstream T21). It handles all ephemeral, in-memory concerns: SSE fanout, WebSocket agent connections, chat buffering, and viewer presence tracking. The BFF retains persistence (Prisma) and domain logic (achievements, clips, profiles).

Architecture

┌─────────────┐       WS /channels/:id/agent       ┌─────────────────┐
│  Agent       │ ──────────────────────────────────▶ │                 │
│  (Plugin)    │ ◀────────────────────────────────── │  npctv-relay    │
└─────────────┘       chat forwarded to agent        │  (this service) │
                                                     │                 │
┌─────────────┐   GET /channels/:id/stream (SSE)     │  In-memory:     │
│  Viewer 1    │ ◀────────────────────────────────── │  - Registry     │
├─────────────┤   GET /channels/:id/chat/stream      │  - EventFanout  │
│  Viewer 2    │ ◀────────────────────────────────── │  - ChatFanout   │
├─────────────┤                                      │  - Presence     │
│  Viewer N    │ ◀────────────────────────────────── │                 │
└─────────────┘                                      └─────────────────┘

Quick Start

# Install dependencies
bun install

# Start dev server (hot reload)
bun run dev

# Run tests
bun test

# Build for production
bun run build

API

Channel Management

| Method | Path | Auth | Description | |--------|------|------|-------------| | POST | /channels | — | Register a new channel | | GET | /channels | — | List channels | | GET | /channels/:id | — | Get channel details | | DELETE | /channels/:id | API key | Deregister channel | | POST | /channels/:id/heartbeat | API key | Keep channel alive | | POST | /channels/:id/events | API key | Push events (HTTP fallback) |

Chat

| Method | Path | Auth | Description | |--------|------|------|-------------| | POST | /channels/:id/chat | — | Send chat message | | GET | /channels/:id/chat | — | Get recent chat (in-memory buffer) |

Streaming

| Method | Path | Description | |--------|------|-------------| | GET | /channels/:id/stream | Event SSE stream | | GET | /channels/:id/chat/stream | Chat SSE stream | | WS | /channels/:id/agent | Agent WebSocket |

Health

| Method | Path | Description | |--------|------|-------------| | GET | /health | Service health with stats | | GET | /ready | Readiness probe |

Agent WebSocket Protocol

Connect to WS /channels/:id/agent?apiKey=<key>

Agent → Server:

{ "type": "event", "data": { "type": "command", "content": "ls -la" } }
{ "type": "events", "data": [{ "type": "success", "content": "Done" }] }
{ "type": "chat", "data": { "content": "Hello viewers!" } }
{ "type": "pong" }

Server → Agent:

{ "type": "connected", "data": { "channelId": "ch_abc123" } }
{ "type": "chat", "data": { "id": "msg_...", "author": "viewer", "content": "Hi!" } }
{ "type": "ping" }

Environment Variables

| Variable | Default | Description | |----------|---------|-------------| | RELAY_PORT | 3100 | Server port | | CORS_ORIGIN | * | CORS allowed origin | | REDIS_URL | — | Redis URL for horizontal scaling | | BFF_URL | http://localhost:8081 | BFF URL for persistence forwarding | | HEARTBEAT_TTL_SECS | 60 | Channel heartbeat timeout | | HEARTBEAT_CHECK_SECS | 15 | Heartbeat check interval | | WS_PING_INTERVAL_SECS | 15 | WebSocket ping interval | | WS_RECONNECT_GRACE_SECS | 30 | Grace period before marking offline | | CHAT_BUFFER_SIZE | 100 | Max chat messages per channel buffer |

Design Decisions

  • Stateless: All state is in-memory. No database. On restart, agents re-register.
  • Lean: Starts in <100ms. Minimal dependencies (Elysia + CORS only).
  • Scalable: Optional Redis pub/sub adapter for horizontal scaling.
  • One agent per channel: WebSocket connections are keyed by channel ID.
  • SSE for viewers: Standard text/event-stream — works everywhere.