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

@agentgate/sdk

v0.1.0

Published

SDK for integrating AgentGate into your applications

Downloads

278

Readme

@agentgate/sdk

TypeScript SDK for agents to request human approvals via AgentGate.

Installation

npm install @agentgate/sdk
# or
pnpm add @agentgate/sdk

Quick Start

import { AgentGateClient } from '@agentgate/sdk'

const client = new AgentGateClient({
  baseUrl: 'http://localhost:3000',
  apiKey: 'your-api-key' // optional
})

// Request approval for an action
const request = await client.request({
  action: 'send_email',
  params: { to: '[email protected]' },
  context: { dealValue: 50000 }
})

console.log(`Request ${request.id} created, waiting for approval...`)

// Wait for human decision (polls until decided or timeout)
const decided = await client.waitForDecision(request.id, {
  timeout: 5 * 60 * 1000, // 5 minutes (default)
  pollInterval: 2000      // 2 seconds (default)
})

if (decided.status === 'approved') {
  // Execute the action
  console.log('Approved! Sending email...')
} else if (decided.status === 'denied') {
  console.log('Request denied:', decided.decisionReason)
} else if (decided.status === 'expired') {
  console.log('Request expired before decision')
}

API Reference

AgentGateClient

Constructor

new AgentGateClient({
  baseUrl: string,    // Required: URL of your AgentGate server
  apiKey?: string     // Optional: API key for authentication
})

Methods

request(options): Promise<ApprovalRequest>

Submit an approval request. Returns immediately with the created request.

const request = await client.request({
  action: 'send_email',           // Required: action identifier
  params: { to: '[email protected]' }, // Optional: action parameters
  context: { reason: 'Follow up' }, // Optional: contextual info
  urgency: 'high',                // Optional: 'low' | 'normal' | 'high' | 'critical'
  expiresAt: new Date(Date.now() + 3600000) // Optional: expiration time
})
getRequest(id): Promise<ApprovalRequest>

Get an approval request by ID.

const request = await client.getRequest('req_123')
waitForDecision(id, options?): Promise<ApprovalRequest>

Poll until a decision is made or timeout is reached.

const decided = await client.waitForDecision('req_123', {
  timeout: 300000,     // 5 minutes (default)
  pollInterval: 2000   // 2 seconds (default)
})

Throws TimeoutError if timeout is reached.

listRequests(options?): Promise<ApprovalRequest[]>

List approval requests with optional filters.

const requests = await client.listRequests({
  status: 'pending',  // Filter by status
  action: 'send_email', // Filter by action
  limit: 10,          // Max results
  offset: 0           // Pagination offset
})

Policy Management

// List all policies
const policies = await client.listPolicies()

// Get a specific policy
const policy = await client.getPolicy('pol_123')

// Create a policy
const newPolicy = await client.createPolicy({
  name: 'Auto-approve low-risk emails',
  rules: [{ match: { action: 'send_email' }, decision: 'auto_approve' }],
  priority: 100,
  enabled: true,
})

// Update a policy
const updated = await client.updatePolicy('pol_123', { enabled: false })

// Delete a policy
await client.deletePolicy('pol_123')

Webhook Management

// List webhooks
const webhooks = await client.listWebhooks()

// Create a webhook (secret is only returned once!)
const wh = await client.createWebhook({
  url: 'https://example.com/webhook',
  events: ['request.approved', 'request.denied'],
})
console.log('Save this secret:', wh.secret)

// Update a webhook
await client.updateWebhook('wh_123', { enabled: false })

// Delete a webhook
await client.deleteWebhook('wh_123')

// Test a webhook
const result = await client.testWebhook('wh_123')
console.log(result.success ? 'Delivered!' : 'Failed:', result.message)

Audit Logs

// List audit entries with filters
const audit = await client.listAuditLogs({
  eventType: 'approved',
  actor: 'dashboard:admin',
  from: '2024-01-01',
  to: '2024-01-31',
  limit: 20,
})
console.log(audit.entries, audit.pagination)

// Get unique actors for filter dropdowns
const actors = await client.getAuditActors()

API Key Management

// List API keys (secrets are never returned)
const keys = await client.listApiKeys()

// Create an API key (key is only returned once!)
const newKey = await client.createApiKey({
  name: 'CI Pipeline',
  scopes: ['agent'],
})
console.log('Save this key:', newKey.key)

// Revoke an API key
await client.revokeApiKey('key_123')

Error Handling

import { AgentGateError, TimeoutError } from '@agentgate/sdk'

try {
  await client.waitForDecision(id)
} catch (error) {
  if (error instanceof TimeoutError) {
    console.log('Timed out waiting for decision')
  } else if (error instanceof AgentGateError) {
    console.log(`API error: ${error.message} (${error.statusCode})`)
  }
}

Types

All types from @agentgate/core are re-exported for convenience:

import type {
  ApprovalRequest,
  ApprovalStatus,
  ApprovalUrgency,
  DecisionType,
  Policy,
  PolicyRule,
  PolicyDecision,
  Webhook,
  WebhookCreateOptions,
  WebhookCreateResult,
  AuditEntry,
  AuditListResult,
  ApiKey,
  ApiKeyCreateResult,
} from '@agentgate/sdk'

License

MIT