rivetkit 2.0.2 → 2.0.4-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 (403) hide show
  1. package/README.md +3 -5
  2. package/dist/browser/client.d.ts +2485 -0
  3. package/dist/browser/client.js +5182 -0
  4. package/dist/browser/client.js.map +1 -0
  5. package/dist/browser/inspector/client.d.ts +130 -0
  6. package/dist/browser/inspector/client.js +2854 -0
  7. package/dist/browser/inspector/client.js.map +1 -0
  8. package/dist/browser/v3-DnYObHH3.d.ts +279 -0
  9. package/dist/inspector.tar.gz +0 -0
  10. package/dist/schemas/actor-inspector/v1.ts +784 -0
  11. package/dist/schemas/actor-inspector/v2.ts +796 -0
  12. package/dist/schemas/actor-inspector/v3.ts +899 -0
  13. package/dist/schemas/actor-persist/v1.ts +225 -0
  14. package/dist/schemas/actor-persist/v2.ts +268 -0
  15. package/dist/schemas/actor-persist/v3.ts +280 -0
  16. package/dist/schemas/actor-persist/v4.ts +406 -0
  17. package/dist/schemas/client-protocol/v1.ts +441 -0
  18. package/dist/schemas/client-protocol/v2.ts +438 -0
  19. package/dist/schemas/client-protocol/v3.ts +554 -0
  20. package/dist/schemas/file-system-driver/v1.ts +108 -0
  21. package/dist/schemas/file-system-driver/v2.ts +142 -0
  22. package/dist/schemas/file-system-driver/v3.ts +167 -0
  23. package/dist/schemas/persist/v1.ts +781 -0
  24. package/dist/schemas/transport/v1.ts +697 -0
  25. package/dist/tsup/actor/errors.cjs +106 -0
  26. package/dist/tsup/actor/errors.cjs.map +1 -0
  27. package/dist/tsup/actor/errors.d.cts +188 -0
  28. package/dist/tsup/actor/errors.d.ts +188 -0
  29. package/dist/tsup/actor/errors.js +106 -0
  30. package/dist/tsup/actor/errors.js.map +1 -0
  31. package/dist/tsup/actor-router-consts-D29T1Z-K.d.cts +24 -0
  32. package/dist/tsup/actor-router-consts-D29T1Z-K.d.ts +24 -0
  33. package/dist/tsup/chunk-325TLXJT.js +1060 -0
  34. package/dist/tsup/chunk-325TLXJT.js.map +1 -0
  35. package/dist/tsup/chunk-424PT5DM.js +23 -0
  36. package/dist/tsup/chunk-424PT5DM.js.map +1 -0
  37. package/dist/tsup/chunk-4JVIG3SS.cjs +6289 -0
  38. package/dist/tsup/chunk-4JVIG3SS.cjs.map +1 -0
  39. package/dist/tsup/chunk-6LJAZ5R4.cjs +96 -0
  40. package/dist/tsup/chunk-6LJAZ5R4.cjs.map +1 -0
  41. package/dist/tsup/chunk-6XU3FMCB.cjs +534 -0
  42. package/dist/tsup/chunk-6XU3FMCB.cjs.map +1 -0
  43. package/dist/tsup/chunk-7HTNH26M.js +509 -0
  44. package/dist/tsup/chunk-7HTNH26M.js.map +1 -0
  45. package/dist/tsup/chunk-AUVH72RE.cjs +5977 -0
  46. package/dist/tsup/chunk-AUVH72RE.cjs.map +1 -0
  47. package/dist/tsup/chunk-D4BYUPNQ.js +645 -0
  48. package/dist/tsup/chunk-D4BYUPNQ.js.map +1 -0
  49. package/dist/tsup/chunk-HDQ2JUQT.cjs +23 -0
  50. package/dist/tsup/chunk-HDQ2JUQT.cjs.map +1 -0
  51. package/dist/tsup/chunk-HHXX2VRM.js +6289 -0
  52. package/dist/tsup/chunk-HHXX2VRM.js.map +1 -0
  53. package/dist/tsup/chunk-JEAEA2PB.js +49 -0
  54. package/dist/tsup/chunk-JEAEA2PB.js.map +1 -0
  55. package/dist/tsup/chunk-JYSEG3VF.cjs +642 -0
  56. package/dist/tsup/chunk-JYSEG3VF.cjs.map +1 -0
  57. package/dist/tsup/chunk-K6DGYILQ.js +2657 -0
  58. package/dist/tsup/chunk-K6DGYILQ.js.map +1 -0
  59. package/dist/tsup/chunk-KJSYAUOM.js +96 -0
  60. package/dist/tsup/chunk-KJSYAUOM.js.map +1 -0
  61. package/dist/tsup/chunk-L47L3ZWJ.cjs +509 -0
  62. package/dist/tsup/chunk-L47L3ZWJ.cjs.map +1 -0
  63. package/dist/tsup/chunk-LXUQ667X.js +2006 -0
  64. package/dist/tsup/chunk-LXUQ667X.js.map +1 -0
  65. package/dist/tsup/chunk-MXNPAB5W.js +5977 -0
  66. package/dist/tsup/chunk-MXNPAB5W.js.map +1 -0
  67. package/dist/tsup/chunk-N4KRDJ56.js +72 -0
  68. package/dist/tsup/chunk-N4KRDJ56.js.map +1 -0
  69. package/dist/tsup/chunk-NIYZDWMW.cjs +2006 -0
  70. package/dist/tsup/chunk-NIYZDWMW.cjs.map +1 -0
  71. package/dist/tsup/chunk-PQZHDKRW.cjs +1060 -0
  72. package/dist/tsup/chunk-PQZHDKRW.cjs.map +1 -0
  73. package/dist/tsup/chunk-PVOE6BU7.cjs +1050 -0
  74. package/dist/tsup/chunk-PVOE6BU7.cjs.map +1 -0
  75. package/dist/tsup/chunk-Q4UD2GA4.cjs +1810 -0
  76. package/dist/tsup/chunk-Q4UD2GA4.cjs.map +1 -0
  77. package/dist/tsup/chunk-QUD664YZ.js +1810 -0
  78. package/dist/tsup/chunk-QUD664YZ.js.map +1 -0
  79. package/dist/tsup/chunk-RTOCTWME.js +1050 -0
  80. package/dist/tsup/chunk-RTOCTWME.js.map +1 -0
  81. package/dist/tsup/chunk-SAZZ4SB2.cjs +2657 -0
  82. package/dist/tsup/chunk-SAZZ4SB2.cjs.map +1 -0
  83. package/dist/tsup/chunk-SR3KQE7Q.cjs +72 -0
  84. package/dist/tsup/chunk-SR3KQE7Q.cjs.map +1 -0
  85. package/dist/tsup/chunk-V2GHLYC6.cjs +49 -0
  86. package/dist/tsup/chunk-V2GHLYC6.cjs.map +1 -0
  87. package/dist/tsup/chunk-V3WG7XTW.cjs +645 -0
  88. package/dist/tsup/chunk-V3WG7XTW.cjs.map +1 -0
  89. package/dist/tsup/chunk-VKVNIQRQ.js +257 -0
  90. package/dist/tsup/chunk-VKVNIQRQ.js.map +1 -0
  91. package/dist/tsup/chunk-WMPW7JYC.js +642 -0
  92. package/dist/tsup/chunk-WMPW7JYC.js.map +1 -0
  93. package/dist/tsup/chunk-Z7HNQ2WF.js +534 -0
  94. package/dist/tsup/chunk-Z7HNQ2WF.js.map +1 -0
  95. package/dist/tsup/chunk-ZFY5J2EP.cjs +257 -0
  96. package/dist/tsup/chunk-ZFY5J2EP.cjs.map +1 -0
  97. package/dist/tsup/client/mod.cjs +33 -0
  98. package/dist/tsup/client/mod.cjs.map +1 -0
  99. package/dist/tsup/client/mod.d.cts +64 -0
  100. package/dist/tsup/client/mod.d.ts +64 -0
  101. package/dist/tsup/client/mod.js +33 -0
  102. package/dist/tsup/client/mod.js.map +1 -0
  103. package/dist/tsup/common/log.cjs +21 -0
  104. package/dist/tsup/common/log.cjs.map +1 -0
  105. package/dist/tsup/common/log.d.cts +34 -0
  106. package/dist/tsup/common/log.d.ts +34 -0
  107. package/dist/tsup/common/log.js +21 -0
  108. package/dist/tsup/common/log.js.map +1 -0
  109. package/dist/tsup/common/websocket.cjs +10 -0
  110. package/dist/tsup/common/websocket.cjs.map +1 -0
  111. package/dist/tsup/common/websocket.d.cts +3 -0
  112. package/dist/tsup/common/websocket.d.ts +3 -0
  113. package/dist/tsup/common/websocket.js +10 -0
  114. package/dist/tsup/common/websocket.js.map +1 -0
  115. package/dist/tsup/config-BiNoIHRs.d.cts +80 -0
  116. package/dist/tsup/config-BiNoIHRs.d.ts +80 -0
  117. package/dist/tsup/config-P3XujgRr.d.ts +2594 -0
  118. package/dist/tsup/config-_gfywqqI.d.cts +2594 -0
  119. package/dist/tsup/context-Bxd8Cx4H.d.cts +75 -0
  120. package/dist/tsup/context-uNA4TRn3.d.ts +75 -0
  121. package/dist/tsup/db/drizzle/mod.cjs +49 -0
  122. package/dist/tsup/db/drizzle/mod.cjs.map +1 -0
  123. package/dist/tsup/db/drizzle/mod.d.cts +17 -0
  124. package/dist/tsup/db/drizzle/mod.d.ts +17 -0
  125. package/dist/tsup/db/drizzle/mod.js +49 -0
  126. package/dist/tsup/db/drizzle/mod.js.map +1 -0
  127. package/dist/tsup/db/mod.cjs +9 -0
  128. package/dist/tsup/db/mod.cjs.map +1 -0
  129. package/dist/tsup/db/mod.d.cts +9 -0
  130. package/dist/tsup/db/mod.d.ts +9 -0
  131. package/dist/tsup/db/mod.js +9 -0
  132. package/dist/tsup/db/mod.js.map +1 -0
  133. package/dist/tsup/driver-BcLvZcKl.d.cts +13 -0
  134. package/dist/tsup/driver-CPGHKXyh.d.ts +13 -0
  135. package/dist/tsup/driver-helpers/mod.cjs +53 -0
  136. package/dist/tsup/driver-helpers/mod.cjs.map +1 -0
  137. package/dist/tsup/driver-helpers/mod.d.cts +47 -0
  138. package/dist/tsup/driver-helpers/mod.d.ts +47 -0
  139. package/dist/tsup/driver-helpers/mod.js +53 -0
  140. package/dist/tsup/driver-helpers/mod.js.map +1 -0
  141. package/dist/tsup/driver-test-suite/mod.cjs +4974 -0
  142. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -0
  143. package/dist/tsup/driver-test-suite/mod.d.cts +73 -0
  144. package/dist/tsup/driver-test-suite/mod.d.ts +73 -0
  145. package/dist/tsup/driver-test-suite/mod.js +4974 -0
  146. package/dist/tsup/driver-test-suite/mod.js.map +1 -0
  147. package/dist/tsup/inspector/mod.cjs +164 -0
  148. package/dist/tsup/inspector/mod.cjs.map +1 -0
  149. package/dist/tsup/inspector/mod.d.cts +130 -0
  150. package/dist/tsup/inspector/mod.d.ts +130 -0
  151. package/dist/tsup/inspector/mod.js +164 -0
  152. package/dist/tsup/inspector/mod.js.map +1 -0
  153. package/dist/tsup/keys-CydblqMh.d.cts +13 -0
  154. package/dist/tsup/keys-CydblqMh.d.ts +13 -0
  155. package/dist/tsup/mod.cjs +82 -0
  156. package/dist/tsup/mod.cjs.map +1 -0
  157. package/dist/tsup/mod.d.cts +126 -0
  158. package/dist/tsup/mod.d.ts +126 -0
  159. package/dist/tsup/mod.js +82 -0
  160. package/dist/tsup/mod.js.map +1 -0
  161. package/dist/tsup/serve-test-suite/mod.cjs +2601 -0
  162. package/dist/tsup/serve-test-suite/mod.cjs.map +1 -0
  163. package/dist/tsup/serve-test-suite/mod.d.cts +9 -0
  164. package/dist/tsup/serve-test-suite/mod.d.ts +9 -0
  165. package/dist/tsup/serve-test-suite/mod.js +2601 -0
  166. package/dist/tsup/serve-test-suite/mod.js.map +1 -0
  167. package/dist/tsup/test/mod.cjs +90 -0
  168. package/dist/tsup/test/mod.cjs.map +1 -0
  169. package/dist/tsup/test/mod.d.cts +26 -0
  170. package/dist/tsup/test/mod.d.ts +26 -0
  171. package/dist/tsup/test/mod.js +90 -0
  172. package/dist/tsup/test/mod.js.map +1 -0
  173. package/dist/tsup/utils-fwx3o3K9.d.cts +18 -0
  174. package/dist/tsup/utils-fwx3o3K9.d.ts +18 -0
  175. package/dist/tsup/utils.cjs +43 -0
  176. package/dist/tsup/utils.cjs.map +1 -0
  177. package/dist/tsup/utils.d.cts +148 -0
  178. package/dist/tsup/utils.d.ts +148 -0
  179. package/dist/tsup/utils.js +43 -0
  180. package/dist/tsup/utils.js.map +1 -0
  181. package/dist/tsup/v3-DnYObHH3.d.cts +279 -0
  182. package/dist/tsup/v3-DnYObHH3.d.ts +279 -0
  183. package/dist/tsup/workflow/mod.cjs +16 -0
  184. package/dist/tsup/workflow/mod.cjs.map +1 -0
  185. package/dist/tsup/workflow/mod.d.cts +25 -0
  186. package/dist/tsup/workflow/mod.d.ts +25 -0
  187. package/dist/tsup/workflow/mod.js +16 -0
  188. package/dist/tsup/workflow/mod.js.map +1 -0
  189. package/package.json +293 -5
  190. package/src/actor/config.ts +1221 -0
  191. package/src/actor/conn/driver.ts +61 -0
  192. package/src/actor/conn/drivers/http.ts +17 -0
  193. package/src/actor/conn/drivers/raw-request.ts +24 -0
  194. package/src/actor/conn/drivers/raw-websocket.ts +65 -0
  195. package/src/actor/conn/drivers/websocket.ts +144 -0
  196. package/src/actor/conn/mod.ts +288 -0
  197. package/src/actor/conn/persisted.ts +81 -0
  198. package/src/actor/conn/state-manager.ts +196 -0
  199. package/src/actor/contexts/action.ts +47 -0
  200. package/src/actor/contexts/base/actor.ts +347 -0
  201. package/src/actor/contexts/base/conn-init.ts +68 -0
  202. package/src/actor/contexts/base/conn.ts +73 -0
  203. package/src/actor/contexts/before-action-response.ts +42 -0
  204. package/src/actor/contexts/before-connect.ts +31 -0
  205. package/src/actor/contexts/connect.ts +42 -0
  206. package/src/actor/contexts/create-conn-state.ts +32 -0
  207. package/src/actor/contexts/create-vars.ts +39 -0
  208. package/src/actor/contexts/create.ts +39 -0
  209. package/src/actor/contexts/destroy.ts +42 -0
  210. package/src/actor/contexts/disconnect.ts +43 -0
  211. package/src/actor/contexts/index.ts +33 -0
  212. package/src/actor/contexts/request.ts +80 -0
  213. package/src/actor/contexts/run.ts +47 -0
  214. package/src/actor/contexts/sleep.ts +42 -0
  215. package/src/actor/contexts/state-change.ts +42 -0
  216. package/src/actor/contexts/wake.ts +42 -0
  217. package/src/actor/contexts/websocket.ts +80 -0
  218. package/src/actor/database.ts +13 -0
  219. package/src/actor/definition.ts +64 -0
  220. package/src/actor/driver.ts +114 -0
  221. package/src/actor/errors.ts +556 -0
  222. package/src/actor/instance/connection-manager.ts +574 -0
  223. package/src/actor/instance/event-manager.ts +314 -0
  224. package/src/actor/instance/keys.ts +146 -0
  225. package/src/actor/instance/kv.ts +241 -0
  226. package/src/actor/instance/mod.ts +1658 -0
  227. package/src/actor/instance/persisted.ts +67 -0
  228. package/src/actor/instance/queue-manager.ts +603 -0
  229. package/src/actor/instance/queue.ts +345 -0
  230. package/src/actor/instance/schedule-manager.ts +392 -0
  231. package/src/actor/instance/state-manager.ts +542 -0
  232. package/src/actor/instance/traces-driver.ts +128 -0
  233. package/src/actor/keys.test.ts +275 -0
  234. package/src/actor/keys.ts +89 -0
  235. package/src/actor/log.ts +6 -0
  236. package/src/actor/mod.ts +110 -0
  237. package/src/actor/protocol/old.ts +416 -0
  238. package/src/actor/protocol/serde.ts +222 -0
  239. package/src/actor/router-endpoints.ts +400 -0
  240. package/src/actor/router-websocket-endpoints.test.ts +54 -0
  241. package/src/actor/router-websocket-endpoints.ts +405 -0
  242. package/src/actor/router.ts +380 -0
  243. package/src/actor/schedule.ts +17 -0
  244. package/src/actor/schema.ts +291 -0
  245. package/src/actor/utils.test.ts +48 -0
  246. package/src/actor/utils.ts +158 -0
  247. package/src/client/actor-common.ts +32 -0
  248. package/src/client/actor-conn.ts +1262 -0
  249. package/src/client/actor-handle.ts +344 -0
  250. package/src/client/actor-query.ts +112 -0
  251. package/src/client/client.ts +558 -0
  252. package/src/client/config.ts +151 -0
  253. package/src/client/errors.ts +76 -0
  254. package/src/client/log.ts +5 -0
  255. package/src/client/mod.browser.ts +2 -0
  256. package/src/client/mod.ts +70 -0
  257. package/src/client/queue.ts +146 -0
  258. package/src/client/raw-utils.ts +149 -0
  259. package/src/client/test.ts +44 -0
  260. package/src/client/utils.ts +252 -0
  261. package/src/common/actor-router-consts.ts +59 -0
  262. package/src/common/cors.ts +57 -0
  263. package/src/common/eventsource-interface.ts +47 -0
  264. package/src/common/eventsource.ts +44 -0
  265. package/src/common/inline-websocket-adapter.ts +154 -0
  266. package/src/common/log-levels.ts +27 -0
  267. package/src/common/log.ts +229 -0
  268. package/src/common/logfmt.ts +221 -0
  269. package/src/common/network.ts +2 -0
  270. package/src/common/router.ts +174 -0
  271. package/src/common/utils.ts +339 -0
  272. package/src/common/websocket-interface.ts +7 -0
  273. package/src/common/websocket.ts +43 -0
  274. package/src/db/config.ts +100 -0
  275. package/src/db/drizzle/mod.ts +226 -0
  276. package/src/db/drizzle/sqlite-core.ts +22 -0
  277. package/src/db/mod.ts +125 -0
  278. package/src/db/shared.ts +92 -0
  279. package/src/db/sqlite-vfs.ts +12 -0
  280. package/src/devtools-loader/index.ts +33 -0
  281. package/src/devtools-loader/log.ts +5 -0
  282. package/src/driver-helpers/mod.ts +33 -0
  283. package/src/driver-helpers/utils.ts +54 -0
  284. package/src/driver-test-suite/log.ts +5 -0
  285. package/src/driver-test-suite/mod.ts +293 -0
  286. package/src/driver-test-suite/test-inline-client-driver.ts +307 -0
  287. package/src/driver-test-suite/tests/access-control.ts +218 -0
  288. package/src/driver-test-suite/tests/action-features.ts +203 -0
  289. package/src/driver-test-suite/tests/actor-conn-hibernation.ts +152 -0
  290. package/src/driver-test-suite/tests/actor-conn-state.ts +300 -0
  291. package/src/driver-test-suite/tests/actor-conn.ts +596 -0
  292. package/src/driver-test-suite/tests/actor-db-raw.ts +73 -0
  293. package/src/driver-test-suite/tests/actor-db.ts +477 -0
  294. package/src/driver-test-suite/tests/actor-destroy.ts +294 -0
  295. package/src/driver-test-suite/tests/actor-driver.ts +18 -0
  296. package/src/driver-test-suite/tests/actor-error-handling.ts +150 -0
  297. package/src/driver-test-suite/tests/actor-handle.ts +312 -0
  298. package/src/driver-test-suite/tests/actor-inline-client.ts +163 -0
  299. package/src/driver-test-suite/tests/actor-inspector.ts +264 -0
  300. package/src/driver-test-suite/tests/actor-kv.ts +65 -0
  301. package/src/driver-test-suite/tests/actor-metadata.ts +116 -0
  302. package/src/driver-test-suite/tests/actor-onstatechange.ts +95 -0
  303. package/src/driver-test-suite/tests/actor-queue.ts +325 -0
  304. package/src/driver-test-suite/tests/actor-run.ts +181 -0
  305. package/src/driver-test-suite/tests/actor-schedule.ts +97 -0
  306. package/src/driver-test-suite/tests/actor-sleep.ts +415 -0
  307. package/src/driver-test-suite/tests/actor-state.ts +54 -0
  308. package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
  309. package/src/driver-test-suite/tests/actor-vars.ts +97 -0
  310. package/src/driver-test-suite/tests/actor-workflow.ts +118 -0
  311. package/src/driver-test-suite/tests/manager-driver.ts +388 -0
  312. package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -0
  313. package/src/driver-test-suite/tests/raw-http-request-properties.ts +454 -0
  314. package/src/driver-test-suite/tests/raw-http.ts +359 -0
  315. package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -0
  316. package/src/driver-test-suite/tests/raw-websocket.ts +513 -0
  317. package/src/driver-test-suite/tests/request-access.ts +240 -0
  318. package/src/driver-test-suite/utils.ts +80 -0
  319. package/src/drivers/default.ts +38 -0
  320. package/src/drivers/engine/actor-driver.ts +1027 -0
  321. package/src/drivers/engine/config.ts +43 -0
  322. package/src/drivers/engine/log.ts +5 -0
  323. package/src/drivers/engine/mod.ts +36 -0
  324. package/src/drivers/file-system/actor.ts +102 -0
  325. package/src/drivers/file-system/global-state.ts +1445 -0
  326. package/src/drivers/file-system/kv-limits.ts +70 -0
  327. package/src/drivers/file-system/log.ts +5 -0
  328. package/src/drivers/file-system/manager.ts +300 -0
  329. package/src/drivers/file-system/mod.ts +78 -0
  330. package/src/drivers/file-system/sqlite-runtime.ts +210 -0
  331. package/src/drivers/file-system/utils.ts +125 -0
  332. package/src/engine-process/constants.ts +2 -0
  333. package/src/engine-process/log.ts +5 -0
  334. package/src/engine-process/mod.ts +464 -0
  335. package/src/globals.d.ts +35 -0
  336. package/src/inspector/actor-inspector.ts +352 -0
  337. package/src/inspector/config.ts +49 -0
  338. package/src/inspector/handler.ts +273 -0
  339. package/src/inspector/log.ts +5 -0
  340. package/src/inspector/mod.browser.ts +8 -0
  341. package/src/inspector/mod.ts +4 -0
  342. package/src/inspector/serve-ui.ts +40 -0
  343. package/src/inspector/transport.ts +18 -0
  344. package/src/inspector/utils.ts +32 -0
  345. package/src/manager/driver.ts +106 -0
  346. package/src/manager/gateway.ts +668 -0
  347. package/src/manager/log.ts +5 -0
  348. package/src/manager/mod.ts +2 -0
  349. package/src/manager/protocol/mod.ts +22 -0
  350. package/src/manager/protocol/query.ts +85 -0
  351. package/src/manager/router-schema.ts +22 -0
  352. package/src/manager/router.ts +660 -0
  353. package/src/manager-api/actors.ts +83 -0
  354. package/src/manager-api/common.ts +4 -0
  355. package/src/mod.ts +24 -0
  356. package/src/registry/config/driver.ts +21 -0
  357. package/src/registry/config/index.ts +510 -0
  358. package/src/registry/config/legacy-runner.ts +157 -0
  359. package/src/registry/config/runner.ts +21 -0
  360. package/src/registry/config/serverless.ts +94 -0
  361. package/src/registry/index.ts +194 -0
  362. package/src/registry/log.ts +5 -0
  363. package/src/remote-manager-driver/actor-http-client.ts +84 -0
  364. package/src/remote-manager-driver/actor-websocket-client.ts +81 -0
  365. package/src/remote-manager-driver/api-endpoints.ts +159 -0
  366. package/src/remote-manager-driver/api-utils.ts +69 -0
  367. package/src/remote-manager-driver/log.ts +5 -0
  368. package/src/remote-manager-driver/metadata.ts +64 -0
  369. package/src/remote-manager-driver/mod.ts +414 -0
  370. package/src/remote-manager-driver/ws-proxy.ts +189 -0
  371. package/src/schemas/actor-inspector/mod.ts +1 -0
  372. package/src/schemas/actor-inspector/versioned.ts +233 -0
  373. package/src/schemas/actor-persist/mod.ts +1 -0
  374. package/src/schemas/actor-persist/versioned.ts +217 -0
  375. package/src/schemas/client-protocol/mod.ts +1 -0
  376. package/src/schemas/client-protocol/versioned.ts +330 -0
  377. package/src/schemas/client-protocol-zod/mod.ts +118 -0
  378. package/src/schemas/file-system-driver/mod.ts +1 -0
  379. package/src/schemas/file-system-driver/versioned.ts +135 -0
  380. package/src/schemas/persist/mod.ts +1 -0
  381. package/src/schemas/transport/mod.ts +1 -0
  382. package/src/serde.ts +138 -0
  383. package/src/serve-test-suite/mod.ts +148 -0
  384. package/src/serverless/configure.ts +82 -0
  385. package/src/serverless/log.ts +5 -0
  386. package/src/serverless/router.test.ts +299 -0
  387. package/src/serverless/router.ts +215 -0
  388. package/src/test/log.ts +5 -0
  389. package/src/test/mod.ts +99 -0
  390. package/src/utils/crypto.ts +24 -0
  391. package/src/utils/endpoint-parser.test.ts +202 -0
  392. package/src/utils/endpoint-parser.ts +124 -0
  393. package/src/utils/env-vars.ts +78 -0
  394. package/src/utils/node.ts +178 -0
  395. package/src/utils/router.ts +83 -0
  396. package/src/utils/serve.ts +212 -0
  397. package/src/utils.test.ts +34 -0
  398. package/src/utils.ts +437 -0
  399. package/src/workflow/constants.ts +2 -0
  400. package/src/workflow/context.ts +597 -0
  401. package/src/workflow/driver.ts +194 -0
  402. package/src/workflow/inspector.ts +268 -0
  403. package/src/workflow/mod.ts +128 -0
