run402 4.93.1 → 4.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/README.md +43 -41
  2. package/cli.mjs +34 -29
  3. package/core-dist/config.js +52 -18
  4. package/core-dist/control-plane-session.js +31 -6
  5. package/core-dist/keystore.js +7 -7
  6. package/core-dist/profiles.js +9 -7
  7. package/core-dist/{allowance-auth.js → wallet-auth.js} +15 -15
  8. package/{sdk/core-dist/allowance.js → core-dist/wallet.js} +20 -20
  9. package/{sdk/core-dist/write-auth-session.js → core-dist/write-approvals.js} +19 -19
  10. package/gitvault-surface.json +1 -1
  11. package/lib/admin.mjs +1 -1
  12. package/lib/agent.mjs +20 -18
  13. package/lib/approve.mjs +81 -0
  14. package/lib/apps.mjs +3 -3
  15. package/lib/assets.mjs +2 -2
  16. package/lib/billing.mjs +6 -6
  17. package/lib/buzz-doctor.mjs +1 -1
  18. package/lib/buzz-notifications.mjs +1 -1
  19. package/lib/buzz.mjs +1 -1
  20. package/lib/buzz.test.mjs +1 -1
  21. package/lib/ci.mjs +4 -4
  22. package/lib/cold-start.mjs +21 -21
  23. package/lib/command-manifest.mjs +20 -34
  24. package/lib/config.mjs +24 -24
  25. package/lib/contacts.mjs +13 -13
  26. package/lib/contracts.mjs +1 -1
  27. package/lib/credentials.mjs +2 -2
  28. package/lib/daemon-path.mjs +1 -1
  29. package/lib/delegates.mjs +1 -1
  30. package/lib/deliveries.mjs +4 -4
  31. package/lib/deploy-rehearse-discovery.test.mjs +7 -7
  32. package/lib/deploy-v2.mjs +232 -184
  33. package/lib/deploy.mjs +21 -53
  34. package/lib/doctor-source-scan.mjs +1 -1
  35. package/lib/doctor.mjs +57 -57
  36. package/lib/escalations.mjs +1 -1
  37. package/lib/feedback.mjs +10 -10
  38. package/lib/gitvault-daemon.mjs +1 -1
  39. package/lib/image.mjs +3 -3
  40. package/lib/init.mjs +66 -66
  41. package/lib/lightning-wallet.mjs +28 -28
  42. package/lib/login.mjs +207 -0
  43. package/lib/logout.mjs +53 -0
  44. package/lib/next-actions.mjs +15 -15
  45. package/lib/org.mjs +100 -13
  46. package/lib/pay.mjs +1 -1
  47. package/lib/projects.mjs +26 -29
  48. package/lib/redeem.mjs +7 -8
  49. package/lib/remote-helper-session.mjs +12 -12
  50. package/lib/repos.mjs +62 -62
  51. package/lib/rooms.mjs +103 -67
  52. package/lib/sdk-errors.mjs +9 -4
  53. package/lib/sdk.mjs +3 -3
  54. package/lib/service.mjs +5 -5
  55. package/lib/session-proofs.mjs +21 -0
  56. package/lib/sign-in.mjs +296 -0
  57. package/lib/sites.mjs +8 -8
  58. package/lib/stats.mjs +2 -2
  59. package/lib/status.mjs +25 -25
  60. package/lib/subdomains.mjs +19 -19
  61. package/lib/subscriptions.mjs +8 -8
  62. package/lib/tier.mjs +29 -22
  63. package/lib/transfer.mjs +58 -85
  64. package/lib/up.mjs +7 -7
  65. package/lib/wallet-context.mjs +3 -3
  66. package/lib/wallet-context.test.mjs +3 -3
  67. package/lib/wallets.mjs +196 -31
  68. package/lib/webhook-secret.mjs +6 -6
  69. package/lib/whoami.mjs +75 -0
  70. package/package.json +1 -1
  71. package/sdk/core-dist/config.js +52 -18
  72. package/sdk/core-dist/control-plane-session.js +31 -6
  73. package/sdk/core-dist/keystore.js +7 -7
  74. package/sdk/core-dist/profiles.js +9 -7
  75. package/sdk/core-dist/{allowance-auth.js → wallet-auth.js} +15 -15
  76. package/{core-dist/allowance.js → sdk/core-dist/wallet.js} +20 -20
  77. package/{core-dist/write-auth-session.js → sdk/core-dist/write-approvals.js} +19 -19
  78. package/sdk/dist/actions.d.ts +1 -1
  79. package/sdk/dist/actions.d.ts.map +1 -1
  80. package/sdk/dist/control-plane-credentials.d.ts +8 -8
  81. package/sdk/dist/control-plane-credentials.js +7 -7
  82. package/sdk/dist/credentials.d.ts +19 -19
  83. package/sdk/dist/credentials.d.ts.map +1 -1
  84. package/sdk/dist/credentials.js +1 -1
  85. package/sdk/dist/errors.d.ts +24 -26
  86. package/sdk/dist/errors.d.ts.map +1 -1
  87. package/sdk/dist/errors.js +34 -37
  88. package/sdk/dist/errors.js.map +1 -1
  89. package/sdk/dist/index.d.ts +29 -16
  90. package/sdk/dist/index.d.ts.map +1 -1
  91. package/sdk/dist/index.js +29 -16
  92. package/sdk/dist/index.js.map +1 -1
  93. package/sdk/dist/kernel.d.ts +1 -1
  94. package/sdk/dist/kernel.d.ts.map +1 -1
  95. package/sdk/dist/kernel.js +10 -9
  96. package/sdk/dist/kernel.js.map +1 -1
  97. package/sdk/dist/namespaces/admin.d.ts +51 -120
  98. package/sdk/dist/namespaces/admin.d.ts.map +1 -1
  99. package/sdk/dist/namespaces/admin.js +41 -45
  100. package/sdk/dist/namespaces/admin.js.map +1 -1
  101. package/sdk/dist/namespaces/agent.d.ts +2 -2
  102. package/sdk/dist/namespaces/agent.d.ts.map +1 -1
  103. package/sdk/dist/namespaces/agent.js +2 -2
  104. package/sdk/dist/namespaces/agent.js.map +1 -1
  105. package/sdk/dist/namespaces/ai.d.ts +1 -1
  106. package/sdk/dist/namespaces/ai.js +1 -1
  107. package/sdk/dist/namespaces/billing.d.ts +6 -3
  108. package/sdk/dist/namespaces/billing.d.ts.map +1 -1
  109. package/sdk/dist/namespaces/billing.js.map +1 -1
  110. package/sdk/dist/namespaces/buzz-notifications.types.d.ts +1 -1
  111. package/sdk/dist/namespaces/buzz.d.ts +2 -2
  112. package/sdk/dist/namespaces/buzz.d.ts.map +1 -1
  113. package/sdk/dist/namespaces/buzz.js +2 -2
  114. package/sdk/dist/namespaces/buzz.js.map +1 -1
  115. package/sdk/dist/namespaces/buzz.types.d.ts +2 -2
  116. package/sdk/dist/namespaces/buzz.types.d.ts.map +1 -1
  117. package/sdk/dist/namespaces/credentials.types.d.ts +1 -1
  118. package/sdk/dist/namespaces/deploy.d.ts +1 -1
  119. package/sdk/dist/namespaces/deploy.js +5 -5
  120. package/sdk/dist/namespaces/deploy.js.map +1 -1
  121. package/sdk/dist/namespaces/deploy.types.d.ts +4 -4
  122. package/sdk/dist/namespaces/escalations.d.ts +1 -1
  123. package/sdk/dist/namespaces/escalations.js +1 -1
  124. package/sdk/dist/namespaces/escalations.types.d.ts +2 -2
  125. package/sdk/dist/namespaces/escalations.types.d.ts.map +1 -1
  126. package/sdk/dist/namespaces/events.types.d.ts +1 -1
  127. package/sdk/dist/namespaces/functions.d.ts +1 -1
  128. package/sdk/dist/namespaces/functions.js +1 -1
  129. package/sdk/dist/namespaces/gitvault.crypto.d.ts +1 -1
  130. package/sdk/dist/namespaces/gitvault.d.ts +24 -24
  131. package/sdk/dist/namespaces/gitvault.d.ts.map +1 -1
  132. package/sdk/dist/namespaces/gitvault.js +109 -109
  133. package/sdk/dist/namespaces/gitvault.js.map +1 -1
  134. package/sdk/dist/namespaces/me.d.ts +120 -0
  135. package/sdk/dist/namespaces/me.d.ts.map +1 -0
  136. package/sdk/dist/namespaces/me.js +34 -0
  137. package/sdk/dist/namespaces/me.js.map +1 -0
  138. package/sdk/dist/namespaces/org.d.ts +108 -6
  139. package/sdk/dist/namespaces/org.d.ts.map +1 -1
  140. package/sdk/dist/namespaces/org.js +63 -7
  141. package/sdk/dist/namespaces/org.js.map +1 -1
  142. package/sdk/dist/namespaces/org.types.d.ts +29 -9
  143. package/sdk/dist/namespaces/org.types.d.ts.map +1 -1
  144. package/sdk/dist/namespaces/pay.js +3 -3
  145. package/sdk/dist/namespaces/pay.js.map +1 -1
  146. package/sdk/dist/namespaces/projects.d.ts +9 -9
  147. package/sdk/dist/namespaces/projects.js +15 -15
  148. package/sdk/dist/namespaces/projects.js.map +1 -1
  149. package/sdk/dist/namespaces/projects.types.d.ts +28 -12
  150. package/sdk/dist/namespaces/projects.types.d.ts.map +1 -1
  151. package/sdk/dist/namespaces/rooms.d.ts +7 -7
  152. package/sdk/dist/namespaces/rooms.js +17 -17
  153. package/sdk/dist/namespaces/rooms.js.map +1 -1
  154. package/sdk/dist/namespaces/rooms.types.d.ts +9 -9
  155. package/sdk/dist/namespaces/rooms.types.d.ts.map +1 -1
  156. package/sdk/dist/namespaces/service.d.ts +1 -1
  157. package/sdk/dist/namespaces/service.js +1 -1
  158. package/sdk/dist/namespaces/{operator-session.d.ts → session.d.ts} +135 -51
  159. package/sdk/dist/namespaces/session.d.ts.map +1 -0
  160. package/sdk/dist/namespaces/{operator-session.js → session.js} +118 -30
  161. package/sdk/dist/namespaces/session.js.map +1 -0
  162. package/sdk/dist/namespaces/subdomains.d.ts +5 -5
  163. package/sdk/dist/namespaces/subdomains.d.ts.map +1 -1
  164. package/sdk/dist/namespaces/subdomains.js +6 -6
  165. package/sdk/dist/namespaces/subdomains.js.map +1 -1
  166. package/sdk/dist/namespaces/tier.d.ts +43 -20
  167. package/sdk/dist/namespaces/tier.d.ts.map +1 -1
  168. package/sdk/dist/namespaces/tier.js +7 -7
  169. package/sdk/dist/namespaces/tier.js.map +1 -1
  170. package/sdk/dist/namespaces/transfers.d.ts +74 -71
  171. package/sdk/dist/namespaces/transfers.d.ts.map +1 -1
  172. package/sdk/dist/namespaces/transfers.js +31 -38
  173. package/sdk/dist/namespaces/transfers.js.map +1 -1
  174. package/sdk/dist/namespaces/vouchers.d.ts +9 -10
  175. package/sdk/dist/namespaces/vouchers.d.ts.map +1 -1
  176. package/sdk/dist/namespaces/vouchers.js +4 -5
  177. package/sdk/dist/namespaces/vouchers.js.map +1 -1
  178. package/sdk/dist/namespaces/wallets.d.ts +72 -3
  179. package/sdk/dist/namespaces/wallets.d.ts.map +1 -1
  180. package/sdk/dist/namespaces/wallets.js +141 -3
  181. package/sdk/dist/namespaces/wallets.js.map +1 -1
  182. package/sdk/dist/namespaces/write-approval.d.ts +101 -0
  183. package/sdk/dist/namespaces/write-approval.d.ts.map +1 -0
  184. package/sdk/dist/namespaces/write-approval.js +62 -0
  185. package/sdk/dist/namespaces/write-approval.js.map +1 -0
  186. package/sdk/dist/node/actions-node.d.ts +3 -3
  187. package/sdk/dist/node/actions-node.d.ts.map +1 -1
  188. package/sdk/dist/node/actions-node.js +36 -36
  189. package/sdk/dist/node/actions-node.js.map +1 -1
  190. package/sdk/dist/node/{bearer-claim-key.d.ts → bearer-redeem-key.d.ts} +12 -12
  191. package/sdk/dist/node/bearer-redeem-key.d.ts.map +1 -0
  192. package/sdk/dist/node/{bearer-claim-key.js → bearer-redeem-key.js} +21 -21
  193. package/sdk/dist/node/bearer-redeem-key.js.map +1 -0
  194. package/sdk/dist/node/ci.d.ts +1 -1
  195. package/sdk/dist/node/ci.d.ts.map +1 -1
  196. package/sdk/dist/node/ci.js +6 -6
  197. package/sdk/dist/node/ci.js.map +1 -1
  198. package/sdk/dist/node/credentials.d.ts +17 -16
  199. package/sdk/dist/node/credentials.d.ts.map +1 -1
  200. package/sdk/dist/node/credentials.js +28 -27
  201. package/sdk/dist/node/credentials.js.map +1 -1
  202. package/sdk/dist/node/funding-recovery.d.ts +1 -1
  203. package/sdk/dist/node/funding-recovery.d.ts.map +1 -1
  204. package/sdk/dist/node/funding-recovery.js +1 -1
  205. package/sdk/dist/node/funding-recovery.js.map +1 -1
  206. package/sdk/dist/node/gitvault-apply.d.ts +1 -1
  207. package/sdk/dist/node/gitvault-apply.d.ts.map +1 -1
  208. package/sdk/dist/node/gitvault-handoff.d.ts +22 -22
  209. package/sdk/dist/node/gitvault-handoff.d.ts.map +1 -1
  210. package/sdk/dist/node/gitvault-handoff.js +45 -45
  211. package/sdk/dist/node/gitvault-handoff.js.map +1 -1
  212. package/sdk/dist/node/gitvault-prewarm.js +7 -7
  213. package/sdk/dist/node/gitvault-prewarm.js.map +1 -1
  214. package/sdk/dist/node/gitvault-restore.d.ts +1 -1
  215. package/sdk/dist/node/gitvault-restore.js +1 -1
  216. package/sdk/dist/node/index.d.ts +16 -16
  217. package/sdk/dist/node/index.d.ts.map +1 -1
  218. package/sdk/dist/node/index.js +15 -15
  219. package/sdk/dist/node/index.js.map +1 -1
  220. package/sdk/dist/node/org-adopt.d.ts +49 -0
  221. package/sdk/dist/node/org-adopt.d.ts.map +1 -0
  222. package/sdk/dist/node/org-adopt.js +77 -0
  223. package/sdk/dist/node/org-adopt.js.map +1 -0
  224. package/sdk/dist/node/paid-fetch.d.ts +7 -7
  225. package/sdk/dist/node/paid-fetch.d.ts.map +1 -1
  226. package/sdk/dist/node/paid-fetch.js +54 -54
  227. package/sdk/dist/node/paid-fetch.js.map +1 -1
  228. package/sdk/dist/node/preflight.d.ts +1 -1
  229. package/sdk/dist/node/preflight.d.ts.map +1 -1
  230. package/sdk/dist/node/preflight.js +1 -1
  231. package/sdk/dist/node/preflight.js.map +1 -1
  232. package/sdk/dist/node/source-scan.d.ts +1 -1
  233. package/sdk/dist/node/source-scan.js +2 -2
  234. package/sdk/dist/node/source-scan.js.map +1 -1
  235. package/sdk/dist/scoped.d.ts +3 -3
  236. package/sdk/dist/scoped.d.ts.map +1 -1
  237. package/sdk/dist/scoped.js +2 -2
  238. package/sdk/dist/scoped.js.map +1 -1
  239. package/core-dist/operator-session.js +0 -154
  240. package/lib/allowance.mjs +0 -355
  241. package/lib/operator-proofs.mjs +0 -22
  242. package/lib/operator.mjs +0 -771
  243. package/sdk/core-dist/operator-session.js +0 -154
  244. package/sdk/dist/namespaces/allowance.d.ts +0 -79
  245. package/sdk/dist/namespaces/allowance.d.ts.map +0 -1
  246. package/sdk/dist/namespaces/allowance.js +0 -149
  247. package/sdk/dist/namespaces/allowance.js.map +0 -1
  248. package/sdk/dist/namespaces/operator-session.d.ts.map +0 -1
  249. package/sdk/dist/namespaces/operator-session.js.map +0 -1
  250. package/sdk/dist/namespaces/operator.d.ts +0 -359
  251. package/sdk/dist/namespaces/operator.d.ts.map +0 -1
  252. package/sdk/dist/namespaces/operator.js +0 -272
  253. package/sdk/dist/namespaces/operator.js.map +0 -1
  254. package/sdk/dist/node/bearer-claim-key.d.ts.map +0 -1
  255. package/sdk/dist/node/bearer-claim-key.js.map +0 -1
  256. package/sdk/dist/node/operator-claim.d.ts +0 -49
  257. package/sdk/dist/node/operator-claim.d.ts.map +0 -1
  258. package/sdk/dist/node/operator-claim.js +0 -77
  259. package/sdk/dist/node/operator-claim.js.map +0 -1
