agent402-client 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +16 -0
  2. package/index.js +33 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -63,6 +63,21 @@ const { messages } = await a.getWorkflowPrompt("security-audit", { domain: "stri
63
63
  // → feed messages straight to any LLM
64
64
  ```
65
65
 
66
+ ## Discover the live x402 economy
67
+
68
+ Want to see who's actually getting paid on x402 right now — not just what tools
69
+ this service exposes? `topSellers()` returns the live leaderboard of sellers
70
+ settling USDC on Base in the last ~24h, derived from on-chain transfers. Free
71
+ to call (no payment, no proof-of-work):
72
+
73
+ ```js
74
+ const { window, asOf, results, totalSellers } = await a.topSellers({ limit: 10 });
75
+ // → { window: "24h", asOf, totalSellers, results: [{ rank, name, wallet, totalUsd, callsSettled, uniqueBuyers, ... }] }
76
+
77
+ // Rank by call volume instead of USDC, and include the host's own wallet:
78
+ await a.topSellers({ sort: "calls", include: "all" });
79
+ ```
80
+
66
81
  ## API
67
82
 
68
83
  | Method | What |
@@ -71,6 +86,7 @@ const { messages } = await a.getWorkflowPrompt("security-audit", { domain: "stri
71
86
  | `await a.find(task, { k = 5 })` | Resolve a plain-language task to the best-matching tools (route, price, schema, example) |
72
87
  | `await a.findWorkflows(task, { k = 2 })` | Resolve a task to matching multi-tool workflow templates (skill packs) |
73
88
  | `await a.getWorkflowPrompt(slug, args)` | Fetch the rendered prompt messages for a skill pack with arguments substituted in |
89
+ | `await a.topSellers({ limit?, sort?, include? })` | Live x402 leaderboard: which sellers are settling the most USDC on Base in the last ~24h (free, no payment) |
74
90
  | `await a.call(slug, params, { idempotencyKey?, cache? })` | Call a tool; auto-pays (PoW for free tools, x402 for wallet-only); returns the JSON result |
75
91
  | `Agent402.solvePow(pow)` | Solve a proof-of-work challenge object → an `X-Pow-Solution` value |
76
92
  | `a.clearCache()` | Drop the in-memory result cache |
package/index.js CHANGED
@@ -77,6 +77,39 @@ export class Agent402 {
77
77
  return r.json();
78
78
  }
79
79
 
80
+ /**
81
+ * Live x402 leaderboard — the sellers earning the most USDC (or serving the
82
+ * most calls) on Base in the last ~24h, derived from on-chain USDC
83
+ * transfers. Free; no payment, no wallet, no proof-of-work. Useful when
84
+ * building agents that want to discover the live x402 economy beyond a
85
+ * single service's catalog. Hourly snapshot — safe to call freely.
86
+ *
87
+ * @param {object} [opts]
88
+ * @param {number} [opts.limit=10] max rows (1-50)
89
+ * @param {"usd"|"calls"} [opts.sort="usd"] rank by USDC settled or call count
90
+ * @param {"external"|"all"} [opts.include="external"] hide this service's own wallet (default) or include it
91
+ * @returns {Promise<{window:string, asOf:string, sort:string, include:string, totalSellers:number, results:Array<object>, source:string}>}
92
+ */
93
+ async topSellers({ limit = 10, sort = "usd", include = "external" } = {}) {
94
+ const top = Math.min(Math.max(parseInt(limit, 10) || 10, 1), 50);
95
+ const sortParam = sort === "calls" ? "calls" : "usd";
96
+ const includeParam = include === "all" ? "all" : "external";
97
+ const url = `${this.baseUrl}/api/leaderboard?top=${top}&sort=${sortParam}&include=${includeParam}`;
98
+ const r = await this.f(url);
99
+ if (!r.ok) throw new Error(`topSellers failed: HTTP ${r.status}`);
100
+ const snap = await r.json();
101
+ return {
102
+ window: snap.windowLabel || snap.windowServed || "24h",
103
+ asOf: snap.asOf,
104
+ sort: snap.sortServed || sortParam,
105
+ include: snap.include || includeParam,
106
+ totalSellers: snap.totalSellers ?? (snap.leaderboard || []).length,
107
+ results: snap.leaderboard || [],
108
+ ...(snap.warming || snap.scanSkipped ? { warming: true } : {}),
109
+ source: `${this.baseUrl}/api/leaderboard`,
110
+ };
111
+ }
112
+
80
113
  /** Solve a proof-of-work challenge object (from a 402 body) into an X-Pow-Solution value. */
81
114
  static solvePow(pow) {
82
115
  let n = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent402-client",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Tiny buyer-side client for Agent402 (x402): resolve a task to a tool and call it with payment handled for you — free tools settle via built-in proof-of-work (no wallet), wallet-only tools via your x402 fetch. Caching + idempotent retries.",
5
5
  "type": "module",
6
6
  "main": "index.js",