tenjin-cli 0.1.0-alpha.27 → 0.1.0-alpha.29

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.
Files changed (148) hide show
  1. package/README.md +18 -26
  2. package/dist/alive-3J3CHOQP.js +21 -0
  3. package/dist/{chunk-XVYATBKD.js → chunk-25GGN553.js} +897 -522
  4. package/dist/chunk-25GGN553.js.map +1 -0
  5. package/dist/{chunk-B2L53TMK.js → chunk-2SNUOHAT.js} +28 -23
  6. package/dist/chunk-2SNUOHAT.js.map +1 -0
  7. package/dist/{chunk-5NEHH2E5.js → chunk-3FY5HG7R.js} +86 -19
  8. package/dist/chunk-3FY5HG7R.js.map +1 -0
  9. package/dist/{chunk-YQOQ6XEI.js → chunk-4FYMDRD3.js} +51 -41
  10. package/dist/chunk-4FYMDRD3.js.map +1 -0
  11. package/dist/chunk-6W5GYG3W.js +128 -0
  12. package/dist/chunk-6W5GYG3W.js.map +1 -0
  13. package/dist/{chunk-G4AM2SOL.js → chunk-AMEUXNJT.js} +4 -8
  14. package/dist/{chunk-G4AM2SOL.js.map → chunk-AMEUXNJT.js.map} +1 -1
  15. package/dist/chunk-EWLU46J6.js +100 -0
  16. package/dist/chunk-EWLU46J6.js.map +1 -0
  17. package/dist/chunk-LRCJ2IZ5.js +115 -0
  18. package/dist/{chunk-HC3QEZKT.js.map → chunk-LRCJ2IZ5.js.map} +1 -1
  19. package/dist/{chunk-X7I343ZY.js → chunk-LX5OT4TQ.js} +3 -3
  20. package/dist/{chunk-X7I343ZY.js.map → chunk-LX5OT4TQ.js.map} +1 -1
  21. package/dist/{chunk-DATCR7AU.js → chunk-MG3G644T.js} +5 -7
  22. package/dist/{chunk-DATCR7AU.js.map → chunk-MG3G644T.js.map} +1 -1
  23. package/dist/{chunk-BOAI23CX.js → chunk-MOG7PB3A.js} +21 -15
  24. package/dist/chunk-MOG7PB3A.js.map +1 -0
  25. package/dist/{chunk-GU4GGKYP.js → chunk-MRUPDSUM.js} +14 -59
  26. package/dist/chunk-MRUPDSUM.js.map +1 -0
  27. package/dist/{chunk-AWKQSKUL.js → chunk-OOSRB3OF.js} +2 -2
  28. package/dist/{chunk-PZ5N6BAL.js → chunk-ORWL5BSN.js} +5 -4
  29. package/dist/chunk-ORWL5BSN.js.map +1 -0
  30. package/dist/chunk-P4LVLFO4.js +29 -0
  31. package/dist/chunk-P4LVLFO4.js.map +1 -0
  32. package/dist/{chunk-VXIBZ6W5.js → chunk-QTGUDCIR.js} +5 -5
  33. package/dist/{chunk-YKM2ZTA2.js → chunk-R4AO7GC2.js} +462 -105
  34. package/dist/chunk-R4AO7GC2.js.map +1 -0
  35. package/dist/{chunk-OHZYNZSD.js → chunk-RJEPZMYY.js} +12 -8
  36. package/dist/chunk-RJEPZMYY.js.map +1 -0
  37. package/dist/chunk-SBL4THYT.js +2074 -0
  38. package/dist/chunk-SBL4THYT.js.map +1 -0
  39. package/dist/{chunk-VNNXAYJE.js → chunk-SFEQGENI.js} +2 -2
  40. package/dist/{chunk-K6AXXYCG.js → chunk-SJLTEINJ.js} +10 -2
  41. package/dist/{chunk-K6AXXYCG.js.map → chunk-SJLTEINJ.js.map} +1 -1
  42. package/dist/{chunk-5FGO6TYT.js → chunk-TROZ6HL4.js} +3 -5
  43. package/dist/{chunk-5FGO6TYT.js.map → chunk-TROZ6HL4.js.map} +1 -1
  44. package/dist/{chunk-SKQQOEWH.js → chunk-USOLCBKC.js} +6 -8
  45. package/dist/{chunk-SKQQOEWH.js.map → chunk-USOLCBKC.js.map} +1 -1
  46. package/dist/{chunk-64SE3QC5.js → chunk-VKQXVCZR.js} +54 -5
  47. package/dist/chunk-VKQXVCZR.js.map +1 -0
  48. package/dist/{chunk-VIOUZW7Z.js → chunk-VVAHFCX2.js} +209 -37
  49. package/dist/chunk-VVAHFCX2.js.map +1 -0
  50. package/dist/{chunk-4L7KMA7P.js → chunk-WM7TJEBP.js} +8 -10
  51. package/dist/{chunk-4L7KMA7P.js.map → chunk-WM7TJEBP.js.map} +1 -1
  52. package/dist/{chunk-2TYQD22Q.js → chunk-XDYKZRLN.js} +23 -16
  53. package/dist/chunk-XDYKZRLN.js.map +1 -0
  54. package/dist/{chunk-LAIZ2AQA.js → chunk-XJQ6CH7X.js} +3 -2
  55. package/dist/{chunk-O7CUHHYU.js → chunk-ZQNGTLOC.js} +8 -10
  56. package/dist/{chunk-O7CUHHYU.js.map → chunk-ZQNGTLOC.js.map} +1 -1
  57. package/dist/{cli-6JNIPZQ6.js → cli-JPTDHGRX.js} +58 -52
  58. package/dist/{cli-6JNIPZQ6.js.map → cli-JPTDHGRX.js.map} +1 -1
  59. package/dist/{config-G75YT6NC.js → config-YYKDH2TH.js} +12 -15
  60. package/dist/{doctor-3GMDOW4Y.js → doctor-SSTXGCHX.js} +298 -269
  61. package/dist/doctor-SSTXGCHX.js.map +1 -0
  62. package/dist/{fund-3IPR5YRJ.js → fund-QWVWRVDK.js} +95 -43
  63. package/dist/{fund-3IPR5YRJ.js.map → fund-QWVWRVDK.js.map} +1 -1
  64. package/dist/hook-command-VWJXRT7H.js +31 -0
  65. package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
  66. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +14 -0
  67. package/dist/hosts/claude/tenjin/.mcp.json +12 -0
  68. package/dist/hosts/claude/tenjin/hooks/hooks.json +221 -0
  69. package/dist/index.js +13 -4
  70. package/dist/index.js.map +1 -1
  71. package/dist/install-2GXXD4DK.js +51 -0
  72. package/dist/{install-identity-PM4AGFFX.js → install-identity-FK3YF227.js} +7 -9
  73. package/dist/{install-wallet-6756NOB5.js → install-wallet-TC22U52X.js} +21 -17
  74. package/dist/{install-wallet-6756NOB5.js.map → install-wallet-TC22U52X.js.map} +1 -1
  75. package/dist/{mcp-33FAAZ7F.js → mcp-42H2F4NY.js} +2128 -372
  76. package/dist/mcp-42H2F4NY.js.map +1 -0
  77. package/dist/package-6DJA3Y2O.js +37 -0
  78. package/dist/{paths-MUXHUOCM.js → paths-POPTXJO6.js} +6 -2
  79. package/dist/{pay-XOYR4PCH.js → pay-LSDJBIAZ.js} +20 -18
  80. package/dist/payments-SPECLBRQ.js +105 -0
  81. package/dist/payments-SPECLBRQ.js.map +1 -0
  82. package/dist/{send-CVGNOQW3.js → send-MHAOLPK3.js} +13 -17
  83. package/dist/{send-CVGNOQW3.js.map → send-MHAOLPK3.js.map} +1 -1
  84. package/dist/status-O2RWLPS5.js +114 -0
  85. package/dist/status-O2RWLPS5.js.map +1 -0
  86. package/dist/{status-line-3IQKGRUH.js → status-line-45TVCRM3.js} +7 -9
  87. package/dist/{status-line-3IQKGRUH.js.map → status-line-45TVCRM3.js.map} +1 -1
  88. package/dist/uninstall-VOK2Z5M4.js +146 -0
  89. package/dist/uninstall-VOK2Z5M4.js.map +1 -0
  90. package/dist/update-FGP3HNLD.js +33 -0
  91. package/dist/update-FGP3HNLD.js.map +1 -0
  92. package/dist/{wallet-B3FVHNTS.js → wallet-DA7OFNEW.js} +18 -14
  93. package/dist/wallet-DA7OFNEW.js.map +1 -0
  94. package/docs/agent-permissions.md +35 -22
  95. package/docs/safety-model.md +3 -1
  96. package/package.json +2 -2
  97. package/dist/chunk-2TYQD22Q.js.map +0 -1
  98. package/dist/chunk-5NEHH2E5.js.map +0 -1
  99. package/dist/chunk-64SE3QC5.js.map +0 -1
  100. package/dist/chunk-6ZSGER3A.js +0 -52
  101. package/dist/chunk-6ZSGER3A.js.map +0 -1
  102. package/dist/chunk-B2L53TMK.js.map +0 -1
  103. package/dist/chunk-BOAI23CX.js.map +0 -1
  104. package/dist/chunk-DSNXKUXI.js +0 -172
  105. package/dist/chunk-DSNXKUXI.js.map +0 -1
  106. package/dist/chunk-GU4GGKYP.js.map +0 -1
  107. package/dist/chunk-H2L33M7F.js +0 -944
  108. package/dist/chunk-H2L33M7F.js.map +0 -1
  109. package/dist/chunk-HC3QEZKT.js +0 -87
  110. package/dist/chunk-JLEF5WHM.js +0 -132
  111. package/dist/chunk-JLEF5WHM.js.map +0 -1
  112. package/dist/chunk-MAQUL5BD.js +0 -99
  113. package/dist/chunk-MAQUL5BD.js.map +0 -1
  114. package/dist/chunk-OHZYNZSD.js.map +0 -1
  115. package/dist/chunk-PY7MQUKP.js +0 -755
  116. package/dist/chunk-PY7MQUKP.js.map +0 -1
  117. package/dist/chunk-PZ5N6BAL.js.map +0 -1
  118. package/dist/chunk-TGLKKLQG.js +0 -11
  119. package/dist/chunk-TGLKKLQG.js.map +0 -1
  120. package/dist/chunk-VIOUZW7Z.js.map +0 -1
  121. package/dist/chunk-XVYATBKD.js.map +0 -1
  122. package/dist/chunk-YKM2ZTA2.js.map +0 -1
  123. package/dist/chunk-YQOQ6XEI.js.map +0 -1
  124. package/dist/doctor-3GMDOW4Y.js.map +0 -1
  125. package/dist/hook-command-ZXX4FT4N.js +0 -32
  126. package/dist/install-6OROTYHZ.js +0 -72
  127. package/dist/mcp-33FAAZ7F.js.map +0 -1
  128. package/dist/payments-UTQDBO7H.js +0 -48
  129. package/dist/payments-UTQDBO7H.js.map +0 -1
  130. package/dist/status-NACN4DGX.js +0 -72
  131. package/dist/status-NACN4DGX.js.map +0 -1
  132. package/dist/status-line-wiring-QXBOOY2T.js +0 -31
  133. package/dist/uninstall-NYFKSYW4.js +0 -175
  134. package/dist/uninstall-NYFKSYW4.js.map +0 -1
  135. package/dist/update-RJDA5ZY3.js +0 -442
  136. package/dist/update-RJDA5ZY3.js.map +0 -1
  137. /package/dist/{config-G75YT6NC.js.map → alive-3J3CHOQP.js.map} +0 -0
  138. /package/dist/{chunk-AWKQSKUL.js.map → chunk-OOSRB3OF.js.map} +0 -0
  139. /package/dist/{chunk-VXIBZ6W5.js.map → chunk-QTGUDCIR.js.map} +0 -0
  140. /package/dist/{chunk-VNNXAYJE.js.map → chunk-SFEQGENI.js.map} +0 -0
  141. /package/dist/{chunk-LAIZ2AQA.js.map → chunk-XJQ6CH7X.js.map} +0 -0
  142. /package/dist/{hook-command-ZXX4FT4N.js.map → config-YYKDH2TH.js.map} +0 -0
  143. /package/dist/{install-6OROTYHZ.js.map → hook-command-VWJXRT7H.js.map} +0 -0
  144. /package/dist/{install-identity-PM4AGFFX.js.map → install-2GXXD4DK.js.map} +0 -0
  145. /package/dist/{paths-MUXHUOCM.js.map → install-identity-FK3YF227.js.map} +0 -0
  146. /package/dist/{pay-XOYR4PCH.js.map → package-6DJA3Y2O.js.map} +0 -0
  147. /package/dist/{status-line-wiring-QXBOOY2T.js.map → paths-POPTXJO6.js.map} +0 -0
  148. /package/dist/{wallet-B3FVHNTS.js.map → pay-LSDJBIAZ.js.map} +0 -0
