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

@kuralle-agents/messaging

v0.6.1

Published

Core interfaces and Kuralle adapter for messaging platforms

Readme

@kuralle-agents/messaging

Core interfaces and Hono router adapter for connecting messaging platforms to the Kuralle runtime.

Install

npm install @kuralle-agents/messaging

What it does

Provides the PlatformClient interface that every messaging vendor package implements, and createMessagingRouter that wires platform clients to a Kuralle Runtime over a Hono router.

  • createMessagingRouter — creates a Hono router with webhook endpoints for each platform. Routes inbound messages to a Runtime turn, streams responses back as text or interactive messages, and handles deduplication and messaging window tracking automatically.
  • PlatformClient — interface that normalizes sending, receiving, media, webhooks, and format conversion across vendors. Implement this to add any messaging platform.
  • SessionResolver — maps inbound messages to Kuralle session IDs. Default: {platform}:{threadId}. Swap in ThreadIdResolver, PhoneLookupResolver, or a custom SessionResolverChain.
  • StreamMapper — consumes AsyncIterable<HarnessStreamPart>, sends typing indicators during streaming, delegates final output to a ResponseMapper.
  • MessageDeduplicator — LRU cache that prevents duplicate webhook processing.
  • WindowTracker / WindowStore — tracks 24-hour messaging windows per thread; used by createMessagingRouter to detect expired windows.
  • OutboundPipeline + windowGuard — window-safe outbound path (see below).

Window-safe outbound

Every outbound send — default StreamMapper text replies, custom responseMapper (ResponseContext.sendText / sendInteractive / sendMedia), and router fallbackMessage on runtime errors — traverses an OutboundPipeline with a non-removable, terminal windowGuard middleware. The driver reads WindowStore.get(threadId) once per send and sets req.meta.window; when the window is closed, free-form payloads (text, media, interactive) defer ({ kind: 'deferred', reason: 'window-closed' }) with zero client calls. Templates are window-agnostic and pass through.

createMessagingRouter accepts optional windowStore (default InMemoryWindowStore) and outbound (extra middleware installed before windowGuard). Custom responseMapper closures still return Promise<SendResult>; deferred sends resolve to a synthetic result with an empty messageId (not delivered).

WhatsAppClient.sendTextOrTemplate is deprecated — it bypasses this pipeline. Use OutboundPipeline / the router instead.

  • Error classes: MessagingError, RateLimitError (with retryAfterMs), WindowClosedError (with suggestedTemplates), AuthenticationError, PermissionError, RecipientError, TemplateError, MediaError, WebhookVerificationError.

Usage

import { Hono } from 'hono';
import { createRuntime, defineAgent } from '@kuralle-agents/core';
import { createMessagingRouter } from '@kuralle-agents/messaging';
import { createWhatsAppClient } from '@kuralle-agents/messaging-meta/whatsapp';

const runtime = createRuntime({
  agents: [defineAgent({ id: 'support', instructions: 'You are a support agent.' })],
  defaultAgentId: 'support',
});

const whatsapp = createWhatsAppClient({
  accessToken: process.env.WHATSAPP_ACCESS_TOKEN!,
  appSecret: process.env.META_APP_SECRET!,
  phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,
  verifyToken: process.env.WHATSAPP_VERIFY_TOKEN!,
});

const router = createMessagingRouter({ runtime, platforms: { whatsapp } });

const app = new Hono();
app.route('/messaging', router);
// Webhook: POST /messaging/whatsapp/webhook

Error handling

import { RateLimitError, WindowClosedError } from '@kuralle-agents/messaging';

try {
  await client.sendText(to, text);
} catch (e) {
  if (e instanceof RateLimitError) await sleep(e.retryAfterMs);
  if (e instanceof WindowClosedError) { /* send a template instead */ }
}

Related