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

@agentlair/mastra

v0.1.1

Published

AgentLair telemetry and trust integration for Mastra. Captures agent calls, tool use, and token usage — builds your agent's behavioral trust profile.

Downloads

46

Readme

@agentlair/mastra

AgentLair integration for Mastra — telemetry hooks, AAT verification, and Proof of Principal Authorization (PoPA) enrollment for AI agents.

Zero required runtime dependencies. No @mastra/core version pinning.

Install

npm install @agentlair/mastra
# or
bun add @agentlair/mastra

Quick start

import { createAgentLairPlugin } from '@agentlair/mastra';
import { Agent } from '@mastra/core/agent';

const agentlair = createAgentLairPlugin({
  apiKey: process.env.AGENTLAIR_API_KEY!,  // al_live_...
  agentId: 'my-mastra-agent',
});

const agent = new Agent({ ... });

// Wrap generate calls
agentlair.onGenerateStart({ model: 'gpt-4o', toolCount: 3 });
const result = await agent.generate('Summarise last week's invoices');
agentlair.onGenerateFinish({
  text: result.text,
  finishReason: 'stop',
  usage: result.usage,
});

await agentlair.shutdown(); // flush before process exit

Get your API key at agentlair.dev.

What gets captured

| Hook | AgentLair event | Category | Data | |---|---|---|---| | onGenerateStart | generate_start | session | model, tool count, message count | | onGenerateFinish | generate_finish | session | token usage, finish reason, error | | onToolCallStart | {toolName} | tool | tool name, call ID | | onToolCallFinish | {toolName}_complete | tool | duration, success/failure, error |

Events are batched and flushed every 5 seconds. Buffer auto-flushes at 50 events.

AAT verification

Verify that incoming requests carry a valid AgentLair Agent Authentication Token:

const request = new Request('https://my-service.com/api/run', {
  headers: { Authorization: 'Bearer <agent_aat>' },
});

const token = request.headers.get('Authorization')?.replace('Bearer ', '') ?? '';
const agent = await agentlair.verifyAat(token, {
  audience: 'https://my-service.com',
});

if (!agent) {
  return new Response('Unauthorized', { status: 401 });
}

console.log(`Verified agent: ${agent.name} (${agent.agentId})`);
console.log(`Scopes: ${agent.scopes.join(', ')}`);

verifyAat uses EdDSA/Ed25519 via the Web Crypto API — no external JWT library needed.

PoPA enrollment

Record that a human principal has explicitly delegated authority to an agent:

const enrollment = await agentlair.enrollPoPA({
  principalId: 'user_hakon',
  scopes: ['write:invoices', 'read:accounts'],
  description: 'Authorized to process invoices on behalf of Håkon',
  expiresAt: '2026-06-01T00:00:00Z',
});

console.log(`PoPA enrollment: ${enrollment.enrollmentId}`);

Tool call tracking

Instrument individual tool calls to capture timing and failure rates:

const tools = {
  web_search: async (args) => {
    const callId = crypto.randomUUID();
    agentlair.onToolCallStart({ toolCallId: callId, toolName: 'web_search', args });

    try {
      const result = await doSearch(args.query);
      agentlair.onToolCallFinish({ toolCallId: callId, toolName: 'web_search', result });
      return result;
    } catch (err) {
      agentlair.onToolCallFinish({ toolCallId: callId, toolName: 'web_search', error: err });
      throw err;
    }
  },
};

Configuration

const agentlair = createAgentLairPlugin({
  // Required
  apiKey: 'al_live_...',       // Your AgentLair API key
  agentId: 'my-agent',         // Agent identifier for event attribution

  // Optional
  baseUrl: 'https://agentlair.dev',  // API base URL
  flushInterval: 5000,               // Batch flush interval (ms)
  maxBufferSize: 50,                 // Force-flush threshold (events)
  sessionId: 'custom-session-id',    // Group events by session
  timeout: 3000,                     // Request timeout (ms)
  captureInputs: false,              // Log input metadata (message count)
  captureOutputs: false,             // Log output metadata (response length)
  onError: (err) => console.error(err),  // Error handler (swallowed by default)
});

Standalone vs. upstream PR

This package ships the integration independently of Mastra PR #16032 (@mastra/auth-agentlair). You can adopt AgentLair telemetry today without waiting for the PR to merge.

When @mastra/auth-agentlair lands in the official Mastra release, it will provide deeper framework integration (Mastra Studio UI, native auth provider). This package remains the zero-dependency starting point.

Behavioral trust

Events submitted through this adapter feed AgentLair's trust engine. Your agent's trust profile reflects:

  • Consistency of tool usage patterns over time
  • Transparency of decision trails
  • Reliability under observed conditions

Trust scores are available via the AgentLair API and can gate access to other agents and services.

License

Apache-2.0