package/lib/allowance.mjs DELETED
@@ -1,355 +0,0 @@
1
- import { readAllowance, saveAllowance, allowanceFile } from "./config.mjs";
2
- import { getSdk } from "./sdk.mjs";
3
- import { reportSdkError, fail } from "./sdk-errors.mjs";
4
- import { assertKnownFlags, flagValue, normalizeArgv, parseIntegerFlag, positionalArgs, failUnknownSubcommand } from "./argparse.mjs";
5
-
6
- const HELP = `run402 allowance — Manage your agent allowance
7
-
8
- Usage:
9
- run402 allowance <subcommand>
10
-
11
- Subcommands:
12
- status Show allowance address, network, rail, and funding status
13
- create Generate a new allowance and save it locally
14
- fund Request test funds from the faucet (Base Sepolia or Tempo)
15
- balance Show on-chain balances and Run402 billing balance
16
- export Print the allowance address as JSON (useful for scripting)
17
- checkout Create an org balance checkout session (--amount <usd_micros>)
18
- history View billing transaction history (--limit <n>)
19
-
20
- Notes:
21
- - Agent allowance is stored locally at ~/.config/run402/allowance.json
22
- - The allowance works on any EVM chain (Base for x402, Tempo for MPP)
23
- - Use 'run402 init' for x402 or 'run402 init mpp' for MPP rail
24
-
25
- Examples:
26
- run402 allowance create
27
- run402 allowance status
28
- run402 allowance fund
29
- run402 allowance export
30
- run402 allowance balance
31
- run402 allowance checkout --amount 5000000
32
- run402 allowance history --limit 10
33
- `;
34
-
35
- const SUB_HELP = {
36
- checkout: `run402 allowance checkout — Create an org balance checkout session
37
-
38
- Usage:
39
- run402 allowance checkout --amount <usd_micros>
40
-
41
- Options:
42
- --amount <n> Amount in USD micros (required; e.g. 5000000 for $5)
43
-
44
- Examples:
45
- run402 allowance checkout --amount 5000000
46
- run402 allowance checkout --amount 10000000
47
- `,
48
- history: `run402 allowance history — View billing transaction history
49
-
50
- Usage:
51
- run402 allowance history [--limit <n>]
52
-
53
- Options:
54
- --limit <n> Max entries to return (default: 20)
55
-
56
- Examples:
57
- run402 allowance history
58
- run402 allowance history --limit 10
59
- `,
60
- };
61
-
62
- const USDC_ABI = [{ name: "balanceOf", type: "function", stateMutability: "view", inputs: [{ name: "account", type: "address" }], outputs: [{ name: "", type: "uint256" }] }];
63
- const USDC_MAINNET = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
64
- const USDC_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
65
- const PATH_USD = "0x20c0000000000000000000000000000000000000";
66
- const TEMPO_RPC = "https://rpc.moderato.tempo.xyz/";
67
-
68
- async function loadDeps() {
69
- const { generatePrivateKey, privateKeyToAccount } = await import("viem/accounts");
70
- const { createPublicClient, http, defineChain } = await import("viem");
71
- const { base, baseSepolia } = await import("viem/chains");
72
- const tempoModerato = defineChain({
73
- id: 42431,
74
- name: "Tempo Moderato",
75
- nativeCurrency: { name: "pathUSD", symbol: "pathUSD", decimals: 6 },
76
- rpcUrls: { default: { http: [TEMPO_RPC] } },
77
- });
78
- return { generatePrivateKey, privateKeyToAccount, createPublicClient, http, base, baseSepolia, tempoModerato };
79
- }
80
-
81
- async function status() {
82
- try {
83
- const data = await getSdk().allowance.status();
84
- if (!data.configured) {
85
- console.log(JSON.stringify({ wallet: null, hint: "Run: run402 allowance create" }));
86
- return;
87
- }
88
- const w = readAllowance();
89
- // The Lightning allowance (mpp-lightning-over-nwc): public facts plus a
90
- // best-effort balance read over NWC; the pairing secret never prints.
91
- const { describeLightning, readLightningBalance } = await import("./lightning-wallet.mjs");
92
- const lightning = w?.lightning ? describeLightning(w, null, await readLightningBalance(w)) : null;
93
- console.log(JSON.stringify({
94
- wallet: {
95
- address: data.address,
96
- created: data.created,
97
- configured: data.configured,
98
- // `faucet_used` is named for what it is: an on-disk marker that
99
- // tracks faucet invocation, not pay-readiness. For a true "can this
100
- // account pay right now" check, use `run402 allowance balance`.
101
- faucet_used: !!data.faucet_used,
102
- rail: data.rail ?? w?.rail ?? "x402",
103
- path: data.path ?? allowanceFile(),
104
- },
105
- ...(lightning ? { lightning } : {}),
106
- }));
107
- } catch (err) {
108
- reportSdkError(err);
109
- }
110
- }
111
-
112
- async function create() {
113
- try {
114
- const result = await getSdk().allowance.create();
115
- console.log(JSON.stringify({
116
- address: result.address,
117
- path: result.path ?? allowanceFile(),
118
- created: true,
119
- }));
120
- } catch (err) {
121
- const msg = (err instanceof Error) ? err.message : String(err);
122
- if (/already exists/i.test(msg)) {
123
- fail({
124
- code: "ALLOWANCE_EXISTS",
125
- message: "Agent allowance already exists.",
126
- hint: "Use 'status' to check it.",
127
- });
128
- }
129
- reportSdkError(err);
130
- }
131
- }
132
-
133
- async function fund() {
134
- const w = readAllowance();
135
- if (!w) {
136
- fail({
137
- code: "NO_ALLOWANCE",
138
- message: "No agent allowance.",
139
- hint: "Run: run402 allowance create",
140
- });
141
- }
142
-
143
- if (w.rail === "mpp") {
144
- // Tempo Moderato faucet — instant, no polling needed
145
- const { createPublicClient, http, tempoModerato } = await loadDeps();
146
- const client = createPublicClient({ chain: tempoModerato, transport: http() });
147
- const before = await readUsdcBalance(client, PATH_USD, w.address).catch(() => 0);
148
-
149
- const res = await fetch(TEMPO_RPC, {
150
- method: "POST",
151
- headers: { "Content-Type": "application/json" },
152
- body: JSON.stringify({ jsonrpc: "2.0", method: "tempo_fundAddress", params: [w.address], id: 1 }),
153
- });
154
- const data = await res.json();
155
- if (data.error) {
156
- fail({
157
- code: "FAUCET_FAILED",
158
- message: data.error.message || "Tempo faucet failed",
159
- details: { rail: "mpp" },
160
- });
161
- }
162
-
163
- // Re-read balance once (instant confirmation)
164
- const now = await readUsdcBalance(client, PATH_USD, w.address).catch(() => before);
165
- saveAllowance({ ...w, funded: true, lastFaucet: new Date().toISOString() });
166
- console.log(JSON.stringify({
167
- address: w.address,
168
- rail: "mpp",
169
- onchain: {
170
- "tempo-moderato_pathusd_micros": now,
171
- },
172
- }, null, 2));
173
- return;
174
- }
175
-
176
- // Default: Base Sepolia faucet (existing behavior)
177
- const { createPublicClient, http, baseSepolia } = await loadDeps();
178
- const client = createPublicClient({ chain: baseSepolia, transport: http() });
179
- const before = await readUsdcBalance(client, USDC_SEPOLIA, w.address).catch(() => 0);
180
-
181
- let data;
182
- try {
183
- data = await getSdk().allowance.faucet(w.address);
184
- } catch (err) {
185
- reportSdkError(err);
186
- }
187
-
188
- const MAX_WAIT = 30;
189
- for (let i = 0; i < MAX_WAIT; i++) {
190
- await new Promise(r => setTimeout(r, 1000));
191
- const now = await readUsdcBalance(client, USDC_SEPOLIA, w.address).catch(() => before);
192
- if (now > before) {
193
- saveAllowance({ ...w, funded: true, lastFaucet: new Date().toISOString() });
194
- console.log(JSON.stringify({
195
- address: w.address,
196
- rail: w.rail || "x402",
197
- onchain: {
198
- "base-sepolia_usd_micros": now,
199
- },
200
- }, null, 2));
201
- return;
202
- }
203
- }
204
-
205
- saveAllowance({ ...w, funded: true, lastFaucet: new Date().toISOString() });
206
- console.log(JSON.stringify({ ...data, balance_confirmed: false, hint: "Faucet request sent but on-chain balance not yet confirmed" }));
207
- }
208
-
209
- async function readUsdcBalance(client, usdc, address) {
210
- const raw = await client.readContract({ address: usdc, abi: USDC_ABI, functionName: "balanceOf", args: [address] });
211
- return Number(raw);
212
- }
213
-
214
- async function balance() {
215
- const w = readAllowance();
216
- if (!w) {
217
- fail({
218
- code: "NO_ALLOWANCE",
219
- message: "No agent allowance.",
220
- hint: "Run: run402 allowance create",
221
- });
222
- }
223
-
224
- const { createPublicClient, http, base, baseSepolia, tempoModerato } = await loadDeps();
225
- const mainnetClient = createPublicClient({ chain: base, transport: http() });
226
- const sepoliaClient = createPublicClient({ chain: baseSepolia, transport: http() });
227
- const tempoClient = createPublicClient({ chain: tempoModerato, transport: http() });
228
-
229
- const [mainnetUsdc, sepoliaUsdc, tempoPathUsd, billingRes] = await Promise.all([
230
- readUsdcBalance(mainnetClient, USDC_MAINNET, w.address).catch(() => null),
231
- readUsdcBalance(sepoliaClient, USDC_SEPOLIA, w.address).catch(() => null),
232
- readUsdcBalance(tempoClient, PATH_USD, w.address).catch(() => null),
233
- getSdk().billing.checkBalance(w.address).catch(() => null),
234
- ]);
235
-
236
- console.log(JSON.stringify({
237
- address: w.address,
238
- rail: w.rail || "x402",
239
- onchain: {
240
- "base-mainnet_usd_micros": mainnetUsdc,
241
- "base-sepolia_usd_micros": sepoliaUsdc,
242
- "tempo-moderato_pathusd_micros": tempoPathUsd,
243
- },
244
- run402: billingRes ? { balance_usd_micros: billingRes.available_usd_micros } : "no organization",
245
- }, null, 2));
246
- }
247
-
248
- async function exportAddr(args = []) {
249
- const parsedArgs = normalizeArgv(args);
250
- assertKnownFlags(parsedArgs, [], []);
251
- const bare = positionalArgs(parsedArgs, []);
252
- if (bare.length > 0) {
253
- fail({
254
- code: "BAD_USAGE",
255
- message: `Unexpected argument for allowance export: ${bare[0]}`,
256
- details: { argument: bare[0] },
257
- });
258
- }
259
- try {
260
- const address = await getSdk().allowance.export();
261
- console.log(JSON.stringify({ address }));
262
- } catch {
263
- fail({ code: "NO_ALLOWANCE", message: "No agent allowance." });
264
- }
265
- }
266
-
267
- async function checkout(args) {
268
- const w = readAllowance();
269
- if (!w) {
270
- fail({
271
- code: "NO_ALLOWANCE",
272
- message: "No agent allowance.",
273
- hint: "Run: run402 allowance create",
274
- });
275
- }
276
- const parsedArgs = normalizeArgv(args);
277
- assertKnownFlags(parsedArgs, ["--amount", "--help", "-h"], ["--amount"]);
278
- const bare = positionalArgs(parsedArgs, ["--amount"]);
279
- if (bare.length > 0) {
280
- fail({
281
- code: "BAD_USAGE",
282
- message: `Unexpected argument for allowance checkout: ${bare[0]}`,
283
- details: { argument: bare[0] },
284
- });
285
- }
286
- const amountRaw = flagValue(parsedArgs, "--amount");
287
- if (amountRaw === null) {
288
- fail({
289
- code: "BAD_USAGE",
290
- message: "Missing --amount <usd_micros>",
291
- hint: "e.g. --amount 5000000 for $5",
292
- });
293
- }
294
- const amount = parseIntegerFlag("--amount", amountRaw, { min: 1 });
295
- try {
296
- const org = await getSdk().billing.lookupOrganization(w.address);
297
- const data = await getSdk().billing.createCheckout(org.org_id, {
298
- product: "balance_topup",
299
- amountUsdMicros: amount,
300
- });
301
- console.log(JSON.stringify(data, null, 2));
302
- } catch (err) {
303
- reportSdkError(err);
304
- }
305
- }
306
-
307
- async function history(args) {
308
- const w = readAllowance();
309
- if (!w) {
310
- fail({
311
- code: "NO_ALLOWANCE",
312
- message: "No agent allowance.",
313
- hint: "Run: run402 allowance create",
314
- });
315
- }
316
- const parsedArgs = normalizeArgv(args);
317
- assertKnownFlags(parsedArgs, ["--limit", "--help", "-h"], ["--limit"]);
318
- const bare = positionalArgs(parsedArgs, ["--limit"]);
319
- if (bare.length > 0) {
320
- fail({
321
- code: "BAD_USAGE",
322
- message: `Unexpected argument for allowance history: ${bare[0]}`,
323
- details: { argument: bare[0] },
324
- });
325
- }
326
- const limit = parseIntegerFlag("--limit", flagValue(parsedArgs, "--limit"), { min: 1, def: 20 });
327
- try {
328
- const data = await getSdk().billing.history(w.address, limit);
329
- console.log(JSON.stringify(data, null, 2));
330
- } catch (err) {
331
- reportSdkError(err);
332
- }
333
- }
334
-
335
- export async function run(sub, args) {
336
- if (!sub || sub === '--help' || sub === '-h') {
337
- console.log(HELP);
338
- process.exit(0);
339
- }
340
- if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) {
341
- console.log(SUB_HELP[sub] || HELP);
342
- process.exit(0);
343
- }
344
- switch (sub) {
345
- case "status": await status(); break;
346
- case "create": await create(); break;
347
- case "fund": await fund(); break;
348
- case "balance": await balance(); break;
349
- case "export": await exportAddr(args); break;
350
- case "checkout": await checkout(args); break;
351
- case "history": await history(args); break;
352
- default:
353
- failUnknownSubcommand("allowance", sub);
354
- }
355
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * one-passkey-per-person: the two proofs a wallet-authenticated notification
3
- * mutation carries when the human behind this wallet is logged in.
4
- *
5
- * `run402 operator login --loopback` caches a passkey-fresh control-plane
6
- * session. The gateway accepts that session — sent as `Authorization: Bearer`
7
- * beside the wallet's `SIGN-IN-WITH-X` on the SAME request — as
8
- * `operator_passkey` assurance for a wallet contact whose verified email the
9
- * session's principal holds. So a person who logged in once is never asked to
10
- * enroll a second passkey. With no live cached session this returns
11
- * `undefined` and the verb behaves exactly as before (wallet auth alone).
12
- */
13
- import { allowanceAuthHeaders } from "./config.mjs";
14
- import { loadLiveControlPlaneSession } from "../core-dist/control-plane-session.js";
15
-
16
- /** `{ siwx, token }` for `path`, or `undefined` when no live operator session is cached. */
17
- export function operatorProofs(path) {
18
- const siwx = allowanceAuthHeaders(path)["SIGN-IN-WITH-X"];
19
- const live = loadLiveControlPlaneSession();
20
- if (!live || !live.control_plane_session_token) return undefined;
21
- return { siwx, token: live.control_plane_session_token };
22
- }