@haven_ai/sdk 0.1.18-alpha.0 → 0.1.19-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/dist/index.cjs CHANGED
@@ -349,6 +349,7 @@ function optionAuthorizationAmount(option) {
349
349
  return option.maxAmountRequired ?? option.amount;
350
350
  }
351
351
  var X402_MAX_AUTHORIZATION_WINDOW_SECONDS = 600;
352
+ var X402_SETTLEMENT_FORWARD_MARGIN_SECONDS = 300;
352
353
  function clampAuthorizationWindow(seconds) {
353
354
  const requested = typeof seconds === "number" && Number.isFinite(seconds) ? seconds : 30;
354
355
  return Math.min(Math.max(Math.floor(requested), 1), X402_MAX_AUTHORIZATION_WINDOW_SECONDS);
@@ -546,7 +547,12 @@ function toStandardPaymentRequirements(paymentRequired, option) {
546
547
  // Second enforcement point (#715): the parse path clamps too, but this is
547
548
  // the last stop before the x402 library turns the timeout into
548
549
  // `validBefore` — options constructed without parsing are bounded here.
549
- maxTimeoutSeconds: clampAuthorizationWindow(option.maxTimeoutSeconds),
550
+ // The forward margin (#1256) is added ONLY here, at signing: the parse
551
+ // path keeps recording the merchant's advertised timeout unchanged, and
552
+ // the library's `validBefore = now + this value` then carries enough
553
+ // slack to satisfy the facilitator's `validBefore ≥ now + maxTimeout`
554
+ // verify rule after our funding leg confirms.
555
+ maxTimeoutSeconds: clampAuthorizationWindow(option.maxTimeoutSeconds) + X402_SETTLEMENT_FORWARD_MARGIN_SECONDS,
550
556
  extra: option.extra
551
557
  };
552
558
  }
@@ -3608,6 +3614,45 @@ for that credential.
3608
3614
  `;
3609
3615
  var SKILL_FOLDER_NAME = "haven-pay";
3610
3616
 
3617
+ // src/node-version.ts
3618
+ var HAVEN_MINIMUM_NODE_VERSION = "24.0.0";
3619
+ function parseNodeVersion(value) {
3620
+ const match = value.trim().match(/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?/);
3621
+ if (!match) return [0, 0, 0];
3622
+ return [Number(match[1] ?? 0), Number(match[2] ?? 0), Number(match[3] ?? 0)];
3623
+ }
3624
+ function compareNodeVersions(left, right) {
3625
+ const leftParts = parseNodeVersion(left);
3626
+ const rightParts = parseNodeVersion(right);
3627
+ for (let i = 0; i < 3; i += 1) {
3628
+ if (leftParts[i] !== rightParts[i]) return leftParts[i] > rightParts[i] ? 1 : -1;
3629
+ }
3630
+ return 0;
3631
+ }
3632
+ function isSupportedNodeVersion(nodeVersion = process.versions.node, minimumNodeVersion = HAVEN_MINIMUM_NODE_VERSION) {
3633
+ return compareNodeVersions(nodeVersion, minimumNodeVersion) >= 0;
3634
+ }
3635
+ function unsupportedNodeVersionMessage(options) {
3636
+ const nodeVersion = options.nodeVersion ?? process.versions.node;
3637
+ const minimum = options.minimumNodeVersion ?? HAVEN_MINIMUM_NODE_VERSION;
3638
+ const lines = [
3639
+ `${options.subject} requires Node.js >=${minimum}, but this is Node.js ${nodeVersion}.`,
3640
+ "",
3641
+ "Upgrade Node, then try again:",
3642
+ ` nvm install ${major(minimum)} && nvm use ${major(minimum)} (nvm)`,
3643
+ ` fnm install ${major(minimum)} && fnm use ${major(minimum)} (fnm)`,
3644
+ ` volta install node@${major(minimum)} (volta)`,
3645
+ ` or download Node ${major(minimum)} from https://nodejs.org`,
3646
+ "",
3647
+ "If you use a version manager, check that the agent runtime launching Haven picks up the same version \u2014 upgrading your shell does not always change what a desktop app spawns."
3648
+ ];
3649
+ if (options.retryHint) lines.push("", options.retryHint);
3650
+ return lines.join("\n");
3651
+ }
3652
+ function major(version) {
3653
+ return String(parseNodeVersion(version)[0]);
3654
+ }
3655
+
3611
3656
  // src/sweep.ts
