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

@heywinit/chat-middleware

v0.1.0

Published

Middleware layer for the Vercel Chat SDK — global error handling and per-event context enrichment

Readme

@heywinit/chat-middleware

Middleware layer for the Vercel Chat SDK. Add global error handling, authentication, and context enrichment to your bot with a simple, familiar middleware pattern.

Features

  • Global Interceptors: Run logic before every event handler (mention, message, action, etc.).
  • Context Enrichment: Inject data into a shared context object accessible by all downstream handlers.
  • Global Error Handling: Catch and handle errors across all bot interactions in one place.
  • Ordered Execution: Middleware functions execute in the order they are registered.
  • Async Support: Full support for async/await in the middleware chain.

Installation

pnpm add @heywinit/chat-middleware

Basic Usage

import { applyMiddleware } from '@heywinit/chat-middleware';

applyMiddleware(bot, {
  beforeEach: [
    // Logger & Context Enrichment
    async (ctx, next) => {
      ctx.data.startTime = Date.now();
      console.log(`[${ctx.type}] Processing event...`);
      await next();
      const duration = Date.now() - ctx.data.startTime;
      console.log(`[${ctx.type}] Handled in ${duration}ms`);
    },
    // Simple Auth
    async (ctx, next) => {
      if (ctx.type === 'action' && !ctx.event.user.isAdmin) {
        return; // Halt execution if not authorized
      }
      await next();
    }
  ],
  onError: async (err, ctx) => {
    console.error('Bot Error:', err);
    if (ctx.thread) {
      await ctx.thread.post("Oops! Something went wrong.");
    }
  }
});

Technical Details

applyMiddleware(bot, config)

This function wraps the bot's event registration methods to inject the middleware chain.

Middleware Context (MiddlewareContext)

Every middleware function receives a context object:

  • type: The event type (mention, message, subscribed, action, command).
  • event: The raw event object from the underlying adapter.
  • thread: The Thread instance (if applicable to the event).
  • message: The Message instance (if applicable to the event).
  • data: A mutable record for passing information between middleware and into your bot's handlers.

The next() Function

Middleware must call await next() to continue to the next middleware in the chain or the final event handler. If next() is not called, the execution stops.

License

MIT