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
@@ -6,7 +6,8 @@ import {
6
6
  type SpanStatusInput,
7
7
  type Traces,
8
8
  } from "@rivetkit/traces";
9
- import type { SqliteVfs } from "@rivetkit/sqlite-vfs";
9
+ import type { ISqliteVfs } from "@rivetkit/sqlite-vfs";
10
+ import { ActorMetrics } from "@/actor/metrics";
10
11
  import invariant from "invariant";
11
12
  import type { ActorKey } from "@/actor/mod";
12
13
  import type { Client } from "@/client/client";
@@ -21,10 +22,7 @@ import {
21
22
  } from "@/schemas/actor-persist/versioned";
22
23
  import { EXTRA_ERROR_LOG } from "@/utils";
23
24
  import { getRivetExperimentalOtel } from "@/utils/env-vars";
24
- import {
25
- type ActorConfig,
26
- getRunFunction,
27
- } from "../config";
25
+ import { type ActorConfig, getRunFunction } from "../config";
28
26
  import type { ConnDriver } from "../conn/driver";
29
27
  import { createHttpDriver } from "../conn/drivers/http";
30
28
  import {
@@ -80,6 +78,7 @@ enum CanSleep {
80
78
  Yes,
81
79
  NotReady,
82
80
  NotStarted,
81
+ PreventSleep,
83
82
  ActiveConns,
84
83
  ActiveDisconnectCallbacks,
85
84
  ActiveHonoHttpRequests,
@@ -173,7 +172,8 @@ export class ActorInstance<
173
172
  // MARK: - Variables & Database
174
173
  #vars?: V;
175
174
  #db?: InferDatabaseClient<DB>;
176
- #sqliteVfs?: SqliteVfs;
175
+ #sqliteVfs?: ISqliteVfs;
176
+ #metrics = new ActorMetrics();
177
177
 
178
178
  // MARK: - Background Tasks
179
179
  #backgroundPromises: Promise<void>[] = [];
@@ -184,6 +184,7 @@ export class ActorInstance<
184
184
  // MARK: - HTTP/WebSocket Tracking
185
185
  #activeHonoHttpRequests = 0;
186
186
  #activeKeepAwakeCount = 0;
187
+ #preventSleep = false;
187
188
 
188
189
  // MARK: - Deprecated (kept for compatibility)
189
190
  #schedule!: Schedule;
@@ -262,6 +263,10 @@ export class ActorInstance<
262
263
  return this.#inspectorToken;
263
264
  }
264
265
 
266
+ get metrics(): ActorMetrics {
267
+ return this.#metrics;
268
+ }
269
+
265
270
  // MARK: - Tracing
266
271
  getCurrentTraceSpan(): SpanHandle | null {
267
272
  return this.#traces.getCurrentSpan();
@@ -332,6 +337,10 @@ export class ActorInstance<
332
337
  return this.#abortController.signal;
333
338
  }
334
339
 
340
+ get preventSleep(): boolean {
341
+ return this.#preventSleep;
342
+ }
343
+
335
344
  get actions(): string[] {
336
345
  return Object.keys(this.#config.actions ?? {});
337
346
  }
@@ -505,10 +514,17 @@ export class ActorInstance<
505
514
  // is intentional and safe.
506
515
  try {
507
516
  this.#abortController.abort();
508
- } catch { }
517
+ } catch {}
509
518
 
510
519
  // Wait for run handler to complete
511
- await this.#waitForRunHandler(this.overrides.runStopTimeout !== undefined ? Math.min(this.#config.options.runStopTimeout, this.overrides.runStopTimeout) : this.#config.options.runStopTimeout);
520
+ await this.#waitForRunHandler(
521
+ this.overrides.runStopTimeout !== undefined
522
+ ? Math.min(
523
+ this.#config.options.runStopTimeout,
524
+ this.overrides.runStopTimeout,
525
+ )
526
+ : this.#config.options.runStopTimeout,
527
+ );
512
528
 
513
529
  // Call onStop lifecycle
514
530
  if (mode === "sleep") {
@@ -519,14 +535,19 @@ export class ActorInstance<
519
535
  assertUnreachable(mode);
520
536
  }
521
537
 
522
- // Disconnect non-hibernatable connections
523
- await this.#disconnectConnections();
524
-
525
538
  // Wait for background tasks
