rivetkit 2.0.9 → 2.0.11

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 (123) hide show
  1. package/dist/tsup/{chunk-F2YZNUPU.js → chunk-3JUN3IEH.js} +3 -3
  2. package/dist/tsup/{chunk-DL7TPF63.cjs → chunk-5ABUOI3V.cjs} +7 -7
  3. package/dist/tsup/{chunk-DL7TPF63.cjs.map → chunk-5ABUOI3V.cjs.map} +1 -1
  4. package/dist/tsup/{chunk-SDXTJDDR.cjs → chunk-5JZPEJVJ.cjs} +58 -14
  5. package/dist/tsup/chunk-5JZPEJVJ.cjs.map +1 -0
  6. package/dist/tsup/{chunk-SOC4HWCG.cjs → chunk-6PORXHSQ.cjs} +92 -39
  7. package/dist/tsup/chunk-6PORXHSQ.cjs.map +1 -0
  8. package/dist/tsup/{chunk-QGRYH6TU.cjs → chunk-765F7ILI.cjs} +7 -6
  9. package/dist/tsup/chunk-765F7ILI.cjs.map +1 -0
  10. package/dist/tsup/{chunk-DLPIL3VC.js → chunk-7DCESQ4O.js} +2 -2
  11. package/dist/tsup/{chunk-R7OP5N25.js → chunk-AZI2T6UF.js} +53 -9
  12. package/dist/tsup/chunk-AZI2T6UF.js.map +1 -0
  13. package/dist/tsup/{chunk-A44TWAS5.cjs → chunk-GGIW54I2.cjs} +6 -6
  14. package/dist/tsup/{chunk-A44TWAS5.cjs.map → chunk-GGIW54I2.cjs.map} +1 -1
  15. package/dist/tsup/{chunk-7OMMIAWP.cjs → chunk-HDCLOVOE.cjs} +17 -12
  16. package/dist/tsup/chunk-HDCLOVOE.cjs.map +1 -0
  17. package/dist/tsup/{chunk-2MJYYF2Q.cjs → chunk-I6AVFIVY.cjs} +12 -12
  18. package/dist/tsup/{chunk-2MJYYF2Q.cjs.map → chunk-I6AVFIVY.cjs.map} +1 -1
  19. package/dist/tsup/{chunk-WBSPHV5V.js → chunk-JTWD6ZT2.js} +2 -2
  20. package/dist/tsup/{chunk-4YV6RDZL.cjs → chunk-LXFOO25H.cjs} +722 -359
  21. package/dist/tsup/chunk-LXFOO25H.cjs.map +1 -0
  22. package/dist/tsup/{chunk-YR2VY4XS.js → chunk-MIP4PYTD.js} +5 -4
  23. package/dist/tsup/chunk-MIP4PYTD.js.map +1 -0
  24. package/dist/tsup/{chunk-KHZ2QSQ4.js → chunk-MT5ES4XD.js} +32 -10
  25. package/dist/tsup/chunk-MT5ES4XD.js.map +1 -0
  26. package/dist/tsup/{chunk-U2IXX6DY.cjs → chunk-NLYAKGML.cjs} +5 -6
  27. package/dist/tsup/chunk-NLYAKGML.cjs.map +1 -0
  28. package/dist/tsup/{chunk-FZP2IBIX.js → chunk-NOXYAPM2.js} +603 -240
  29. package/dist/tsup/chunk-NOXYAPM2.js.map +1 -0
  30. package/dist/tsup/{chunk-E63WU5PL.js → chunk-NQFIZSTR.js} +5 -6
  31. package/dist/tsup/chunk-NQFIZSTR.js.map +1 -0
  32. package/dist/tsup/{chunk-4PSLOAXR.cjs → chunk-O7BIBANW.cjs} +226 -204
  33. package/dist/tsup/chunk-O7BIBANW.cjs.map +1 -0
  34. package/dist/tsup/{chunk-VVCL5DXN.js → chunk-OHSP4BUE.js} +97 -44
  35. package/dist/tsup/{chunk-VVCL5DXN.js.map → chunk-OHSP4BUE.js.map} +1 -1
  36. package/dist/tsup/{chunk-APHV6WXU.js → chunk-SBUJ3KIM.js} +2 -2
  37. package/dist/tsup/{chunk-DZZQG7VH.cjs → chunk-WYTLLIJM.cjs} +3 -3
  38. package/dist/tsup/{chunk-DZZQG7VH.cjs.map → chunk-WYTLLIJM.cjs.map} +1 -1
  39. package/dist/tsup/{chunk-WRSWUDFA.js → chunk-XO7VX4MN.js} +14 -9
  40. package/dist/tsup/chunk-XO7VX4MN.js.map +1 -0
  41. package/dist/tsup/client/mod.cjs +9 -9
  42. package/dist/tsup/client/mod.d.cts +2 -2
  43. package/dist/tsup/client/mod.d.ts +2 -2
  44. package/dist/tsup/client/mod.js +8 -8
  45. package/dist/tsup/common/log.cjs +3 -3
  46. package/dist/tsup/common/log.js +2 -2
  47. package/dist/tsup/common/websocket.cjs +4 -4
  48. package/dist/tsup/common/websocket.js +3 -3
  49. package/dist/tsup/{conn-CEh3WKbA.d.cts → conn-CT_8ZBT_.d.cts} +204 -199
  50. package/dist/tsup/{conn-Bt8rkUzm.d.ts → conn-d5F0M95s.d.ts} +204 -199
  51. package/dist/tsup/driver-helpers/mod.cjs +5 -5
  52. package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
  53. package/dist/tsup/driver-helpers/mod.d.cts +1 -1
  54. package/dist/tsup/driver-helpers/mod.d.ts +1 -1
  55. package/dist/tsup/driver-helpers/mod.js +6 -6
  56. package/dist/tsup/driver-test-suite/mod.cjs +117 -103
  57. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  58. package/dist/tsup/driver-test-suite/mod.d.cts +3 -2
  59. package/dist/tsup/driver-test-suite/mod.d.ts +3 -2
  60. package/dist/tsup/driver-test-suite/mod.js +62 -48
  61. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  62. package/dist/tsup/inspector/mod.cjs +6 -6
  63. package/dist/tsup/inspector/mod.d.cts +6 -6
  64. package/dist/tsup/inspector/mod.d.ts +6 -6
  65. package/dist/tsup/inspector/mod.js +5 -5
  66. package/dist/tsup/mod.cjs +10 -10
  67. package/dist/tsup/mod.d.cts +8 -39
  68. package/dist/tsup/mod.d.ts +8 -39
  69. package/dist/tsup/mod.js +9 -9
  70. package/dist/tsup/test/mod.cjs +11 -11
  71. package/dist/tsup/test/mod.d.cts +1 -1
  72. package/dist/tsup/test/mod.d.ts +1 -1
  73. package/dist/tsup/test/mod.js +10 -10
  74. package/dist/tsup/utils.cjs +2 -2
  75. package/dist/tsup/utils.d.cts +2 -1
  76. package/dist/tsup/utils.d.ts +2 -1
  77. package/dist/tsup/utils.js +1 -1
  78. package/package.json +4 -5
  79. package/src/actor/driver.ts +2 -2
  80. package/src/actor/protocol/serde.ts +75 -3
  81. package/src/actor/router-endpoints.ts +6 -6
  82. package/src/actor/router.ts +2 -2
  83. package/src/client/actor-conn.ts +24 -3
  84. package/src/client/config.ts +19 -26
  85. package/src/driver-helpers/mod.ts +4 -1
  86. package/src/driver-test-suite/mod.ts +66 -44
  87. package/src/driver-test-suite/utils.ts +4 -1
  88. package/src/drivers/default.ts +11 -9
  89. package/src/drivers/engine/actor-driver.ts +42 -39
  90. package/src/drivers/engine/config.ts +9 -22
  91. package/src/drivers/engine/mod.ts +9 -8
  92. package/src/drivers/file-system/global-state.ts +4 -4
  93. package/src/engine-process/log.ts +5 -0
  94. package/src/engine-process/mod.ts +316 -0
  95. package/src/inspector/utils.ts +6 -4
  96. package/src/manager/driver.ts +2 -2
  97. package/src/manager/gateway.ts +29 -11
  98. package/src/manager/router-schema.ts +20 -0
  99. package/src/manager/router.ts +116 -29
  100. package/src/registry/mod.ts +168 -113
  101. package/src/registry/run-config.ts +116 -47
  102. package/src/registry/serve.ts +3 -1
  103. package/src/serde.ts +3 -3
  104. package/src/test/config.ts +2 -2
  105. package/src/test/mod.ts +6 -3
  106. package/src/utils.ts +2 -0
  107. package/dist/tsup/chunk-4PSLOAXR.cjs.map +0 -1
  108. package/dist/tsup/chunk-4YV6RDZL.cjs.map +0 -1
  109. package/dist/tsup/chunk-7OMMIAWP.cjs.map +0 -1
  110. package/dist/tsup/chunk-E63WU5PL.js.map +0 -1
  111. package/dist/tsup/chunk-FZP2IBIX.js.map +0 -1
  112. package/dist/tsup/chunk-KHZ2QSQ4.js.map +0 -1
  113. package/dist/tsup/chunk-QGRYH6TU.cjs.map +0 -1
  114. package/dist/tsup/chunk-R7OP5N25.js.map +0 -1
  115. package/dist/tsup/chunk-SDXTJDDR.cjs.map +0 -1
  116. package/dist/tsup/chunk-SOC4HWCG.cjs.map +0 -1
  117. package/dist/tsup/chunk-U2IXX6DY.cjs.map +0 -1
  118. package/dist/tsup/chunk-WRSWUDFA.js.map +0 -1
  119. package/dist/tsup/chunk-YR2VY4XS.js.map +0 -1
  120. /package/dist/tsup/{chunk-F2YZNUPU.js.map → chunk-3JUN3IEH.js.map} +0 -0
  121. /package/dist/tsup/{chunk-DLPIL3VC.js.map → chunk-7DCESQ4O.js.map} +0 -0
  122. /package/dist/tsup/{chunk-WBSPHV5V.js.map → chunk-JTWD6ZT2.js.map} +0 -0
  123. /package/dist/tsup/{chunk-APHV6WXU.js.map → chunk-SBUJ3KIM.js.map} +0 -0
