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,558 @@
1
+ import type { AnyActorDefinition } from "@/actor/definition";
2
+ import type { Encoding } from "@/actor/protocol/serde";
3
+ import type { ManagerDriver } from "@/driver-helpers/mod";
4
+ import type { ActorQuery } from "@/manager/protocol/query";
5
+ import type { Registry } from "@/registry";
6
+ import type { ActorActionFunction } from "./actor-common";
7
+ import {
8
+ type ActorConn,
9
+ type ActorConnRaw,
10
+ CONNECT_SYMBOL,
11
+ } from "./actor-conn";
12
+ import { type ActorHandle, ActorHandleRaw } from "./actor-handle";
13
+ import { queryActor } from "./actor-query";
14
+ import type { ClientConfig } from "./config";
15
+ import { logger } from "./log";
16
+
17
+ export type { ClientConfig, ClientConfigInput } from "./config";
18
+
19
+ /** Extract the actor registry from the registry definition. */
20
+ export type ExtractActorsFromRegistry<A extends Registry<any>> =
21
+ A extends Registry<infer Actors> ? Actors : never;
22
+
23
+ /** Extract the registry definition from the client. */
24
+ export type ExtractRegistryFromClient<C extends Client<Registry<{}>>> =
25
+ C extends Client<infer A> ? A : never;
26
+
27
+ /**
28
+ * Represents a actor accessor that provides methods to interact with a specific actor.
29
+ */
30
+ export interface ActorAccessor<AD extends AnyActorDefinition> {
31
+ /**
32
+ * Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
33
+ * The actor name is automatically injected from the property accessor.
34
+ *
35
+ * @template AD The actor class that this handle is for.
36
+ * @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
37
+ * @param {GetWithIdOptions} [opts] - Options for getting the actor.
38
+ * @returns {ActorHandle<AD>} - A handle to the actor.
39
+ */
40
+ get(key?: string | string[], opts?: GetWithIdOptions): ActorHandle<AD>;
41
+
42
+ /**
43
+ * Gets a stateless handle to a actor by its key, creating it if necessary.
44
+ * The actor name is automatically injected from the property accessor.
45
+ *
46
+ * @template AD The actor class that this handle is for.
47
+ * @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
48
+ * @param {GetOptions} [opts] - Options for getting the actor.
49
+ * @returns {ActorHandle<AD>} - A handle to the actor.
50
+ */
51
+ getOrCreate(
52
+ key?: string | string[],
53
+ opts?: GetOrCreateOptions,
54
+ ): ActorHandle<AD>;
55
+
56
+ /**
57
+ * Gets a stateless handle to a actor by its ID.
58
+ *
59
+ * @template AD The actor class that this handle is for.
60
+ * @param {string} actorId - The ID of the actor.
61
+ * @param {GetWithIdOptions} [opts] - Options for getting the actor.
62
+ * @returns {ActorHandle<AD>} - A handle to the actor.
63
+ */
64
+ getForId(actorId: string, opts?: GetWithIdOptions): ActorHandle<AD>;
65
+
66
+ /**
67
+ * Creates a new actor with the name automatically injected from the property accessor,
68
+ * and returns a stateless handle to it with the actor ID resolved.
69
+ *
70
+ * @template AD The actor class that this handle is for.
71
+ * @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
72
+ * @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
73
+ * @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
74
+ */
75
+ create(
76
+ key?: string | string[],
77
+ opts?: CreateOptions,
78
+ ): Promise<ActorHandle<AD>>;
79
+ }
80
+
81
+ /**
82
+ * Options for querying actors.
83
+ * @typedef {Object} QueryOptions
84
+ * @property {unknown} [parameters] - Parameters to pass to the connection.
85
+ */
86
+ export interface QueryOptions {
87
+ /** Parameters to pass to the connection. */
88
+ params?: unknown;
89
+ /** Signal to abort the request. */
90
+ signal?: AbortSignal;
91
+ }
92
+
93
+ /**
94
+ * Options for getting a actor by ID.
95
+ * @typedef {QueryOptions} GetWithIdOptions
96
+ */
97
+ export interface GetWithIdOptions extends QueryOptions {}
98
+
99
+ /**
100
+ * Options for getting a actor.
101
+ * @typedef {QueryOptions} GetOptions
102
+ */
103
+ export interface GetOptions extends QueryOptions {}
104
+
105
+ /**
106
+ * Options for getting or creating a actor.
107
+ * @typedef {QueryOptions} GetOrCreateOptions
108
+ * @property {string} [createInRegion] - Region to create the actor in if it doesn't exist.
109
+ */
110
+ export interface GetOrCreateOptions extends QueryOptions {
111
+ /** Region to create the actor in if it doesn't exist. */
112
+ createInRegion?: string;
113
+ /** Input data to pass to the actor. */
114
+ createWithInput?: unknown;
115
+ }
116
+
117
+ /**
118
+ * Options for creating a actor.
119
+ * @typedef {QueryOptions} CreateOptions
120
+ * @property {string} [region] - The region to create the actor in.
121
+ */
122
+ export interface CreateOptions extends QueryOptions {
123
+ /** The region to create the actor in. */
124
+ region?: string;
125
+ /** Input data to pass to the actor. */
126
+ input?: unknown;
127
+ }
128
+
129
+ /**
130
+ * Represents a region to connect to.
131
+ * @typedef {Object} Region
132
+ * @property {string} id - The region ID.
133
+ * @property {string} name - The region name.
134
+ * @see {@link https://rivet.dev/docs/edge|Edge Networking}
135
+ * @see {@link https://rivet.dev/docs/regions|Available Regions}
136
+ */
137
+ export interface Region {
138
+ /**
139
+ * The region slug.
140
+ */
141
+ id: string;
142
+
143
+ /**
144
+ * The human-friendly region name.
145
+ */
146
+ name: string;
147
+ }
148
+
149
+ export const ACTOR_CONNS_SYMBOL = Symbol("actorConns");
150
+ export const CREATE_ACTOR_CONN_PROXY = Symbol("createActorConnProxy");
151
+
152
+ /**
153
+ * Client for managing & connecting to actors.
154
+ *
155
+ * @template A The actors map type that defines the available actors.
156
+ * @see {@link https://rivet.dev/docs/manage|Create & Manage Actors}
157
+ */
158
+ export class ClientRaw {
159
+ #disposed = false;
160
+
161
+ [ACTOR_CONNS_SYMBOL] = new Set<ActorConnRaw>();
162
+
163
+ #driver: ManagerDriver;
164
+ #encodingKind: Encoding;
165
+
166
+ /**
167
+ * Creates an instance of Client.
168
+ */
169
+ public constructor(driver: ManagerDriver, encoding: Encoding | undefined) {
170
+ this.#driver = driver;
171
+
172
+ this.#encodingKind = encoding ?? "bare";
173
+ }
174
+
175
+ /**
176
+ * Gets a stateless handle to a actor by its ID.
177
+ *
178
+ * @template AD The actor class that this handle is for.
179
+ * @param {string} name - The name of the actor.
180
+ * @param {string} actorId - The ID of the actor.
181
+ * @param {GetWithIdOptions} [opts] - Options for getting the actor.
182
+ * @returns {ActorHandle<AD>} - A handle to the actor.
183
+ */
184
+ getForId<AD extends AnyActorDefinition>(
185
+ name: string,
186
+ actorId: string,
187
+ opts?: GetWithIdOptions,
188
+ ): ActorHandle<AD> {
189
+ logger().debug({
190
+ msg: "get handle to actor with id",
191
+ name,
192
+ actorId,
193
+ params: opts?.params,
194
+ });
195
+
196
+ const actorQuery: ActorQuery = {
197
+ getForId: {
198
+ name,
199
+ actorId,
200
+ },
201
+ };
202
+
203
+ const handle = this.#createHandle(opts?.params, actorQuery);
204
+ return createActorProxy(handle) as ActorHandle<AD>;
205
+ }
206
+
207
+ /**
208
+ * Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
209
+ *
210
+ * @template AD The actor class that this handle is for.
211
+ * @param {string} name - The name of the actor.
212
+ * @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
213
+ * @param {GetWithIdOptions} [opts] - Options for getting the actor.
214
+ * @returns {ActorHandle<AD>} - A handle to the actor.
215
+ */
216
+ get<AD extends AnyActorDefinition>(
217
+ name: string,
218
+ key?: string | string[],
219
+ opts?: GetWithIdOptions,
220
+ ): ActorHandle<AD> {
221
+ // Convert string to array of strings
222
+ const keyArray: string[] = typeof key === "string" ? [key] : key || [];
223
+
224
+ logger().debug({
225
+ msg: "get handle to actor",
226
+ name,
227
+ key: keyArray,
228
+ parameters: opts?.params,
229
+ });
230
+
231
+ const actorQuery: ActorQuery = {
232
+ getForKey: {
233
+ name,
234
+ key: keyArray,
235
+ },
236
+ };
237
+
238
+ const handle = this.#createHandle(opts?.params, actorQuery);
239
+ return createActorProxy(handle) as ActorHandle<AD>;
240
+ }
241
+
242
+ /**
243
+ * Gets a stateless handle to a actor by its key, creating it if necessary.
244
+ *
245
+ * @template AD The actor class that this handle is for.
246
+ * @param {string} name - The name of the actor.
247
+ * @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
248
+ * @param {GetOptions} [opts] - Options for getting the actor.
249
+ * @returns {ActorHandle<AD>} - A handle to the actor.
250
+ */
251
+ getOrCreate<AD extends AnyActorDefinition>(
252
+ name: string,
253
+ key?: string | string[],
254
+ opts?: GetOrCreateOptions,
255
+ ): ActorHandle<AD> {
256
+ // Convert string to array of strings
257
+ const keyArray: string[] = typeof key === "string" ? [key] : key || [];
258
+
259
+ logger().debug({
260
+ msg: "get or create handle to actor",
261
+ name,
262
+ key: keyArray,
263
+ parameters: opts?.params,
264
+ createInRegion: opts?.createInRegion,
265
+ });
266
+
267
+ const actorQuery: ActorQuery = {
268
+ getOrCreateForKey: {
269
+ name,
270
+ key: keyArray,
271
+ input: opts?.createWithInput,
272
+ region: opts?.createInRegion,
273
+ },
274
+ };
275
+
276
+ const handle = this.#createHandle(opts?.params, actorQuery);
277
+ return createActorProxy(handle) as ActorHandle<AD>;
278
+ }
279
+
280
+ /**
281
+ * Creates a new actor with the provided key and returns a stateless handle to it.
282
+ * Resolves the actor ID and returns a handle with getForId query.
283
+ *
284
+ * @template AD The actor class that this handle is for.
285
+ * @param {string} name - The name of the actor.
286
+ * @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
287
+ * @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
288
+ * @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
289
+ */
290
+ async create<AD extends AnyActorDefinition>(
291
+ name: string,
292
+ key?: string | string[],
293
+ opts?: CreateOptions,
294
+ ): Promise<ActorHandle<AD>> {
295
+ // Convert string to array of strings
296
+ const keyArray: string[] = typeof key === "string" ? [key] : key || [];
297
+
298
+ const createQuery = {
299
+ create: {
300
+ ...opts,
301
+ // Do these last to override `opts`
302
+ name,
303
+ key: keyArray,
304
+ },
305
+ } satisfies ActorQuery;
306
+
307
+ logger().debug({
308
+ msg: "create actor handle",
309
+ name,
310
+ key: keyArray,
311
+ parameters: opts?.params,
312
+ create: createQuery.create,
313
+ });
314
+
315
+ // Create the actor
316
+ const { actorId } = await queryActor(
317
+ undefined,
318
+ createQuery,
319
+ this.#driver,
320
+ );
321
+ logger().debug({
322
+ msg: "created actor with ID",
323
+ name,
324
+ key: keyArray,
325
+ actorId,
326
+ });
327
+
328
+ // Create handle with actor ID
329
+ const getForIdQuery = {
330
+ getForId: {
331
+ name,
332
+ actorId,
333
+ },
334
+ } satisfies ActorQuery;
335
+ const handle = this.#createHandle(opts?.params, getForIdQuery);
336
+
337
+ const proxy = createActorProxy(handle) as ActorHandle<AD>;
338
+
339
+ return proxy;
340
+ }
341
+
342
+ #createHandle(params: unknown, actorQuery: ActorQuery): ActorHandleRaw {
343
+ return new ActorHandleRaw(
344
+ this,
345
+ this.#driver,
346
+ params,
347
+ this.#encodingKind,
348
+ actorQuery,
349
+ );
350
+ }
351
+
352
+ [CREATE_ACTOR_CONN_PROXY]<AD extends AnyActorDefinition>(
353
+ conn: ActorConnRaw,
354
+ ): ActorConn<AD> {
355
+ // Save to connection list
356
+ this[ACTOR_CONNS_SYMBOL].add(conn);
357
+
358
+ // Start connection
359
+ conn[CONNECT_SYMBOL]();
360
+
361
+ return createActorProxy(conn) as ActorConn<AD>;
362
+ }
363
+
364
+ /**
365
+ * Disconnects from all actors.
366
+ *
367
+ * @returns {Promise<void>} A promise that resolves when all connections are closed.
368
+ */
369
+ async dispose(): Promise<void> {
370
+ if (this.#disposed) {
371
+ logger().warn({ msg: "client already disconnected" });
372
+ return;
373
+ }
374
+ this.#disposed = true;
375
+
376
+ logger().debug({ msg: "disposing client" });
377
+
378
+ const disposePromises = [];
379
+
380
+ // Dispose all connections
381
+ for (const conn of this[ACTOR_CONNS_SYMBOL].values()) {
382
+ disposePromises.push(conn.dispose());
383
+ }
384
+
385
+ await Promise.all(disposePromises);
386
+ }
387
+ }
388
+
389
+ /**
390
+ * Client type with actor accessors.
391
+ * This adds property accessors for actor names to the ClientRaw base class.
392
+ *
393
+ * @template A The actor registry type.
394
+ */
395
+ export type Client<A extends Registry<any>> = ClientRaw & {
396
+ [K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<
397
+ ExtractActorsFromRegistry<A>[K]
398
+ >;
399
+ };
400
+
401
+ export type AnyClient = Client<Registry<any>>;
402
+
403
+ export function createClientWithDriver<A extends Registry<any>>(
404
+ driver: ManagerDriver,
405
+ config: { encoding?: Encoding } = {},
406
+ ): Client<A> {
407
+ const client = new ClientRaw(driver, config.encoding);
408
+
409
+ // Create proxy for accessing actors by name
410
+ return new Proxy(client, {
411
+ get: (target: ClientRaw, prop: string | symbol, receiver: unknown) => {
412
+ // Get the real property if it exists
413
+ if (typeof prop === "symbol" || prop in target) {
414
+ const value = Reflect.get(target, prop, receiver);
415
+ // Preserve method binding
416
+ if (typeof value === "function") {
417
+ return value.bind(target);
418
+ }
419
+ return value;
420
+ }
421
+
422
+ // Handle actor accessor for string properties (actor names)
423
+ if (typeof prop === "string") {
424
+ // Return actor accessor object with methods
425
+ return {
426
+ // Handle methods (stateless action)
427
+ get: (
428
+ key?: string | string[],
429
+ opts?: GetWithIdOptions,
430
+ ): ActorHandle<
431
+ ExtractActorsFromRegistry<A>[typeof prop]
432
+ > => {
433
+ return target.get<
434
+ ExtractActorsFromRegistry<A>[typeof prop]
435
+ >(prop, key, opts);
436
+ },
437
+ getOrCreate: (
438
+ key?: string | string[],
439
+ opts?: GetOptions,
440
+ ): ActorHandle<
441
+ ExtractActorsFromRegistry<A>[typeof prop]
442
+ > => {
443
+ return target.getOrCreate<
444
+ ExtractActorsFromRegistry<A>[typeof prop]
445
+ >(prop, key, opts);
446
+ },
447
+ getForId: (
448
+ actorId: string,
449
+ opts?: GetWithIdOptions,
450
+ ): ActorHandle<
451
+ ExtractActorsFromRegistry<A>[typeof prop]
452
+ > => {
453
+ return target.getForId<
454
+ ExtractActorsFromRegistry<A>[typeof prop]
455
+ >(prop, actorId, opts);
456
+ },
457
+ create: async (
458
+ key: string | string[],
459
+ opts: CreateOptions = {},
460
+ ): Promise<
461
+ ActorHandle<ExtractActorsFromRegistry<A>[typeof prop]>
462
+ > => {
463
+ return await target.create<
464
+ ExtractActorsFromRegistry<A>[typeof prop]
465
+ >(prop, key, opts);
466
+ },
467
+ } as ActorAccessor<ExtractActorsFromRegistry<A>[typeof prop]>;
468
+ }
469
+
470
+ return undefined;
471
+ },
472
+ }) as Client<A>;
473
+ }
474
+
475
+ /**
476
+ * Creates a proxy for a actor that enables calling actions without explicitly using `.action`.
477
+ **/
478
+ function createActorProxy<AD extends AnyActorDefinition>(
479
+ handle: ActorHandleRaw | ActorConnRaw,
480
+ ): ActorHandle<AD> | ActorConn<AD> {
481
+ // Stores returned action functions for faster calls
482
+ const methodCache = new Map<string, ActorActionFunction>();
483
+ return new Proxy(handle, {
484
+ get(target: ActorHandleRaw, prop: string | symbol, receiver: unknown) {
485
+ // Handle built-in Symbol properties
486
+ if (typeof prop === "symbol") {
487
+ return Reflect.get(target, prop, receiver);
488
+ }
489
+
490
+ // Handle built-in Promise methods and existing properties
491
+ if (prop === "constructor" || prop in target) {
492
+ const value = Reflect.get(target, prop, target);
493
+ // Preserve method binding
494
+ if (typeof value === "function") {
495
+ return value.bind(target);
496
+ }
497
+ return value;
498
+ }
499
+
500
+ // Create action function that preserves 'this' context
501
+ if (typeof prop === "string") {
502
+ // If JS is attempting to calling this as a promise, ignore it
503
+ if (prop === "then") return undefined;
504
+
505
+ let method = methodCache.get(prop);
506
+ if (!method) {
507
+ method = (...args: unknown[]) =>
508
+ target.action({ name: prop, args });
509
+ methodCache.set(prop, method);
510
+ }
511
+ return method;
512
+ }
513
+ },
514
+
515
+ // Support for 'in' operator
516
+ has(target: ActorHandleRaw, prop: string | symbol) {
517
+ // All string properties are potentially action functions.
518
+ if (typeof prop === "string") return true;
519
+ // For symbols, defer to the target's own has behavior
520
+ return Reflect.has(target, prop);
521
+ },
522
+
523
+ // Support instanceof checks
524
+ getPrototypeOf(target: ActorHandleRaw) {
525
+ return Reflect.getPrototypeOf(target);
526
+ },
527
+
528
+ // Prevent property enumeration of non-existent action methods
529
+ ownKeys(target: ActorHandleRaw) {
530
+ return Reflect.ownKeys(target);
531
+ },
532
+
533
+ // Support proper property descriptors
534
+ getOwnPropertyDescriptor(
535
+ target: ActorHandleRaw,
536
+ prop: string | symbol,
537
+ ) {
538
+ const targetDescriptor = Reflect.getOwnPropertyDescriptor(
539
+ target,
540
+ prop,
541
+ );
542
+ if (targetDescriptor) {
543
+ return targetDescriptor;
544
+ }
545
+ if (typeof prop === "string") {
546
+ // Make action methods appear non-enumerable
547
+ return {
548
+ configurable: true,
549
+ enumerable: false,
550
+ writable: false,
551
+ value: (...args: unknown[]) =>
552
+ target.action({ name: prop, args }),
553
+ };
554
+ }
555
+ return undefined;
556
+ },
557
+ }) as ActorHandle<AD> | ActorConn<AD>;
558
+ }
@@ -0,0 +1,151 @@
1
+ import z from "zod/v4";
2
+ import { EncodingSchema } from "@/actor/protocol/serde";
3
+ import { type GetUpgradeWebSocket } from "@/utils";
4
+ import {
5
+ getRivetEngine,
6
+ getRivetEndpoint,
7
+ getRivetToken,
8
+ getRivetNamespace,
9
+ getRivetRunner,
10
+ } from "@/utils/env-vars";
11
+ import type { RegistryConfig } from "@/registry/config";
12
+ import { tryParseEndpoint } from "@/utils/endpoint-parser";
13
+
14
+ /**
15
+ * Gets the default endpoint for the client.
16
+ *
17
+ * In browser: uses current origin + /api/rivet
18
+ *
19
+ * Server-side: uses 127.0.0.1:6420
20
+ */
21
+ function getDefaultEndpoint(): string {
22
+ if (typeof window !== "undefined" && window.location?.origin) {
23
+ return `${window.location.origin}/api/rivet`;
24
+ }
25
+ return "http://127.0.0.1:6420";
26
+ }
27
+
28
+ /**
29
+ * Base client config schema without transforms so it can be merged in to other schemas.
30
+ */
31
+ export const ClientConfigSchemaBase = z.object({
32
+ /**
33
+ * Endpoint to connect to for Rivet Engine or RivetKit manager API.
34
+ *
35
+ * Supports URL auth syntax for namespace and token:
36
+ * - `https://namespace:token@api.rivet.dev`
37
+ * - `https://namespace@api.rivet.dev`
38
+ *
39
+ * Can also be set via RIVET_ENDPOINT environment variables.
40
+ *
41
+ * Defaults to current origin + /api/rivet in browser, or 127.0.0.1:6420 server-side.
42
+ */
43
+ endpoint: z
44
+ .string()
45
+ .optional()
46
+ .transform(
47
+ (val) =>
48
+ val ??
49
+ getRivetEngine() ??
50
+ getRivetEndpoint() ??
51
+ getDefaultEndpoint(),
52
+ ),
53
+
54
+ /** Token to use to authenticate with the API. */
55
+ token: z
56
+ .string()
57
+ .optional()
58
+ .transform((val) => val ?? getRivetToken()),
59
+
60
+ /** Namespace to connect to. */
61
+ namespace: z
62
+ .string()
63
+ .optional()
64
+ .transform((val) => val ?? getRivetNamespace()),
65
+
66
+ /** Name of the runner. This is used to group together runners in to different pools. */
67
+ runnerName: z.string().default(() => getRivetRunner() ?? "default"),
68
+
69
+ encoding: EncodingSchema.default("bare"),
70
+
71
+ headers: z
72
+ .record(z.string(), z.string())
73
+ .optional()
74
+ .default(() => ({})),
75
+
76
+ // See RunConfig.getUpgradeWebSocket
77
+ //
78
+ // This is required in the client config in order to support
79
+ // `proxyWebSocket`
80
+ getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
81
+
82
+ /** Whether to automatically perform health checks when the client is created. */
83
+ disableMetadataLookup: z.boolean().optional().default(false),
84
+
85
+ /** Whether to enable RivetKit Devtools integration. */
86
+ devtools: z
87
+ .boolean()
88
+ .default(
89
+ () =>
90
+ typeof window !== "undefined" &&
91
+ (window?.location?.hostname === "127.0.0.1" ||
92
+ window.location?.hostname === "localhost"),
93
+ ),
94
+ });
95
+
96
+ export const ClientConfigSchema = ClientConfigSchemaBase.transform(
97
+ (config, ctx) => transformClientConfig(config, ctx),
98
+ );
99
+
100
+ export type ClientConfig = z.infer<typeof ClientConfigSchema>;
101
+
102
+ export type ClientConfigInput = z.input<typeof ClientConfigSchema>;
103
+
104
+ export function transformClientConfig(
105
+ config: z.infer<typeof ClientConfigSchemaBase>,
106
+ ctx: z.RefinementCtx,
107
+ ) {
108
+ const parsedEndpoint = tryParseEndpoint(ctx, {
109
+ endpoint: config.endpoint,
110
+ path: ["endpoint"],
111
+ namespace: config.namespace,
112
+ token: config.token,
113
+ });
114
+
115
+ return {
116
+ ...config,
117
+ endpoint: parsedEndpoint?.endpoint,
118
+ namespace: parsedEndpoint?.namespace ?? config.namespace ?? "default",
119
+ token: parsedEndpoint?.token ?? config.token,
120
+ };
121
+ }
122
+
123
+ /**
124
+ * Converts a base config in to a client config.
125
+ *
126
+ * The base config does not include all of the properties of the client config,
127
+ * so this converts the subset of properties in to the client config.
128
+ *
129
+ * Note: We construct the object directly rather than using ClientConfigSchema.parse()
130
+ * because RegistryConfig has already transformed the endpoint, namespace, and token.
131
+ * Re-parsing would attempt to extract namespace/token from the endpoint URL again.
132
+ */
133
+ export function convertRegistryConfigToClientConfig(
134
+ config: RegistryConfig,
135
+ ): ClientConfig {
136
+ return {
137
+ endpoint: config.endpoint,
138
+ token: config.token,
139
+ namespace: config.namespace,
140
+ runnerName: config.runner.runnerName,
141
+ headers: config.headers,
142
+ encoding: "bare",
143
+ getUpgradeWebSocket: undefined,
144
+ // We don't need health checks for internal clients
145
+ disableMetadataLookup: true,
146
+ devtools:
147
+ typeof window !== "undefined" &&
148
+ (window?.location?.hostname === "127.0.0.1" ||
149
+ window?.location?.hostname === "localhost"),
150
+ };
151
+ }