@blockrun/clawrouter 0.12.314 → 0.12.316

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.js CHANGED
@@ -44237,7 +44237,7 @@ var init_chunk_XW2CWVLZ = __esm({
44237
44237
  }
44238
44238
  });
44239
44239
 
44240
- // node_modules/@x402/core/dist/esm/chunk-U5TAZTKB.mjs
44240
+ // node_modules/@x402/core/dist/esm/chunk-PVRH2E6N.mjs
44241
44241
  function encodePaymentSignatureHeader(paymentPayload) {
44242
44242
  return safeBase64Encode(JSON.stringify(paymentPayload));
44243
44243
  }
@@ -44260,8 +44260,8 @@ function decodePaymentResponseHeader(paymentResponseHeader) {
44260
44260
  );
44261
44261
  }
44262
44262
  var MAX_CONTROL_PLANE_RESPONSE_BYTES, verifyResponseSchema, settleResponseSchema, supportedKindSchema, supportedResponseSchema, x402HTTPClient, requireDecodedJsonObject;
44263
- var init_chunk_U5TAZTKB = __esm({
44264
- "node_modules/@x402/core/dist/esm/chunk-U5TAZTKB.mjs"() {
44263
+ var init_chunk_PVRH2E6N = __esm({
44264
+ "node_modules/@x402/core/dist/esm/chunk-PVRH2E6N.mjs"() {
44265
44265
  "use strict";
44266
44266
  init_chunk_Z7WXFCST();
44267
44267
  init_chunk_VE37GDG2();
@@ -44574,7 +44574,7 @@ var DEFAULT_MAX_AMOUNT_PER_PAYMENT, x402Client;
44574
44574
  var init_client = __esm({
44575
44575
  "node_modules/@x402/core/dist/esm/client/index.mjs"() {
44576
44576
  "use strict";
44577
- init_chunk_U5TAZTKB();
44577
+ init_chunk_PVRH2E6N();
44578
44578
  init_chunk_Z7WXFCST();
44579
44579
  init_chunk_VE37GDG2();
44580
44580
  init_chunk_MA7F3CLI();
@@ -45215,7 +45215,7 @@ var init_client = __esm({
45215
45215
  var init_http3 = __esm({
45216
45216
  "node_modules/@x402/core/dist/esm/http/index.mjs"() {
45217
45217
  "use strict";
45218
- init_chunk_U5TAZTKB();
45218
+ init_chunk_PVRH2E6N();
45219
45219
  init_chunk_Z7WXFCST();
45220
45220
  init_chunk_VE37GDG2();
45221
45221
  init_chunk_MA7F3CLI();
@@ -80345,7 +80345,7 @@ var init_src3 = __esm({
80345
80345
  }
80346
80346
  });
80347
80347
 
80348
- // node_modules/@x402/svm/dist/esm/chunk-TYATVISX.mjs
80348
+ // node_modules/@x402/svm/dist/esm/chunk-DAIKIZVB.mjs
80349
80349
  function normalizeNetwork(network) {
80350
80350
  if (network.includes(":")) {
80351
80351
  const supported = [SOLANA_MAINNET_CAIP2, SOLANA_DEVNET_CAIP2, SOLANA_TESTNET_CAIP2];
@@ -80582,8 +80582,8 @@ async function recordPendingOrTerminal(store, key3, signature3, payer, network,
80582
80582
  };
80583
80583
  }
80584
80584
  var TOKEN_PROGRAM_ADDRESS3, TOKEN_2022_PROGRAM_ADDRESS2, COMPUTE_BUDGET_PROGRAM_ADDRESS2, MEMO_PROGRAM_ADDRESS, LIGHTHOUSE_PROGRAM_ADDRESS, DEVNET_RPC_URL, TESTNET_RPC_URL, MAINNET_RPC_URL, DEVNET_WS_URL, TESTNET_WS_URL, MAINNET_WS_URL, DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS, MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS, DEFAULT_COMPUTE_UNIT_LIMIT, DEFAULT_MAX_COMPUTE_UNITS, DEFAULT_MAX_REQUIRED_SIGNATURES, MAX_MEMO_BYTES, ACCEPTED_TRANSACTION_VERSIONS, ADVERTISED_TRANSACTION_VERSIONS, CLIENT_SUPPORTED_TRANSACTION_VERSIONS, SETTLEMENT_TTL_MS, SVM_ADDRESS_REGEX, SOLANA_MAINNET_CAIP2, SOLANA_DEVNET_CAIP2, SOLANA_TESTNET_CAIP2, V1_TO_V2_NETWORK_MAP, ErrInvalidPayloadTransaction, ErrUnsupportedTransactionVersion, ErrFeePayerTransferringFunds, ErrMemoMismatch, ErrMemoCount, ErrSmartWalletFeePayerNotIsolated, ErrSmartWalletMalformedComputeBudget, ErrSmartWalletMalformedComputeLimit, ErrSmartWalletMalformedComputePrice, ErrSmartWalletComputeUnitsTooHigh, ErrSmartWalletPriorityFeeTooHigh, ErrSmartWalletUnsupportedComputeBudget, ErrSmartWalletAltResolutionUnavailable, ErrSmartWalletAltResolutionFailed, ErrSmartWalletComputeBudgetViolation, ErrSmartWalletSimulationFailed, ErrSmartWalletCannotDeriveATA, ErrSmartWalletNoTransferInSimulation, ErrSmartWalletTransferMismatch, ErrSmartWalletMultipleMatchingTransfers, USDC_MAINNET_ADDRESS, USDC_DEVNET_ADDRESS, USDC_TESTNET_ADDRESS, DEFAULT_ASSETS2, getDefaultAsset2, findDefaultAsset2, BASIS_POINTS_DENOMINATOR, SLOT_COMMITMENT, TransactionOnchainFailureError;
80585
- var init_chunk_TYATVISX = __esm({
80586
- "node_modules/@x402/svm/dist/esm/chunk-TYATVISX.mjs"() {
80585
+ var init_chunk_DAIKIZVB = __esm({
80586
+ "node_modules/@x402/svm/dist/esm/chunk-DAIKIZVB.mjs"() {
80587
80587
  "use strict";
80588
80588
  init_sha2563();
80589
80589
  init_index_node39();
@@ -80803,7 +80803,7 @@ var init_src4 = __esm({
80803
80803
  }
80804
80804
  });
80805
80805
 
80806
- // node_modules/@x402/svm/dist/esm/chunk-A5U3JRDR.mjs
80806
+ // node_modules/@x402/svm/dist/esm/chunk-RZ6M7L3U.mjs
80807
80807
  function maxTransactionSize(version31) {
80808
80808
  return version31 === 1 ? V1_MAX_TRANSACTION_SIZE : V0_MAX_TRANSACTION_SIZE;
80809
80809
  }
@@ -80901,10 +80901,10 @@ function checkTransactionV1Budget(config2, programAddresses, limits) {
80901
80901
  return void 0;
80902
80902
  }
80903
80903
  var V0_MAX_TRANSACTION_SIZE, V1_MAX_TRANSACTION_SIZE, DEFAULT_LOADED_ACCOUNTS_DATA_SIZE_LIMIT;
80904
- var init_chunk_A5U3JRDR = __esm({
80905
- "node_modules/@x402/svm/dist/esm/chunk-A5U3JRDR.mjs"() {
80904
+ var init_chunk_RZ6M7L3U = __esm({
80905
+ "node_modules/@x402/svm/dist/esm/chunk-RZ6M7L3U.mjs"() {
80906
80906
  "use strict";
80907
- init_chunk_TYATVISX();
80907
+ init_chunk_DAIKIZVB();
80908
80908
  init_index_node39();
80909
80909
  init_src4();
80910
80910
  V0_MAX_TRANSACTION_SIZE = 1232;
@@ -80913,7 +80913,7 @@ var init_chunk_A5U3JRDR = __esm({
80913
80913
  }
80914
80914
  });
80915
80915
 
80916
- // node_modules/@x402/svm/dist/esm/chunk-BU4OMUDH.mjs
80916
+ // node_modules/@x402/svm/dist/esm/chunk-DP3B4MQJ.mjs
80917
80917
  function encodeVoucherMessageBytes(args) {
80918
80918
  const channelBytes = getBase58Encoder().encode(args.channelId);
80919
80919
  if (channelBytes.byteLength !== 32) {
@@ -81359,11 +81359,11 @@ function randomU64() {
81359
81359
  return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getBigUint64(0, true);
81360
81360
  }
81361
81361
  var VOUCHER_MAGIC, PAYMENT_CHANNELS_PROGRAM_ADDRESS, ASSOCIATED_TOKEN_PROGRAM_ID, PAYMENT_CHANNELS_PROGRAM_ID, MAINNET_TREASURY_OWNER_BYTES, MAINNET_TREASURY_OWNER, DEVNET_TREASURY_OWNER, OPEN_DISCRIMINATOR, TOP_UP_DISCRIMINATOR, U64_MAX2, OPEN_MAX_COMPUTE_UNIT_LIMIT, OPEN_DEFAULT_COMPUTE_UNIT_LIMIT, RENT_SYSVAR, MAX_CHANNEL_PDA_CACHE_ENTRIES, channelPdaCache;
81362
- var init_chunk_BU4OMUDH = __esm({
81363
- "node_modules/@x402/svm/dist/esm/chunk-BU4OMUDH.mjs"() {
81362
+ var init_chunk_DP3B4MQJ = __esm({
81363
+ "node_modules/@x402/svm/dist/esm/chunk-DP3B4MQJ.mjs"() {
81364
81364
  "use strict";
81365
- init_chunk_A5U3JRDR();
81366
- init_chunk_TYATVISX();
81365
+ init_chunk_RZ6M7L3U();
81366
+ init_chunk_DAIKIZVB();
81367
81367
  init_index_node39();
81368
81368
  init_index_node39();
81369
81369
  init_index_node39();
@@ -81428,7 +81428,7 @@ var init_chunk_BU4OMUDH = __esm({
81428
81428
  }
81429
81429
  });
81430
81430
 
81431
- // node_modules/@x402/svm/dist/esm/chunk-3WM4BBCN.mjs
81431
+ // node_modules/@x402/svm/dist/esm/chunk-VITMNYMM.mjs
81432
81432
  function getRequestCloseInstructionDataEncoder() {
81433
81433
  return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()]]), (value) => ({
81434
81434
  ...value,
@@ -81501,12 +81501,12 @@ function requestMemo(value) {
81501
81501
  );
81502
81502
  }
81503
81503
  var REQUEST_CLOSE_DISCRIMINATOR;
81504
- var init_chunk_3WM4BBCN = __esm({
81505
- "node_modules/@x402/svm/dist/esm/chunk-3WM4BBCN.mjs"() {
81504
+ var init_chunk_VITMNYMM = __esm({
81505
+ "node_modules/@x402/svm/dist/esm/chunk-VITMNYMM.mjs"() {
81506
81506
  "use strict";
81507
- init_chunk_BU4OMUDH();
81508
- init_chunk_A5U3JRDR();
81509
- init_chunk_TYATVISX();
81507
+ init_chunk_DP3B4MQJ();
81508
+ init_chunk_RZ6M7L3U();
81509
+ init_chunk_DAIKIZVB();
81510
81510
  init_index_node39();
81511
81511
  init_index_node39();
81512
81512
  init_index_node40();
@@ -81514,7 +81514,7 @@ var init_chunk_3WM4BBCN = __esm({
81514
81514
  }
81515
81515
  });
81516
81516
 
81517
- // node_modules/@x402/svm/dist/esm/chunk-CHLO3MPU.mjs
81517
+ // node_modules/@x402/svm/dist/esm/chunk-NUK2USQ3.mjs
81518
81518
  function getChannelDecoder() {
81519
81519
  return getStructDecoder([
81520
81520
  ["discriminator", getU8Decoder()],
@@ -81536,15 +81536,15 @@ function getChannelDecoder() {
81536
81536
  ["openSlot", getU64Decoder()]
81537
81537
  ]);
81538
81538
  }
81539
- var init_chunk_CHLO3MPU = __esm({
81540
- "node_modules/@x402/svm/dist/esm/chunk-CHLO3MPU.mjs"() {
81539
+ var init_chunk_NUK2USQ3 = __esm({
81540
+ "node_modules/@x402/svm/dist/esm/chunk-NUK2USQ3.mjs"() {
81541
81541
  "use strict";
81542
- init_chunk_BU4OMUDH();
81542
+ init_chunk_DP3B4MQJ();
81543
81543
  init_index_node39();
81544
81544
  }
81545
81545
  });
81546
81546
 
81547
- // node_modules/@x402/svm/dist/esm/chunk-PQ3QK4Z4.mjs
81547
+ // node_modules/@x402/svm/dist/esm/chunk-RMG2KWUT.mjs
81548
81548
  function channelAddressFilters(value, offset) {
81549
81549
  return [
81550
81550
  { dataSize: CHANNEL_ACCOUNT_SIZE },
@@ -81615,11 +81615,11 @@ async function validateDiscoveredAccount(pubkey, owner, base64Data, expectedProg
81615
81615
  return { channelId: pubkey, channel };
81616
81616
  }
81617
81617
  var CHANNEL_ACCOUNT_SIZE, CHANNEL_RENT_PAYER_OFFSET, CHANNEL_PAYER_OFFSET;
81618
- var init_chunk_PQ3QK4Z4 = __esm({
81619
- "node_modules/@x402/svm/dist/esm/chunk-PQ3QK4Z4.mjs"() {
81618
+ var init_chunk_RMG2KWUT = __esm({
81619
+ "node_modules/@x402/svm/dist/esm/chunk-RMG2KWUT.mjs"() {
81620
81620
  "use strict";
81621
- init_chunk_CHLO3MPU();
81622
- init_chunk_BU4OMUDH();
81621
+ init_chunk_NUK2USQ3();
81622
+ init_chunk_DP3B4MQJ();
81623
81623
  init_index_node39();
81624
81624
  CHANNEL_ACCOUNT_SIZE = 256n;
81625
81625
  CHANNEL_RENT_PAYER_OFFSET = 216n;
@@ -81627,7 +81627,7 @@ var init_chunk_PQ3QK4Z4 = __esm({
81627
81627
  }
81628
81628
  });
81629
81629
 
81630
- // node_modules/@x402/svm/dist/esm/chunk-GAYY7QRO.mjs
81630
+ // node_modules/@x402/svm/dist/esm/chunk-CJ2GGI22.mjs
81631
81631
  function isBatchVoucher(value) {
81632
81632
  if (!isRecord(value)) return false;
81633
81633
  return typeof value.channelId === "string" && typeof value.maxClaimableAmount === "string" && typeof value.expiresAt === "number" && typeof value.signature === "string";
@@ -81812,12 +81812,12 @@ function parseReceiverBindingMemo(memo2) {
81812
81812
  return isAddress2(authorizer) ? authorizer : void 0;
81813
81813
  }
81814
81814
  var BATCH_SETTLEMENT_SCHEME2, MIN_WITHDRAW_DELAY2, MAX_WITHDRAW_DELAY, FULL_SPLIT_BPS, CLIENT_VOUCHER_EXPIRES_AT, AUTHORIZATION_DOMAIN, CLOSE_DOMAIN, V1_MAX_CLAIM_CHANNELS, V1_MAX_SETTLE_CHANNELS, PREFIX, BatchError, isDecimal, isSafeUint, isOptional, isString, RECEIVER_BINDING_MEMO_PREFIX;
81815
- var init_chunk_GAYY7QRO = __esm({
81816
- "node_modules/@x402/svm/dist/esm/chunk-GAYY7QRO.mjs"() {
81815
+ var init_chunk_CJ2GGI22 = __esm({
81816
+ "node_modules/@x402/svm/dist/esm/chunk-CJ2GGI22.mjs"() {
81817
81817
  "use strict";
81818
- init_chunk_BU4OMUDH();
81819
- init_chunk_A5U3JRDR();
81820
- init_chunk_TYATVISX();
81818
+ init_chunk_DP3B4MQJ();
81819
+ init_chunk_RZ6M7L3U();
81820
+ init_chunk_DAIKIZVB();
81821
81821
  init_index_node39();
81822
81822
  init_index_node39();
81823
81823
  BATCH_SETTLEMENT_SCHEME2 = "batch-settlement";
@@ -81865,7 +81865,7 @@ var init_chunk_GAYY7QRO = __esm({
81865
81865
  }
81866
81866
  });
81867
81867
 
81868
- // node_modules/@x402/svm/dist/esm/chunk-5EQYNZXP.mjs
81868
+ // node_modules/@x402/svm/dist/esm/chunk-2RSZYSMO.mjs
81869
81869
  function parseTokenProgramHint(extra) {
81870
81870
  const hint = extra?.tokenProgram;
81871
81871
  if (hint === void 0 || hint === null || hint === "") {
@@ -81893,14 +81893,14 @@ function requireTokenProgramHint(extra, invalid) {
81893
81893
  if (hinted === void 0) throw new Error(invalid);
81894
81894
  return hinted;
81895
81895
  }
81896
- var init_chunk_5EQYNZXP = __esm({
81897
- "node_modules/@x402/svm/dist/esm/chunk-5EQYNZXP.mjs"() {
81896
+ var init_chunk_2RSZYSMO = __esm({
81897
+ "node_modules/@x402/svm/dist/esm/chunk-2RSZYSMO.mjs"() {
81898
81898
  "use strict";
81899
- init_chunk_TYATVISX();
81899
+ init_chunk_DAIKIZVB();
81900
81900
  }
81901
81901
  });
81902
81902
 
81903
- // node_modules/@x402/svm/dist/esm/chunk-Y7W3OBHW.mjs
81903
+ // node_modules/@x402/svm/dist/esm/chunk-HRH33QP2.mjs
81904
81904
  async function checkCorrectiveState(args) {
81905
81905
  const state = args.accept.extra?.channelState;
81906
81906
  if (!isBatchChannelState(state)) {
@@ -82341,15 +82341,15 @@ async function buildBatchRefundPayload(args) {
82341
82341
  });
82342
82342
  }
82343
82343
  var BatchChannelTracker, NoBatchChannelToRefundError, DEFAULT_SERVER_SIGNED_MAX_DEPOSIT, UntrustedOperatorError, ServerSignedTrustPolicy, DEFAULT_DEPOSIT_MULTIPLIER, MIN_DEPOSIT_MULTIPLIER, OPERATION_KEY_SEPARATOR, BatchSvmScheme;
82344
- var init_chunk_Y7W3OBHW = __esm({
82345
- "node_modules/@x402/svm/dist/esm/chunk-Y7W3OBHW.mjs"() {
82346
- "use strict";
82347
- init_chunk_3WM4BBCN();
82348
- init_chunk_PQ3QK4Z4();
82349
- init_chunk_GAYY7QRO();
82350
- init_chunk_5EQYNZXP();
82351
- init_chunk_BU4OMUDH();
82352
- init_chunk_TYATVISX();
82344
+ var init_chunk_HRH33QP2 = __esm({
82345
+ "node_modules/@x402/svm/dist/esm/chunk-HRH33QP2.mjs"() {
82346
+ "use strict";
82347
+ init_chunk_VITMNYMM();
82348
+ init_chunk_RMG2KWUT();
82349
+ init_chunk_CJ2GGI22();
82350
+ init_chunk_2RSZYSMO();
82351
+ init_chunk_DP3B4MQJ();
82352
+ init_chunk_DAIKIZVB();
82353
82353
  init_index_node39();
82354
82354
  init_http3();
82355
82355
  init_utils9();
@@ -83337,7 +83337,7 @@ var init_chunk_Y7W3OBHW = __esm({
83337
83337
  }
83338
83338
  });
83339
83339
 
83340
- // node_modules/@x402/svm/dist/esm/chunk-7IXSBHSJ.mjs
83340
+ // node_modules/@x402/svm/dist/esm/chunk-HQM7VUNZ.mjs
83341
83341
  function getChannelDistributionHash(splits) {
83342
83342
  const hasher = sha2568.create();
83343
83343
  const count = new Uint8Array(4);
@@ -83351,19 +83351,19 @@ function getChannelDistributionHash(splits) {
83351
83351
  }
83352
83352
  return hasher.digest();
83353
83353
  }
83354
- var init_chunk_7IXSBHSJ = __esm({
83355
- "node_modules/@x402/svm/dist/esm/chunk-7IXSBHSJ.mjs"() {
83354
+ var init_chunk_HQM7VUNZ = __esm({
83355
+ "node_modules/@x402/svm/dist/esm/chunk-HQM7VUNZ.mjs"() {
83356
83356
  "use strict";
83357
- init_chunk_CHLO3MPU();
83358
- init_chunk_BU4OMUDH();
83359
- init_chunk_A5U3JRDR();
83360
- init_chunk_TYATVISX();
83357
+ init_chunk_NUK2USQ3();
83358
+ init_chunk_DP3B4MQJ();
83359
+ init_chunk_RZ6M7L3U();
83360
+ init_chunk_DAIKIZVB();
83361
83361
  init_sha2563();
83362
83362
  init_index_node39();
83363
83363
  }
83364
83364
  });
83365
83365
 
83366
- // node_modules/@x402/svm/dist/esm/chunk-OT6AP35X.mjs
83366
+ // node_modules/@x402/svm/dist/esm/chunk-SINLL373.mjs
83367
83367
  function encodeCloseAuthorizationDigest(binding) {
83368
83368
  const base582 = getBase58Encoder();
83369
83369
  const network = new TextEncoder().encode(binding.network);
@@ -83434,11 +83434,11 @@ async function verifyCloseAuthorization(authorization, binding, receiverAuthoriz
83434
83434
  return false;
83435
83435
  }
83436
83436
  }
83437
- var init_chunk_OT6AP35X = __esm({
83438
- "node_modules/@x402/svm/dist/esm/chunk-OT6AP35X.mjs"() {
83437
+ var init_chunk_SINLL373 = __esm({
83438
+ "node_modules/@x402/svm/dist/esm/chunk-SINLL373.mjs"() {
83439
83439
  "use strict";
83440
- init_chunk_GAYY7QRO();
83441
- init_chunk_BU4OMUDH();
83440
+ init_chunk_CJ2GGI22();
83441
+ init_chunk_DP3B4MQJ();
83442
83442
  init_sha2563();
83443
83443
  init_index_node39();
83444
83444
  }
@@ -83471,14 +83471,14 @@ var init_chunk_WIPN332D = __esm({
83471
83471
  }
83472
83472
  });
83473
83473
 
83474
- // node_modules/@x402/svm/dist/esm/chunk-OJGL5KXB.mjs
83474
+ // node_modules/@x402/svm/dist/esm/chunk-2P7IHAQJ.mjs
83475
83475
  var ExactSvmScheme;
83476
- var init_chunk_OJGL5KXB = __esm({
83477
- "node_modules/@x402/svm/dist/esm/chunk-OJGL5KXB.mjs"() {
83476
+ var init_chunk_2P7IHAQJ = __esm({
83477
+ "node_modules/@x402/svm/dist/esm/chunk-2P7IHAQJ.mjs"() {
83478
83478
  "use strict";
83479
83479
  init_chunk_WIPN332D();
83480
- init_chunk_A5U3JRDR();
83481
- init_chunk_TYATVISX();
83480
+ init_chunk_RZ6M7L3U();
83481
+ init_chunk_DAIKIZVB();
83482
83482
  init_src2();
83483
83483
  init_src3();
83484
83484
  init_index_node39();
@@ -83592,7 +83592,7 @@ var init_chunk_OJGL5KXB = __esm({
83592
83592
  }
83593
83593
  });
83594
83594
 
83595
- // node_modules/@x402/svm/dist/esm/chunk-FHYNBUS4.mjs
83595
+ // node_modules/@x402/svm/dist/esm/chunk-7TSGYOB2.mjs
83596
83596
  function assertSmartWalletLimits(limits) {
83597
83597
  assertLimit("smartWalletMaxComputeUnits", limits?.maxComputeUnits, 1);
83598
83598
  assertLimit("smartWalletMaxPriorityFeeMicroLamports", limits?.maxPriorityFeeMicroLamports, 0);
@@ -84018,11 +84018,11 @@ async function verifyPostSettlement(signer, signature3, network, requirements, s
84018
84018
  return { verified: false, method: "unverified" };
84019
84019
  }
84020
84020
  var DEFAULT_SMART_WALLET_MAX_COMPUTE_UNITS, DEFAULT_SMART_WALLET_MAX_PRIORITY_FEE_MICROLAMPORTS, IX_SET_COMPUTE_UNIT_LIMIT, IX_SET_COMPUTE_UNIT_PRICE, IX_TOKEN_TRANSFER_CHECKED, TOKEN_PROGRAMS, SMART_WALLET_V1_BUDGET_REASONS;
84021
- var init_chunk_FHYNBUS4 = __esm({
84022
- "node_modules/@x402/svm/dist/esm/chunk-FHYNBUS4.mjs"() {
84021
+ var init_chunk_7TSGYOB2 = __esm({
84022
+ "node_modules/@x402/svm/dist/esm/chunk-7TSGYOB2.mjs"() {
84023
84023
  "use strict";
84024
- init_chunk_A5U3JRDR();
84025
- init_chunk_TYATVISX();
84024
+ init_chunk_RZ6M7L3U();
84025
+ init_chunk_DAIKIZVB();
84026
84026
  init_src4();
84027
84027
  init_src2();
84028
84028
  init_src3();
@@ -84048,12 +84048,12 @@ var init_chunk_FHYNBUS4 = __esm({
84048
84048
  }
84049
84049
  });
84050
84050
 
84051
- // node_modules/@x402/svm/dist/esm/chunk-BAY4U3CP.mjs
84051
+ // node_modules/@x402/svm/dist/esm/chunk-L56Y5KBE.mjs
84052
84052
  var SettlementCache;
84053
- var init_chunk_BAY4U3CP = __esm({
84054
- "node_modules/@x402/svm/dist/esm/chunk-BAY4U3CP.mjs"() {
84053
+ var init_chunk_L56Y5KBE = __esm({
84054
+ "node_modules/@x402/svm/dist/esm/chunk-L56Y5KBE.mjs"() {
84055
84055
  "use strict";
84056
- init_chunk_TYATVISX();
84056
+ init_chunk_DAIKIZVB();
84057
84057
  SettlementCache = class {
84058
84058
  constructor() {
84059
84059
  this.entries = /* @__PURE__ */ new Map();
@@ -84100,7 +84100,7 @@ var init_chunk_BAY4U3CP = __esm({
84100
84100
  }
84101
84101
  });
84102
84102
 
84103
- // node_modules/@x402/svm/dist/esm/chunk-HHRGQ6BR.mjs
84103
+ // node_modules/@x402/svm/dist/esm/chunk-NQRJ53N4.mjs
84104
84104
  function resolveUptoSvmPaymentChannelConfig(requirements) {
84105
84105
  const feePayer = requirements.extra?.feePayer;
84106
84106
  if (typeof feePayer !== "string" || feePayer.length === 0) {
@@ -84117,22 +84117,22 @@ function resolveUptoSvmPaymentChannelConfig(requirements) {
84117
84117
  const splits = [{ bps: BASIS_POINTS_DENOMINATOR, recipient: requirements.payTo }];
84118
84118
  return { feePayer, receiverAuthorizer, splits, withdrawDelay };
84119
84119
  }
84120
- var init_chunk_HHRGQ6BR = __esm({
84121
- "node_modules/@x402/svm/dist/esm/chunk-HHRGQ6BR.mjs"() {
84120
+ var init_chunk_NQRJ53N4 = __esm({
84121
+ "node_modules/@x402/svm/dist/esm/chunk-NQRJ53N4.mjs"() {
84122
84122
  "use strict";
84123
- init_chunk_TYATVISX();
84123
+ init_chunk_DAIKIZVB();
84124
84124
  }
84125
84125
  });
84126
84126
 
84127
- // node_modules/@x402/svm/dist/esm/chunk-XBZL4F4W.mjs
84127
+ // node_modules/@x402/svm/dist/esm/chunk-QPYYLXPW.mjs
84128
84128
  var UptoSvmScheme;
84129
- var init_chunk_XBZL4F4W = __esm({
84130
- "node_modules/@x402/svm/dist/esm/chunk-XBZL4F4W.mjs"() {
84129
+ var init_chunk_QPYYLXPW = __esm({
84130
+ "node_modules/@x402/svm/dist/esm/chunk-QPYYLXPW.mjs"() {
84131
84131
  "use strict";
84132
- init_chunk_HHRGQ6BR();
84133
- init_chunk_5EQYNZXP();
84134
- init_chunk_BU4OMUDH();
84135
- init_chunk_TYATVISX();
84132
+ init_chunk_NQRJ53N4();
84133
+ init_chunk_2RSZYSMO();
84134
+ init_chunk_DP3B4MQJ();
84135
+ init_chunk_DAIKIZVB();
84136
84136
  init_src3();
84137
84137
  init_src2();
84138
84138
  UptoSvmScheme = class {
@@ -84606,23 +84606,23 @@ var init_esm5 = __esm({
84606
84606
  "node_modules/@x402/svm/dist/esm/index.mjs"() {
84607
84607
  "use strict";
84608
84608
  init_chunk_NLVYNPNC();
84609
- init_chunk_Y7W3OBHW();
84610
- init_chunk_7IXSBHSJ();
84611
- init_chunk_3WM4BBCN();
84612
- init_chunk_PQ3QK4Z4();
84613
- init_chunk_OT6AP35X();
84614
- init_chunk_GAYY7QRO();
84615
- init_chunk_CHLO3MPU();
84616
- init_chunk_OJGL5KXB();
84609
+ init_chunk_HRH33QP2();
84610
+ init_chunk_HQM7VUNZ();
84611
+ init_chunk_VITMNYMM();
84612
+ init_chunk_RMG2KWUT();
84613
+ init_chunk_SINLL373();
84614
+ init_chunk_CJ2GGI22();
84615
+ init_chunk_NUK2USQ3();
84616
+ init_chunk_2P7IHAQJ();
84617
84617
  init_chunk_WIPN332D();
84618
- init_chunk_FHYNBUS4();
84619
- init_chunk_BAY4U3CP();
84620
- init_chunk_XBZL4F4W();
84621
- init_chunk_HHRGQ6BR();
84622
- init_chunk_5EQYNZXP();
84623
- init_chunk_BU4OMUDH();
84624
- init_chunk_A5U3JRDR();
84625
- init_chunk_TYATVISX();
84618
+ init_chunk_7TSGYOB2();
84619
+ init_chunk_L56Y5KBE();
84620
+ init_chunk_QPYYLXPW();
84621
+ init_chunk_NQRJ53N4();
84622
+ init_chunk_2RSZYSMO();
84623
+ init_chunk_DP3B4MQJ();
84624
+ init_chunk_RZ6M7L3U();
84625
+ init_chunk_DAIKIZVB();
84626
84626
  init_index_node39();
84627
84627
  }
84628
84628
  });
@@ -84649,15 +84649,15 @@ __export(client_exports2, {
84649
84649
  var init_client2 = __esm({
84650
84650
  "node_modules/@x402/svm/dist/esm/batch-settlement/client/index.mjs"() {
84651
84651
  "use strict";
84652
- init_chunk_Y7W3OBHW();
84653
- init_chunk_3WM4BBCN();
84654
- init_chunk_PQ3QK4Z4();
84655
- init_chunk_GAYY7QRO();
84656
- init_chunk_CHLO3MPU();
84657
- init_chunk_5EQYNZXP();
84658
- init_chunk_BU4OMUDH();
84659
- init_chunk_A5U3JRDR();
84660
- init_chunk_TYATVISX();
84652
+ init_chunk_HRH33QP2();
84653
+ init_chunk_VITMNYMM();
84654
+ init_chunk_RMG2KWUT();
84655
+ init_chunk_CJ2GGI22();
84656
+ init_chunk_NUK2USQ3();
84657
+ init_chunk_2RSZYSMO();
84658
+ init_chunk_DP3B4MQJ();
84659
+ init_chunk_RZ6M7L3U();
84660
+ init_chunk_DAIKIZVB();
84661
84661
  }
84662
84662
  });
84663
84663
 
@@ -84776,7 +84776,7 @@ import * as path4 from "path";
84776
84776
  import * as os3 from "os";
84777
84777
  import { createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey2, sign as ed25519Sign } from "crypto";
84778
84778
  import { AsyncLocalStorage } from "async_hooks";
84779
- import { randomUUID } from "crypto";
84779
+ import { randomUUID as randomUUID2 } from "crypto";
84780
84780
  import * as fs6 from "fs";
84781
84781
  import * as path5 from "path";
84782
84782
  import * as fs7 from "fs";
@@ -87316,7 +87316,7 @@ function lockChannelFile(file2) {
87316
87316
  if (registry22.locks.has(file2)) return void 0;
87317
87317
  const lock = `${file2}.lock`;
87318
87318
  fs6.mkdirSync(path5.dirname(lock), { recursive: true, mode: 448 });
87319
- const token = randomUUID();
87319
+ const token = randomUUID2();
87320
87320
  for (let attempt = 0; attempt < 2; attempt += 1) {
87321
87321
  const tmp = `${lock}.${process.pid}.${token}.tmp`;
87322
87322
  try {
@@ -87536,7 +87536,7 @@ function withDepositBlockhash(paymentRequired, blockhash2) {
87536
87536
  function withPaymentIdentifier(paymentRequired) {
87537
87537
  const declared = paymentRequired.extensions?.[PAYMENT_IDENTIFIER];
87538
87538
  if (typeof declared?.info?.required !== "boolean") return paymentRequired;
87539
- const id2 = `pay_${randomUUID().replace(/-/g, "")}`;
87539
+ const id2 = `pay_${randomUUID2().replace(/-/g, "")}`;
87540
87540
  return {
87541
87541
  ...paymentRequired,
87542
87542
  extensions: { ...paymentRequired.extensions, [PAYMENT_IDENTIFIER]: { ...declared, info: { ...declared.info, id: id2 } } }
@@ -96028,7 +96028,7 @@ var init_dist = __esm({
96028
96028
  fsyncDirectory(dir);
96029
96029
  return;
96030
96030
  }
96031
- const tmp = `${this.file}.${process.pid}.${randomUUID()}.tmp`;
96031
+ const tmp = `${this.file}.${process.pid}.${randomUUID2()}.tmp`;
96032
96032
  const fd = fs6.openSync(tmp, "w", 384);
96033
96033
  try {
96034
96034
  fs6.writeSync(fd, JSON.stringify({ version: 1, intents }, null, 2));
@@ -130567,14 +130567,14 @@ var init_chunk_WWACQNRQ = __esm({
130567
130567
  }
130568
130568
  });
130569
130569
 
130570
- // node_modules/@x402/svm/dist/esm/chunk-RERS6LWQ.mjs
130570
+ // node_modules/@x402/svm/dist/esm/chunk-PQ2KWLVO.mjs
130571
130571
  var ExactSvmSchemeV1;
130572
- var init_chunk_RERS6LWQ = __esm({
130573
- "node_modules/@x402/svm/dist/esm/chunk-RERS6LWQ.mjs"() {
130572
+ var init_chunk_PQ2KWLVO = __esm({
130573
+ "node_modules/@x402/svm/dist/esm/chunk-PQ2KWLVO.mjs"() {
130574
130574
  "use strict";
130575
130575
  init_chunk_WIPN332D();
130576
- init_chunk_A5U3JRDR();
130577
- init_chunk_TYATVISX();
130576
+ init_chunk_RZ6M7L3U();
130577
+ init_chunk_DAIKIZVB();
130578
130578
  init_src2();
130579
130579
  init_src3();
130580
130580
  init_index_node39();
@@ -130702,15 +130702,15 @@ var init_facilitator = __esm({
130702
130702
  }
130703
130703
  });
130704
130704
 
130705
- // node_modules/@x402/svm/dist/esm/chunk-CUM4W6LX.mjs
130705
+ // node_modules/@x402/svm/dist/esm/chunk-RCDWMK2L.mjs
130706
130706
  var addressEncoder, compiledMessageDecoder, compiledMessageDecoder2;
130707
- var init_chunk_CUM4W6LX = __esm({
130708
- "node_modules/@x402/svm/dist/esm/chunk-CUM4W6LX.mjs"() {
130707
+ var init_chunk_RCDWMK2L = __esm({
130708
+ "node_modules/@x402/svm/dist/esm/chunk-RCDWMK2L.mjs"() {
130709
130709
  "use strict";
130710
- init_chunk_FHYNBUS4();
130711
- init_chunk_BAY4U3CP();
130712
- init_chunk_A5U3JRDR();
130713
- init_chunk_TYATVISX();
130710
+ init_chunk_7TSGYOB2();
130711
+ init_chunk_L56Y5KBE();
130712
+ init_chunk_RZ6M7L3U();
130713
+ init_chunk_DAIKIZVB();
130714
130714
  init_index_node39();
130715
130715
  init_facilitator();
130716
130716
  init_index_node39();
@@ -130755,15 +130755,15 @@ function registerExactSvmScheme(client, config2) {
130755
130755
  var init_client3 = __esm({
130756
130756
  "node_modules/@x402/svm/dist/esm/exact/client/index.mjs"() {
130757
130757
  "use strict";
130758
- init_chunk_OJGL5KXB();
130758
+ init_chunk_2P7IHAQJ();
130759
130759
  init_chunk_WWACQNRQ();
130760
- init_chunk_RERS6LWQ();
130760
+ init_chunk_PQ2KWLVO();
130761
130761
  init_chunk_WIPN332D();
130762
- init_chunk_CUM4W6LX();
130763
- init_chunk_FHYNBUS4();
130764
- init_chunk_BAY4U3CP();
130765
- init_chunk_A5U3JRDR();
130766
- init_chunk_TYATVISX();
130762
+ init_chunk_RCDWMK2L();
130763
+ init_chunk_7TSGYOB2();
130764
+ init_chunk_L56Y5KBE();
130765
+ init_chunk_RZ6M7L3U();
130766
+ init_chunk_DAIKIZVB();
130767
130767
  init_utils9();
130768
130768
  }
130769
130769
  });
@@ -130778,13 +130778,13 @@ var init_v1 = __esm({
130778
130778
  "node_modules/@x402/svm/dist/esm/v1/index.mjs"() {
130779
130779
  "use strict";
130780
130780
  init_chunk_WWACQNRQ();
130781
- init_chunk_RERS6LWQ();
130781
+ init_chunk_PQ2KWLVO();
130782
130782
  init_chunk_WIPN332D();
130783
- init_chunk_CUM4W6LX();
130784
- init_chunk_FHYNBUS4();
130785
- init_chunk_BAY4U3CP();
130786
- init_chunk_A5U3JRDR();
130787
- init_chunk_TYATVISX();
130783
+ init_chunk_RCDWMK2L();
130784
+ init_chunk_7TSGYOB2();
130785
+ init_chunk_L56Y5KBE();
130786
+ init_chunk_RZ6M7L3U();
130787
+ init_chunk_DAIKIZVB();
130788
130788
  }
130789
130789
  });
130790
130790
 
@@ -261218,7 +261218,7 @@ var require_axios = __commonJS({
261218
261218
  function getEnv2(key3) {
261219
261219
  return process.env[key3.toLowerCase()] || process.env[key3.toUpperCase()] || "";
261220
261220
  }
261221
- var VERSION4 = "1.21.0";
261221
+ var VERSION4 = "1.21.1";
261222
261222
  function parseProtocol2(url4) {
261223
261223
  const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url4);
261224
261224
  return match && match[1].toLowerCase() || "";
@@ -264426,8 +264426,11 @@ var require_axios = __commonJS({
264426
264426
  throw new CanceledError3(null, config2);
264427
264427
  }
264428
264428
  }
264429
- function elapsedSince2(start) {
264430
- return Math.max(0, Date.now() - start);
264429
+ function resolveClock2() {
264430
+ return typeof performance !== "undefined" && utils$1.isFunction(performance.now) ? () => performance.now() : Date.now;
264431
+ }
264432
+ function elapsedSince2(now2, start) {
264433
+ return Math.max(0, Math.round(now2() - start));
264431
264434
  }
264432
264435
  function dispatchRequest2(_config) {
264433
264436
  const config2 = utils$1.toSafeFlatObject(_config);
@@ -264438,10 +264441,11 @@ var require_axios = __commonJS({
264438
264441
  config2.headers.setContentType("application/x-www-form-urlencoded", false);
264439
264442
  }
264440
264443
  const adapter2 = adapters.getAdapter(config2.adapter || defaults2.adapter, config2);
264441
- const start = Date.now();
264444
+ const now2 = resolveClock2();
264445
+ const start = now2();
264442
264446
  return adapter2(config2).then(function onAdapterResolution(response) {
264443
264447
  throwIfCancellationRequested2(config2);
264444
- response.duration = elapsedSince2(start);
264448
+ response.duration = elapsedSince2(now2, start);
264445
264449
  config2.response = response;
264446
264450
  try {
264447
264451
  response.data = transformData2.call(config2, config2.transformResponse, response);
@@ -264454,7 +264458,7 @@ var require_axios = __commonJS({
264454
264458
  if (!isCancel3(reason)) {
264455
264459
  throwIfCancellationRequested2(config2);
264456
264460
  if (reason && reason.response) {
264457
- reason.response.duration = elapsedSince2(start);
264461
+ reason.response.duration = elapsedSince2(now2, start);
264458
264462
  config2.response = reason.response;
264459
264463
  try {
264460
264464
  reason.response.data = transformData2.call(config2, config2.transformResponse, reason.response);
@@ -282541,6 +282545,7 @@ function resolveMaxTokens(parsed, fallback2 = DEFAULT_MAX_TOKENS) {
282541
282545
  import * as fs from "fs";
282542
282546
  import * as path from "path";
282543
282547
  import { homedir as homedir2 } from "os";
282548
+ import { randomUUID } from "crypto";
282544
282549
 
282545
282550
  // src/payment-chain.ts
282546
282551
  var PAYMENT_CHAINS = ["base", "solana", "arc"];
@@ -282613,6 +282618,15 @@ function cloneLimits(limits) {
282613
282618
  }
282614
282619
  return clone2;
282615
282620
  }
282621
+ function recordKey(r2) {
282622
+ return r2.id ?? `${r2.timestamp}|${r2.amount}|${r2.model ?? ""}|${r2.action ?? ""}`;
282623
+ }
282624
+ function mergeSpendHistory(a, b) {
282625
+ const byKey = /* @__PURE__ */ new Map();
282626
+ for (const r2 of a) byKey.set(recordKey(r2), r2);
282627
+ for (const r2 of b) if (!byKey.has(recordKey(r2))) byKey.set(recordKey(r2), r2);
282628
+ return [...byKey.values()].sort((x, y) => x.timestamp - y.timestamp);
282629
+ }
282616
282630
  function canonicalLimits(limits) {
282617
282631
  return JSON.stringify(
282618
282632
  Object.fromEntries(Object.entries(limits).sort(([a], [b]) => a < b ? -1 : 1))
@@ -282626,53 +282640,61 @@ var SpendPolicyConflictError = class extends Error {
282626
282640
  };
282627
282641
  var FileSpendControlStorage = class {
282628
282642
  spendingFile;
282629
- constructor() {
282630
- this.spendingFile = path.join(WALLET_DIR, "spending.json");
282643
+ constructor(spendingFile) {
282644
+ this.spendingFile = spendingFile ?? path.join(WALLET_DIR, "spending.json");
282631
282645
  }
282632
282646
  load() {
282647
+ let raw;
282633
282648
  try {
282634
- if (fs.existsSync(this.spendingFile)) {
282635
- const data = JSON.parse(readTextFileSync(this.spendingFile));
282636
- const rawLimits = data.limits ?? {};
282637
- const rawHistory = data.history ?? [];
282638
- const limits = {};
282639
- for (const key3 of ["perRequest", "hourly", "daily", "session"]) {
282640
- const val = rawLimits[key3];
282641
- if (typeof val === "number" && val > 0 && Number.isFinite(val)) {
282642
- limits[key3] = val;
282643
- }
282644
- }
282645
- for (const key3 of POLICY_LISTS) {
282646
- if (!Object.prototype.hasOwnProperty.call(rawLimits, key3)) continue;
282647
- const val = rawLimits[key3];
282648
- if (!isValidPolicyValues(val)) {
282649
- throw new MalformedSpendPolicyError(key3);
282650
- }
282651
- if (val.length === 0) continue;
282652
- limits[key3] = normalizePolicyValues(key3, val);
282653
- }
282654
- const history = [];
282655
- if (Array.isArray(rawHistory)) {
282656
- for (const r2 of rawHistory) {
282657
- if (typeof r2?.timestamp === "number" && typeof r2?.amount === "number" && Number.isFinite(r2.timestamp) && Number.isFinite(r2.amount) && r2.amount >= 0) {
282658
- history.push({
282659
- timestamp: r2.timestamp,
282660
- amount: r2.amount,
282661
- model: typeof r2.model === "string" ? r2.model : void 0,
282662
- action: typeof r2.action === "string" ? r2.action : void 0
282663
- });
282664
- }
282649
+ raw = readTextFileSync(this.spendingFile);
282650
+ } catch (err) {
282651
+ const code = err?.code;
282652
+ if (code === "ENOENT" || code === "ENOTDIR") {
282653
+ return null;
282654
+ }
282655
+ throw new UnreadableSpendPolicyError(err);
282656
+ }
282657
+ try {
282658
+ const data = JSON.parse(raw);
282659
+ const rawLimits = data.limits ?? {};
282660
+ const rawHistory = data.history ?? [];
282661
+ const limits = {};
282662
+ for (const key3 of ["perRequest", "hourly", "daily", "session"]) {
282663
+ const val = rawLimits[key3];
282664
+ if (typeof val === "number" && val > 0 && Number.isFinite(val)) {
282665
+ limits[key3] = val;
282666
+ }
282667
+ }
282668
+ for (const key3 of POLICY_LISTS) {
282669
+ if (!Object.prototype.hasOwnProperty.call(rawLimits, key3)) continue;
282670
+ const val = rawLimits[key3];
282671
+ if (!isValidPolicyValues(val)) {
282672
+ throw new MalformedSpendPolicyError(key3);
282673
+ }
282674
+ if (val.length === 0) continue;
282675
+ limits[key3] = normalizePolicyValues(key3, val);
282676
+ }
282677
+ const history = [];
282678
+ if (Array.isArray(rawHistory)) {
282679
+ for (const r2 of rawHistory) {
282680
+ if (typeof r2?.timestamp === "number" && typeof r2?.amount === "number" && Number.isFinite(r2.timestamp) && Number.isFinite(r2.amount) && r2.amount >= 0) {
282681
+ history.push({
282682
+ timestamp: r2.timestamp,
282683
+ amount: r2.amount,
282684
+ model: typeof r2.model === "string" ? r2.model : void 0,
282685
+ action: typeof r2.action === "string" ? r2.action : void 0,
282686
+ ...typeof r2.id === "string" && r2.id !== "" ? { id: r2.id } : {}
282687
+ });
282665
282688
  }
282666
282689
  }
282667
- return { limits, history };
282668
282690
  }
282691
+ return { limits, history };
282669
282692
  } catch (err) {
282670
282693
  if (err instanceof MalformedSpendPolicyError) {
282671
282694
  throw err;
282672
282695
  }
282673
282696
  throw new UnreadableSpendPolicyError(err);
282674
282697
  }
282675
- return null;
282676
282698
  }
282677
282699
  save(data) {
282678
282700
  try {
@@ -282760,6 +282782,8 @@ var SpendControl = class {
282760
282782
  diskLimits = {};
282761
282783
  /** Set when spending.json held an unusable policy list: refuse every payment. */
282762
282784
  policyFileBroken;
282785
+ /** Whether persisted history loaded successfully; when false, recovery from an initial failure restores history. */
282786
+ initialHistoryLoaded = false;
282763
282787
  storage;
282764
282788
  now;
282765
282789
  constructor(options) {
@@ -282825,7 +282849,7 @@ var SpendControl = class {
282825
282849
  data = this.storage.load();
282826
282850
  } catch (err) {
282827
282851
  if (err instanceof UnreadableSpendPolicyError) {
282828
- console.error(`${err.message} \u2014 keeping the limits already in effect`);
282852
+ console.error(`${err.message}: keeping the limits already in effect`);
282829
282853
  return;
282830
282854
  }
282831
282855
  if (!(err instanceof MalformedSpendPolicyError)) throw err;
@@ -282833,6 +282857,13 @@ var SpendControl = class {
282833
282857
  console.error(`[ClawRouter] ${err.message}`);
282834
282858
  return;
282835
282859
  }
282860
+ if (!this.initialHistoryLoaded) {
282861
+ if (data) {
282862
+ this.history = data.history;
282863
+ this.cleanup();
282864
+ }
282865
+ this.initialHistoryLoaded = true;
282866
+ }
282836
282867
  this.policyFileBroken = void 0;
282837
282868
  this.limits = data ? cloneLimits(data.limits) : {};
282838
282869
  this.diskLimits = cloneLimits(this.limits);
@@ -282926,6 +282957,9 @@ var SpendControl = class {
282926
282957
  };
282927
282958
  }
282928
282959
  const now2 = this.now();
282960
+ if (this.limits.hourly !== void 0 || this.limits.daily !== void 0) {
282961
+ this.syncHistory();
282962
+ }
282929
282963
  if (this.limits.perRequest !== void 0) {
282930
282964
  if (estimatedCost3 > this.limits.perRequest) {
282931
282965
  return {
@@ -282988,7 +283022,8 @@ var SpendControl = class {
282988
283022
  timestamp: this.now(),
282989
283023
  amount,
282990
283024
  model: metadata?.model,
282991
- action: metadata?.action
283025
+ action: metadata?.action,
283026
+ id: randomUUID()
282992
283027
  };
282993
283028
  this.history.push(record2);
282994
283029
  this.sessionSpent += amount;
@@ -283119,6 +283154,32 @@ var SpendControl = class {
283119
283154
  this.sessionSpent = 0;
283120
283155
  this.sessionCalls = 0;
283121
283156
  }
283157
+ /**
283158
+ * Fold in spend that other processes recorded to the same spending.json.
283159
+ *
283160
+ * The hourly and daily windows are per wallet, not per process, but each
283161
+ * process used to read the file once at startup and then trust its own copy:
283162
+ * N proxies started on one wallet each let the full window through, and the
283163
+ * last writer's history replaced the others' on disk (GHSA-9xv2-9567-rxrw).
283164
+ * Re-reading before every amount check and every write closes that for
283165
+ * anything not signed in the same instant. Two processes checking within
283166
+ * one signing round trip of each other can still both pass; reservations
283167
+ * are per process by design (see reserve()).
283168
+ *
283169
+ * A read failure keeps the ledger this instance already has: a file we
283170
+ * cannot read is no reason to forget spend we know about.
283171
+ */
283172
+ syncHistory() {
283173
+ let data;
283174
+ try {
283175
+ data = this.storage.load();
283176
+ } catch {
283177
+ return;
283178
+ }
283179
+ if (!data || data.history.length === 0) return;
283180
+ this.history = mergeSpendHistory(this.history, data.history);
283181
+ this.cleanup();
283182
+ }
283122
283183
  cleanup() {
283123
283184
  const cutoff = this.now() - DAY_MS;
283124
283185
  this.history = this.history.filter((r2) => r2.timestamp >= cutoff);
@@ -283128,6 +283189,7 @@ var SpendControl = class {
283128
283189
  return;
283129
283190
  }
283130
283191
  if (!this.limitsDirty && this.storage.saveHistory) {
283192
+ this.syncHistory();
283131
283193
  this.storage.saveHistory([...this.history]);
283132
283194
  return;
283133
283195
  }
@@ -283160,19 +283222,15 @@ var SpendControl = class {
283160
283222
  try {
283161
283223
  data = this.storage.load();
283162
283224
  } catch (err) {
283163
- if (err instanceof UnreadableSpendPolicyError) {
283225
+ if (err instanceof UnreadableSpendPolicyError || err instanceof MalformedSpendPolicyError) {
283226
+ this.policyFileBroken = err.message;
283227
+ console.error(`[ClawRouter] ${err.message}`);
283164
283228
  console.error(
283165
- `${err.message} \u2014 starting fresh (any configured spend policy is NOT in effect until this file is repaired)`
283229
+ "[ClawRouter] All paid requests will be refused until spending.json is repaired. Free models are unaffected."
283166
283230
  );
283167
283231
  return;
283168
283232
  }
283169
- if (!(err instanceof MalformedSpendPolicyError)) throw err;
283170
- this.policyFileBroken = err.message;
283171
- console.error(`[ClawRouter] ${err.message}`);
283172
- console.error(
283173
- "[ClawRouter] All paid requests will be refused until spending.json is repaired. Free models are unaffected."
283174
- );
283175
- return;
283233
+ throw err;
283176
283234
  }
283177
283235
  if (data) {
283178
283236
  this.limits = cloneLimits(data.limits);
@@ -283180,6 +283238,7 @@ var SpendControl = class {
283180
283238
  this.history = data.history;
283181
283239
  this.cleanup();
283182
283240
  }
283241
+ this.initialHistoryLoaded = true;
283183
283242
  }
283184
283243
  };
283185
283244
  var sharedControlHost = () => process;
@@ -283610,7 +283669,7 @@ function createPermit2Nonce() {
283610
283669
  return BigInt(toHex(randomBytes9)).toString();
283611
283670
  }
283612
283671
 
283613
- // node_modules/@x402/evm/dist/esm/chunk-GPMYUGHX.mjs
283672
+ // node_modules/@x402/evm/dist/esm/chunk-5AIYL4HT.mjs
283614
283673
  var EVM_NETWORK_CHAIN_ID_MAP = {
283615
283674
  ethereum: 1,
283616
283675
  sepolia: 11155111,
@@ -283635,7 +283694,9 @@ var EVM_NETWORK_CHAIN_ID_MAP = {
283635
283694
  stable: 988,
283636
283695
  "stable-testnet": 2201,
283637
283696
  celo: 42220,
283638
- flare: 14
283697
+ flare: 14,
283698
+ hemi: 43111,
283699
+ "hemi-testnet": 743111
283639
283700
  };
283640
283701
  var NETWORKS = Object.keys(EVM_NETWORK_CHAIN_ID_MAP);
283641
283702
  function getEvmChainIdV1(network) {
@@ -283720,7 +283781,7 @@ var DEFAULT_MAX_PRIORITY_FEE_PER_GAS = 100000000n;
283720
283781
  var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
283721
283782
  var x402ExactPermit2ProxyAddress = "0x402085c248EeA27D92E8b30b2C58ed07f9E20001";
283722
283783
 
283723
- // node_modules/@x402/evm/dist/esm/chunk-DIAR36YQ.mjs
283784
+ // node_modules/@x402/evm/dist/esm/chunk-AB46Q4WU.mjs
283724
283785
  var EIP2612_GAS_SPONSORING_KEY = "eip2612GasSponsoring";
283725
283786
  var ERC20_APPROVAL_GAS_SPONSORING_KEY = "erc20ApprovalGasSponsoring";
283726
283787
  var ERC20_APPROVAL_GAS_SPONSORING_VERSION = "1";
@@ -283956,7 +284017,7 @@ async function trySignErc20ApprovalExtension(signer, options, requirements, cont
283956
284017
  };
283957
284018
  }
283958
284019
 
283959
- // node_modules/@x402/evm/dist/esm/chunk-LQQ3M4DU.mjs
284020
+ // node_modules/@x402/evm/dist/esm/chunk-6XWQF37J.mjs
283960
284021
  var DEFAULT_ASSETS = {
283961
284022
  "eip155:8453": [
283962
284023
  {
@@ -284271,8 +284332,39 @@ var DEFAULT_ASSETS = {
284271
284332
  decimals: 6,
284272
284333
  symbol: "USDC"
284273
284334
  }
284274
- ]
284335
+ ],
284275
284336
  // Arc Testnet USDC (EIP-3009 supported)
284337
+ "eip155:4663": [
284338
+ {
284339
+ asset: "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168",
284340
+ name: "Global Dollar",
284341
+ version: "1",
284342
+ decimals: 6,
284343
+ symbol: "USDG"
284344
+ }
284345
+ ],
284346
+ // Robinhood Chain mainnet USDG (EIP-3009 supported)
284347
+ "eip155:43111": [
284348
+ {
284349
+ asset: "0xad11a8BEb98bbf61dbb1aa0F6d6F2ECD87b35afA",
284350
+ name: "Bridged USDC (Stargate)",
284351
+ version: "2",
284352
+ decimals: 6,
284353
+ symbol: "USDC.e"
284354
+ }
284355
+ ],
284356
+ // Hemi mainnet USDC.e (EIP-3009 supported)
284357
+ "eip155:743111": [
284358
+ {
284359
+ asset: "0xD47971C7F5B1067d25cd45d30b2c9eb60de96443",
284360
+ name: "USDC.e",
284361
+ version: "1",
284362
+ decimals: 6,
284363
+ symbol: "USDC.e",
284364
+ assetTransferMethod: "permit2"
284365
+ }
284366
+ ]
284367
+ // Hemi testnet USDC.e (no EIP-3009, no EIP-2612)
284276
284368
  };
284277
284369
  function resolveNetworkKey(network) {
284278
284370
  if (network in DEFAULT_ASSETS) {
@@ -284294,7 +284386,7 @@ var findDefaultAsset = (asset, network) => {
284294
284386
  return assets.find((entry) => entry.asset.toLowerCase() === normalized);
284295
284387
  };
284296
284388
 
284297
- // node_modules/@x402/evm/dist/esm/chunk-7TZ3NXXP.mjs
284389
+ // node_modules/@x402/evm/dist/esm/chunk-X42JDBHW.mjs
284298
284390
  var ExactEvmSchemeV1 = class {
284299
284391
  /**
284300
284392
  * Creates a new ExactEvmClientV1 instance.
@@ -284376,7 +284468,7 @@ var ExactEvmSchemeV1 = class {
284376
284468
  }
284377
284469
  };
284378
284470
 
284379
- // node_modules/@x402/evm/dist/esm/chunk-UNNRPMWF.mjs
284471
+ // node_modules/@x402/evm/dist/esm/chunk-QKR4OFMY.mjs
284380
284472
  async function createPermit2PayloadForProxy(proxyAddress, signer, x402Version2, paymentRequirements) {
284381
284473
  const now2 = Math.floor(Date.now() / 1e3);
284382
284474
  const nonce = createPermit2Nonce();
@@ -284428,7 +284520,7 @@ async function signPermit2Authorization(signer, permit2Authorization, requiremen
284428
284520
  });
284429
284521
  }
284430
284522
 
284431
- // node_modules/@x402/evm/dist/esm/chunk-WC3UEIYC.mjs
284523
+ // node_modules/@x402/evm/dist/esm/chunk-H3CLVT6Z.mjs
284432
284524
  var MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
284433
284525
  async function createPermit2Payload(signer, x402Version2, paymentRequirements) {
284434
284526
  return createPermit2PayloadForProxy(
@@ -284439,7 +284531,7 @@ async function createPermit2Payload(signer, x402Version2, paymentRequirements) {
284439
284531
  );
284440
284532
  }
284441
284533
 
284442
- // node_modules/@x402/evm/dist/esm/chunk-CJ62XFQ3.mjs
284534
+ // node_modules/@x402/evm/dist/esm/chunk-374U7QOG.mjs
284443
284535
  init_utils9();
284444
284536
  async function createEIP3009Payload(signer, x402Version2, paymentRequirements) {
284445
284537
  const nonce = createNonce();
@@ -284579,7 +284671,7 @@ function registerExactEvmScheme(client, config2) {
284579
284671
  return client;
284580
284672
  }
284581
284673
 
284582
- // node_modules/@x402/evm/dist/esm/chunk-F43KMW3I.mjs
284674
+ // node_modules/@x402/evm/dist/esm/chunk-BBPWOJXX.mjs
284583
284675
  var SALT_BINDING_TYPEHASH = keccak256(
284584
284676
  toBytes(
284585
284677
  "x402AuthCaptureSaltBinding(address receiverAuthorizer,address policy,uint256 saltNonce)"
@@ -284591,7 +284683,7 @@ var PAYMENT_INFO_TYPEHASH = keccak256(
284591
284683
  )
284592
284684
  );
284593
284685
 
284594
- // node_modules/@x402/evm/dist/esm/chunk-X3UZRZQA.mjs
284686
+ // node_modules/@x402/evm/dist/esm/chunk-7DJ4WEQ5.mjs
284595
284687
  var CHANNEL_CONFIG_TYPEHASH = keccak256(
284596
284688
  toBytes(
284597
284689
  "ChannelConfig(address payer,address payerAuthorizer,address receiver,address receiverAuthorizer,address token,uint40 withdrawDelay,bytes32 salt)"
@@ -284599,7 +284691,7 @@ var CHANNEL_CONFIG_TYPEHASH = keccak256(
284599
284691
  );
284600
284692
  var UINT96_MASK = (1n << 96n) - 1n;
284601
284693
 
284602
- // node_modules/@x402/evm/dist/esm/chunk-AHBFVQIT.mjs
284694
+ // node_modules/@x402/evm/dist/esm/chunk-AEYKXGQA.mjs
284603
284695
  init_http3();
284604
284696
  init_http3();
284605
284697
  init_client();
@@ -289977,6 +290069,8 @@ var SessionSpend = class _SessionSpend {
289977
290069
  signedMicros = 0n;
289978
290070
  /** Each signature this request made, in order, at the amount that still counts. */
289979
290071
  signedLog = [];
290072
+ /** API-key rail: the latest dispatch's charge was reported by the gateway and recorded. */
290073
+ lastDispatchCharged = false;
289980
290074
  released = false;
289981
290075
  /**
289982
290076
  * Strict mode: admit the request only if the session's spend, plus what its
@@ -290066,13 +290160,32 @@ var SessionSpend = class _SessionSpend {
290066
290160
  this.signedMicros += delta;
290067
290161
  this.store.addSessionCost(this.sessionId, delta);
290068
290162
  }
290163
+ /**
290164
+ * API-key rail: a dispatch is about to go out. Its charge, if the gateway
290165
+ * reports one, belongs to it alone — an earlier attempt's reported charge
290166
+ * must not stand in for this one's estimate.
290167
+ */
290168
+ beginDispatch() {
290169
+ this.lastDispatchCharged = false;
290170
+ }
290171
+ /**
290172
+ * API-key rail: the gateway reported what it charged for the latest
290173
+ * dispatch (`x-blockrun-cost-usd`), on whatever status. It is spend now.
290174
+ */
290175
+ recordCharged(chargedMicros) {
290176
+ this.lastDispatchCharged = true;
290177
+ if (chargedMicros <= 0n) return;
290178
+ this.store.addSessionCost(this.sessionId, chargedMicros);
290179
+ this.shrinkHold(chargedMicros);
290180
+ }
290069
290181
  /**
290070
290182
  * An attempt succeeded. When nothing was signed for this request (the API
290071
- * key rail), the local estimate is the only record of the spend. When a
290072
- * payment was signed, it is already recorded at its real amount.
290183
+ * key rail), the local estimate is the only record of the spend — unless the
290184
+ * gateway reported the winning dispatch's charge, which is already recorded.
290185
+ * When a payment was signed, it is already recorded at its real amount.
290073
290186
  */
290074
290187
  recordSuccess(estimateMicros) {
290075
- if (this.signedLog.length > 0 || estimateMicros <= 0n) return;
290188
+ if (this.signedLog.length > 0 || this.lastDispatchCharged || estimateMicros <= 0n) return;
290076
290189
  this.store.addSessionCost(this.sessionId, estimateMicros);
290077
290190
  this.shrinkHold(estimateMicros);
290078
290191
  }
@@ -290429,12 +290542,28 @@ function shortenPaths(messages) {
290429
290542
 
290430
290543
  // src/compression/layers/json-compact.ts
290431
290544
  function compactJson(jsonString) {
290545
+ if (typeof jsonString !== "string") return jsonString;
290432
290546
  try {
290433
- const parsed = JSON.parse(jsonString);
290434
- return JSON.stringify(parsed);
290547
+ JSON.parse(jsonString);
290435
290548
  } catch {
290436
290549
  return jsonString;
290437
290550
  }
290551
+ let out = "";
290552
+ let start = 0;
290553
+ let inString = false;
290554
+ for (let i = 0; i < jsonString.length; i++) {
290555
+ const ch = jsonString[i];
290556
+ if (inString) {
290557
+ if (ch === "\\") i++;
290558
+ else if (ch === '"') inString = false;
290559
+ } else if (ch === '"') {
290560
+ inString = true;
290561
+ } else if (ch === " " || ch === " " || ch === "\n" || ch === "\r") {
290562
+ out += jsonString.slice(start, i);
290563
+ start = i + 1;
290564
+ }
290565
+ }
290566
+ return out + jsonString.slice(start);
290438
290567
  }
290439
290568
  function looksLikeJson(str) {
290440
290569
  const trimmed = str.trim();
@@ -292213,6 +292342,9 @@ var SHARE_PRESETS = [
292213
292342
  function isSharePreset(s3) {
292214
292343
  return SHARE_PRESETS.includes(s3);
292215
292344
  }
292345
+ var TELEGRAM_MAX_LEN = 4096;
292346
+ var TELEGRAM_SUFFIX_RESERVE = 24;
292347
+ var TELEGRAM_CHUNK_CONTENT_LIMIT = TELEGRAM_MAX_LEN - TELEGRAM_SUFFIX_RESERVE;
292216
292348
  var PH_BOLD = "__CR_PH_BOLD_";
292217
292349
  var PH_LINK = "__CR_PH_LINK_";
292218
292350
  var PH_END = "__";
@@ -292673,20 +292805,44 @@ var ClientDisconnectedError = class extends Error {
292673
292805
  this.name = "ClientDisconnectedError";
292674
292806
  }
292675
292807
  };
292676
- async function readBodyWithTimeout(body, timeoutMs = MODEL_BODY_READ_TIMEOUT_MS) {
292808
+ function isClientAbortError(err, res) {
292809
+ if (err instanceof ClientDisconnectedError) return true;
292810
+ if (!(err instanceof Error)) return false;
292811
+ const clientGone = res.destroyed && !res.writableEnded;
292812
+ return clientGone && (err.name === "AbortError" || err.message.includes("aborted"));
292813
+ }
292814
+ async function readBodyWithTimeout(body, timeoutMs = MODEL_BODY_READ_TIMEOUT_MS, signal, abortError = () => new ClientDisconnectedError()) {
292677
292815
  if (!body) return [];
292816
+ if (signal?.aborted) {
292817
+ await body.cancel().catch(() => {
292818
+ });
292819
+ throw abortError();
292820
+ }
292678
292821
  const reader = body.getReader();
292679
292822
  const chunks = [];
292680
292823
  let timer2;
292824
+ let abortHandler;
292681
292825
  try {
292682
292826
  while (true) {
292827
+ if (signal?.aborted) {
292828
+ throw abortError();
292829
+ }
292830
+ const abortPromise = signal ? new Promise((_, reject) => {
292831
+ abortHandler = () => reject(abortError());
292832
+ signal.addEventListener("abort", abortHandler, { once: true });
292833
+ }) : null;
292683
292834
  const result = await Promise.race([
292684
292835
  reader.read(),
292685
292836
  new Promise((_, reject) => {
292686
292837
  timer2 = setTimeout(() => reject(new Error("Body read timeout")), timeoutMs);
292687
- })
292838
+ }),
292839
+ ...abortPromise ? [abortPromise] : []
292688
292840
  ]);
292689
292841
  clearTimeout(timer2);
292842
+ if (signal && abortHandler) {
292843
+ signal.removeEventListener("abort", abortHandler);
292844
+ abortHandler = void 0;
292845
+ }
292690
292846
  if (result.done) break;
292691
292847
  chunks.push(result.value);
292692
292848
  }
@@ -292696,6 +292852,9 @@ async function readBodyWithTimeout(body, timeoutMs = MODEL_BODY_READ_TIMEOUT_MS)
292696
292852
  throw err;
292697
292853
  } finally {
292698
292854
  clearTimeout(timer2);
292855
+ if (signal && abortHandler) {
292856
+ signal.removeEventListener("abort", abortHandler);
292857
+ }
292699
292858
  reader.releaseLock();
292700
292859
  }
292701
292860
  return chunks;
@@ -293729,6 +293888,26 @@ function withZeroCapGuard(inner, isFree) {
293729
293888
  return inner(input2, init2);
293730
293889
  };
293731
293890
  }
293891
+ function withSessionCostCap(inner) {
293892
+ return async (input2, init2) => {
293893
+ const store = paymentStore.getStore();
293894
+ const spend = store?.sessionSpend;
293895
+ const published = store?.estimatedUsd;
293896
+ if (spend?.isStrict && published !== void 0) {
293897
+ const attemptMicros = usdToMicros(published);
293898
+ if (!spend.coverPayment(attemptMicros)) {
293899
+ throw new CostCapError(
293900
+ `ClawRouter cost cap exceeded: dispatching an estimated $${microsToUsd(attemptMicros).toFixed(6)} would push this session past its maxCostPerRun limit`
293901
+ );
293902
+ }
293903
+ }
293904
+ if (published !== void 0) spend?.beginDispatch();
293905
+ const response = await inner(input2, init2);
293906
+ const charged = gatewaySettledCostUsd(response);
293907
+ if (spend && charged !== void 0) spend.recordCharged(usdToMicros(charged));
293908
+ return response;
293909
+ };
293910
+ }
293732
293911
  function isMessagesPath(url3) {
293733
293912
  return url3 === "/v1/messages" || (url3?.startsWith("/v1/messages?") ?? false);
293734
293913
  }
@@ -293776,9 +293955,15 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
293776
293955
  headers["user-agent"] = USER_AGENT;
293777
293956
  console.log(`[ClawRouter] ${requestLabel} request: ${req.method} ${req.url}`);
293778
293957
  const clientAbort = new AbortController();
293779
- res.on("close", () => {
293780
- if (!res.writableEnded) clientAbort.abort();
293781
- });
293958
+ const onClientDisconnect = () => {
293959
+ if (!res.writableEnded && !clientAbort.signal.aborted) {
293960
+ clientAbort.abort();
293961
+ }
293962
+ };
293963
+ res.on("close", onClientDisconnect);
293964
+ if ((res.destroyed || req.socket?.destroyed) && !res.writableEnded) {
293965
+ onClientDisconnect();
293966
+ }
293782
293967
  publishDispatchCost(0);
293783
293968
  const upstream = await payFetch(upstreamUrl, {
293784
293969
  method: req.method ?? "POST",
@@ -293820,7 +294005,7 @@ async function proxyPaidApiRequest(req, res, apiBase, payFetch, getActualPayment
293820
294005
  res.end();
293821
294006
  }
293822
294007
  } else {
293823
- const chunks = upstream.body ? await readBodyWithTimeout(upstream.body, ERROR_BODY_READ_TIMEOUT_MS) : [];
294008
+ const chunks = upstream.body ? await readBodyWithTimeout(upstream.body, ERROR_BODY_READ_TIMEOUT_MS, clientAbort.signal) : [];
293824
294009
  res.writeHead(upstream.status, responseHeaders);
293825
294010
  for (const chunk of chunks) {
293826
294011
  safeWrite(res, Buffer.from(chunk));
@@ -294162,15 +294347,17 @@ async function startProxy(options) {
294162
294347
  const { freeIds } = catalog.current();
294163
294348
  return freeIds.has(resolveModelAlias(model)) || [...freeIds].some((id2) => toUpstreamModelId(id2) === model);
294164
294349
  };
294165
- const payFetch = authMode === "api-key" ? withSpendPolicy(
294166
- options.maxCostPerRunUsd === 0 ? withZeroCapGuard(keyFetch, isFreeForCap) : keyFetch,
294167
- options.spendControl ?? getSharedSpendControl(),
294168
- () => {
294169
- const store = paymentStore.getStore();
294170
- const published = store?.estimatedUsd;
294171
- if (store) store.estimatedUsd = void 0;
294172
- return published;
294173
- }
294350
+ const payFetch = authMode === "api-key" ? withSessionCostCap(
294351
+ withSpendPolicy(
294352
+ options.maxCostPerRunUsd === 0 ? withZeroCapGuard(keyFetch, isFreeForCap) : keyFetch,
294353
+ options.spendControl ?? getSharedSpendControl(),
294354
+ () => {
294355
+ const store = paymentStore.getStore();
294356
+ const published = store?.estimatedUsd;
294357
+ if (store) store.estimatedUsd = void 0;
294358
+ return published;
294359
+ }
294360
+ )
294174
294361
  ) : createPayFetchWithPreAuth(fetch, x402, void 0, {
294175
294362
  skipPreAuth: paymentChain === "solana",
294176
294363
  // Per-request cost estimate so pre-auth is only reused when the cached
@@ -295168,13 +295355,18 @@ async function startProxy(options) {
295168
295355
  );
295169
295356
  } catch (err) {
295170
295357
  if (refuseOverCostCap(res, err)) return;
295171
- const error62 = err instanceof Error ? err : new Error(String(err));
295172
- options.onError?.(error62);
295173
- if (!res.headersSent) {
295358
+ const clientGone = isClientAbortError(err, res);
295359
+ if (!clientGone) options.onError?.(err instanceof Error ? err : new Error(String(err)));
295360
+ if (clientGone) {
295361
+ if (!res.writableEnded) res.destroy();
295362
+ } else if (!res.headersSent) {
295174
295363
  res.writeHead(502, { "Content-Type": "application/json" });
295175
295364
  res.end(
295176
295365
  JSON.stringify({
295177
- error: { message: `Partner proxy error: ${error62.message}`, type: "partner_error" }
295366
+ error: {
295367
+ message: `Partner proxy error: ${err instanceof Error ? err.message : String(err)}`,
295368
+ type: "partner_error"
295369
+ }
295178
295370
  })
295179
295371
  );
295180
295372
  } else if (!res.writableEnded) {
@@ -295203,18 +295395,25 @@ async function startProxy(options) {
295203
295395
  );
295204
295396
  } catch (err) {
295205
295397
  if (refuseOverCostCap(res, err)) return;
295206
- const error62 = err instanceof Error ? err : new Error(String(err));
295207
- options.onError?.(error62);
295208
- if (!res.headersSent) {
295398
+ const clientGone = isClientAbortError(err, res);
295399
+ if (!clientGone) options.onError?.(err instanceof Error ? err : new Error(String(err)));
295400
+ if (clientGone) {
295401
+ if (!res.writableEnded) res.destroy();
295402
+ } else if (!res.headersSent) {
295209
295403
  res.writeHead(502, { "Content-Type": "application/json" });
295210
295404
  res.end(
295211
295405
  JSON.stringify({
295212
- error: { message: `Account API error: ${error62.message}`, type: "account_error" }
295406
+ error: {
295407
+ message: `Account API error: ${err instanceof Error ? err.message : String(err)}`,
295408
+ type: "account_error"
295409
+ }
295213
295410
  })
295214
295411
  );
295215
295412
  } else if (!res.writableEnded) {
295216
295413
  res.end();
295217
295414
  }
295415
+ } finally {
295416
+ paymentStore.getStore()?.sessionSpend?.release();
295218
295417
  }
295219
295418
  return;
295220
295419
  }
@@ -296747,6 +296946,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
296747
296946
  } else {
296748
296947
  clearInterval(heartbeatInterval);
296749
296948
  heartbeatInterval = void 0;
296949
+ onClientClose();
296750
296950
  }
296751
296951
  }, HEARTBEAT_INTERVAL_MS);
296752
296952
  }
@@ -296776,7 +296976,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
296776
296976
  const timeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
296777
296977
  const globalController = new AbortController();
296778
296978
  const timeoutId = setTimeout(() => globalController.abort(), timeoutMs);
296779
- const clientDisconnected = () => res.destroyed && !res.writableEnded;
296979
+ const clientDisconnected = () => (res.destroyed || req.socket?.destroyed === true) && !res.writableEnded;
296780
296980
  const abortError = () => clientDisconnected() ? new ClientDisconnectedError() : new Error(`Request timed out after ${timeoutMs}ms`);
296781
296981
  const onClientClose = () => {
296782
296982
  if (!res.writableEnded && !globalController.signal.aborted) {
@@ -296785,7 +296985,9 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
296785
296985
  }
296786
296986
  };
296787
296987
  res.on("close", onClientClose);
296788
- if (res.destroyed) onClientClose();
296988
+ if (clientDisconnected()) {
296989
+ onClientClose();
296990
+ }
296789
296991
  try {
296790
296992
  let modelsToTry;
296791
296993
  const excludeList = options.excludeModels ?? loadExcludeList();
@@ -297433,7 +297635,12 @@ data: [DONE]
297433
297635
  const responseChunks = [];
297434
297636
  if (headersSentEarly) {
297435
297637
  if (upstream.body) {
297436
- const chunks = await readBodyWithTimeout(upstream.body);
297638
+ const chunks = await readBodyWithTimeout(
297639
+ upstream.body,
297640
+ MODEL_BODY_READ_TIMEOUT_MS,
297641
+ globalController.signal,
297642
+ abortError
297643
+ );
297437
297644
  const jsonBody = Buffer.concat(chunks);
297438
297645
  const jsonStr = jsonBody.toString();
297439
297646
  try {
@@ -297564,7 +297771,9 @@ data: [DONE]
297564
297771
  responseChunks.push(Buffer.from(finishData));
297565
297772
  }
297566
297773
  }
297567
- } catch {
297774
+ } catch (err) {
297775
+ if (err instanceof ClientDisconnectedError) throw err;
297776
+ if (globalController.signal.aborted) throw abortError();
297568
297777
  const errPayload = JSON.stringify({
297569
297778
  error: {
297570
297779
  message: `Upstream response could not be parsed: ${jsonStr.slice(0, 200)}`,
@@ -297652,7 +297861,12 @@ data: [DONE]
297652
297861
  }
297653
297862
  const bodyParts = [];
297654
297863
  if (upstream.body) {
297655
- const chunks = await readBodyWithTimeout(upstream.body);
297864
+ const chunks = await readBodyWithTimeout(
297865
+ upstream.body,
297866
+ MODEL_BODY_READ_TIMEOUT_MS,
297867
+ globalController.signal,
297868
+ abortError
297869
+ );
297656
297870
  for (const chunk of chunks) {
297657
297871
  bodyParts.push(Buffer.from(chunk));
297658
297872
  }
@@ -298173,7 +298387,7 @@ import {
298173
298387
  } from "fs";
298174
298388
  import { readFile as readFileAsync } from "fs/promises";
298175
298389
  import { homedir as homedir15 } from "os";
298176
- import { randomUUID as randomUUID2 } from "crypto";
298390
+ import { randomUUID as randomUUID3 } from "crypto";
298177
298391
  import { join as join19 } from "path";
298178
298392
  init_accounts();
298179
298393
 
@@ -299322,7 +299536,7 @@ var AMOY_CONTRACTS = {
299322
299536
  conditionalTokens: "0x69308FB512518e39F9b16112fA8d994F4e2Bf8bB",
299323
299537
  exchangeV2: "0xE111180000d2663C0091e4f400237545B87B996B",
299324
299538
  negRiskExchangeV2: "0xe2222d279d744050d28e00520010520000310F59",
299325
- exchangeV3: "0x9fE6e61422AdB6F610d8597F9684b16912D50C3D"
299539
+ exchangeV3: "0xe3333700cA9d93003F00f0F71f8515005F6c00Aa"
299326
299540
  };
299327
299541
  var MATIC_CONTRACTS = {
299328
299542
  exchange: "0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",
@@ -302372,7 +302586,7 @@ import { resolve as resolvePath } from "path";
302372
302586
  import zlib from "zlib";
302373
302587
 
302374
302588
  // node_modules/axios/lib/env/data.js
302375
- var VERSION2 = "1.21.0";
302589
+ var VERSION2 = "1.21.1";
302376
302590
 
302377
302591
  // node_modules/axios/lib/helpers/parseProtocol.js
302378
302592
  function parseProtocol(url3) {
@@ -305873,8 +306087,11 @@ function throwIfCancellationRequested(config2) {
305873
306087
  throw new CanceledError_default(null, config2);
305874
306088
  }
305875
306089
  }
305876
- function elapsedSince(start) {
305877
- return Math.max(0, Date.now() - start);
306090
+ function resolveClock() {
306091
+ return typeof performance !== "undefined" && utils_default.isFunction(performance.now) ? () => performance.now() : Date.now;
306092
+ }
306093
+ function elapsedSince(now2, start) {
306094
+ return Math.max(0, Math.round(now2() - start));
305878
306095
  }
305879
306096
  function dispatchRequest(_config) {
305880
306097
  const config2 = utils_default.toSafeFlatObject(_config);
@@ -305885,11 +306102,12 @@ function dispatchRequest(_config) {
305885
306102
  config2.headers.setContentType("application/x-www-form-urlencoded", false);
305886
306103
  }
305887
306104
  const adapter2 = adapters_default.getAdapter(config2.adapter || defaults_default.adapter, config2);
305888
- const start = Date.now();
306105
+ const now2 = resolveClock();
306106
+ const start = now2();
305889
306107
  return adapter2(config2).then(
305890
306108
  function onAdapterResolution(response) {
305891
306109
  throwIfCancellationRequested(config2);
305892
- response.duration = elapsedSince(start);
306110
+ response.duration = elapsedSince(now2, start);
305893
306111
  config2.response = response;
305894
306112
  try {
305895
306113
  response.data = transformData.call(config2, config2.transformResponse, response);
@@ -305903,7 +306121,7 @@ function dispatchRequest(_config) {
305903
306121
  if (!isCancel(reason)) {
305904
306122
  throwIfCancellationRequested(config2);
305905
306123
  if (reason && reason.response) {
305906
- reason.response.duration = elapsedSince(start);
306124
+ reason.response.duration = elapsedSince(now2, start);
305907
306125
  config2.response = reason.response;
305908
306126
  try {
305909
306127
  reason.response.data = transformData.call(
@@ -310527,7 +310745,7 @@ async function waitForProxyHealth(port, timeoutMs = 3e3) {
310527
310745
  return false;
310528
310746
  }
310529
310747
  function writePrivateJsonSync(path8, value) {
310530
- const temporary = `${path8}.tmp.${randomUUID2()}`;
310748
+ const temporary = `${path8}.tmp.${randomUUID3()}`;
310531
310749
  try {
310532
310750
  writeFileSync8(temporary, JSON.stringify(value, null, 2), { mode: 384 });
310533
310751
  renameSync3(temporary, path8);
@@ -312550,6 +312768,6 @@ js-sha3/src/sha3.js:
312550
312768
  *)
312551
312769
 
312552
312770
  axios/dist/node/axios.cjs:
312553
- (*! Axios v1.21.0 Copyright (c) 2026 Matt Zabriskie and contributors *)
312771
+ (*! Axios v1.21.1 Copyright (c) 2026 Matt Zabriskie and contributors *)
312554
312772
  */
312555
312773
  //# sourceMappingURL=index.js.map