526
539
  await this.#waitBackgroundPromises(
527
- this.overrides.waitUntilTimeout !== undefined ? Math.min(this.#config.options.waitUntilTimeout, this.overrides.waitUntilTimeout) : this.#config.options.waitUntilTimeout,
540
+ this.overrides.waitUntilTimeout !== undefined
541
+ ? Math.min(
542
+ this.#config.options.waitUntilTimeout,
543
+ this.overrides.waitUntilTimeout,
544
+ )
545
+ : this.#config.options.waitUntilTimeout,
528
546
  );
529
547
 
548
+ // Disconnect non-hibernatable connections
549
+ await this.#disconnectConnections();
550
+
530
551
  // Clear timeouts and save state
531
552
  this.#rLog.info({ msg: "clearing pending save timeouts" });
532
553
  this.stateManager.clearPendingSaveTimeout();
@@ -633,14 +654,14 @@ export class ActorInstance<
633
654
  async processMessage(
634
655
  message: {
635
656
  body:
636
- | {
637
- tag: "ActionRequest";
638
- val: { id: bigint; name: string; args: unknown };
639
- }
640
- | {
641
- tag: "SubscriptionRequest";
642
- val: { eventName: string; subscribe: boolean };
643
- };
657
+ | {
658
+ tag: "ActionRequest";
659
+ val: { id: bigint; name: string; args: unknown };
660
+ }
661
+ | {
662
+ tag: "SubscriptionRequest";
663
+ val: { eventName: string; subscribe: boolean };
664
+ };
644
665
  },
645
666
  conn: Conn<S, CP, CS, V, I, DB, E, Q>,
646
667
  ) {
@@ -661,7 +682,10 @@ export class ActorInstance<
661
682
  ctx: ActionContext<S, CP, CS, V, I, DB, E, Q>,
662
683
  eventName: string,
663
684
  ): Promise<void> {
664
- const canSubscribe = getEventCanSubscribe(this.#config.events, eventName);
685
+ const canSubscribe = getEventCanSubscribe(
686
+ this.#config.events,
687
+ eventName,
688
+ );
665
689
  if (!canSubscribe) {
666
690
  return;
667
691
  }
@@ -720,7 +744,9 @@ export class ActorInstance<
720
744
  }
721
745
 
722
746
  this.#activeKeepAwakeCount++;
747
+ this.#metrics.actionCalls++;
723
748
  this.resetSleepTimer();
749
+ const actionStart = performance.now();
724
750
  const actionSpan = this.startTraceSpan(`actor.action.${actionName}`, {
725
751
  "rivet.action.name": actionName,
726
752
  });
@@ -781,6 +807,7 @@ export class ActorInstance<
781
807
  return output;
782
808
  });
783
809
  } catch (error) {
810
+ this.#metrics.actionErrors++;
784
811
  const isTimeout = error instanceof DeadlineError;
785
812
  const message = isTimeout
786
813
  ? "ActionTimedOut"
@@ -804,6 +831,7 @@ export class ActorInstance<
804
831
  });
805
832
  throw error;
806
833
  } finally {
834
+ this.#metrics.actionTotalMs += performance.now() - actionStart;
807
835
  if (!spanEnded && actionSpan.isActive()) {
808
836
  this.#traces.endSpan(actionSpan, {
809
837
  status: { code: "OK" },
@@ -834,33 +862,33 @@ export class ActorInstance<
834
862
  }
835
863
  const onRequest = this.#config.onRequest;
836
864
 
837
- return await this.runInTraceSpan(
838
- "actor.onRequest",
839
- {
840
- "http.method": request.method,
841
- "http.url": request.url,
842
- "rivet.conn.id": conn.id,
843
- },
844
- async () => {
845
- const ctx = new RequestContext(this, conn, request);
846
- try {
847
- const response = await onRequest(ctx, request);
848
- if (!response) {
849
- throw new errors.InvalidRequestHandlerResponse();
850
- }
851
- return response;
852
- } catch (error) {
853
- this.#rLog.error({
854
- msg: "onRequest error",
855
- error: stringifyError(error),
856
- });
857
- throw error;
858
- } finally {
859
- this.stateManager.savePersistThrottled();
865
+ return await this.runInTraceSpan(
866
+ "actor.onRequest",
867
+ {
868
+ "http.method": request.method,
869
+ "http.url": request.url,
870
+ "rivet.conn.id": conn.id,
871
+ },
872
+ async () => {
873
+ const ctx = new RequestContext(this, conn, request);
874
+ try {
875
+ const response = await onRequest(ctx, request);
876
+ if (!response) {
877
+ throw new errors.InvalidRequestHandlerResponse();
860
878
  }
861
- },
862
- );
863
- }
879
+ return response;
880
+ } catch (error) {
881
+ this.#rLog.error({
882
+ msg: "onRequest error",
883
+ error: stringifyError(error),
884
+ });
885
+ throw error;
886
+ } finally {
887
+ this.stateManager.savePersistThrottled();
888
+ }
889
+ },
890
+ );
891
+ }
864
892
 
