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

@agentmail/convex

v0.1.0

Published

A Convex component for AgentMail.

Readme

@agentmail/convex

A Convex component for AgentMail.

AgentMail is a stateful email inbox for AI agents — every message your agent sends or receives is persisted as part of a thread, with labels, full bodies, and history. This component brings that inbox state into your Convex database so your agents and your UI both see it live.

It's the difference between "I built on Resend and rebuilt my own thread/label/draft store on top" and "the inbox already exists; I just useQuery it."

What you get

  • Threads as first-class state. Every inbound message persists with its thread_id, in_reply_to, and references in your Convex DB. Subscribe to listInboundMessages({ threadId }) and watch the thread update reactively.
  • Full message bodies. Text, HTML, extracted text/HTML, attachments metadata — not just headers or previews.
  • Labels. Tag conversations on send (labels: ["urgent", "support-agent"]) and query threads by label via listThreads({ labels }).
  • Durable sending. sendMessage/replyToMessage/forwardMessage enqueue from a mutation; a workpool action talks to AgentMail with bounded retries. Lifecycle (pending → sent → delivered/bounced/...) is itself a reactive query.
  • Idempotent webhook ingest. Svix-verified, deduped by event_id, callbacks dispatched via a separate workpool so a slow user handler can't block inbound mail.
  • Reactive UI. useQuery over inbox state — new mail, status changes, thread updates — without polling.
  • Isolated component. Its own tables (inboxes, inboundMessages, outboundMessages, events), sandboxed from your app's data.

Install

npm install @agentmail/convex

Wire it into your Convex app:

// convex/convex.config.ts
import { defineApp } from "convex/server";
import agentmail from "@agentmail/convex/convex.config";

const app = defineApp();
app.use(agentmail);
export default app;

Set credentials on your Convex deployment (kept out of mutation args so they don't appear in function logs):

npx convex env set AGENTMAIL_API_KEY your_api_key
npx convex env set AGENTMAIL_WEBHOOK_SECRET whsec_...
# Optional: EU residency
npx convex env set AGENTMAIL_BASE_URL https://api.agentmail.eu/v0

Query threads and messages

The most reactive part of the API. Subscribe from React; new mail appears the instant AgentMail's webhook fires.

// convex/email.ts
import { query } from "./_generated/server";
import { components } from "./_generated/api";
import { v } from "convex/values";

export const listThread = query({
  args: { threadId: v.string() },
  handler: (ctx, { threadId }) =>
    ctx.runQuery(components.agentmail.lib.listInboundMessages, { threadId }),
});

export const listInbox = query({
  args: { inboxId: v.string() },
  handler: (ctx, { inboxId }) =>
    ctx.runQuery(components.agentmail.lib.listInboundMessages, { inboxId }),
});
// React
const messages = useQuery(api.email.listThread, { threadId });

For thread metadata (last message, participants, label set) from AgentMail's remote API:

import { AgentMail } from "@agentmail/convex";
const agentmail = new AgentMail(components.agentmail);

await agentmail.listThreads(ctx, inboxId, { labels: ["urgent"] });
await agentmail.getThread(ctx, inboxId, threadId);
await agentmail.getMessage(ctx, inboxId, messageId);

Send mail (with labels)

import { mutation } from "./_generated/server";
import { components } from "./_generated/api";
import { AgentMail } from "@agentmail/convex";
import { v } from "convex/values";

const agentmail = new AgentMail(components.agentmail);

export const sendHello = mutation({
  args: { inboxId: v.string(), to: v.string() },
  handler: async (ctx, args) => {
    return await agentmail.sendMessage(ctx, args.inboxId, {
      to: args.to,
      subject: "Hello from my Convex agent",
      text: "Hi! This was sent from a Convex mutation.",
      labels: ["support-agent", "auto-reply"],
    });
  },
});

The return value is an OutboundId. Subscribe to it for live delivery status:

const status = useQuery(api.email.sendStatus, { outboundId });
// → { status: "sent" | "delivered" | "bounced" | ..., agentmailMessageId, threadId, errorMessage }

Receive mail

Mount the webhook handler in convex/http.ts:

import { httpRouter } from "convex/server";
import { httpAction } from "./_generated/server";
import { components } from "./_generated/api";
import { AgentMail } from "@agentmail/convex";

const agentmail = new AgentMail(components.agentmail);
const http = httpRouter();

http.route({
  path: "/agentmail/webhook",
  method: "POST",
  handler: httpAction(async (ctx, req) => agentmail.handleWebhook(ctx, req)),
});

export default http;

Register the webhook URL with AgentMail (https://your-deployment.convex.site/agentmail/webhook) and copy the secret into AGENTMAIL_WEBHOOK_SECRET.

React to inbound mail (your agent runs here)

import { internalMutation } from "./_generated/server";
import { components, internal } from "./_generated/api";
import { AgentMail } from "@agentmail/convex";
import { v } from "convex/values";

const agentmail = new AgentMail(components.agentmail, {
  onMessageReceived: internal.email.onMessageReceived,
});

export const onMessageReceived = internalMutation({
  args: { message: v.any(), thread: v.any(), eventId: v.string() },
  handler: async (ctx, args) => {
    // Your LLM agent runs here.
    await ctx.scheduler.runAfter(0, internal.email.autoReply, {
      inboxId: args.message.inbox_id,
      messageId: args.message.message_id,
      threadId: args.message.thread_id,
      text: args.message.text ?? "",
    });
  },
});

The thread argument carries everything AgentMail knows about the thread at the moment the message landed — labels, participants, message count — so your agent can decide what to do without a follow-up round-trip.

Configuration

new AgentMail(component, options?) accepts an options object. Credentials are read from the Convex deployment's env vars and not accepted here, so they never appear in function logs.

| Option | Env var (component-side) | Default | | ------------------- | -------------------------- | -------------------------------- | | — | AGENTMAIL_API_KEY | required | | — | AGENTMAIL_BASE_URL | https://api.agentmail.to/v0 | | webhookSecret | AGENTMAIL_WEBHOOK_SECRET | required for webhook handler | | retryAttempts | — | 5 | | initialBackoffMs | — | 30000 | | onMessageReceived | — | none | | onEvent | — | none (fires on every event type) |

For EU residency, set AGENTMAIL_BASE_URL=https://api.agentmail.eu/v0.

License

Apache-2.0