@weftlabs/sdk 0.29.0 → 0.31.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.
package/README.md CHANGED
@@ -56,8 +56,9 @@ and is executed from the packed npm artifact in CI.
56
56
 
57
57
  ## Bounded paid fetch
58
58
 
59
- Every paid fetch needs an explicit spending ceiling. Supply an idempotency key
60
- and reuse that same key when retrying after a timeout or uncertain response.
59
+ Every paid fetch needs an explicit `maxCostUsd` merchant-principal ceiling;
60
+ it excludes gas, provider fees, and prerequisite operations. Supply an
61
+ idempotency key and preserve it if you decide to retry the same purchase.
61
62
 
62
63
  ```js
63
64
  import { randomUUID } from "node:crypto";
@@ -80,8 +81,51 @@ const artifact = await weft.fetch(
80
81
  console.log({ idempotencyKey, artifact });
81
82
  ```
82
83
 
83
- Do not create a new key for a retry of the same logical purchase. The CLI
84
- generates a key automatically and returns it in its success envelope.
84
+ Do not create a new key for a retry of the same logical purchase. Reuse the
85
+ key from the first attempt.
86
+
87
+ ### Opt-in refill and total-cost controls
88
+
89
+ These fields require a server that supports and enforces them. Their presence
90
+ in the SDK does not establish server support. Omitting both preserves legacy
91
+ behavior, including eligible Tempo refills.
92
+
93
+ - `allowTempoRefill: false` prevents the request from creating, adopting, or
94
+ enqueueing a Base-to-Tempo refill. It does not select a payment rail or bound
95
+ fees. Unrelated bridges remain unchanged.
96
+ - `maxTotalCostUsd` is an all-in buyer-debit ceiling covering merchant principal,
97
+ gas, provider fees, and prerequisite buyer-paid operations. Supply a decimal
98
+ string with at most six fractional digits. It implies no refill; explicitly
99
+ combining it with `allowTempoRefill: true` is invalid and the server returns
100
+ `422 INCOMPATIBLE_FETCH_CONTROLS`.
101
+
102
+ For example, the request fields for an all-in bound are:
103
+
104
+ ```js
105
+ const request = {
106
+ url: "https://merchant.example/data",
107
+ maxCostUsd: "0.050000",
108
+ allowTempoRefill: false,
109
+ maxTotalCostUsd: "0.050000",
110
+ };
111
+ ```
112
+
113
+ There is currently no supported binding upstream guarantee for all buyer costs.
114
+ The bounded-fetch contract therefore refuses bounded paid requests with
115
+ `402 TOTAL_COST_UNVERIFIABLE` before payment preparation, approval, reservation,
116
+ or refill. It also refuses recovery of older payments and SIWX wallet signing
117
+ in this mode. This is not a working bounded paid route: estimates, expected
118
+ sponsorship, and receipts cannot supply the missing cost authority. Raising
119
+ the ceiling does not resolve this refusal. Stored-result replay describes a
120
+ historical payment, not a new bounded authorization.
121
+
122
+ `WeftClient.fetch` preserves failures as `WeftError` and never automatically
123
+ retries, raises bounds, or enables refill. A `409`, unknown error, or uncertain
124
+ network outcome is not permission to retry or relax controls; `retryable: true`
125
+ is not payment authorization. If your application decides a retry is appropriate,
126
+ keep the same idempotency key, request attribution, and safety controls. Changing
127
+ controls under a reserved key can produce `IDEMPOTENCY_CONFLICT`. A later refusal
128
+ does not cancel an earlier uncertain payment or release its hold.
85
129
 
86
130
  ## Retrieve a wallet-protected result
87
131
 
@@ -111,23 +155,10 @@ fresh provider state even when the idempotency key is repeated. Do not repeat
111
155
  the paid submission to poll. `SIWX_RETRIEVAL_FAILED` means the challenge was
112
156
  unsafe or authentication failed; keep the zero ceiling when investigating.
113
157
 
114
- ## CLI
115
-
116
- The `weft` executable is published separately as `@weftlabs/cli`.
117
-
118
- ```sh
119
- npx --package @weftlabs/cli weft me
120
- npx --package @weftlabs/cli weft balance
121
- npx --package @weftlabs/cli weft search "weather data API" --max-results 5
122
- npx --package @weftlabs/cli weft fetch "https://merchant.example/data" \
123
- --max-cost-usd 0.05
124
- ```
158
+ ## Command-line client
125
159
 
126
- The CLI accepts credentials from `--api-key-stdin`, `WEFT_API_KEY`, or its
127
- protected local stored OAuth/bootstrap credentials. It never accepts a key in
128
- process arguments. Every response is a versioned JSON envelope suitable for
129
- scripts. See the [CLI guide](../cli/README.md) for credential-free bootstrap,
130
- human claim, and automatic Skill installation.
160
+ The `weft` executable is a separate package. See
161
+ [weftlabs/weft-cli](https://github.com/weftlabs/weft-cli).
131
162
 
132
163
  ## Error handling
133
164
 
@@ -152,6 +183,7 @@ try {
152
183
  code: error.code,
153
184
  requestId: error.requestId,
154
185
  retryable: error.retryable,
186
+ charge: error.charge,
155
187
  details: error.details,
156
188
  });
157
189
  }
@@ -170,9 +202,18 @@ try {
170
202
  - `429`: honor `Retry-After` and back off.
171
203
  - `5xx`: retry transient failures with backoff; reuse the idempotency key for a
172
204
  paid fetch.
173
- - `status: 0` (`NETWORK_ERROR`): the request failed before any Weft response,
174
- so the outcome is uncertain. `retryable` is `true`; retry with backoff and
175
- reuse the idempotency key for a paid fetch.
205
+ - `status: 0` (`NETWORK_ERROR`): no Weft response was received, so the outcome
206
+ is uncertain. `retryable` is `true`, but does not authorize another payment.
207
+ If retrying is appropriate, use backoff and preserve the paid fetch's
208
+ idempotency key, attribution, and safety controls.
209
+ - `charge`: `"none"` means this call cannot have paid. For a fetch, Weft
210
+ refused before it signed a payment (for example `EXCEEDED_MAX_COST` or
211
+ `MERCHANT_RETURNED_NON_402`). `"possible"` means this fetch can have paid
212
+ (a 5xx, a network error, `PAID_DELIVERY_FAILED`). After `"possible"`, retry
213
+ only with the same idempotency key and the same request: Weft returns the
214
+ stored response or reuses the existing payment. A new key can pay again.
215
+ `"none"` covers this call only; an earlier call with the same key can still
216
+ have paid.
176
217
 
177
218
  ## Advanced generated APIs
178
219
 
@@ -136,7 +136,7 @@ function createFacilitatorClient(config, weftAuthHeaders) {
136
136
  }
137
137
 
138
138
  // package.json
139
- var version = "0.29.0";
139
+ var version = "0.31.0";
140
140
 
141
141
  // src/facilitator/middleware/product.ts
142
142
  var PRODUCT_TYPES = ["api", "agent", "mcp"];