rivetkit 2.0.3 → 2.0.5

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 (237) hide show
  1. package/README.md +11 -0
  2. package/dist/schemas/actor-persist/v1.ts +21 -24
  3. package/dist/schemas/client-protocol/v1.ts +6 -0
  4. package/dist/tsup/actor/errors.cjs +10 -2
  5. package/dist/tsup/actor/errors.cjs.map +1 -1
  6. package/dist/tsup/actor/errors.d.cts +17 -4
  7. package/dist/tsup/actor/errors.d.ts +17 -4
  8. package/dist/tsup/actor/errors.js +11 -3
  9. package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-2MD57QF4.js} +119 -115
  10. package/dist/tsup/chunk-2MD57QF4.js.map +1 -0
  11. package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-5QGQK44L.cjs} +103 -44
  12. package/dist/tsup/chunk-5QGQK44L.cjs.map +1 -0
  13. package/dist/tsup/chunk-5YTI25C3.cjs +250 -0
  14. package/dist/tsup/chunk-5YTI25C3.cjs.map +1 -0
  15. package/dist/tsup/chunk-B2QGJGZQ.js +338 -0
  16. package/dist/tsup/chunk-B2QGJGZQ.js.map +1 -0
  17. package/dist/tsup/{chunk-3H7O2A7I.js → chunk-CFFKMUYH.js} +61 -22
  18. package/dist/tsup/chunk-CFFKMUYH.js.map +1 -0
  19. package/dist/tsup/{chunk-FLMTTN27.js → chunk-CKA54YQN.js} +15 -8
  20. package/dist/tsup/chunk-CKA54YQN.js.map +1 -0
  21. package/dist/tsup/chunk-D7NWUCRK.cjs +20 -0
  22. package/dist/tsup/chunk-D7NWUCRK.cjs.map +1 -0
  23. package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-FGFT4FVX.cjs} +12 -27
  24. package/dist/tsup/chunk-FGFT4FVX.cjs.map +1 -0
  25. package/dist/tsup/chunk-I5VTWPHW.js +20 -0
  26. package/dist/tsup/chunk-I5VTWPHW.js.map +1 -0
  27. package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-IRMBWX36.cjs} +146 -142
  28. package/dist/tsup/chunk-IRMBWX36.cjs.map +1 -0
  29. package/dist/tsup/chunk-L7QRXNWP.js +6562 -0
  30. package/dist/tsup/chunk-L7QRXNWP.js.map +1 -0
  31. package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LZIBTLEY.cjs} +20 -13
  32. package/dist/tsup/chunk-LZIBTLEY.cjs.map +1 -0
  33. package/dist/tsup/chunk-MRZS2J4X.cjs +6562 -0
  34. package/dist/tsup/chunk-MRZS2J4X.cjs.map +1 -0
  35. package/dist/tsup/{chunk-PO4VLDWA.js → chunk-PG3K2LI7.js} +3 -5
  36. package/dist/tsup/chunk-PG3K2LI7.js.map +1 -0
  37. package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-PHSQJ6QI.cjs} +3 -5
  38. package/dist/tsup/chunk-PHSQJ6QI.cjs.map +1 -0
  39. package/dist/tsup/chunk-RM2SVURR.cjs +338 -0
  40. package/dist/tsup/chunk-RM2SVURR.cjs.map +1 -0
  41. package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-WADSS5X4.cjs} +66 -27
  42. package/dist/tsup/chunk-WADSS5X4.cjs.map +1 -0
  43. package/dist/tsup/chunk-WNGOBAA7.js +250 -0
  44. package/dist/tsup/chunk-WNGOBAA7.js.map +1 -0
  45. package/dist/tsup/{chunk-INGJP237.js → chunk-YPZFLUO6.js} +103 -44
  46. package/dist/tsup/chunk-YPZFLUO6.js.map +1 -0
  47. package/dist/tsup/{chunk-6PDXBYI5.js → chunk-YW6Y6VNE.js} +8 -23
  48. package/dist/tsup/chunk-YW6Y6VNE.js.map +1 -0
  49. package/dist/tsup/client/mod.cjs +10 -10
  50. package/dist/tsup/client/mod.d.cts +7 -13
  51. package/dist/tsup/client/mod.d.ts +7 -13
  52. package/dist/tsup/client/mod.js +9 -9
  53. package/dist/tsup/common/log.cjs +12 -4
  54. package/dist/tsup/common/log.cjs.map +1 -1
  55. package/dist/tsup/common/log.d.cts +23 -17
  56. package/dist/tsup/common/log.d.ts +23 -17
  57. package/dist/tsup/common/log.js +15 -7
  58. package/dist/tsup/common/websocket.cjs +5 -5
  59. package/dist/tsup/common/websocket.js +4 -4
  60. package/dist/tsup/{common-CpqORuCq.d.cts → common-CXCe7s6i.d.cts} +2 -2
  61. package/dist/tsup/{common-CpqORuCq.d.ts → common-CXCe7s6i.d.ts} +2 -2
  62. package/dist/tsup/{connection-BwUMoe6n.d.ts → connection-BvE-Oq7t.d.ts} +215 -234
  63. package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-DTzmWwU5.d.cts} +215 -234
  64. package/dist/tsup/driver-helpers/mod.cjs +6 -9
  65. package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
  66. package/dist/tsup/driver-helpers/mod.d.cts +5 -6
  67. package/dist/tsup/driver-helpers/mod.d.ts +5 -6
  68. package/dist/tsup/driver-helpers/mod.js +6 -9
  69. package/dist/tsup/driver-test-suite/mod.cjs +615 -1357
  70. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  71. package/dist/tsup/driver-test-suite/mod.d.cts +12 -6
  72. package/dist/tsup/driver-test-suite/mod.d.ts +12 -6
  73. package/dist/tsup/driver-test-suite/mod.js +1334 -2076
  74. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  75. package/dist/tsup/inspector/mod.cjs +6 -8
  76. package/dist/tsup/inspector/mod.cjs.map +1 -1
  77. package/dist/tsup/inspector/mod.d.cts +3 -3
  78. package/dist/tsup/inspector/mod.d.ts +3 -3
  79. package/dist/tsup/inspector/mod.js +8 -10
  80. package/dist/tsup/mod.cjs +9 -15
  81. package/dist/tsup/mod.cjs.map +1 -1
  82. package/dist/tsup/mod.d.cts +47 -42
  83. package/dist/tsup/mod.d.ts +47 -42
  84. package/dist/tsup/mod.js +10 -16
  85. package/dist/tsup/{router-endpoints-DAbqVFx2.d.ts → router-endpoints-CctffZNL.d.cts} +2 -3
  86. package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-DFm1BglJ.d.ts} +2 -3
  87. package/dist/tsup/test/mod.cjs +10 -14
  88. package/dist/tsup/test/mod.cjs.map +1 -1
  89. package/dist/tsup/test/mod.d.cts +4 -5
  90. package/dist/tsup/test/mod.d.ts +4 -5
  91. package/dist/tsup/test/mod.js +9 -13
  92. package/dist/tsup/{utils-CT0cv4jd.d.ts → utils-fwx3o3K9.d.cts} +1 -0
  93. package/dist/tsup/{utils-CT0cv4jd.d.cts → utils-fwx3o3K9.d.ts} +1 -0
  94. package/dist/tsup/utils.cjs +5 -3
  95. package/dist/tsup/utils.cjs.map +1 -1
  96. package/dist/tsup/utils.d.cts +19 -2
  97. package/dist/tsup/utils.d.ts +19 -2
  98. package/dist/tsup/utils.js +4 -2
  99. package/package.json +6 -6
  100. package/src/actor/action.ts +1 -5
  101. package/src/actor/config.ts +27 -295
  102. package/src/actor/connection.ts +9 -12
  103. package/src/actor/context.ts +1 -4
  104. package/src/actor/definition.ts +7 -11
  105. package/src/actor/errors.ts +98 -36
  106. package/src/actor/generic-conn-driver.ts +28 -16
  107. package/src/actor/instance.ts +177 -133
  108. package/src/actor/log.ts +4 -13
  109. package/src/actor/mod.ts +0 -5
  110. package/src/actor/protocol/old.ts +42 -26
  111. package/src/actor/protocol/serde.ts +1 -1
  112. package/src/actor/router-endpoints.ts +47 -39
  113. package/src/actor/router.ts +22 -19
  114. package/src/actor/unstable-react.ts +1 -1
  115. package/src/actor/utils.ts +6 -2
  116. package/src/client/actor-common.ts +1 -1
  117. package/src/client/actor-conn.ts +152 -91
  118. package/src/client/actor-handle.ts +85 -25
  119. package/src/client/actor-query.ts +65 -0
  120. package/src/client/client.ts +29 -98
  121. package/src/client/config.ts +44 -0
  122. package/src/client/errors.ts +1 -0
  123. package/src/client/log.ts +2 -4
  124. package/src/client/mod.ts +16 -12
  125. package/src/client/raw-utils.ts +82 -25
  126. package/src/client/utils.ts +5 -3
  127. package/src/common/fake-event-source.ts +10 -9
  128. package/src/common/inline-websocket-adapter2.ts +39 -30
  129. package/src/common/log.ts +176 -101
  130. package/src/common/logfmt.ts +21 -30
  131. package/src/common/router.ts +12 -19
  132. package/src/common/utils.ts +27 -13
  133. package/src/common/websocket.ts +0 -1
  134. package/src/driver-helpers/mod.ts +1 -1
  135. package/src/driver-test-suite/log.ts +1 -3
  136. package/src/driver-test-suite/mod.ts +87 -61
  137. package/src/driver-test-suite/test-inline-client-driver.ts +441 -255
  138. package/src/driver-test-suite/tests/actor-error-handling.ts +4 -12
  139. package/src/driver-test-suite/tests/actor-handle.ts +33 -0
  140. package/src/driver-test-suite/tests/actor-inspector.ts +2 -1
  141. package/src/driver-test-suite/tests/manager-driver.ts +5 -3
  142. package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
  143. package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
  144. package/src/driver-test-suite/tests/request-access.ts +112 -126
  145. package/src/driver-test-suite/utils.ts +10 -6
  146. package/src/drivers/default.ts +7 -4
  147. package/src/drivers/engine/actor-driver.ts +22 -13
  148. package/src/drivers/engine/config.ts +2 -10
  149. package/src/drivers/engine/kv.ts +1 -1
  150. package/src/drivers/engine/log.ts +1 -3
  151. package/src/drivers/engine/mod.ts +2 -3
  152. package/src/drivers/file-system/actor.ts +1 -1
  153. package/src/drivers/file-system/global-state.ts +36 -21
  154. package/src/drivers/file-system/log.ts +1 -3
  155. package/src/drivers/file-system/manager.ts +33 -15
  156. package/src/inspector/config.ts +9 -4
  157. package/src/inspector/log.ts +1 -1
  158. package/src/inspector/manager.ts +2 -2
  159. package/src/inspector/utils.ts +1 -1
  160. package/src/manager/driver.ts +10 -2
  161. package/src/manager/hono-websocket-adapter.ts +21 -12
  162. package/src/manager/log.ts +2 -4
  163. package/src/manager/mod.ts +1 -1
  164. package/src/manager/router.ts +378 -1390
  165. package/src/manager-api/routes/actors-create.ts +16 -0
  166. package/src/manager-api/routes/actors-delete.ts +4 -0
  167. package/src/manager-api/routes/actors-get-by-id.ts +7 -0
  168. package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
  169. package/src/manager-api/routes/actors-get.ts +7 -0
  170. package/src/manager-api/routes/common.ts +18 -0
  171. package/src/mod.ts +0 -2
  172. package/src/registry/config.ts +1 -1
  173. package/src/registry/log.ts +2 -4
  174. package/src/registry/mod.ts +63 -34
  175. package/src/registry/run-config.ts +39 -26
  176. package/src/registry/serve.ts +4 -5
  177. package/src/remote-manager-driver/actor-http-client.ts +74 -0
  178. package/src/remote-manager-driver/actor-websocket-client.ts +64 -0
  179. package/src/remote-manager-driver/api-endpoints.ts +79 -0
  180. package/src/remote-manager-driver/api-utils.ts +46 -0
  181. package/src/remote-manager-driver/log.ts +5 -0
  182. package/src/remote-manager-driver/mod.ts +275 -0
  183. package/src/{drivers/engine → remote-manager-driver}/ws-proxy.ts +24 -14
  184. package/src/serde.ts +8 -2
  185. package/src/test/log.ts +1 -3
  186. package/src/test/mod.ts +17 -16
  187. package/src/utils.ts +53 -0
  188. package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
  189. package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
  190. package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
  191. package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
  192. package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
  193. package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
  194. package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
  195. package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
  196. package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
  197. package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
  198. package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
  199. package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
  200. package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
  201. package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
  202. package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
  203. package/dist/tsup/chunk-INGJP237.js.map +0 -1
  204. package/dist/tsup/chunk-KJCJLKRM.js +0 -116
  205. package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
  206. package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
  207. package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
  208. package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
  209. package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
  210. package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
  211. package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
  212. package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
  213. package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
  214. package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
  215. package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
  216. package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
  217. package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
  218. package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
  219. package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
  220. package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
  221. package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
  222. package/dist/tsup/chunk-UVUPOS46.js +0 -230
  223. package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
  224. package/dist/tsup/chunk-VRRHBNJC.js +0 -189
  225. package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
  226. package/dist/tsup/chunk-XFSS33EQ.js +0 -202
  227. package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
  228. package/src/client/http-client-driver.ts +0 -326
  229. package/src/driver-test-suite/tests/actor-auth.ts +0 -591
  230. package/src/drivers/engine/api-endpoints.ts +0 -128
  231. package/src/drivers/engine/api-utils.ts +0 -70
  232. package/src/drivers/engine/manager-driver.ts +0 -391
  233. package/src/inline-client-driver/log.ts +0 -7
  234. package/src/inline-client-driver/mod.ts +0 -385
  235. package/src/manager/auth.ts +0 -121
  236. /package/src/{drivers/engine → actor}/keys.test.ts +0 -0
  237. /package/src/{drivers/engine → actor}/keys.ts +0 -0
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ import { ActorSchema } from "./common";
3
+
4
+ export const ActorsCreateRequestSchema = z.object({
5
+ name: z.string(),
6
+ runner_name_selector: z.string(),
7
+ crash_policy: z.string(),
8
+ key: z.string().nullable().optional(),
9
+ input: z.string().nullable().optional(),
10
+ });
11
+ export type ActorsCreateRequest = z.infer<typeof ActorsCreateRequestSchema>;
12
+
13
+ export const ActorsCreateResponseSchema = z.object({
14
+ actor: ActorSchema,
15
+ });
16
+ export type ActorsCreateResponse = z.infer<typeof ActorsCreateResponseSchema>;
@@ -0,0 +1,4 @@
1
+ import { z } from "zod";
2
+
3
+ export const ActorsDeleteResponseSchema = z.object({});
4
+ export type ActorsDeleteResponse = z.infer<typeof ActorsDeleteResponseSchema>;
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+ import { RivetIdSchema } from "./common";
3
+
4
+ export const ActorsGetByIdResponseSchema = z.object({
5
+ actor_id: RivetIdSchema.nullable().optional(),
6
+ });
7
+ export type ActorsGetByIdResponse = z.infer<typeof ActorsGetByIdResponseSchema>;
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+ import { ActorSchema, RivetIdSchema } from "./common";
3
+
4
+ export const ActorsGetOrCreateResponseSchema = z.object({
5
+ actor: ActorSchema,
6
+ created: z.boolean(),
7
+ });
8
+ export type ActorsGetOrCreateResponse = z.infer<
9
+ typeof ActorsGetOrCreateResponseSchema
10
+ >;
11
+
12
+ export const ActorsGetOrCreateByIdResponseSchema = z.object({
13
+ actor_id: RivetIdSchema,
14
+ created: z.boolean(),
15
+ });
16
+ export type ActorsGetOrCreateByIdResponse = z.infer<
17
+ typeof ActorsGetOrCreateByIdResponseSchema
18
+ >;
19
+
20
+ export const ActorsGetOrCreateByIdRequestSchema = z.object({
21
+ name: z.string(),
22
+ key: z.string(),
23
+ runner_name_selector: z.string(),
24
+ crash_policy: z.string(),
25
+ input: z.string().nullable().optional(),
26
+ });
27
+ export type ActorsGetOrCreateByIdRequest = z.infer<
28
+ typeof ActorsGetOrCreateByIdRequestSchema
29
+ >;
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+ import { ActorSchema } from "./common";
3
+
4
+ export const ActorsGetResponseSchema = z.object({
5
+ actor: ActorSchema,
6
+ });
7
+ export type ActorsGetResponse = z.infer<typeof ActorsGetResponseSchema>;
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+
3
+ export const RivetIdSchema = z.string();
4
+ export type RivetId = z.infer<typeof RivetIdSchema>;
5
+
6
+ export const ActorSchema = z.object({
7
+ actor_id: RivetIdSchema,
8
+ name: z.string(),
9
+ key: z.string(),
10
+ namespace_id: RivetIdSchema,
11
+ runner_name_selector: z.string(),
12
+ create_ts: z.number(),
13
+ connectable_ts: z.number().nullable().optional(),
14
+ destroy_ts: z.number().nullable().optional(),
15
+ sleep_ts: z.number().nullable().optional(),
16
+ start_ts: z.number().nullable().optional(),
17
+ });
18
+ export type Actor = z.infer<typeof ActorSchema>;
package/src/mod.ts CHANGED
@@ -3,7 +3,6 @@ export * from "@/actor/mod";
3
3
  export {
4
4
  type AnyClient,
5
5
  type Client,
6
- type ClientDriver,
7
6
  createClientWithDriver,
8
7
  } from "@/client/client";
