@haven_ai/sdk 0.2.0-alpha.0 → 0.2.1-alpha.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 +13 -6
- package/dist/index.cjs +201 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +260 -76
- package/dist/index.d.ts +260 -76
- package/dist/index.js +200 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -123,7 +123,26 @@ var AgentPaymentNextAction = {
|
|
|
123
123
|
* settled to the merchant. The wallet owner should initiate a sweep to
|
|
124
124
|
* return those funds to the originating Safe.
|
|
125
125
|
*/
|
|
126
|
-
SweepStrandedFunds: "sweep_stranded_funds"
|
|
126
|
+
SweepStrandedFunds: "sweep_stranded_funds",
|
|
127
|
+
/**
|
|
128
|
+
* #2970: a `submitted` erc7710 x402 intent whose settlement window has
|
|
129
|
+
* passed with no on-chain settlement evidence Haven could verify. Distinct
|
|
130
|
+
* from {@link CheckStatusLater}, which this REPLACES once the window is
|
|
131
|
+
* past — but it is not futile: Haven's settlement sweep (120s tick) scans
|
|
132
|
+
* each candidate over its own window plus a 120s clock-skew allowance, so
|
|
133
|
+
* it can still attribute the settlement for a short while after this value
|
|
134
|
+
* first appears. Poll {@link CheckStatusLater}'s tool
|
|
135
|
+
* (`haven_get_payment_status`) once more, roughly two minutes later; if it
|
|
136
|
+
* still shows no evidence, tell the user the goods were delivered but
|
|
137
|
+
* Haven holds no verified settlement evidence for this payment. If the
|
|
138
|
+
* agent holds the merchant's real settlement transaction hash (from
|
|
139
|
+
* `PAYMENT-RESPONSE`'s `transaction` field, or a prior settle/complete
|
|
140
|
+
* result's `settlement_tx_hash`), report it with the hosted
|
|
141
|
+
* `haven_report_settlement_evidence` tool instead of waiting —
|
|
142
|
+
* `haven_report_x402_outcome` takes no hash and refuses a non-`confirmed`
|
|
143
|
+
* intent.
|
|
144
|
+
*/
|
|
145
|
+
AwaitingSettlementEvidence: "awaiting_settlement_evidence"
|
|
127
146
|
};
|
|
128
147
|
var AgentPaymentNextActionAccountAlias = {
|
|
129
148
|
/** Account-vocabulary twin of `fund_safe_or_raise_allowance`; same meaning. */
|
|
@@ -143,12 +162,14 @@ var AgentPaymentFailureCode = {
|
|
|
143
162
|
PriceExceedsMax: "PRICE_EXCEEDS_MAX",
|
|
144
163
|
/** The x402 funding/quote window expired before the signer or hosted settle step could finish. */
|
|
145
164
|
PaymentWindowExpired: "PAYMENT_WINDOW_EXPIRED",
|
|
146
|
-
/** The
|
|
165
|
+
/** The merchant rejected the paid retry. On eip3009 the funding leg had succeeded (sweep);
|
|
166
|
+
* on erc7710 there is no funding leg — nothing to sweep, follow the message (#2983). */
|
|
147
167
|
MerchantRejectedAfterFunding: "MERCHANT_REJECTED_AFTER_FUNDING",
|
|
148
168
|
/** #1300 review: funding is on-chain but the merchant never ANSWERED the
|
|
149
169
|
* paid retry within the timeout. NOT proof of rejection — the merchant
|
|
150
|
-
*
|
|
151
|
-
*
|
|
170
|
+
* may still settle late, so the guidance is verify-then-act. On eip3009
|
|
171
|
+
* the funding leg had succeeded (verify-then-sweep); on erc7710 there is
|
|
172
|
+
* no funding leg — nothing to sweep, follow the message (#3000). */
|
|
152
173
|
MerchantUnresponsiveAfterFunding: "MERCHANT_UNRESPONSIVE_AFTER_FUNDING",
|
|
153
174
|
/**
|
|
154
175
|
* #1307: the caller omitted merchant_url/tool_name (asking Haven to
|
|
@@ -174,7 +195,17 @@ var AgentPaymentFailureCode = {
|
|
|
174
195
|
* asset can represent (truncating it would silently change the user's cap).
|
|
175
196
|
* The fallback is the exact atomic `max_amount`.
|
|
176
197
|
*/
|
|
177
|
-
MaxAmountUnconvertible: "MAX_AMOUNT_UNCONVERTIBLE"
|
|
198
|
+
MaxAmountUnconvertible: "MAX_AMOUNT_UNCONVERTIBLE",
|
|
199
|
+
/**
|
|
200
|
+
* #2979: the merchant answered a `tools/call` probe with its own
|
|
201
|
+
* machine-readable "cannot settle right now" refusal (HTTP 503,
|
|
202
|
+
* `{ error: 'merchant_not_ready', reason_code, ... }`) instead of a 402
|
|
203
|
+
* challenge — e.g. its settlement wallet is out of gas. No 402 was ever
|
|
204
|
+
* issued and no payment was created; this is honest and (per
|
|
205
|
+
* `retry_after_s`, when present) usually transient, unlike a permanent
|
|
206
|
+
* endpoint miss.
|
|
207
|
+
*/
|
|
208
|
+
MerchantNotReady: "MERCHANT_NOT_READY"
|
|
178
209
|
};
|
|
179
210
|
var AgentPaymentRail = {
|
|
180
211
|
/** Standard Haven payment from the user's Safe through an approved delegate allowance. */
|
|
@@ -222,16 +253,18 @@ var AgentPaymentNextActionDescriptions = {
|
|
|
222
253
|
[AgentPaymentNextAction.PaymentWindowExpired]: "The x402 funding/quote window expired. Re-quote with the same idempotency key before asking the signer to build a merchant payment header again.",
|
|
223
254
|
[AgentPaymentNextAction.FundSafeOrRaiseAllowance]: "Stop and tell the user that the account needs to be funded or the agent budget raised before the payment can succeed.",
|
|
224
255
|
[AgentPaymentNextAction.RetryWithExplicitContext]: "Retry the same tool call, this time passing merchant_url, tool_name, arguments, and mcp_transport explicitly \u2014 the server had no stored context to rehydrate for this payment id.",
|
|
225
|
-
[AgentPaymentNextAction.SweepStrandedFunds]: "Tell the user that funds may be stranded in the delegate wallet and prompt them to initiate a sweep in Haven to return them to the originating account."
|
|
256
|
+
[AgentPaymentNextAction.SweepStrandedFunds]: "Tell the user that funds may be stranded in the delegate wallet and prompt them to initiate a sweep in Haven to return them to the originating account.",
|
|
257
|
+
[AgentPaymentNextAction.AwaitingSettlementEvidence]: "The settlement window passed with no verified on-chain evidence yet. If you hold the merchant's real settlement transaction hash, report it with haven_report_settlement_evidence. Otherwise, Haven's settlement sweep may still attribute it within about two minutes \u2014 poll getPaymentStatus once more, then tell the user the goods were delivered but unverified if it still shows nothing."
|
|
226
258
|
};
|
|
227
259
|
var AgentPaymentFailureCodeDescriptions = {
|
|
228
260
|
[AgentPaymentFailureCode.PriceExceedsMax]: "The merchant-authoritative x402 amount exceeds the caller's max_amount cap. No funding transfer was created; ask the user before retrying with a larger cap.",
|
|
229
261
|
[AgentPaymentFailureCode.PaymentWindowExpired]: "The x402 funding/quote window expired before the signer or hosted settle step could finish. Re-quote via haven_pay_mcp_tool with the same idempotency key to avoid duplicate funding.",
|
|
230
|
-
[AgentPaymentFailureCode.MerchantRejectedAfterFunding]: "The
|
|
231
|
-
[AgentPaymentFailureCode.MerchantUnresponsiveAfterFunding]: "The
|
|
262
|
+
[AgentPaymentFailureCode.MerchantRejectedAfterFunding]: "The merchant rejected the paid retry. eip3009: the funding leg succeeded \u2014 stop retrying the merchant and reconcile stranded delegate funds with haven_sweep_delegate. erc7710: no funding leg, nothing to sweep \u2014 follow the message (re-quote later, or check haven_get_payment_status after the window first).",
|
|
263
|
+
[AgentPaymentFailureCode.MerchantUnresponsiveAfterFunding]: "The merchant did not answer the paid retry before the timeout. The merchant may still settle late. eip3009: the funding leg succeeded \u2014 check haven_get_payment_status, retry haven_complete_mcp_tool once, sweep only if no settlement appears. erc7710: no funding leg, nothing to sweep, and haven_complete_mcp_tool has no erc7710 branch \u2014 do not retry it; check haven_get_payment_status after the payment window and re-quote only if it shows no settlement.",
|
|
232
264
|
[AgentPaymentFailureCode.MerchantCallContextUnavailable]: "merchant_url/tool_name were omitted and no stored merchant call context is available for this payment_id. Re-send merchant_url, tool_name, arguments, and mcp_transport explicitly.",
|
|
233
265
|
[AgentPaymentFailureCode.AmbiguousMaxAmount]: "Both max_amount (atomic units) and max_amount_human (whole tokens) were supplied for one purchase. Nothing was contacted and nothing was spent. Re-send with exactly ONE: max_amount_human for a cap the user stated in tokens, max_amount for an exact atomic figure.",
|
|
234
|
-
[AgentPaymentFailureCode.MaxAmountUnconvertible]: "max_amount_human could not be converted to atomic units against this quote's asset \u2014 either its decimals are unknown to Haven or the cap has more decimal places than the asset supports. Nothing was spent. Round the cap, or re-send it as an exact atomic max_amount."
|
|
266
|
+
[AgentPaymentFailureCode.MaxAmountUnconvertible]: "max_amount_human could not be converted to atomic units against this quote's asset \u2014 either its decimals are unknown to Haven or the cap has more decimal places than the asset supports. Nothing was spent. Round the cap, or re-send it as an exact atomic max_amount.",
|
|
267
|
+
[AgentPaymentFailureCode.MerchantNotReady]: 'The merchant refused the probe with its own "cannot settle right now" signal instead of a 402 challenge. No payment was created. Often transient \u2014 retry later (see retry_after_s in the message, if given) rather than treating this as a broken or wrong endpoint.'
|
|
235
268
|
};
|
|
236
269
|
var AgentPaymentWarningCode = {
|
|
237
270
|
/** No max_amount cap was supplied — the live quoted price was accepted as-is. */
|
|
@@ -262,7 +295,24 @@ var AgentPaymentWarningCode = {
|
|
|
262
295
|
* on-chain policy re-checks at redemption either way; this only says the
|
|
263
296
|
* guidance shown here may be optimistic.
|
|
264
297
|
*/
|
|
265
|
-
AllowanceReadOptimistic: "ALLOWANCE_READ_OPTIMISTIC"
|
|
298
|
+
AllowanceReadOptimistic: "ALLOWANCE_READ_OPTIMISTIC",
|
|
299
|
+
/**
|
|
300
|
+
* #2991: the quote tools' `expected_settlement_scheme` prediction of what
|
|
301
|
+
* `haven_prepare_catalog_purchase` / `haven_pay_mcp_tool` will actually
|
|
302
|
+
* select could not be computed — the agent's execution rail could not be
|
|
303
|
+
* read from Haven, so `expected_settlement_scheme` is `null` rather than a
|
|
304
|
+
* guess. `accepted_scheme` (the merchant's offer) is unaffected.
|
|
305
|
+
*/
|
|
306
|
+
X402SchemeUnknown: "X402_SCHEME_UNKNOWN",
|
|
307
|
+
/**
|
|
308
|
+
* #2968: the merchant answered 200 and handed over goods, but Haven holds NO
|
|
309
|
+
* on-chain evidence that the payment moved. `settled: false` beside this code
|
|
310
|
+
* is not a failure — it is the absence of proof, and the two must travel
|
|
311
|
+
* together so an agent can tell "the user has the goods" apart from "the
|
|
312
|
+
* money moved". Carries the intent's `expires_at`: after that instant the
|
|
313
|
+
* settlement can no longer land at all.
|
|
314
|
+
*/
|
|
315
|
+
SettlementUnconfirmed: "SETTLEMENT_UNCONFIRMED"
|
|
266
316
|
};
|
|
267
317
|
var AgentPaymentRailDescriptions = {
|
|
268
318
|
[AgentPaymentRail.Direct]: "Standard Haven payment from the user-controlled account, redeeming the agent's on-chain budget delegation.",
|
|
@@ -326,8 +376,18 @@ var MerchantTimeoutError = class extends HavenApiError {
|
|
|
326
376
|
};
|
|
327
377
|
var X402UnexpectedStatusError = class extends HavenApiError {
|
|
328
378
|
x402ErrorCode = "unexpected_non_402_status";
|
|
329
|
-
|
|
330
|
-
|
|
379
|
+
/**
|
|
380
|
+
* #2979: `body` is the merchant's own JSON, when the non-402 response
|
|
381
|
+
* carried one — e.g. the demo merchant's `/mcp` readiness gate answers
|
|
382
|
+
* `503 { error: 'merchant_not_ready', reason_code, ... }`. Optional and
|
|
383
|
+
* best-effort: a non-JSON or unreadable body leaves this `undefined`, same
|
|
384
|
+
* as before this field existed. Consumers key on it (not on the message
|
|
385
|
+
* string) to distinguish an honest, machine-readable merchant refusal from
|
|
386
|
+
* a genuine "this is not the x402 endpoint" miss, which otherwise look
|
|
387
|
+
* identical — both are just "some non-402 status".
|
|
388
|
+
*/
|
|
389
|
+
constructor(message, statusCode, body) {
|
|
390
|
+
super(message, statusCode, body);
|
|
331
391
|
this.name = "X402UnexpectedStatusError";
|
|
332
392
|
}
|
|
333
393
|
};
|
|
@@ -366,6 +426,17 @@ var HavenSigningError = class extends HavenError {
|
|
|
366
426
|
this.name = "HavenSigningError";
|
|
367
427
|
}
|
|
368
428
|
};
|
|
429
|
+
var HavenZeroSettlementHashError = class extends HavenError {
|
|
430
|
+
constructor(paymentId) {
|
|
431
|
+
super(
|
|
432
|
+
"settlement_tx_hash is the zero hash (0x00\u202600), which is never a real settlement transaction \u2014 refused before any report was sent.",
|
|
433
|
+
"ZERO_SETTLEMENT_HASH",
|
|
434
|
+
400,
|
|
435
|
+
paymentId
|
|
436
|
+
);
|
|
437
|
+
this.name = "HavenZeroSettlementHashError";
|
|
438
|
+
}
|
|
439
|
+
};
|
|
369
440
|
var SignerRefusalCode = {
|
|
370
441
|
/** `SUPPORTED_X402_EXPECTED_VERSIONS` in `@haven_ai/signer` does not include the received version. */
|
|
371
442
|
UnsupportedExpectedContextVersion: "UNSUPPORTED_EXPECTED_CONTEXT_VERSION",
|
|
@@ -1114,6 +1185,15 @@ var HavenApiTransport = class {
|
|
|
1114
1185
|
};
|
|
1115
1186
|
|
|
1116
1187
|
// src/payment-mappers.ts
|
|
1188
|
+
function mapParties(raw) {
|
|
1189
|
+
if (!raw) return void 0;
|
|
1190
|
+
return {
|
|
1191
|
+
treasuryAccount: raw.treasury_account,
|
|
1192
|
+
delegate: raw.delegate,
|
|
1193
|
+
delegateAccount: raw.delegate_account,
|
|
1194
|
+
merchant: raw.merchant
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1117
1197
|
function mapPaymentResult(raw, buildExplorerUrl2) {
|
|
1118
1198
|
return {
|
|
1119
1199
|
paymentId: raw.payment_id,
|
|
@@ -1153,6 +1233,7 @@ function mapPaymentStatusResult(raw) {
|
|
|
1153
1233
|
resourceUrl: raw.resource_url,
|
|
1154
1234
|
merchantAddress: raw.merchant_address,
|
|
1155
1235
|
payerAddress: raw.payer_address ?? null,
|
|
1236
|
+
parties: mapParties(raw.parties),
|
|
1156
1237
|
txHash: raw.tx_hash,
|
|
1157
1238
|
expiresAt: raw.expires_at,
|
|
1158
1239
|
chainId: raw.chain_id,
|
|
@@ -1186,10 +1267,13 @@ function mapPaymentReceipt(raw) {
|
|
|
1186
1267
|
rail: raw.rail,
|
|
1187
1268
|
proofStatus: raw.proof_status,
|
|
1188
1269
|
txHash: raw.tx_hash,
|
|
1270
|
+
fundingTxHash: raw.funding_tx_hash ?? null,
|
|
1271
|
+
settlementTxHash: raw.settlement_tx_hash ?? null,
|
|
1189
1272
|
chainId: raw.chain_id,
|
|
1190
1273
|
resourceUrl: raw.resource_url,
|
|
1191
1274
|
merchantAddress: raw.merchant_address,
|
|
1192
1275
|
payerAddress: raw.payer_address,
|
|
1276
|
+
parties: mapParties(raw.parties),
|
|
1193
1277
|
settlementAddress: raw.settlement_address,
|
|
1194
1278
|
tokenSymbol: raw.token_symbol,
|
|
1195
1279
|
tokenAddress: raw.token_address,
|
|
@@ -2913,15 +2997,57 @@ var MerchantCompletion = class {
|
|
|
2913
2997
|
for (let attempt = 0; ; attempt += 1) {
|
|
2914
2998
|
try {
|
|
2915
2999
|
await this.post("/machine-payments/evidence", body);
|
|
2916
|
-
return;
|
|
3000
|
+
return { outcome: "confirmed" };
|
|
2917
3001
|
} catch (err) {
|
|
2918
|
-
const
|
|
2919
|
-
|
|
3002
|
+
const statusCode = err instanceof HavenApiError ? err.statusCode : void 0;
|
|
3003
|
+
const retryable = statusCode === EVIDENCE_RETRYABLE_STATUS;
|
|
3004
|
+
if (!retryable) {
|
|
3005
|
+
return { outcome: "refused", statusCode: statusCode ?? 0 };
|
|
3006
|
+
}
|
|
3007
|
+
if (attempt >= EVIDENCE_RETRY_DELAYS_MS.length) {
|
|
3008
|
+
return { outcome: "retryable", statusCode };
|
|
3009
|
+
}
|
|
2920
3010
|
await this.sleep(EVIDENCE_RETRY_DELAYS_MS[attempt]);
|
|
2921
3011
|
}
|
|
2922
3012
|
}
|
|
2923
3013
|
}
|
|
3014
|
+
/**
|
|
3015
|
+
* #2972: report the merchant's REAL settlement transaction hash for an
|
|
3016
|
+
* erc7710 x402 payment out of band — the remedy #2970's guidance could not
|
|
3017
|
+
* name, because no hosted tool accepted a hash. An agent reaches this after
|
|
3018
|
+
* `haven_settle_mcp_tool` / `haven_complete_mcp_tool` answered
|
|
3019
|
+
* `DELIVERED_UNSETTLED` or `SETTLEMENT_PENDING`, or after
|
|
3020
|
+
* `haven_get_payment_status` reports `awaiting_settlement_evidence` — in
|
|
3021
|
+
* every one of those cases the agent may be holding the merchant's own
|
|
3022
|
+
* `PAYMENT-RESPONSE.transaction` while Haven has nothing.
|
|
3023
|
+
*
|
|
3024
|
+
* Reuses `reportEvidence` — same backend seam
|
|
3025
|
+
* (`POST /machine-payments/evidence` → `observeErc7710Settlement`,
|
|
3026
|
+
* fail-closed — see `settlement-observed.ts`), same three-outcome contract.
|
|
3027
|
+
* `resourceUrl` and `merchantStatus` are omitted: this call has no fresh
|
|
3028
|
+
* merchant HTTP exchange to read either from, and both are optional at the
|
|
3029
|
+
* backend (see the parameter doc on `reportEvidence`).
|
|
3030
|
+
*
|
|
3031
|
+
* The zero hash is refused HERE, client-side, before any network call —
|
|
3032
|
+
* never posted. `isZeroSettlementTxHash` is the same recognizer the #2970
|
|
3033
|
+
* gate uses, so a caller cannot "fix" a missing hash by reporting the demo
|
|
3034
|
+
* merchant's own marker and getting a different verdict than the settle
|
|
3035
|
+
* path already gave it.
|
|
3036
|
+
*/
|
|
3037
|
+
async reportSettlementEvidence(paymentId, settlementTxHash) {
|
|
3038
|
+
if (isZeroSettlementTxHash(settlementTxHash)) {
|
|
3039
|
+
throw new HavenZeroSettlementHashError(paymentId);
|
|
3040
|
+
}
|
|
3041
|
+
return this.reportEvidence({
|
|
3042
|
+
paymentId,
|
|
3043
|
+
rail: "x402",
|
|
3044
|
+
txHash: settlementTxHash
|
|
3045
|
+
});
|
|
3046
|
+
}
|
|
2924
3047
|
};
|
|
3048
|
+
function isZeroSettlementTxHash(hash) {
|
|
3049
|
+
return typeof hash === "string" && /^0x0+$/i.test(hash);
|
|
3050
|
+
}
|
|
2925
3051
|
function parseMerchantSettlement(header) {
|
|
2926
3052
|
if (!header) return {};
|
|
2927
3053
|
const parsed = parseProtocolReceiptHeader(header);
|
|
@@ -3423,7 +3549,7 @@ var HavenClient = class {
|
|
|
3423
3549
|
const query = params.size > 0 ? `?${params.toString()}` : "";
|
|
3424
3550
|
const raw = await this.get(`/catalog${query}`);
|
|
3425
3551
|
let entries = raw.entries.map(mapCatalogEntry);
|
|
3426
|
-
if (options.verified === "verified") entries = entries.filter((e) => e.
|
|
3552
|
+
if (options.verified === "verified") entries = entries.filter((e) => e.verifiedPayable === true);
|
|
3427
3553
|
if (options.verified === "operator") entries = entries.filter((e) => e.source === "operator");
|
|
3428
3554
|
return entries;
|
|
3429
3555
|
}
|
|
@@ -3560,9 +3686,16 @@ var HavenClient = class {
|
|
|
3560
3686
|
const request = snapshotX402Request(url, initialInit);
|
|
3561
3687
|
const response = await this.merchantTransport.fetch(url, initialInit);
|
|
3562
3688
|
if (response.status !== 402) {
|
|
3689
|
+
let body;
|
|
3690
|
+
try {
|
|
3691
|
+
body = await response.clone().json();
|
|
3692
|
+
} catch {
|
|
3693
|
+
body = void 0;
|
|
3694
|
+
}
|
|
3563
3695
|
throw new X402UnexpectedStatusError(
|
|
3564
3696
|
`Expected an x402 quote response with HTTP 402, got HTTP ${response.status}.`,
|
|
3565
|
-
response.status || 400
|
|
3697
|
+
response.status || 400,
|
|
3698
|
+
body
|
|
3566
3699
|
);
|
|
3567
3700
|
}
|
|
3568
3701
|
if (response.headers.get("MACHINE-PAYMENT-CHALLENGE")) {
|
|
@@ -3851,6 +3984,7 @@ var HavenClient = class {
|
|
|
3851
3984
|
} catch {
|
|
3852
3985
|
body = text;
|
|
3853
3986
|
}
|
|
3987
|
+
let evidenceOutcome;
|
|
3854
3988
|
if (!surfaced.ok) {
|
|
3855
3989
|
if (!input.noFundingLeg && fundingTxHash) {
|
|
3856
3990
|
await this.merchantCompletion.recordRetryRejected({
|
|
@@ -3870,9 +4004,10 @@ var HavenClient = class {
|
|
|
3870
4004
|
});
|
|
3871
4005
|
}
|
|
3872
4006
|
} else {
|
|
3873
|
-
const
|
|
4007
|
+
const rawEvidenceTxHash = input.noFundingLeg ? settlement.settlementTxHash ?? void 0 : fundingTxHash ?? void 0;
|
|
4008
|
+
const evidenceTxHash = rawEvidenceTxHash && !isZeroSettlementTxHash(rawEvidenceTxHash) ? rawEvidenceTxHash : void 0;
|
|
3874
4009
|
if (evidenceTxHash) {
|
|
3875
|
-
await this.merchantCompletion.reportEvidence({
|
|
4010
|
+
evidenceOutcome = await this.merchantCompletion.reportEvidence({
|
|
3876
4011
|
paymentId: evidenceContext.paymentId,
|
|
3877
4012
|
rail: "x402",
|
|
3878
4013
|
txHash: evidenceTxHash,
|
|
@@ -3890,7 +4025,8 @@ var HavenClient = class {
|
|
|
3890
4025
|
status: surfaced.status,
|
|
3891
4026
|
ok: surfaced.ok,
|
|
3892
4027
|
body,
|
|
3893
|
-
settlementTxHash: settlement.settlementTxHash ?? void 0
|
|
4028
|
+
settlementTxHash: settlement.settlementTxHash ?? void 0,
|
|
4029
|
+
evidenceOutcome
|
|
3894
4030
|
};
|
|
3895
4031
|
}
|
|
3896
4032
|
/**
|
|
@@ -3905,6 +4041,19 @@ var HavenClient = class {
|
|
|
3905
4041
|
async reportX402MerchantOutcome(input) {
|
|
3906
4042
|
return await this.merchantCompletion.reportMerchantOutcome(input);
|
|
3907
4043
|
}
|
|
4044
|
+
/**
|
|
4045
|
+
* #2972: report the merchant's real settlement transaction hash for an
|
|
4046
|
+
* erc7710 x402 payment — the remedy for `DELIVERED_UNSETTLED` /
|
|
4047
|
+
* `SETTLEMENT_PENDING` / `awaiting_settlement_evidence` when the agent
|
|
4048
|
+
* holds the hash (`PAYMENT-RESPONSE.transaction`, or a prior settle/
|
|
4049
|
+
* complete result's `settlement_tx_hash`) and Haven does not. See
|
|
4050
|
+
* `MerchantCompletion.reportSettlementEvidence` for the fail-closed
|
|
4051
|
+
* verification this posts into (`observeErc7710Settlement`) and the
|
|
4052
|
+
* client-side zero-hash refusal.
|
|
4053
|
+
*/
|
|
4054
|
+
async reportSettlementEvidence(paymentId, settlementTxHash) {
|
|
4055
|
+
return await this.merchantCompletion.reportSettlementEvidence(paymentId, settlementTxHash);
|
|
4056
|
+
}
|
|
3908
4057
|
/**
|
|
3909
4058
|
* GET /x402/:id/merchant-call-context — the settle-leg twin of #1263's
|
|
3910
4059
|
* sign-context fetch (#1307). Re-serves the stored merchant MCP-tool call
|
|
@@ -4079,8 +4228,8 @@ var toolDescriptions = {
|
|
|
4079
4228
|
// MACHINE-PAYMENT-CHALLENGE was never produced by anything besides the now
|
|
4080
4229
|
// deleted `/demo/mpp/*` route. Use the x402 fragments above instead.
|
|
4081
4230
|
getPaymentStatus: {
|
|
4082
|
-
summary: "Fetch structured Haven payment status
|
|
4083
|
-
behavior: "
|
|
4231
|
+
summary: "Fetch structured Haven payment status for agent recovery.",
|
|
4232
|
+
behavior: "State: phase, nextAction, rail, amount, merchant, resource, idempotency, message; parties: treasury/delegate/delegateAccount/merchant. awaiting_settlement_evidence: poll once, else unverified.",
|
|
4084
4233
|
nextActionGuidance: ""
|
|
4085
4234
|
},
|
|
4086
4235
|
getResumeState: {
|
|
@@ -4120,7 +4269,7 @@ var toolDescriptions = {
|
|
|
4120
4269
|
},
|
|
4121
4270
|
discoverTools: {
|
|
4122
4271
|
summary: "Step 1 of a purchase: discover payable services from Haven's curated merchant catalog \u2014 names, prices, and which pay tool to use next.",
|
|
4123
|
-
selectionGuidance: "Use this when the user asks what the agent can buy, pay for, or which paid services exist \u2014 or when you need a resource URL for a service the user described. Use verified=verified
|
|
4272
|
+
selectionGuidance: "Use this when the user asks what the agent can buy, pay for, or which paid services exist \u2014 or when you need a resource URL for a service the user described. Use verified=verified for entries Haven watched pass a live quote probe (operator-curated or self-submitted) \u2014 domain_verified is the only ownership claim; never treat these badges as proof of merchant honesty, quality, or reliability. Do NOT use for balance, budget, or spend-limit questions \u2014 use haven_get_allowances. Do NOT use to pay \u2014 each returned entry names the pay tool to use next.",
|
|
4124
4273
|
behavior: "Use each entry's suggested_tool field first \u2014 it names the exact next call. Read-only lookup against Haven's curated catalog; entries are periodically re-verified against the live merchant and degraded entries are flagged. Use category for a case-insensitive category filter (for example, VPN or vpn), or search for a product name, category, or description term. Returns name, description, price, rail, resource URL, tool_name, tool_arguments, suggested_tool, and the provenance badges source/domain_verified/verified_payable. The catalog price (price_display/price_atomic, marked price_is_indicative) is a last-verified hint, NOT authoritative \u2014 the real price comes from the merchant's live 402 at pay time. Never creates a payment, signature, or approval.",
|
|
4125
4274
|
nextActionGuidance: `Pick an entry and pay it with the tool named in suggested_tool, passing the entry's resource_url, tool_name, and tool_arguments for MCP merchants. Confirm the price from the live pay-tool result (not the catalog), and pass the user's cap as max_amount_human in whole tokens ("no more than 1 USDC" \u2192 max_amount_human: "1") \u2014 never convert it to atomic units by hand.`
|
|
4126
4275
|
},
|
|
@@ -4141,6 +4290,11 @@ var toolDescriptions = {
|
|
|
4141
4290
|
selectionGuidance: "Use this for plain transfers \u2014 refunding a user, paying a freelancer, topping up a co-agent's wallet, or moving funds between addresses. Do NOT use for x402 paid endpoints \u2014 use haven_pay_x402 instead. Do NOT use for read-only allowance, budget, or what-can-I-spend questions \u2014 use haven_get_allowances.",
|
|
4142
4291
|
behavior: "Sends the requested amount by redeeming the agent's on-chain budget delegation, account to recipient with no funding leg. Budget, recipient and expiry are enforced on-chain while the transfer is prepared, so a request outside them is declined before any money moves and before the agent is asked to sign \u2014 it is never queued for a human to approve later. The agent's signing key signs the account's typed data; Haven never receives the key.",
|
|
4143
4292
|
nextActionGuidance: "On a decline, report the reason to the user and ask them to grant or raise the budget in Haven \u2014 there is nothing to poll and no approval will arrive. After a successful send, poll haven_get_payment_status until nextAction=none."
|
|
4293
|
+
},
|
|
4294
|
+
reportSettlementEvidence: {
|
|
4295
|
+
summary: "Report an erc7710 payment's real settlement transaction hash so Haven can verify it on-chain and confirm the payment.",
|
|
4296
|
+
behavior: "Pass payment_id and settlement_tx_hash (0x + 64 hex chars) \u2014 from PAYMENT-RESPONSE or a prior settlement_tx_hash. Haven verifies on-chain before confirming; a zero, mismatched, or reverted hash is refused. Your own payments only.",
|
|
4297
|
+
nextActionGuidance: "code DELIVERED_UNSETTLED: did not verify, do not retry \u2014 poll haven_get_payment_status. code SETTLEMENT_PENDING (retryable:true): not mined or RPC unreachable \u2014 report the same hash again shortly."
|
|
4144
4298
|
}
|
|
4145
4299
|
};
|
|
4146
4300
|
|
|
@@ -4743,15 +4897,30 @@ present and surface \`message\` or \`error\` verbatim. Common cases:
|
|
|
4743
4897
|
Round the cap, or send an exact atomic \`max_amount\`.
|
|
4744
4898
|
- \`PAYMENT_WINDOW_EXPIRED\`: re-run the quote/prepare tool with the same
|
|
4745
4899
|
\`idempotency_key\`, then sign the fresh payload.
|
|
4900
|
+
- \`MERCHANT_NOT_READY\`: the merchant refused the quote with its own
|
|
4901
|
+
"cannot settle right now" signal (a 503 \`merchant_not_ready\` with a
|
|
4902
|
+
\`reason_code\`) instead of a 402. No payment was created. Tell the user;
|
|
4903
|
+
retry later (the message carries \`retry_after_s\` when the merchant gave
|
|
4904
|
+
one) \u2014 this is not a wrong or broken endpoint.
|
|
4746
4905
|
- \`MERCHANT_REJECTED_AFTER_FUNDING\`: the merchant refused the paid retry.
|
|
4747
|
-
Stop-and-sweep \u2014 stop retrying the
|
|
4748
|
-
\`mcp__haven__haven_sweep_delegate\` to recover stranded
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4906
|
+
On eip3009 (\`rail\` not \`erc7710\`): Stop-and-sweep \u2014 stop retrying the
|
|
4907
|
+
merchant and use \`mcp__haven__haven_sweep_delegate\` to recover stranded
|
|
4908
|
+
delegate funds. On erc7710 there is no funding leg and nothing to sweep:
|
|
4909
|
+
follow the message \u2014 it says whether the merchant declined to settle
|
|
4910
|
+
(re-quote later) or whether to check \`haven_get_payment_status\` after
|
|
4911
|
+
the payment window first.
|
|
4912
|
+
- \`MERCHANT_UNRESPONSIVE_AFTER_FUNDING\`: the merchant never answered the paid
|
|
4913
|
+
retry. This is NOT proof of rejection \u2014 the merchant may still settle late.
|
|
4914
|
+
On eip3009 (\`rail\` not \`erc7710\`), funding confirmed on-chain: Verify-then-sweep,
|
|
4915
|
+
never a blind sweep \u2014 check \`mcp__haven__haven_get_payment_status\`, retry
|
|
4753
4916
|
\`mcp__haven__haven_complete_mcp_tool\` ONCE, and only sweep with
|
|
4754
|
-
\`mcp__haven__haven_sweep_delegate\` if no settlement appears.
|
|
4917
|
+
\`mcp__haven__haven_sweep_delegate\` if no settlement appears. On erc7710
|
|
4918
|
+
there is no funding leg and nothing to sweep, and
|
|
4919
|
+
\`mcp__haven__haven_complete_mcp_tool\` has no erc7710 branch (it refuses a
|
|
4920
|
+
submitted intent) \u2014 do not retry it: the merchant may still redeem the
|
|
4921
|
+
settlement authorization within the payment window, so check
|
|
4922
|
+
\`mcp__haven__haven_get_payment_status\` after that window and re-quote only
|
|
4923
|
+
if it shows no settlement.
|
|
4755
4924
|
- Budget exceeded: tell the user how much remains (from
|
|
4756
4925
|
\`mcp__haven__haven_get_allowances\`) and that they can raise the budget in
|
|
4757
4926
|
Haven.
|
|
@@ -4858,6 +5027,6 @@ function sameUrl(a, b) {
|
|
|
4858
5027
|
}
|
|
4859
5028
|
}
|
|
4860
5029
|
|
|
4861
|
-
export { AGENT_APPROVAL_RELAY_JSON_SENTENCE, AGENT_APPROVAL_RELAY_PROSE_SENTENCE, AGENT_COMMAND_MODIFICATION_SENTENCE, AGENT_JSON_MODE_SENTENCE, AGENT_LOCAL_KEY_SENTENCE, AGENT_NETWORK_ACCESS_SENTENCE, AGENT_ONBOARDING_PROMPT, AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, AGENT_README_SECTION_MD, AGENT_SECRET_HYGIENE_SENTENCE, AGENT_WIRING_COLLISION_RELAY_SENTENCE, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionAccountAlias, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, AgentPaymentWarningCode, CONNECTOR_PACKAGE_NAME, DEFAULT_CONFIRMATION_TIMEOUT_MS, DISCOVERY_MAX_BYTES, ERC7710_ASSET_TRANSFER_METHOD, HAVEN_AGENT_RUNBOOK_MD, HAVEN_CONNECTOR_CHANNEL, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_BODY_MD, HAVEN_SKILL_MD, HavenApiError, HavenClient, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, MERCHANT_DISCOVERY_PATHS, MerchantTimeoutError, RECEIPT_VERSION, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, SignerRefusalCode, TRANSFER_WITH_AUTHORIZATION_TYPES, X402AlreadySettledError, X402PaymentHeaderValidationError, X402UnexpectedStatusError, X402_LEGACY_PAYMENT_HEADER_NAME, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_PAYMENT_HEADER_NAME, X402_PAYMENT_HEADER_NAMES_SENT, X402_PAYMENT_REQUIRED_HEADER_NAME, X402_PAYMENT_RESPONSE_HEADER_NAME, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, accountAddressTwins, addressFromKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, canonicalAgentPaymentNextAction, compareNodeVersions, composeDescription, connectorRerunCommand, connectorSpec, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodePaymentProof, havenTools, isConnectorChannel, isErc7710Option, isFundAccountOrRaiseAllowance, isSupportedNodeVersion, isSweepableChain, normalizePaymentRequired, parsePaymentRequired, parsePaymentRequiredResponse, readAccountAddress, readAccountId, readX402ReceiptPayer, resolveConnectorChannel, resolveTokenFromAddress, sameUrl, selectErc7710PaymentOption, selectPaymentOption, selectStandardPaymentOption, selectX402SettlementScheme, signHash, signUserOpTypedDataForDelegation, signerUpdateFallback, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, validateStandardX402PaymentHeader, verifyPaymentReceipt, verifySignature, x402AssetTransferMethod, x402AuthorizationAmount, x402FacilitatorAddresses, x402V2PaymentEnvelope };
|
|
5030
|
+
export { AGENT_APPROVAL_RELAY_JSON_SENTENCE, AGENT_APPROVAL_RELAY_PROSE_SENTENCE, AGENT_COMMAND_MODIFICATION_SENTENCE, AGENT_JSON_MODE_SENTENCE, AGENT_LOCAL_KEY_SENTENCE, AGENT_NETWORK_ACCESS_SENTENCE, AGENT_ONBOARDING_PROMPT, AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, AGENT_README_SECTION_MD, AGENT_SECRET_HYGIENE_SENTENCE, AGENT_WIRING_COLLISION_RELAY_SENTENCE, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionAccountAlias, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, AgentPaymentWarningCode, CONNECTOR_PACKAGE_NAME, DEFAULT_CONFIRMATION_TIMEOUT_MS, DISCOVERY_MAX_BYTES, ERC7710_ASSET_TRANSFER_METHOD, HAVEN_AGENT_RUNBOOK_MD, HAVEN_CONNECTOR_CHANNEL, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_BODY_MD, HAVEN_SKILL_MD, HavenApiError, HavenClient, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, HavenZeroSettlementHashError, MERCHANT_DISCOVERY_PATHS, MerchantTimeoutError, RECEIPT_VERSION, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, SignerRefusalCode, TRANSFER_WITH_AUTHORIZATION_TYPES, X402AlreadySettledError, X402PaymentHeaderValidationError, X402UnexpectedStatusError, X402_LEGACY_PAYMENT_HEADER_NAME, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_PAYMENT_HEADER_NAME, X402_PAYMENT_HEADER_NAMES_SENT, X402_PAYMENT_REQUIRED_HEADER_NAME, X402_PAYMENT_RESPONSE_HEADER_NAME, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, accountAddressTwins, addressFromKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, canonicalAgentPaymentNextAction, compareNodeVersions, composeDescription, connectorRerunCommand, connectorSpec, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodePaymentProof, havenTools, isConnectorChannel, isErc7710Option, isFundAccountOrRaiseAllowance, isSupportedNodeVersion, isSweepableChain, isZeroSettlementTxHash, normalizePaymentRequired, parsePaymentRequired, parsePaymentRequiredResponse, readAccountAddress, readAccountId, readX402ReceiptPayer, resolveConnectorChannel, resolveTokenFromAddress, sameUrl, selectErc7710PaymentOption, selectPaymentOption, selectStandardPaymentOption, selectX402SettlementScheme, signHash, signUserOpTypedDataForDelegation, signerUpdateFallback, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, validateStandardX402PaymentHeader, verifyPaymentReceipt, verifySignature, x402AssetTransferMethod, x402AuthorizationAmount, x402FacilitatorAddresses, x402V2PaymentEnvelope };
|
|
4862
5031
|
//# sourceMappingURL=index.js.map
|
|
4863
5032
|
//# sourceMappingURL=index.js.map
|