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

le-agent-sdk

v0.3.1

Published

TypeScript SDK for Lightning Enable Agent Service Agreements

Downloads

311

Readme

le-agent-sdk

Discord

npm version Tests License: MIT

TypeScript SDK for Lightning Enable Agent Service Agreements (ASA).

Discover, request, and settle agent-to-agent services over Nostr with L402 Lightning payments.

Installation

npm install le-agent-sdk

Quick Start

Provider: Publish a Service

Register an agent capability on the Nostr network so other agents can discover it, then listen for incoming service requests.

import { AgentManager, AgentCapability, AgentPricing } from "le-agent-sdk";

const manager = new AgentManager({
  privateKey: "<your_hex_private_key>",
  relayUrls: ["wss://agents.lightningenable.com"],
});

const cap = new AgentCapability({
  serviceId: "translate-v1",
  categories: ["ai", "translation"],
  content: "AI translation service. Supports 50+ languages.",
  pricing: [new AgentPricing({ amount: 10, unit: "sats", model: "per-request" })],
  l402Endpoint: "https://api.lightningenable.com/l402/proxy/translate",
  hashtags: ["translation", "ai"],
});

const eventId = await manager.publishCapability(cap);
console.log(`Published capability: ${eventId}`);

// Listen for incoming service requests
for await (const request of manager.listenRequests()) {
  console.log(`Request from ${request.pubkey}: ${request.content}`);

  // Respond with an agreement that carries the L402 settlement endpoint
  const agreement = await manager.publishAgreement({
    requestEventId: request.eventId,
    capabilityEventId: eventId,
    requesterPubkey: request.pubkey,
    agreedPriceSats: 10,
    l402Endpoint: cap.l402Endpoint ?? "",
  });
  console.log(`Published agreement: ${agreement.eventId}`);
}

Requester: Discover and Use Services

Find available services and settle via L402 payments.

import { AgentManager } from "le-agent-sdk";

const manager = new AgentManager({
  privateKey: "<your_hex_private_key>",
  relayUrls: ["wss://agents.lightningenable.com"],
  // For automatic L402 payment, wire in your wallet:
  // payInvoiceCallback: async (invoice) => "<hex_preimage>",
});

// Discover translation services
const capabilities = await manager.discover({
  categories: ["translation"],
  hashtags: ["ai"],
  limit: 10,
});

for (const cap of capabilities) {
  console.log(`[${cap.serviceId}] ${cap.content.substring(0, 60)}`);
  if (cap.pricing.length > 0) {
    console.log(`  Price: ${cap.pricing[0].amount} ${cap.pricing[0].unit}/${cap.pricing[0].model}`);
  }
}

// Settle directly against the capability's L402 endpoint
const chosen = capabilities[0];
if (chosen.l402Endpoint) {
  const response = await manager.settleViaL402(chosen);
  console.log(`Result: HTTP ${response.status}`);
  console.log(await response.text());
}

If a capability has no L402 endpoint, send a service request instead and wait for the provider to respond with an agreement:

const request = await manager.requestService(
  chosen.eventId,
  chosen.pubkey,
  100, // budget in sats
  { source_lang: "en", target_lang: "es" },
  "Please translate: Hello, how are you?"
);
console.log(`Sent request: ${request.eventId}`);
// When the provider publishes an agreement, settle it:
// const response = await manager.settle(agreement);

Reputation: Attest and Check Track Record

After a completed agreement, publish a review (Nostr kind 38403). Before hiring an agent, query its attestations.

import { AgentManager } from "le-agent-sdk";

const manager = new AgentManager({
  privateKey: "<your_hex_private_key>",
  relayUrls: ["wss://agents.lightningenable.com"],
});

// Publish a review of the provider after a completed agreement
const attestationEventId = await manager.publishAttestation(
  "<provider_pubkey>",
  "<agreement_event_id>",
  5, // rating
  "Fast, accurate translation. Would hire again."
);
console.log(`Published attestation: ${attestationEventId}`);

