@wlfi-agent/cli 1.4.13 → 1.4.15

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 (289) hide show
  1. package/Cargo.lock +3968 -0
  2. package/Cargo.toml +50 -0
  3. package/README.md +426 -6
  4. package/crates/vault-cli-admin/Cargo.toml +26 -0
  5. package/crates/vault-cli-admin/src/io_utils.rs +500 -0
  6. package/crates/vault-cli-admin/src/main.rs +3990 -0
  7. package/crates/vault-cli-admin/src/shared_config.rs +624 -0
  8. package/crates/vault-cli-admin/src/tui/amounts.rs +180 -0
  9. package/crates/vault-cli-admin/src/tui/token_rpc.rs +250 -0
  10. package/crates/vault-cli-admin/src/tui/utils.rs +82 -0
  11. package/crates/vault-cli-admin/src/tui.rs +3410 -0
  12. package/crates/vault-cli-agent/Cargo.toml +24 -0
  13. package/crates/vault-cli-agent/src/io_utils.rs +576 -0
  14. package/crates/vault-cli-agent/src/main.rs +833 -0
  15. package/crates/vault-cli-daemon/Cargo.toml +28 -0
  16. package/crates/vault-cli-daemon/src/bin/wlfi-agent-system-keychain.rs +216 -0
  17. package/crates/vault-cli-daemon/src/main.rs +644 -0
  18. package/crates/vault-cli-daemon/src/relay_sync.rs +894 -0
  19. package/crates/vault-cli-daemon/tests/system_keychain_helper_acl.rs +167 -0
  20. package/crates/vault-daemon/Cargo.toml +32 -0
  21. package/crates/vault-daemon/src/daemon_parts/api_impl_and_utils.rs +1041 -0
  22. package/crates/vault-daemon/src/daemon_parts/core_helpers.rs +1256 -0
  23. package/crates/vault-daemon/src/daemon_parts/types_api_rpc.rs +622 -0
  24. package/crates/vault-daemon/src/lib.rs +54 -0
  25. package/crates/vault-daemon/src/persistence.rs +441 -0
  26. package/crates/vault-daemon/src/tests.rs +237 -0
  27. package/crates/vault-daemon/src/tests_parts/part1.rs +1224 -0
  28. package/crates/vault-daemon/src/tests_parts/part2.rs +1021 -0
  29. package/crates/vault-daemon/src/tests_parts/part3.rs +835 -0
  30. package/crates/vault-daemon/src/tests_parts/part4.rs +604 -0
  31. package/crates/vault-domain/Cargo.toml +20 -0
  32. package/crates/vault-domain/src/action.rs +849 -0
  33. package/crates/vault-domain/src/address.rs +51 -0
  34. package/crates/vault-domain/src/approval.rs +90 -0
  35. package/crates/vault-domain/src/constants.rs +4 -0
  36. package/crates/vault-domain/src/error.rs +54 -0
  37. package/crates/vault-domain/src/keys.rs +71 -0
  38. package/crates/vault-domain/src/lib.rs +42 -0
  39. package/crates/vault-domain/src/nonce.rs +102 -0
  40. package/crates/vault-domain/src/policy.rs +172 -0
  41. package/crates/vault-domain/src/request.rs +53 -0
  42. package/crates/vault-domain/src/scope.rs +24 -0
  43. package/crates/vault-domain/src/session.rs +50 -0
  44. package/crates/vault-domain/src/signature.rs +34 -0
  45. package/crates/vault-domain/src/tests.rs +651 -0
  46. package/crates/vault-domain/src/u128_as_decimal_string.rs +44 -0
  47. package/crates/vault-policy/Cargo.toml +17 -0
  48. package/crates/vault-policy/src/engine.rs +301 -0
  49. package/crates/vault-policy/src/error.rs +81 -0
  50. package/crates/vault-policy/src/lib.rs +17 -0
  51. package/crates/vault-policy/src/report.rs +34 -0
  52. package/crates/vault-policy/src/tests.rs +891 -0
  53. package/crates/vault-policy/src/tests_explain.rs +78 -0
  54. package/crates/vault-sdk-agent/Cargo.toml +21 -0
  55. package/crates/vault-sdk-agent/src/lib.rs +711 -0
  56. package/crates/vault-signer/Cargo.toml +25 -0
  57. package/crates/vault-signer/src/lib.rs +731 -0
  58. package/crates/vault-signer/tests/secure_enclave_acl.rs +54 -0
  59. package/crates/vault-transport-unix/Cargo.toml +24 -0
  60. package/crates/vault-transport-unix/src/lib.rs +1640 -0
  61. package/crates/vault-transport-xpc/Cargo.toml +25 -0
  62. package/crates/vault-transport-xpc/src/client_codec_api.rs +635 -0
  63. package/crates/vault-transport-xpc/src/lib.rs +680 -0
  64. package/crates/vault-transport-xpc/src/tests.rs +818 -0
  65. package/crates/vault-transport-xpc/tests/e2e_flow.rs +773 -0
  66. package/dist/cli.cjs +35088 -0
  67. package/dist/cli.cjs.map +1 -0
  68. package/package.json +45 -41
  69. package/packages/cache/.turbo/turbo-build.log +52 -0
  70. package/packages/cache/dist/chunk-2QFWMUXT.cjs +43 -0
  71. package/packages/cache/dist/chunk-2QFWMUXT.cjs.map +1 -0
  72. package/packages/cache/dist/chunk-4U63TZTQ.js +43 -0
  73. package/packages/cache/dist/chunk-4U63TZTQ.js.map +1 -0
  74. package/packages/cache/dist/chunk-ALQ6H7KG.cjs +404 -0
  75. package/packages/cache/dist/chunk-ALQ6H7KG.cjs.map +1 -0
  76. package/packages/cache/dist/chunk-FGJEEF5N.js +404 -0
  77. package/packages/cache/dist/chunk-FGJEEF5N.js.map +1 -0
  78. package/packages/cache/dist/chunk-UYNEHZHB.cjs +45 -0
  79. package/packages/cache/dist/chunk-UYNEHZHB.cjs.map +1 -0
  80. package/packages/cache/dist/chunk-VXVMPG3W.js +45 -0
  81. package/packages/cache/dist/chunk-VXVMPG3W.js.map +1 -0
  82. package/packages/cache/dist/client/index.cjs +11 -0
  83. package/packages/cache/dist/client/index.cjs.map +1 -0
  84. package/packages/cache/dist/client/index.d.cts +15 -0
  85. package/packages/cache/dist/client/index.d.ts +15 -0
  86. package/packages/cache/dist/client/index.js +11 -0
  87. package/packages/cache/dist/client/index.js.map +1 -0
  88. package/packages/cache/dist/errors/index.cjs +11 -0
  89. package/packages/cache/dist/errors/index.cjs.map +1 -0
  90. package/packages/cache/dist/errors/index.d.cts +26 -0
  91. package/packages/cache/dist/errors/index.d.ts +26 -0
  92. package/packages/cache/dist/errors/index.js +11 -0
  93. package/packages/cache/dist/errors/index.js.map +1 -0
  94. package/packages/cache/dist/index.cjs +29 -0
  95. package/packages/cache/dist/index.cjs.map +1 -0
  96. package/packages/cache/dist/index.d.cts +4 -0
  97. package/packages/cache/dist/index.d.ts +4 -0
  98. package/packages/cache/dist/index.js +29 -0
  99. package/packages/cache/dist/index.js.map +1 -0
  100. package/packages/cache/dist/service/index.cjs +15 -0
  101. package/packages/cache/dist/service/index.cjs.map +1 -0
  102. package/packages/cache/dist/service/index.d.cts +184 -0
  103. package/packages/cache/dist/service/index.d.ts +184 -0
  104. package/packages/cache/dist/service/index.js +15 -0
  105. package/packages/cache/dist/service/index.js.map +1 -0
  106. package/packages/cache/node_modules/.bin/jiti +17 -0
  107. package/packages/cache/node_modules/.bin/tsc +17 -0
  108. package/packages/cache/node_modules/.bin/tsserver +17 -0
  109. package/packages/cache/node_modules/.bin/tsup +17 -0
  110. package/packages/cache/node_modules/.bin/tsup-node +17 -0
  111. package/packages/cache/node_modules/.bin/tsx +17 -0
  112. package/packages/cache/node_modules/.bin/vitest +17 -0
  113. package/packages/cache/package.json +48 -0
  114. package/packages/cache/src/client/index.ts +56 -0
  115. package/packages/cache/src/errors/index.ts +53 -0
  116. package/packages/cache/src/index.ts +3 -0
  117. package/packages/cache/src/service/index.test.ts +263 -0
  118. package/packages/cache/src/service/index.ts +678 -0
  119. package/packages/cache/tsconfig.json +13 -0
  120. package/packages/cache/tsup.config.ts +13 -0
  121. package/packages/cache/vitest.config.ts +16 -0
  122. package/packages/config/.turbo/turbo-build.log +18 -0
  123. package/packages/config/dist/index.cjs +1037 -0
  124. package/packages/config/dist/index.cjs.map +1 -0
  125. package/packages/config/dist/index.d.ts +131 -0
  126. package/packages/config/node_modules/.bin/jiti +17 -0
  127. package/packages/config/node_modules/.bin/tsc +17 -0
  128. package/packages/config/node_modules/.bin/tsserver +17 -0
  129. package/packages/config/node_modules/.bin/tsup +17 -0
  130. package/packages/config/node_modules/.bin/tsup-node +17 -0
  131. package/packages/config/node_modules/.bin/tsx +17 -0
  132. package/packages/config/package.json +21 -0
  133. package/packages/config/src/index.js +1 -0
  134. package/packages/config/src/index.ts +1282 -0
  135. package/packages/config/tsconfig.json +4 -0
  136. package/packages/rpc/.turbo/turbo-build.log +32 -0
  137. package/packages/rpc/dist/_esm-BCLXDO2R.cjs +3660 -0
  138. package/packages/rpc/dist/_esm-BCLXDO2R.cjs.map +1 -0
  139. package/packages/rpc/dist/ccip-OWJLAW55.cjs +16 -0
  140. package/packages/rpc/dist/ccip-OWJLAW55.cjs.map +1 -0
  141. package/packages/rpc/dist/chunk-APQIFZ3B.cjs +6247 -0
  142. package/packages/rpc/dist/chunk-APQIFZ3B.cjs.map +1 -0
  143. package/packages/rpc/dist/chunk-CDO2GWRD.cjs +410 -0
  144. package/packages/rpc/dist/chunk-CDO2GWRD.cjs.map +1 -0
  145. package/packages/rpc/dist/chunk-QGTNTFJ7.cjs +2249 -0
  146. package/packages/rpc/dist/chunk-QGTNTFJ7.cjs.map +1 -0
  147. package/packages/rpc/dist/chunk-TZDTAHWR.cjs +44 -0
  148. package/packages/rpc/dist/chunk-TZDTAHWR.cjs.map +1 -0
  149. package/packages/rpc/dist/index.cjs +7342 -0
  150. package/packages/rpc/dist/index.cjs.map +1 -0
  151. package/packages/rpc/dist/index.d.ts +3857 -0
  152. package/packages/rpc/dist/secp256k1-WCNM675D.cjs +18 -0
  153. package/packages/rpc/dist/secp256k1-WCNM675D.cjs.map +1 -0
  154. package/packages/rpc/node_modules/.bin/jiti +17 -0
  155. package/packages/rpc/node_modules/.bin/tsc +17 -0
  156. package/packages/rpc/node_modules/.bin/tsserver +17 -0
  157. package/packages/rpc/node_modules/.bin/tsup +17 -0
  158. package/packages/rpc/node_modules/.bin/tsup-node +17 -0
  159. package/packages/rpc/node_modules/.bin/tsx +17 -0
  160. package/packages/rpc/package.json +25 -0
  161. package/packages/rpc/src/index.ts +206 -0
  162. package/packages/rpc/tsconfig.json +4 -0
  163. package/packages/typescript/base.json +36 -0
  164. package/packages/typescript/nextjs.json +17 -0
  165. package/packages/typescript/package.json +10 -0
  166. package/packages/ui/.turbo/turbo-build.log +44 -0
  167. package/packages/ui/dist/chunk-MOAFBKSA.js +11 -0
  168. package/packages/ui/dist/chunk-MOAFBKSA.js.map +1 -0
  169. package/packages/ui/dist/components/badge.d.ts +12 -0
  170. package/packages/ui/dist/components/badge.js +31 -0
  171. package/packages/ui/dist/components/badge.js.map +1 -0
  172. package/packages/ui/dist/components/button.d.ts +13 -0
  173. package/packages/ui/dist/components/button.js +40 -0
  174. package/packages/ui/dist/components/button.js.map +1 -0
  175. package/packages/ui/dist/components/card.d.ts +10 -0
  176. package/packages/ui/dist/components/card.js +39 -0
  177. package/packages/ui/dist/components/card.js.map +1 -0
  178. package/packages/ui/dist/components/input.d.ts +5 -0
  179. package/packages/ui/dist/components/input.js +28 -0
  180. package/packages/ui/dist/components/input.js.map +1 -0
  181. package/packages/ui/dist/components/label.d.ts +5 -0
  182. package/packages/ui/dist/components/label.js +13 -0
  183. package/packages/ui/dist/components/label.js.map +1 -0
  184. package/packages/ui/dist/components/separator.d.ts +5 -0
  185. package/packages/ui/dist/components/separator.js +13 -0
  186. package/packages/ui/dist/components/separator.js.map +1 -0
  187. package/packages/ui/dist/components/textarea.d.ts +5 -0
  188. package/packages/ui/dist/components/textarea.js +27 -0
  189. package/packages/ui/dist/components/textarea.js.map +1 -0
  190. package/packages/ui/dist/tailwind.d.ts +56 -0
  191. package/packages/ui/dist/tailwind.js +60 -0
  192. package/packages/ui/dist/tailwind.js.map +1 -0
  193. package/packages/ui/dist/utils/cn.d.ts +5 -0
  194. package/packages/ui/dist/utils/cn.js +7 -0
  195. package/packages/ui/dist/utils/cn.js.map +1 -0
  196. package/packages/ui/node_modules/.bin/jiti +17 -0
  197. package/packages/ui/node_modules/.bin/tsc +17 -0
  198. package/packages/ui/node_modules/.bin/tsserver +17 -0
  199. package/packages/ui/node_modules/.bin/tsup +17 -0
  200. package/packages/ui/node_modules/.bin/tsup-node +17 -0
  201. package/packages/ui/node_modules/.bin/tsx +17 -0
  202. package/packages/ui/package.json +69 -0
  203. package/packages/ui/src/components/badge.tsx +27 -0
  204. package/packages/ui/src/components/button.tsx +40 -0
  205. package/packages/ui/src/components/card.tsx +31 -0
  206. package/packages/ui/src/components/input.tsx +21 -0
  207. package/packages/ui/src/components/label.tsx +6 -0
  208. package/packages/ui/src/components/separator.tsx +6 -0
  209. package/packages/ui/src/components/textarea.tsx +20 -0
  210. package/packages/ui/src/globals.css +70 -0
  211. package/packages/ui/src/tailwind.ts +56 -0
  212. package/packages/ui/src/utils/cn.ts +6 -0
  213. package/packages/ui/tsconfig.json +20 -0
  214. package/packages/ui/tsup.config.ts +20 -0
  215. package/pnpm-workspace.yaml +4 -0
  216. package/scripts/install-rust-binaries.mjs +84 -0
  217. package/scripts/launchd/install-user-daemon.sh +358 -0
  218. package/scripts/launchd/run-vault-daemon.sh +5 -0
  219. package/scripts/launchd/run-wlfi-agent-daemon.sh +73 -0
  220. package/scripts/launchd/uninstall-user-daemon.sh +103 -0
  221. package/src/cli.ts +2121 -0
  222. package/src/lib/admin-guard.js +1 -0
  223. package/src/lib/admin-guard.ts +185 -0
  224. package/src/lib/admin-passthrough.ts +33 -0
  225. package/src/lib/admin-reset.ts +751 -0
  226. package/src/lib/admin-setup.ts +1612 -0
  227. package/src/lib/agent-auth-clear.js +1 -0
  228. package/src/lib/agent-auth-clear.ts +58 -0
  229. package/src/lib/agent-auth-forwarding.js +1 -0
  230. package/src/lib/agent-auth-forwarding.ts +149 -0
  231. package/src/lib/agent-auth-migrate.js +1 -0
  232. package/src/lib/agent-auth-migrate.ts +150 -0
  233. package/src/lib/agent-auth-revoke.ts +103 -0
  234. package/src/lib/agent-auth-rotate.ts +107 -0
  235. package/src/lib/agent-auth-token.js +1 -0
  236. package/src/lib/agent-auth-token.ts +25 -0
  237. package/src/lib/agent-auth.ts +89 -0
  238. package/src/lib/asset-broadcast.js +1 -0
  239. package/src/lib/asset-broadcast.ts +285 -0
  240. package/src/lib/bootstrap-artifacts.js +1 -0
  241. package/src/lib/bootstrap-artifacts.ts +205 -0
  242. package/src/lib/bootstrap-credentials.js +1 -0
  243. package/src/lib/bootstrap-credentials.ts +832 -0
  244. package/src/lib/config-amounts.js +1 -0
  245. package/src/lib/config-amounts.ts +189 -0
  246. package/src/lib/config-mutation.ts +27 -0
  247. package/src/lib/fs-trust.js +1 -0
  248. package/src/lib/fs-trust.ts +537 -0
  249. package/src/lib/keychain.js +1 -0
  250. package/src/lib/keychain.ts +225 -0
  251. package/src/lib/local-admin-access.ts +106 -0
  252. package/src/lib/network-selection.js +1 -0
  253. package/src/lib/network-selection.ts +71 -0
  254. package/src/lib/passthrough-security.js +1 -0
  255. package/src/lib/passthrough-security.ts +114 -0
  256. package/src/lib/rpc-guard.js +1 -0
  257. package/src/lib/rpc-guard.ts +7 -0
  258. package/src/lib/rust-spawn-options.js +1 -0
  259. package/src/lib/rust-spawn-options.ts +98 -0
  260. package/src/lib/rust.js +1 -0
  261. package/src/lib/rust.ts +143 -0
  262. package/src/lib/signed-tx.js +1 -0
  263. package/src/lib/signed-tx.ts +116 -0
  264. package/src/lib/status-repair-cli.ts +116 -0
  265. package/src/lib/sudo.js +1 -0
  266. package/src/lib/sudo.ts +172 -0
  267. package/src/lib/vault-password-forwarding.js +1 -0
  268. package/src/lib/vault-password-forwarding.ts +155 -0
  269. package/src/lib/wallet-profile.js +1 -0
  270. package/src/lib/wallet-profile.ts +332 -0
  271. package/src/lib/wallet-repair.js +1 -0
  272. package/src/lib/wallet-repair.ts +304 -0
  273. package/src/lib/wallet-setup.js +1 -0
  274. package/src/lib/wallet-setup.ts +1466 -0
  275. package/src/lib/wallet-status.js +1 -0
  276. package/src/lib/wallet-status.ts +640 -0
  277. package/tsconfig.base.json +17 -0
  278. package/tsconfig.json +10 -0
  279. package/tsup.config.ts +25 -0
  280. package/turbo.json +41 -0
  281. package/LICENSE.md +0 -1
  282. package/dist/wlfa/index.cjs +0 -250
  283. package/dist/wlfa/index.d.cts +0 -1
  284. package/dist/wlfa/index.d.ts +0 -1
  285. package/dist/wlfa/index.js +0 -250
  286. package/dist/wlfc/index.cjs +0 -1839
  287. package/dist/wlfc/index.d.cts +0 -1
  288. package/dist/wlfc/index.d.ts +0 -1
  289. package/dist/wlfc/index.js +0 -1839
