@haven_ai/sdk 0.0.0-dev.202609141042.b4fd152 → 0.0.0-dev.202609141609.ad8a780

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/dist/index.cjs CHANGED
@@ -125,7 +125,23 @@ var AgentPaymentNextAction = {
125
125
  * settled to the merchant. The wallet owner should initiate a sweep to
126
126
  * return those funds to the originating Safe.
127
127
  */
128
- SweepStrandedFunds: "sweep_stranded_funds"
128
+ SweepStrandedFunds: "sweep_stranded_funds",
129
+ /**
130
+ * #2970: a `submitted` erc7710 x402 intent whose settlement window has
131
+ * passed with no on-chain settlement evidence Haven could verify. Distinct
132
+ * from {@link CheckStatusLater}, which this REPLACES once the window is
133
+ * past — but it is not futile: Haven's settlement sweep (120s tick) scans
134
+ * each candidate over its own window plus a 120s clock-skew allowance, so
135
+ * it can still attribute the settlement for a short while after this value
136
+ * first appears. Poll {@link CheckStatusLater}'s tool
137
+ * (`haven_get_payment_status`) once more, roughly two minutes later; if it
138
+ * still shows no evidence, tell the user the goods were delivered but
139
+ * Haven holds no verified settlement evidence for this payment. There is
140
+ * no tool that reports a settlement transaction hash for this scheme —
141
+ * `haven_report_x402_outcome` takes no hash and refuses a non-`confirmed`
142
+ * intent.
143
+ */
144
+ AwaitingSettlementEvidence: "awaiting_settlement_evidence"
129
145
  };
