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

@ag-ui/mastra

v1.1.2

Published

Implementation of the AG-UI protocol for Mastra.

Readme

@ag-ui/mastra

Implementation of the AG-UI protocol for Mastra.

Connects Mastra agents (local and remote) to frontend applications via the AG-UI protocol. Supports streaming responses, memory management, and tool execution.

Installation

Install the @ag-ui/mastra package:

# npm
npm install @ag-ui/mastra
# pnpm
pnpm add @ag-ui/mastra
# yarn
yarn add @ag-ui/mastra

Install the required peer dependencies:

npm install @mastra/client-js @mastra/core @ag-ui/core @ag-ui/client @copilotkit/runtime

Usage

import { MastraAgent } from "@ag-ui/mastra";
import { mastra } from "./mastra"; // Your Mastra instance

// Create an AG-UI compatible agent
const agent = new MastraAgent({
  agent: mastra.getAgent("weather-agent"),
  resourceId: "user-123",
});

// Run with streaming
const result = await agent.runAgent({
  messages: [{ role: "user", content: "What's the weather like?" }],
});

Features

  • Local & remote agents – Works with in-process and network Mastra agents
  • Memory integration – Automatic thread and working memory management
  • Tool streaming – Real-time tool call execution and results
  • State management – Bidirectional state synchronization
  • Human-in-the-loop – Mastra tool suspend/resume bridged to AG-UI interrupts

Interrupts (tool suspend/resume)

When a Mastra tool suspends, the bridge surfaces it to the frontend. Two channels exist:

  • Legacy CustomEvent(name="on_interrupt") — always emitted (backward compatibility). Its value is a JSON string carrying type:"mastra_suspend", toolCallId, toolName, suspendPayload, args, resumeSchema, and the snapshot-keying runId.
  • Standard RunFinishedEvent.outcome = { type: "interrupt", interrupts } — the canonical AG-UI signal. Each suspend maps to an Interrupt (reason, toolCallId, responseSchema — parsed from resumeSchema); the remaining round-trip data lives under metadata.mastra. Its id is `${runId}::${toolCallId}` — the snapshot-keying runId is encoded into the id because a standard-path client only round-trips interruptId (not metadata) on resume; the bridge decodes it back out.

Resume is consumed from both channels regardless of the flag: the legacy forwardedProps.command.resume and the standard RunAgentInput.resume array.

Opt-out (emitInterruptOutcome, default true). The structured outcome is the canonical AG-UI interrupt path, emitted by default alongside the legacy event. It requires a CopilotKit client >= 1.61.2 — the release that reads outcome:"interrupt" and resumes via RunAgentInput.resume. On older clients (<= 1.61.1, incl. 1.60.1/1.61.0) the client records the structured interrupt but never addresses it on resume, stranding the run with Thread has N pending interrupt(s) not addressed by resume. If you target a client below 1.61.2, set emitInterruptOutcome: false to fall back to the legacy on_interrupt-only path. When on, BOTH channels are emitted; when off, only the legacy event plus a plain RUN_FINISHED.

const agent = new MastraAgent({
  agent: mastra.getAgent("interrupt-agent"),
  resourceId: "user-123",
  // Default true. Set false if your CopilotKit client is < 1.61.2.
  emitInterruptOutcome: false,
});

To run the example server in the dojo

cd integrations/mastra/typescript/examples
pnpm install
pnpm run dev