package/package.json CHANGED
@@ -1,50 +1,54 @@
1
1
  {
2
- "dependencies": {
3
- "@inquirer/prompts": "8.2.0",
4
- "commander": "14.0.3",
5
- "@wlfi-agent/agent-wallet-sdk": "0.1.0"
6
- },
7
- "devDependencies": {
8
- "@types/node": "24.10.1",
9
- "tsup": "8.5.1",
10
- "typescript": "5.9.3",
11
- "tsx": "4.21.0",
12
- "@wlf/typescript": "1.1.4"
13
- },
2
+ "name": "@wlfi-agent/cli",
3
+ "version": "1.4.15",
4
+ "description": "Single-entrypoint WLFI agent CLI",
5
+ "type": "module",
14
6
  "bin": {
15
- "wlfa": "dist/wlfa/index.js",
16
- "wlfc": "dist/wlfc/index.js"
7
+ "wlfi-agent": "dist/cli.cjs"
17
8
  },
18
9
  "files": [
19
- "dist/wlfa",
20
- "dist/wlfc"
10
+ "dist",
11
+ "scripts",
12
+ "src",
13
+ "packages",
14
+ "crates",
15
+ "Cargo.toml",
16
+ "Cargo.lock",
17
+ "README.md",
18
+ "turbo.json",
19
+ "pnpm-workspace.yaml",
20
+ "tsconfig.base.json",
21
+ "tsconfig.json",
22
+ "tsup.config.ts"
21
23
  ],
22
- "exports": {
23
- "./wlfa": {
24
- "types": "./dist/wlfa/index.d.ts",
25
- "import": "./dist/wlfa/index.js",
26
- "require": "./dist/wlfa/index.cjs"
27
- },
28
- "./wlfc": {
29
- "types": "./dist/wlfc/index.d.ts",
30
- "import": "./dist/wlfc/index.js",
31
- "require": "./dist/wlfc/index.cjs"
32
- }
24
+ "workspaces": [
25
+ "packages/*",
26
+ "apps/*",
27
+ "apps/maintenance/*"
28
+ ],
29
+ "engines": {
30
+ "node": ">=20"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^24.0.0",
34
+ "commander": "^13.1.0",
35
+ "tsup": "^8.4.0",
36
+ "turbo": "^2.4.4",
37
+ "typescript": "^5.8.2",
38
+ "viem": "^2.37.5",
39
+ "@biomejs/biome": "^2.3.11",
40
+ "tsx": "^4.21.0",
41
+ "@wlfi-agent/config": "0.1.0",
42
+ "@wlfi-agent/rpc": "0.1.0"
33
43
  },
34
- "name": "@wlfi-agent/cli",
35
- "private": false,
36
- "type": "module",
37
- "version": "1.4.13",
38
44
  "scripts": {
39
- "build": "tsup",
40
- "clean": "rm -rf .turbo node_modules dist",
41
- "dev": "tsup --watch",
42
- "lint": "biome check",
43
- "lint:ci": "biome ci",
44
- "lint:fix": "biome check --write",
45
- "tenderly:mine-block": "tsx ./src/tenderly/mine-block.ts",
46
- "wlfa": "tsx ./src/wlfa/index.ts",
47
- "wlfc": "tsx ./src/wlfc/index.ts",
48
- "typecheck": "tsc --noEmit"
45
+ "build": "turbo run build && tsup --config tsup.config.ts",
46
+ "check": "turbo run check typecheck && cargo test --workspace --no-run",
47
+ "install:rust-binaries": "node ./scripts/install-rust-binaries.mjs",
48
+ "postinstall": "node ./scripts/install-rust-binaries.mjs",
49
+ "test:ts": "node --experimental-strip-types --test test/**/*.test.mjs",
50
+ "lint": "biome check .",
51
+ "lint:fix": "biome check --write .",
52
+ "typecheck": "turbo run typecheck && tsc --noEmit"
49
53
  }
50
54
  }
@@ -0,0 +1,52 @@
1
+
2
+ > @wlfi-agent/cache@0.0.0 build /Users/hanzhi/Documents/WLFI/wlfi-agent-sdk/packages/cache
3
+ > tsup
4
+
5
+ CLI Building entry: src/index.ts, src/client/index.ts, src/errors/index.ts, src/service/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Using tsup config: /Users/hanzhi/Documents/WLFI/wlfi-agent-sdk/packages/cache/tsup.config.ts
9
+ CLI Target: node20
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ ESM dist/index.js 566.00 B
14
+ ESM dist/chunk-FGJEEF5N.js 14.18 KB
15
+ ESM dist/client/index.js 201.00 B
16
+ ESM dist/errors/index.js 181.00 B
17
+ ESM dist/service/index.js 337.00 B
18
+ ESM dist/chunk-4U63TZTQ.js 1.06 KB
19
+ ESM dist/chunk-VXVMPG3W.js 1.27 KB
20
+ ESM dist/client/index.js.map 71.00 B
21
+ ESM dist/service/index.js.map 71.00 B
22
+ ESM dist/chunk-VXVMPG3W.js.map 2.50 KB
23
+ ESM dist/index.js.map 71.00 B
24
+ ESM dist/chunk-4U63TZTQ.js.map 2.10 KB
25
+ ESM dist/chunk-FGJEEF5N.js.map 30.74 KB
26
+ ESM dist/errors/index.js.map 71.00 B
27
+ ESM ⚡️ Build success in 79ms
28
+ CJS dist/client/index.cjs 360.00 B
29
+ CJS dist/index.cjs 940.00 B
30
+ CJS dist/chunk-ALQ6H7KG.cjs 16.64 KB
31
+ CJS dist/chunk-UYNEHZHB.cjs 2.60 KB
32
+ CJS dist/errors/index.cjs 340.00 B
33
+ CJS dist/chunk-2QFWMUXT.cjs 1.16 KB
34
+ CJS dist/service/index.cjs 527.00 B
35
+ CJS dist/client/index.cjs.map 286.00 B
36
+ CJS dist/index.cjs.map 379.00 B
37
+ CJS dist/chunk-2QFWMUXT.cjs.map 2.74 KB
38
+ CJS dist/errors/index.cjs.map 286.00 B
39
+ CJS dist/chunk-ALQ6H7KG.cjs.map 35.69 KB
40
+ CJS dist/service/index.cjs.map 324.00 B
41
+ CJS dist/chunk-UYNEHZHB.cjs.map 2.61 KB
42
+ CJS ⚡️ Build success in 80ms
43
+ DTS Build start
44
+ DTS ⚡️ Build success in 1310ms
45
+ DTS dist/index.d.ts 761.00 B
46
+ DTS dist/client/index.d.ts 527.00 B
47
+ DTS dist/errors/index.d.ts 833.00 B
48
+ DTS dist/service/index.d.ts 6.68 KB
49
+ DTS dist/index.d.cts 764.00 B
50
+ DTS dist/client/index.d.cts 527.00 B
51
+ DTS dist/errors/index.d.cts 833.00 B
52
+ DTS dist/service/index.d.cts 6.68 KB
@@ -0,0 +1,43 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/errors/index.ts
2
+ var cacheErrorCodes = {
3
+ connectionFailed: "CACHE_CONNECTION_FAILED",
4
+ invalidPayload: "CACHE_INVALID_PAYLOAD",
5
+ notFound: "CACHE_NOT_FOUND",
6
+ unknown: "CACHE_UNKNOWN"
7
+ };
8
+ var CacheError = class extends Error {
9
+
10
+
11
+
12
+
13
+ constructor(options) {
14
+ super(options.message);
15
+ this.name = "CacheError";
16
+ this.code = options.code;
17
+ this.key = options.key;
18
+ this.operation = options.operation;
19
+ this.cause = options.cause;
20
+ }
21
+ };
22
+ var toCacheError = (error, context = {}) => {
23
+ if (error instanceof CacheError) {
24
+ return error;
25
+ }
26
+ const message = error instanceof Error ? error.message : "Unknown cache error";
27
+ const normalizedMessage = message.toLowerCase();
28
+ const code = normalizedMessage.includes("connect") ? cacheErrorCodes.connectionFailed : cacheErrorCodes.unknown;
29
+ return new CacheError({
30
+ cause: error,
31
+ code,
32
+ key: context.key,
33
+ message,
34
+ operation: context.operation
35
+ });
36
+ };
37
+
38
+
39
+
40
+
41
+
42
+ exports.cacheErrorCodes = cacheErrorCodes; exports.CacheError = CacheError; exports.toCacheError = toCacheError;
43
+ //# sourceMappingURL=chunk-2QFWMUXT.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/hanzhi/Documents/WLFI/wlfi-agent-sdk/packages/cache/dist/chunk-2QFWMUXT.cjs","../src/errors/index.ts"],"names":[],"mappings":"AAAA;ACAO,IAAM,gBAAA,EAAkB;AAAA,EAC7B,gBAAA,EAAkB,yBAAA;AAAA,EAClB,cAAA,EAAgB,uBAAA;AAAA,EAChB,QAAA,EAAU,iBAAA;AAAA,EACV,OAAA,EAAS;AACX,CAAA;AAIO,IAAM,WAAA,EAAN,MAAA,QAAyB,MAAM;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACS;AAAA,EAElB,WAAA,CAAY,OAAA,EAMT;AACD,IAAA,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA;AACrB,IAAA,IAAA,CAAK,KAAA,EAAO,YAAA;AACZ,IAAA,IAAA,CAAK,KAAA,EAAO,OAAA,CAAQ,IAAA;AACpB,IAAA,IAAA,CAAK,IAAA,EAAM,OAAA,CAAQ,GAAA;AACnB,IAAA,IAAA,CAAK,UAAA,EAAY,OAAA,CAAQ,SAAA;AACzB,IAAA,IAAA,CAAK,MAAA,EAAQ,OAAA,CAAQ,KAAA;AAAA,EACvB;AACF,CAAA;AAEO,IAAM,aAAA,EAAe,CAC1B,KAAA,EACA,QAAA,EAAgD,CAAC,CAAA,EAAA,GAClC;AACf,EAAA,GAAA,CAAI,MAAA,WAAiB,UAAA,EAAY;AAC/B,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAA,EAAU,MAAA,WAAiB,MAAA,EAAQ,KAAA,CAAM,QAAA,EAAU,qBAAA;AACzD,EAAA,MAAM,kBAAA,EAAoB,OAAA,CAAQ,WAAA,CAAY,CAAA;AAC9C,EAAA,MAAM,KAAA,EAAO,iBAAA,CAAkB,QAAA,CAAS,SAAS,EAAA,EAC7C,eAAA,CAAgB,iBAAA,EAChB,eAAA,CAAgB,OAAA;AAEpB,EAAA,OAAO,IAAI,UAAA,CAAW;AAAA,IACpB,KAAA,EAAO,KAAA;AAAA,IACP,IAAA;AAAA,IACA,GAAA,EAAK,OAAA,CAAQ,GAAA;AAAA,IACb,OAAA;AAAA,IACA,SAAA,EAAW,OAAA,CAAQ;AAAA,EACrB,CAAC,CAAA;AACH,CAAA;ADhBA;AACA;AACE;AACA;AACA;AACF,gHAAC","file":"/Users/hanzhi/Documents/WLFI/wlfi-agent-sdk/packages/cache/dist/chunk-2QFWMUXT.cjs","sourcesContent":[null,"export const cacheErrorCodes = {\n connectionFailed: 'CACHE_CONNECTION_FAILED',\n invalidPayload: 'CACHE_INVALID_PAYLOAD',\n notFound: 'CACHE_NOT_FOUND',\n unknown: 'CACHE_UNKNOWN',\n} as const;\n\nexport type CacheErrorCode = (typeof cacheErrorCodes)[keyof typeof cacheErrorCodes];\n\nexport class CacheError extends Error {\n readonly code: CacheErrorCode;\n readonly key?: string;\n readonly operation?: string;\n override readonly cause?: unknown;\n\n constructor(options: {\n cause?: unknown;\n code: CacheErrorCode;\n key?: string;\n message: string;\n operation?: string;\n }) {\n super(options.message);\n this.name = 'CacheError';\n this.code = options.code;\n this.key = options.key;\n this.operation = options.operation;\n this.cause = options.cause;\n }\n}\n\nexport const toCacheError = (\n error: unknown,\n context: { key?: string; operation?: string } = {},\n): CacheError => {\n if (error instanceof CacheError) {\n return error;\n }\n\n const message = error instanceof Error ? error.message : 'Unknown cache error';\n const normalizedMessage = message.toLowerCase();\n const code = normalizedMessage.includes('connect')\n ? cacheErrorCodes.connectionFailed\n : cacheErrorCodes.unknown;\n\n return new CacheError({\n cause: error,\n code,\n key: context.key,\n message,\n operation: context.operation,\n });\n};\n"]}
@@ -0,0 +1,43 @@
1
+ // src/errors/index.ts
2
+ var cacheErrorCodes = {
3
+ connectionFailed: "CACHE_CONNECTION_FAILED",
4
+ invalidPayload: "CACHE_INVALID_PAYLOAD",
5
+ notFound: "CACHE_NOT_FOUND",
6
+ unknown: "CACHE_UNKNOWN"
7
+ };
8
+ var CacheError = class extends Error {
9
+ code;
10
+ key;
11
+ operation;
12
+ cause;
13
+ constructor(options) {
14
+ super(options.message);
15
+ this.name = "CacheError";
16
+ this.code = options.code;
17
+ this.key = options.key;
18
+ this.operation = options.operation;
19
+ this.cause = options.cause;
20
+ }
21
+ };
22
+ var toCacheError = (error, context = {}) => {
23
+ if (error instanceof CacheError) {
24
+ return error;
25
+ }
26
+ const message = error instanceof Error ? error.message : "Unknown cache error";
27
+ const normalizedMessage = message.toLowerCase();
28
+ const code = normalizedMessage.includes("connect") ? cacheErrorCodes.connectionFailed : cacheErrorCodes.unknown;
29
+ return new CacheError({
30
+ cause: error,
31
+ code,
32
+ key: context.key,
33
+ message,
34
+ operation: context.operation
35
+ });
36
+ };
37
+
38
+ export {
39
+ cacheErrorCodes,
40
+ CacheError,
41
+ toCacheError
42
+ };
43
+ //# sourceMappingURL=chunk-4U63TZTQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors/index.ts"],"sourcesContent":["export const cacheErrorCodes = {\n connectionFailed: 'CACHE_CONNECTION_FAILED',\n invalidPayload: 'CACHE_INVALID_PAYLOAD',\n notFound: 'CACHE_NOT_FOUND',\n unknown: 'CACHE_UNKNOWN',\n} as const;\n\nexport type CacheErrorCode = (typeof cacheErrorCodes)[keyof typeof cacheErrorCodes];\n\nexport class CacheError extends Error {\n readonly code: CacheErrorCode;\n readonly key?: string;\n readonly operation?: string;\n override readonly cause?: unknown;\n\n constructor(options: {\n cause?: unknown;\n code: CacheErrorCode;\n key?: string;\n message: string;\n operation?: string;\n }) {\n super(options.message);\n this.name = 'CacheError';\n this.code = options.code;\n this.key = options.key;\n this.operation = options.operation;\n this.cause = options.cause;\n }\n}\n\nexport const toCacheError = (\n error: unknown,\n context: { key?: string; operation?: string } = {},\n): CacheError => {\n if (error instanceof CacheError) {\n return error;\n }\n\n const message = error instanceof Error ? error.message : 'Unknown cache error';\n const normalizedMessage = message.toLowerCase();\n const code = normalizedMessage.includes('connect')\n ? cacheErrorCodes.connectionFailed\n : cacheErrorCodes.unknown;\n\n return new CacheError({\n cause: error,\n code,\n key: context.key,\n message,\n operation: context.operation,\n });\n};\n"],"mappings":";AAAO,IAAM,kBAAkB;AAAA,EAC7B,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,SAAS;AACX;AAIO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACS;AAAA,EAElB,YAAY,SAMT;AACD,UAAM,QAAQ,OAAO;AACrB,SAAK,OAAO;AACZ,SAAK,OAAO,QAAQ;AACpB,SAAK,MAAM,QAAQ;AACnB,SAAK,YAAY,QAAQ;AACzB,SAAK,QAAQ,QAAQ;AAAA,EACvB;AACF;AAEO,IAAM,eAAe,CAC1B,OACA,UAAgD,CAAC,MAClC;AACf,MAAI,iBAAiB,YAAY;AAC/B,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;AACzD,QAAM,oBAAoB,QAAQ,YAAY;AAC9C,QAAM,OAAO,kBAAkB,SAAS,SAAS,IAC7C,gBAAgB,mBAChB,gBAAgB;AAEpB,SAAO,IAAI,WAAW;AAAA,IACpB,OAAO;AAAA,IACP;AAAA,IACA,KAAK,QAAQ;AAAA,IACb;AAAA,IACA,WAAW,QAAQ;AAAA,EACrB,CAAC;AACH;","names":[]}
@@ -0,0 +1,404 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
+
3
+ var _chunkUYNEHZHBcjs = require('./chunk-UYNEHZHB.cjs');
4
+
5
+
6
+
7
+
8
+ var _chunk2QFWMUXTcjs = require('./chunk-2QFWMUXT.cjs');
9
+
10
+ // src/service/index.ts
11
+ var _crypto = require('crypto');
12
+ var relayApprovalStatuses = [
13
+ "pending",
14
+ "approved",
15
+ "rejected",
16
+ "completed",
17
+ "expired"
18
+ ];
19
+ var relayUpdateStatuses = [
20
+ "pending",
21
+ "inflight",
22
+ "applied",
23
+ "rejected",
24
+ "failed"
25
+ ];
26
+ var defaultNamespace = "wlfi:relay";
27
+ var activeApprovalUpdateScanLimit = 250;
28
+ var approvalCapabilityFailureWindowMs = 5 * 60 * 1e3;
29
+ var approvalCapabilityMaxFailures = 5;
30
+ var approvalCapabilityBlockWindowMs = 10 * 60 * 1e3;
31
+ var toIsoTimestamp = (value = /* @__PURE__ */ new Date()) => value.toISOString();
32
+ var dedupe = (values) => [...new Set(values)];
33
+ var matchesOptionalFilter = (value, expected) => {
34
+ if (!expected) {
35
+ return true;
36
+ }
37
+ return _optionalChain([value, 'optionalAccess', _ => _.toLowerCase, 'call', _2 => _2()]) === expected.toLowerCase();
38
+ };
39
+ var clampLimit = (limit, fallback, max) => {
40
+ if (!limit || Number.isNaN(limit)) {
41
+ return fallback;
42
+ }
43
+ return Math.max(1, Math.min(limit, max));
44
+ };
45
+ var createApprovalCapabilityToken = () => _crypto.randomBytes.call(void 0, 32).toString("hex");
46
+ var approvalCapabilityHash = (token) => _crypto.createHash.call(void 0, "sha256").update(token, "utf8").digest("hex");
47
+ var RelayCacheService = (_class = class {
48
+
49
+
50
+ constructor(options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);_class.prototype.__init9.call(this);_class.prototype.__init10.call(this);
51
+ this.client = _nullishCoalesce(options.client, () => ( _chunkUYNEHZHBcjs.getCacheClient.call(void 0, )));
52
+ this.namespace = _nullishCoalesce(options.namespace, () => ( defaultNamespace));
53
+ }
54
+ async ping() {
55
+ try {
56
+ return await this.client.ping();
57
+ } catch (error) {
58
+ throw _chunk2QFWMUXTcjs.toCacheError.call(void 0, error, { operation: "ping" });
59
+ }
60
+ }
61
+ async syncDaemonRegistration(input) {
62
+ const profile = {
63
+ ...input.daemon,
64
+ lastSeenAt: input.daemon.lastSeenAt || toIsoTimestamp(),
65
+ updatedAt: input.daemon.updatedAt || toIsoTimestamp()
66
+ };
67
+ try {
68
+ await this.writeJson(this.daemonProfileKey(profile.daemonId), profile);
69
+ await this.client.sadd(this.daemonIndexKey(), profile.daemonId);
70
+ if (input.policies) {
71
+ const policies = input.policies.map((policy) => ({
72
+ ...policy,
73
+ daemonId: profile.daemonId
74
+ }));
75
+ await this.writeJson(this.daemonPoliciesKey(profile.daemonId), policies);
76
+ }
77
+ if (input.agentKeys) {
78
+ const agentKeys = input.agentKeys.map((agentKey) => ({
79
+ ...agentKey,
80
+ daemonId: profile.daemonId
81
+ }));
82
+ await this.writeJson(this.daemonAgentKeysKey(profile.daemonId), agentKeys);
83
+ }
84
+ if (input.approvalRequests) {
85
+ for (const approvalRequest of input.approvalRequests) {
86
+ const normalized = { ...approvalRequest, daemonId: profile.daemonId };
87
+ await this.writeJson(this.approvalKey(normalized.approvalRequestId), normalized);
88
+ await this.client.zadd(
89
+ this.daemonApprovalsKey(profile.daemonId),
90
+ Date.parse(normalized.requestedAt),
91
+ normalized.approvalRequestId
92
+ );
93
+ }
94
+ }
95
+ return {
96
+ agentKeyCount: _nullishCoalesce(_optionalChain([input, 'access', _3 => _3.agentKeys, 'optionalAccess', _4 => _4.length]), () => ( 0)),
97
+ approvalRequestCount: _nullishCoalesce(_optionalChain([input, 'access', _5 => _5.approvalRequests, 'optionalAccess', _6 => _6.length]), () => ( 0)),
98
+ policyCount: _nullishCoalesce(_optionalChain([input, 'access', _7 => _7.policies, 'optionalAccess', _8 => _8.length]), () => ( 0))
99
+ };
100
+ } catch (error) {
101
+ throw _chunk2QFWMUXTcjs.toCacheError.call(void 0, error, {
102
+ key: this.daemonProfileKey(profile.daemonId),
103
+ operation: "syncDaemonRegistration"
104
+ });
105
+ }
106
+ }
107
+ async listDaemons() {
108
+ const daemonIds = await this.client.smembers(this.daemonIndexKey());
109
+ const profiles = await Promise.all(
110
+ daemonIds.map(
111
+ (daemonId) => this.readJson(this.daemonProfileKey(daemonId))
112
+ )
113
+ );
114
+ return profiles.filter((profile) => Boolean(profile));
115
+ }
116
+ async getDaemonProfile(daemonId) {
117
+ return await this.readJson(this.daemonProfileKey(daemonId));
118
+ }
119
+ async getDaemonPolicies(daemonId) {
120
+ return await _asyncNullishCoalesce(await this.readJson(this.daemonPoliciesKey(daemonId)), async () => ( []));
121
+ }
122
+ async getDaemonAgentKeys(daemonId) {
123
+ return await _asyncNullishCoalesce(await this.readJson(this.daemonAgentKeysKey(daemonId)), async () => ( []));
124
+ }
125
+ async getApprovalRequest(approvalRequestId) {
126
+ return await this.readJson(this.approvalKey(approvalRequestId));
127
+ }
128
+ async listApprovalRequests(filters = {}) {
129
+ const limit = clampLimit(filters.limit, 100, 500);
130
+ const daemonIds = filters.daemonId ? [filters.daemonId] : await this.client.smembers(this.daemonIndexKey());
131
+ const requestIdsByDaemon = await Promise.all(
132
+ daemonIds.map(
133
+ (daemonId) => this.client.zrange(this.daemonApprovalsKey(daemonId), 0, limit * 2, "REV")
134
+ )
135
+ );
136
+ const requestIds = dedupe(requestIdsByDaemon.flat()).slice(0, limit * 3);
137
+ const requests = await Promise.all(
138
+ requestIds.map(
139
+ (requestId) => this.readJson(this.approvalKey(requestId))
140
+ )
141
+ );
142
+ return requests.filter((request) => Boolean(request)).filter((request) => filters.daemonId ? request.daemonId === filters.daemonId : true).filter((request) => filters.status ? request.status === filters.status : true).filter((request) => matchesOptionalFilter(request.destination, filters.destination)).filter((request) => matchesOptionalFilter(request.tokenAddress, filters.tokenAddress)).sort((left, right) => Date.parse(right.requestedAt) - Date.parse(left.requestedAt)).slice(0, limit);
143
+ }
144
+ async createEncryptedUpdate(input) {
145
+ const updateId = _nullishCoalesce(input.updateId, () => ( _crypto.randomUUID.call(void 0, )));
146
+ const now = toIsoTimestamp();
147
+ const record = {
148
+ createdAt: now,
149
+ daemonId: input.daemonId,
150
+ metadata: input.metadata,
151
+ payload: input.payload,
152
+ status: "pending",
153
+ targetApprovalRequestId: input.targetApprovalRequestId,
154
+ type: input.type,
155
+ updateId,
156
+ updatedAt: now
157
+ };
158
+ await this.writeJson(this.updateKey(updateId), record);
159
+ await this.client.zadd(this.daemonUpdatesKey(input.daemonId), Date.now(), updateId);
160
+ return record;
161
+ }
162
+ async hasActiveApprovalUpdate(daemonId, approvalRequestId) {
163
+ const updateIds = await this.client.zrange(
164
+ this.daemonUpdatesKey(daemonId),
165
+ 0,
166
+ activeApprovalUpdateScanLimit,
167
+ "REV"
168
+ );
169
+ for (const updateId of updateIds) {
170
+ const record = await this.readJson(this.updateKey(updateId));
171
+ if (!record) {
172
+ continue;
173
+ }
174
+ if (record.type !== "manual_approval_decision" || record.targetApprovalRequestId !== approvalRequestId) {
175
+ continue;
176
+ }
177
+ if (record.status === "pending" || record.status === "inflight") {
178
+ return true;
179
+ }
180
+ }
181
+ return false;
182
+ }
183
+ async consumeApprovalCapability(approvalRequestId, capabilityHash) {
184
+ try {
185
+ const result = await this.client.set(
186
+ this.approvalCapabilityConsumedKey(approvalRequestId, capabilityHash),
187
+ toIsoTimestamp(),
188
+ "NX"
189
+ );
190
+ return result === "OK";
191
+ } catch (error) {
192
+ throw _chunk2QFWMUXTcjs.toCacheError.call(void 0, error, {
193
+ key: this.approvalCapabilityConsumedKey(approvalRequestId, capabilityHash),
194
+ operation: "consumeApprovalCapability"
195
+ });
196
+ }
197
+ }
198
+ async releaseApprovalCapabilityConsumption(approvalRequestId, capabilityHash) {
199
+ try {
200
+ await this.client.del(this.approvalCapabilityConsumedKey(approvalRequestId, capabilityHash));
201
+ } catch (error) {
202
+ throw _chunk2QFWMUXTcjs.toCacheError.call(void 0, error, {
203
+ key: this.approvalCapabilityConsumedKey(approvalRequestId, capabilityHash),
204
+ operation: "releaseApprovalCapabilityConsumption"
205
+ });
206
+ }
207
+ }
208
+ async clearApprovalCapabilityFailures(approvalRequestId) {
209
+ try {
210
+ await this.client.del(this.approvalCapabilityFailuresKey(approvalRequestId));
211
+ } catch (error) {
212
+ throw _chunk2QFWMUXTcjs.toCacheError.call(void 0, error, {
213
+ key: this.approvalCapabilityFailuresKey(approvalRequestId),
214
+ operation: "clearApprovalCapabilityFailures"
215
+ });
216
+ }
217
+ }
218
+ async recordApprovalCapabilityFailure(approvalRequestId) {
219
+ const key = this.approvalCapabilityFailuresKey(approvalRequestId);
220
+ const now = /* @__PURE__ */ new Date();
221
+ const nowMs = now.getTime();
222
+ const existing = await this.readJson(key);
223
+ if (_optionalChain([existing, 'optionalAccess', _9 => _9.blockedUntil]) && Date.parse(existing.blockedUntil) > nowMs) {
224
+ return {
225
+ attempts: existing.attempts,
226
+ blocked: true,
227
+ blockedUntil: existing.blockedUntil
228
+ };
229
+ }
230
+ const firstFailedAtMs = _optionalChain([existing, 'optionalAccess', _10 => _10.firstFailedAt]) ? Date.parse(existing.firstFailedAt) : Number.NaN;
231
+ const withinWindow = Number.isFinite(firstFailedAtMs) && nowMs - firstFailedAtMs <= approvalCapabilityFailureWindowMs;
232
+ const attempts = withinWindow && existing ? existing.attempts + 1 : 1;
233
+ const firstFailedAt = withinWindow && existing ? existing.firstFailedAt : now.toISOString();
234
+ const blockedUntil = attempts >= approvalCapabilityMaxFailures ? new Date(nowMs + approvalCapabilityBlockWindowMs).toISOString() : void 0;
235
+ await this.writeJson(key, {
236
+ attempts,
237
+ blockedUntil,
238
+ firstFailedAt,
239
+ lastFailedAt: now.toISOString()
240
+ });
241
+ return {
242
+ attempts,
243
+ blocked: blockedUntil !== void 0,
244
+ blockedUntil: _nullishCoalesce(blockedUntil, () => ( null))
245
+ };
246
+ }
247
+ async rotateApprovalCapability(approvalRequestId) {
248
+ const key = this.approvalKey(approvalRequestId);
249
+ const approval = await this.readJson(key);
250
+ if (!approval) {
251
+ throw new (0, _chunk2QFWMUXTcjs.CacheError)({
252
+ code: _chunk2QFWMUXTcjs.cacheErrorCodes.notFound,
253
+ key,
254
+ message: `Unknown approval '${approvalRequestId}'`,
255
+ operation: "rotateApprovalCapability"
256
+ });
257
+ }
258
+ if (approval.status !== "pending") {
259
+ throw new (0, _chunk2QFWMUXTcjs.CacheError)({
260
+ code: _chunk2QFWMUXTcjs.cacheErrorCodes.invalidPayload,
261
+ key,
262
+ message: `Approval '${approvalRequestId}' is '${approval.status}' and cannot accept a new secure approval link`,
263
+ operation: "rotateApprovalCapability"
264
+ });
265
+ }
266
+ const capabilityToken = createApprovalCapabilityToken();
267
+ const nextRecord = {
268
+ ...approval,
269
+ metadata: {
270
+ ..._nullishCoalesce(approval.metadata, () => ( {})),
271
+ approvalCapabilityHash: approvalCapabilityHash(capabilityToken),
272
+ approvalCapabilityToken: capabilityToken
273
+ },
274
+ updatedAt: toIsoTimestamp()
275
+ };
276
+ await this.writeJson(key, nextRecord);
277
+ await this.clearApprovalCapabilityFailures(approvalRequestId);
278
+ return nextRecord;
279
+ }
280
+ async claimEncryptedUpdates(input) {
281
+ const limit = clampLimit(input.limit, 25, 100);
282
+ const leaseSeconds = clampLimit(input.leaseSeconds, 30, 300);
283
+ const now = /* @__PURE__ */ new Date();
284
+ const nowMs = now.getTime();
285
+ const claimUntil = new Date(nowMs + leaseSeconds * 1e3).toISOString();
286
+ const updateIds = await this.client.zrange(
287
+ this.daemonUpdatesKey(input.daemonId),
288
+ 0,
289
+ limit * 4,
290
+ "REV"
291
+ );
292
+ const claimed = [];
293
+ for (const updateId of updateIds) {
294
+ if (claimed.length >= limit) {
295
+ break;
296
+ }
297
+ const record = await this.readJson(this.updateKey(updateId));
298
+ if (!record) {
299
+ continue;
300
+ }
301
+ if (record.status === "applied" || record.status === "failed" || record.status === "rejected") {
302
+ continue;
303
+ }
304
+ if (record.status === "inflight" && record.claimUntil && Date.parse(record.claimUntil) > nowMs) {
305
+ continue;
306
+ }
307
+ const nextRecord = {
308
+ ...record,
309
+ claimToken: _crypto.randomUUID.call(void 0, ),
310
+ claimUntil,
311
+ lastDeliveredAt: now.toISOString(),
312
+ status: "inflight",
313
+ updatedAt: now.toISOString()
314
+ };
315
+ await this.writeJson(this.updateKey(updateId), nextRecord);
316
+ claimed.push(nextRecord);
317
+ }
318
+ return claimed;
319
+ }
320
+ async submitUpdateFeedback(input) {
321
+ const key = this.updateKey(input.updateId);
322
+ const record = await this.readJson(key);
323
+ if (!record || record.daemonId !== input.daemonId) {
324
+ throw new (0, _chunk2QFWMUXTcjs.CacheError)({
325
+ code: _chunk2QFWMUXTcjs.cacheErrorCodes.notFound,
326
+ key,
327
+ message: `Unknown update '${input.updateId}' for daemon '${input.daemonId}'`,
328
+ operation: "submitUpdateFeedback"
329
+ });
330
+ }
331
+ if (!record.claimToken || record.claimToken !== input.claimToken) {
332
+ throw new (0, _chunk2QFWMUXTcjs.CacheError)({
333
+ code: _chunk2QFWMUXTcjs.cacheErrorCodes.invalidPayload,
334
+ key,
335
+ message: `Claim token mismatch for update '${input.updateId}'`,
336
+ operation: "submitUpdateFeedback"
337
+ });
338
+ }
339
+ const feedback = {
340
+ daemonId: input.daemonId,
341
+ details: input.details,
342
+ feedbackAt: toIsoTimestamp(),
343
+ message: input.message,
344
+ status: input.status,
345
+ updateId: input.updateId
346
+ };
347
+ const nextRecord = {
348
+ ...record,
349
+ claimToken: void 0,
350
+ claimUntil: void 0,
351
+ feedback,
352
+ status: input.status,
353
+ updatedAt: toIsoTimestamp()
354
+ };
355
+ await this.writeJson(key, nextRecord);
356
+ return nextRecord;
357
+ }
358
+ async getEncryptedUpdate(updateId) {
359
+ return await this.readJson(this.updateKey(updateId));
360
+ }
361
+ async removeEncryptedUpdate(daemonId, updateId) {
362
+ await this.client.zrem(this.daemonUpdatesKey(daemonId), updateId);
363
+ await this.client.del(this.updateKey(updateId));
364
+ }
365
+ __init() {this.daemonIndexKey = () => `${this.namespace}:daemons`}
366
+ __init2() {this.daemonProfileKey = (daemonId) => `${this.namespace}:daemon:${daemonId}:profile`}
367
+ __init3() {this.daemonPoliciesKey = (daemonId) => `${this.namespace}:daemon:${daemonId}:policies`}
368
+ __init4() {this.daemonAgentKeysKey = (daemonId) => `${this.namespace}:daemon:${daemonId}:agent-keys`}
369
+ __init5() {this.daemonApprovalsKey = (daemonId) => `${this.namespace}:daemon:${daemonId}:approvals`}
370
+ __init6() {this.daemonUpdatesKey = (daemonId) => `${this.namespace}:daemon:${daemonId}:updates`}
371
+ __init7() {this.approvalKey = (approvalRequestId) => `${this.namespace}:approval:${approvalRequestId}`}
372
+ __init8() {this.approvalCapabilityConsumedKey = (approvalRequestId, capabilityHash) => `${this.namespace}:approval:${approvalRequestId}:capability:${capabilityHash}:consumed`}
373
+ __init9() {this.approvalCapabilityFailuresKey = (approvalRequestId) => `${this.namespace}:approval:${approvalRequestId}:capability-failures`}
374
+ __init10() {this.updateKey = (updateId) => `${this.namespace}:update:${updateId}`}
375
+ async readJson(key) {
376
+ try {
377
+ const payload = await this.client.get(key);
378
+ if (payload === null) {
379
+ return null;
380
+ }
381
+ return JSON.parse(payload);
382
+ } catch (error) {
383
+ throw _chunk2QFWMUXTcjs.toCacheError.call(void 0, error, { key, operation: "readJson" });
384
+ }
385
+ }
386
+ async writeJson(key, value) {
387
+ try {
388
+ await this.client.set(key, JSON.stringify(value));
389
+ } catch (error) {
390
+ throw _chunk2QFWMUXTcjs.toCacheError.call(void 0, error, { key, operation: "writeJson" });
391
+ }
392
+ }
393
+ }, _class);
394
+ var createRelayCacheService = (options = {}) => {
395
+ return new RelayCacheService(options);
396
+ };
397
+
398
+
399
+
400
+
401
+
402
+
403
+ exports.relayApprovalStatuses = relayApprovalStatuses; exports.relayUpdateStatuses = relayUpdateStatuses; exports.RelayCacheService = RelayCacheService; exports.createRelayCacheService = createRelayCacheService;
404
+ //# sourceMappingURL=chunk-ALQ6H7KG.cjs.map