// Check an agent's track record before hiring it
const reputation = await manager.getReputation("<provider_pubkey>");
if (reputation.count === 0) {
  console.log("No attestations yet");
} else {
  console.log(`Reputation: ${reputation.average.toFixed(1)}/5.0 from ${reputation.count} attestations`);
}

getReputation returns a ReputationResult: { average, count, attestations }.

API Reference

Core Classes

| Export | Description | |--------|-------------| | AgentManager | Main entry point. Manages Nostr relay connections, publishes capabilities, discovers services, and handles L402 settlement. | | AgentCapability | Defines a service offering with pricing, categories, endpoints, and metadata. Published as Nostr kind 38400 events. | | AgentServiceRequest | A request for service from one agent to another (kind 38401). | | AgentServiceAgreement | Bilateral contract between provider and requester (kind 38402). | | AgentAttestation | Post-completion review of an agent (kind 38403): rating plus review text. The building block for on-protocol reputation. |

AgentManager Methods

| Method | Description | |--------|-------------| | discover(options?) | Query relays for agent capabilities. Filter by categories, hashtags, limit, timeout. Returns AgentCapability[]. | | publishCapability(capability) | Publish a capability advertisement to relays. Returns the Nostr event ID. | | requestService(capabilityEventId, providerPubkey, budgetSats?, params?, content?) | Send a service request to a provider. Returns the published AgentServiceRequest. | | listenRequests() | Async generator yielding incoming AgentServiceRequests addressed to this agent. | | publishAgreement(options) | Publish a service agreement (provider side). Returns the published AgentServiceAgreement. | | settle(agreement, options?) | Execute L402 settlement against an agreement's L402 endpoint. Returns a Response. | | settleViaL402(capability, options?) | Settle directly against a capability's L402 endpoint, skipping the request/agreement steps. Returns a Response. | | createChallenge(agreement, priceSats?, description?) | Provider side: create an L402 challenge (invoice + macaroon) via the Lightning Enable API. Requires leApiKey. | | verifyPayment(macaroon, preimage) | Provider side: verify an L402 token to confirm payment before delivering the service. Requires leApiKey. | | publishAttestation(subjectPubkey, agreementId, rating, content) | Publish a review of an agent after a completed agreement (kind 38403). Returns the Nostr event ID. | | getReputation(pubkey) | Query relays for attestations about an agent. Returns ReputationResult (average, count, attestations). |

Nostr Layer

| Export | Description | |--------|-------------| | RelayClient | WebSocket client for Nostr relay communication. Handles subscriptions and event publishing. | | NostrEvent | Nostr event construction, serialization, and signing. | | TagParser | Utilities for parsing and building Nostr event tags and filters. |

Payment Layer

| Export | Description | |--------|-------------| | L402Client | HTTP client with automatic L402 challenge-response handling (402 → pay → retry). | | L402ProducerClient | Client for the Lightning Enable producer API: create L402 challenges and verify payments. Requires a Lightning Enable API key. | | AgentPricing | Pricing model (amount, unit, model such as per-request/per-token). | | parseL402Challenge, validatePreimage, decodeInvoiceAmountSats | Helpers for working with L402 challenges and invoices. |

Protocol

Agent Service Agreements use four Nostr event kinds:

  • 38400 — Agent Capability: provider advertises available services
  • 38401 — Agent Service Request: requester asks for a service
  • 38402 — Agent Service Agreement: bilateral contract with terms and pricing
  • 38403 — Agent Attestation: post-completion review that builds on-protocol reputation

The flow is discover → request → settle → attest. Settlement happens via L402 (Lightning HTTP 402) through Lightning Enable endpoints. Lightning Enable does not hold funds — the configured payment provider facilitates custody and settlement.

Examples

Runnable versions of the quickstarts live in examples/:

npx tsx examples/simple-provider.ts
npx tsx examples/simple-requester.ts

Related Projects

License

MIT