865
893
  handleRawWebSocket(
866
894
  conn: Conn<S, CP, CS, V, I, DB, E, Q>,
@@ -1002,6 +1030,17 @@ export class ActorInstance<
1002
1030
  }
1003
1031
  }
1004
1032
 
1033
+ setPreventSleep(prevent: boolean) {
1034
+ if (this.#preventSleep === prevent) return;
1035
+
1036
+ this.#preventSleep = prevent;
1037
+ this.#rLog.debug({
1038
+ msg: "updated prevent sleep state",
1039
+ prevent,
1040
+ });
1041
+ this.resetSleepTimer();
1042
+ }
1043
+
1005
1044
  beginQueueWait() {
1006
1045
  this.assertReady(true);
1007
1046
  this.#activeQueueWaitCount++;
@@ -1278,7 +1317,12 @@ export class ActorInstance<
1278
1317
  if (result instanceof Promise) {
1279
1318
  await deadline(
1280
1319
  result,
1281
- this.overrides.onSleepTimeout !== undefined ? Math.min(this.#config.options.onSleepTimeout, this.overrides.onSleepTimeout) : this.#config.options.onSleepTimeout,
1320
+ this.overrides.onSleepTimeout !== undefined
1321
+ ? Math.min(
1322
+ this.#config.options.onSleepTimeout,
1323
+ this.overrides.onSleepTimeout,
1324
+ )
1325
+ : this.#config.options.onSleepTimeout,
1282
1326
  );
1283
1327
  }
1284
1328
  },
@@ -1310,7 +1354,13 @@ export class ActorInstance<
1310
1354
  if (result instanceof Promise) {
1311
1355
  await deadline(
1312
1356
  result,
1313
- this.overrides.onDestroyTimeout !== undefined ? Math.min(this.#config.options.onDestroyTimeout, this.overrides.onDestroyTimeout) : this.#config.options.onDestroyTimeout,
1357
+ this.overrides.onDestroyTimeout !== undefined
1358
+ ? Math.min(
1359
+ this.#config.options
1360
+ .onDestroyTimeout,
1361
+ this.overrides.onDestroyTimeout,
1362
+ )
1363
+ : this.#config.options.onDestroyTimeout,
1314
1364
  );
1315
1365
  }
1316
1366
  },
@@ -1342,6 +1392,9 @@ export class ActorInstance<
1342
1392
  runFn(this.actorContext),
1343
1393
  );
1344
1394
 
1395
+ // Do not destroy or immediately sleep the actor when run exits. Finished
1396
+ // workflows must stay inspectable when something goes wrong, and callers
1397
+ // may still need to invoke actions after the run handler has completed.
1345
1398
  if (runResult instanceof Promise) {
1346
1399
  this.#runPromise = runResult
1347
1400
  .then(() => {
@@ -1355,20 +1408,12 @@ export class ActorInstance<
1355
1408
  return;
1356
1409
  }
1357
1410
 
1358
- // Run handler exited normally - this should crash the actor
1359
- this.emitTraceEvent(
1360
- "actor.crash",
1361
- { "rivet.actor.reason": "run_exited" },
1362
- runSpan,
1363
- );
1364
- this.endTraceSpan(runSpan, {
1365
- code: "ERROR",
1366
- message: "run exited unexpectedly",
1367
- });
1368
- this.#rLog.warn({
1369
- msg: "run handler exited unexpectedly, crashing actor to reschedule",
1411
+ if (runSpan.isActive()) {
1412
+ this.endTraceSpan(runSpan, { code: "OK" });
1413
+ }
1414
+ this.#rLog.info({
1415
+ msg: "run handler exited",
1370
1416
  });