9
8
  export { InlineWebSocketAdapter2 } from "@/common/inline-websocket-adapter2";
@@ -13,7 +12,6 @@ export {
13
12
  createFileSystemDriver,
14
13
  createMemoryDriver,
15
14
  } from "@/drivers/file-system/mod";
16
- export { createInlineClientDriver } from "@/inline-client-driver/mod";
17
15
  // Re-export important protocol types and utilities needed by drivers
18
16
  export type { ActorQuery } from "@/manager/protocol/query";
19
17
  export * from "@/registry/mod";
@@ -5,7 +5,7 @@ import type { ActorDefinition, AnyActorDefinition } from "@/actor/definition";
5
5
 
6
6
  export const ActorsSchema = z.record(
7
7
  z.string(),
8
- z.custom<ActorDefinition<any, any, any, any, any, any, any, any>>(),
8
+ z.custom<ActorDefinition<any, any, any, any, any, any, any>>(),
9
9
  );
10
10
  export type RegistryActors = z.infer<typeof ActorsSchema>;
11
11
 
@@ -1,7 +1,5 @@
1
- import { getLogger } from "@/common//log";
2
-
3
- export const LOGGER_NAME = "registry";
1
+ import { getLogger } from "@/common/log";
4
2
 
5
3
  export function logger() {
6
- return getLogger(LOGGER_NAME);
4
+ return getLogger("registry");
7
5
  }
