@absol-labs/agent 0.10.0 → 0.12.0-rc.1

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 (331) hide show
  1. package/README.md +106 -30
  2. package/dist/capability/invocation-capability.d.ts +20 -8
  3. package/dist/capability/invocation-capability.d.ts.map +1 -1
  4. package/dist/capability/invocation-capability.js.map +1 -1
  5. package/dist/capability/probe-capability.d.ts +225 -0
  6. package/dist/capability/probe-capability.d.ts.map +1 -0
  7. package/dist/capability/probe-capability.js +248 -0
  8. package/dist/capability/probe-capability.js.map +1 -0
  9. package/dist/cli/args.d.ts +11 -0
  10. package/dist/cli/args.d.ts.map +1 -1
  11. package/dist/cli/args.js +23 -0
  12. package/dist/cli/args.js.map +1 -1
  13. package/dist/cli/commands/claim.d.ts.map +1 -1
  14. package/dist/cli/commands/claim.js +21 -5
  15. package/dist/cli/commands/claim.js.map +1 -1
  16. package/dist/cli/commands/close.d.ts.map +1 -1
  17. package/dist/cli/commands/close.js +51 -7
  18. package/dist/cli/commands/close.js.map +1 -1
  19. package/dist/cli/commands/invoke.d.ts +2 -0
  20. package/dist/cli/commands/invoke.d.ts.map +1 -1
  21. package/dist/cli/commands/invoke.js +3 -2
  22. package/dist/cli/commands/invoke.js.map +1 -1
  23. package/dist/cli/commands/mcp.d.ts.map +1 -1
  24. package/dist/cli/commands/mcp.js +15 -2
  25. package/dist/cli/commands/mcp.js.map +1 -1
  26. package/dist/cli/commands/open.d.ts.map +1 -1
  27. package/dist/cli/commands/open.js +121 -15
  28. package/dist/cli/commands/open.js.map +1 -1
  29. package/dist/cli/commands/pay.d.ts +19 -0
  30. package/dist/cli/commands/pay.d.ts.map +1 -0
  31. package/dist/cli/commands/pay.js +355 -0
  32. package/dist/cli/commands/pay.js.map +1 -0
  33. package/dist/cli/commands/reclaim-unverified.d.ts.map +1 -1
  34. package/dist/cli/commands/reclaim-unverified.js +15 -6
  35. package/dist/cli/commands/reclaim-unverified.js.map +1 -1
  36. package/dist/cli/commands/reclaim.d.ts +23 -2
  37. package/dist/cli/commands/reclaim.d.ts.map +1 -1
  38. package/dist/cli/commands/reclaim.js +200 -21
  39. package/dist/cli/commands/reclaim.js.map +1 -1
  40. package/dist/cli/commands/refund.d.ts +13 -0
  41. package/dist/cli/commands/refund.d.ts.map +1 -0
  42. package/dist/cli/commands/refund.js +224 -0
  43. package/dist/cli/commands/refund.js.map +1 -0
  44. package/dist/cli/commands/status.d.ts.map +1 -1
  45. package/dist/cli/commands/status.js +10 -1
  46. package/dist/cli/commands/status.js.map +1 -1
  47. package/dist/cli/commands/streams.js +9 -13
  48. package/dist/cli/commands/streams.js.map +1 -1
  49. package/dist/cli/commands/watch.d.ts.map +1 -1
  50. package/dist/cli/commands/watch.js +2 -1
  51. package/dist/cli/commands/watch.js.map +1 -1
  52. package/dist/cli/config.d.ts +44 -26
  53. package/dist/cli/config.d.ts.map +1 -1
  54. package/dist/cli/config.js +88 -38
  55. package/dist/cli/config.js.map +1 -1
  56. package/dist/cli/deps.d.ts +86 -7
  57. package/dist/cli/deps.d.ts.map +1 -1
  58. package/dist/cli/deps.js +102 -16
  59. package/dist/cli/deps.js.map +1 -1
  60. package/dist/cli/errors.d.ts.map +1 -1
  61. package/dist/cli/errors.js +21 -1
  62. package/dist/cli/errors.js.map +1 -1
  63. package/dist/cli/escape-hatch.d.ts +6 -4
  64. package/dist/cli/escape-hatch.d.ts.map +1 -1
  65. package/dist/cli/escape-hatch.js +6 -2
  66. package/dist/cli/escape-hatch.js.map +1 -1
  67. package/dist/cli/listings.d.ts +18 -0
  68. package/dist/cli/listings.d.ts.map +1 -1
  69. package/dist/cli/listings.js +22 -12
  70. package/dist/cli/listings.js.map +1 -1
  71. package/dist/cli/preflight.d.ts +20 -14
  72. package/dist/cli/preflight.d.ts.map +1 -1
  73. package/dist/cli/preflight.js +34 -20
  74. package/dist/cli/preflight.js.map +1 -1
  75. package/dist/cli/privy.d.ts +83 -0
  76. package/dist/cli/privy.d.ts.map +1 -0
  77. package/dist/cli/privy.js +232 -0
  78. package/dist/cli/privy.js.map +1 -0
  79. package/dist/cli/reclaimability.d.ts +82 -0
  80. package/dist/cli/reclaimability.d.ts.map +1 -0
  81. package/dist/cli/reclaimability.js +80 -0
  82. package/dist/cli/reclaimability.js.map +1 -0
  83. package/dist/cli/run.d.ts +2 -1
  84. package/dist/cli/run.d.ts.map +1 -1
  85. package/dist/cli/run.js +40 -11
  86. package/dist/cli/run.js.map +1 -1
  87. package/dist/cli/scan-range.d.ts +2 -2
  88. package/dist/cli/scan-range.js +2 -2
  89. package/dist/cli/spend-policy.d.ts +60 -0
  90. package/dist/cli/spend-policy.d.ts.map +1 -0
  91. package/dist/cli/spend-policy.js +65 -0
  92. package/dist/cli/spend-policy.js.map +1 -0
  93. package/dist/cli/status.d.ts +3 -1
  94. package/dist/cli/status.d.ts.map +1 -1
  95. package/dist/cli/status.js +15 -3
  96. package/dist/cli/status.js.map +1 -1
  97. package/dist/cli/wallet.d.ts +109 -40
  98. package/dist/cli/wallet.d.ts.map +1 -1
  99. package/dist/cli/wallet.js +109 -44
  100. package/dist/cli/wallet.js.map +1 -1
  101. package/dist/discovery/rate-band.d.ts +74 -0
  102. package/dist/discovery/rate-band.d.ts.map +1 -0
  103. package/dist/discovery/rate-band.js +114 -0
  104. package/dist/discovery/rate-band.js.map +1 -0
  105. package/dist/escrow-generation.d.ts +81 -0
  106. package/dist/escrow-generation.d.ts.map +1 -0
  107. package/dist/escrow-generation.js +76 -0
  108. package/dist/escrow-generation.js.map +1 -0
  109. package/dist/frameworks/agentkit.d.ts +8 -4
  110. package/dist/frameworks/agentkit.d.ts.map +1 -1
  111. package/dist/frameworks/agentkit.js +27 -10
  112. package/dist/frameworks/agentkit.js.map +1 -1
  113. package/dist/frameworks/eliza.d.ts +3 -3
  114. package/dist/frameworks/eliza.d.ts.map +1 -1
  115. package/dist/frameworks/eliza.js +15 -6
  116. package/dist/frameworks/eliza.js.map +1 -1
  117. package/dist/frameworks/langchain.d.ts.map +1 -1
  118. package/dist/frameworks/langchain.js +8 -0
  119. package/dist/frameworks/langchain.js.map +1 -1
  120. package/dist/gateway/caller-auth-gateway.d.ts +91 -4
  121. package/dist/gateway/caller-auth-gateway.d.ts.map +1 -1
  122. package/dist/gateway/caller-auth-gateway.js +184 -7
  123. package/dist/gateway/caller-auth-gateway.js.map +1 -1
  124. package/dist/gateway/http-server.d.ts +121 -1
  125. package/dist/gateway/http-server.d.ts.map +1 -1
  126. package/dist/gateway/http-server.js +474 -5
  127. package/dist/gateway/http-server.js.map +1 -1
  128. package/dist/gateway/probe-auth.d.ts +112 -0
  129. package/dist/gateway/probe-auth.d.ts.map +1 -0
  130. package/dist/gateway/probe-auth.js +127 -0
  131. package/dist/gateway/probe-auth.js.map +1 -0
  132. package/dist/gateway/signed-rate-bounds.d.ts +51 -0
  133. package/dist/gateway/signed-rate-bounds.d.ts.map +1 -0
  134. package/dist/gateway/signed-rate-bounds.js +94 -0
  135. package/dist/gateway/signed-rate-bounds.js.map +1 -0
  136. package/dist/gateway/x402-opener-mode.d.ts +215 -0
  137. package/dist/gateway/x402-opener-mode.d.ts.map +1 -0
  138. package/dist/gateway/x402-opener-mode.js +639 -0
  139. package/dist/gateway/x402-opener-mode.js.map +1 -0
  140. package/dist/index.d.ts +11 -5
  141. package/dist/index.d.ts.map +1 -1
  142. package/dist/index.js +15 -5
  143. package/dist/index.js.map +1 -1
  144. package/dist/mandates/env.d.ts +3 -2
  145. package/dist/mandates/env.d.ts.map +1 -1
  146. package/dist/mandates/env.js +3 -2
  147. package/dist/mandates/env.js.map +1 -1
  148. package/dist/mcp/server.d.ts +100 -0
  149. package/dist/mcp/server.d.ts.map +1 -1
  150. package/dist/mcp/server.js +719 -39
  151. package/dist/mcp/server.js.map +1 -1
  152. package/dist/mcp/service-invoker.d.ts +97 -0
  153. package/dist/mcp/service-invoker.d.ts.map +1 -0
  154. package/dist/mcp/service-invoker.js +167 -0
  155. package/dist/mcp/service-invoker.js.map +1 -0
  156. package/dist/mcp/x402-tools.d.ts +104 -0
  157. package/dist/mcp/x402-tools.d.ts.map +1 -0
  158. package/dist/mcp/x402-tools.js +434 -0
  159. package/dist/mcp/x402-tools.js.map +1 -0
  160. package/dist/network.d.ts +119 -0
  161. package/dist/network.d.ts.map +1 -0
  162. package/dist/network.js +199 -0
  163. package/dist/network.js.map +1 -0
  164. package/dist/sdk/invoke.d.ts +23 -4
  165. package/dist/sdk/invoke.d.ts.map +1 -1
  166. package/dist/sdk/invoke.js +71 -10
  167. package/dist/sdk/invoke.js.map +1 -1
  168. package/dist/wallet/autonomous-wallet-broker.d.ts +3 -0
  169. package/dist/wallet/autonomous-wallet-broker.d.ts.map +1 -1
  170. package/dist/wallet/autonomous-wallet-broker.js +27 -23
  171. package/dist/wallet/autonomous-wallet-broker.js.map +1 -1
  172. package/dist/wallet/autonomous-wallet-protocol.d.ts +8 -2
  173. package/dist/wallet/autonomous-wallet-protocol.d.ts.map +1 -1
  174. package/dist/wallet/autonomous-wallet-protocol.js +9 -2
  175. package/dist/wallet/autonomous-wallet-protocol.js.map +1 -1
  176. package/dist/wallet/autonomous-wallet.d.ts.map +1 -1
  177. package/dist/wallet/autonomous-wallet.js +3 -2
  178. package/dist/wallet/autonomous-wallet.js.map +1 -1
  179. package/dist/wallet/broker-escrows.d.ts +222 -0
  180. package/dist/wallet/broker-escrows.d.ts.map +1 -0
  181. package/dist/wallet/broker-escrows.js +36 -0
  182. package/dist/wallet/broker-escrows.js.map +1 -0
  183. package/dist/wallet/lifecycle.d.ts +21 -5
  184. package/dist/wallet/lifecycle.d.ts.map +1 -1
  185. package/dist/wallet/lifecycle.js +32 -12
  186. package/dist/wallet/lifecycle.js.map +1 -1
  187. package/dist/wallet/privy-broker-server.d.ts.map +1 -1
  188. package/dist/wallet/privy-broker-server.js +31 -26
  189. package/dist/wallet/privy-broker-server.js.map +1 -1
  190. package/dist/wallet/privy-session-broker.d.ts +14 -5
  191. package/dist/wallet/privy-session-broker.d.ts.map +1 -1
  192. package/dist/wallet/privy-session-broker.js +29 -17
  193. package/dist/wallet/privy-session-broker.js.map +1 -1
  194. package/dist/wallet/privy-session-provider.d.ts +3 -1
  195. package/dist/wallet/privy-session-provider.d.ts.map +1 -1
  196. package/dist/wallet/privy-session-provider.js +5 -3
  197. package/dist/wallet/privy-session-provider.js.map +1 -1
  198. package/dist/wallet/provider.d.ts.map +1 -1
  199. package/dist/wallet/provider.js +15 -8
  200. package/dist/wallet/provider.js.map +1 -1
  201. package/dist/x402/facilitator.d.ts +42 -17
  202. package/dist/x402/facilitator.d.ts.map +1 -1
  203. package/dist/x402/facilitator.js +49 -33
  204. package/dist/x402/facilitator.js.map +1 -1
  205. package/dist/x402-buyer/guarded-fetch.d.ts +51 -0
  206. package/dist/x402-buyer/guarded-fetch.d.ts.map +1 -0
  207. package/dist/x402-buyer/guarded-fetch.js +147 -0
  208. package/dist/x402-buyer/guarded-fetch.js.map +1 -0
  209. package/dist/x402-buyer/index.d.ts +10 -0
  210. package/dist/x402-buyer/index.d.ts.map +1 -0
  211. package/dist/x402-buyer/index.js +10 -0
  212. package/dist/x402-buyer/index.js.map +1 -0
  213. package/dist/x402-buyer/pay.d.ts +135 -0
  214. package/dist/x402-buyer/pay.d.ts.map +1 -0
  215. package/dist/x402-buyer/pay.js +336 -0
  216. package/dist/x402-buyer/pay.js.map +1 -0
  217. package/dist/x402-opener/abi.d.ts +684 -0
  218. package/dist/x402-opener/abi.d.ts.map +1 -0
  219. package/dist/x402-opener/abi.js +880 -0
  220. package/dist/x402-opener/abi.js.map +1 -0
  221. package/dist/x402-opener/facilitator-entry.d.ts +3 -0
  222. package/dist/x402-opener/facilitator-entry.d.ts.map +1 -0
  223. package/dist/x402-opener/facilitator-entry.js +37 -0
  224. package/dist/x402-opener/facilitator-entry.js.map +1 -0
  225. package/dist/x402-opener/facilitator-server.d.ts +180 -0
  226. package/dist/x402-opener/facilitator-server.d.ts.map +1 -0
  227. package/dist/x402-opener/facilitator-server.js +696 -0
  228. package/dist/x402-opener/facilitator-server.js.map +1 -0
  229. package/dist/x402-opener/index.d.ts +14 -0
  230. package/dist/x402-opener/index.d.ts.map +1 -0
  231. package/dist/x402-opener/index.js +14 -0
  232. package/dist/x402-opener/index.js.map +1 -0
  233. package/dist/x402-opener/listing-resolver.d.ts +55 -0
  234. package/dist/x402-opener/listing-resolver.d.ts.map +1 -0
  235. package/dist/x402-opener/listing-resolver.js +125 -0
  236. package/dist/x402-opener/listing-resolver.js.map +1 -0
  237. package/dist/x402-opener/refund-relay.d.ts +240 -0
  238. package/dist/x402-opener/refund-relay.d.ts.map +1 -0
  239. package/dist/x402-opener/refund-relay.js +1240 -0
  240. package/dist/x402-opener/refund-relay.js.map +1 -0
  241. package/dist/x402-opener/relayer-queue.d.ts +14 -0
  242. package/dist/x402-opener/relayer-queue.d.ts.map +1 -0
  243. package/dist/x402-opener/relayer-queue.js +18 -0
  244. package/dist/x402-opener/relayer-queue.js.map +1 -0
  245. package/dist/x402-opener/scheme.d.ts +217 -0
  246. package/dist/x402-opener/scheme.d.ts.map +1 -0
  247. package/dist/x402-opener/scheme.js +749 -0
  248. package/dist/x402-opener/scheme.js.map +1 -0
  249. package/dist/x402-opener/terms.d.ts +105 -0
  250. package/dist/x402-opener/terms.d.ts.map +1 -0
  251. package/dist/x402-opener/terms.js +212 -0
  252. package/dist/x402-opener/terms.js.map +1 -0
  253. package/dist/zktls/reclaim.d.ts +2 -2
  254. package/docs/agent-layer.md +13 -8
  255. package/docs/autonomous-privy-wallet.md +188 -0
  256. package/docs/cli.md +342 -53
  257. package/docs/langchain.md +5 -0
  258. package/docs/mcp-hosted.md +4 -3
  259. package/docs/mcp-reference.md +245 -0
  260. package/docs/probe-capability.md +191 -0
  261. package/docs/quickstart.md +54 -5
  262. package/docs/threat-model.md +24 -3
  263. package/docs/x402.md +681 -0
  264. package/package.json +19 -6
  265. package/src/capability/invocation-capability.ts +17 -1
  266. package/src/capability/probe-capability.ts +355 -0
  267. package/src/cli/args.ts +29 -0
  268. package/src/cli/commands/claim.ts +31 -5
  269. package/src/cli/commands/close.ts +56 -7
  270. package/src/cli/commands/invoke.ts +6 -2
  271. package/src/cli/commands/mcp.ts +18 -2
  272. package/src/cli/commands/open.ts +151 -14
  273. package/src/cli/commands/pay.ts +442 -0
  274. package/src/cli/commands/reclaim-unverified.ts +24 -6
  275. package/src/cli/commands/reclaim.ts +274 -19
  276. package/src/cli/commands/refund.ts +277 -0
  277. package/src/cli/commands/status.ts +17 -1
  278. package/src/cli/commands/streams.ts +11 -15
  279. package/src/cli/commands/watch.ts +7 -1
  280. package/src/cli/config.ts +139 -52
  281. package/src/cli/deps.ts +189 -25
  282. package/src/cli/errors.ts +24 -1
  283. package/src/cli/escape-hatch.ts +19 -5
  284. package/src/cli/listings.ts +43 -10
  285. package/src/cli/preflight.ts +36 -21
  286. package/src/cli/privy.ts +398 -0
  287. package/src/cli/reclaimability.ts +154 -0
  288. package/src/cli/run.ts +54 -11
  289. package/src/cli/scan-range.ts +2 -2
  290. package/src/cli/spend-policy.ts +139 -0
  291. package/src/cli/status.ts +14 -1
  292. package/src/cli/wallet.ts +189 -58
  293. package/src/discovery/rate-band.ts +172 -0
  294. package/src/escrow-generation.ts +135 -0
  295. package/src/frameworks/agentkit.ts +45 -11
  296. package/src/frameworks/eliza.ts +27 -5
  297. package/src/frameworks/langchain.ts +14 -0
  298. package/src/gateway/caller-auth-gateway.ts +336 -13
  299. package/src/gateway/http-server.ts +690 -7
  300. package/src/gateway/probe-auth.ts +191 -0
  301. package/src/gateway/signed-rate-bounds.ts +164 -0
  302. package/src/gateway/x402-opener-mode.ts +974 -0
  303. package/src/index.ts +112 -14
  304. package/src/mandates/env.ts +3 -2
  305. package/src/mcp/server.ts +973 -44
  306. package/src/mcp/service-invoker.ts +285 -0
  307. package/src/mcp/x402-tools.ts +621 -0
  308. package/src/network.ts +302 -0
  309. package/src/sdk/invoke.ts +96 -17
  310. package/src/wallet/autonomous-wallet-broker.ts +46 -20
  311. package/src/wallet/autonomous-wallet-protocol.ts +11 -2
  312. package/src/wallet/autonomous-wallet.ts +4 -2
  313. package/src/wallet/broker-escrows.ts +66 -0
  314. package/src/wallet/lifecycle.ts +53 -18
  315. package/src/wallet/privy-broker-server.ts +35 -25
  316. package/src/wallet/privy-session-broker.ts +58 -25
  317. package/src/wallet/privy-session-provider.ts +7 -3
  318. package/src/wallet/provider.ts +20 -15
  319. package/src/x402/facilitator.ts +85 -46
  320. package/src/x402-buyer/guarded-fetch.ts +213 -0
  321. package/src/x402-buyer/index.ts +9 -0
  322. package/src/x402-buyer/pay.ts +517 -0
  323. package/src/x402-opener/abi.ts +881 -0
  324. package/src/x402-opener/facilitator-entry.ts +45 -0
  325. package/src/x402-opener/facilitator-server.ts +1014 -0
  326. package/src/x402-opener/index.ts +13 -0
  327. package/src/x402-opener/listing-resolver.ts +202 -0
  328. package/src/x402-opener/refund-relay.ts +1743 -0
  329. package/src/x402-opener/relayer-queue.ts +18 -0
  330. package/src/x402-opener/scheme.ts +1133 -0
  331. package/src/x402-opener/terms.ts +300 -0
