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

public-transit

v0.1.2

Published

A WebSocket relay that connects agent handlers (running in Node.js) with browser clients. Handlers register with the relay server and expose an async generator interface. Browser clients connect over WebSocket to invoke handlers, stream responses, and man

Readme

public-transit

A WebSocket relay that connects agent handlers (running in Node.js) with browser clients. Handlers register with the relay server and expose an async generator interface. Browser clients connect over WebSocket to invoke handlers, stream responses, and manage sessions with abort/undo/redo support.

This is useful when you need to bridge a long-running backend process (like an AI agent, build tool, or CLI) with a browser frontend over WebSocket, with built-in session management, reconnection, and multiplexing.

Install

npm install public-transit

How it works

┌─────────┐   WebSocket   ┌──────────────┐   WebSocket   ┌─────────┐
│ Browser  │ ◄───────────► │ Relay Server │ ◄───────────► │ Handler │
│ (client) │               │   (hub)      │               │ (agent) │
└─────────┘               └──────────────┘               └─────────┘
  1. A relay server runs on a known port (default 4722)
  2. Handlers connect and register themselves by ID (e.g. "my-agent")
  3. Browser clients connect and can invoke any registered handler
  4. Messages stream back from handler → relay → browser in real time

Usage

1. Start a relay with a handler (Node.js)

The simplest way — connectRelay auto-starts a relay server if one isn't already running, then registers your handler:

import { connectRelay } from "public-transit";

const connection = await connectRelay({
  handler: {
    agentId: "my-agent",
    run: async function* (prompt, options) {
      yield { type: "status", content: "Thinking..." };
      // do work...
      yield { type: "done", content: "Here's the result." };
    },
    abort: (sessionId) => {
      // cancel in-progress work
    },
  },
});

// later: connection.disconnect()

2. Connect from the browser

import { createRelayClient } from "public-transit/client";

const client = createRelayClient();
await client.connect();

// Listen for handler availability
client.onHandlersChange((handlers) => {
  console.log("Available handlers:", handlers);
});

// Send a request
client.sendAgentRequest("my-agent", {
  prompt: "Refactor this component",
  content: ["const App = () => <div>hello</div>"],
});

// Stream responses
client.onMessage((message) => {
  if (message.type === "agent-status") {
    console.log("Status:", message.content);
  } else if (message.type === "agent-done") {
    console.log("Done:", message.content);
  } else if (message.type === "agent-error") {
    console.error("Error:", message.content);
  }
});

3. Use the high-level agent provider (browser)

For a more ergonomic async-iterable interface:

import { createRelayClient, createRelayAgentProvider } from "public-transit/client";

const client = createRelayClient();
await client.connect();

const agent = createRelayAgentProvider({
  relayClient: client,
  agentId: "my-agent",
});

const controller = new AbortController();

for await (const chunk of agent.send(
  { prompt: "Fix the bug", content: ["..."] },
  controller.signal,
)) {
  console.log(chunk);
}

4. Standalone relay server (advanced)

If you want to run the relay server separately from handlers:

import { createRelayServer } from "public-transit/server";

const server = createRelayServer({ port: 4722, token: "secret" });
await server.start();

// Handlers and browsers connect over WebSocket
// Token is validated on connection

Exports

| Path | Platform | Description | | ----------------- | -------- | ---------------------------------------------- | | public-transit | Node.js | Everything (server + client + protocol) | | public-transit/server | Node.js | createRelayServer | | public-transit/client | Browser | createRelayClient, createRelayAgentProvider| | public-transit/protocol | Any | Shared types and constants |

Authentication

Pass a token option to the server and clients. The relay validates the token on both HTTP health checks and WebSocket connections:

// Server
createRelayServer({ token: "secret" });

// Handler
connectRelay({ handler, token: "secret" });

// Browser
createRelayClient({ token: "secret" });

License

MIT