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

@apnex/message-router

v0.1.2

Published

Sovereign Message-router (Layer 2) — kind/subkind dispatch + seen-id LRU dedup + hooks-pattern host-injection for the OIS Universal Adapter

Readme

@apnex/message-router

Sovereign Layer-2 Message dispatch + dedup for the OIS Universal Adapter.

Sovereign-package #6, sibling to @apnex/network-adapter (Layer 1), @apnex/cognitive-layer, @apnex/storage-provider, and @apnex/repo-event-bridge. Mission-56 W2.1 deliverable; design ratified at thread-332 (Design v1.2 §"Architectural commitments #4").

Architectural placement

[Layer 1 — @apnex/network-adapter (Universal Adapter)]
  src/wire/         — TCP/SSE wire FSM
  src/kernel/       — handshake / session FSM / agent identity
  src/tool-manager/ — Initialize/ListTools/CallTool MCP-boundary handler
                      ↓ emits the v1.0 notification contract
[Layer 2 — @apnex/message-router]    ← this package
  Per-kind dispatch; seen-id LRU dedup; hooks-pattern host-injection
                      ↓ invokes
[Layer 3 — Per-host shim (adapters/<host>-plugin)]
  Implements `notificationHooks`; renders to the host surface

The router is a pure routing core. It does not subscribe to a transport, render to a host surface, or implement claim/ack — those concerns live at Layers 1, 3, and Hub respectively. Layer 2's invariants are: (a) deliver the right Message to the right hook, (b) dedup duplicate Message ID delivery (push+poll race), (c) preserve the v1.0 notification contract additively.

Surface

Message envelope

The routable unit. Five v1.0 kinds:

| Kind | Hook called | Payload | |---|---|---| | notification.actionable | onActionableEvent | AgentEvent | | notification.informational | onInformationalEvent | AgentEvent | | state.change | onStateChange | SessionState, previous, optional SessionReconnectReason | | pending-action.dispatch | onPendingActionItem | DrainedPendingAction | | repo-event | onActionableEvent | AgentEvent (mission-52 bridge translator output) |

Subkind discrimination (e.g., event.event for pr-merged vs pr-review-approved) is forward-compat extension scope (W3+); v1.0 routing is kind-only.

MessageRouter

import { MessageRouter, type NotificationHooks } from "@apnex/message-router";

const hooks: NotificationHooks = {
  onActionableEvent: (event) => { /* wake the LLM */ },
  onInformationalEvent: (event) => { /* log / context inject */ },
  onStateChange: (state, previous, reason) => { /* diagnostic */ },
  onPendingActionItem: (item) => { /* backlog hint */ },
};

const router = new MessageRouter({ hooks });

router.route({ kind: "notification.actionable", event });

route(message) returns true if the message was dispatched to a hook, or false if it was deduped (LRU short-circuit) or the relevant hook is not implemented.

All four hooks are optional — omitting one silently disables that dispatch path, preserving the v1.0 notification contract semantics.

Seen-id LRU dedup

Bounded LRU keyed by Message ID (AgentEvent.id → string-coerced) for the three event kinds, and queue-item ID for pending-action.dispatch. State changes never dedup — they are FSM transitions, not Hub Messages, and have no stable wire identity.

Default capacity: 1000. Override via the OIS_ADAPTER_SEEN_ID_CACHE_N env var (read at construction time):

OIS_ADAPTER_SEEN_ID_CACHE_N=4096 node my-adapter.mjs

For tests / advanced wiring, supply an explicit capacity that wins over the env var:

new MessageRouter({ hooks, cacheOptions: { capacity: 16 } });

Or share a pre-constructed cache across routers:

import { SeenIdCache } from "@apnex/message-router";

const cache = new SeenIdCache({ capacity: 1024 });
const router = new MessageRouter({ hooks, seenIdCache: cache });

Anti-goals (binding)

  • Not a transport. Layer 1 (@apnex/network-adapter) owns wire + kernel. Layer 2 receives already-classified messages.
  • Not a renderer. Per-host render mechanisms (<channel> / promptAsync / future) live in Layer 3 shims. Layer 2 invokes the hook; the hook decides the render.
  • No claim/ack semantics. v1.1 (M-Push-Foundation W3) extends ack to two-step new → received → acked; v1.0 routing is forward-compatible.
  • No subkind routing in v1.0. Subkind dispatch (<channel> source-attribute taxonomy etc.) is a forward-compat extension that overlays additively on top of kind dispatch.
  • No npm-publish prep. Distribution-readiness (@apnex/*@apnex/*) is M-Adapter-Distribution Tier 2.

Cross-references

  • docs/specs/universal-adapter-notification-contract.md — v1.0 hook surface + payload shapes (load-bearing for this package)
  • docs/designs/m-push-foundation-design.md v1.2 §"Architectural commitments #4" — Layer-2 dedup invariant
  • packages/network-adapter/ — Layer 1 source; emits the contract this router consumes
  • packages/repo-event-bridge/ — sovereign-package precedent (layout, dist/-commit pattern)
  • methodology calibration #20 — committed dist/ for file:-ref packages (cross-package install order)

Provenance

  • Mission: mission-56 W2.1 (M-Push-Foundation)
  • Design: v1.2 (architect lily); ratified at thread-332 round-3
  • Engineer: greg / 2026-04-26
  • Review: architect-pool cross-approval per docs/methodology/multi-agent-pr-workflow.md calibration B