3612
3657
  var SWEEP_BASE_CHAIN_ID = 8453;
3613
3658
  var SWEEP_BASE_SEPOLIA_CHAIN_ID = 84532;
@@ -3729,6 +3774,7 @@ exports.AgentPaymentPhaseSchema = AgentPaymentPhaseSchema;
3729
3774
  exports.AgentPaymentRail = AgentPaymentRail;
3730
3775
  exports.AgentPaymentRailDescriptions = AgentPaymentRailDescriptions;
3731
3776
  exports.AgentPaymentRailSchema = AgentPaymentRailSchema;
3777
+ exports.HAVEN_MINIMUM_NODE_VERSION = HAVEN_MINIMUM_NODE_VERSION;
3732
3778
  exports.HAVEN_SKILL_MD = HAVEN_SKILL_MD;
3733
3779
  exports.HavenApiError = HavenApiError;
3734
3780
  exports.HavenClient = HavenClient;
@@ -3743,11 +3789,14 @@ exports.SWEEP_BASE_SEPOLIA_CHAIN_ID = SWEEP_BASE_SEPOLIA_CHAIN_ID;
3743
3789
  exports.SWEEP_BASE_SEPOLIA_USDC_ADDRESS = SWEEP_BASE_SEPOLIA_USDC_ADDRESS;
3744
3790
  exports.SWEEP_BASE_USDC_ADDRESS = SWEEP_BASE_USDC_ADDRESS;
3745
3791
  exports.TRANSFER_WITH_AUTHORIZATION_TYPES = TRANSFER_WITH_AUTHORIZATION_TYPES;
3792
+ exports.X402_MAX_AUTHORIZATION_WINDOW_SECONDS = X402_MAX_AUTHORIZATION_WINDOW_SECONDS;
3793
+ exports.X402_SETTLEMENT_FORWARD_MARGIN_SECONDS = X402_SETTLEMENT_FORWARD_MARGIN_SECONDS;
3746
3794
  exports.addressFromKey = addressFromKey;
3747
3795
  exports.buildMachinePaymentIdempotencyKey = buildMachinePaymentIdempotencyKey;
3748
3796
  exports.buildSweepAuthorizationMessage = buildSweepAuthorizationMessage;
3749
3797
  exports.buildSweepTypedData = buildSweepTypedData;
3750
3798
  exports.buildX402ExpectedMessage = buildX402ExpectedMessage;
3799
+ exports.compareNodeVersions = compareNodeVersions;
3751
3800
  exports.composeDescription = composeDescription;
3752
3801
  exports.decodeBase64Json = decodeBase64Json;
3753
3802
  exports.decodeBase64Utf8 = decodeBase64Utf8;
@@ -3756,6 +3805,7 @@ exports.encodeBase64Utf8 = encodeBase64Utf8;
3756
3805
  exports.encodeMachinePaymentProof = encodeMachinePaymentProof;
3757
3806
  exports.encodePaymentProof = encodePaymentProof;
3758
3807
  exports.havenTools = havenTools;
3808
+ exports.isSupportedNodeVersion = isSupportedNodeVersion;
3759
3809
  exports.isSweepableChain = isSweepableChain;
3760
3810
  exports.parseMachinePaymentChallenge = parseMachinePaymentChallenge;
3761
3811
  exports.parseMachinePaymentChallengeResponse = parseMachinePaymentChallengeResponse;
@@ -3769,6 +3819,7 @@ exports.sweepUsdcAddress = sweepUsdcAddress;
3769
3819
  exports.sweepUsdcDomain = sweepUsdcDomain;
3770
3820
  exports.toStandardPaymentRequirements = toStandardPaymentRequirements;
3771
3821
  exports.toolDescriptions = toolDescriptions;
3822
+ exports.unsupportedNodeVersionMessage = unsupportedNodeVersionMessage;
3772
3823
  exports.verifyPaymentReceipt = verifyPaymentReceipt;
3773
3824
  exports.verifySignature = verifySignature;
3774
3825
  exports.x402AuthorizationAmount = x402AuthorizationAmount;