@@ -0,0 +1,232 @@
1
+ import { custom, isAddress, getAddress, } from "viem";
2
+ import { AutonomousWalletError, EncryptedFileCredentialStore, HttpAutonomousWalletBroker, METRIK_AUTONOMOUS_WALLET_BROKER_URL, METRIK_WALLET_ENCRYPTION_KEY_ENV, createAutonomousWalletProvider, createDefaultAutonomousWalletStore, } from "../wallet/autonomous-wallet.js";
3
+ import { createPrivySessionProvider } from "../wallet/privy-session-provider.js";
4
+ import { PRIVY_BROKER_CHAIN_ID } from "../wallet/privy-session-broker.js";
5
+ import { defaultNetwork } from "../network.js";
6
+ import { createPrivyEmbeddedAccount, } from "../wallet/provider.js";
7
+ import { configError } from "./errors.js";
8
+ /** The store key naming the agent-owned wallet in the host credential store. */
9
+ export const PRIVY_WALLET_KEY_ENV = "METRIK_AGENT_PRIVY_WALLET_KEY";
10
+ /** Broker base URL. Optional for `autonomous`, REQUIRED for `session`. */
11
+ export const PRIVY_BROKER_URL_ENV = "METRIK_AGENT_PRIVY_BROKER_URL";
12
+ /** A scoped session token minted by the broker's `POST /v1/sessions`. */
13
+ export const PRIVY_SESSION_TOKEN_ENV = "METRIK_AGENT_PRIVY_SESSION_TOKEN";
14
+ /** The embedded wallet address the session is bound to. */
15
+ export const PRIVY_ADDRESS_ENV = "METRIK_AGENT_PRIVY_ADDRESS";
16
+ /** The PUBLIC Privy app id. Not a secret — the broker serves it at `/v1/config`. */
17
+ export const PRIVY_APP_ID_ENV = "METRIK_AGENT_PRIVY_APP_ID";
18
+ /** Every variable either Privy shape reads. Named in errors, never printed. */
19
+ export const PRIVY_ENV_VARS = [
20
+ PRIVY_WALLET_KEY_ENV,
21
+ PRIVY_BROKER_URL_ENV,
22
+ PRIVY_SESSION_TOKEN_ENV,
23
+ PRIVY_ADDRESS_ENV,
24
+ PRIVY_APP_ID_ENV,
25
+ ];
26
+ /** The variables the user-owned session shape needs, all of them. */
27
+ export const PRIVY_SESSION_ENV_VARS = [
28
+ PRIVY_BROKER_URL_ENV,
29
+ PRIVY_SESSION_TOKEN_ENV,
30
+ PRIVY_ADDRESS_ENV,
31
+ PRIVY_APP_ID_ENV,
32
+ ];
33
+ /** Reads a broker's public policy. No credential is sent; nothing secret is served. */
34
+ export async function fetchPrivySpendPolicy(brokerUrl, fetchImpl = fetch) {
35
+ const base = brokerUrl.replace(/\/$/, "");
36
+ const response = await fetchImpl(`${base}/v1/config`, {
37
+ headers: { accept: "application/json" },
38
+ }).catch((error) => {
39
+ throw configError(`the Privy broker at ${base} did not answer its public policy`, `${describe(error)} The CLI reads GET /v1/config to know the ceiling your wallet is capped at; without it, it cannot tell you before broadcasting whether a hire fits.`);
40
+ });
41
+ const body = (await response.json().catch(() => null));
42
+ if (!response.ok || body === null) {
43
+ throw configError(`the Privy broker at ${base} rejected the public policy read (${response.status})`);
44
+ }
45
+ const chainId = Number(body.chainId);
46
+ const maxTotalUsdc = asBigint(body.maxTotalUsdcAtomic);
47
+ const maxRatePerSecondUsdc = asBigint(body.maxRatePerSecondAtomic);
48
+ const maxDurationSeconds = Number(body.maxDurationSeconds);
49
+ if (!Number.isSafeInteger(chainId) ||
50
+ maxTotalUsdc === null ||
51
+ maxRatePerSecondUsdc === null ||
52
+ !Number.isSafeInteger(maxDurationSeconds)) {
53
+ throw configError(`the Privy broker at ${base} returned a policy this CLI cannot read`, "expected chainId, maxTotalUsdcAtomic, maxRatePerSecondAtomic and maxDurationSeconds.");
54
+ }
55
+ return {
56
+ brokerUrl: base,
57
+ chainId,
58
+ maxTotalUsdc,
59
+ maxRatePerSecondUsdc,
60
+ maxDurationSeconds,
61
+ };
62
+ }
63
+ function asBigint(value) {
64
+ if (typeof value === "bigint")
65
+ return value;
66
+ if (typeof value === "number" && Number.isSafeInteger(value))
67
+ return BigInt(value);
68
+ if (typeof value === "string" && /^[0-9]+$/.test(value))
69
+ return BigInt(value);
70
+ return null;
71
+ }
72
+ /**
73
+ * Resolves a Privy wallet from the environment, or `null` when no Privy
74
+ * variable is set at all.
75
+ *
76
+ * A PARTIALLY configured Privy setup is an error, not a `null` — "you set the
77
+ * session token but not the address" and "you configured no Privy wallet" are
78
+ * different facts, and rendering the first as the second sends the reader
79
+ * looking in the wrong place. This mirrors the CDP path exactly.
80
+ */
81
+ export async function resolvePrivyCliWallet(env, options = {}) {
82
+ const walletKey = read(env, PRIVY_WALLET_KEY_ENV);
83
+ const brokerUrl = read(env, PRIVY_BROKER_URL_ENV);
84
+ const sessionToken = read(env, PRIVY_SESSION_TOKEN_ENV);
85
+ const address = read(env, PRIVY_ADDRESS_ENV);
86
+ const appId = read(env, PRIVY_APP_ID_ENV);
87
+ if (walletKey === null &&
88
+ brokerUrl === null &&
89
+ sessionToken === null &&
90
+ address === null &&
91
+ appId === null) {
92
+ return null;
93
+ }
94
+ if (walletKey !== null) {
95
+ if (sessionToken !== null) {
96
+ options.note?.(`warning: both ${PRIVY_WALLET_KEY_ENV} and ${PRIVY_SESSION_TOKEN_ENV} are set; using the agent-owned wallet named by ${PRIVY_WALLET_KEY_ENV}. Unset it to sign with the session token.`);
97
+ }
98
+ return await resolveAutonomous(walletKey, brokerUrl, env, options);
99
+ }
100
+ const missing = PRIVY_SESSION_ENV_VARS.filter((name) => read(env, name) === null);
101
+ if (missing.length > 0) {
102
+ throw configError(`the Privy wallet is partially configured: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not set`, `a Privy wallet is configured one of two ways: set ${PRIVY_WALLET_KEY_ENV} to the store key of an agent-owned wallet you provisioned with provisionMetrikAutonomousWallet(), or set all of ${PRIVY_SESSION_ENV_VARS.join(", ")} for a broker session. Set the missing one${missing.length === 1 ? "" : "s"}, or unset the others to use a different wallet.`);
103
+ }
104
+ return resolveSession({
105
+ brokerUrl: brokerUrl,
106
+ sessionToken: sessionToken,
107
+ address: address,
108
+ appId: appId,
109
+ ...(options.rpcUrl === undefined ? {} : { rpcUrl: options.rpcUrl }),
110
+ ...(options.fetchImpl === undefined
111
+ ? {}
112
+ : { fetchImpl: options.fetchImpl }),
113
+ });
114
+ }
115
+ async function resolveAutonomous(walletKey, brokerUrlOverride, env, options) {
116
+ const store = options.store ?? selectCredentialStore(env);
117
+ let record;
118
+ try {
119
+ record = await store.load(walletKey);
120
+ }
121
+ catch (error) {
122
+ throw configError(`could not read the agent-owned Privy wallet "${walletKey}" from the credential store`, `${describe(error)} On a headless host the OS credential store is often unavailable; set ${METRIK_WALLET_ENCRYPTION_KEY_ENV} to use the encrypted-file store instead.`);
123
+ }
124
+ if (record === null) {
125
+ throw configError(`no agent-owned Privy wallet is stored under the key "${walletKey}"`, `the CLI never provisions a wallet on your behalf — a fund-moving command is the wrong place to mint one. Provision it once with provisionMetrikAutonomousWallet({ storeKey: "${walletKey}" }) (see docs/autonomous-privy-wallet.md), then re-run this command.`);
126
+ }
127
+ if (record.walletId === undefined || record.address === undefined) {
128
+ throw configError(`the agent-owned Privy wallet "${walletKey}" was never finished provisioning`, "the local key exists but the broker never returned a wallet id and address. Re-run provisionMetrikAutonomousWallet() with the same store key — it retries with the same key and idempotency nonce.");
129
+ }
130
+ const brokerUrl = brokerUrlOverride ?? record.brokerUrl;
131
+ if (brokerUrlOverride !== null && brokerUrlOverride !== record.brokerUrl) {
132
+ options.note?.(`note: ${PRIVY_BROKER_URL_ENV} (${brokerUrlOverride}) overrides the broker this wallet was provisioned against (${record.brokerUrl}); only a broker holding this wallet's Privy authorization key can authorize it.`);
133
+ }
134
+ let broker;
135
+ try {
136
+ broker = new HttpAutonomousWalletBroker(brokerUrl, {
137
+ ...(options.fetchImpl === undefined
138
+ ? {}
139
+ : { fetchImpl: options.fetchImpl }),
140
+ });
141
+ }
142
+ catch (error) {
143
+ throw configError(`the autonomous wallet broker URL is not usable: ${describe(error)}`, `set ${PRIVY_BROKER_URL_ENV} to an HTTPS broker you control (the default is ${METRIK_AUTONOMOUS_WALLET_BROKER_URL}).`);
144
+ }
145
+ const provider = createAutonomousWalletProvider({
146
+ wallet: record,
147
+ broker,
148
+ ...(options.rpcUrl === undefined ? {} : { rpcUrl: options.rpcUrl }),
149
+ ...(options.fetchImpl === undefined
150
+ ? {}
151
+ : { fetchImpl: options.fetchImpl }),
152
+ });
153
+ const account = await embeddedAccount(provider, record.appId, record.address);
154
+ return {
155
+ source: "privy-autonomous",
156
+ account,
157
+ transport: custom(provider),
158
+ description: `${record.address} (agent-owned Privy wallet "${walletKey}" via ${brokerUrl})`,
159
+ readSpendPolicy: async () => await fetchPrivySpendPolicy(brokerUrl, options.fetchImpl ?? globalThis.fetch.bind(globalThis)),
160
+ };
161
+ }
162
+ function resolveSession(input) {
163
+ if (!isAddress(input.address)) {
164
+ throw configError(`${PRIVY_ADDRESS_ENV} must be a 0x-prefixed 20-byte address`);
165
+ }
166
+ const address = getAddress(input.address);
167
+ let provider;
168
+ try {
169
+ provider = createPrivySessionProvider({
170
+ brokerUrl: input.brokerUrl,
171
+ sessionToken: input.sessionToken,
172
+ address,
173
+ ...(input.rpcUrl === undefined ? {} : { rpcUrl: input.rpcUrl }),
174
+ ...(input.fetchImpl === undefined ? {} : { fetchImpl: input.fetchImpl }),
175
+ });
176
+ }
177
+ catch (error) {
178
+ throw configError(`the Privy session broker URL is not usable: ${describe(error)}`, `set ${PRIVY_BROKER_URL_ENV} to the HTTPS broker that minted ${PRIVY_SESSION_TOKEN_ENV}. A session token is only valid against the broker that issued it.`);
179
+ }
180
+ return embeddedAccount(provider, input.appId, address).then((account) => ({
181
+ source: "privy-session",
182
+ account,
183
+ transport: custom(provider),
184
+ description: `${address} (Privy broker session via ${input.brokerUrl})`,
185
+ readSpendPolicy: async () => await fetchPrivySpendPolicy(input.brokerUrl, input.fetchImpl ?? globalThis.fetch.bind(globalThis)),
186
+ }));
187
+ }
188
+ /**
189
+ * Wraps a provider in the package's existing Privy EOA adapter.
190
+ *
191
+ * Both CLI providers answer `eth_chainId` and `eth_accounts` locally, so the
192
+ * adapter's session assertion is a pure local consistency check here — no
193
+ * network call happens while the wallet is being resolved.
194
+ */
195
+ async function embeddedAccount(provider, appId, address) {
196
+ try {
197
+ return await createPrivyEmbeddedAccount({
198
+ appId,
199
+ address,
200
+ provider,
201
+ chainId: PRIVY_BROKER_CHAIN_ID,
202
+ });
203
+ }
204
+ catch (error) {
205
+ throw configError(`the Privy wallet could not be prepared: ${describe(error)}`, `check ${PRIVY_ENV_VARS.join(", ")}. Metrik Privy wallets are on the broker's network only (${defaultNetwork().name}, chain ${PRIVY_BROKER_CHAIN_ID}).`);
206
+ }
207
+ }
208
+ /**
209
+ * The credential store the autonomous wallet was provisioned into.
210
+ *
211
+ * Selection mirrors `provisionMetrikAutonomousWallet`'s documented options:
212
+ * setting `METRIK_WALLET_ENCRYPTION_KEY` means the encrypted-file store (the
213
+ * durable option for a headless host), otherwise the host OS store. Picking a
214
+ * different store than provisioning used simply finds no record, and the
215
+ * "no wallet is stored under this key" error above says so.
216
+ */
217
+ function selectCredentialStore(env) {
218
+ if (read(env, METRIK_WALLET_ENCRYPTION_KEY_ENV) !== null) {
219
+ return new EncryptedFileCredentialStore({ env });
220
+ }
221
+ return createDefaultAutonomousWalletStore();
222
+ }
223
+ function read(env, name) {
224
+ const value = env[name];
225
+ return value === undefined || value.length === 0 ? null : value;
226
+ }
227
+ function describe(error) {
228
+ if (error instanceof AutonomousWalletError)
229
+ return error.message;
230
+ return error instanceof Error ? error.message : String(error);
231
+ }
232
+ //# sourceMappingURL=privy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privy.js","sourceRoot":"","sources":["../../src/cli/privy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,SAAS,EACT,UAAU,GAGX,MAAM,MAAM,CAAC;AAEd,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC5B,0BAA0B,EAC1B,mCAAmC,EACnC,gCAAgC,EAChC,8BAA8B,EAC9B,kCAAkC,GAGnC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,0BAA0B,GAE3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAmB1C,gFAAgF;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AACpE,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AACpE,yEAAyE;AACzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,kCAAkC,CAAC;AAC1E,2DAA2D;AAC3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AAC9D,oFAAoF;AACpF,MAAM,CAAC,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAE5D,+EAA+E;AAC/E,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,oBAAoB;IACp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StreamV2 } from "@absol-labs/sdk";
2
+ import type { CliReadClient } from "./deps.js";
3
+ /**
4
+ * Why a proof-based reclaim cannot go through right now, read from chain state
5
+ * rather than decoded out of a revert.
6
+ *
7
+ * `metrik reclaim` used to learn this only by sending the simulation and
8
+ * reading what came back. That works exactly as well as the endpoint's revert
9
+ * data does, and on the public Base Sepolia RPC it frequently does not work at
10
+ * all: an already-reclaimed stream, a stream that is still running, and a
11
+ * stream whose stop time is not checkpointed yet ALL came back as
12
+ *
13
+ * reclaim simulation failed: Execution reverted for an unknown reason.
14
+ *
15
+ * Three different situations, three completely different next actions — you
16
+ * already have the money / close it first / wait ~20 seconds — and one message
17
+ * that distinguishes none of them. Worse, the retry loop keys off the same
18
+ * undecoded revert, so the wait that this command advertises never engaged.
19
+ *
20
+ * Every one of these conditions is a pure function of state the CLI already
21
+ * reads elsewhere (`getStreamV2`, `latestCheckpointCheckedAt`, the chain clock,
22
+ * and {@link settlementCoverage}, which `metrik status` has always used to
23
+ * decide the same question). So the condition is named from that state, before
24
+ * a transaction is built, the way `reclaim-unverified` has always named
25
+ * "already reclaimed". No revert data required.
26
+ */
27
+ export type ReclaimBlocker =
28
+ /** `AlreadyReclaimed()` / `NothingToReclaim()`: the money is already back. */
29
+ {
30
+ readonly kind: "reclaimed";
31
+ }
32
+ /** `StreamNotReclaimable()`: neither closed nor expired, so the clock runs. */
33
+ | {
34
+ readonly kind: "running";
35
+ readonly expiresAt: number;
36
+ readonly secondsRemaining: number;
37
+ }
38
+ /**
39
+ * `SettlementWindowOpen()`: the stream has stopped but no checkpoint reaches
40
+ * its stop time yet. The ONLY one of the three that is a wait rather than a
41
+ * refusal — the oracle publishes roughly every 15-22s.
42
+ */
43
+ | {
44
+ readonly kind: "awaiting-checkpoint";
45
+ readonly stopAt: number;
46
+ readonly coveredUpTo: number | null;
47
+ };
48
+ /**
49
+ * The blocker implied by this state, or `null` when nothing in the state blocks
50
+ * a reclaim. Pure, so every branch is testable without an RPC — the same reason
51
+ * {@link settlementCoverage} is.
52
+ *
53
+ * Order matters and follows the escrow: a reclaimed stream is terminal, a
54
+ * running stream cannot be reclaimed at any settlement state, and only then
55
+ * does checkpoint coverage decide.
56
+ */
57
+ export declare function classifyReclaimBlocker(stream: Pick<StreamV2, "status" | "closedAt" | "expiresAt" | "reclaimed">, latestCheckpointCheckedAt: number | null, nowSeconds: number): ReclaimBlocker | null;
58
+ /**
59
+ * Read the state the classifier needs and name the blocker.
60
+ *
61
+ * **Fails open.** A read that does not answer returns `null` — "nothing known
62
+ * to block this" — never a refusal. Refusing to return a buyer's money because
63
+ * a load-balanced endpoint would not answer a view call is the one outcome this
64
+ * command must never produce; the transaction itself remains the authority.
65
+ */
66
+ export declare function readReclaimBlocker(read: Pick<CliReadClient, "getStreamV2" | "latestCheckpointCheckedAt" | "latestBlockTimestamp">, streamId: `0x${string}`, fallbackNowSeconds: number): Promise<ReclaimBlocker | null>;
67
+ /**
68
+ * The refusal for a blocker that will not clear on its own, as message + hint.
69
+ *
70
+ * `awaiting-checkpoint` has no entry here on purpose: it clears by itself, so
71
+ * it is narrated by {@link describeAwaitingCheckpoint} and waited out, never
72
+ * raised as an error.
73
+ */
74
+ export declare function describeTerminalBlocker(blocker: ReclaimBlocker, streamId: `0x${string}`): {
75
+ readonly message: string;
76
+ readonly hint: string;
77
+ } | null;
78
+ /** The wait, named: what stopped, how far the oracle has published. */
79
+ export declare function describeAwaitingCheckpoint(blocker: Extract<ReclaimBlocker, {
80
+ kind: "awaiting-checkpoint";
81
+ }>): string;
82
+ //# sourceMappingURL=reclaimability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reclaimability.d.ts","sourceRoot":"","sources":["../../src/cli/reclaimability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAKhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH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E,MAAM,CAQR"}
@@ -0,0 +1,80 @@
1
+ import { formatDuration } from "./amounts.js";
2
+ import { formatTimestamp, readChainNow } from "./escape-hatch.js";
3
+ import { settlementCoverage } from "./status.js";
4
+ /**
5
+ * The blocker implied by this state, or `null` when nothing in the state blocks
6
+ * a reclaim. Pure, so every branch is testable without an RPC — the same reason
7
+ * {@link settlementCoverage} is.
8
+ *
9
+ * Order matters and follows the escrow: a reclaimed stream is terminal, a
10
+ * running stream cannot be reclaimed at any settlement state, and only then
11
+ * does checkpoint coverage decide.
12
+ */
13
+ export function classifyReclaimBlocker(stream, latestCheckpointCheckedAt, nowSeconds) {
14
+ if (stream.reclaimed)
15
+ return { kind: "reclaimed" };
16
+ if (stream.status !== "closed" && nowSeconds < stream.expiresAt) {
17
+ return {
18
+ kind: "running",
19
+ expiresAt: stream.expiresAt,
20
+ secondsRemaining: stream.expiresAt - nowSeconds,
21
+ };
22
+ }
23
+ const coverage = settlementCoverage(stream, latestCheckpointCheckedAt, nowSeconds);
24
+ if (coverage.pending && coverage.stopAt !== null) {
25
+ return {
26
+ kind: "awaiting-checkpoint",
27
+ stopAt: coverage.stopAt,
28
+ coveredUpTo: coverage.coveredUpTo,
29
+ };
30
+ }
31
+ return null;
32
+ }
33
+ /**
34
+ * Read the state the classifier needs and name the blocker.
35
+ *
36
+ * **Fails open.** A read that does not answer returns `null` — "nothing known
37
+ * to block this" — never a refusal. Refusing to return a buyer's money because
38
+ * a load-balanced endpoint would not answer a view call is the one outcome this
39
+ * command must never produce; the transaction itself remains the authority.
40
+ */
41
+ export async function readReclaimBlocker(read, streamId, fallbackNowSeconds) {
42
+ const stream = await read.getStreamV2(streamId).catch(() => null);
43
+ if (stream === null)
44
+ return null;
45
+ const now = await readChainNow(read, fallbackNowSeconds);
46
+ const latestCheckpointCheckedAt = await read
47
+ .latestCheckpointCheckedAt()
48
+ .catch(() => null);
49
+ return classifyReclaimBlocker(stream, latestCheckpointCheckedAt, now.seconds);
50
+ }
51
+ /**
52
+ * The refusal for a blocker that will not clear on its own, as message + hint.
53
+ *
54
+ * `awaiting-checkpoint` has no entry here on purpose: it clears by itself, so
55
+ * it is narrated by {@link describeAwaitingCheckpoint} and waited out, never
56
+ * raised as an error.
57
+ */
58
+ export function describeTerminalBlocker(blocker, streamId) {
59
+ if (blocker.kind === "reclaimed") {
60
+ return {
61
+ message: "this stream has already been reclaimed — there is nothing left to take back",
62
+ hint: `check where it went: metrik status ${streamId}`,
63
+ };
64
+ }
65
+ if (blocker.kind === "running") {
66
+ return {
67
+ message: `the stream is still running, so there is nothing to reclaim yet — the meter stops at ${formatTimestamp(blocker.expiresAt)}, in ${formatDuration(blocker.secondsRemaining)}`,
68
+ hint: `stop the clock first — \`metrik close ${streamId}\`, or re-run this command with --close-first — or wait for it to expire. (If you closed it moments ago, the RPC endpoint may not have caught up yet: re-run this command.)`,
69
+ };
70
+ }
71
+ return null;
72
+ }
73
+ /** The wait, named: what stopped, how far the oracle has published. */
74
+ export function describeAwaitingCheckpoint(blocker) {
75
+ const covered = blocker.coveredUpTo === null
76
+ ? "how far the oracle has published could not be read"
77
+ : `the oracle has published only to ${formatTimestamp(blocker.coveredUpTo)}`;
78
+ return `the stream stopped at ${formatTimestamp(blocker.stopAt)} and ${covered}. Reclaim reverts until a checkpoint reaches the stop time — the oracle publishes roughly every 15-22s, so this waits.`;
79
+ }
80
+ //# sourceMappingURL=reclaimability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reclaimability.js","sourceRoot":"","sources":["../../src/cli/reclaimability.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AA+CjD;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAAyE,EACzE,yBAAwC,EACxC,UAAkB;IAElB,IAAI,MA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C,OAAuB,EACvB,QAAuB;IAEvB,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO;YACL,OAAO,EACL,6EAA6E;YAC/E,IAAI,EAAE,uCAAuC,QAAQ,EAAE;SACxD,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO;YACL,OAAO,EAAE,wFAAwF,eAAe,CAC9G,OAAO,CAAC,SAAS,CAClB,QAAQ,cAAc,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE;YACnD,IAAI,EAAE,yCAAyC,QAAQ,6KAA6K;SACrO,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,0BAA0B,CACxC,OAAiE;IAEjE,MAAM,OAAO,GACX,OAAO,CAAC,WAAW,KAAK,IAAI;QAC1B,CAAC,CAAC,oDAAoD;QACtD,CAAC,CAAC,oCAAoC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;IACjF,OAAO,yBAAyB,eAAe,CAC7C,OAAO,CAAC,MAAM,CACf,QAAQ,OAAO,wHAAwH,CAAC;AAC3I,CAAC"}
package/dist/cli/run.d.ts CHANGED
@@ -3,7 +3,8 @@ import { type CliDependencies } from "./deps.js";
3
3
  import type { CommandSpec } from "./context.js";
