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

@ar-agents/core

v0.2.0

Published

Shared primitives for @ar-agents/* packages: typed error base, tool middleware (compose, withMetrics, withRetry, withTimeout, withApproval HITL gate, withHalt kill-switch), the central risk manifest (classifyTool + enforceRiskPolicy: the art. 102 approval

Downloads

930

Readme

@ar-agents/core

Shared primitives for the @ar-agents/* family. Typed error base, telemetry hook contract, and composable tool middleware (metrics, retry, timeout, HITL approval). Zero runtime deps beyond the Vercel AI SDK tool shape.

pnpm add @ar-agents/core

What's inside

Typed errors

Every package in the family extends ArAgentsError so callers can write retry/fallback logic that's transferable across tools:

import {
  ArAgentsError,
  ArAgentsRateLimitError,
  ArAgentsValidationError,
  isArAgentsError,
} from "@ar-agents/core";

try {
  await tool.execute(args, ctx);
} catch (err) {
  if (isArAgentsError(err) && err.retryable) {
    await backoff();
    return retry();
  }
  if (err instanceof ArAgentsRateLimitError) {
    await sleep(err.retryAfterMs);
    return retry();
  }
  if (err instanceof ArAgentsValidationError) {
    surfaceToOperator(err.field, err.message);
  }
  throw err;
}

Every error carries code: string, retryable: boolean, and context: Record<string, unknown>. Subclasses (ArAgentsAuthError, ArAgentsProtocolError, etc.) populate them with sane defaults.

Tool middleware

Composable wrappers around any Vercel AI SDK 6 tool. Mix and match:

import {
  compose,
  withMetrics,
  withRetry,
  withTimeout,
  withApproval,
  applyToAllTools,
  consoleTelemetryHook,
} from "@ar-agents/core";
import { mercadoPagoTools } from "@ar-agents/mercadopago";

const telemetry = consoleTelemetryHook();

const baseTools = mercadoPagoTools({ client, state, backUrl });

const tools = applyToAllTools(baseTools, (name) =>
  compose(
    // outermost first at runtime → HITL gate runs BEFORE retry
    withApproval(name, { approve: askUser }),
    withRetry({ maxAttempts: 3 }),
    withTimeout(name, 10_000),
    withMetrics(name, { telemetry }),
  ),
);

Telemetry hooks

A tiny TelemetryHook interface keeps the family observability-agnostic. Plug your OTel exporter, Datadog shipper, Honeycomb, or console:

import { combineHooks, consoleTelemetryHook, type TelemetryHook } from "@ar-agents/core";

const myOtelHook: TelemetryHook = {
  onToolEvent(event) {
    span.setAttribute("tool.name", event.name);
    span.setAttribute("tool.ok", event.ok);
    // …
  },
};

const telemetry = combineHooks(consoleTelemetryHook(), myOtelHook);

A throwing hook never crashes the request — observability is best-effort by design.

HITL approval gate

withApproval is the runtime enforcement of the requiresConfirmation flag in tools.manifest.json:

const tools = applyToAllTools(myTools, (name) =>
  withApproval(name, {
    approve: async (toolName, args) => {
      // Ask the user, call a policy engine, consult an allowlist…
      return await dialogConfirm(`Run ${toolName}?`, args);
    },
    refusedMessage: "Operator denied this operation.",
  }),
);

The gate runs BEFORE execute, so denied calls never burn the underlying API quota.

Why a separate package

mercadopago shipped its own middleware + telemetry stack first. Lifting them to @ar-agents/core gives all 20+ packages the same primitives without each maintaining its own — the family looks coherent from the outside, and the shared concerns evolve in one place.

License

MIT — Nazareno Clemente [email protected]