agent402-client 0.8.17 → 0.8.18

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 +19 -6
  2. package/index.js +4 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -5,7 +5,7 @@ instance) - the buy side of [Agentic Finance](https://agent402.tools/agentic-fin
5
5
  agents paying per request over x402 or MPP. **Resolve a task to a tool, then call it - with payment handled for
6
6
  you.** Free pure-CPU tools settle with a built-in proof-of-work (no wallet, zero
7
7
  dependencies); wallet-only tools settle via an x402- or MPP-wrapped fetch you
8
- provide, or through a prepaid credits key already issued. Results are cached, and every
8
+ provide, or through a prepaid credits key. Results are cached, and every
9
9
  send carries an `Idempotency-Key` that is stable per client and per operation, so
10
10
  a retried lost response replays the paid answer on the credits and proof-of-work
11
11
  paths (the wallet path is different: see "Retries and double charges").
@@ -71,11 +71,14 @@ const a = new Agent402({ fetch: payFetch });
71
71
  const article = await a.call("extract", { url: "https://agent402.tools/guides/x402-in-5-minutes" });
72
72
  ```
73
73
 
74
- ## Prepaid credits (keys already issued)
74
+ ## Paying with a credits key
75
75
 
76
- New credits are not on sale. A key already issued (`a402_...`) still works: pass it
76
+ A prepaid credits key (`a402_...`; agent402.tools/credits says whether packs are on
77
+ sale) pays for Agent402's own services: pass it
77
78
  as `creditsKey` and the SDK sends `Authorization: Bearer a402_...` on wallet-only
78
- calls (the wallet-scoped routes, memory and usage, refuse it and need a wallet); the server authorizes
79
+ calls (the wallet-scoped routes, memory and usage, refuse it and need a wallet, as do
80
+ the routes that buy from an outside seller: the route-execute tiers,
81
+ `seller-payability`, `decide-execute` and the flight routes); the server authorizes
79
82
  against the key's balance before the handler runs and debits the list price only
80
83
  on a successful (200) response (the `X-Credits-Balance` header carries what is
81
84
  left; credits never expire). A refused call throws with the balance; nothing is
@@ -116,7 +119,17 @@ What the server does with it depends on how the call was paid:
116
119
  dedupe). So on the wallet path a retry after a lost response can settle twice;
117
120
  the `Idempotency-Key` cannot prevent that on its own. If that matters for your
118
121
  workload, use a credits key for the tools you retry, or keep the signed
119
- request and resend it yourself.
122
+ request and resend it yourself. A resent signed request needs no key: the
123
+ server answers a request re-sent with the same signed EVM payment, to the same
124
+ route with the same body, from its first answer inside the replay window,
125
+ with no second settlement, and marks it `X-Replayed-Answer: 1` (identity-bound
126
+ routes, routes with a lasting effect and streamed calls excepted).
127
+ - **Circle Gateway batched option:** where the server offers it on Arc or Base,
128
+ the 402 carries a second accept whose `extra.name` is `GatewayWalletBatched`.
129
+ This package pays the plain accept on those networks (the stock x402 client
130
+ takes the first accept it can pay, and the plain one is first); the batched
131
+ one needs a client that signs under the Gateway domain against a Circle
132
+ Gateway deposit.
120
133
 
121
134
  ## Workflows (skill packs)
122
135
 
@@ -361,7 +374,7 @@ each call reserves its amount synchronously, so N simultaneous calls can't each
361
374
  pass against the same pre-commit total.
362
375
 
363
376
  - **Zero dependencies** for the free/proof-of-work path (uses `node:crypto`).
364
- - **Non-custodial:** paid settlement is your `@x402/fetch` / `mppx` fetch + wallet (or a prepaid credits key you bought); this client never sees a private key.
377
+ - **Non-custodial:** paid settlement is your `@x402/fetch` / `mppx` fetch + wallet (or a prepaid credits key); this client never sees a private key.
365
378
  - MIT licensed. Part of [Agent402](https://github.com/MikeyPetrillo/Agent402).
366
379
 
367
380
  ## Pick the settlement chain (`withNetworkPreference`)
package/index.js CHANGED
@@ -30,7 +30,7 @@ export { AsyncJobPendingError } from "./async-job.js";
30
30
  // `User-Agent: agent402-client/<version>` - a standard header, no extra
31
31
  // network calls - so a seller can attribute traffic (and settled payments)
32
32
  // to this SDK. Product token only; nothing about the caller rides along.
33
- const VERSION = "0.8.17";
33
+ const VERSION = "0.8.18";
34
34
  const USER_AGENT = `agent402-client/${VERSION}`;
35
35
  // 32MB: about a hundred times any realistic response from this catalog (the
36
36
  // largest is a base64 image at a few MB), so it cannot break a legitimate
@@ -94,8 +94,8 @@ export class Agent402 {
94
94
  * @param {string[]} [opts.payNetworks] the chains your pre-wrapped `fetch` pays on (e.g. ["base"], the
95
95
  * names withNetworkPreference takes): without an x402Client the
96
96
  * caps count the dearest accept on these chains, not on every chain
97
- * @param {string} [opts.creditsKey] a prepaid card-credits key (a402_...) already issued (new credits are
98
- * not on sale) - pays wallet-only tools when no payFetch is given
97
+ * @param {string} [opts.creditsKey] a prepaid card-credits key (a402_...) - pays wallet-only tools on
98
+ * Agent402's own services when no payFetch is given
99
99
  * @param {number|null} [opts.maxResponseBytes=33554432]
100
100
  * Hard ceiling on a response body, enforced BEFORE it is parsed. null disables it.
101
101
  * @param {{id:string, validate:function}} [opts.outputValidator]
@@ -581,7 +581,7 @@ export class Agent402 {
581
581
  }
582
582
  const r = await send(); // no wallet - succeeds only on a FREE_MODE instance
583
583
  if (r.ok) return this._deliverResponse(slug, r, cacheKey, cache, validator, { maxResponseBytes, paid: false });
584
- throw this._fail(slug, r, `call "${slug}" failed: HTTP ${r.status} - wallet-only tool; construct with { fetch: payFetch } (an @x402/fetch-wrapped fetch) or { creditsKey } (a prepaid credits key already issued; new credits are not on sale)`);
584
+ throw this._fail(slug, r, `call "${slug}" failed: HTTP ${r.status} - wallet-only tool; construct with { fetch: payFetch } (an @x402/fetch-wrapped fetch) or { creditsKey } (a prepaid credits key; routes that buy from an outside seller need a wallet)`);
585
585
  }
586
586
 
587
587
  // Free (compute-payable) tool: succeeds plainly on a FREE_MODE instance,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent402-client",
3
- "version": "0.8.17",
3
+ "version": "0.8.18",
4
4
  "description": "Agent402 buyer SDK: resolve a task to a tool across 500+ pay-per-call endpoints and call it with payment handled - free via proof-of-work, or over x402 or MPP (a stock mppx fetch works) with a wallet you keep; the buy side of Agentic Finance. Caching, idempotent retries (Idempotency-Key), non-custodial, zero dependencies.",
5
5
  "type": "module",
6
6
  "main": "index.js",