4
4
  /**
5
5
  * The command surface, in the order the product loop runs:
6
- * discover -> open -> invoke -> watch/status -> close -> reclaim, then the
6
+ * discover -> open (or pay, over x402) -> invoke -> watch/status -> close ->
7
+ * reclaim (or refund, through an x402 seller's gasless relay), then the
7
8
  * operator's own redemption (`claim`) and the buyer's last-resort exit
8
9
  * (`reclaim-unverified`). `streams` (which of them are mine?) sits inside that
9
10
  * loop; `mcp` (run the same loop from an MCP host) sits after it.
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAQA,O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wBAAsB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAiEpE;AAqBD,wBAAgB,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAoEvD"}
package/dist/cli/run.js CHANGED
@@ -1,25 +1,46 @@
1
- import { assertKnownFlags, booleanFlag, parseArgs } from "./args.js";
2
- import { CONFIG_FLAGS, GLOBAL_FLAGS, TESTNET_CHAIN_IDS, resolveConfig, } from "./config.js";
1
+ import { assertKnownFlags, booleanFlag, jsonOutputRequested, parseArgs, } from "./args.js";
2
+ import { CONFIG_FLAGS, GLOBAL_FLAGS, CLI_NETWORK_POLICY, resolveConfig, } from "./config.js";
3
+ import { describeAllowedNetworks } from "../network.js";
3
4
  import { CliError, describeError, usageError } from "./errors.js";
4
5
  import { createPrinter } from "./output.js";
5
6
  import { startHeartbeat } from "./progress.js";
6
7
  import { defaultCliDependencies } from "./deps.js";
7
8
  import { packageVersion } from "./version.js";
8
- import { CDP_ENV_VARS, PRIVATE_KEY_ENV } from "./wallet.js";
9
+ import { CDP_ENV_VARS, PRIVATE_KEY_ENV, PRIVY_SESSION_ENV_VARS, PRIVY_WALLET_KEY_ENV, } from "./wallet.js";
9
10
  import { claimCommand } from "./commands/claim.js";
10
11
  import { closeCommand } from "./commands/close.js";
11
12
  import { discoverCommand } from "./commands/discover.js";
12
13
  import { invokeCommand } from "./commands/invoke.js";
13
14
  import { mcpCommand } from "./commands/mcp.js";
14
15
  import { openCommand } from "./commands/open.js";
16
+ import { payCommand } from "./commands/pay.js";
15
17
  import { reclaimCommand } from "./commands/reclaim.js";
18
+ import { refundCommand } from "./commands/refund.js";
16
19
  import { reclaimUnverifiedCommand } from "./commands/reclaim-unverified.js";
17
20
  import { statusCommand } from "./commands/status.js";
18
21
  import { streamsCommand } from "./commands/streams.js";
19
22
  import { watchCommand } from "./commands/watch.js";
23
+ /**
24
+ * Every wallet source, named in the order they are resolved. Privy shipped in
25
+ * 0.11.0 as resolution step 3 and worked, but appeared in no user-facing text
26
+ * at all — so the only way to learn the CLI could use it was to read the
27
+ * source or the docs. An external reviewer running the published package
28
+ * concluded it did not exist.
29
+ */
30
+ const WALLET_SOURCES = `${PRIVATE_KEY_ENV}, ${CDP_ENV_VARS.join(" + ")}, ` +
31
+ `or ${PRIVY_WALLET_KEY_ENV} (Privy; or a broker session via ${PRIVY_SESSION_ENV_VARS.join(" + ")}).`;
32
+ /**
33
+ * Said in the help, not only discovered at runtime. `claim` is the OPERATOR's
34
+ * side and a Privy broker policy allowlists BUYER actions only, so a Privy
35
+ * wallet cannot sign one — the broker refuses, and the client cannot raise its
36
+ * own ceiling. The command already warns when it runs; someone choosing a
37
+ * wallet needs it before that.
38
+ */
39
+ const PRIVY_CLAIM_NOTE = "`metrik claim` does NOT work on a Privy wallet: the broker's transaction allowlist is buyer-only. Claim with the operator's own key.";
20
40
  /**
21
41
  * The command surface, in the order the product loop runs:
22
- * discover -> open -> invoke -> watch/status -> close -> reclaim, then the
42
+ * discover -> open (or pay, over x402) -> invoke -> watch/status -> close ->
43
+ * reclaim (or refund, through an x402 seller's gasless relay), then the
23
44
  * operator's own redemption (`claim`) and the buyer's last-resort exit
24
45
  * (`reclaim-unverified`). `streams` (which of them are mine?) sits inside that
25
46
  * loop; `mcp` (run the same loop from an MCP host) sits after it.
@@ -27,12 +48,14 @@ import { watchCommand } from "./commands/watch.js";
27
48
  export const COMMANDS = [
28
49
  discoverCommand,
29
50
  openCommand,
51
+ payCommand,
30
52
  statusCommand,
31
53
  streamsCommand,
32
54
  watchCommand,
33
55
  invokeCommand,
34
56
  closeCommand,
35
57
  reclaimCommand,
58
+ refundCommand,
36
59
  reclaimUnverifiedCommand,
37
60
  claimCommand,
38
61
  mcpCommand,
@@ -52,7 +75,7 @@ export async function runCli(options) {
52
75
  let json = false;
53
76
  try {
54
77
  const args = parseArgs(options.argv);
55
- json = booleanFlag(args, "json");
78
+ json = jsonOutputRequested(args);
56
79
  const out = createPrinter(streams, json);
57
80
  // `--version` is checked before the bare-invocation help branch: `metrik
58
81
  // --version` parses to no command at all.
@@ -130,12 +153,13 @@ export function renderHelp(commandName) {
130
153
  ...(command.signs
131
154
  ? [
132
155
  "",
133
- `Broadcasts a transaction. Requires a wallet in the environment: ${PRIVATE_KEY_ENV}, or ${CDP_ENV_VARS.join(" + ")}.`,
156
+ `Broadcasts a transaction. Requires a wallet in the environment: ${WALLET_SOURCES}`,
157
+ ...(command.name === "claim" ? [PRIVY_CLAIM_NOTE] : []),
134
158
  ]
135
159
  : command.requiresKey === true
136
160
  ? [
137
161
  "",
138
- `Broadcasts nothing, but signs an off-chain EIP-712 capability, so it requires a wallet in the environment: ${PRIVATE_KEY_ENV}, or ${CDP_ENV_VARS.join(" + ")}.`,
162
+ `Broadcasts nothing, but signs an off-chain EIP-712 capability, so it requires a wallet in the environment: ${WALLET_SOURCES}`,
139
163
  ]
140
164
  : []),
141
165
  ].join("\n");
@@ -157,16 +181,21 @@ export function renderHelp(commandName) {
157
181
  " --json machine-readable output on stdout",
158
182
  " --help this text, or `metrik <command> --help`",
159
183
  "",
160
- "Settlement flags (all default to Metrik's Base Sepolia deployment):",
161
- " --chain-id --rpc-url --escrow --usdc --oracle-url --registry-url",
184
+ "Settlement flags (all default to the selected network's registry entry):",
185
+ " --network --chain-id --rpc-url --escrow --usdc --oracle-url --registry-url",
186
+ " --network takes a registry id, chain id or CAIP-2 id (env METRIK_NETWORK).",
162
187
  "",
163
188
  "Wallet (read from the environment only; never accepted as a flag):",
164
- ` ${PRIVATE_KEY_ENV} a Base Sepolia test key. Checked first.`,
189
+ ` ${PRIVATE_KEY_ENV} a testnet key. Checked first.`,
165
190
  ` ${CDP_ENV_VARS.join(", ")}`,
166
191
  " a Coinbase CDP Server Wallet v2 account. Used when no private key is set.",
192
+ ` ${PRIVY_WALLET_KEY_ENV}`,
193
+ " a Privy wallet you provisioned, reached through a broker. Checked third.",
194
+ ` A broker session instead: ${PRIVY_SESSION_ENV_VARS.join(", ")}.`,
195
+ ` ${PRIVY_CLAIM_NOTE}`,
167
196
  " A credential on the command line lands in shell history; these never are.",
168
197
  "",
169
- `TESTNET ONLY: this CLI refuses any chain outside ${TESTNET_CHAIN_IDS.join(", ")} (Base Sepolia),`,
198
+ `TESTNET ONLY: this CLI refuses any chain outside the registered testnets: ${describeAllowedNetworks(CLI_NETWORK_POLICY)},`,
170
199
  "and re-checks the chain id the RPC actually serves before signing. There is no override.",
171
200
  ].join("\n");
172
201
  }
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,aAAa,EAAmB,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAwB,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG5D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;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K,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5I;QACD,EAAE;QACF,eAAe;QACf,qDAAqD;QACrD,2DAA2D;QAC3D,EAAE;QACF,0EAA0E;QAC1E,oFAAoF;QACpF,8EAA8E;QAC9E,EAAE;QACF,oEAAoE;QACpE,KAAK,eAAe,iCAAiC;QACrD,KAAK,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC9B,+EAA+E;QAC/E,KAAK,oBAAoB,EAAE;QAC3B,8EAA8E;QAC9E,iCAAiC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;QACrE,OAAO,gBAAgB,EAAE;QACzB,6EAA6E;QAC7E,EAAE;QACF,6EAA6E,uBAAuB,CAAC,kBAAkB,CAAC,GAAG;QAC3H,0FAA0F;KAC3F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
@@ -19,13 +19,13 @@
19
19
  * `buyer` and `operator` are INDEXED on `StreamOpened`, so a per-wallet scan is
20
20
  * a server-side topic filter whose response is tiny regardless of range. What
21
21
  * public RPCs cap is the per-call BLOCK RANGE, and a topic filter does not lift
22
- * it: `sepolia.base.org` answers a wider range with `-32614 "eth_getLogs is
22
+ * it: the public RPC answers a wider range with `-32614 "eth_getLogs is
23
23
  * limited to a 10,000 range"`. So the page size is the cap, not a guess below
24
24
  * it.
25
25
  */
