rivetkit 2.0.3 → 2.0.4

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 (233) 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-6PDXBYI5.js → chunk-3F2YSRJL.js} +8 -23
  10. package/dist/tsup/chunk-3F2YSRJL.js.map +1 -0
  11. package/dist/tsup/chunk-4CXBCT26.cjs +250 -0
  12. package/dist/tsup/chunk-4CXBCT26.cjs.map +1 -0
  13. package/dist/tsup/chunk-4R73YDN3.cjs +20 -0
  14. package/dist/tsup/chunk-4R73YDN3.cjs.map +1 -0
  15. package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-6LJT3QRL.cjs} +39 -25
  16. package/dist/tsup/chunk-6LJT3QRL.cjs.map +1 -0
  17. package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-GICQ3YCU.cjs} +143 -141
  18. package/dist/tsup/chunk-GICQ3YCU.cjs.map +1 -0
  19. package/dist/tsup/{chunk-FLMTTN27.js → chunk-H26RP6GD.js} +15 -8
  20. package/dist/tsup/chunk-H26RP6GD.js.map +1 -0
  21. package/dist/tsup/chunk-HI3HWJRC.js +20 -0
  22. package/dist/tsup/chunk-HI3HWJRC.js.map +1 -0
  23. package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-HLLF4B4Q.js} +116 -114
  24. package/dist/tsup/chunk-HLLF4B4Q.js.map +1 -0
  25. package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-IH6CKNDW.cjs} +12 -27
  26. package/dist/tsup/chunk-IH6CKNDW.cjs.map +1 -0
  27. package/dist/tsup/chunk-LV2S3OU3.js +250 -0
  28. package/dist/tsup/chunk-LV2S3OU3.js.map +1 -0
  29. package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LWNKVZG5.cjs} +20 -13
  30. package/dist/tsup/chunk-LWNKVZG5.cjs.map +1 -0
  31. package/dist/tsup/{chunk-INGJP237.js → chunk-NFU2BBT5.js} +102 -43
  32. package/dist/tsup/chunk-NFU2BBT5.js.map +1 -0
  33. package/dist/tsup/{chunk-3H7O2A7I.js → chunk-PQY7KKTL.js} +33 -19
  34. package/dist/tsup/chunk-PQY7KKTL.js.map +1 -0
  35. package/dist/tsup/{chunk-PO4VLDWA.js → chunk-QK72M5JB.js} +3 -5
  36. package/dist/tsup/chunk-QK72M5JB.js.map +1 -0
  37. package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-QNNXFOQV.cjs} +3 -5
  38. package/dist/tsup/chunk-QNNXFOQV.cjs.map +1 -0
  39. package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-SBHHJ6QS.cjs} +102 -43
  40. package/dist/tsup/chunk-SBHHJ6QS.cjs.map +1 -0
  41. package/dist/tsup/chunk-TQ62L3X7.js +325 -0
  42. package/dist/tsup/chunk-TQ62L3X7.js.map +1 -0
  43. package/dist/tsup/chunk-VO7ZRVVD.cjs +6293 -0
  44. package/dist/tsup/chunk-VO7ZRVVD.cjs.map +1 -0
  45. package/dist/tsup/chunk-WHBPJNGW.cjs +325 -0
  46. package/dist/tsup/chunk-WHBPJNGW.cjs.map +1 -0
  47. package/dist/tsup/chunk-XJQHKJ4P.js +6293 -0
  48. package/dist/tsup/chunk-XJQHKJ4P.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-BI-6UIBJ.d.ts} +196 -226
  63. package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-Dyd4NLGW.d.cts} +196 -226
  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 +155 -1363
  70. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  71. package/dist/tsup/driver-test-suite/mod.d.cts +11 -5
  72. package/dist/tsup/driver-test-suite/mod.d.ts +11 -5
  73. package/dist/tsup/driver-test-suite/mod.js +876 -2084
  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-BTe_Rsdn.d.cts} +2 -3
  86. package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-CBSrKHmo.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 +3 -3
  95. package/dist/tsup/utils.d.cts +1 -1
  96. package/dist/tsup/utils.d.ts +1 -1
  97. package/dist/tsup/utils.js +2 -2
  98. package/package.json +4 -4
  99. package/src/actor/action.ts +1 -5
  100. package/src/actor/config.ts +27 -295
  101. package/src/actor/connection.ts +9 -12
  102. package/src/actor/context.ts +1 -4
  103. package/src/actor/definition.ts +7 -11
  104. package/src/actor/errors.ts +97 -35
  105. package/src/actor/generic-conn-driver.ts +28 -16
  106. package/src/actor/instance.ts +177 -133
  107. package/src/actor/log.ts +4 -13
  108. package/src/actor/mod.ts +0 -5
  109. package/src/actor/protocol/old.ts +42 -26
  110. package/src/actor/protocol/serde.ts +1 -1
  111. package/src/actor/router-endpoints.ts +41 -38
  112. package/src/actor/router.ts +20 -18
  113. package/src/actor/unstable-react.ts +1 -1
  114. package/src/actor/utils.ts +6 -2
  115. package/src/client/actor-common.ts +1 -1
  116. package/src/client/actor-conn.ts +152 -91
  117. package/src/client/actor-handle.ts +85 -25
  118. package/src/client/actor-query.ts +65 -0
  119. package/src/client/client.ts +29 -98
  120. package/src/client/config.ts +44 -0
  121. package/src/client/errors.ts +1 -0
  122. package/src/client/log.ts +2 -4
  123. package/src/client/mod.ts +16 -12
  124. package/src/client/raw-utils.ts +82 -25
  125. package/src/client/utils.ts +5 -3
  126. package/src/common/fake-event-source.ts +10 -9
  127. package/src/common/inline-websocket-adapter2.ts +39 -30
  128. package/src/common/log.ts +176 -101
  129. package/src/common/logfmt.ts +21 -30
  130. package/src/common/router.ts +12 -19
  131. package/src/common/utils.ts +27 -13
  132. package/src/common/websocket.ts +0 -1
  133. package/src/driver-helpers/mod.ts +1 -1
  134. package/src/driver-test-suite/log.ts +1 -3
  135. package/src/driver-test-suite/mod.ts +86 -60
  136. package/src/driver-test-suite/tests/actor-handle.ts +33 -0
  137. package/src/driver-test-suite/tests/manager-driver.ts +5 -3
  138. package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
  139. package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
  140. package/src/driver-test-suite/tests/request-access.ts +112 -126
  141. package/src/driver-test-suite/utils.ts +13 -10
  142. package/src/drivers/default.ts +7 -4
  143. package/src/drivers/engine/actor-driver.ts +22 -13
  144. package/src/drivers/engine/config.ts +2 -10
  145. package/src/drivers/engine/kv.ts +1 -1
  146. package/src/drivers/engine/log.ts +1 -3
  147. package/src/drivers/engine/mod.ts +2 -3
  148. package/src/drivers/file-system/actor.ts +1 -1
  149. package/src/drivers/file-system/global-state.ts +33 -20
  150. package/src/drivers/file-system/log.ts +1 -3
  151. package/src/drivers/file-system/manager.ts +31 -8
  152. package/src/inspector/config.ts +9 -4
  153. package/src/inspector/log.ts +1 -1
  154. package/src/inspector/manager.ts +2 -2
  155. package/src/inspector/utils.ts +1 -1
  156. package/src/manager/driver.ts +10 -2
  157. package/src/manager/hono-websocket-adapter.ts +21 -12
  158. package/src/manager/log.ts +2 -4
  159. package/src/manager/mod.ts +1 -1
  160. package/src/manager/router.ts +277 -1657
  161. package/src/manager-api/routes/actors-create.ts +16 -0
  162. package/src/manager-api/routes/actors-delete.ts +4 -0
  163. package/src/manager-api/routes/actors-get-by-id.ts +7 -0
  164. package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
  165. package/src/manager-api/routes/actors-get.ts +7 -0
  166. package/src/manager-api/routes/common.ts +18 -0
  167. package/src/mod.ts +0 -2
  168. package/src/registry/config.ts +1 -1
  169. package/src/registry/log.ts +2 -4
  170. package/src/registry/mod.ts +57 -24
  171. package/src/registry/run-config.ts +31 -33
  172. package/src/registry/serve.ts +4 -5
  173. package/src/remote-manager-driver/actor-http-client.ts +72 -0
  174. package/src/remote-manager-driver/actor-websocket-client.ts +63 -0
  175. package/src/remote-manager-driver/api-endpoints.ts +79 -0
  176. package/src/remote-manager-driver/api-utils.ts +43 -0
  177. package/src/remote-manager-driver/log.ts +5 -0
  178. package/src/remote-manager-driver/mod.ts +274 -0
  179. package/src/{drivers/engine → remote-manager-driver}/ws-proxy.ts +24 -14
  180. package/src/serde.ts +8 -2
  181. package/src/test/log.ts +1 -3
  182. package/src/test/mod.ts +17 -16
  183. package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
  184. package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
  185. package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
  186. package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
  187. package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
  188. package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
  189. package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
  190. package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
  191. package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
  192. package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
  193. package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
  194. package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
  195. package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
  196. package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
  197. package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
  198. package/dist/tsup/chunk-INGJP237.js.map +0 -1
  199. package/dist/tsup/chunk-KJCJLKRM.js +0 -116
  200. package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
  201. package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
  202. package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
  203. package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
  204. package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
  205. package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
  206. package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
  207. package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
  208. package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
  209. package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
  210. package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
  211. package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
  212. package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
  213. package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
  214. package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
  215. package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
  216. package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
  217. package/dist/tsup/chunk-UVUPOS46.js +0 -230
  218. package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
  219. package/dist/tsup/chunk-VRRHBNJC.js +0 -189
  220. package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
  221. package/dist/tsup/chunk-XFSS33EQ.js +0 -202
  222. package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
  223. package/src/client/http-client-driver.ts +0 -326
  224. package/src/driver-test-suite/test-inline-client-driver.ts +0 -402
  225. package/src/driver-test-suite/tests/actor-auth.ts +0 -591
  226. package/src/drivers/engine/api-endpoints.ts +0 -128
  227. package/src/drivers/engine/api-utils.ts +0 -70
  228. package/src/drivers/engine/manager-driver.ts +0 -391
  229. package/src/inline-client-driver/log.ts +0 -7
  230. package/src/inline-client-driver/mod.ts +0 -385
  231. package/src/manager/auth.ts +0 -121
  232. /package/src/{drivers/engine → actor}/keys.test.ts +0 -0
  233. /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,6 +21,8 @@ import {
21
21
  import { crossPlatformServe } from "./serve";
22
22
 
23
23
  interface ServerOutput<A extends Registry<any>> {
24
+ config: RunConfig;
25
+ driver: DriverConfig;
24
26
  client: Client<A>;
25
27
  hono: Hono;
26
28
  handler: (req: Request) => Promise<Response>;
@@ -44,9 +46,24 @@ export class Registry<A extends RegistryActors> {
44
46
  public createServer(inputConfig?: RunConfigInput): ServerOutput<this> {
45
47
  const config = RunConfigSchema.parse(inputConfig);
46
48
 
49
+ // Configure logger
50
+ if (config.logging?.baseLogger) {
51
+ // Use provided base logger
52
+ configureBaseLogger(config.logging.baseLogger);
53
+ } else {
54
+ // Configure default logger with log level from config
55
+ // getPinoLevel will handle env variable priority
56
+ configureDefaultLogger(config.logging?.level);
57
+ }
58
+
47
59
  // Choose the driver based on configuration
48
60
  const driver = chooseDefaultDriver(config);
49
61
 
62
+ // TODO: Find cleaner way of disabling by default
63
+ if (driver.name === "engine") {
64
+ config.inspector.enabled = false;
65
+ }
66
+
50
67
  // Configure getUpgradeWebSocket lazily so we can assign it in crossPlatformServe
51
68
  let upgradeWebSocket: any;
52
69
  if (!config.getUpgradeWebSocket) {
@@ -55,45 +72,56 @@ export class Registry<A extends RegistryActors> {
55
72
 
56
73
  // Create router
57
74
  const managerDriver = driver.manager(this.#config, config);
58
- const clientDriver = createInlineClientDriver(managerDriver);
59
75
  const { router: hono } = createManagerRouter(
60
76
  this.#config,
61
77
  config,
62
- clientDriver,
63
78
  managerDriver,
64
79
  false,
65
80
  );
66
81
 
67
82
  // Create client
68
- const client = createClientWithDriver<this>(clientDriver);
83
+ const client = createClientWithDriver<this>(managerDriver, config);
69
84
 
70
85
  const driverLog = managerDriver.extraStartupLog?.() ?? {};
71
- logger().info("rivetkit ready", {
86
+ logger().info({
87
+ msg: "rivetkit ready",
72
88
  driver: driver.name,
73
89
  definitions: Object.keys(this.#config.use).length,
74
90
  ...driverLog,
75
91
  });
76
- if (config.inspector?.enabled) {
77
- logger().info("inspector ready", {
78
- url: getInspectorUrl(config),
79
- });
92
+ if (config.inspector?.enabled && managerDriver.inspector) {
93
+ logger().info({ msg: "inspector ready", url: getInspectorUrl(config) });
80
94
  }
81
95
 
82
- // Create runner
83
- if (config.role === "all" || config.role === "runner") {
84
- const inlineClient = createClientWithDriver(
85
- createInlineClientDriver(managerDriver),
86
- );
87
- const _actorDriver = driver.actor(
88
- this.#config,
89
- config,
90
- managerDriver,
91
- inlineClient,
92
- );
93
- // TODO: What do we do with the actor driver here?
96
+ // Print welcome information
97
+ if (!config.noWelcome) {
98
+ const displayInfo = managerDriver.displayInformation();
99
+ console.log();
100
+ console.log(` RivetKit ${pkg.version} (${displayInfo.name})`);
101
+ console.log(` - Endpoint: http://127.0.0.1:6420`);
102
+ for (const [k, v] of Object.entries(displayInfo.properties)) {
103
+ const padding = " ".repeat(Math.max(0, 13 - k.length));
104
+ console.log(` - ${k}:${padding}${v}`);
105
+ }
106
+ if (config.inspector?.enabled && managerDriver.inspector) {
107
+ console.log(` - Inspector: ${getInspectorUrl(config)}`);
108
+ }
109
+ console.log();
94
110
  }
95
111
 
112
+ // Create runner
113
+ //
114
+ // Even though we do not use the return value, this is required to start the code that will handle incoming actors
115
+ const _actorDriver = driver.actor(
116
+ this.#config,
117
+ config,
118
+ managerDriver,
119
+ client,
120
+ );
121
+
96
122
  return {
123
+ config,
124
+ driver,
97
125
  client,
98
126
  hono,
99
127
  handler: async (req: Request) => await hono.fetch(req),
@@ -108,8 +136,13 @@ export class Registry<A extends RegistryActors> {
108
136
  * Runs the registry as a standalone server.
109
137
  */
110
138
  public async runServer(inputConfig?: RunConfigInput) {
111
- const { serve } = this.createServer(inputConfig);
112
- serve();
139
+ const { driver, serve } = this.createServer(inputConfig);
140
+
141
+ // TODO: FInd better way of doing this
142
+ // Don't run server by default
143
+ if (driver.name !== "engine") {
144
+ serve();
145
+ }
113
146
  }
114
147
  }
115
148
 
@@ -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,34 @@ 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(),
25
-
26
- /** Endpoint to connect to the Rivet engine. Can be configured via RIVET_ENGINE env var. */
27
- engine: z.string().optional(),
28
-
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(),
34
-
35
- role: z.enum(["all", "server", "runner"]).optional().default("all"),
36
-
37
- /** CORS configuration for the router. Uses Hono's CORS middleware options. */
38
- cors: z.custom<CorsOptions>().optional(),
39
-
40
- maxIncomingMessageSize: z.number().optional().default(65_536),
41
-
42
- inspector: InspectorConfigSchema,
43
-
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({});
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(),
27
+
28
+ maxIncomingMessageSize: z.number().optional().default(65_536),
29
+
30
+ inspector: InspectorConfigSchema,
31
+
32
+ /**
33
+ * Base path for the router. This is used to prefix all routes.
34
+ * For example, if the base path is `/api`, then the route `/actors` will be
35
+ * available at `/api/actors`.
36
+ */
37
+ basePath: z.string().optional().default("/"),
38
+
39
+ /** Disable welcome message. */
40
+ noWelcome: z.boolean().optional().default(false),
41
+
42
+ logging: z
43
+ .object({
44
+ baseLogger: z.custom<Logger>().optional(),
45
+ level: LogLevelSchema.optional(),
46
+ })
47
+ .optional()
48
+ .default({}),
49
+ }).default({});
52
50
 
53
51
  export type RunConfig = z.infer<typeof RunConfigSchema>;
54
52
  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,72 @@
1
+ import type { ClientConfig } from "@/client/config";
2
+ import { getEndpoint } from "./api-utils";
3
+
4
+ export async function sendHttpRequestToActor(
5
+ runConfig: ClientConfig,
6
+ actorId: string,
7
+ actorRequest: Request,
8
+ ): Promise<Response> {
9
+ // Route through guard port
10
+ const url = new URL(actorRequest.url);
11
+ const endpoint = getEndpoint(runConfig);
12
+ const guardUrl = `${endpoint}${url.pathname}${url.search}`;
13
+
14
+ // Handle body properly based on method and presence
15
+ let bodyToSend: ArrayBuffer | null = null;
16
+ const guardHeaders = buildGuardHeadersForHttp(actorRequest, actorId);
17
+
18
+ if (
19
+ actorRequest.body &&
20
+ actorRequest.method !== "GET" &&
21
+ actorRequest.method !== "HEAD"
22
+ ) {
23
+ if (actorRequest.bodyUsed) {
24
+ throw new Error("Request body has already been consumed");
25
+ }
26
+
27
+ // TODO: This buffers the entire request in memory every time. We
28
+ // need to properly implement streaming bodies.
29
+ // Clone and read the body to ensure it can be sent
30
+ const clonedRequest = actorRequest.clone();
31
+ bodyToSend = await clonedRequest.arrayBuffer();
32
+
33
+ // If this is a streaming request, we need to convert the headers
34
+ // for the basic array buffer
35
+ guardHeaders.delete("transfer-encoding");
36
+ guardHeaders.set(
37
+ "content-length",
38
+ String((bodyToSend as ArrayBuffer).byteLength),
39
+ );
40
+ }
41
+
42
+ const guardRequest = new Request(guardUrl, {
43
+ method: actorRequest.method,
44
+ headers: guardHeaders,
45
+ body: bodyToSend,
46
+ });
47
+
48
+ return mutableResponse(await fetch(guardRequest));
49
+ }
50
+
51
+ function mutableResponse(fetchRes: Response): Response {
52
+ // We cannot return the raw response from `fetch` since the response type is not mutable.
53
+ //
54
+ // In order for middleware to be able to mutate the response, we need to build a new Response object that is mutable.
55
+ return new Response(fetchRes.body, fetchRes);
56
+ }
57
+
58
+ function buildGuardHeadersForHttp(
59
+ actorRequest: Request,
60
+ actorId: string,
61
+ ): Headers {
62
+ const headers = new Headers();
63
+ // Copy all headers from the original request
64
+ for (const [key, value] of actorRequest.headers.entries()) {
65
+ headers.set(key, value);
66
+ }
67
+ // Add guard-specific headers
68
+ headers.set("x-rivet-target", "actor");
69
+ headers.set("x-rivet-actor", actorId);
70
+ headers.set("x-rivet-port", "main");
71
+ return headers;
72
+ }
@@ -0,0 +1,63 @@
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 { getEndpoint } from "./api-utils";
10
+ import { logger } from "./log";
11
+
12
+ export async function openWebSocketToActor(
13
+ runConfig: ClientConfig,
14
+ path: string,
15
+ actorId: string,
16
+ encoding: Encoding,
17
+ params: unknown,
18
+ ): Promise<UniversalWebSocket> {
19
+ const WebSocket = await importWebSocket();
20
+
21
+ // WebSocket connections go through guard
22
+ const endpoint = getEndpoint(runConfig);
23
+ const guardUrl = `${endpoint}${path}`;
24
+
25
+ logger().debug({
26
+ msg: "opening websocket to actor via guard",
27
+ actorId,
28
+ path,
29
+ guardUrl,
30
+ });
31
+
32
+ // Create WebSocket connection
33
+ const ws = new WebSocket(guardUrl, {
34
+ headers: buildGuardHeadersForWebSocket(actorId, encoding, params),
35
+ });
36
+
37
+ // Set binary type to arraybuffer for proper encoding support
38
+ ws.binaryType = "arraybuffer";
39
+
40
+ logger().debug({ msg: "websocket connection opened", actorId });
41
+
42
+ return ws as UniversalWebSocket;
43
+ }
44
+
45
+ export function buildGuardHeadersForWebSocket(
46
+ actorId: string,
47
+ encoding: Encoding,
48
+ params?: unknown,
49
+ authData?: unknown,
50
+ ): Record<string, string> {
51
+ const headers: Record<string, string> = {};
52
+ headers["x-rivet-target"] = "actor";
53
+ headers["x-rivet-actor"] = actorId;
54
+ headers["x-rivet-port"] = "main";
55
+ headers[HEADER_ENCODING] = encoding;
56
+ if (params) {
57
+ headers[HEADER_CONN_PARAMS] = JSON.stringify(params);
58
+ }
59
+ if (authData) {
60
+ headers[HEADER_AUTH_DATA] = JSON.stringify(authData);
61
+ }
62
+ return headers;
63
+ }
@@ -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,43 @@
1
+ import type { ClientConfig } from "@/client/config";
2
+ import { sendHttpRequest } from "@/client/utils";
3
+ import { logger } from "./log";
4
+
5
+ // Error class for Engine API errors
6
+ export class EngineApiError extends Error {
7
+ constructor(
8
+ public readonly group: string,
9
+ public readonly code: string,
10
+ message?: string,
11
+ ) {
12
+ super(message || `Engine API error: ${group}/${code}`);
13
+ this.name = "EngineApiError";
14
+ }
15
+ }
16
+
17
+ export function getEndpoint(config: ClientConfig) {
18
+ return config.endpoint ?? "http://127.0.0.1:6420";
19
+ }
20
+
21
+ // Helper function for making API calls
22
+ export async function apiCall<TInput = unknown, TOutput = unknown>(
23
+ config: ClientConfig,
24
+ method: "GET" | "POST" | "PUT" | "DELETE",
25
+ path: string,
26
+ body?: TInput,
27
+ ): Promise<TOutput> {
28
+ const endpoint = getEndpoint(config);
29
+ const url = `${endpoint}${path}${path.includes("?") ? "&" : "?"}namespace=${encodeURIComponent(config.namespace)}`;
30
+
31
+ logger().debug({ msg: "making api call", method, url });
32
+
33
+ return await sendHttpRequest<TInput, TOutput>({
34
+ method,
35
+ url,
36
+ headers: {},
37
+ body,
38
+ encoding: "json",
39
+ skipParseResponse: false,
40
+ requestVersionedDataHandler: undefined,
41
+ responseVersionedDataHandler: undefined,
42
+ });
43
+ }
@@ -0,0 +1,5 @@
1
+ import { getLogger } from "@/common//log";
2
+
3
+ export function logger() {
4
+ return getLogger("remote-manager-driver");
5
+ }