130
146
  var AgentPaymentNextActionAccountAlias = {
131
147
  /** Account-vocabulary twin of `fund_safe_or_raise_allowance`; same meaning. */
@@ -224,7 +240,8 @@ var AgentPaymentNextActionDescriptions = {
224
240
  [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.",
225
241
  [AgentPaymentNextAction.FundSafeOrRaiseAllowance]: "Stop and tell the user that the account needs to be funded or the agent budget raised before the payment can succeed.",
226
242
  [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.",
227
- [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."
243
+ [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.",
244
+ [AgentPaymentNextAction.AwaitingSettlementEvidence]: "The settlement window passed with no verified on-chain evidence yet. 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."
228
245
  };
229
246
  var AgentPaymentFailureCodeDescriptions = {
230
247
  [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.",
@@ -1116,6 +1133,15 @@ var HavenApiTransport = class {
1116
1133
  };
1117
1134
 
1118
1135
  // src/payment-mappers.ts
1136
+ function mapParties(raw) {
1137
+ if (!raw) return void 0;
1138
+ return {
1139
+ treasuryAccount: raw.treasury_account,
1140
+ delegate: raw.delegate,
1141
+ delegateAccount: raw.delegate_account,
1142
+ merchant: raw.merchant
1143
+ };
1144
+ }
1119
1145
  function mapPaymentResult(raw, buildExplorerUrl2) {
1120
1146
  return {
1121
1147
  paymentId: raw.payment_id,
@@ -1155,6 +1181,7 @@ function mapPaymentStatusResult(raw) {
1155
1181
  resourceUrl: raw.resource_url,
1156
1182
  merchantAddress: raw.merchant_address,
1157
1183
  payerAddress: raw.payer_address ?? null,
1184
+ parties: mapParties(raw.parties),
1158
1185
  txHash: raw.tx_hash,
1159
1186
  expiresAt: raw.expires_at,
1160
1187
  chainId: raw.chain_id,
@@ -1192,6 +1219,7 @@ function mapPaymentReceipt(raw) {
1192
1219
  resourceUrl: raw.resource_url,
1193
1220
  merchantAddress: raw.merchant_address,
1194
1221
  payerAddress: raw.payer_address,
1222
+ parties: mapParties(raw.parties),
1195
1223
  settlementAddress: raw.settlement_address,
1196
1224
  tokenSymbol: raw.token_symbol,
1197
1225
  tokenAddress: raw.token_address,
@@ -2915,15 +2943,24 @@ var MerchantCompletion = class {
2915
2943
  for (let attempt = 0; ; attempt += 1) {
2916
2944
  try {
2917
2945
  await this.post("/machine-payments/evidence", body);
2918
- return;
2946
+ return { outcome: "confirmed" };
2919
2947
  } catch (err) {
2920
- const retryable = err instanceof HavenApiError && err.statusCode === EVIDENCE_RETRYABLE_STATUS;
2921
- if (!retryable || attempt >= EVIDENCE_RETRY_DELAYS_MS.length) return;
2948
+ const statusCode = err instanceof HavenApiError ? err.statusCode : void 0;
2949
+ const retryable = statusCode === EVIDENCE_RETRYABLE_STATUS;
2950
+ if (!retryable) {
2951
+ return { outcome: "refused", statusCode: statusCode ?? 0 };
2952
+ }
2953
+ if (attempt >= EVIDENCE_RETRY_DELAYS_MS.length) {
2954
+ return { outcome: "retryable", statusCode };
2955
+ }
2922
2956
  await this.sleep(EVIDENCE_RETRY_DELAYS_MS[attempt]);
2923
2957
  }
2924
2958
  }
2925
2959
  }
2926
2960
  };
2961
+ function isZeroSettlementTxHash(hash) {
2962
+ return typeof hash === "string" && /^0x0+$/i.test(hash);
2963
+ }
2927
2964
  function parseMerchantSettlement(header) {
2928
2965
  if (!header) return {};
2929
2966
  const parsed = parseProtocolReceiptHeader(header);
@@ -3853,6 +3890,7 @@ var HavenClient = class {
3853
3890
  } catch {
3854
3891
  body = text;
3855
3892
  }
3893
+ let evidenceOutcome;
3856
3894
  if (!surfaced.ok) {
3857
3895
  if (!input.noFundingLeg && fundingTxHash) {
3858
3896
  await this.merchantCompletion.recordRetryRejected({
@@ -3872,9 +3910,10 @@ var HavenClient = class {
3872
3910
  });
3873
3911
  }
3874
3912
  } else {
3875
- const evidenceTxHash = input.noFundingLeg ? settlement.settlementTxHash ?? void 0 : fundingTxHash ?? void 0;
3913
+ const rawEvidenceTxHash = input.noFundingLeg ? settlement.settlementTxHash ?? void 0 : fundingTxHash ?? void 0;
3914
+ const evidenceTxHash = rawEvidenceTxHash && !isZeroSettlementTxHash(rawEvidenceTxHash) ? rawEvidenceTxHash : void 0;
3876
3915
  if (evidenceTxHash) {
3877
- await this.merchantCompletion.reportEvidence({
3916
+ evidenceOutcome = await this.merchantCompletion.reportEvidence({
3878
3917
  paymentId: evidenceContext.paymentId,
3879
3918
  rail: "x402",
3880
3919
  txHash: evidenceTxHash,
@@ -3892,7 +3931,8 @@ var HavenClient = class {
3892
3931
  status: surfaced.status,
3893
3932
  ok: surfaced.ok,
3894
3933
  body,
3895
- settlementTxHash: settlement.settlementTxHash ?? void 0
3934
+ settlementTxHash: settlement.settlementTxHash ?? void 0,
3935
+ evidenceOutcome
3896
3936
  };
3897
3937
  }
3898
3938
  /**
@@ -4081,8 +4121,8 @@ var toolDescriptions = {
4081
4121
  // MACHINE-PAYMENT-CHALLENGE was never produced by anything besides the now
4082
4122
  // deleted `/demo/mpp/*` route. Use the x402 fragments above instead.
4083
4123
  getPaymentStatus: {
4084
- summary: "Fetch structured Haven payment status, including phase and nextAction taxonomy for agent recovery.",
4085
- behavior: "Accepts a payment intent id and returns the full state taxonomy (phase, nextAction, rail, amount, merchant, resource url, idempotency key, message).",
4124
+ summary: "Fetch structured Haven payment status for agent recovery.",
4125
+ behavior: "State: phase, nextAction, rail, amount, merchant, resource, idempotency, message; parties: treasury/delegate/delegateAccount/merchant. awaiting_settlement_evidence: poll once, else unverified.",
4086
4126
  nextActionGuidance: ""
4087
4127
  },
4088
4128
  getResumeState: {
@@ -4947,6 +4987,7 @@ exports.isErc7710Option = isErc7710Option;
4947
4987
  exports.isFundAccountOrRaiseAllowance = isFundAccountOrRaiseAllowance;
4948
4988
  exports.isSupportedNodeVersion = isSupportedNodeVersion;
4949
4989
  exports.isSweepableChain = isSweepableChain;
4990
+ exports.isZeroSettlementTxHash = isZeroSettlementTxHash;
4950
4991
  exports.normalizePaymentRequired = normalizePaymentRequired;
4951
4992
  exports.parsePaymentRequired = parsePaymentRequired;
4952
4993
  exports.parsePaymentRequiredResponse = parsePaymentRequiredResponse;