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

@tryagent/sdk

v0.0.61

Published

TypeScript SDK for creating TryAgent escalations.

Downloads

40

Readme

@tryagent/sdk

TypeScript SDK for creating TryAgent escalations from AI agents and workflows.

Use TryAgent when an agent reaches a decision it should not make alone. Your code sends the decision point, evidence, choices, and resume target. TryAgent routes the escalation to the right reviewers, records the decision or timeout path, and calls your workflow back when it can continue.

Full documentation: https://tryagentai.mintlify.app/quickstart

Install

pnpm add @tryagent/sdk
npm install @tryagent/sdk

Prerequisites

Before calling the SDK, create these in TryAgent:

  • A workspace API key, available to your runtime as TRYAGENT_API_KEY.
  • An escalation policy key, such as orders.auth_doc.
  • A resume webhook endpoint if your workflow should continue after the reviewer decides.

Create a client

import { TryAgent } from "@tryagent/sdk";

const tryagent = new TryAgent({
  apiKey: process.env.TRYAGENT_API_KEY!,
});

The SDK defaults to https://api.tryagent.ai. Pass baseUrl only for local development or tests.

const tryagent = new TryAgent({
  apiKey: process.env.TRYAGENT_API_KEY!,
  baseUrl: "http://localhost:4000",
});

Send an escalation

const escalation = await tryagent.escalate("orders.auth_doc", {
  agentId: "order-agent",
  runId: "run_4821",
  subject: {
    type: "order",
    id: "ord_4821",
    label: "Order #4821",
  },
  question: "The authorization document is missing a signature date. Continue?",
  evidence: [
    "Candidate name is present.",
    "Employer is present.",
    "Signature date is blank.",
  ],
  choices: [
    { id: "manual_review", label: "Send to manual review" },
    { id: "continue", label: "Continue anyway" },
  ],
  responseFields: [
    {
      type: "number",
      name: "approvedLimit",
      label: "Approved limit",
      min: 0,
      step: 0.01,
    },
    {
      type: "select",
      name: "riskLevel",
      label: "Risk level",
      options: [
        { value: "low", label: "Low" },
        { value: "high", label: "High" },
      ],
    },
  ],
  resume: {
    mode: "webhook",
    url: "https://api.example.com/tryagent/resume",
    secret: process.env.TRYAGENT_WEBHOOK_SECRET!,
  },
});

console.log(escalation.id, escalation.status);

escalate returns as soon as TryAgent creates the escalation. It does not wait for a human reviewer. Store the returned escalation ID if you want to correlate logs or audit records.

Resume your workflow

When a reviewer decides, or the policy timeout path applies, TryAgent sends a POST request to resume.url. Use the event's runId to load and continue the paused workflow. If you configured responseFields, the callback includes the validated structured values as response.

When resume.secret is set, TryAgent signs the exact JSON body with HMAC-SHA256 and includes:

  • x-tryagent-event: escalation.decided
  • x-tryagent-delivery: resume:<escalation id>
  • x-tryagent-signature: v1=<hex hmac>

Verify the signature before applying the decision. webhooks.constructEvent verifies the HMAC (constant-time, via Web Crypto so it runs on Node, edge, and Workers) and returns the typed event, throwing WebhookSignatureError when verification fails. Always pass the raw request body — re-serializing JSON changes the bytes and breaks the signature.

import { WebhookSignatureError } from "@tryagent/sdk";

export async function POST(request: Request) {
  const body = await request.text();

  try {
    const event = await tryagent.webhooks.constructEvent({
      payload: body,
      signature: request.headers.get("x-tryagent-signature"),
      secret: process.env.TRYAGENT_WEBHOOK_SECRET!,
    });

    await resumeWorkflow(event.runId, { choice: event.choice });
    return Response.json({ ok: true });
  } catch (error) {
    if (error instanceof WebhookSignatureError) {
      return Response.json({ error: "Invalid signature" }, { status: 401 });
    }
    throw error;
  }
}

See the quickstart for the full callback handler.

Read and manage escalations

Beyond escalate, the escalations resource exposes the rest of the lifecycle:

await tryagent.escalations.list({ status: "open" });
await tryagent.escalations.get(escalationId);
await tryagent.escalations.acknowledge(escalationId);
await tryagent.escalations.decide(escalationId, { choice: "continue", reason: "Verified" });
await tryagent.escalations.cancel(escalationId, { reason: "Duplicate" });

These methods work with an ain_live_ API key as long as the key carries the matching scope, or with a workspace user token/getToken. API-key scopes:

| Method | Required scope | | --- | --- | | escalate / create | escalations:write | | list, get | escalations:read | | acknowledge | escalations:acknowledge | | decide | escalations:decide | | cancel | escalations:cancel |

Keys are issued with all escalation scopes by default, so every method works out of the box. To restrict a key, pass a narrower scopes array to POST /api-keys; a call that needs a scope the key lacks returns 403.

Handle errors

Non-2xx API responses and network failures throw ApiError.

import { ApiError } from "@tryagent/sdk";

try {
  await tryagent.escalate("orders.auth_doc", input);
} catch (error) {
  if (error instanceof ApiError) {
    console.error(error.status, error.requestId, error.body);
    throw error;
  }

  throw error;
}