rivetkit 2.1.5 → 2.1.6-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 (333) hide show
  1. package/dist/browser/client.d.ts +593 -588
  2. package/dist/browser/client.js +215 -35
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +109 -10
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/inspector.tar.gz +0 -0
  7. package/dist/tsup/actor/errors.cjs +2 -2
  8. package/dist/tsup/actor/errors.js +1 -1
  9. package/dist/tsup/{actor-router-consts-D29T1Z-K.d.cts → actor-router-consts-DU-1IdQj.d.cts} +1 -1
  10. package/dist/tsup/{actor-router-consts-D29T1Z-K.d.ts → actor-router-consts-DU-1IdQj.d.ts} +1 -1
  11. package/dist/tsup/chunk-2ELYUO6C.cjs +112 -0
  12. package/dist/tsup/chunk-2ELYUO6C.cjs.map +1 -0
  13. package/dist/tsup/chunk-2LY7RW3Y.cjs +2316 -0
  14. package/dist/tsup/chunk-2LY7RW3Y.cjs.map +1 -0
  15. package/dist/tsup/{chunk-L47L3ZWJ.cjs → chunk-6G7ZNM27.cjs} +11 -6
  16. package/dist/tsup/chunk-6G7ZNM27.cjs.map +1 -0
  17. package/dist/tsup/{chunk-PB5AEMKQ.cjs → chunk-A4KEUCB6.cjs} +84 -34
  18. package/dist/tsup/chunk-A4KEUCB6.cjs.map +1 -0
  19. package/dist/tsup/{chunk-7HTNH26M.js → chunk-AKUJ5OTO.js} +11 -6
  20. package/dist/tsup/chunk-AKUJ5OTO.js.map +1 -0
  21. package/dist/tsup/{chunk-TADUYCHF.js → chunk-C22JYHVT.js} +77 -27
  22. package/dist/tsup/chunk-C22JYHVT.js.map +1 -0
  23. package/dist/tsup/chunk-C4EB42ET.js +1459 -0
  24. package/dist/tsup/chunk-C4EB42ET.js.map +1 -0
  25. package/dist/tsup/chunk-CGGGBIDP.cjs +1459 -0
  26. package/dist/tsup/chunk-CGGGBIDP.cjs.map +1 -0
  27. package/dist/tsup/chunk-CMQPDBBR.cjs +1486 -0
  28. package/dist/tsup/chunk-CMQPDBBR.cjs.map +1 -0
  29. package/dist/tsup/{chunk-GQGRQDRL.cjs → chunk-DH6UINWA.cjs} +4 -4
  30. package/dist/tsup/{chunk-GQGRQDRL.cjs.map → chunk-DH6UINWA.cjs.map} +1 -1
  31. package/dist/tsup/chunk-DK46YYCJ.js +1486 -0
  32. package/dist/tsup/chunk-DK46YYCJ.js.map +1 -0
  33. package/dist/tsup/chunk-EGWXXBZV.js +2316 -0
  34. package/dist/tsup/chunk-EGWXXBZV.js.map +1 -0
  35. package/dist/tsup/{chunk-S662Y6ZU.js → chunk-EONWXYMN.js} +2 -2
  36. package/dist/tsup/{chunk-N4KRDJ56.js → chunk-GFGRBYO2.js} +35 -6
  37. package/dist/tsup/chunk-GFGRBYO2.js.map +1 -0
  38. package/dist/tsup/{chunk-IIJNPVPQ.cjs → chunk-GUHXWPGB.cjs} +1515 -1479
  39. package/dist/tsup/chunk-GUHXWPGB.cjs.map +1 -0
  40. package/dist/tsup/{chunk-TI5PXQGG.cjs → chunk-HNE2AK6C.cjs} +2375 -3713
  41. package/dist/tsup/chunk-HNE2AK6C.cjs.map +1 -0
  42. package/dist/tsup/{chunk-2OK7S6QF.js → chunk-I5I6OALK.js} +2 -2
  43. package/dist/tsup/chunk-IHQAF2HV.cjs +23 -0
  44. package/dist/tsup/chunk-IHQAF2HV.cjs.map +1 -0
  45. package/dist/tsup/{chunk-U5SMSA27.cjs → chunk-JJNZQDUN.cjs} +667 -2517
  46. package/dist/tsup/chunk-JJNZQDUN.cjs.map +1 -0
  47. package/dist/tsup/{chunk-ZPWOYQHN.js → chunk-JJSPHLJN.js} +219 -287
  48. package/dist/tsup/chunk-JJSPHLJN.js.map +1 -0
  49. package/dist/tsup/chunk-JRKPV5NJ.js +481 -0
  50. package/dist/tsup/chunk-JRKPV5NJ.js.map +1 -0
  51. package/dist/tsup/{chunk-VKVNIQRQ.js → chunk-K7MVU5SI.js} +36 -41
  52. package/dist/tsup/chunk-K7MVU5SI.js.map +1 -0
  53. package/dist/tsup/{chunk-KJSYAUOM.js → chunk-MLK3GY6P.js} +43 -27
  54. package/dist/tsup/chunk-MLK3GY6P.js.map +1 -0
  55. package/dist/tsup/{chunk-HYPIHCDT.cjs → chunk-MPLMTJY5.cjs} +123 -23
  56. package/dist/tsup/chunk-MPLMTJY5.cjs.map +1 -0
  57. package/dist/tsup/{chunk-MIX2KB6U.js → chunk-PQWI44WD.js} +1755 -3093
  58. package/dist/tsup/chunk-PQWI44WD.js.map +1 -0
  59. package/dist/tsup/{chunk-SR3KQE7Q.cjs → chunk-SQFCIDCG.cjs} +35 -6
  60. package/dist/tsup/chunk-SQFCIDCG.cjs.map +1 -0
  61. package/dist/tsup/{chunk-WY2SHWXQ.js → chunk-SVHJSM2E.js} +110 -24
  62. package/dist/tsup/chunk-SVHJSM2E.js.map +1 -0
  63. package/dist/tsup/chunk-T5KYKM6R.js +49 -0
  64. package/dist/tsup/chunk-T5KYKM6R.js.map +1 -0
  65. package/dist/tsup/{chunk-7WF2QSIC.cjs → chunk-TJ7DKW6F.cjs} +123 -37
  66. package/dist/tsup/chunk-TJ7DKW6F.cjs.map +1 -0
  67. package/dist/tsup/chunk-UQZRMTM3.js +23 -0
  68. package/dist/tsup/chunk-UQZRMTM3.js.map +1 -0
  69. package/dist/tsup/{chunk-JC6BEPE7.cjs → chunk-V3JSZR5P.cjs} +3 -3
  70. package/dist/tsup/{chunk-JC6BEPE7.cjs.map → chunk-V3JSZR5P.cjs.map} +1 -1
  71. package/dist/tsup/{chunk-OAXJWGMU.cjs → chunk-VBR35EQF.cjs} +271 -339
  72. package/dist/tsup/chunk-VBR35EQF.cjs.map +1 -0
  73. package/dist/tsup/{chunk-EIATSBYZ.js → chunk-VWYO36X4.js} +117 -17
  74. package/dist/tsup/chunk-VWYO36X4.js.map +1 -0
  75. package/dist/tsup/{chunk-JPXO2H55.js → chunk-WW27B6DM.js} +1452 -1416
  76. package/dist/tsup/chunk-WW27B6DM.js.map +1 -0
  77. package/dist/tsup/chunk-YAE3MEJM.cjs +49 -0
  78. package/dist/tsup/chunk-YAE3MEJM.cjs.map +1 -0
  79. package/dist/tsup/{chunk-SRIM3GHD.js → chunk-YGYGANCA.js} +473 -2323
  80. package/dist/tsup/chunk-YGYGANCA.js.map +1 -0
  81. package/dist/tsup/chunk-YZJWZBY5.cjs +481 -0
  82. package/dist/tsup/chunk-YZJWZBY5.cjs.map +1 -0
  83. package/dist/tsup/{chunk-ZFY5J2EP.cjs → chunk-ZZLJ5TSM.cjs} +39 -44
  84. package/dist/tsup/chunk-ZZLJ5TSM.cjs.map +1 -0
  85. package/dist/tsup/client/mod.cjs +10 -7
  86. package/dist/tsup/client/mod.cjs.map +1 -1
  87. package/dist/tsup/client/mod.d.cts +6 -6
  88. package/dist/tsup/client/mod.d.ts +6 -6
  89. package/dist/tsup/client/mod.js +11 -8
  90. package/dist/tsup/common/log.cjs +3 -3
  91. package/dist/tsup/common/log.js +2 -2
  92. package/dist/tsup/common/websocket.cjs +4 -4
  93. package/dist/tsup/common/websocket.js +3 -3
  94. package/dist/tsup/{config-Qj-zLJPc.d.ts → config-C2Wwnc69.d.ts} +142 -208
  95. package/dist/tsup/{config-BiNoIHRs.d.ts → config-DROwzBLT.d.cts} +82 -6
  96. package/dist/tsup/{config-BiNoIHRs.d.cts → config-DROwzBLT.d.ts} +82 -6
  97. package/dist/tsup/{config-iPj5l1bL.d.cts → config-ehT-_3BB.d.cts} +142 -208
  98. package/dist/tsup/{context-DzvH1PBK.d.cts → context-DGMJuAyc.d.ts} +16 -3
  99. package/dist/tsup/{context-CQCMuHND.d.ts → context-Dpp2RJbW.d.cts} +16 -3
  100. package/dist/tsup/db/drizzle/mod.cjs +3 -3
  101. package/dist/tsup/db/drizzle/mod.d.cts +1 -1
  102. package/dist/tsup/db/drizzle/mod.d.ts +1 -1
  103. package/dist/tsup/db/drizzle/mod.js +2 -2
  104. package/dist/tsup/db/mod.cjs +3 -3
  105. package/dist/tsup/db/mod.d.cts +1 -1
  106. package/dist/tsup/db/mod.d.ts +1 -1
  107. package/dist/tsup/db/mod.js +2 -2
  108. package/dist/tsup/{driver-Jo8v-kbU.d.ts → driver-CYZP9QYo.d.ts} +1 -1
  109. package/dist/tsup/{driver-iV8J-WMv.d.cts → driver-CoTFpipv.d.cts} +1 -1
  110. package/dist/tsup/driver-helpers/mod.cjs +7 -5
  111. package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
  112. package/dist/tsup/driver-helpers/mod.d.cts +17 -18
  113. package/dist/tsup/driver-helpers/mod.d.ts +17 -18
  114. package/dist/tsup/driver-helpers/mod.js +11 -9
  115. package/dist/tsup/driver-test-suite/mod.cjs +1275 -228
  116. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  117. package/dist/tsup/driver-test-suite/mod.d.cts +6 -5
  118. package/dist/tsup/driver-test-suite/mod.d.ts +6 -5
  119. package/dist/tsup/driver-test-suite/mod.js +1581 -534
  120. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  121. package/dist/tsup/inspector/mod.cjs +4 -4
  122. package/dist/tsup/inspector/mod.js +3 -3
  123. package/dist/tsup/mod.cjs +15 -9
  124. package/dist/tsup/mod.cjs.map +1 -1
  125. package/dist/tsup/mod.d.cts +9 -9
  126. package/dist/tsup/mod.d.ts +9 -9
  127. package/dist/tsup/mod.js +19 -13
  128. package/dist/tsup/sandbox/client.cjs +28 -0
  129. package/dist/tsup/sandbox/client.cjs.map +1 -0
  130. package/dist/tsup/sandbox/client.d.cts +88 -0
  131. package/dist/tsup/sandbox/client.d.ts +88 -0
  132. package/dist/tsup/sandbox/client.js +28 -0
  133. package/dist/tsup/sandbox/client.js.map +1 -0
  134. package/dist/tsup/sandbox/index.cjs +761 -0
  135. package/dist/tsup/sandbox/index.cjs.map +1 -0
  136. package/dist/tsup/sandbox/index.d.cts +120 -0
  137. package/dist/tsup/sandbox/index.d.ts +120 -0
  138. package/dist/tsup/sandbox/index.js +761 -0
  139. package/dist/tsup/sandbox/index.js.map +1 -0
  140. package/dist/tsup/sandbox/providers/computesdk.cjs +3 -0
  141. package/dist/tsup/sandbox/providers/computesdk.cjs.map +1 -0
  142. package/dist/tsup/sandbox/providers/computesdk.d.cts +7 -0
  143. package/dist/tsup/sandbox/providers/computesdk.d.ts +7 -0
  144. package/dist/tsup/sandbox/providers/computesdk.js +3 -0
  145. package/dist/tsup/sandbox/providers/computesdk.js.map +1 -0
  146. package/dist/tsup/sandbox/providers/daytona.cjs +3 -0
  147. package/dist/tsup/sandbox/providers/daytona.cjs.map +1 -0
  148. package/dist/tsup/sandbox/providers/daytona.d.cts +1 -0
  149. package/dist/tsup/sandbox/providers/daytona.d.ts +1 -0
  150. package/dist/tsup/sandbox/providers/daytona.js +3 -0
  151. package/dist/tsup/sandbox/providers/daytona.js.map +1 -0
  152. package/dist/tsup/sandbox/providers/docker.cjs +3 -0
  153. package/dist/tsup/sandbox/providers/docker.cjs.map +1 -0
  154. package/dist/tsup/sandbox/providers/docker.d.cts +1 -0
  155. package/dist/tsup/sandbox/providers/docker.d.ts +1 -0
  156. package/dist/tsup/sandbox/providers/docker.js +3 -0
  157. package/dist/tsup/sandbox/providers/docker.js.map +1 -0
  158. package/dist/tsup/sandbox/providers/e2b.cjs +3 -0
  159. package/dist/tsup/sandbox/providers/e2b.cjs.map +1 -0
  160. package/dist/tsup/sandbox/providers/e2b.d.cts +1 -0
  161. package/dist/tsup/sandbox/providers/e2b.d.ts +1 -0
  162. package/dist/tsup/sandbox/providers/e2b.js +3 -0
  163. package/dist/tsup/sandbox/providers/e2b.js.map +1 -0
  164. package/dist/tsup/sandbox/providers/local.cjs +3 -0
  165. package/dist/tsup/sandbox/providers/local.cjs.map +1 -0
  166. package/dist/tsup/sandbox/providers/local.d.cts +1 -0
  167. package/dist/tsup/sandbox/providers/local.d.ts +1 -0
  168. package/dist/tsup/sandbox/providers/local.js +3 -0
  169. package/dist/tsup/sandbox/providers/local.js.map +1 -0
  170. package/dist/tsup/sandbox/providers/modal.cjs +3 -0
  171. package/dist/tsup/sandbox/providers/modal.cjs.map +1 -0
  172. package/dist/tsup/sandbox/providers/modal.d.cts +1 -0
  173. package/dist/tsup/sandbox/providers/modal.d.ts +1 -0
  174. package/dist/tsup/sandbox/providers/modal.js +3 -0
  175. package/dist/tsup/sandbox/providers/modal.js.map +1 -0
  176. package/dist/tsup/sandbox/providers/vercel.cjs +3 -0
  177. package/dist/tsup/sandbox/providers/vercel.cjs.map +1 -0
  178. package/dist/tsup/sandbox/providers/vercel.d.cts +1 -0
  179. package/dist/tsup/sandbox/providers/vercel.d.ts +1 -0
  180. package/dist/tsup/sandbox/providers/vercel.js +3 -0
  181. package/dist/tsup/sandbox/providers/vercel.js.map +1 -0
  182. package/dist/tsup/serve-test-suite/mod.cjs +451 -327
  183. package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
  184. package/dist/tsup/serve-test-suite/mod.js +362 -238
  185. package/dist/tsup/serve-test-suite/mod.js.map +1 -1
  186. package/dist/tsup/test/mod.cjs +17 -14
  187. package/dist/tsup/test/mod.cjs.map +1 -1
  188. package/dist/tsup/test/mod.d.cts +4 -4
  189. package/dist/tsup/test/mod.d.ts +4 -4
  190. package/dist/tsup/test/mod.js +14 -11
  191. package/dist/tsup/test/mod.js.map +1 -1
  192. package/dist/tsup/utils.cjs +3 -3
  193. package/dist/tsup/utils.js +2 -2
  194. package/dist/tsup/workflow/mod.cjs +6 -6
  195. package/dist/tsup/workflow/mod.d.cts +13 -9
  196. package/dist/tsup/workflow/mod.d.ts +13 -9
  197. package/dist/tsup/workflow/mod.js +5 -5
  198. package/package.json +114 -15
  199. package/src/actor/config.ts +94 -88
  200. package/src/actor/conn/drivers/websocket.ts +2 -1
  201. package/src/actor/contexts/base/actor.ts +27 -4
  202. package/src/actor/database.ts +6 -1
  203. package/src/actor/driver.ts +27 -8
  204. package/src/actor/errors.ts +10 -5
  205. package/src/actor/instance/connection-manager.ts +4 -3
  206. package/src/actor/instance/kv.ts +52 -9
  207. package/src/actor/instance/mod.ts +135 -84
  208. package/src/actor/instance/queue-manager.ts +2 -5
  209. package/src/actor/instance/queue.ts +31 -29
  210. package/src/actor/instance/state-manager.ts +7 -1
  211. package/src/actor/instance/traces-driver.ts +34 -36
  212. package/src/actor/metrics.ts +137 -0
  213. package/src/actor/protocol/old.ts +9 -12
  214. package/src/actor/router-websocket-endpoints.ts +12 -6
  215. package/src/actor/router.ts +46 -9
  216. package/src/actor/schema.ts +14 -22
  217. package/src/client/actor-common.ts +65 -0
  218. package/src/client/actor-conn.ts +71 -9
  219. package/src/client/actor-handle.ts +22 -5
  220. package/src/client/client.ts +32 -6
  221. package/src/client/config.ts +18 -21
  222. package/src/client/mod.ts +1 -0
  223. package/src/client/queue.ts +8 -6
  224. package/src/common/inline-websocket-adapter.ts +8 -2
  225. package/src/common/router.ts +1 -4
  226. package/src/common/utils.ts +2 -5
  227. package/src/db/config.ts +10 -5
  228. package/src/db/drizzle/mod.ts +51 -41
  229. package/src/db/mod.ts +54 -29
  230. package/src/db/shared.ts +42 -8
  231. package/src/driver-helpers/mod.ts +2 -1
  232. package/src/driver-helpers/sqlite-pool.ts +42 -0
  233. package/src/driver-helpers/utils.ts +0 -20
  234. package/src/driver-test-suite/mod.ts +11 -1
  235. package/src/driver-test-suite/tests/access-control.ts +19 -12
  236. package/src/driver-test-suite/tests/action-features.ts +20 -8
  237. package/src/driver-test-suite/tests/actor-conn.ts +94 -8
  238. package/src/driver-test-suite/tests/actor-db-kv-stats.ts +282 -0
  239. package/src/driver-test-suite/tests/actor-db-raw.ts +6 -2
  240. package/src/driver-test-suite/tests/actor-db.ts +101 -31
  241. package/src/driver-test-suite/tests/actor-inspector.ts +174 -32
  242. package/src/driver-test-suite/tests/actor-kv.ts +79 -33
  243. package/src/driver-test-suite/tests/actor-lifecycle.ts +4 -12
  244. package/src/driver-test-suite/tests/actor-queue.ts +125 -17
  245. package/src/driver-test-suite/tests/actor-run.ts +59 -55
  246. package/src/driver-test-suite/tests/actor-sandbox.ts +78 -0
  247. package/src/driver-test-suite/tests/actor-schedule.ts +1 -4
  248. package/src/driver-test-suite/tests/actor-sleep.ts +111 -0
  249. package/src/driver-test-suite/tests/actor-workflow.ts +387 -3
  250. package/src/driver-test-suite/tests/conn-error-serialization.ts +3 -1
  251. package/src/driver-test-suite/tests/raw-websocket.ts +5 -1
  252. package/src/drivers/default.ts +1 -3
  253. package/src/drivers/engine/actor-driver.ts +94 -21
  254. package/src/drivers/engine/config.ts +4 -12
  255. package/src/drivers/engine/mod.ts +1 -5
  256. package/src/drivers/file-system/actor.ts +43 -8
  257. package/src/drivers/file-system/global-state.ts +180 -64
  258. package/src/drivers/file-system/kv-limits.ts +1 -1
  259. package/src/drivers/file-system/sqlite-runtime.ts +13 -4
  260. package/src/engine-process/mod.ts +5 -1
  261. package/src/inspector/actor-inspector.ts +47 -21
  262. package/src/inspector/config.ts +1 -4
  263. package/src/inspector/mod.browser.ts +2 -2
  264. package/src/inspector/mod.ts +4 -1
  265. package/src/inspector/serve-ui.ts +0 -1
  266. package/src/inspector/workflow-history-json.ts +309 -0
  267. package/src/manager/gateway.ts +6 -2
  268. package/src/manager/router.ts +3 -3
  269. package/src/registry/config/index.ts +65 -12
  270. package/src/registry/config/runner.ts +19 -4
  271. package/src/registry/index.ts +42 -89
  272. package/src/sandbox/actor/db.ts +36 -0
  273. package/src/sandbox/actor/index.ts +476 -0
  274. package/src/sandbox/actor/session.ts +350 -0
  275. package/src/sandbox/actor.test.ts +36 -0
  276. package/src/sandbox/client.test.ts +484 -0
  277. package/src/sandbox/client.ts +707 -0
  278. package/src/sandbox/config.ts +151 -0
  279. package/src/sandbox/index.ts +41 -0
  280. package/src/sandbox/providers/computesdk.ts +1 -0
  281. package/src/sandbox/providers/daytona.ts +1 -0
  282. package/src/sandbox/providers/docker.ts +1 -0
  283. package/src/sandbox/providers/e2b.ts +1 -0
  284. package/src/sandbox/providers/local.ts +1 -0
  285. package/src/sandbox/providers/modal.ts +1 -0
  286. package/src/sandbox/providers/vercel.ts +1 -0
  287. package/src/sandbox/session-persist-driver.ts +180 -0
  288. package/src/sandbox/types.ts +138 -0
  289. package/src/serverless/configure.ts +5 -3
  290. package/src/serverless/router.test.ts +17 -9
  291. package/src/serverless/router.ts +20 -13
  292. package/src/test/mod.ts +3 -4
  293. package/src/utils/endpoint-parser.test.ts +6 -2
  294. package/src/utils/endpoint-parser.ts +6 -2
  295. package/src/utils/env-vars.ts +0 -2
  296. package/src/utils/node.ts +1 -1
  297. package/src/utils/serve.ts +10 -5
  298. package/src/utils.ts +6 -1
  299. package/src/workflow/constants.ts +1 -2
  300. package/src/workflow/context.ts +42 -9
  301. package/src/workflow/driver.ts +57 -23
  302. package/src/workflow/inspector.ts +7 -13
  303. package/src/workflow/mod.ts +91 -4
  304. package/dist/tsup/chunk-6LJAZ5R4.cjs +0 -96
  305. package/dist/tsup/chunk-6LJAZ5R4.cjs.map +0 -1
  306. package/dist/tsup/chunk-7HTNH26M.js.map +0 -1
  307. package/dist/tsup/chunk-7WF2QSIC.cjs.map +0 -1
  308. package/dist/tsup/chunk-D2SPAJVT.cjs +0 -645
  309. package/dist/tsup/chunk-D2SPAJVT.cjs.map +0 -1
  310. package/dist/tsup/chunk-EIATSBYZ.js.map +0 -1
  311. package/dist/tsup/chunk-HYPIHCDT.cjs.map +0 -1
  312. package/dist/tsup/chunk-IIJNPVPQ.cjs.map +0 -1
  313. package/dist/tsup/chunk-JPXO2H55.js.map +0 -1
  314. package/dist/tsup/chunk-KJSYAUOM.js.map +0 -1
  315. package/dist/tsup/chunk-L47L3ZWJ.cjs.map +0 -1
  316. package/dist/tsup/chunk-MIX2KB6U.js.map +0 -1
  317. package/dist/tsup/chunk-N4KRDJ56.js.map +0 -1
  318. package/dist/tsup/chunk-OAXJWGMU.cjs.map +0 -1
  319. package/dist/tsup/chunk-PB5AEMKQ.cjs.map +0 -1
  320. package/dist/tsup/chunk-R5OQUSLN.js +0 -645
  321. package/dist/tsup/chunk-R5OQUSLN.js.map +0 -1
  322. package/dist/tsup/chunk-SR3KQE7Q.cjs.map +0 -1
  323. package/dist/tsup/chunk-SRIM3GHD.js.map +0 -1
  324. package/dist/tsup/chunk-TADUYCHF.js.map +0 -1
  325. package/dist/tsup/chunk-TI5PXQGG.cjs.map +0 -1
  326. package/dist/tsup/chunk-U5SMSA27.cjs.map +0 -1
  327. package/dist/tsup/chunk-VKVNIQRQ.js.map +0 -1
  328. package/dist/tsup/chunk-WY2SHWXQ.js.map +0 -1
  329. package/dist/tsup/chunk-ZFY5J2EP.cjs.map +0 -1
  330. package/dist/tsup/chunk-ZPWOYQHN.js.map +0 -1
  331. package/src/db/sqlite-vfs.ts +0 -12
  332. /package/dist/tsup/{chunk-S662Y6ZU.js.map → chunk-EONWXYMN.js.map} +0 -0
  333. /package/dist/tsup/{chunk-2OK7S6QF.js.map → chunk-I5I6OALK.js.map} +0 -0
