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

@theokit/gateway-matrix

v0.1.0

Published

Matrix protocol platform adapter for @theokit/gateway. ADRs D413-D421.

Downloads

103

Readme

@theokit/gateway-matrix

Matrix protocol platform adapter for @theokit/gateway.

Decentralized federation. Works with matrix.org, element.io, self-hosted Synapse/Dendrite, etc. Bot in @bot:matrix.org can receive from @alice:element.io via federation built-in.

Install

pnpm add @theokit/sdk @theokit/gateway @theokit/gateway-matrix
pnpm add matrix-js-sdk  # ~2MB peer-dep

Quick start

import { Agent } from "@theokit/sdk";
import { GatewayRunner } from "@theokit/gateway";
import { MatrixAdapter } from "@theokit/gateway-matrix";

const adapter = new MatrixAdapter({
  homeserverUrl: "https://matrix.org",
  accessToken: process.env.MATRIX_ACCESS_TOKEN!,
  userId: "@theo-bot:matrix.org",
});

const runner = new GatewayRunner({
  adapters: [adapter],
  handler: async (event, ctx) => {
    if (event.platform !== "matrix") return;
    await ctx.reply(`Echo: ${event.text}`);
  },
});

await runner.start();

Access token

Element web UI is the easiest path:

  1. Sign in as the bot account.
  2. Settings → Help & About → Advanced.
  3. Click "Access Token" → reveal + copy.
  4. Save as MATRIX_ACCESS_TOKEN in .env.

Keep this token secret — it grants full account access.

DM detection (D416)

Matrix has no native "DM" concept — DMs are simply rooms with 2 members. The adapter applies the canonical heuristic:

room.getJoinedMemberCount() === 2 → channel.type: "dm"
≥3 members                       → channel.type: "group"

Edge case: a user who creates a 2-person room intended as a small group will still be detected as a DM. Use event.matrix.roomId + Matrix's m.direct account-data to override if you need precision.

Initial sync flood guard (EC-3 absorbed)

On startup, matrix-js-sdk delivers the most recent ~10 events per room. A bot in 50 rooms = 500 events fired in seconds → 500 LLM calls = cost explosion. The adapter filters events older than 60s (event.getTs() < Date.now() - 60_000) so initial sync only delivers genuinely live messages. To replay history programmatically, use the raw MatrixClient via adapter.getClient().

Alias resolution (D419)

// All three accepted (caller's choice):
await ctx.reply("hi");                       // event.channel.id = room id from inbound
await adapter.sendMessage({
  channel: { id: "#general:matrix.org", type: "group" },  // alias resolved
  text: "...",
});
await adapter.sendMessage({
  channel: { id: "!abc123:matrix.org", type: "group" },   // room id direct
  text: "...",
});

Aliases are resolved + cached on first use. If the admin renames an alias mid-process, sends to the cached value fail (rare — restart resolves).

What's NOT supported in v0.1

| Feature | Status | Workaround | |---|---|---| | E2EE rooms | Refused with warn stderr (D418) | Use unencrypted rooms; E2EE in v0.2 | | Threads (MSC4140) | Deferred to v0.2 (D417) | All replies land at room root | | Reactions / redactions | Inbound preserved via event.matrix.raw | Outbound: adapter.getClient().sendEvent(...) | | Media (image/file/audio) | Inbound delivered with empty text | Read event.matrix.raw.getContent() for the file URL | | Sync token persistence | Process-local | Restart re-syncs (mitigated by 60s freshness filter) |

Federation transparency (D420)

The adapter doesn't handle federation — Matrix protocol does. Your bot in @theo-bot:matrix.org can be added to rooms by users on any homeserver and the conversation flows transparently. Outbound performance varies with remote homeserver latency; failure modes (e.g. remote unreachable) surface as SendResult{send_failed}.

ADRs

D413 – D421 in .claude/knowledge-base/adrs/.