agent402-client 0.2.0 → 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 +34 -0
  2. package/index.js +33 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -47,12 +47,46 @@ const a = new Agent402({ fetch: payFetch });
47
47
  const article = await a.call("extract", { url: "https://example.com/article" });
48
48
  ```
49
49
 
50
+ ## Workflows (skill packs)
51
+
52
+ For jobs that no single tool covers — e.g. "audit a domain", "build a stock
53
+ brief" — Agent402 ships curated multi-tool **skill packs**: 5–7 catalog tools
54
+ composed into a Claude-ready task template. Discover them the same way you'd
55
+ discover a tool:
56
+
57
+ ```js
58
+ const packs = await a.findWorkflows("security audit");
59
+ // → [{ slug: "security-audit", title, tagline, toolSlugs, score, url, promptName }]
60
+
61
+ // Render the full prompt with arguments substituted in (same output as MCP prompts/get).
62
+ const { messages } = await a.getWorkflowPrompt("security-audit", { domain: "stripe.com" });
63
+ // → feed messages straight to any LLM
64
+ ```
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
+
50
81
  ## API
51
82
 
52
83
  | Method | What |
53
84
  |---|---|
54
85
  | `new Agent402({ baseUrl?, fetch?, cache?, fetchImpl? })` | `fetch` is your x402-wrapped fetch for paid tools (optional); `cache` (default `true`) memoizes deterministic results |
55
86
  | `await a.find(task, { k = 5 })` | Resolve a plain-language task to the best-matching tools (route, price, schema, example) |
87
+ | `await a.findWorkflows(task, { k = 2 })` | Resolve a task to matching multi-tool workflow templates (skill packs) |
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) |
56
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 |
57
91
  | `Agent402.solvePow(pow)` | Solve a proof-of-work challenge object → an `X-Pow-Solution` value |
58
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.0",
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",