@@ -2,10 +2,12 @@ import type { cors } from "hono/cors";
2
2
  import type { Logger } from "pino";
3
3
  import { z } from "zod";
4
4
  import type { ActorDriverBuilder } from "@/actor/driver";
5
- import { ClientConfigSchema } from "@/client/config";
6
5
  import { LogLevelSchema } from "@/common/log";
6
+ import { EngingConfigSchema as EngineConfigSchema } from "@/drivers/engine/config";
7
7
  import { InspectorConfigSchema } from "@/inspector/config";
8
8
  import type { ManagerDriverBuilder } from "@/manager/driver";
9
+ import type { GetUpgradeWebSocket } from "@/utils";
10
+ import { getEnvUniversal } from "@/utils";
9
11
 
10
12
  type CorsOptions = NonNullable<Parameters<typeof cors>[0]>;
11
13
 
@@ -19,49 +21,116 @@ export const DriverConfigSchema = z.object({
19
21
  export type DriverConfig = z.infer<typeof DriverConfigSchema>;
20
22
 
21
23
  /** Base config used for the actor config across all platforms. */
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
- /** @experimental */
33
- disableServer: z.boolean().optional().default(false),
34
-
35
- /** @experimental */
36
- disableActorDriver: z.boolean().optional().default(false),
37
-
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("/"),
46
-
47
- /**
48
- * @experimental
49
- *
50
- * Disable welcome message.
51
- * */
52
- noWelcome: z.boolean().optional().default(false),
53
-
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({});
65
-
66
- export type RunConfig = z.infer<typeof RunConfigSchema>;
67
- export type RunConfigInput = z.input<typeof RunConfigSchema>;
24
+ export const RunnerConfigSchema = z
25
+ .object({
26
+ driver: DriverConfigSchema.optional(),
27
+
28
+ /** CORS configuration for the router. Uses Hono's CORS middleware options. */
29
+ cors: z.custom<CorsOptions>().optional(),
30
+
31
+ /** @experimental */
32
+ maxIncomingMessageSize: z.number().optional().default(65_536),
33
+
34
+ /** @experimental */
35
+ inspector: InspectorConfigSchema,
36
+
37
+ /** @experimental */
38
+ disableDefaultServer: z.boolean().optional().default(false),
39
+
40
+ /** @experimental */
41
+ defaultServerPort: z.number().default(6420),
42
+
43
+ /** @experimental */
44
+ runEngine: z
45
+ .boolean()
46
+ .optional()
47
+ .default(() => getEnvUniversal("RIVET_RUN_ENGINE") === "1"),
48
+
49
+ /** @experimental */
50
+ runEngineVersion: z
51
+ .string()
52
+ .optional()
53
+ .default(() => getEnvUniversal("RIVET_RUN_ENGINE_VERSION") ?? "25.7.3"),
54
+
55
+ /** @experimental */
56
+ overrideServerAddress: z.string().optional(),
57
+
58
+ /** @experimental */
59
+ disableActorDriver: z.boolean().optional().default(false),
60
+
61
+ /**
62
+ * @experimental
63
+ *
64
+ * Whether to run runners normally or have them managed
65
+ * serverlessly (by the Rivet Engine for example).
66
+ */
67
+ runnerKind: z
68
+ .enum(["serverless", "normal"])
69
+ .optional()
70
+ .default(() =>
71
+ getEnvUniversal("RIVET_RUNNER_KIND") === "serverless"
72
+ ? "serverless"
73
+ : "normal",
74
+ ),
75
+ totalSlots: z.number().optional(),
76
+
77
+ /**
78
+ * @experimental
79
+ *
80
+ * Base path for the router. This is used to prefix all routes.
81
+ * For example, if the base path is `/api`, then the route `/actors` will be
82
+ * available at `/api/actors`.
83
+ */
84
+ basePath: z.string().optional().default("/"),
85
+
86
+ /**
87
+ * @experimental
88
+ *
89
+ * Disable welcome message.
90
+ * */
91
+ noWelcome: z.boolean().optional().default(false),
92
+
93
+ /**
94
+ * @experimental
95
+ * */
96
+ logging: z
97
+ .object({
98
+ baseLogger: z.custom<Logger>().optional(),
99
+ level: LogLevelSchema.optional(),
100
+ })
101
+ .optional()
102
+ .default({}),
103
+
104
+ /**
105
+ * @experimental
106
+ *
107
+ * Automatically configure serverless runners in the engine.
108
+ * Can only be used when runnerKind is "serverless".
109
+ * If true, uses default configuration. Can also provide custom configuration.
110
+ */
111
+ autoConfigureServerless: z
112
+ .union([
113
+ z.boolean(),
114
+ z.object({
115
+ url: z.string().optional(),
116
+ headers: z.record(z.string(), z.string()).optional(),
117
+ maxRunners: z.number().optional(),
118
+ minRunners: z.number().optional(),
119
+ requestLifespan: z.number().optional(),
120
+ runnersMargin: z.number().optional(),
121
+ slotsPerRunner: z.number().optional(),
122
+ }),
123
+ ])
124
+ .optional(),
125
+
126
+ // This is a function to allow for lazy configuration of upgradeWebSocket on the
127
+ // fly. This is required since the dependencies that upgradeWebSocket
128
+ // (specifically Node.js) can sometimes only be specified after the router is
129
+ // created or must be imported async using `await import(...)`
130
+ getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
131
+ })
132
+ .merge(EngineConfigSchema.removeDefault())
133
+ .default({});
134
+
135
+ export type RunnerConfig = z.infer<typeof RunnerConfigSchema>;
136
+ export type RunnerConfigInput = z.input<typeof RunnerConfigSchema>;
@@ -1,7 +1,9 @@
1
1
  import { Hono } from "hono";
2
2
  import { logger } from "./log";
3
+ import type { RunnerConfig } from "./run-config";
3
4
 
4
5
  export async function crossPlatformServe(
6
+ runConfig: RunnerConfig,
5
7
  rivetKitRouter: Hono<any>,
6
8
  userRouter: Hono | undefined,
7
9
  ) {
@@ -47,7 +49,7 @@ export async function crossPlatformServe(
47
49
  });
48
50
 
49
51
  // Start server
50
- const port = 6420;
52
+ const port = runConfig.defaultServerPort;
51
53
  const server = serve({ fetch: app.fetch, port }, () =>
52
54
  logger().info({ msg: "server listening", port }),
53
55
  );
package/src/serde.ts CHANGED
@@ -3,7 +3,7 @@ import invariant from "invariant";
3
3
  import { assertUnreachable } from "@/common/utils";
4
4
  import type { VersionedDataHandler } from "@/common/versioned-data";
5
5
  import type { Encoding } from "@/mod";
6
- import { jsonStringifyCompat } from "./actor/protocol/serde";
6
+ import { jsonParseCompat, jsonStringifyCompat } from "./actor/protocol/serde";
7
7
 
8
8
  export function uint8ArrayToBase64(uint8Array: Uint8Array): string {
9
9
  // Check if Buffer is available (Node.js)
@@ -78,11 +78,11 @@ export function deserializeWithEncoding<T>(
78
78
  ): T {
79
79
  if (encoding === "json") {
80
80
  if (typeof buffer === "string") {
81
- return JSON.parse(buffer);
81
+ return jsonParseCompat(buffer);
82
82
  } else {
83
83
  const decoder = new TextDecoder("utf-8");
84
84
  const jsonString = decoder.decode(buffer);
85
- return JSON.parse(jsonString);
85
+ return jsonParseCompat(jsonString);
86
86
  }
87
87
  } else if (encoding === "cbor") {
88
88
  invariant(
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
- import { RunConfigSchema } from "@/registry/run-config";
2
+ import { RunnerConfigSchema } from "@/registry/run-config";
3
3
 
4
- export const ConfigSchema = RunConfigSchema.removeDefault()
4
+ export const ConfigSchema = RunnerConfigSchema.removeDefault()
5
5
  .extend({
6
6
  hostname: z
7
7
  .string()
package/src/test/mod.ts CHANGED
@@ -10,8 +10,9 @@ import {
10
10
  getInspectorUrl,
11
11
  } from "@/inspector/utils";
12
12
  import { createManagerRouter } from "@/manager/router";
13
+ import { createClientWithDriver } from "@/mod";
13
14
  import type { Registry } from "@/registry/mod";
14
- import { RunConfigSchema } from "@/registry/run-config";
15
+ import { RunnerConfigSchema } from "@/registry/run-config";
15
16
  import { ConfigSchema, type InputConfig } from "./config";
16
17
  import { logger } from "./log";
17
18
 
@@ -27,15 +28,17 @@ function serve(registry: Registry<any>, inputConfig?: InputConfig): ServerType {
27
28
  }
28
29
 
29
30
  // Create router
30
- const runConfig = RunConfigSchema.parse(inputConfig);
31
+ const runConfig = RunnerConfigSchema.parse(inputConfig);
31
32
  const driver = inputConfig.driver ?? createFileSystemOrMemoryDriver(false);
32
33
  const managerDriver = driver.manager(registry.config, config);
34
+ const client = createClientWithDriver(managerDriver);
33
35
  configureInspectorAccessToken(config, managerDriver);
34
36
  const { router } = createManagerRouter(
35
37
  registry.config,
36
38
  runConfig,
37
39
  managerDriver,
38
- undefined,
40
+ driver,
41
+ client,
39
42
  );
40
43
 
41
44
  // Inject WebSocket
package/src/utils.ts CHANGED
@@ -31,6 +31,8 @@ export type UpgradeWebSocket = (
31
31
  createEvents: (c: HonoContext) => any,
32
32
  ) => HonoHandler;
33
33
 
34
+ export type GetUpgradeWebSocket = () => UpgradeWebSocket;
35
+
34
36
  export function getEnvUniversal(key: string): string | undefined {
35
37
  if (typeof Deno !== "undefined") {
36
38
  return Deno.env.get(key);