@@ -1,10 +1,32 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ ADDITIVE_ARRAY_INFO_FIELDS,
4
+ HTTPFacilitatorClient,
5
+ PaymentRequirementsV2Schema,
6
+ SIGN_IN_WITH_X,
7
+ SIWX_HEADER,
8
+ buildSiwxHeader,
9
+ convertToTokenAmount,
10
+ decodePaymentRequiredHeader,
11
+ decodePaymentResponseHeader,
12
+ deepEqual,
13
+ findByNetworkAndScheme,
14
+ findSchemesByNetwork,
15
+ networkMatchesPattern,
16
+ parseMoney,
17
+ toComparableArray,
18
+ x402HTTPClient,
19
+ x402Version
20
+ } from "./chunk-7EKYXMUO.js";
2
21
  import {
3
22
  promptYesNo
4
23
  } from "./chunk-LHHMV4GU.js";
5
24
  import {
6
25
  assertPublicDestination
7
- } from "./chunk-LAIZ2AQA.js";
26
+ } from "./chunk-XJQ6CH7X.js";
27
+ import {
28
+ USDC_ADDRESS
29
+ } from "./chunk-SFEQGENI.js";
8
30
  import {
9
31
  BATCH_SETTLEMENT_ADDRESS,
10
32
  BATCH_SETTLEMENT_SCHEME,
@@ -25,30 +47,20 @@ import {
25
47
  receiveAuthorizationTypes,
26
48
  voucherTypes
27
49
  } from "./chunk-LFZJM56J.js";
28
- import {
29
- ADDITIVE_ARRAY_INFO_FIELDS,
30
- HTTPFacilitatorClient,
31
- PaymentRequirementsV2Schema,
32
- SIGN_IN_WITH_X,
33
- SIWX_HEADER,
34
- buildSiwxHeader,
35
- convertToTokenAmount,
36
- decodePaymentRequiredHeader,
37
- decodePaymentResponseHeader,
38
- deepEqual,
39
- findByNetworkAndScheme,
40
- findSchemesByNetwork,
41
- networkMatchesPattern,
42
- parseMoney,
43
- toComparableArray,
44
- x402HTTPClient,
45
- x402Version
46
- } from "./chunk-7EKYXMUO.js";
47
50
  import {
48
51
  createPublicClient,
49
52
  http,
50
53
  recoverTypedDataAddress
51
54
  } from "./chunk-EL56RW2J.js";
55
+ import {
56
+ describeWallet,
57
+ resolveSpendAuthorizer,
58
+ resolveWalletProvider
59
+ } from "./chunk-ZQNGTLOC.js";
60
+ import {
61
+ readSpendSummary,
62
+ spentOf
63
+ } from "./chunk-LX5OT4TQ.js";
52
64
  import {
53
65
  encodeAbiParameters,
54
66
  encodeFunctionData,
@@ -58,13 +70,14 @@ import {
58
70
  toBytes
59
71
  } from "./chunk-TTNESUPQ.js";
60
72
  import {
61
- USDC_ADDRESS
62
- } from "./chunk-VNNXAYJE.js";
73
+ withFileLock
74
+ } from "./chunk-MEFB5KHA.js";
63
75
  import {
64
- describeWallet,
65
- resolveSpendAuthorizer,
66
- resolveWalletProvider
67
- } from "./chunk-O7CUHHYU.js";
76
+ evaluatePlan
77
+ } from "./chunk-2SNUOHAT.js";
78
+ import {
79
+ sanitizeForTerminal
80
+ } from "./chunk-TROZ6HL4.js";
68
81
  import {
69
82
  getAddress
70
83
  } from "./chunk-EGELTSPU.js";