@@ -1,9 +1,5 @@
1
1
  import { z } from "zod/v4";
2
- import {
3
- ClientConfigSchemaBase,
4
- transformClientConfig,
5
- } from "@/client/config";
6
- import { getRivetRunnerKey } from "@/utils/env-vars";
2
+ import { ClientConfigSchemaBase, transformClientConfig } from "@/client/config";
7
3
 
8
4
  /**
9
5
  * Base engine config schema without transforms so it can be merged in to other schemas.
@@ -11,11 +7,10 @@ import { getRivetRunnerKey } from "@/utils/env-vars";
11
7
  * We include the client config since this includes the common properties like endpoint, namespace, etc.
12
8
  */
13
9
  export const EngineConfigSchemaBase = ClientConfigSchemaBase.extend({
14
- /** Unique key for this runner. Runners connecting a given key will replace any other runner connected with the same key. */
10
+ /** Deprecated. Unique key for this runner. Runners connecting a given key will replace any other runner connected with the same key. */
15
11
  runnerKey: z
16
12
  .string()
17
- .optional()
18
- .transform((val) => val ?? getRivetRunnerKey()),
13
+ .optional(),
19
14
 
20
15
  /** How many actors this runner can run. */
21
16
  totalSlots: z.number().default(100_000),
@@ -36,8 +31,5 @@ export function transformEngineConfig(
36
31
  config: z.infer<typeof EngineConfigSchemaBase>,
37
32
  ctx: z.RefinementCtx,
38
33
  ) {
39
- return {
40
- ...transformClientConfig(config, ctx),
41
- runnerKey: config.runnerKey,
42
- };
34
+ return transformClientConfig(config, ctx);
43
35
  }
@@ -25,11 +25,7 @@ export function createEngineDriver(): DriverConfig {
25
25
  managerDriver: ManagerDriver,
26
26
  inlineClient: Client<any>,
27
27
  ) => {
28
- return new EngineActorDriver(
29
- config,
30
- managerDriver,
31
- inlineClient,
32
- );
28
+ return new EngineActorDriver(config, managerDriver, inlineClient);
33
29
  },
34
30
  autoStartActorDriver: true,
35
31
  };
@@ -1,12 +1,12 @@
1
1
  import type { AnyClient } from "@/client/client";
2
2
  import type { RawDatabaseClient } from "@/db/config";
3
- import type { SqliteVfs } from "@rivetkit/sqlite-vfs";
3
+ import type { ISqliteVfs } from "@rivetkit/sqlite-vfs";
4
4
  import {
5
- importSqliteVfs,
6
5
  type ActorDriver,
7
6
  type AnyActorInstance,
8
7
  type ManagerDriver,
9
8
  } from "@/driver-helpers/mod";
9
+ import { SqliteVfsPoolManager } from "@/driver-helpers/sqlite-pool";
10
10
  import type { FileSystemGlobalState } from "./global-state";
11
11
  import { RegistryConfig } from "@/registry/config";
12
12
 
@@ -20,6 +20,8 @@ export class FileSystemActorDriver implements ActorDriver {
20
20
  #managerDriver: ManagerDriver;
21
21
  #inlineClient: AnyClient;
22
22
  #state: FileSystemGlobalState;
23
+ #sqlitePool: SqliteVfsPoolManager;
24
+ startSleep?: (actorId: string) => void;
23
25
 
24
26
  constructor(
25
27
  config: RegistryConfig,
@@ -31,6 +33,16 @@ export class FileSystemActorDriver implements ActorDriver {
31
33
  this.#managerDriver = managerDriver;
32
34
  this.#inlineClient = inlineClient;
33
35
  this.#state = state;
36
+ this.#sqlitePool = new SqliteVfsPoolManager(config);
37
+
38
+ if (this.#state.persist) {
39
+ // Only define startSleep when persistence is enabled. The actor runtime
40
+ // checks for this property to determine whether the driver supports sleep.
41
+ this.startSleep = (actorId: string) => {
42
+ // Spawns the sleepActor promise.
43
+ this.#state.sleepActor(actorId);
44
+ };
45
+ }
34
46
  }
35
47
 
36
48
  async loadActor(actorId: string): Promise<AnyActorInstance> {
@@ -71,11 +83,35 @@ export class FileSystemActorDriver implements ActorDriver {
71
83
  await this.#state.kvBatchDelete(actorId, keys);
72
84
  }
73
85
 
86
+ async kvDeleteRange(
87
+ actorId: string,
88
+ start: Uint8Array,
89
+ end: Uint8Array,
90
+ ): Promise<void> {
91
+ await this.#state.kvDeleteRange(actorId, start, end);
92
+ }
93
+
74
94
  async kvListPrefix(
75
95
  actorId: string,
76
96
  prefix: Uint8Array,
97
+ options?: {
98
+ reverse?: boolean;
99
+ limit?: number;
100
+ },
101
+ ): Promise<[Uint8Array, Uint8Array][]> {
102
+ return await this.#state.kvListPrefix(actorId, prefix, options);
103
+ }
104
+
105
+ async kvListRange(
106
+ actorId: string,
107
+ start: Uint8Array,
108
+ end: Uint8Array,
109
+ options?: {
110
+ reverse?: boolean;
111
+ limit?: number;
112
+ },
77
113
  ): Promise<[Uint8Array, Uint8Array][]> {
78
- return await this.#state.kvListPrefix(actorId, prefix);
114
+ return await this.#state.kvListRange(actorId, start, end, options);
79
115
  }
80
116
 
81
117
  async setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void> {
@@ -83,13 +119,12 @@ export class FileSystemActorDriver implements ActorDriver {
83
119
  }
84
120
 
85
121
  /** Creates a SQLite VFS instance for creating KV-backed databases */
86
- async createSqliteVfs(): Promise<SqliteVfs> {
87
- return await importSqliteVfs();
122
+ async createSqliteVfs(actorId: string): Promise<ISqliteVfs> {
123
+ return await this.#sqlitePool.acquire(actorId);
88
124
  }
89
125
 
90
- startSleep(actorId: string): void {
91
- // Spawns the sleepActor promise
92
- this.#state.sleepActor(actorId);
126
+ async shutdownRunner(_immediate: boolean): Promise<void> {
127
+ await this.#sqlitePool.shutdown();
93
128
  }
94
129
 
95
130
  async startDestroy(actorId: string): Promise<void> {
@@ -44,8 +44,20 @@ import {
44
44
  validateKvKeys,
45
45
  } from "./kv-limits";
46
46
 
47
+ const DEFAULT_LIST_LIMIT = 16_384;
48
+
47
49
  // Actor handler to track running instances
48
50
 
51
+ function compareBytes(a: Uint8Array, b: Uint8Array): number {
52
+ const len = Math.min(a.length, b.length);
53
+ for (let i = 0; i < len; i++) {
54
+ if (a[i] !== b[i]) {
55
+ return a[i] - b[i];
56
+ }
57
+ }
58
+ return a.length - b.length;
59
+ }
60
+
49
61
  enum ActorLifecycleState {
50
62
  NONEXISTENT, // Entry exists but actor not yet created
51
63
  AWAKE, // Actor is running normally
@@ -563,36 +575,36 @@ export class FileSystemGlobalState {
563
575
  entry.generation = crypto.randomUUID();
564
576
  }
565
577
 
566
- // Initialize storage (runtime KV is stored in SQLite; state.kvStorage is legacy-only)
567
- const initialKvState = getInitialActorKvState(input);
578
+ // Initialize storage (runtime KV is stored in SQLite; state.kvStorage is legacy-only)
579
+ const initialKvState = getInitialActorKvState(input);
568
580
 
569
- await this.#withActorWrite(actorId, async (lockedEntry) => {
570
- lockedEntry.state = {
581
+ await this.#withActorWrite(actorId, async (lockedEntry) => {
582
+ lockedEntry.state = {
583
+ actorId,
584
+ name,
585
+ key: key as readonly string[],
586
+ createdAt: BigInt(Date.now()),
587
+ kvStorage: [],
588
+ startTs: null,
589
+ connectableTs: null,
590
+ sleepTs: null,
591
+ destroyTs: null,
592
+ };
593
+ if (this.#persist) {
594
+ await this.#performWrite(
571
595
  actorId,
572
- name,
573
- key: key as readonly string[],
574
- createdAt: BigInt(Date.now()),
575
- kvStorage: [],
576
- startTs: null,
577
- connectableTs: null,
578
- sleepTs: null,
579
- destroyTs: null,
580
- };
581
- if (this.#persist) {
582
- await this.#performWrite(
583
- actorId,
584
- lockedEntry.generation,
585
- lockedEntry.state,
586
- );
587
- }
588
- if (initialKvState.length > 0) {
589
- const db = this.#getOrCreateActorKvDatabase(actorId);
590
- this.#putKvEntriesInDb(db, initialKvState);
591
- }
592
- });
593
- }
594
- return entry;
596
+ lockedEntry.generation,
597
+ lockedEntry.state,
598
+ );
599
+ }
600
+ if (initialKvState.length > 0) {
601
+ const db = this.#getOrCreateActorKvDatabase(actorId);
602
+ this.#putKvEntriesInDb(db, initialKvState);
603
+ }
604
+ });
595
605
  }
606
+ return entry;
607
+ }
596
608
 