1371
- this.startDestroy();
1372
1417
  })
1373
1418
  .catch((error) => {
1374
1419
  if (this.#stopCalled) {
@@ -1382,24 +1427,14 @@ export class ActorInstance<
1382
1427
  return;
1383
1428
  }
1384
1429
 
1385
- // Run handler threw an error - crash the actor
1386
- this.emitTraceEvent(
1387
- "actor.crash",
1388
- {
1389
- "rivet.actor.reason": "run_error",
1390
- "error.message": stringifyError(error),
1391
- },
1392
- runSpan,
1393
- );
1394
1430
  this.endTraceSpan(runSpan, {
1395
1431
  code: "ERROR",
1396
1432
  message: stringifyError(error),
1397
1433
  });
1398
1434
  this.#rLog.error({
1399
- msg: "run handler threw error, crashing actor to reschedule",
1435
+ msg: "run handler threw error",
1400
1436
  error: stringifyError(error),
1401
1437
  });
1402
- this.startDestroy();
1403
1438
  })
1404
1439
  .finally(() => {
1405
1440
  this.#runHandlerActive = false;
@@ -1407,6 +1442,9 @@ export class ActorInstance<
1407
1442
  });
1408
1443
  } else if (runSpan.isActive()) {
1409
1444
  this.endTraceSpan(runSpan, { code: "OK" });
1445
+ this.#rLog.info({
1446
+ msg: "run handler exited",
1447
+ });
1410
1448
  this.#runHandlerActive = false;
1411
1449
  this.resetSleepTimer();
1412
1450
  }
@@ -1443,27 +1481,37 @@ export class ActorInstance<
1443
1481
 
1444
1482
  let client: InferDatabaseClient<DB> | undefined;