@@ -1,10 +1,10 @@
1
1
  import type { Hono } from "hono";
2
- import { createActorRouter } from "@/actor/router";
3
2
  import { type Client, createClientWithDriver } from "@/client/client";
3
+ import { configureBaseLogger, configureDefaultLogger } from "@/common/log";
4
4
  import { chooseDefaultDriver } from "@/drivers/default";
5
- import { createInlineClientDriver } from "@/inline-client-driver/mod";
6
5
  import { getInspectorUrl } from "@/inspector/utils";
7
6
  import { createManagerRouter } from "@/manager/router";
7
+ import pkg from "../../package.json" with { type: "json" };
8
8
  import {
9
9
  type RegistryActors,
10
10
  type RegistryConfig,
@@ -21,10 +21,10 @@ import {
21
21
  import { crossPlatformServe } from "./serve";
22
22
 
23
23
  interface ServerOutput<A extends Registry<any>> {
24
+ /** Client to communicate with the actors. */
24
25
  client: Client<A>;
25
- hono: Hono;
26
- handler: (req: Request) => Promise<Response>;
27
- serve: (hono?: Hono) => void;
26
+ /** Fetch handler to manually route requests to the Rivet manager API. */
27
+ fetch: (request: Request, ...args: any) => Response | Promise<Response>;
28
28
  }
29
29
 
30
30
  export class Registry<A extends RegistryActors> {
@@ -41,12 +41,34 @@ export class Registry<A extends RegistryActors> {
41
41
  /**
42
42
  * Runs the registry for a server.
43
43
  */
44
- public createServer(inputConfig?: RunConfigInput): ServerOutput<this> {
44
+ public start(inputConfig?: RunConfigInput): ServerOutput<this> {
45
45
  const config = RunConfigSchema.parse(inputConfig);
46
46
 
47
+ // Configure logger
48
+ if (config.logging?.baseLogger) {
49
+ // Use provided base logger
50
+ configureBaseLogger(config.logging.baseLogger);
51
+ } else {
52
+ // Configure default logger with log level from config
53
+ // getPinoLevel will handle env variable priority
54
+ configureDefaultLogger(config.logging?.level);
55
+ }
56
+
47
57
  // Choose the driver based on configuration
48
58
  const driver = chooseDefaultDriver(config);
49
59
 
60
+ // TODO: Find cleaner way of disabling by default
61
+ if (driver.name === "engine") {
62
+ config.inspector.enabled = false;
63
+ config.disableServer = true;
64
+ }
65
+ if (driver.name === "cloudflare-workers") {
66
+ config.inspector.enabled = false;
67
+ config.disableServer = true;
68
+ config.disableActorDriver = true;
69
+ config.noWelcome = true;
70
+ }
71
+
50
72
  // Configure getUpgradeWebSocket lazily so we can assign it in crossPlatformServe
51
73
  let upgradeWebSocket: any;
52
74
  if (!config.getUpgradeWebSocket) {
@@ -55,62 +77,69 @@ export class Registry<A extends RegistryActors> {
55
77
 
56
78
  // Create router
57
79
  const managerDriver = driver.manager(this.#config, config);
58
- const clientDriver = createInlineClientDriver(managerDriver);
59
80
  const { router: hono } = createManagerRouter(
60
81
  this.#config,
61
82
  config,
62
- clientDriver,
63
83
  managerDriver,
64
84
  false,
65
85
  );
66
86
 
67
87
  // Create client
68
- const client = createClientWithDriver<this>(clientDriver);
88
+ const client = createClientWithDriver<this>(managerDriver, config);
69
89
 
70
90
  const driverLog = managerDriver.extraStartupLog?.() ?? {};
71
- logger().info("rivetkit ready", {
91
+ logger().info({
92
+ msg: "rivetkit ready",
72
93
  driver: driver.name,
73
94
  definitions: Object.keys(this.#config.use).length,
74
95
  ...driverLog,
75
96
  });
76
- if (config.inspector?.enabled) {
77
- logger().info("inspector ready", {
78
- url: getInspectorUrl(config),
79
- });
97
+ if (config.inspector?.enabled && managerDriver.inspector) {
98
+ logger().info({ msg: "inspector ready", url: getInspectorUrl(config) });
99
+ }
100
+
101
+ // Print welcome information
102
+ if (!config.noWelcome) {
103
+ const displayInfo = managerDriver.displayInformation();
104
+ console.log();
105
+ console.log(` RivetKit ${pkg.version} (${displayInfo.name})`);
106
+ console.log(` - Endpoint: http://127.0.0.1:6420`);
107
+ for (const [k, v] of Object.entries(displayInfo.properties)) {
108
+ const padding = " ".repeat(Math.max(0, 13 - k.length));
109
+ console.log(` - ${k}:${padding}${v}`);
110
+ }
111
+ if (config.inspector?.enabled && managerDriver.inspector) {
112
+ console.log(` - Inspector: ${getInspectorUrl(config)}`);
113
+ }
114
+ console.log();
80
115
  }
81
116
 
117
+ // HACK: We need to find a better way to let the driver itself decide when to start the actor driver
82
118
  // Create runner
83
- if (config.role === "all" || config.role === "runner") {
84
- const inlineClient = createClientWithDriver(
85
- createInlineClientDriver(managerDriver),
86
- );
119
+ //
120
+ // Even though we do not use the return value, this is required to start the code that will handle incoming actors
121
+ if (!config.disableActorDriver) {
87
122
  const _actorDriver = driver.actor(
88
123
  this.#config,
89
124
  config,
90
125
  managerDriver,
91
- inlineClient,
126
+ client,
92
127
  );
93
- // TODO: What do we do with the actor driver here?
128
+ }
129
+
130
+ // Start server
131
+ if (!config.disableServer) {
132
+ (async () => {
133
+ const out = await crossPlatformServe(hono, undefined);
134
+ upgradeWebSocket = out.upgradeWebSocket;
135
+ })();
94
136
  }
95
137
 
96
138
  return {
97
139
  client,
98
- hono,
99
- handler: async (req: Request) => await hono.fetch(req),
100
- serve: async (app) => {
101
- const out = await crossPlatformServe(hono, app);
102
- upgradeWebSocket = out.upgradeWebSocket;
103
- },
140
+ fetch: hono.fetch.bind(hono),
104
141
  };
105
142
  }
106
-
107
- /**
108
- * Runs the registry as a standalone server.
109
- */
110
- public async runServer(inputConfig?: RunConfigInput) {
111
- const { serve } = this.createServer(inputConfig);
112
- serve();
113
- }
114
143
  }
115
144
 
116
145
  export function setup<A extends RegistryActors>(
@@ -1,14 +1,14 @@
1
1
  import type { cors } from "hono/cors";
2
+ import type { Logger } from "pino";
2
3
  import { z } from "zod";
3
4
  import type { ActorDriverBuilder } from "@/actor/driver";
5
+ import { ClientConfigSchema } from "@/client/config";
6
+ import { LogLevelSchema } from "@/common/log";
4
7
  import { InspectorConfigSchema } from "@/inspector/config";
5
8
  import type { ManagerDriverBuilder } from "@/manager/driver";
6
- import type { UpgradeWebSocket } from "@/utils";
7
9
 
8
10
  type CorsOptions = NonNullable<Parameters<typeof cors>[0]>;
9
11
 
10
- export type GetUpgradeWebSocket = () => UpgradeWebSocket;
11
-
12
12
  export const DriverConfigSchema = z.object({
13
13
  /** Machine-readable name to identify this driver by. */
14
14
  name: z.string(),
@@ -19,36 +19,49 @@ export const DriverConfigSchema = z.object({
19
19
  export type DriverConfig = z.infer<typeof DriverConfigSchema>;
20
20
 
21
21
  /** Base config used for the actor config across all platforms. */
22
- export const RunConfigSchema = z
23
- .object({
24
- driver: DriverConfigSchema.optional(),
22
+ export const RunConfigSchema = ClientConfigSchema.extend({
23
+ driver: DriverConfigSchema.optional(),
24
+
25
+ /** CORS configuration for the router. Uses Hono's CORS middleware options. */
26
+ cors: z.custom<CorsOptions>().optional(),
25
27
 
26
- /** Endpoint to connect to the Rivet engine. Can be configured via RIVET_ENGINE env var. */
27
- engine: z.string().optional(),
28
+ maxIncomingMessageSize: z.number().optional().default(65_536),
28
29
 
29
- // This is a function to allow for lazy configuration of upgradeWebSocket on the
30
- // fly. This is required since the dependencies that profie upgradeWebSocket
31
- // (specifically Node.js) can sometimes only be specified after the router is
32
- // created or must be imported async using `await import(...)`
33
- getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
30
+ inspector: InspectorConfigSchema,
34
31
 
35
- role: z.enum(["all", "server", "runner"]).optional().default("all"),
32
+ /** @experimental */
33
+ disableServer: z.boolean().optional().default(false),
36
34
 
37
- /** CORS configuration for the router. Uses Hono's CORS middleware options. */
38
- cors: z.custom<CorsOptions>().optional(),
35
+ /** @experimental */
36
+ disableActorDriver: z.boolean().optional().default(false),
39
37
 
40
- maxIncomingMessageSize: z.number().optional().default(65_536),
38
+ /**
39
+ * @experimental
40
+ *
41
+ * Base path for the router. This is used to prefix all routes.
42
+ * For example, if the base path is `/api`, then the route `/actors` will be
43
+ * available at `/api/actors`.
44
+ */
45
+ basePath: z.string().optional().default("/"),
41
46
 
42
- inspector: InspectorConfigSchema,
47
+ /**
48
+ * @experimental
49
+ *
50
+ * Disable welcome message.
51
+ * */
52
+ noWelcome: z.boolean().optional().default(false),
43
53
 
44
- /**
45
- * Base path for the router. This is used to prefix all routes.
46
- * For example, if the base path is `/api`, then the route `/actors` will be
47
- * available at `/api/actors`.
48
- */
49
- basePath: z.string().optional().default("/"),
50
- })
51
- .default({});
54
+ /**
55
+ * @experimental
56
+ * */
57
+ logging: z
58
+ .object({
59
+ baseLogger: z.custom<Logger>().optional(),
60
+ level: LogLevelSchema.optional(),
61
+ })
62
+ .optional()
63
+ .default({}),
64
+ }).default({});
52
65
 
53
66
  export type RunConfig = z.infer<typeof RunConfigSchema>;
54
67
  export type RunConfigInput = z.input<typeof RunConfigSchema>;
@@ -21,7 +21,8 @@ export async function crossPlatformServe(
21
21
  }
22
22
 
23
23
  // Mount registry
24
- app.route("/registry", rivetKitRouter);
24
+ // app.route("/registry", rivetKitRouter);
25
+ app.route("/", rivetKitRouter);
25
26
 
26
27
  // Import @hono/node-ws
27
28
  let createNodeWebSocket: any;
@@ -41,11 +42,9 @@ export async function crossPlatformServe(
41
42
  });
42
43
 
43
44
  // Start server
44
- const port = Number.parseInt(
45
- getEnvUniversal("PORT") ?? getEnvUniversal("PORT_HTTP") ?? "8080",
46
- );
45
+ const port = 6420;
47
46
  const server = serve({ fetch: app.fetch, port }, () =>
48
- logger().info("server listening", { port }),
47
+ logger().info({ msg: "server listening", port }),
49
48
  );
50
49
  injectWebSocket(server);
51
50
 
@@ -0,0 +1,74 @@
1
+ import type { ClientConfig } from "@/client/config";
2
+ import { combineUrlPath } from "@/utils";
3
+ import { getEndpoint } from "./api-utils";
4
+
5
+ export async function sendHttpRequestToActor(
6
+ runConfig: ClientConfig,
7
+ actorId: string,
8
+ actorRequest: Request,
9
+ ): Promise<Response> {
10
+ // Route through guard port
11
+ const url = new URL(actorRequest.url);
12
+ const endpoint = getEndpoint(runConfig);
13
+ const guardUrl = combineUrlPath(endpoint, url.pathname + url.search);
14
+
15
+ // Handle body properly based on method and presence
16
+ let bodyToSend: ArrayBuffer | null = null;
17
+ const guardHeaders = buildGuardHeadersForHttp(actorRequest, actorId);
18
+
19
+ if (
20
+ actorRequest.body &&
21
+ actorRequest.method !== "GET" &&
22
+ actorRequest.method !== "HEAD"
23
+ ) {
24
+ if (actorRequest.bodyUsed) {
25
+ throw new Error("Request body has already been consumed");
26
+ }
27
+
28
+ // TODO: This buffers the entire request in memory every time. We
29
+ // need to properly implement streaming bodies.
30
+ // Clone and read the body to ensure it can be sent
31
+ const clonedRequest = actorRequest.clone();
32
+ bodyToSend = await clonedRequest.arrayBuffer();
33
+
34
+ // If this is a streaming request, we need to convert the headers
35
+ // for the basic array buffer
36
+ guardHeaders.delete("transfer-encoding");
37
+ guardHeaders.set(
38
+ "content-length",
39
+ String((bodyToSend as ArrayBuffer).byteLength),
40
+ );
41
+ }
42
+
43
+ const guardRequest = new Request(guardUrl, {
44
+ method: actorRequest.method,
45
+ headers: guardHeaders,
46
+ body: bodyToSend,
47
+ signal: actorRequest.signal,
48
+ });
49
+
50
+ return mutableResponse(await fetch(guardRequest));
51
+ }
52
+
53
+ function mutableResponse(fetchRes: Response): Response {
54
+ // We cannot return the raw response from `fetch` since the response type is not mutable.
55
+ //
56
+ // In order for middleware to be able to mutate the response, we need to build a new Response object that is mutable.
57
+ return new Response(fetchRes.body, fetchRes);
58
+ }
59
+
60
+ function buildGuardHeadersForHttp(
61
+ actorRequest: Request,
62
+ actorId: string,
63
+ ): Headers {
64
+ const headers = new Headers();
65
+ // Copy all headers from the original request
66
+ for (const [key, value] of actorRequest.headers.entries()) {
67
+ headers.set(key, value);
68
+ }
69
+ // Add guard-specific headers
70
+ headers.set("x-rivet-target", "actor");
71
+ headers.set("x-rivet-actor", actorId);
72
+ headers.set("x-rivet-port", "main");
73
+ return headers;
74
+ }
@@ -0,0 +1,64 @@
1
+ import {
2
+ HEADER_AUTH_DATA,
3
+ HEADER_CONN_PARAMS,
4
+ HEADER_ENCODING,
5
+ } from "@/actor/router-endpoints";
6
+ import type { ClientConfig } from "@/client/config";
7
+ import { importWebSocket } from "@/common/websocket";
8
+ import type { Encoding, UniversalWebSocket } from "@/mod";
9
+ import { combineUrlPath } from "@/utils";
10
+ import { getEndpoint } from "./api-utils";
11
+ import { logger } from "./log";
12
+
13
+ export async function openWebSocketToActor(
14
+ runConfig: ClientConfig,
15
+ path: string,
16
+ actorId: string,
17
+ encoding: Encoding,
18
+ params: unknown,
19
+ ): Promise<UniversalWebSocket> {
20
+ const WebSocket = await importWebSocket();
21
+
22
+ // WebSocket connections go through guard
23
+ const endpoint = getEndpoint(runConfig);
24
+ const guardUrl = combineUrlPath(endpoint, path);
25
+
26
+ logger().debug({
27
+ msg: "opening websocket to actor via guard",
28
+ actorId,
29
+ path,
30
+ guardUrl,
31
+ });
32
+
33
+ // Create WebSocket connection
34
+ const ws = new WebSocket(guardUrl, {
35
+ headers: buildGuardHeadersForWebSocket(actorId, encoding, params),
36
+ });
37
+
38
+ // Set binary type to arraybuffer for proper encoding support
39
+ ws.binaryType = "arraybuffer";
40
+
41
+ logger().debug({ msg: "websocket connection opened", actorId });
42
+
43
+ return ws as UniversalWebSocket;
44
+ }
45
+
46
+ export function buildGuardHeadersForWebSocket(
47
+ actorId: string,
48
+ encoding: Encoding,
49
+ params?: unknown,
50
+ authData?: unknown,
51
+ ): Record<string, string> {
52
+ const headers: Record<string, string> = {};
53
+ headers["x-rivet-target"] = "actor";
54
+ headers["x-rivet-actor"] = actorId;
55
+ headers["x-rivet-port"] = "main";
56
+ headers[HEADER_ENCODING] = encoding;
57
+ if (params) {
58
+ headers[HEADER_CONN_PARAMS] = JSON.stringify(params);
59
+ }
60
+ if (authData) {
61
+ headers[HEADER_AUTH_DATA] = JSON.stringify(authData);
62
+ }
63
+ return headers;
64
+ }
@@ -0,0 +1,79 @@
1
+ import { serializeActorKey } from "@/actor/keys";
2
+ import type { ClientConfig } from "@/client/client";
3
+ import type {
4
+ ActorsCreateRequest,
5
+ ActorsCreateResponse,
6
+ } from "@/manager-api/routes/actors-create";
7
+ import type { ActorsDeleteResponse } from "@/manager-api/routes/actors-delete";
8
+ import type { ActorsGetResponse } from "@/manager-api/routes/actors-get";
9
+ import type { ActorsGetByIdResponse } from "@/manager-api/routes/actors-get-by-id";
10
+ import type {
11
+ ActorsGetOrCreateByIdRequest,
12
+ ActorsGetOrCreateByIdResponse,
13
+ } from "@/manager-api/routes/actors-get-or-create-by-id";
14
+ import type { RivetId } from "@/manager-api/routes/common";
15
+ import { apiCall } from "./api-utils";
16
+
17
+ // MARK: Get actor
18
+ export async function getActor(
19
+ config: ClientConfig,
20
+ actorId: RivetId,
21
+ ): Promise<ActorsGetResponse> {
22
+ return apiCall<never, ActorsGetResponse>(
23
+ config,
24
+ "GET",
25
+ `/actors/${encodeURIComponent(actorId)}`,
26
+ );
27
+ }
28
+
29
+ // MARK: Get actor by id
30
+ export async function getActorById(
31
+ config: ClientConfig,
32
+ name: string,
33
+ key: string[],
34
+ ): Promise<ActorsGetByIdResponse> {
35
+ const serializedKey = serializeActorKey(key);
36
+ return apiCall<never, ActorsGetByIdResponse>(
37
+ config,
38
+ "GET",
39
+ `/actors/by-id?name=${encodeURIComponent(name)}&key=${encodeURIComponent(serializedKey)}`,
40
+ );
41
+ }
42
+
43
+ // MARK: Get or create actor by id
44
+ export async function getOrCreateActorById(
45
+ config: ClientConfig,
46
+ request: ActorsGetOrCreateByIdRequest,
47
+ ): Promise<ActorsGetOrCreateByIdResponse> {
48
+ return apiCall<ActorsGetOrCreateByIdRequest, ActorsGetOrCreateByIdResponse>(
49
+ config,
50
+ "PUT",
51
+ `/actors/by-id`,
52
+ request,
53
+ );
54
+ }
55
+
56
+ // MARK: Create actor
57
+ export async function createActor(
58
+ config: ClientConfig,
59
+ request: ActorsCreateRequest,
60
+ ): Promise<ActorsCreateResponse> {
61
+ return apiCall<ActorsCreateRequest, ActorsCreateResponse>(
62
+ config,
63
+ "POST",
64
+ `/actors`,
65
+ request,
66
+ );
67
+ }
68
+
69
+ // MARK: Destroy actor
70
+ export async function destroyActor(
71
+ config: ClientConfig,
72
+ actorId: RivetId,
73
+ ): Promise<ActorsDeleteResponse> {
74
+ return apiCall<never, ActorsDeleteResponse>(
75
+ config,
76
+ "DELETE",
77
+ `/actors/${encodeURIComponent(actorId)}`,
78
+ );
79
+ }
@@ -0,0 +1,46 @@
1
+ import type { ClientConfig } from "@/client/config";
2
+ import { sendHttpRequest } from "@/client/utils";
3
+ import { combineUrlPath } from "@/utils";
4
+ import { logger } from "./log";
5
+
6
+ // Error class for Engine API errors
7
+ export class EngineApiError extends Error {
8
+ constructor(
9
+ public readonly group: string,
10
+ public readonly code: string,
11
+ message?: string,
12
+ ) {
13
+ super(message || `Engine API error: ${group}/${code}`);
14
+ this.name = "EngineApiError";
15
+ }
16
+ }
17
+
18
+ export function getEndpoint(config: ClientConfig) {
19
+ return config.endpoint ?? "http://127.0.0.1:6420";
20
+ }
21
+
22
+ // Helper function for making API calls
23
+ export async function apiCall<TInput = unknown, TOutput = unknown>(
24
+ config: ClientConfig,
25
+ method: "GET" | "POST" | "PUT" | "DELETE",
26
+ path: string,
27
+ body?: TInput,
28
+ ): Promise<TOutput> {
29
+ const endpoint = getEndpoint(config);
30
+ const url = combineUrlPath(endpoint, path, {
31
+ namespace: config.namespace,
32
+ });
33
+
34
+ logger().debug({ msg: "making api call", method, url });
35
+
36
+ return await sendHttpRequest<TInput, TOutput>({
37
+ method,
38
+ url,
39
+ headers: {},
40
+ body,
41
+ encoding: "json",
42
+ skipParseResponse: false,
43
+ requestVersionedDataHandler: undefined,
44
+ responseVersionedDataHandler: undefined,
45
+ });
46
+ }
@@ -0,0 +1,5 @@
1
+ import { getLogger } from "@/common//log";
2
+
3
+ export function logger() {
4
+ return getLogger("remote-manager-driver");
5
+ }