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

@reinsjs/agent

v0.9.0

Published

reins — hand the reins to the model. createAgent() + re-exports of @reinsjs/core, @reinsjs/server and @reinsjs/ui-agui

Downloads

3,836

Readme

@reinsjs/agent

Hand the reins to the model. @reinsjs/agent is the umbrella package: createAgent() plus everything from @reinsjs/core, @reinsjs/server and @reinsjs/ui-agui re-exported, so one install gives you an agent with a Web-standard handler and an AG-UI stream. Bring a lowering layer (@reinsjs/lowering-fetch, recommended, or @reinsjs/lowering-pi) and, optionally, the brain (@reinsjs/brain) and a store (@reinsjs/store-sqlite, @reinsjs/store-pg).

pnpm add @reinsjs/agent @reinsjs/lowering-fetch @reinsjs/brain
import { anthropic } from "@reinsjs/lowering-fetch" // or "@reinsjs/lowering-pi" — same call, see its README
import { approval, compact, perception } from "@reinsjs/brain"
import { createAgent, defineTool, memoryStore } from "@reinsjs/agent"

const deploy = defineTool<{ env: "staging" | "prod" }>({
  name: "deploy",
  description: "Ship the current build",
  inputSchema: { type: "object", properties: { env: { type: "string", enum: ["staging", "prod"] } }, required: ["env"] },
  needsApproval: true,
  execute: ({ env }) => `deployed to ${env}`,
})

export const agent = createAgent({
  model: anthropic("claude-opus-5", { apiKey: process.env.ANTHROPIC_API_KEY! }),
  tools: [deploy],
  store: memoryStore(),                 // sqliteStores(...) / pgStores(...) for anything real
  sockets: [perception(), compact(), approval()],
  systemPrompt: "Be brief and direct.",
  secret: process.env.REINS_SECRET,     // signs the pause state so it can round-trip through a client
})

export const POST = agent.handler        // (Request) => Promise<Response>, AG-UI over SSE

Without HTTP:

for await (const event of agent.run({ input: "Ship staging" })) console.log(event.type)

run() yields every event of this session as it is appended (a handoff's opening events are in the new session — read them from toSessionId) and returns done | paused | handoff | error. A paused result carries a small signed state; resume from any process with agent.run({ sessionId, resume: state, decisions: [{ toolCallId, approved: true, by: "alice" }] }).

Messages that reach your host while a run is going can be handed to the model before its next call: pass agent.run({ input, pullInput }) (see "Input that arrives mid-run" in @reinsjs/core). It is a per-run option — createAgent does not take it, and asTool sub-agents never pull. Over HTTP, handler: { midRunInput: true } queues a message that arrives while the session's run is active into that run instead of answering 409 (see "Messages during a run" in @reinsjs/server).

Agents as tools

import { asTool } from "@reinsjs/agent"

const lead = createAgent({
  model, store,
  tools: [
    asTool(analyst, { name: "ask_analyst", description: "Ask the inventory analyst. Give a self-contained question." }),
    asTool(writer,  { name: "ask_writer",  description: "Ask the copywriter for customer-facing copy.", abort: "detached" }),
  ],
  sockets: [approval(), budget({ limits: { totalTokens: 500_000 } })],
})

Whether to call an expert, what to ask, and whether to trust the answer are the parent model's decisions; there is no orchestrator. asTool handles what a hand-rolled wrapper gets wrong: when the child pauses for approval the parent pauses too (Interruption { kind: "subagent" } carries the child's interruptions), the host answers with decisions: [{ toolCallId, sessionId: childSessionId, approved, by }], and the child's tokens count against the parent's budget. With the default abort: "linked", stopping the parent (abort(new RunStop())) stops the child too and closes its pending calls; a later call to the same expert starts a fresh task instead of resuming the stopped one. examples/team in the repository is a complete three-role setup on Postgres.

What you get for free

  • An append-only timeline you can replay, fork and audit — the model reads what actually happened, in order.
  • A loop that is one plain async generator with no private state — long, because the edge cases are handled in the open, but readable and copyable — with pause/resume as a return value.
  • Brain modules that let the model tidy its own context, keep constraints, spill big results, remember, ask before dangerous actions, and stop at a budget — each optional, each measured before it became a default.
  • Fail-closed defaults: unknown events are rejected, forged approval decisions cannot enter through the input, sessions are 404 to anyone not explicitly authorized.
  • One run per session across processes when the store provides a RunLease (pgStores() does): createAgent installs leasedRunRegistry with its defaults (30 s lease, random owner). To tune ttlMs / owner, build it yourself and pass handler: { runs } — see "Multiple instances" in @reinsjs/server. If you call createAgent per request (tools assembled per session), build the registry once at process level and pass the same handler: { runs } every time; each call otherwise gets its own: stop requests and mid-run input do not reach a run started by another call, and a second request on a busy session answers 409 saying the run is "on another instance" — or, without a RunLease, starts a second run on the same session.

Documentation

The design documents are in Chinese under docs/ at the repository root: docs/系统全景图.md (overview), docs/archive/implementation-plans/2026-09-08-技术方案v1.0.md (spec), docs/archive/2026-10-30-决策日志DECISIONS-0.1至0.4.md (why). Package READMEs are in English.

MIT © 2026 NewRate Limited.