1445
1483
  try {
1446
- // Every actor gets its own SqliteVfs/@rivetkit/sqlite instance. The async
1447
- // @rivetkit/sqlite build is not re-entrant, and sharing one instance across
1448
- // actors can cause cross-actor contention and runtime corruption.
1484
+ // Acquire a SQLite VFS handle for this actor. The driver may return a
1485
+ // standalone VFS or a pooled handle that shares a WASM instance.
1449
1486
  if (!this.#sqliteVfs && this.driver.createSqliteVfs) {
1450
- this.#sqliteVfs = await this.driver.createSqliteVfs();
1487
+ this.#sqliteVfs = await this.driver.createSqliteVfs(this.#actorId);
1451
1488
  }
1452
1489
 
1453
1490
  client = await this.#config.db.createClient({
1454
1491
  actorId: this.#actorId,
1455
1492
  overrideRawDatabaseClient: this.driver.overrideRawDatabaseClient
1456
- ? () => this.driver.overrideRawDatabaseClient!(this.#actorId)
1493
+ ? () =>
1494
+ this.driver.overrideRawDatabaseClient!(
1495
+ this.#actorId,
1496
+ )
1457
1497
  : undefined,
1458
- overrideDrizzleDatabaseClient: this.driver.overrideDrizzleDatabaseClient
1459
- ? () => this.driver.overrideDrizzleDatabaseClient!(this.#actorId)
1498
+ overrideDrizzleDatabaseClient: this.driver
1499
+ .overrideDrizzleDatabaseClient
1500
+ ? () =>
1501
+ this.driver.overrideDrizzleDatabaseClient!(
1502
+ this.#actorId,
1503
+ )
1460
1504
  : undefined,
1461
1505
  kv: {
1462
- batchPut: (entries) => this.driver.kvBatchPut(this.#actorId, entries),
1463
- batchGet: (keys) => this.driver.kvBatchGet(this.#actorId, keys),
1464
- batchDelete: (keys) => this.driver.kvBatchDelete(this.#actorId, keys),
1506
+ batchPut: (entries) =>
1507
+ this.driver.kvBatchPut(this.#actorId, entries),
1508
+ batchGet: (keys) =>
1509
+ this.driver.kvBatchGet(this.#actorId, keys),
1510
+ batchDelete: (keys) =>
1511
+ this.driver.kvBatchDelete(this.#actorId, keys),
1465
1512
  },
1466
1513
  sqliteVfs: this.#sqliteVfs,
1514
+ metrics: this.#metrics,
1467
1515
  });
1468
1516
  this.#rLog.info({ msg: "database migration starting" });
1469
1517
  await this.#config.db.onMigrate?.(client);
@@ -1498,7 +1546,9 @@ export class ActorInstance<
1498
1546
  });
1499
1547
  throw error;
1500
1548
  }
1501
- const wrappedError = new Error(`Database setup failed: ${String(error)}`);
1549
+ const wrappedError = new Error(
1550
+ `Database setup failed: ${String(error)}`,
1551
+ );
1502
1552
  this.#rLog.error({
1503
1553
  msg: "database setup failed with non-Error object",
1504
1554
  error: String(error),
@@ -1634,6 +1684,7 @@ export class ActorInstance<
1634
1684
  #canSleep(): CanSleep {
1635
1685
  if (!this.#ready) return CanSleep.NotReady;
1636
1686
  if (!this.#started) return CanSleep.NotReady;
1687
+ if (this.#preventSleep) return CanSleep.PreventSleep;
1637
1688
  if (this.#activeHonoHttpRequests > 0)
1638
1689
  return CanSleep.ActiveHonoHttpRequests;
1639
1690
  if (this.#activeKeepAwakeCount > 0) return CanSleep.ActiveKeepAwake;
@@ -259,8 +259,7 @@ export class QueueManager<
259
259
  ): Promise<QueueMessage[]> {
260
260
  this.#actor.assertReady();
261
261
  const limitedCount = Math.max(1, count);
262
- const nameSet =
263
- names && names.length > 0 ? new Set(names) : undefined;
262
+ const nameSet = names && names.length > 0 ? new Set(names) : undefined;
264
263
 
265
264
  const immediate = await this.#drainMessages(
266
265
  nameSet,
@@ -356,8 +355,7 @@ export class QueueManager<
356
355
  names: readonly string[] | undefined,
357
356
  abortSignal?: AbortSignal,
358
357
  ): Promise<void> {
359
- const nameSet =
360
- names && names.length > 0 ? new Set(names) : undefined;
358
+ const nameSet = names && names.length > 0 ? new Set(names) : undefined;
361
359
  const existing = await this.#loadQueueMessages();
362
360
  if (nameSet) {
363
361
  if (existing.some((message) => nameSet.has(message.name))) {
@@ -599,5 +597,4 @@ export class QueueManager<
599
597
  ACTOR_PERSIST_CURRENT_VERSION,
600
598
  );
601
599
  }
602
-
603
600
  }
@@ -17,7 +17,8 @@ export type QueueMessageOf<Name extends string, Body> = Omit<
17
17
  body: Body;
18
18
  };
19
19
 
20
- export type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues & string;
20
+ export type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues &
21
+ string;
21
22
  export type QueueFilterName<TQueues extends QueueSchemaConfig> =
22
23
  keyof TQueues extends never ? string : QueueName<TQueues>;
23
24
 
@@ -49,9 +50,7 @@ type QueueCompletableMessageForName<
49
50
  TQueues extends QueueSchemaConfig,
50
51
  TName extends QueueFilterName<TQueues>,
51
52
  > = QueueMessageForName<TQueues, TName> & {
52
- complete(
53
- ...args: QueueCompleteArgsForName<TQueues, TName>
54
- ): Promise<void>;
53
+ complete(...args: QueueCompleteArgsForName<TQueues, TName>): Promise<void>;
55
54
  };
56
55
 
57
56
  export type QueueResultMessageForName<
@@ -159,7 +158,9 @@ export class ActorQueue<
159
158
  const TCompletable extends boolean = false,
160
159
  >(
161
160
  opts?: QueueNextOptions<TName, TCompletable>,
162
- ): Promise<QueueResultMessageForName<TQueues, TName, TCompletable> | undefined> {
161
+ ): Promise<
162
+ QueueResultMessageForName<TQueues, TName, TCompletable> | undefined
163
+ > {
163
164
  const resolvedOpts = (opts ?? {}) as QueueNextOptions<
164
165
  TName,
165
166
  TCompletable
@@ -194,20 +195,16 @@ export class ActorQueue<
194
195
  resolvedOpts.signal,
195
196
  );
196
197
  const messages = await this.#queueManager
197
- .receive(
198
- names,
199
- count,
200
- resolvedOpts.timeout,
201
- signal,
202
- completable,
203
- )
198
+ .receive(names, count, resolvedOpts.timeout, signal, completable)
204
199
  .finally(cleanup);
205
200
  if (!completable) {
206
201
  return messages as Array<
207
202
  QueueResultMessageForName<TQueues, TName, TCompletable>
208
203
  >;
209
204
  }
210
- return messages.map((message) => this.#makeCompletableMessage(message)) as unknown as Array<
205
+ return messages.map((message) =>
206
+ this.#makeCompletableMessage(message),
207
+ ) as unknown as Array<
211
208
  QueueResultMessageForName<TQueues, TName, TCompletable>
212
209
  >;
213
210
  }
@@ -217,7 +214,9 @@ export class ActorQueue<
217
214
  const TCompletable extends boolean = false,
218
215
  >(
219
216
  opts?: QueueTryNextOptions<TName, TCompletable>,
220
- ): Promise<QueueResultMessageForName<TQueues, TName, TCompletable> | undefined> {
217
+ ): Promise<
218
+ QueueResultMessageForName<TQueues, TName, TCompletable> | undefined
219
+ > {
221
220
  const resolvedOpts = (opts ?? {}) as QueueTryNextOptions<
222
221
  TName,
223
222
  TCompletable
@@ -245,7 +244,9 @@ export class ActorQueue<
245
244
  count: resolvedOpts.count,
246
245
  timeout: 0,
247
246
  completable: true,
248
- })) as Array<QueueResultMessageForName<TQueues, TName, TCompletable>>;
247
+ })) as Array<
248
+ QueueResultMessageForName<TQueues, TName, TCompletable>
249
+ >;
249
250
  }
250
251
  return (await this.nextBatch<TName, false>({
251
252
  names: resolvedOpts.names,
@@ -268,16 +269,17 @@ export class ActorQueue<
268
269
  >;
269
270
  while (!this.#abortSignal.aborted) {
270
271
  try {
271
- const message = resolvedOpts.completable === true
272
- ? await this.next<TName, true>({
273
- names: resolvedOpts.names,
274
- signal: resolvedOpts.signal,
275
- completable: true,
276
- })
277
- : await this.next<TName, false>({
278
- names: resolvedOpts.names,
279
- signal: resolvedOpts.signal,
280
- });
272
+ const message =
273
+ resolvedOpts.completable === true
274
+ ? await this.next<TName, true>({
275
+ names: resolvedOpts.names,
276
+ signal: resolvedOpts.signal,
277
+ completable: true,
278
+ })
279
+ : await this.next<TName, false>({
280
+ names: resolvedOpts.names,
281
+ signal: resolvedOpts.signal,
282
+ });
281
283
  if (!message) {
282
284
  continue;
283
285
  }
@@ -308,16 +310,16 @@ export class ActorQueue<
308
310
  return await this.#queueManager.enqueue(name, body);
309
311
  }
310
312
 
311
- #normalizeNames(names: readonly string[] | undefined): string[] | undefined {
313
+ #normalizeNames(
314
+ names: readonly string[] | undefined,
315
+ ): string[] | undefined {
312
316
  if (!names || names.length === 0) {
313
317
  return undefined;
314
318
  }
315
319
  return [...new Set(names)];
316
320
  }
317
321
 
318
- #makeCompletableMessage(
319
- message: QueueMessage,
320
- ): QueueMessage & {
322
+ #makeCompletableMessage(message: QueueMessage): QueueMessage & {
321
323
  complete: (response?: unknown) => Promise<void>;
322
324
  } {
323
325
  const messageId = message.id.toString();
@@ -219,7 +219,13 @@ export class StateManager<
219
219
  } else {
220
220
  // Create promise for waiting
221
221
  if (!this.#onPersistSavedPromise) {
222
- this.#onPersistSavedPromise = promiseWithResolvers((reason) => loggerWithoutContext().warn({ msg: "unhandled persist saved promise rejection", reason }));
222
+ this.#onPersistSavedPromise = promiseWithResolvers(
223
+ (reason) =>
224
+ loggerWithoutContext().warn({
225
+ msg: "unhandled persist saved promise rejection",
226
+ reason,
227
+ }),
228
+ );
223
229
  }
224
230
 
225
231
  // Save throttled
@@ -13,14 +13,15 @@ function stripPrefix(prefix: Uint8Array, key: Uint8Array): Uint8Array {
13
13
  return key.slice(prefix.length);
14
14
  }
15
15
 
16
- function compareBytes(a: Uint8Array, b: Uint8Array): number {
17
- const len = Math.min(a.length, b.length);
18
- for (let i = 0; i < len; i++) {
19
- if (a[i] !== b[i]) {
20
- return a[i] - b[i];
16
+ function computeUpperBound(prefix: Uint8Array): Uint8Array | null {
17
+ const upperBound = prefix.slice();
18
+ for (let i = upperBound.length - 1; i >= 0; i--) {
19
+ if (upperBound[i] !== 0xff) {
20
+ upperBound[i]++;
21
+ return upperBound.slice(0, i + 1);
21
22
  }
22
23
  }
23
- return a.length - b.length;
24
+ return null;
24
25
  }
25
26
 
26
27
  export class ActorTracesDriver implements TracesDriver {
@@ -55,17 +56,26 @@ export class ActorTracesDriver implements TracesDriver {
55
56
 
56
57
  async deletePrefix(prefix: Uint8Array): Promise<void> {
57
58
  const fullPrefix = concatPrefix(this.#prefix, prefix);
58
- const entries = await this.#driver.kvListPrefix(
59
- this.#actorId,
60
- fullPrefix,
61
- );
62
- if (entries.length === 0) {
63
- return;
59
+ const fullEnd = computeUpperBound(fullPrefix);
60
+ if (fullEnd) {
61
+ await this.#driver.kvDeleteRange(
62
+ this.#actorId,
63
+ fullPrefix,
64
+ fullEnd,
65
+ );
66
+ } else {
67
+ const entries = await this.#driver.kvListPrefix(
68
+ this.#actorId,
69
+ fullPrefix,
70
+ );
71
+ if (entries.length === 0) {
72
+ return;
73
+ }
74
+ await this.#driver.kvBatchDelete(
75
+ this.#actorId,
76
+ entries.map(([key]) => key),
77
+ );
64
78
  }
65
- await this.#driver.kvBatchDelete(
66
- this.#actorId,
67
- entries.map(([key]) => key),
68
- );
69
79
  }
70
80
 
71
81
  async list(
@@ -87,33 +97,21 @@ export class ActorTracesDriver implements TracesDriver {
87
97
  end: Uint8Array,
88
98
  options?: { reverse?: boolean; limit?: number },
89
99
  ): Promise<Array<{ key: Uint8Array; value: Uint8Array }>> {
90
- const fullStart = concatPrefix(this.#prefix, start);
91
- const fullEnd = concatPrefix(this.#prefix, end);
92
- const entries = await this.#driver.kvListPrefix(
100
+ const entries = await this.#driver.kvListRange(
93
101
  this.#actorId,
94
- this.#prefix,
102
+ concatPrefix(this.#prefix, start),
103
+ concatPrefix(this.#prefix, end),
104
+ options,
95
105
  );
96
- const filtered = entries
97
- .filter(([key]) => {
98
- return (
99
- compareBytes(key, fullStart) >= 0 &&
100
- compareBytes(key, fullEnd) < 0
101
- );
102
- })
103
- .sort(([keyA], [keyB]) => compareBytes(keyA, keyB));
104
- if (options?.reverse) {
105
- filtered.reverse();
106
- }
107
- const limited = options?.limit
108
- ? filtered.slice(0, options.limit)
109
- : filtered;
110
- return limited.map(([key, value]) => ({
106
+ return entries.map(([key, value]) => ({
111
107
  key: stripPrefix(this.#prefix, key),
112
108
  value,
113
109
  }));
114
110
  }
115
111
 
116
- async batch(writes: Array<{ key: Uint8Array; value: Uint8Array }>): Promise<void> {
112
+ async batch(
113
+ writes: Array<{ key: Uint8Array; value: Uint8Array }>,
114
+ ): Promise<void> {
117
115
  if (writes.length === 0) {
118
116
  return;
119
117
  }