@@ -74,25 +87,22 @@ import {
74
87
  import {
75
88
  fetchFailureToCliError,
76
89
  httpRequest
77
- } from "./chunk-OHZYNZSD.js";
78
- import {
79
- sanitizeForTerminal
80
- } from "./chunk-5FGO6TYT.js";
90
+ } from "./chunk-RJEPZMYY.js";
81
91
  import {
82
92
  resolveContextSettings
83
- } from "./chunk-G4AM2SOL.js";
84
- import {
85
- parseUsdToAtomic,
86
- toMoney
87
- } from "./chunk-6ZSGER3A.js";
93
+ } from "./chunk-AMEUXNJT.js";
88
94
  import {
95
+ CliError,
89
96
  external_exports,
90
97
  isSameDeployment,
91
- readUsdcBalanceWithFallback
92
- } from "./chunk-VIOUZW7Z.js";
98
+ parseUsdToAtomic,
99
+ readUsdcBalanceWithFallback,
100
+ toMoney,
101
+ writeFileAtomic
102
+ } from "./chunk-VVAHFCX2.js";
93
103
  import {
94
- CliError
95
- } from "./chunk-JLEF5WHM.js";
104
+ quotesDir
105
+ } from "./chunk-SJLTEINJ.js";
96
106
  import {
97
107
  __commonJS,
98
108
  __toESM
@@ -475,11 +485,11 @@ var require_codegen = __commonJS({
475
485
  const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
476
486
  return `${varKind} ${this.name}${rhs};` + _n;
477
487
  }
478
- optimizeNames(names, constants) {
488
+ optimizeNames(names, constants2) {
479
489
  if (!names[this.name.str])
480
490
  return;
481
491
  if (this.rhs)
482
- this.rhs = optimizeExpr(this.rhs, names, constants);
492
+ this.rhs = optimizeExpr(this.rhs, names, constants2);
483
493
  return this;
484
494
  }
485
495
  get names() {
@@ -496,10 +506,10 @@ var require_codegen = __commonJS({
496
506
  render({ _n }) {
497
507
  return `${this.lhs} = ${this.rhs};` + _n;
498
508
  }
499
- optimizeNames(names, constants) {
509
+ optimizeNames(names, constants2) {
500
510
  if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
501
511
  return;
502
- this.rhs = optimizeExpr(this.rhs, names, constants);
512
+ this.rhs = optimizeExpr(this.rhs, names, constants2);
503
513
  return this;
504
514
  }
505
515
  get names() {
@@ -560,8 +570,8 @@ var require_codegen = __commonJS({
560
570
  optimizeNodes() {
561
571
  return `${this.code}` ? this : void 0;
562
572
  }
563
- optimizeNames(names, constants) {
564
- this.code = optimizeExpr(this.code, names, constants);
573
+ optimizeNames(names, constants2) {
574
+ this.code = optimizeExpr(this.code, names, constants2);
565
575
  return this;
566
576
  }
567
577
  get names() {
@@ -590,12 +600,12 @@ var require_codegen = __commonJS({
590
600
  }
591
601
  return nodes.length > 0 ? this : void 0;
592
602
  }
593
- optimizeNames(names, constants) {
603
+ optimizeNames(names, constants2) {
594
604
  const { nodes } = this;
595
605
  let i = nodes.length;
596
606
  while (i--) {
597
607
  const n = nodes[i];
598
- if (n.optimizeNames(names, constants))
608
+ if (n.optimizeNames(names, constants2))
599
609
  continue;
600
610
  subtractNames(names, n.names);
601
611
  nodes.splice(i, 1);
@@ -648,12 +658,12 @@ var require_codegen = __commonJS({
648
658
  return void 0;
649
659
  return this;
650
660
  }
651
- optimizeNames(names, constants) {
661
+ optimizeNames(names, constants2) {
652
662
  var _a;
653
- this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);
654
- if (!(super.optimizeNames(names, constants) || this.else))
663
+ this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants2);
664
+ if (!(super.optimizeNames(names, constants2) || this.else))
655
665
  return;
656
- this.condition = optimizeExpr(this.condition, names, constants);
666
+ this.condition = optimizeExpr(this.condition, names, constants2);
657
667
  return this;
658
668
  }
659
669
  get names() {
@@ -676,10 +686,10 @@ var require_codegen = __commonJS({
676
686
  render(opts) {
677
687
  return `for(${this.iteration})` + super.render(opts);
678
688
  }
679
- optimizeNames(names, constants) {
680
- if (!super.optimizeNames(names, constants))
689
+ optimizeNames(names, constants2) {
690
+ if (!super.optimizeNames(names, constants2))
681
691
  return;
682
- this.iteration = optimizeExpr(this.iteration, names, constants);
692
+ this.iteration = optimizeExpr(this.iteration, names, constants2);
683
693
  return this;
684
694
  }
685
695
  get names() {
@@ -715,10 +725,10 @@ var require_codegen = __commonJS({
715
725
  render(opts) {
716
726
  return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
717
727
  }
718
- optimizeNames(names, constants) {
719
- if (!super.optimizeNames(names, constants))
728
+ optimizeNames(names, constants2) {
729
+ if (!super.optimizeNames(names, constants2))
720
730
  return;
721
- this.iterable = optimizeExpr(this.iterable, names, constants);
731
+ this.iterable = optimizeExpr(this.iterable, names, constants2);
722
732
  return this;
723
733
  }
724
734
  get names() {
@@ -760,11 +770,11 @@ var require_codegen = __commonJS({
760
770
  (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
761
771
  return this;
762
772
  }
763
- optimizeNames(names, constants) {
773
+ optimizeNames(names, constants2) {
764
774
  var _a, _b;
765
- super.optimizeNames(names, constants);
766
- (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);
767
- (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants);
775
+ super.optimizeNames(names, constants2);
776
+ (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants2);
777
+ (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants2);
768
778
  return this;
769
779
  }
770
780
  get names() {
@@ -1065,7 +1075,7 @@ var require_codegen = __commonJS({
1065
1075
  function addExprNames(names, from) {
1066
1076
  return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
1067
1077
  }
1068
- function optimizeExpr(expr, names, constants) {
1078
+ function optimizeExpr(expr, names, constants2) {
1069
1079
  if (expr instanceof code_1.Name)
1070
1080
  return replaceName(expr);
1071
1081
  if (!canOptimize(expr))
@@ -1080,14 +1090,14 @@ var require_codegen = __commonJS({
1080
1090
  return items;
1081
1091
  }, []));
1082
1092
  function replaceName(n) {
1083
- const c = constants[n.str];
1093
+ const c = constants2[n.str];
1084
1094
  if (c === void 0 || names[n.str] !== 1)
1085
1095
  return n;
1086
1096
  delete names[n.str];
1087
1097
  return c;
1088
1098
  }
1089
1099
  function canOptimize(e) {
1090
- return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants[c.str] !== void 0);
1100
+ return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants2[c.str] !== void 0);
1091
1101
  }
1092
1102
  }
1093
1103
  function subtractNames(names, from) {
@@ -8859,11 +8869,11 @@ function policyFix(reason, allowlistSubject) {
8859
8869
  case "not_allowlisted":
8860
8870
  return `Add ${allowlistSubject} to allowlistCreators, or clear the allowlist.`;
8861
8871
  case "session_budget_exceeded":
8862
- return "Raise sessionBudget with `tenjin config set sessionBudget <usd>`, or wait for the window to roll over.";
8872
+ return "Today's automatic budget is spent; it comes back as the rolling 24 hours pass. Nothing more is paid without the user's yes.";
8863
8873
  case "duplicate_in_flight":
8864
8874
  return "Let the in-flight request finish and read its result; retrying the same request does not renew authorization.";
8865
8875
  default:
8866
- return "Adjust your spend policy with `tenjin config set`.";
8876
+ return "This is over what this machine pays without asking, so it is not paid without the user's yes.";
8867
8877
  }
8868
8878
  }
8869
8879
  async function confirmSpend(input) {
@@ -8875,6 +8885,193 @@ async function confirmSpend(input) {
8875
8885
  return promptYesNo(prompt);
8876
8886
  }
8877
8887
 
8888
+ // src/lib/spend-quotes.ts
8889
+ import { randomBytes } from "node:crypto";
8890
+ import { constants } from "node:fs";
8891
+ import { open, opendir, rm } from "node:fs/promises";
8892
+ import { join as join2 } from "node:path";
8893
+ var QUOTE_TTL_MS = 10 * 6e4;
8894
+ var MAX_QUOTE_BYTES = 512 * 1024;
8895
+ var QUOTE_ID = /^q_[A-Za-z0-9_-]{12}$/;
8896
+ var Iso = external_exports.string().max(40);
8897
+ var Digits = external_exports.string().regex(/^\d+$/);
8898
+ var QuoteSchema = external_exports.strictObject({
8899
+ version: external_exports.literal(1),
8900
+ id: external_exports.string().regex(QUOTE_ID),
8901
+ createdAt: Iso,
8902
+ expiresAt: Iso,
8903
+ /** What the payments buy, as the user is asked about it. */
8904
+ what: external_exports.string().min(1).max(400),
8905
+ /** The one sentence the agent repeats and the user answers. */
8906
+ sentence: external_exports.string().min(1).max(800),
8907
+ totalAtomic: Digits,
8908
+ payments: external_exports.array(external_exports.strictObject({ amountAtomic: Digits, creator: external_exports.string().min(1).max(300) })).min(1).max(8),
8909
+ /** The call this quote runs, exactly: the router's own shape. */
8910
+ call: external_exports.unknown(),
8911
+ /** It ran: nothing more is paid on it. */
8912
+ usedAt: Iso.optional()
8913
+ });
8914
+ function isQuoteId(id) {
8915
+ return QUOTE_ID.test(id);
8916
+ }
8917
+ function quotePath(dataDir, id) {
8918
+ return join2(quotesDir(dataDir), `${id}.json`);
8919
+ }
8920
+ async function createQuote(dataDir, plan, now = Date.now) {
8921
+ const at = now();
8922
+ const quote = {
8923
+ version: 1,
8924
+ id: `q_${randomBytes(9).toString("base64url")}`,
8925
+ createdAt: new Date(at).toISOString(),
8926
+ expiresAt: new Date(at + QUOTE_TTL_MS).toISOString(),
8927
+ what: plan.what.slice(0, 400),
8928
+ sentence: plan.sentence.slice(0, 800),
8929
+ totalAtomic: plan.payments.reduce((sum, payment) => sum + payment.amountAtomic, 0n).toString(),
8930
+ payments: plan.payments.map((payment) => ({
8931
+ amountAtomic: payment.amountAtomic.toString(),
8932
+ creator: payment.creator
8933
+ })),
8934
+ call: plan.call
8935
+ };
8936
+ await writeQuote(dataDir, quote);
8937
+ void pruneQuotes(dataDir, at);
8938
+ return quote;
8939
+ }
8940
+ async function writeQuote(dataDir, quote) {
8941
+ await writeFileAtomic(quotePath(dataDir, quote.id), JSON.stringify(quote), {
8942
+ mode: 384,
8943
+ dirMode: 448
8944
+ });
8945
+ }
8946
+ async function readQuote(dataDir, id) {
8947
+ if (!isQuoteId(id)) return null;
8948
+ const file = await open(quotePath(dataDir, id), constants.O_RDONLY | constants.O_NOFOLLOW).catch(
8949
+ () => void 0
8950
+ );
8951
+ if (file === void 0) return null;
8952
+ try {
8953
+ const stat = await file.stat();
8954
+ if (!stat.isFile() || stat.size > MAX_QUOTE_BYTES) return null;
8955
+ const parsed = QuoteSchema.safeParse(JSON.parse(await file.readFile("utf8")));
8956
+ return parsed.success && parsed.data.id === id ? parsed.data : null;
8957
+ } catch {
8958
+ return null;
8959
+ } finally {
8960
+ await file.close().catch(() => void 0);
8961
+ }
8962
+ }
8963
+ function quoteClosed(quote, now) {
8964
+ if (quote.usedAt !== void 0) return "used";
8965
+ return Date.parse(quote.expiresAt) <= now ? "expired" : null;
8966
+ }
8967
+ async function changeQuote(dataDir, id, change) {
8968
+ if (!isQuoteId(id)) return { refused: "missing" };
8969
+ return withFileLock(
8970
+ `${quotePath(dataDir, id)}.lock`,
8971
+ async () => {
8972
+ const current = await readQuote(dataDir, id);
8973
+ if (current === null) return { refused: "missing" };
8974
+ const next = change(current);
8975
+ if (typeof next === "string") return { refused: next };
8976
+ await writeQuote(dataDir, next);
8977
+ return { quote: next };
8978
+ },
8979
+ { timeoutMs: 3e4 }
8980
+ );
8981
+ }
8982
+ function useQuote(dataDir, id, now = Date.now) {
8983
+ return changeQuote(dataDir, id, (quote) => {
8984
+ const at = now();
8985
+ return quoteClosed(quote, at) ?? { ...quote, usedAt: new Date(at).toISOString() };
8986
+ });
8987
+ }
8988
+ async function pruneQuotes(dataDir, now) {
8989
+ try {
8990
+ const dir = quotesDir(dataDir);
8991
+ for await (const entry of await opendir(dir)) {
8992
+ const id = entry.name.replace(/\.json$/, "");
8993
+ if (!entry.isFile() || !entry.name.endsWith(".json") || !isQuoteId(id)) continue;
8994
+ const quote = await readQuote(dataDir, id);
8995
+ const stale = quote !== null ? Date.parse(quote.expiresAt) < now : await open(join2(dir, entry.name), constants.O_RDONLY | constants.O_NOFOLLOW).then(async (file) => {
8996
+ try {
8997
+ return now - (await file.stat()).mtimeMs > 24 * 60 * 6e4;
8998
+ } finally {
8999
+ await file.close().catch(() => void 0);
9000
+ }
9001
+ }).catch(() => false);
9002
+ if (stale) await rm(join2(dir, entry.name), { force: true }).catch(() => void 0);
9003
+ }
9004
+ } catch {
9005
+ }
9006
+ }
9007
+
9008
+ // src/lib/spend-plan.ts
9009
+ var minted = /* @__PURE__ */ new WeakSet();
9010
+ var spent = /* @__PURE__ */ new WeakSet();
9011
+ function mint(amountAtomic, approved) {
9012
+ const slot = Object.freeze({ amountAtomic, approved });
9013
+ minted.add(slot);
9014
+ return slot;
9015
+ }
9016
+ function spendSlot(slot, amountAtomic) {
9017
+ if (typeof slot !== "object" || slot === null || !minted.has(slot)) {
9018
+ return "unplanned";
9019
+ }
9020
+ const held = slot;
9021
+ if (spent.has(held)) return "spent";
9022
+ if (amountAtomic > held.amountAtomic) return "above_plan";
9023
+ spent.add(held);
9024
+ return null;
9025
+ }
9026
+ async function admitPlan(payments, opts) {
9027
+ const totalAtomic = payments.reduce((sum, payment) => sum + payment.amountAtomic, 0n);
9028
+ const ledger = await readSpendSummary(opts.dataDir, {
9029
+ ...opts.now !== void 0 ? { now: opts.now } : {}
9030
+ });
9031
+ const spentAtomic = ledger === null ? 0n : spentOf(ledger);
9032
+ const evaluation = evaluatePlan(opts.policy, payments, spentAtomic);
9033
+ if (evaluation.reason === "not_allowlisted") return { refused: { message: evaluation.message } };
9034
+ const over = evaluation.decision !== "allow";
9035
+ if ((payments.length > 1 || over) && totalAtomic > 0n) {
9036
+ const balanceAtomic = await opts.balance();
9037
+ if (balanceAtomic !== null && balanceAtomic < totalAtomic) {
9038
+ return { short: { balanceAtomic, totalAtomic } };
9039
+ }
9040
+ }
9041
+ if (over) {
9042
+ const budget = opts.policy.sessionBudgetAtomic;
9043
+ return {
9044
+ over: {
9045
+ reason: evaluation.reason === "session_budget_exceeded" ? "session_budget_exceeded" : "above_auto_spend",
9046
+ totalAtomic,
9047
+ maxAutoSpendAtomic: opts.policy.maxAutoSpendAtomic,
9048
+ budgetLeftAtomic: budget === null ? null : budget > spentAtomic ? budget - spentAtomic : 0n
9049
+ }
9050
+ };
9051
+ }
9052
+ return { admitted: payments.map((payment) => mint(payment.amountAtomic, false)) };
9053
+ }
9054
+ async function admitQuote(dataDir, id, opts) {
9055
+ const now = opts.now ?? Date.now;
9056
+ const kept = await readQuote(dataDir, id);
9057
+ if (kept === null) return { refused: "missing" };
9058
+ const closed = quoteClosed(kept, now());
9059
+ if (closed !== null) return { refused: closed };
9060
+ const totalAtomic = BigInt(kept.totalAtomic);
9061
+ if (totalAtomic > 0n) {
9062
+ const balanceAtomic = await opts.balance();
9063
+ if (balanceAtomic !== null && balanceAtomic < totalAtomic) {
9064
+ return { short: { balanceAtomic, totalAtomic } };
9065
+ }
9066
+ }
9067
+ const used = await useQuote(dataDir, id, now);
9068
+ if ("refused" in used) return used;
9069
+ return {
9070
+ quote: used.quote,
9071
+ admitted: used.quote.payments.map((payment) => mint(BigInt(payment.amountAtomic), true))
9072
+ };
9073
+ }
9074
+
8878
9075
  // node_modules/.pnpm/@x402+core@2.28.0/node_modules/@x402/core/dist/esm/client/index.mjs
8879
9076
  var DEFAULT_MAX_AMOUNT_PER_PAYMENT = "$1";
8880
9077
  function isAtomicAmount(amount) {
@@ -11748,6 +11945,13 @@ async function executePay(args, ctx, deps, warnings) {
11748
11945
  { details: { reason: "invalid_router_terms" } }
11749
11946
  );
11750
11947
  }
11948
+ if (args.admit === void 0) {
11949
+ throw new CliError(
11950
+ "REFUSED",
11951
+ "A router payment is signed only against its call's spend plan, and this one has none; nothing was sent.",
11952
+ { details: { reason: "unplanned" } }
11953
+ );
11954
+ }
11751
11955
  }
11752
11956
  const settings = await resolveContextSettings(ctx);
11753
11957
  const maxPriceAtomic = args.maxPrice !== void 0 ? BigInt(parseUsdToAtomic(args.maxPrice)) : void 0;
@@ -11781,6 +11985,7 @@ async function executePay(args, ctx, deps, warnings) {
11781
11985
  }
11782
11986
  if (probe.status >= 200 && probe.status < 300) {
11783
11987
  const caveat = assertUsableResult(args.resultSchema, probe.text, probe.status, "free");
11988
+ args.onPaidLeg?.({ status: probe.status, header: probe.header });
11784
11989
  return deliver(url, lane, probe, {
11785
11990
  paid: false,
11786
11991
  ...caveat !== void 0 ? { caveat } : {},
@@ -11819,6 +12024,8 @@ async function executePay(args, ctx, deps, warnings) {
11819
12024
  warnings
11820
12025
  );
11821
12026
  }
12027
+ const entitlement = paymentRequired.extensions?.[SIGN_IN_WITH_X] !== void 0;
12028
+ let slot = router && !entitlement ? await args.admit(firstSeenAmount) : void 0;
11822
12029
  const provider = resolveWalletProvider(
11823
12030
  ctx,
11824
12031
  deps.provider !== void 0 ? { provider: deps.provider } : {}
@@ -11827,7 +12034,7 @@ async function executePay(args, ctx, deps, warnings) {
11827
12034
  openedSigner.current = signer;
11828
12035
  let effectiveChallenge = paymentRequired;
11829
12036
  let effectiveRequirement = requirement;
11830
- if (paymentRequired.extensions?.[SIGN_IN_WITH_X] !== void 0) {
12037
+ if (entitlement) {
11831
12038
  const siwxHeader = await buildSiwxHeader(signer, {
11832
12039
  baseUrl: new URL(url).origin,
11833
12040
  chainId: requirement.network
@@ -11844,6 +12051,7 @@ async function executePay(args, ctx, deps, warnings) {
11844
12051
  recheck.status,
11845
12052
  "entitled"
11846
12053
  );
12054
+ args.onPaidLeg?.({ status: recheck.status, header: recheck.header });
11847
12055
  return deliver(url, lane, recheck, {
11848
12056
  paid: false,
11849
12057
  entitled: true,
@@ -11896,6 +12104,32 @@ async function executePay(args, ctx, deps, warnings) {
11896
12104
  }
11897
12105
  }
11898
12106
  const amountAtomic = BigInt(effectiveRequirement.amount);
12107
+ if (router && entitlement) slot = await args.admit(amountAtomic);
12108
+ if (router) {
12109
+ const refusal2 = spendSlot(slot, amountAtomic);
12110
+ if (refusal2 === "above_plan") {
12111
+ throw new CliError(
12112
+ "PAYMENT_FAILED",
12113
+ `The live price ($${toMoney(amountAtomic.toString()).usd}) is above the $${toMoney(slot.amountAtomic.toString()).usd} this call planned for it, so nothing was signed.`,
12114
+ {
12115
+ fix: "Call again for a fresh plan at the new price.",
12116
+ details: {
12117
+ reason: "above_plan",
12118
+ plannedAtomic: slot.amountAtomic.toString(),
12119
+ live: { amount: amountAtomic.toString() }
12120
+ }
12121
+ }
12122
+ );
12123
+ }
12124
+ if (refusal2 !== null) {
12125
+ throw new CliError(
12126
+ "REFUSED",
12127
+ "A router payment is signed only against an unspent slot of its call's spend plan; nothing was signed.",
12128
+ { details: { reason: refusal2 } }
12129
+ );
12130
+ }
12131
+ }
12132
+ const approved = slot?.approved === true;
11899
12133
  const authorizer = resolveSpendAuthorizer(
11900
12134
  ctx,
11901
12135
  settings.policy,
@@ -11903,7 +12137,7 @@ async function executePay(args, ctx, deps, warnings) {
11903
12137
  );
11904
12138
  const verifiedVia = registry ?? termsLabel;
11905
12139
  const via = verifiedVia !== void 0 ? ` (${sanitizeForTerminal(verifiedVia)})` : "";
11906
- const mode = router ? "automatic" : "manual";
12140
+ const mode = router && !approved ? "automatic" : "manual";
11907
12141
  const reservationId = await gateSpend({
11908
12142
  mode,
11909
12143
  ctx,
@@ -11912,7 +12146,7 @@ async function executePay(args, ctx, deps, warnings) {
11912
12146
  creator: host,
11913
12147
  ...maxPriceAtomic !== void 0 ? { maxPriceAtomic } : {},
11914
12148
  ...args.requestKey !== void 0 ? { requestKey: args.requestKey } : {},
11915
- yes: args.yes === true,
12149
+ yes: args.yes === true || approved,
11916
12150
  ...deps.confirm !== void 0 ? { confirm: deps.confirm } : {},
11917
12151
  payeeLabel: `${sanitizeForTerminal(url)}${via}; recipient ${sanitizeForTerminal(effectiveRequirement.payTo)}, ${sanitizeForTerminal(effectiveRequirement.network)} / ${sanitizeForTerminal(effectiveRequirement.asset)}`,
11918
12152
  allowlistSubject: "this host",
@@ -11920,55 +12154,45 @@ async function executePay(args, ctx, deps, warnings) {
11920
12154
  });
11921
12155
  let payment;
11922
12156
  try {
11923
- if (amountAtomic > 0n) {
11924
- const deadline = Date.now() + ctx.flags.timeout;
11925
- const readBalance = deps.readBalance ?? readUsdcBalanceWithFallback;
11926
- let balance = await readBalance(signer.address, settings.rpcUrl, {
11927
- timeoutMs: Math.max(1, Math.floor(ctx.flags.timeout / 2))
11928
- });
11929
- if (balance === null && Date.now() < deadline) {
11930
- await delay(Math.min(1100, Math.floor((deadline - Date.now()) / 2)));
11931
- const remaining = deadline - Date.now();
11932
- if (remaining > 0)
11933
- balance = await readBalance(signer.address, settings.rpcUrl, { timeoutMs: remaining });
11934
- }
11935
- if (balance === null) {
11936
- throw new CliError(
11937
- "REFUSED",
11938
- "The wallet balance could not be read; no payment was signed.",
11939
- {
11940
- fix: "Check the configured Base rpcUrl and retry when it is available.",
11941
- details: { reason: "balance_unavailable", address: signer.address }
11942
- }
11943
- );
11944
- }
11945
- if (balance < amountAtomic) {
11946
- throw new CliError("REFUSED", "The wallet has insufficient USDC; no payment was signed.", {
11947
- fix: "Fund this wallet on Base with `tenjin wallet fund` before paying.",
11948
- details: {
11949
- reason: "insufficient_funds",
11950
- address: signer.address,
11951
- balanceAtomic: balance.toString(),
11952
- requiredAtomic: amountAtomic.toString()
11953
- }
11954
- });
11955
- }
11956
- }
12157
+ await assertBalanceCovers(signer.address, amountAtomic, settings.rpcUrl, ctx, deps);
11957
12158
  payment = await buildExactPayment(effectiveChallenge, signer, effectiveRequirement);
11958
12159
  } catch (err) {
11959
12160
  await authorizer.release(reservationId);
11960
12161
  throw err;
11961
12162
  }
12163
+ const paidTimeoutMs = paidLegTimeoutMs(effectiveRequirement, ctx.flags.timeout);
11962
12164
  const paid = await httpRequest(url, {
11963
12165
  ...fetchOpts,
11964
- timeoutMs: paidLegTimeoutMs(effectiveRequirement, ctx.flags.timeout),
12166
+ timeoutMs: paidTimeoutMs,
11965
12167
  headers: { ...headers, ...payment.headers }
11966
12168
  });
11967
12169
  await authorizer.commit(reservationId, payment.amountAtomic, {
11968
12170
  mode,
11969
12171
  ...payment.authorization !== void 0 ? { nonce: payment.authorization.nonce } : {}
11970
12172
  });
12173
+ if (paid.ok || paid.header !== void 0) {
12174
+ args.onPaidLeg?.({
12175
+ ...paid.status !== void 0 ? { status: paid.status } : {},
12176
+ ...paid.header !== void 0 ? { header: paid.header } : {}
12177
+ });
12178
+ }
11971
12179
  if (!paid.ok) {
12180
+ const statusUrl = paid.kind === "timeout" ? statusUrlOf(paid, url) : null;
12181
+ if (statusUrl !== null) {
12182
+ throw new CliError(
12183
+ "NETWORK_ERROR",
12184
+ `The seller is still working on this: no result within ${Math.round(paidTimeoutMs / 1e3)} s, and it named a status URL to check: ${statusUrl}`,
12185
+ {
12186
+ fix: "The authorization was transmitted and settlement is unknown until the job ends; it is recorded as transmitted exposure. Do not pay again: check the status URL for the result.",
12187
+ details: {
12188
+ statusUrl,
12189
+ amountAtomic: payment.amountAtomic.toString(),
12190
+ settlement: "unknown",
12191
+ ...payment.authorization !== void 0 ? { authorization: payment.authorization } : {}
12192
+ }
12193
+ }
12194
+ );
12195
+ }
11972
12196
  throw fetchFailureToCliError(paid, {
11973
12197
  fix: `The authorization was transmitted and settlement is unknown; it is recorded as transmitted exposure. Do not simply retry: each attempt signs a fresh authorization. ${legFix(paid)}`,
11974
12198
  details: {
@@ -12024,6 +12248,116 @@ function paidLegTimeoutMs(requirement, cliTimeoutMs) {
12024
12248
  }
12025
12249
  return Math.max(cliTimeoutMs, Math.min(advertised * 1e3, MAX_PAID_LEG_TIMEOUT_MS));
12026
12250
  }
12251
+ async function assertBalanceCovers(address, amountAtomic, rpcUrl, ctx, deps) {
12252
+ if (amountAtomic <= 0n) return;
12253
+ const deadline = Date.now() + ctx.flags.timeout;
12254
+ const readBalance = deps.readBalance ?? readUsdcBalanceWithFallback;
12255
+ let balance = await readBalance(address, rpcUrl, {
12256
+ timeoutMs: Math.max(1, Math.floor(ctx.flags.timeout / 2))
12257
+ });
12258
+ if (balance === null && Date.now() < deadline) {
12259
+ await delay(Math.min(1100, Math.floor((deadline - Date.now()) / 2)));
12260
+ const remaining = deadline - Date.now();
12261
+ if (remaining > 0) balance = await readBalance(address, rpcUrl, { timeoutMs: remaining });
12262
+ }
12263
+ if (balance === null) {
12264
+ throw new CliError("REFUSED", "The wallet balance could not be read; no payment was signed.", {
12265
+ fix: "Check the configured Base rpcUrl and retry when it is available.",
12266
+ details: { reason: "balance_unavailable", address }
12267
+ });
12268
+ }
12269
+ if (balance < amountAtomic) {
12270
+ const short = toMoney((amountAtomic - balance).toString()).usd;
12271
+ throw new CliError(
12272
+ "REFUSED",
12273
+ `The wallet has insufficient USDC; no payment was signed. It holds ${toMoney(balance.toString()).usd} USD and this costs ${toMoney(amountAtomic.toString()).usd} USD: ${short} USD short.`,
12274
+ {
12275
+ fix: `Fund this wallet on Base with \`tenjin wallet fund\` (at least ${short} USD more) before paying.`,
12276
+ details: {
12277
+ reason: "insufficient_funds",
12278
+ address,
12279
+ balanceAtomic: balance.toString(),
12280
+ requiredAtomic: amountAtomic.toString()
12281
+ }
12282
+ }
12283
+ );
12284
+ }
12285
+ }
12286
+ async function quoteRouterCall(args, ctx, deps = {}) {
12287
+ const settings = await resolveContextSettings(ctx);
12288
+ const url = args.url.trim();
12289
+ if (resolveLane(url, settings) === "bazaar") {
12290
+ await assertPublicDestination(url, deps.destination ?? {});
12291
+ }
12292
+ const headers = callerHeaders(args.headers);
12293
+ const probe = await httpRequest(url, {
12294
+ timeoutMs: ctx.flags.timeout,
12295
+ blockRedirects: true,
12296
+ binaryBody: true,
12297
+ method: resolveMethod(args),
12298
+ ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {},
12299
+ ...args.rawBody !== void 0 ? { rawBody: args.rawBody } : {},
12300
+ ...Object.keys(headers).length > 0 ? { headers } : {}
12301
+ });
12302
+ if (!probe.ok) {
12303
+ throw fetchFailureToCliError(probe, {
12304
+ fix: `Nothing was sent and nothing was paid. ${legFix(probe)}`
12305
+ });
12306
+ }
12307
+ if (probe.status >= 200 && probe.status < 300) return 0n;
12308
+ if (probe.status !== 402) {
12309
+ const said = providerMessage(probe.json);
12310
+ throw new CliError(
12311
+ "API_UNREACHABLE",
12312
+ `${url} answered ${probe.status}${said === null ? "." : `: ${said}`}`,
12313
+ {
12314
+ fix: "Nothing was paid.",
12315
+ details: { status: probe.status, body: probe.json, ...providerError(probe.text) }
12316
+ }
12317
+ );
12318
+ }
12319
+ const challenge = decodeChallenge(probe, url);
12320
+ const payer = createPayerClient(() => signerOrThrow({}));
12321
+ const requirement = selectRequirement(payer.core, challenge, args.terms);
12322
+ if (requirement === void 0) throw noMatchingEntry(challenge, args.terms);
12323
+ assertWithinTerms(args.terms, requirement);
12324
+ if (challenge.extensions?.[SIGN_IN_WITH_X] === void 0) return BigInt(requirement.amount);
12325
+ const signer = await openWallet(
12326
+ resolveWalletProvider(ctx, deps.provider !== void 0 ? { provider: deps.provider } : {})
12327
+ );
12328
+ const recheck = await httpRequest(url, {
12329
+ timeoutMs: ctx.flags.timeout,
12330
+ blockRedirects: true,
12331
+ binaryBody: true,
12332
+ method: resolveMethod(args),
12333
+ ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {},
12334
+ ...args.rawBody !== void 0 ? { rawBody: args.rawBody } : {},
12335
+ headers: {
12336
+ ...headers,
12337
+ [SIWX_HEADER]: await buildSiwxHeader(signer, {
12338
+ baseUrl: new URL(url).origin,
12339
+ chainId: requirement.network
12340
+ })
12341
+ }
12342
+ });
12343
+ if (!recheck.ok) throw fetchFailureToCliError(recheck);
12344
+ if (recheck.status >= 200 && recheck.status < 300) return 0n;
12345
+ if (recheck.status !== 402) {
12346
+ throw new CliError(
12347
+ "API_UNREACHABLE",
12348
+ `${url} answered ${recheck.status} on the entitlement re-check.`,
12349
+ {
12350
+ fix: "Nothing was paid.",
12351
+ details: { status: recheck.status, body: recheck.json, ...providerError(recheck.text) }
12352
+ }
12353
+ );
12354
+ }
12355
+ const fresh = decodeChallenge(recheck, url);
12356
+ const owed = selectRequirement(payer.core, fresh, args.terms);
12357
+ if (owed === void 0) throw noMatchingEntry(fresh, args.terms);
12358
+ assertWithinTerms(args.terms, owed);
12359
+ return BigInt(owed.amount);
12360
+ }
12027
12361
  function resolveLane(url, settings) {
12028
12362
  let target;
12029
12363
  try {
@@ -12129,6 +12463,21 @@ function unvalidatedCaveat(check) {
12129
12463
  function failedRuleCaveat(check) {
12130
12464
  return `${check.reason ?? "The result does not satisfy its success schema."} The payment settled, so the body is delivered as received, unverified: treat it as possibly not the answer that was paid for.`;
12131
12465
  }
12466
+ var STATUS_URL_HEADERS = ["x-status-url"];
12467
+ function statusUrlOf(failure, requestUrl) {
12468
+ for (const name of STATUS_URL_HEADERS) {
12469
+ const value = failure.header?.(name)?.trim();
12470
+ if (value === void 0 || value.length === 0 || value.length > 2048) continue;
12471
+ try {
12472
+ const status = new URL(value, requestUrl);
12473
+ if (status.protocol === "https:" && status.host === new URL(requestUrl).host) {
12474
+ return status.toString();
12475
+ }
12476
+ } catch {
12477
+ }
12478
+ }
12479
+ return null;
12480
+ }
12132
12481
  function legFix(failure) {
12133
12482
  return failure.kind === "oversized-header" ? "Raising `--max-http-header-size` on the node process that runs this CLI would let the header be read; that is an operator decision, not a default this build changes." : "";
12134
12483
  }
@@ -12327,8 +12676,14 @@ export {
12327
12676
  canonicalHash,
12328
12677
  inputProblems,
12329
12678
  assertResultSchema,
12679
+ validateResultBody,
12330
12680
  projectBody,
12331
12681
  policyFix,
12682
+ createQuote,
12683
+ readQuote,
12684
+ quoteClosed,
12685
+ admitPlan,
12686
+ admitQuote,
12332
12687
  x402Client,
12333
12688
  BatchSettlementEvmScheme,
12334
12689
  toClientEvmSigner,
@@ -12336,6 +12691,8 @@ export {
12336
12691
  runPay,
12337
12692
  MAX_PAID_LEG_TIMEOUT_MS,
12338
12693
  paidLegTimeoutMs,
12694
+ quoteRouterCall,
12695
+ sellerLine,
12339
12696
  settlementTx
12340
12697
  };
12341
- //# sourceMappingURL=chunk-YKM2ZTA2.js.map
12698
+ //# sourceMappingURL=chunk-R4AO7GC2.js.map