agent402-client 0.8.8 → 0.8.10

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 +8 -8
  2. package/index.js +5 -2
  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 by card through a prepaid credits key. Results are cached, and every
8
+ provide, or through a prepaid credits key already issued. 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").
@@ -55,7 +55,7 @@ The SDK's spending caps, reservations and caching apply identically on the MPP
55
55
  path (pinned by `scripts/test-client-mpp.js` in the parent repo, which buys
56
56
  through the SDK with a real mppx client).
57
57
 
58
- **Over x402** with [`@x402/fetch`](https://www.npmjs.com/package/@x402/fetch) - USDC on any of the 12 x402 chains:
58
+ **Over x402** with [`@x402/fetch`](https://www.npmjs.com/package/@x402/fetch) - this snippet registers the EVM scheme, so it pays USDC on the EVM x402 chains; register the matching scheme package as well to pay on Solana, Stellar or Algorand:
59
59
 
60
60
  ```js
61
61
  import { wrapFetchWithPayment } from "@x402/fetch";
@@ -71,15 +71,15 @@ const a = new Agent402({ fetch: payFetch });
71
71
  const article = await a.call("extract", { url: "https://example.com/article" });
72
72
  ```
73
73
 
74
- ## Pay by card instead of a wallet (prepaid credits)
74
+ ## Prepaid credits (keys already issued)
75
75
 
76
- Buy a credits pack ($20 / $50 / $100) at https://agent402.tools/credits, claim the
77
- `a402_...` key once, and pass it as `creditsKey`. The SDK then sends
78
- `Authorization: Bearer a402_...` on wallet-only calls; the server authorizes
76
+ New credits are not on sale. A key already issued (`a402_...`) still works: pass it
77
+ 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
79
  against the key's balance before the handler runs and debits the list price only
80
80
  on a successful (200) response (the `X-Credits-Balance` header carries what is
81
- left; credits never expire). A refused call throws with the balance and a top-up
82
- link; nothing is debited.
81
+ left; credits never expire). A refused call throws with the balance; nothing is
82
+ debited.
83
83
 
84
84
  ```js
85
85
  const client = new Agent402({ creditsKey: "a402_..." });
package/index.js CHANGED
@@ -23,7 +23,7 @@ import { createHash, randomBytes } from "node:crypto";
23
23
  // `User-Agent: agent402-client/<version>` - a standard header, no extra
24
24
  // network calls - so a seller can attribute traffic (and settled payments)
25
25
  // to this SDK. Product token only; nothing about the caller rides along.
26
- const VERSION = "0.8.8";
26
+ const VERSION = "0.8.10";
27
27
  const USER_AGENT = `agent402-client/${VERSION}`;
28
28
  // 32MB: about a hundred times any realistic response from this catalog (the
29
29
  // largest is a base64 image at a few MB), so it cannot break a legitimate
@@ -519,7 +519,10 @@ export class Agent402 {
519
519
  let detail = "";
520
520
  try {
521
521
  const body = await r.json();
522
- const msg = body?.error ?? body?.message ?? body?.detail;
522
+ // A refused payment that says what went wrong carries that sentence in
523
+ // `detail` (an RFC 9457 problem) or `hint` (an x402 refusal), with no
524
+ // `error`; a seller's plain error keeps its place first.
525
+ const msg = body?.error ?? body?.message ?? body?.detail ?? body?.hint;
523
526
  if (msg != null) detail = ` - ${typeof msg === "string" ? msg : JSON.stringify(msg)}`;
524
527
  if (body?.expected != null) detail += ` (expected: ${JSON.stringify(body.expected)})`;
525
528
  } catch { /* not JSON: the status is the whole story */ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent402-client",
3
- "version": "0.8.8",
3
+ "version": "0.8.10",
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",