597
609
  async sleepActor(actorId: string) {
598
610
  invariant(
@@ -609,7 +621,12 @@ export class FileSystemGlobalState {
609
621
  return;
610
622
  }
611
623
  actor.lifecycleState = ActorLifecycleState.STARTING_SLEEP;
612
- actor.stopPromise = promiseWithResolvers((reason) => logger().warn({ msg: "unhandled actor sleep stop promise rejection", reason }));
624
+ actor.stopPromise = promiseWithResolvers((reason) =>
625
+ logger().warn({
626
+ msg: "unhandled actor sleep stop promise rejection",
627
+ reason,
628
+ }),
629
+ );
613
630
 
614
631
  // Wait for actor to fully start before stopping it to avoid race conditions
615
632
  if (actor.loadPromise) await actor.loadPromise.catch();
@@ -640,12 +657,12 @@ export class FileSystemGlobalState {
640
657
  // Stop actor
641
658
  invariant(actor.actor, "actor should be loaded");
642
659
  await actor.actor.onStop("sleep");
643
- } finally {
644
- // Ensure any pending KV writes finish before removing the entry.
645
- await this.#withActorWrite(actorId, async () => {});
646
- this.#closeActorKvDatabase(actorId);
647
- actor.stopPromise?.resolve();
648
- actor.stopPromise = undefined;
660
+ } finally {
661
+ // Ensure any pending KV writes finish before removing the entry.
662
+ await this.#withActorWrite(actorId, async () => { });
663
+ this.#closeActorKvDatabase(actorId);
664
+ actor.stopPromise?.resolve();
665
+ actor.stopPromise = undefined;
649
666
 
650
667
  // Remove from map after stop is complete
651
668
  this.#actors.delete(actorId);
@@ -662,7 +679,12 @@ export class FileSystemGlobalState {
662
679
  return;
663
680
  }
664
681
  actor.lifecycleState = ActorLifecycleState.STARTING_DESTROY;
665
- actor.stopPromise = promiseWithResolvers((reason) => logger().warn({ msg: "unhandled actor destroy stop promise rejection", reason }));
682
+ actor.stopPromise = promiseWithResolvers((reason) =>
683
+ logger().warn({
684
+ msg: "unhandled actor destroy stop promise rejection",
685
+ reason,
686
+ }),
687
+ );
666
688
 
667
689
  // Wait for actor to fully start before stopping it to avoid race conditions
668
690
  if (actor.loadPromise) await actor.loadPromise.catch();
@@ -695,9 +717,9 @@ export class FileSystemGlobalState {
695
717
  await actor.actor.onStop("destroy");
696
718
  }
697
719
 
698
- // Ensure any pending KV writes finish before deleting files.
699
- await this.#withActorWrite(actorId, async () => {});
700
- this.#closeActorKvDatabase(actorId);
720
+ // Ensure any pending KV writes finish before deleting files.
721
+ await this.#withActorWrite(actorId, async () => { });
722
+ this.#closeActorKvDatabase(actorId);
701
723
 
702
724
  // Clear alarm timeout if exists
703
725
  if (actor.alarmTimeout) {
@@ -756,7 +778,7 @@ export class FileSystemGlobalState {
756
778
  }
757
779
  } finally {
758
780
  // Ensure any pending KV writes finish before clearing the entry.
759
- await this.#withActorWrite(actorId, async () => {});
781
+ await this.#withActorWrite(actorId, async () => { });
760
782
  actor.stopPromise?.resolve();
761
783
  actor.stopPromise = undefined;
762
784
 
@@ -835,7 +857,12 @@ export class FileSystemGlobalState {
835
857
  invariant(entry, "actor entry does not exist");
836
858
 
837
859
  const previousWrite = entry.pendingWriteResolver;
838
- const currentWrite = promiseWithResolvers<void>((reason) => logger().warn({ msg: "unhandled kv write promise rejection", reason }));
860
+ const currentWrite = promiseWithResolvers<void>((reason) =>
861
+ logger().warn({
862
+ msg: "unhandled kv write promise rejection",
863
+ reason,
864
+ }),
865
+ );
839
866
  entry.pendingWriteResolver = currentWrite;
840
867
 
841
868
  if (previousWrite) {
@@ -920,7 +947,7 @@ export class FileSystemGlobalState {
920
947
  try {
921
948
  const fs = getNodeFs();
922
949
  await fs.unlink(tempPath);
923
- } catch {}
950
+ } catch { }
924
951
  logger().error({
925
952
  msg: "failed to write alarm",
926
953
  actorId,
@@ -1072,7 +1099,12 @@ export class FileSystemGlobalState {
1072
1099
  }
1073
1100
 
1074
1101
  // Create start promise
1075
- entry.startPromise = promiseWithResolvers((reason) => logger().warn({ msg: "unhandled actor start promise rejection", reason }));
1102
+ entry.startPromise = promiseWithResolvers((reason) =>
1103
+ logger().warn({
1104
+ msg: "unhandled actor start promise rejection",
1105
+ reason,
1106
+ }),
1107
+ );
1076
1108
 
1077
1109
  try {
1078
1110
  // Create actor
@@ -1105,25 +1137,25 @@ export class FileSystemGlobalState {
1105
1137
  connectableTs: now,
1106
1138
  sleepTs: null, // Clear sleep timestamp when actor wakes up
1107
1139
  };
1108
- if (this.#persist) {
1109
- await this.#performWrite(
1110
- actorId,
1111
- lockedEntry.generation,
1112
- lockedEntry.state,
1113
- );
1114
- }
1115
- });
1140
+ if (this.#persist) {
1141
+ await this.#performWrite(
1142
+ actorId,
1143
+ lockedEntry.generation,
1144
+ lockedEntry.state,
1145
+ );
1146
+ }
1147
+ });
1116
1148
 
1117
1149
  // Finish
1118
1150
  entry.startPromise.resolve();
1119
1151
  entry.startPromise = undefined;
1120
1152
 
1121
1153
  return entry.actor;
1122
- } catch (innerError) {
1123
- const error = new Error(
1124
- `Failed to start actor ${actorId}: ${innerError}`,
1125
- { cause: innerError },
1126
- );
1154
+ } catch (innerError) {
1155
+ const error = new Error(
1156
+ `Failed to start actor ${actorId}: ${innerError}`,
1157
+ { cause: innerError },
1158
+ );
1127
1159
  entry.startPromise?.reject(error);
1128
1160
  entry.startPromise = undefined;
1129
1161
  throw error;
@@ -1407,12 +1439,44 @@ export class FileSystemGlobalState {
1407
1439
  });
1408
1440
  }
1409
1441
 
1442
+ /**
1443
+ * Delete KV entries in the half-open range [start, end).
1444
+ */
1445
+ async kvDeleteRange(
1446
+ actorId: string,
1447
+ start: Uint8Array,
1448
+ end: Uint8Array,
1449
+ ): Promise<void> {
1450
+ await this.loadActor(actorId);
1451
+ await this.#withActorWrite(actorId, async (entry) => {
1452
+ if (!entry.state) {
1453
+ if (this.isActorStopping(actorId)) {
1454
+ return;
1455
+ }
1456
+ throw new Error(`Actor ${actorId} state not loaded`);
1457
+ }
1458
+
1459
+ validateKvKey(start, "start key");
1460
+ validateKvKey(end, "end key");
1461
+ if (compareBytes(start, end) >= 0) {
1462
+ return;
1463
+ }
1464
+
1465
+ const db = this.#getOrCreateActorKvDatabase(actorId);
1466
+ db.run("DELETE FROM kv WHERE key >= ? AND key < ?", [start, end]);
1467
+ });
1468
+ }
1469
+
1410
1470
  /**
1411
1471
  * List KV entries with a given prefix for an actor.
1412
1472
  */