26
26
  /**
27
27
  * getLogs page size. The window is `chunk + 1` blocks (bounds inclusive), so
28
- * 9 999 is the largest page `sepolia.base.org` accepts.
28
+ * 9 999 is the largest page the public RPC accepts.
29
29
  */
30
30
  export declare const LOG_SCAN_CHUNK = 9999n;
31
31
  /**
@@ -19,13 +19,13 @@
19
19
  * `buyer` and `operator` are INDEXED on `StreamOpened`, so a per-wallet scan is
20
20
  * a server-side topic filter whose response is tiny regardless of range. What
21
21
  * public RPCs cap is the per-call BLOCK RANGE, and a topic filter does not lift
22
- * it: `sepolia.base.org` answers a wider range with `-32614 "eth_getLogs is
22
+ * it: the public RPC answers a wider range with `-32614 "eth_getLogs is
23
23
  * limited to a 10,000 range"`. So the page size is the cap, not a guess below
24
24
  * it.
25
25
  */
26
26
  /**
27
27
  * getLogs page size. The window is `chunk + 1` blocks (bounds inclusive), so
28
- * 9 999 is the largest page `sepolia.base.org` accepts.
28
+ * 9 999 is the largest page the public RPC accepts.
29
29
  */
30
30
  export const LOG_SCAN_CHUNK = 9999n;
31
31
  /**