agent402-client 0.6.0 → 0.6.1

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 +2 -0
  2. package/index.js +13 -2
  3. package/package.json +4 -2
package/README.md CHANGED
@@ -11,6 +11,8 @@ never double-charges.
11
11
  npm install agent402-client
12
12
  ```
13
13
 
14
+ Runnable copy of the free-tier quickstart below: [`examples/hello-agent402.js`](https://github.com/MikeyPetrillo/Agent402/blob/main/examples/hello-agent402.js) — discover a tool and call it in ~15 lines, no wallet.
15
+
14
16
  ## Free tier (proof-of-work, no wallet)
15
17
 
16
18
  ```js
package/index.js CHANGED
@@ -14,6 +14,13 @@
14
14
  // const a = new Agent402({ fetch: payFetch });
15
15
  import { createHash } from "node:crypto";
16
16
 
17
+ // Keep in lockstep with package.json. Every request the SDK issues carries
18
+ // `User-Agent: agent402-client/<version>` — a standard header, no extra
19
+ // network calls — so a seller can attribute traffic (and settled payments)
20
+ // to this SDK. Product token only; nothing about the caller rides along.
21
+ const VERSION = "0.6.1";
22
+ const USER_AGENT = `agent402-client/${VERSION}`;
23
+
17
24
  const leadingZeroBits = (buf) => { let n = 0; for (const b of buf) { if (b === 0) { n += 8; continue; } n += Math.clz32(b) - 24; break; } return n; };
18
25
 
19
26
  export class Agent402 {
@@ -32,7 +39,9 @@ export class Agent402 {
32
39
  if (typeof fetchImpl !== "function") throw new Error("No fetch available — pass { fetchImpl } on Node < 18");
33
40
  this.baseUrl = String(baseUrl).replace(/\/$/, "");
34
41
  this.payFetch = payFetch || null;
35
- this.f = fetchImpl;
42
+ // Wrap the plain fetch so every request identifies the SDK (see USER_AGENT
43
+ // above). Caller-supplied init.headers still win on a key collision.
44
+ this.f = (url, init = {}) => fetchImpl(url, { ...init, headers: { "User-Agent": USER_AGENT, ...(init.headers || {}) } });
36
45
  this._catalog = null;
37
46
  this._cache = cache ? new Map() : null;
38
47
  // Spending policy (defends the x402 "wallet drain via uncapped spending"
@@ -167,7 +176,9 @@ export class Agent402 {
167
176
 
168
177
  const idem = idempotencyKey || `a402-${createHash("sha256").update(`${cacheKey}:${Date.now()}:${Math.random()}`).digest("hex").slice(0, 24)}`;
169
178
  const send = (extraHeaders = {}, useFetch = this.f) => {
170
- const headers = { "Idempotency-Key": idem, ...extraHeaders };
179
+ // UA set here too (not only in the this.f wrapper) so the x402 payFetch
180
+ // path — the one that settles real payments — always carries it.
181
+ const headers = { "User-Agent": USER_AGENT, "Idempotency-Key": idem, ...extraHeaders };
171
182
  let url = `${this.baseUrl}${tool.path}`;
172
183
  const init = { method: tool.method, headers };
173
184
  if (tool.method === "GET") {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agent402-client",
3
- "version": "0.6.0",
4
- "description": "Buyer-side SDK for Agent402.Tools (x402): resolve a task to a tool across 1,407 pay-per-call endpoints 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 — with a withNetworkPreference helper to pick the settlement chain (USDC on Base/Solana/Polygon/Arbitrum/Stellar or USDG on Robinhood Chain). Caching, idempotent retries, cross-seller Smart Order Router.",
3
+ "version": "0.6.1",
4
+ "description": "Buyer-side SDK for Agent402.Tools (x402): resolve a task to a tool across a catalog of 500 pay-per-call endpoints (400 tools + 100 skill packs) 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 — with a withNetworkPreference helper to pick the settlement chain (USDC on Base/Solana/Polygon/Arbitrum/Monad/Stellar/Algorand or USDG on Robinhood Chain — 8 chains). Caching, idempotent retries, cross-seller Smart Order Router.",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "exports": {
@@ -27,7 +27,9 @@
27
27
  "solana",
28
28
  "polygon",
29
29
  "arbitrum",
30
+ "monad",
30
31
  "stellar",
32
+ "algorand",
31
33
  "proof-of-work",
32
34
  "http-402",
33
35
  "micropayments",