1413
1473
  async kvListPrefix(
1414
1474
  actorId: string,
1415
1475
  prefix: Uint8Array,
1476
+ options?: {
1477
+ reverse?: boolean;
1478
+ limit?: number;
1479
+ },
1416
1480
  ): Promise<[Uint8Array, Uint8Array][]> {
1417
1481
  const entry = await this.loadActor(actorId);
1418
1482
  await this.#waitForPendingWrite(actorId);
@@ -1427,19 +1491,71 @@ export class FileSystemGlobalState {
1427
1491
 
1428
1492
  const db = this.#getOrCreateActorKvDatabase(actorId);
1429
1493
  const upperBound = computePrefixUpperBound(prefix);
1494
+ const direction = options?.reverse ? "DESC" : "ASC";
1495
+ const limit = options?.limit ?? DEFAULT_LIST_LIMIT;
1430
1496
  const rows = upperBound
1431
- ? db.all<{ key: Uint8Array | ArrayBuffer; value: Uint8Array | ArrayBuffer }>(
1432
- "SELECT key, value FROM kv WHERE key >= ? AND key < ? ORDER BY key ASC",
1433
- [prefix, upperBound],
1434
- )
1435
- : db.all<{ key: Uint8Array | ArrayBuffer; value: Uint8Array | ArrayBuffer }>(
1436
- "SELECT key, value FROM kv WHERE key >= ? ORDER BY key ASC",
1437
- [prefix],
1438
- );
1497
+ ? db.all<{
1498
+ key: Uint8Array | ArrayBuffer;
1499
+ value: Uint8Array | ArrayBuffer;
1500
+ }>(
1501
+ `SELECT key, value FROM kv WHERE key >= ? AND key < ? ORDER BY key ${direction} LIMIT ?`,
1502
+ [prefix, upperBound, limit],
1503
+ )
1504
+ : db.all<{
1505
+ key: Uint8Array | ArrayBuffer;
1506
+ value: Uint8Array | ArrayBuffer;
1507
+ }>(
1508
+ `SELECT key, value FROM kv WHERE key >= ? ORDER BY key ${direction} LIMIT ?`,
1509
+ [prefix, limit],
1510
+ );
1439
1511
 
1440
1512
  return rows.map((row) => [
1441
1513
  ensureUint8Array(row.key, "key"),
1442
1514
  ensureUint8Array(row.value, "value"),
1443
1515
  ]);
1444
1516
  }
1445
- }
1517
+
1518
+ /**
1519
+ * List KV entries in the half-open range [start, end).
1520
+ */
1521
+ async kvListRange(
1522
+ actorId: string,
1523
+ start: Uint8Array,
1524
+ end: Uint8Array,
1525
+ options?: {
1526
+ reverse?: boolean;
1527
+ limit?: number;
1528
+ },
1529
+ ): Promise<[Uint8Array, Uint8Array][]> {
1530
+ const entry = await this.loadActor(actorId);
1531
+ await this.#waitForPendingWrite(actorId);
1532
+ if (!entry.state) {
1533
+ if (this.isActorStopping(actorId)) {
1534
+ throw new Error(`Actor ${actorId} is destroying`);
1535
+ } else {
1536
+ throw new Error(`Actor ${actorId} state not loaded`);
1537
+ }
1538
+ }
1539
+ validateKvKey(start, "start key");
1540
+ validateKvKey(end, "end key");
1541
+ if (compareBytes(start, end) >= 0) {
1542
+ return [];
1543
+ }
1544
+
1545
+ const db = this.#getOrCreateActorKvDatabase(actorId);
1546
+ const direction = options?.reverse ? "DESC" : "ASC";
1547
+ const limit = options?.limit ?? DEFAULT_LIST_LIMIT;
1548
+ const rows = db.all<{
1549
+ key: Uint8Array | ArrayBuffer;
1550
+ value: Uint8Array | ArrayBuffer;
1551
+ }>(
1552
+ `SELECT key, value FROM kv WHERE key >= ? AND key < ? ORDER BY key ${direction} LIMIT ?`,
1553
+ [start, end, limit],
1554
+ );
1555
+
1556
+ return rows.map((row) => [
1557
+ ensureUint8Array(row.key, "key"),
1558
+ ensureUint8Array(row.value, "value"),
1559
+ ]);
1560
+ }
1561
+ }
@@ -17,7 +17,7 @@ export function estimateKvSize(db: SqliteRuntimeDatabase): number {
17
17
 
18
18
  export function validateKvKey(
19
19
  key: Uint8Array,
20
- keyLabel: "key" | "prefix key" = "key",
20
+ keyLabel: "key" | "prefix key" | "start key" | "end key" = "key",
21
21
  ): void {
22
22
  if (key.byteLength + KV_KEY_WRAPPER_OVERHEAD_SIZE > KV_MAX_KEY_SIZE) {
23
23
  throw new Error(`${keyLabel} is too long (max 2048 bytes)`);
@@ -110,7 +110,10 @@ export function loadSqliteRuntime(): SqliteRuntime {
110
110
  const rawDb = new BunDatabase(path);
111
111
  configureSqliteRuntimeDatabase(rawDb, path);
112
112
  const query = rawDb.query?.bind(rawDb);
113
- if (!query) throw new Error("bun:sqlite database missing query method");
113
+ if (!query)
114
+ throw new Error(
115
+ "bun:sqlite database missing query method",
116
+ );
114
117
  return createPreparedDatabaseAdapter(rawDb, query);
115
118
  },
116
119
  };
@@ -120,7 +123,9 @@ export function loadSqliteRuntime(): SqliteRuntime {
120
123
  }
121
124
 
122
125
  try {
123
- const nodeSqlite = requireFn(/* webpackIgnore: true */ "node:sqlite") as {
126
+ const nodeSqlite = requireFn(
127
+ /* webpackIgnore: true */ "node:sqlite",
128
+ ) as {
124
129
  DatabaseSync?: SqliteDatabaseCtor;
125
130
  };
126
131
  const NodeDatabaseSync = nodeSqlite.DatabaseSync;
@@ -132,7 +137,9 @@ export function loadSqliteRuntime(): SqliteRuntime {
132
137
  configureSqliteRuntimeDatabase(rawDb, path);
133
138
  const prepare = rawDb.prepare?.bind(rawDb);
134
139
  if (!prepare) {
135
- throw new Error("node:sqlite DatabaseSync missing prepare method");
140
+ throw new Error(
141
+ "node:sqlite DatabaseSync missing prepare method",
142
+ );
136
143
  }
137
144
  return createPreparedDatabaseAdapter(rawDb, prepare);
138
145
  },
@@ -158,7 +165,9 @@ export function loadSqliteRuntime(): SqliteRuntime {
158
165
  configureSqliteRuntimeDatabase(rawDb, path);
159
166
  const prepare = rawDb.prepare?.bind(rawDb);
160
167
  if (!prepare) {
161
- throw new Error("better-sqlite3 database missing prepare method");
168
+ throw new Error(
169
+ "better-sqlite3 database missing prepare method",
170
+ );
162
171
  }
163
172
  return createPreparedDatabaseAdapter(rawDb, prepare);
164
173
  },
@@ -166,7 +166,11 @@ export async function ensureEngineProcess(
166
166
  issues: "https://github.com/rivet-dev/rivetkit/issues",
167
167
  support: "https://rivet.dev/discord",
168
168
  });
169
- } else if (stderrOutput.includes("Rivet Engine has been rolled back to a previous version")) {
169
+ } else if (
170
+ stderrOutput.includes(
171
+ "Rivet Engine has been rolled back to a previous version",
172
+ )
173
+ ) {
170
174
  logger().error({
171
175
  msg: "rivet engine version downgrade detected",
172
176
  hint: `You attempted to downgrade the RivetKit version in development. To fix this, nuke the database by running: '${binaryPath}' database nuke --yes`,
@@ -11,6 +11,7 @@ import * as actorErrors from "@/actor/errors";
11
11
  import type { AnyActorInstance } from "@/mod";
12
12
  import type * as schema from "@/schemas/actor-inspector/mod";
13
13
  import { bufferToArrayBuffer } from "@/utils";
14
+ import { serializeWorkflowHistoryForJson } from "./workflow-history-json";
14
15
 
15
16
  interface ActorInspectorEmitterEvents {
16
17
  stateUpdated: (state: unknown) => void;
@@ -23,7 +24,6 @@ export type Connection = Omit<schema.Connection, "details"> & {
23
24
  details: unknown;
24
25
  };
25
26
 
26
-
27
27
  /**
28
28
  * Provides a unified interface for inspecting actor external and internal state.
29
29
  */
@@ -57,9 +57,7 @@ export class ActorInspector {
57
57
  const maxSize = this.actor.config.options.maxQueueSize;
58
58
  const safeLimit = Math.max(0, Math.floor(limit));
59
59
  const messages = await this.actor.queueManager.getMessages();
60
- const sorted = messages.sort(
61
- (a, b) => a.createdAt - b.createdAt,
62
- );
60
+ const sorted = messages.sort((a, b) => a.createdAt - b.createdAt);
63
61
  const limited = safeLimit > 0 ? sorted.slice(0, safeLimit) : [];
64
62
  return {
65
63
  size: BigInt(this.#lastQueueSize),
@@ -111,25 +109,23 @@ export class ActorInspector {
111
109
  const db = this.actor.db;
112
110
 
113
111
  // Get table list from sqlite_master, excluding internal tables.
114
- const tables = await db.execute(
112
+ const tables = (await db.execute(
115
113
  "SELECT name, type FROM sqlite_master WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '__drizzle_%'",
116
- ) as { name: string; type: string }[];
114
+ )) as { name: string; type: string }[];
117
115
 
118
116
  // Serialize all queries to avoid concurrent @rivetkit/sqlite access
119
117
  // which can cause "file is not a database" errors.
120
118
  const tableInfos = [];
121
119
  for (const table of tables) {
122
120
  const quoted = `"${escapeDoubleQuotes(table.name)}"`;
123
- const sample = await db.execute(
121
+ const sample = (await db.execute(
124
122
  `SELECT * FROM ${quoted} LIMIT 1`,
125
- ) as Record<string, unknown>[];
126
- const countResult = await db.execute(
123
+ )) as Record<string, unknown>[];
124
+ const countResult = (await db.execute(
127
125
  `SELECT COUNT(*) as count FROM ${quoted}`,
128
- ) as { count: number }[];
126
+ )) as { count: number }[];
129
127
 
130
- const columnNames = sample?.[0]
131
- ? Object.keys(sample[0])
132
- : [];
128
+ const columnNames = sample?.[0] ? Object.keys(sample[0]) : [];
133
129
 
134
130
  tableInfos.push({
135
131
  table: { schema: "main", name: table.name, type: table.type },
@@ -263,6 +259,26 @@ export class ActorInspector {
263
259
  await this.actor.stateManager.saveState({ immediate: true });
264
260
  }
265
261
 
262
+ async getDatabaseSchemaJson(): Promise<unknown> {
263
+ return toHttpJsonCompatible(
264
+ cbor.decode(Buffer.from(await this.getDatabaseSchema())),
265
+ );
266
+ }
267
+
268
+ async getDatabaseTableRowsJson(
269
+ table: string,
270
+ limit: number,
271
+ offset: number,
272
+ ): Promise<unknown[]> {
273
+ return toHttpJsonCompatible(
274
+ cbor.decode(
275
+ Buffer.from(
276
+ await this.getDatabaseTableRows(table, limit, offset),
277
+ ),
278
+ ),
279
+ ) as unknown[];
280
+ }
281
+
266
282
  getConnectionsJson(): { id: string; details: unknown }[] {
267
283
  return Array.from(
268
284
  this.actor.connectionManager.connections.entries(),
@@ -314,15 +330,14 @@ export class ActorInspector {
314
330
  return result;
315
331
  }
316
332
 
317
- getWorkflowHistoryJson(): { history: unknown | null; isWorkflowEnabled: boolean } {
318
- const bigIntReplacer = (_key: string, value: unknown) =>
319
- typeof value === "bigint" ? Number(value) : value;
320
- const history = this.getWorkflowHistory();
321
- const safeHistory = history
322
- ? JSON.parse(JSON.stringify(history, bigIntReplacer))
323
- : null;
333
+ getWorkflowHistoryJson(): {
334
+ history: unknown | null;
335
+ isWorkflowEnabled: boolean;
336
+ } {
324
337
  return {
325
- history: safeHistory,
338
+ history: serializeWorkflowHistoryForJson(
339
+ this.getWorkflowHistory(),
340
+ ),
326
341
  isWorkflowEnabled: this.isWorkflowEnabled(),
327
342
  };
328
343
  }
@@ -350,3 +365,14 @@ function escapeDoubleQuotes(value: string): string {
350
365
  return value.replace(/"/g, '""');
351
366
  }
352
367
 
368
+ function toHttpJsonCompatible<T>(value: T): T {
369
+ return JSON.parse(
370
+ JSON.stringify(value, (_key, nestedValue) =>
371
+ typeof nestedValue === "bigint"
372
+ ? Number(nestedValue)
373
+ : nestedValue instanceof Uint8Array
374
+ ? Array.from(nestedValue)
375
+ : nestedValue,
376
+ ),
377
+ ) as T;
378
+ }