@@ -0,0 +1,229 @@
1
+ import {
2
+ type LevelWithSilent,
3
+ type Logger,
4
+ pino,
5
+ stdTimeFunctions,
6
+ } from "pino";
7
+ import { z } from "zod/v4";
8
+ import { getLogLevel, getLogTarget, getLogTimestamp } from "@/utils/env-vars";
9
+ import {
10
+ castToLogValue,
11
+ formatTimestamp,
12
+ LOGGER_CONFIG,
13
+ stringify,
14
+ } from "./logfmt";
15
+
16
+ export type { Logger } from "pino";
17
+
18
+ let baseLogger: Logger | undefined;
19
+ let configuredLogLevel: LogLevel | undefined;
20
+
21
+ /** Cache of child loggers by logger name. */
22
+ const loggerCache = new Map<string, Logger>();
23
+
24
+ export const LogLevelSchema = z.enum([
25
+ "trace",
26
+ "debug",
27
+ "info",
28
+ "warn",
29
+ "error",
30
+ "fatal",
31
+ "silent",
32
+ ]);
33
+
34
+ export type LogLevel = z.infer<typeof LogLevelSchema>;
35
+
36
+ export function getPinoLevel(logLevel?: LogLevel): LevelWithSilent {
37
+ // Priority: provided > configured > env > default
38
+ if (logLevel) {
39
+ return logLevel;
40
+ }
41
+
42
+ if (configuredLogLevel) {
43
+ return configuredLogLevel;
44
+ }
45
+
46
+ const raw = (getLogLevel() || "warn").toString().toLowerCase();
47
+
48
+ const parsed = LogLevelSchema.safeParse(raw);
49
+ if (parsed.success) {
50
+ return parsed.data;
51
+ }
52
+
53
+ // Default to info if invalid
54
+ return "info";
55
+ }
56
+
57
+ export function getIncludeTarget(): boolean {
58
+ return getLogTarget();
59
+ }
60
+
61
+ /**
62
+ * Configure a custom base logger.
63
+ */
64
+ export function configureBaseLogger(logger: Logger): void {
65
+ baseLogger = logger;
66
+ loggerCache.clear();
67
+ }
68
+
69
+ // TODO: This can be simplified in logfmt.ts
70
+ function customWrite(level: string, o: any) {
71
+ const entries: any = {};
72
+
73
+ // Add timestamp if enabled
74
+ if (getLogTimestamp() && o.time) {
75
+ const date = typeof o.time === "number" ? new Date(o.time) : new Date();
76
+ entries.ts = formatTimestamp(date);
77
+ }
78
+
79
+ // Add level
80
+ entries.level = level.toUpperCase();
81
+
82
+ // Add target if present
83
+ if (o.target) {
84
+ entries.target = o.target;
85
+ }
86
+
87
+ // Add message
88
+ if (o.msg) {
89
+ entries.msg = o.msg;
90
+ }
91
+
92
+ // Add other properties
93
+ for (const [key, value] of Object.entries(o)) {
94
+ if (
95
+ key !== "time" &&
96
+ key !== "level" &&
97
+ key !== "target" &&
98
+ key !== "msg" &&
99
+ key !== "pid" &&
100
+ key !== "hostname"
101
+ ) {
102
+ entries[key] = castToLogValue(value);
103
+ }
104
+ }
105
+
106
+ const output = stringify(entries);
107
+ console.log(output);
108
+ }
109
+
110
+ /**
111
+ * Configure the default logger with optional log level.
112
+ */
113
+ export function configureDefaultLogger(logLevel?: LogLevel) {
114
+ // Store the configured log level
115
+ if (logLevel) {
116
+ configuredLogLevel = logLevel;
117
+ }
118
+
119
+ baseLogger = pino({
120
+ level: getPinoLevel(logLevel),
121
+ messageKey: "msg",
122
+ // Do not include pid/hostname in output
123
+ base: {},
124
+ // Keep a string level in the output
125
+ formatters: {
126
+ level(_label: string, number: number) {
127
+ return { level: number };
128
+ },
129
+ },
130
+ timestamp: getLogTimestamp() ? stdTimeFunctions.epochTime : false,
131
+ browser: {
132
+ write: {
133
+ fatal: customWrite.bind(null, "fatal"),
134
+ error: customWrite.bind(null, "error"),
135
+ warn: customWrite.bind(null, "warn"),
136
+ info: customWrite.bind(null, "info"),
137
+ debug: customWrite.bind(null, "debug"),
138
+ trace: customWrite.bind(null, "trace"),
139
+ },
140
+ },
141
+ hooks: {
142
+ logMethod(inputArgs, method, level) {
143
+ // TODO: This is a hack to not implement our own Pino transport target. We can get better perf if we have our own transport target.
144
+
145
+ const levelMap: Record<number, string> = {
146
+ 10: "trace",
147
+ 20: "debug",
148
+ 30: "info",
149
+ 40: "warn",
150
+ 50: "error",
151
+ 60: "fatal",
152
+ };
153
+ const levelName = levelMap[level] || "info";
154
+ const time = getLogTimestamp() ? Date.now() : undefined;
155
+
156
+ // Get bindings from the logger instance (child logger fields)
157
+ const bindings = (this as any).bindings?.() || {};
158
+
159
+ // TODO: This can be simplified in logfmt.ts
160
+ if (inputArgs.length >= 2) {
161
+ const [objOrMsg, msg] = inputArgs;
162
+ if (typeof objOrMsg === "object" && objOrMsg !== null) {
163
+ customWrite(levelName, {
164
+ ...bindings,
165
+ ...objOrMsg,
166
+ msg,
167
+ time,
168
+ });
169
+ } else {
170
+ customWrite(levelName, {
171
+ ...bindings,
172
+ msg: String(objOrMsg),
173
+ time,
174
+ });
175
+ }
176
+ } else if (inputArgs.length === 1) {
177
+ const [objOrMsg] = inputArgs;
178
+ if (typeof objOrMsg === "object" && objOrMsg !== null) {
179
+ customWrite(levelName, {
180
+ ...bindings,
181
+ ...objOrMsg,
182
+ time,
183
+ });
184
+ } else {
185
+ customWrite(levelName, {
186
+ ...bindings,
187
+ msg: String(objOrMsg),
188
+ time,
189
+ });
190
+ }
191
+ }
192
+ },
193
+ },
194
+ });
195
+
196
+ loggerCache.clear();
197
+ }
198
+
199
+ /**
200
+ * Get or initialize the base logger.
201
+ */
202
+ export function getBaseLogger(): Logger {
203
+ if (!baseLogger) {
204
+ configureDefaultLogger();
205
+ }
206
+ return baseLogger!;
207
+ }
208
+
209
+ /**
210
+ * Returns a child logger with `target` bound for the given name.
211
+ */
212
+ export function getLogger(name = "default"): Logger {
213
+ // Check cache first
214
+ const cached = loggerCache.get(name);
215
+ if (cached) {
216
+ return cached;
217
+ }
218
+
219
+ // Create
220
+ const base = getBaseLogger();
221
+
222
+ // Add target to log if enabled
223
+ const child = getIncludeTarget() ? base.child({ target: name }) : base;
224
+
225
+ // Cache the logger
226
+ loggerCache.set(name, child);
227
+
228
+ return child;
229
+ }
@@ -0,0 +1,221 @@
1
+ import { type LogLevel, LogLevels } from "./log-levels";
2
+
3
+ const LOG_LEVEL_COLORS: Record<number, string> = {
4
+ [LogLevels.CRITICAL]: "\x1b[31m", // Red
5
+ [LogLevels.ERROR]: "\x1b[31m", // Red
6
+ [LogLevels.WARN]: "\x1b[33m", // Yellow
7
+ [LogLevels.INFO]: "\x1b[32m", // Green
8
+ [LogLevels.DEBUG]: "\x1b[36m", // Cyan
9
+ [LogLevels.TRACE]: "\x1b[36m", // Cyan
10
+ };
11
+
12
+ const RESET_COLOR = "\x1b[0m";
13
+
14
+ /**
15
+ * Serializes logfmt line from an object.
16
+ *
17
+ * ## Styling Methodology
18
+ *
19
+ * The three things you need to know for every log line is the level, the
20
+ * message, and who called it. These properties are highlighted in different colros
21
+ * and sorted in th eorder that you usually read them.
22
+ *
23
+ * Once you've found a log line you care about, then you want to find the
24
+ * property you need to see. The property names are bolded and the default color
25
+ * while the rest of the data is dim. This lets you scan to find the property
26
+ * name quickly then look closer to read the data associated with the
27
+ * property.
28
+ */
29
+ export function stringify(data: any) {
30
+ let line = "";
31
+ const entries = Object.entries(data);
32
+
33
+ for (let i = 0; i < entries.length; i++) {
34
+ const [key, valueRaw] = entries[i];
35
+
36
+ let isNull = false;
37
+ let valueString: string;
38
+ if (valueRaw == null) {
39
+ isNull = true;
40
+ valueString = "";
41
+ } else {
42
+ valueString = valueRaw.toString();
43
+ }
44
+
45
+ // Clip value unless specifically the error message
46
+ if (valueString.length > 512 && key !== "msg" && key !== "error")
47
+ valueString = `${valueString.slice(0, 512)}...`;
48
+
49
+ const needsQuoting =
50
+ valueString.indexOf(" ") > -1 || valueString.indexOf("=") > -1;
51
+ const needsEscaping =
52
+ valueString.indexOf('"') > -1 || valueString.indexOf("\\") > -1;
53
+
54
+ valueString = valueString.replace(/\n/g, "\\n");
55
+ if (needsEscaping) valueString = valueString.replace(/["\\]/g, "\\$&");
56
+ if (needsQuoting || needsEscaping) valueString = `"${valueString}"`;
57
+ if (valueString === "" && !isNull) valueString = '""';
58
+
59
+ if (LOGGER_CONFIG.enableColor) {
60
+ // With color
61
+
62
+ // Special message colors
63
+ let color = "\x1b[2m";
64
+ if (key === "level") {
65
+ const level = LogLevels[valueString as LogLevel];
66
+ const levelColor = LOG_LEVEL_COLORS[level];
67
+ if (levelColor) {
68
+ color = levelColor;
69
+ }
70
+ } else if (key === "msg") {
71
+ color = "\x1b[32m";
72
+ } else if (key === "trace") {
73
+ color = "\x1b[34m";
74
+ }
75
+
76
+ // Format line
77
+ line += `\x1b[0m\x1b[1m${key}\x1b[0m\x1b[2m=\x1b[0m${color}${valueString}${RESET_COLOR}`;
78
+ } else {
79
+ // No color
80
+ line += `${key}=${valueString}`;
81
+ }
82
+
83
+ if (i !== entries.length - 1) {
84
+ line += " ";
85
+ }
86
+ }
87
+
88
+ return line;
89
+ }
90
+
91
+ export function formatTimestamp(date: Date): string {
92
+ const year = date.getUTCFullYear();
93
+ const month = String(date.getUTCMonth() + 1).padStart(2, "0");
94
+ const day = String(date.getUTCDate()).padStart(2, "0");
95
+ const hours = String(date.getUTCHours()).padStart(2, "0");
96
+ const minutes = String(date.getUTCMinutes()).padStart(2, "0");
97
+ const seconds = String(date.getUTCSeconds()).padStart(2, "0");
98
+ const milliseconds = String(date.getUTCMilliseconds()).padStart(3, "0");
99
+
100
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`;
101
+ }
102
+
103
+ export function castToLogValue(v: unknown): any {
104
+ if (
105
+ typeof v === "string" ||
106
+ typeof v === "number" ||
107
+ typeof v === "bigint" ||
108
+ typeof v === "boolean" ||
109
+ v === null ||
110
+ v === undefined
111
+ ) {
112
+ return v;
113
+ }
114
+ if (v instanceof Error) {
115
+ //args.push(...errorToLogEntries(k, v));
116
+ return String(v);
117
+ }
118
+ try {
119
+ return JSON.stringify(v);
120
+ } catch {
121
+ return "[cannot stringify]";
122
+ }
123
+ }
124
+
125
+ // MARK: Config
126
+ interface GlobalLoggerConfig {
127
+ enableColor: boolean;
128
+ enableSpreadObject: boolean;
129
+ enableErrorStack: boolean;
130
+ }
131
+
132
+ export const LOGGER_CONFIG: GlobalLoggerConfig = {
133
+ enableColor: false,
134
+ enableSpreadObject: false,
135
+ enableErrorStack: false,
136
+ };
137
+
138
+ // MARK: Utils
139
+ /**
140
+ * Converts an object in to an easier to read KV of entries.
141
+ */
142
+ export function spreadObjectToLogEntries(base: string, data: unknown): any {
143
+ if (
144
+ LOGGER_CONFIG.enableSpreadObject &&
145
+ typeof data === "object" &&
146
+ !Array.isArray(data) &&
147
+ data !== null &&
148
+ Object.keys(data).length !== 0 &&
149
+ Object.keys(data).length < 16
150
+ ) {
151
+ const logData: any = {};
152
+ for (const key in data) {
153
+ Object.assign(
154
+ logData,
155
+ spreadObjectToLogEntries(
156
+ `${base}.${key}`,
157
+ // biome-ignore lint/suspicious/noExplicitAny: FIXME
158
+ (data as any)[key],
159
+ ),
160
+ );
161
+ }
162
+ return logData;
163
+ }
164
+
165
+ return { [base]: JSON.stringify(data) };
166
+ }
167
+
168
+ export function errorToLogEntries(base: string, error: unknown): any {
169
+ if (error instanceof Error) {
170
+ return {
171
+ [`${base}.message`]: error.message,
172
+ ...(LOGGER_CONFIG.enableErrorStack && error.stack
173
+ ? { [`${base}.stack`]: formatStackTrace(error.stack) }
174
+ : {}),
175
+ ...(error.cause
176
+ ? errorToLogEntries(`${base}.cause`, error.cause)
177
+ : {}),
178
+ };
179
+ }
180
+ return { [base]: `${error}` };
181
+ }
182
+
183
+ // export function errorToLogEntries(base: string, error: unknown): LogEntry[] {
184
+ // if (error instanceof RuntimeError) {
185
+ // return [
186
+ // [`${base}.code`, error.code],
187
+ // [`${base}.description`, error.errorConfig?.description],
188
+ // [`${base}.module`, error.moduleName],
189
+ // ...(error.trace ? [[`${base}.trace`, stringifyTrace(error.trace)] as LogEntry] : []),
190
+ // ...(LOGGER_CONFIG.enableErrorStack && error.stack
191
+ // ? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]
192
+ // : []),
193
+ // ...(error.meta ? [[`${base}.meta`, JSON.stringify(error.meta)] as LogEntry] : []),
194
+ // ...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),
195
+ // ];
196
+ // } else if (error instanceof Error) {
197
+ // return [
198
+ // [`${base}.name`, error.name],
199
+ // [`${base}.message`, error.message],
200
+ // ...(LOGGER_CONFIG.enableErrorStack && error.stack
201
+ // ? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]
202
+ // : []),
203
+ // ...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),
204
+ // ];
205
+ // } else {
206
+ // return [
207
+ // [base, `${error}`],
208
+ // ];
209
+ // }
210
+ // }
211
+
212
+ /**
213
+ * Formats a JS stack trace in to a legible one-liner.
214
+ */
215
+ function formatStackTrace(stackTrace: string): string {
216
+ const regex = /at (.+?)$/gm;
217
+ const matches = [...stackTrace.matchAll(regex)];
218
+ // Reverse array since the stack goes from top level -> bottom level
219
+ matches.reverse();
220
+ return matches.map((match) => match[1].trim()).join(" > ");
221
+ }
@@ -0,0 +1,2 @@
1
+ /** Only enforced client-side in order to prevent building malformed URLs. */
2
+ export const MAX_CONN_PARAMS_SIZE = 4096;
@@ -0,0 +1,174 @@
1
+ import * as cbor from "cbor-x";
2
+ import type { Context as HonoContext, Next } from "hono";
3
+ import type { Encoding } from "@/actor/protocol/serde";
4
+ import {
5
+ getRequestEncoding,
6
+ getRequestExposeInternalError,
7
+ } from "@/actor/router-endpoints";
8
+ import {
9
+ buildActorNames,
10
+ type RegistryConfig,
11
+ } from "@/registry/config";
12
+ import type * as protocol from "@/schemas/client-protocol/mod";
13
+ import {
14
+ CURRENT_VERSION as CLIENT_PROTOCOL_CURRENT_VERSION,
15
+ HTTP_RESPONSE_ERROR_VERSIONED,
16
+ } from "@/schemas/client-protocol/versioned";
17
+ import {
18
+ type HttpResponseError as HttpResponseErrorJson,
19
+ HttpResponseErrorSchema,
20
+ } from "@/schemas/client-protocol-zod/mod";
21
+ import { encodingIsBinary, serializeWithEncoding } from "@/serde";
22
+ import { bufferToArrayBuffer, VERSION } from "@/utils";
23
+ import { getLogHeaders } from "@/utils/env-vars";
24
+ import { getLogger, type Logger } from "./log";
25
+ import { deconstructError, stringifyError } from "./utils";
26
+
27
+ export function logger() {
28
+ return getLogger("router");
29
+ }
30
+
31
+ export function loggerMiddleware(logger: Logger) {
32
+ return async (c: HonoContext, next: Next) => {
33
+ const method = c.req.method;
34
+ const path = c.req.path;
35
+ const startTime = Date.now();
36
+
37
+ await next();
38
+
39
+ const duration = Date.now() - startTime;
40
+ logger.debug({
41
+ msg: "http request",
42
+ method,
43
+ path,
44
+ status: c.res.status,
45
+ dt: `${duration}ms`,
46
+ reqSize: c.req.header("content-length"),
47
+ resSize: c.res.headers.get("content-length"),
48
+ userAgent: c.req.header("user-agent"),
49
+ ...(getLogHeaders()
50
+ ? { allHeaders: JSON.stringify(c.req.header()) }
51
+ : {}),
52
+ });
53
+ };
54
+ }
55
+
56
+ export function handleRouteNotFound(c: HonoContext) {
57
+ return c.text("Not Found (RivetKit)", 404);
58
+ }
59
+
60
+ export function handleRouteError(error: unknown, c: HonoContext) {
61
+ const exposeInternalError = getRequestExposeInternalError(c.req.raw);
62
+
63
+ const { statusCode, group, code, message, metadata } = deconstructError(
64
+ error,
65
+ logger(),
66
+ {
67
+ method: c.req.method,
68
+ path: c.req.path,
69
+ },
70
+ exposeInternalError,
71
+ );
72
+
73
+ let encoding: Encoding;
74
+ try {
75
+ encoding = getRequestEncoding(c.req);
76
+ } catch (_) {
77
+ encoding = "json";
78
+ }
79
+
80
+ const errorData = { group, code, message, metadata };
81
+ const output = serializeWithEncoding(
82
+ encoding,
83
+ errorData,
84
+ HTTP_RESPONSE_ERROR_VERSIONED,
85
+ CLIENT_PROTOCOL_CURRENT_VERSION,
86
+ HttpResponseErrorSchema,
87
+ // JSON: metadata is the raw value (will be serialized by jsonStringifyCompat)
88
+ (value): HttpResponseErrorJson => ({
89
+ group: value.group,
90
+ code: value.code,
91
+ message: value.message,
92
+ metadata: value.metadata,
93
+ }),
94
+ // BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer
95
+ (value): protocol.HttpResponseError => ({
96
+ group: value.group,
97
+ code: value.code,
98
+ message: value.message,
99
+ metadata: value.metadata
100
+ ? bufferToArrayBuffer(cbor.encode(value.metadata))
101
+ : null,
102
+ }),
103
+ );
104
+
105
+ // TODO: Remove any
106
+ return c.body(output as any, { status: statusCode });
107
+ }
108
+
109
+ export type MetadataRunnerKind =
110
+ | { serverless: Record<never, never> }
111
+ | { normal: Record<never, never> };
112
+
113
+ /**
114
+ * Metadata response interface for the /metadata endpoint
115
+ */
116
+ export interface MetadataResponse {
117
+ runtime: string;
118
+ version: string;
119
+ runner?: {
120
+ kind: MetadataRunnerKind;
121
+ version?: number;
122
+ };
123
+ actorNames: ReturnType<typeof buildActorNames>;
124
+ /**
125
+ * Endpoint that the client should connect to to access this runner.
126
+ *
127
+ * If defined, will override the endpoint the user has configured on startup.
128
+ *
129
+ * This is helpful if attempting to connect to a serverless runner, so the serverless runner can define where the main endpoint lives.
130
+ *
131
+ * This is also helpful for setting up clean redirects as needed.
132
+ **/
133
+ clientEndpoint?: string;
134
+ /**
135
+ * Namespace that the client should use when connecting.
136
+ **/
137
+ clientNamespace?: string;
138
+ /**
139
+ * Token that the client should use when connecting.
140
+ **/
141
+ clientToken?: string;
142
+ }
143
+
144
+ export function handleMetadataRequest(
145
+ c: HonoContext,
146
+ config: RegistryConfig,
147
+ runnerKind: MetadataRunnerKind,
148
+ clientEndpoint: string | undefined,
149
+ clientNamespace: string | undefined,
150
+ clientToken: string | undefined,
151
+ ) {
152
+ const response: MetadataResponse = {
153
+ runtime: "rivetkit",
154
+ version: VERSION,
155
+ runner: {
156
+ kind: runnerKind,
157
+ version: config.runner.version,
158
+ },
159
+ actorNames: buildActorNames(config),
160
+ clientEndpoint,
161
+ clientNamespace,
162
+ clientToken,
163
+ };
164
+
165
+ return c.json(response);
166
+ }
167
+
168
+ export function handleHealthRequest(c: HonoContext) {
169
+ return c.json({
170
+ status: "ok",
171
+ runtime: "rivetkit",
172
+ version: VERSION,
173
+ });
174
+ }