rivetkit 2.3.0-rc.8 → 2.3.0

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 (221) hide show
  1. package/dist/browser/client.d.ts +481 -74
  2. package/dist/browser/client.js +174 -148
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +47 -18
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +2 -2
  7. package/dist/tsup/actor/errors.d.cts +1 -1
  8. package/dist/tsup/actor/errors.d.ts +1 -1
  9. package/dist/tsup/actor/errors.js +1 -1
  10. package/dist/tsup/agent-os/index.cjs +2160 -2086
  11. package/dist/tsup/agent-os/index.cjs.map +1 -1
  12. package/dist/tsup/agent-os/index.d.cts +479 -73
  13. package/dist/tsup/agent-os/index.d.ts +479 -73
  14. package/dist/tsup/agent-os/index.js +2160 -2086
  15. package/dist/tsup/agent-os/index.js.map +1 -1
  16. package/dist/tsup/{chunk-KY3CERZR.js → chunk-2OTRTA3J.js} +7 -21
  17. package/dist/tsup/chunk-2OTRTA3J.js.map +1 -0
  18. package/dist/tsup/{chunk-HGW6PBWR.cjs → chunk-3677IIOV.cjs} +11 -25
  19. package/dist/tsup/chunk-3677IIOV.cjs.map +1 -0
  20. package/dist/tsup/{chunk-OT7FF6GB.cjs → chunk-47HHIEXH.cjs} +24 -9
  21. package/dist/tsup/chunk-47HHIEXH.cjs.map +1 -0
  22. package/dist/tsup/{chunk-EMFKMVJR.js → chunk-4JDSFJS5.js} +69 -58
  23. package/dist/tsup/chunk-4JDSFJS5.js.map +1 -0
  24. package/dist/tsup/{chunk-7HLFSAJP.cjs → chunk-7QKCIVAY.cjs} +225 -214
  25. package/dist/tsup/chunk-7QKCIVAY.cjs.map +1 -0
  26. package/dist/tsup/{chunk-AWTPTUQ7.cjs → chunk-B6VUNZUD.cjs} +10 -10
  27. package/dist/tsup/{chunk-AWTPTUQ7.cjs.map → chunk-B6VUNZUD.cjs.map} +1 -1
  28. package/dist/tsup/{chunk-D3T3ZBSY.js → chunk-BEI24WTI.js} +2 -2
  29. package/dist/tsup/{chunk-TMLOKTRB.js → chunk-BRP62GZC.js} +1 -1
  30. package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
  31. package/dist/tsup/{chunk-D5G75T7J.js → chunk-DPIMKYNB.js} +61 -2
  32. package/dist/tsup/chunk-DPIMKYNB.js.map +1 -0
  33. package/dist/tsup/{chunk-BATTOVHF.cjs → chunk-DXXJPH55.cjs} +40 -13
  34. package/dist/tsup/chunk-DXXJPH55.cjs.map +1 -0
  35. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  36. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  37. package/dist/tsup/{chunk-4BPKKZJO.cjs → chunk-I4LN3FNT.cjs} +10 -10
  38. package/dist/tsup/chunk-I4LN3FNT.cjs.map +1 -0
  39. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  40. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  41. package/dist/tsup/{chunk-63WNTDRC.cjs → chunk-KORQB2IR.cjs} +1 -1
  42. package/dist/tsup/{chunk-63WNTDRC.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
  43. package/dist/tsup/{chunk-6TQSSJ4F.cjs → chunk-LVTBW2RE.cjs} +3 -3
  44. package/dist/tsup/{chunk-6TQSSJ4F.cjs.map → chunk-LVTBW2RE.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-4JU3IPG2.js → chunk-MEHBWPLJ.js} +6 -6
  46. package/dist/tsup/chunk-MEHBWPLJ.js.map +1 -0
  47. package/dist/tsup/{chunk-SRNOPUC6.cjs → chunk-NIY3RSPX.cjs} +62 -3
  48. package/dist/tsup/chunk-NIY3RSPX.cjs.map +1 -0
  49. package/dist/tsup/{chunk-UZXQEGVJ.js → chunk-P2GNQ4RN.js} +4 -4
  50. package/dist/tsup/{chunk-UZXQEGVJ.js.map → chunk-P2GNQ4RN.js.map} +1 -1
  51. package/dist/tsup/{chunk-VUGENVIK.js → chunk-UMZVD6DQ.js} +22 -7
  52. package/dist/tsup/chunk-UMZVD6DQ.js.map +1 -0
  53. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  54. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  55. package/dist/tsup/{chunk-GBG63SUG.js → chunk-VTTFNQQI.js} +32 -5
  56. package/dist/tsup/chunk-VTTFNQQI.js.map +1 -0
  57. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  58. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  59. package/dist/tsup/client/mod.cjs +9 -9
  60. package/dist/tsup/client/mod.d.cts +5 -5
  61. package/dist/tsup/client/mod.d.ts +5 -5
  62. package/dist/tsup/client/mod.js +8 -8
  63. package/dist/tsup/common/log.cjs +3 -3
  64. package/dist/tsup/common/log.js +2 -2
  65. package/dist/tsup/common/websocket.cjs +4 -4
  66. package/dist/tsup/common/websocket.js +3 -3
  67. package/dist/tsup/{config-Ak1lv4gF.d.ts → config-BxWAw3iH.d.ts} +512 -27
  68. package/dist/tsup/{config-DU_xj4qZ.d.cts → config-CZQQ-mso.d.cts} +512 -27
  69. package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.cts} +1 -2
  70. package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.ts} +1 -2
  71. package/dist/tsup/{context-DAAp4Lpg.d.ts → context-Bw7xq8w3.d.cts} +8 -8
  72. package/dist/tsup/{context-Dt_L55q8.d.cts → context-D8QA76sV.d.ts} +8 -8
  73. package/dist/tsup/db/drizzle.cjs +3 -3
  74. package/dist/tsup/db/drizzle.d.cts +1 -1
  75. package/dist/tsup/db/drizzle.d.ts +1 -1
  76. package/dist/tsup/db/drizzle.js +1 -1
  77. package/dist/tsup/db/mod.cjs +2 -2
  78. package/dist/tsup/db/mod.d.cts +2 -2
  79. package/dist/tsup/db/mod.d.ts +2 -2
  80. package/dist/tsup/db/mod.js +1 -1
  81. package/dist/tsup/dynamic/mod.cjs +24 -0
  82. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  83. package/dist/tsup/dynamic/mod.d.cts +37 -0
  84. package/dist/tsup/dynamic/mod.d.ts +37 -0
  85. package/dist/tsup/dynamic/mod.js +24 -0
  86. package/dist/tsup/dynamic/mod.js.map +1 -0
  87. package/dist/tsup/inspector/mod.cjs +6 -6
  88. package/dist/tsup/inspector/mod.js +5 -5
  89. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  90. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  91. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  92. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  93. package/dist/tsup/inspector-tab/mod.js +173 -0
  94. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  95. package/dist/tsup/mod.cjs +615 -348
  96. package/dist/tsup/mod.cjs.map +1 -1
  97. package/dist/tsup/mod.d.cts +5 -5
  98. package/dist/tsup/mod.d.ts +5 -5
  99. package/dist/tsup/mod.js +511 -244
  100. package/dist/tsup/mod.js.map +1 -1
  101. package/dist/tsup/test/mod.cjs +21 -18
  102. package/dist/tsup/test/mod.cjs.map +1 -1
  103. package/dist/tsup/test/mod.d.cts +4 -4
  104. package/dist/tsup/test/mod.d.ts +4 -4
  105. package/dist/tsup/test/mod.js +18 -15
  106. package/dist/tsup/test/mod.js.map +1 -1
  107. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-DQosb24I.d.cts} +1 -1
  108. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-DQosb24I.d.ts} +1 -1
  109. package/dist/tsup/utils.cjs +3 -3
  110. package/dist/tsup/utils.d.cts +1 -1
  111. package/dist/tsup/utils.d.ts +1 -1
  112. package/dist/tsup/utils.js +2 -2
  113. package/dist/tsup/workflow/mod.cjs +279 -279
  114. package/dist/tsup/workflow/mod.cjs.map +1 -1
  115. package/dist/tsup/workflow/mod.d.cts +6 -6
  116. package/dist/tsup/workflow/mod.d.ts +6 -6
  117. package/dist/tsup/workflow/mod.js +380 -380
  118. package/dist/tsup/workflow/mod.js.map +1 -1
  119. package/package.json +29 -9
  120. package/src/actor/config.ts +156 -51
  121. package/src/actor/contexts/index.ts +7 -2
  122. package/src/actor/definition.ts +17 -19
  123. package/src/actor/driver.ts +3 -3
  124. package/src/actor/errors.ts +8 -2
  125. package/src/actor/instance/mod.ts +26 -34
  126. package/src/actor/keys.ts +1 -1
  127. package/src/actor/mod.ts +22 -20
  128. package/src/actor/schema.ts +2 -2
  129. package/src/agent-os/actor/index.ts +38 -18
  130. package/src/agent-os/actor/preview.ts +1 -2
  131. package/src/agent-os/config.ts +1 -1
  132. package/src/agent-os/fs/database-vfs.ts +1 -1
  133. package/src/agent-os/index.ts +16 -15
  134. package/src/client/actor-common.ts +87 -54
  135. package/src/client/actor-conn.ts +11 -11
  136. package/src/client/actor-handle.ts +69 -52
  137. package/src/client/actor-query.ts +5 -5
  138. package/src/client/errors.ts +1 -1
  139. package/src/client/lifecycle-errors.ts +2 -4
  140. package/src/client/query.ts +1 -1
  141. package/src/client/queue.ts +8 -4
  142. package/src/client/raw-utils.ts +8 -6
  143. package/src/client/resolve-gateway-target.ts +1 -1
  144. package/src/client/utils.ts +2 -6
  145. package/src/common/actor-websocket.ts +3 -1
  146. package/src/common/bare/actor-persist/v1.ts +205 -163
  147. package/src/common/bare/actor-persist/v2.ts +265 -213
  148. package/src/common/bare/actor-persist/v3.ts +176 -172
  149. package/src/common/bare/actor-persist/v4.ts +254 -253
  150. package/src/common/bare/transport/v1.ts +659 -543
  151. package/src/common/client-protocol-versioned.ts +66 -64
  152. package/src/common/database/config.ts +2 -8
  153. package/src/common/database/native-database.ts +1 -1
  154. package/src/common/database/shared.ts +1 -0
  155. package/src/common/encoding.ts +13 -17
  156. package/src/common/engine.ts +28 -1
  157. package/src/common/eventsource.ts +1 -1
  158. package/src/common/inline-websocket-adapter.ts +3 -2
  159. package/src/common/router.ts +13 -17
  160. package/src/common/utils.ts +1 -2
  161. package/src/common/websocket-interface.ts +1 -1
  162. package/src/db/mod.ts +1 -1
  163. package/src/devtools-loader/index.ts +4 -7
  164. package/src/devtools-loader/serve-devtools.ts +26 -0
  165. package/src/drivers/engine/actor-driver.ts +48 -46
  166. package/src/dynamic/instance.ts +32 -0
  167. package/src/dynamic/internal.ts +50 -0
  168. package/src/dynamic/isolate-runtime.ts +66 -0
  169. package/src/dynamic/mod.ts +32 -0
  170. package/src/engine-client/actor-http-client.ts +3 -3
  171. package/src/engine-client/actor-websocket-client.ts +5 -5
  172. package/src/engine-client/api-endpoints.ts +51 -2
  173. package/src/engine-client/api-utils.ts +2 -2
  174. package/src/engine-client/driver.ts +1 -1
  175. package/src/engine-client/mod.ts +5 -3
  176. package/src/engine-client/ws-proxy.ts +9 -4
  177. package/src/inspector/client.browser.ts +5 -11
  178. package/src/inspector/mod.ts +1 -3
  179. package/src/inspector-tab/mod.ts +315 -0
  180. package/src/registry/config/envoy.ts +1 -2
  181. package/src/registry/config/index.ts +40 -16
  182. package/src/registry/index.ts +226 -83
  183. package/src/registry/napi-runtime.ts +46 -12
  184. package/src/registry/native-validation.ts +10 -12
  185. package/src/registry/native.ts +307 -164
  186. package/src/registry/process-metrics.ts +90 -23
  187. package/src/registry/runtime.ts +53 -6
  188. package/src/registry/wasm-runtime.ts +30 -3
  189. package/src/serde.ts +1 -1
  190. package/src/serverless/configure.ts +18 -7
  191. package/src/test/mod.ts +11 -8
  192. package/src/utils/endpoint-parser.ts +1 -1
  193. package/src/utils/env-vars.ts +6 -0
  194. package/src/utils/router.ts +1 -1
  195. package/src/utils/serve.ts +4 -5
  196. package/src/utils.ts +1 -2
  197. package/src/workflow/context.ts +30 -29
  198. package/src/workflow/driver.ts +4 -6
  199. package/src/workflow/inspector.ts +2 -2
  200. package/src/workflow/mod.ts +15 -17
  201. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  202. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  203. package/dist/tsup/chunk-4BPKKZJO.cjs.map +0 -1
  204. package/dist/tsup/chunk-4JU3IPG2.js.map +0 -1
  205. package/dist/tsup/chunk-7HLFSAJP.cjs.map +0 -1
  206. package/dist/tsup/chunk-BATTOVHF.cjs.map +0 -1
  207. package/dist/tsup/chunk-D5G75T7J.js.map +0 -1
  208. package/dist/tsup/chunk-EMFKMVJR.js.map +0 -1
  209. package/dist/tsup/chunk-GBG63SUG.js.map +0 -1
  210. package/dist/tsup/chunk-HGW6PBWR.cjs.map +0 -1
  211. package/dist/tsup/chunk-KY3CERZR.js.map +0 -1
  212. package/dist/tsup/chunk-OT7FF6GB.cjs.map +0 -1
  213. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  214. package/dist/tsup/chunk-SRNOPUC6.cjs.map +0 -1
  215. package/dist/tsup/chunk-TMLOKTRB.js.map +0 -1
  216. package/dist/tsup/chunk-VUGENVIK.js.map +0 -1
  217. package/dist/tsup/process-metrics-NW754INA.js +0 -118
  218. package/dist/tsup/process-metrics-NW754INA.js.map +0 -1
  219. package/dist/tsup/process-metrics-TYAGKCEJ.cjs +0 -118
  220. package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +0 -1
  221. /package/dist/tsup/{chunk-D3T3ZBSY.js.map → chunk-BEI24WTI.js.map} +0 -0
@@ -1,9 +1,9 @@
1
1
  import type { EnvoyConfig } from "@rivetkit/rivetkit-native/wrapper";
2
2
  import {
3
- type HibernatingWebSocketMetadata,
4
3
  type EnvoyHandle,
4
+ type HibernatingWebSocketMetadata,
5
5
  openDatabaseFromEnvoy,
6
- protocol,
6
+ type protocol,
7
7
  startEnvoySync,
8
8
  } from "@rivetkit/rivetkit-native/wrapper";
9
9
  import * as cbor from "cbor-x";
@@ -11,17 +11,19 @@ import type { Context as HonoContext } from "hono";
11
11
  import { streamSSE } from "hono/streaming";
12
12
  import { WSContext, type WSContextInit } from "hono/ws";
13
13
  import invariant from "invariant";
14
- import { type AnyConn, CONN_STATE_MANAGER_SYMBOL } from "@/actor/conn/mod";
14
+ import { CONN_STATE_MANAGER_SYMBOL } from "@/actor/conn/mod";
15
15
  import { isStaticActorDefinition, lookupInRegistry } from "@/actor/definition";
16
+ import type { ActorDriver } from "@/actor/driver";
17
+ import { KEYS } from "@/actor/instance/keys";
18
+ import type { AnyActorInstance } from "@/actor/instance/mod";
16
19
  import {
17
- isStaticActorInstance,
18
20
  type AnyStaticActorInstance,
21
+ isStaticActorInstance,
19
22
  } from "@/actor/instance/mod";
20
- import { KEYS } from "@/actor/instance/keys";
21
23
  import {
22
- type PreloadMap,
23
24
  compareBytes,
24
25
  createPreloadMap,
26
+ type PreloadMap,
25
27
  } from "@/actor/instance/preload-map";
26
28
  import { deserializeActorKey } from "@/actor/keys";
27
29
  import type { Encoding } from "@/actor/protocol/serde";
@@ -41,6 +43,10 @@ import {
41
43
  } from "@/common/actor-router-consts";
42
44
  import { getLogger } from "@/common/log";
43
45
  import { deconstructError } from "@/common/utils";
46
+ import type {
47
+ RivetMessageEvent,
48
+ UniversalWebSocket,
49
+ } from "@/common/websocket-interface";
44
50
  import {
45
51
  buildHibernatableWebSocketAckStateTestResponse,
46
52
  type IndexedWebSocketPayload,
@@ -49,21 +55,19 @@ import {
49
55
  setHibernatableWebSocketAckTestHooks,
50
56
  unregisterRemoteHibernatableWebSocketAckHooks,
51
57
  } from "@/common/websocket-test-hooks";
52
- import type {
53
- RivetMessageEvent,
54
- UniversalWebSocket,
55
- } from "@/common/websocket-interface";
56
- import type { ActorDriver } from "@/actor/driver";
57
- import type { AnyActorInstance } from "@/actor/instance/mod";
58
58
  import {
59
- getInitialActorKvState,
59
+ type JsNativeDatabaseLike,
60
+ wrapJsNativeDatabase,
61
+ } from "@/db/native-database";
62
+ import {
60
63
  type EngineControlClient,
64
+ getInitialActorKvState,
61
65
  } from "@/driver-helpers/mod";
62
66
  import { DynamicActorInstance } from "@/dynamic/instance";
63
- import { DynamicActorIsolateRuntime } from "@/dynamic/isolate-runtime";
64
67
  import { isDynamicActorDefinition } from "@/dynamic/internal";
65
- import { buildActorNames, type RegistryConfig } from "@/registry/config";
68
+ import { DynamicActorIsolateRuntime } from "@/dynamic/isolate-runtime";
66
69
  import { getEndpoint } from "@/engine-client/api-utils";
70
+ import { buildActorNames, type RegistryConfig } from "@/registry/config";
67
71
  import {
68
72
  type LongTimeoutHandle,
69
73
  promiseWithResolvers,
@@ -71,10 +75,6 @@ import {
71
75
  stringifyError,
72
76
  VERSION,
73
77
  } from "@/utils";
74
- import {
75
- wrapJsNativeDatabase,
76
- type JsNativeDatabaseLike,
77
- } from "@/db/native-database";
78
78
  import { logger } from "./log";
79
79
 
80
80
  const ENVOY_SSE_PING_INTERVAL = 1000;
@@ -88,13 +88,13 @@ const REMOTE_ACK_HOOK_QUERY_PARAM = "__rivetkitAckHook";
88
88
  //
89
89
  // See engine/packages/pegboard-gateway/src/shared_state.rs
90
90
  // (HWS_MESSAGE_ACK_TIMEOUT)
91
- const CONN_MESSAGE_ACK_DEADLINE = 5_000;
91
+ const _CONN_MESSAGE_ACK_DEADLINE = 5_000;
92
92
 
93
93
  // Force saveState when cumulative message size reaches this threshold (0.5 MB)
94
94
  //
95
95
  // See engine/packages/pegboard-gateway/src/shared_state.rs
96
96
  // (HWS_MAX_PENDING_MSGS_SIZE_PER_REQ)
97
- const CONN_BUFFERED_MESSAGE_SIZE_THRESHOLD = 500_000;
97
+ const _CONN_BUFFERED_MESSAGE_SIZE_THRESHOLD = 500_000;
98
98
 
99
99
  interface ActorHandler {
100
100
  actor?: AnyActorInstance;
@@ -144,7 +144,6 @@ export type DriverContext = {};
144
144
 
145
145
  export class EngineActorDriver implements ActorDriver {
146
146
  #config: RegistryConfig;
147
- #engineClient: EngineControlClient;
148
147
  #inlineClient: Client<any>;
149
148
  #envoy: EnvoyHandle;
150
149
  #actors: Map<string, ActorHandler> = new Map();
@@ -161,15 +160,6 @@ export class EngineActorDriver implements ActorDriver {
161
160
  string,
162
161
  HibernatableRunnerWebSocketBinding
163
162
  >();
164
- #hwsMessageIndex = new Map<
165
- string,
166
- {
167
- serverMessageIndex: number;
168
- bufferedMessageSize: number;
169
- pendingAckFromMessageIndex: boolean;
170
- pendingAckFromBufferSize: boolean;
171
- }
172
- >();
173
163
  #actorRouter: ActorRouter;
174
164
 
175
165
  #envoyStarted: PromiseWithResolvers<void> = promiseWithResolvers((reason) =>
@@ -376,8 +366,7 @@ export class EngineActorDriver implements ActorDriver {
376
366
  requestId: ArrayBuffer,
377
367
  ): void {
378
368
  const key = this.#hibernatableWebSocketAckKey(gatewayId, requestId);
379
- const binding =
380
- this.#hibernatableRunnerWebSocketBindings.get(key);
369
+ const binding = this.#hibernatableRunnerWebSocketBindings.get(key);
381
370
  if (!binding) {
382
371
  return;
383
372
  }
@@ -397,8 +386,7 @@ export class EngineActorDriver implements ActorDriver {
397
386
  requestId: ArrayBuffer,
398
387
  ): void {
399
388
  const key = this.#hibernatableWebSocketAckKey(gatewayId, requestId);
400
- const binding =
401
- this.#hibernatableRunnerWebSocketBindings.get(key);
389
+ const binding = this.#hibernatableRunnerWebSocketBindings.get(key);
402
390
  binding?.detach?.();
403
391
  this.#hibernatableRunnerWebSocketBindings.delete(key);
404
392
  }
@@ -585,7 +573,7 @@ export class EngineActorDriver implements ActorDriver {
585
573
  return handler;
586
574
  }
587
575
 
588
- getContext(actorId: string): DriverContext {
576
+ getContext(_actorId: string): DriverContext {
589
577
  return {};
590
578
  }
591
579
 
@@ -1140,7 +1128,10 @@ export class EngineActorDriver implements ActorDriver {
1140
1128
  actorId: binding.actorId,
1141
1129
  error: stringifyError(error),
1142
1130
  });
1143
- binding.websocket.close(1011, "dynamic.websocket_forward_failed");
1131
+ binding.websocket.close(
1132
+ 1011,
1133
+ "dynamic.websocket_forward_failed",
1134
+ );
1144
1135
  });
1145
1136
  };
1146
1137
  const onClose = (event: CloseEvent) => {
@@ -1270,7 +1261,10 @@ export class EngineActorDriver implements ActorDriver {
1270
1261
  msg: "dynamic runtime websocket binding is missing after restore",
1271
1262
  actorId: binding.actorId,
1272
1263
  });
1273
- binding.websocket.close(1011, "dynamic.websocket_forward_failed");
1264
+ binding.websocket.close(
1265
+ 1011,
1266
+ "dynamic.websocket_forward_failed",
1267
+ );
1274
1268
  return;
1275
1269
  }
1276
1270
 
@@ -1286,7 +1280,10 @@ export class EngineActorDriver implements ActorDriver {
1286
1280
  actorId: binding.actorId,
1287
1281
  error: stringifyError(error),
1288
1282
  });
1289
- binding.websocket.close(1011, "dynamic.websocket_forward_failed");
1283
+ binding.websocket.close(
1284
+ 1011,
1285
+ "dynamic.websocket_forward_failed",
1286
+ );
1290
1287
  });
1291
1288
  };
1292
1289
  const onClose = (event: CloseEvent) => {
@@ -1990,7 +1987,10 @@ export class EngineActorDriver implements ActorDriver {
1990
1987
  isRestoringHibernatable,
1991
1988
  );
1992
1989
  } catch (error) {
1993
- logger().error({ msg: "building websocket handlers errored", error });
1990
+ logger().error({
1991
+ msg: "building websocket handlers errored",
1992
+ error,
1993
+ });
1994
1994
  websocketRaw.close(1011, "ws.route_error");
1995
1995
  return;
1996
1996
  }
@@ -2005,7 +2005,7 @@ export class EngineActorDriver implements ActorDriver {
2005
2005
  // Get connection and actor from wsHandler (may be undefined for inspector endpoint)
2006
2006
  const conn = wsHandler.conn;
2007
2007
  const actor = wsHandler.actor;
2008
- const connStateManager = conn?.[CONN_STATE_MANAGER_SYMBOL];
2008
+ const _connStateManager = conn?.[CONN_STATE_MANAGER_SYMBOL];
2009
2009
 
2010
2010
  // Bind event listeners to Hono WebSocket handlers
2011
2011
  //
@@ -2044,16 +2044,15 @@ export class EngineActorDriver implements ActorDriver {
2044
2044
 
2045
2045
  const currentActor = this.#actors.get(actorId)?.actor;
2046
2046
  const actorForDispatch =
2047
- currentActor &&
2048
- isStaticActorInstance(currentActor)
2047
+ currentActor && isStaticActorInstance(currentActor)
2049
2048
  ? currentActor
2050
2049
  : actor;
2051
2050
  const connForDispatch =
2052
2051
  isHibernatable && actorForDispatch
2053
- ? actorForDispatch.connectionManager.findHibernatableConn(
2052
+ ? (actorForDispatch.connectionManager.findHibernatableConn(
2054
2053
  gatewayIdBuf,
2055
2054
  requestIdBuf,
2056
- ) ?? conn
2055
+ ) ?? conn)
2057
2056
  : conn;
2058
2057
 
2059
2058
  if (actorForDispatch?.isStopping) {
@@ -2063,7 +2062,10 @@ export class EngineActorDriver implements ActorDriver {
2063
2062
  actorId: actorForDispatch?.id,
2064
2063
  messageIndex: event.rivetMessageIndex,
2065
2064
  });
2066
- if (!isRawWebSocketPath && websocket.readyState !== websocket.CLOSED) {
2065
+ if (
2066
+ !isRawWebSocketPath &&
2067
+ websocket.readyState !== websocket.CLOSED
2068
+ ) {
2067
2069
  websocket.close(1011, "actor.stopping");
2068
2070
  }
2069
2071
  return;
@@ -0,0 +1,32 @@
1
+ import type { DynamicActorIsolateRuntime } from "./isolate-runtime";
2
+
3
+ export class DynamicActorInstance {
4
+ constructor(
5
+ public readonly id: string,
6
+ private readonly runtime: DynamicActorIsolateRuntime,
7
+ ) {}
8
+
9
+ get isStopping(): boolean {
10
+ return this.runtime.isStopping;
11
+ }
12
+
13
+ async onStop(mode: "sleep" | "destroy"): Promise<void> {
14
+ await this.runtime.stop(mode);
15
+ }
16
+
17
+ async onAlarm(): Promise<void> {
18
+ await this.runtime.onAlarm();
19
+ }
20
+
21
+ async cleanupPersistedConnections(reason?: string): Promise<number> {
22
+ return await this.runtime.cleanupPersistedConnections(reason);
23
+ }
24
+
25
+ async getHibernatingWebSockets() {
26
+ return await this.runtime.getHibernatingWebSockets();
27
+ }
28
+
29
+ getHibernatingWebSocketMetadata() {
30
+ return this.runtime.getHibernatingWebSocketMetadata();
31
+ }
32
+ }
@@ -0,0 +1,50 @@
1
+ import type {
2
+ AnyActorDefinition,
3
+ BaseActorDefinition,
4
+ } from "@/actor/definition";
5
+
6
+ export const DYNAMIC_ACTOR_DEFINITION_SYMBOL = Symbol.for(
7
+ "rivetkit.dynamic_actor_definition",
8
+ );
9
+
10
+ export interface DynamicActorSource {
11
+ source: string;
12
+ nodeProcess?: {
13
+ memoryLimit?: number;
14
+ cpuTimeLimitMs?: number;
15
+ };
16
+ }
17
+
18
+ export interface DynamicActorLoadContext {
19
+ key: string[];
20
+ client(): Promise<any>;
21
+ }
22
+
23
+ export type DynamicActorLoader = (
24
+ c: DynamicActorLoadContext,
25
+ ) => DynamicActorSource | Promise<DynamicActorSource>;
26
+
27
+ export interface DynamicActorDefinition extends AnyActorDefinition {
28
+ readonly [DYNAMIC_ACTOR_DEFINITION_SYMBOL]: true;
29
+ readonly loader: DynamicActorLoader;
30
+ }
31
+
32
+ export function isDynamicActorDefinition(
33
+ definition: BaseActorDefinition<
34
+ any,
35
+ any,
36
+ any,
37
+ any,
38
+ any,
39
+ any,
40
+ any,
41
+ any,
42
+ any
43
+ >,
44
+ ): definition is DynamicActorDefinition {
45
+ return (
46
+ (definition as Partial<DynamicActorDefinition>)[
47
+ DYNAMIC_ACTOR_DEFINITION_SYMBOL
48
+ ] === true
49
+ );
50
+ }
@@ -0,0 +1,66 @@
1
+ import type { ActorDriver } from "@/actor/driver";
2
+ import type { Client } from "@/client/client";
3
+ import type { RegistryConfig } from "@/registry/config";
4
+ import type { DynamicActorLoader } from "./internal";
5
+
6
+ export interface DynamicActorIsolateRuntimeConfig {
7
+ actorId: string;
8
+ actorName: string;
9
+ actorKey: string[];
10
+ input: unknown;
11
+ region: string;
12
+ loader: DynamicActorLoader;
13
+ actorDriver: ActorDriver;
14
+ inlineClient: Client<any>;
15
+ test: RegistryConfig["test"];
16
+ }
17
+
18
+ export interface DynamicHibernatingWebSocketMetadata {
19
+ gatewayId: ArrayBuffer;
20
+ requestId: ArrayBuffer;
21
+ serverMessageIndex: number;
22
+ clientMessageIndex: number;
23
+ path: string;
24
+ headers: Record<string, string>;
25
+ }
26
+
27
+ export class DynamicActorIsolateRuntime {
28
+ #isStopping = false;
29
+
30
+ constructor(private readonly config: DynamicActorIsolateRuntimeConfig) {}
31
+
32
+ get isStopping(): boolean {
33
+ return this.#isStopping;
34
+ }
35
+
36
+ async start(): Promise<void> {
37
+ await this.config.loader({
38
+ key: this.config.actorKey,
39
+ client: async () => this.config.inlineClient,
40
+ });
41
+ }
42
+
43
+ async stop(_mode: "sleep" | "destroy"): Promise<void> {
44
+ this.#isStopping = true;
45
+ }
46
+
47
+ async dispose(): Promise<void> {
48
+ this.#isStopping = true;
49
+ }
50
+
51
+ async onAlarm(): Promise<void> {}
52
+
53
+ async cleanupPersistedConnections(_reason?: string): Promise<number> {
54
+ return 0;
55
+ }
56
+
57
+ async getHibernatingWebSockets(): Promise<
58
+ DynamicHibernatingWebSocketMetadata[]
59
+ > {
60
+ return [];
61
+ }
62
+
63
+ getHibernatingWebSocketMetadata(): DynamicHibernatingWebSocketMetadata[] {
64
+ return [];
65
+ }
66
+ }
@@ -0,0 +1,32 @@
1
+ import { ActorConfigSchema } from "@/actor/config";
2
+ import type { AnyActorDefinition } from "@/actor/definition";
3
+ import {
4
+ DYNAMIC_ACTOR_DEFINITION_SYMBOL,
5
+ type DynamicActorDefinition,
6
+ type DynamicActorLoader,
7
+ } from "./internal";
8
+
9
+ export interface DynamicActorConfig {
10
+ load: DynamicActorLoader;
11
+ }
12
+
13
+ export function dynamicActor(
14
+ input: DynamicActorConfig,
15
+ ): DynamicActorDefinition {
16
+ const config = ActorConfigSchema.parse({
17
+ actions: {},
18
+ }) as unknown as AnyActorDefinition["config"];
19
+
20
+ return {
21
+ [DYNAMIC_ACTOR_DEFINITION_SYMBOL]: true,
22
+ config,
23
+ loader: input.load,
24
+ };
25
+ }
26
+
27
+ export type {
28
+ DynamicActorDefinition,
29
+ DynamicActorLoadContext,
30
+ DynamicActorLoader,
31
+ DynamicActorSource,
32
+ } from "./internal";
@@ -5,7 +5,7 @@ import {
5
5
  HEADER_RIVET_TARGET,
6
6
  HEADER_RIVET_TOKEN,
7
7
  } from "@/common/actor-router-consts";
8
- import { shouldSkipReadyWait, type GatewayRequestOptions } from "./driver";
8
+ import { type GatewayRequestOptions, shouldSkipReadyWait } from "./driver";
9
9
 
10
10
  export interface HttpGatewayRequestOptions extends GatewayRequestOptions {
11
11
  directActorId?: string;
@@ -34,9 +34,9 @@ export async function sendHttpRequestToGateway(
34
34
  bodyToSend = reqBody;
35
35
 
36
36
  // If this is a streaming request, we need to convert the headers
37
- // for the basic array buffer
37
+ // for the basic array buffer.
38
38
  guardHeaders.delete("transfer-encoding");
39
- guardHeaders.set("content-length", String(bodyToSend.byteLength));
39
+ guardHeaders.delete("content-length");
40
40
  }
41
41
  }
42
42
 
@@ -2,24 +2,24 @@ import {
2
2
  type ClientConfig,
3
3
  DEFAULT_MAX_QUERY_INPUT_SIZE,
4
4
  } from "@/client/config";
5
+ import type { ActorGatewayQuery, CrashPolicy } from "@/client/query";
5
6
  import {
7
+ WS_PROTOCOL_ACTOR,
6
8
  WS_PROTOCOL_CONN_PARAMS,
7
9
  WS_PROTOCOL_ENCODING,
8
10
  WS_PROTOCOL_STANDARD as WS_PROTOCOL_RIVETKIT,
9
- WS_PROTOCOL_TARGET,
10
- WS_PROTOCOL_ACTOR,
11
11
  WS_PROTOCOL_SKIP_READY_WAIT,
12
+ WS_PROTOCOL_TARGET,
12
13
  WS_PROTOCOL_TEST_ACK_HOOK,
13
14
  WS_PROTOCOL_TOKEN,
14
15
  } from "@/common/actor-router-consts";
16
+ import type { JsonCompatValue } from "@/common/encoding";
15
17
  import { importWebSocket } from "@/common/websocket";
16
18
  import { setRemoteHibernatableWebSocketAckTestHooks } from "@/common/websocket-test-hooks";
17
- import type { ActorGatewayQuery, CrashPolicy } from "@/client/query";
18
19
  import type { Encoding, UniversalWebSocket } from "@/mod";
19
- import type { JsonCompatValue } from "@/common/encoding";
20
20
  import { encodeCborCompat, uint8ArrayToBase64 } from "@/serde";
21
21
  import { combineUrlPath } from "@/utils";
22
- import { shouldSkipReadyWait, type GatewayRequestOptions } from "./driver";
22
+ import { type GatewayRequestOptions, shouldSkipReadyWait } from "./driver";
23
23
  import { logger } from "./log";
24
24
 
25
25
  class BufferedRemoteWebSocket implements UniversalWebSocket {
@@ -107,12 +107,59 @@ export async function getDatacenters(
107
107
  return apiCall<never, DatacentersResponse>(config, "GET", `/datacenters`);
108
108
  }
109
109
 
110
+ // MARK: Get runner configs
111
+ export interface RunnerConfig {
112
+ normal?: {
113
+ drain_on_version_upgrade?: boolean;
114
+ actor_eviction_period?: number;
115
+ actor_eviction_rate?: number;
116
+ };
117
+ serverless?: {
118
+ url: string;
119
+ headers: Record<string, string>;
120
+ drain_grace_period?: number;
121
+ max_runners: number;
122
+ min_runners: number;
123
+ request_lifespan: number;
124
+ runners_margin: number;
125
+ slots_per_runner: number;
126
+ metadata_poll_interval?: number;
127
+ drain_on_version_upgrade?: boolean;
128
+ actor_eviction_period?: number;
129
+ actor_eviction_rate?: number;
130
+ };
131
+ protocol_version?: number;
132
+ }
133
+
134
+ export interface RunnerConfigDatacenters {
135
+ datacenters: Record<string, RunnerConfig>;
136
+ }
137
+
138
+ export interface RunnerConfigsResponse {
139
+ runner_configs: Record<string, RunnerConfigDatacenters>;
140
+ }
141
+
142
+ export async function getRunnerConfig(
143
+ config: ClientConfig,
144
+ name: string,
145
+ ): Promise<RunnerConfigsResponse> {
146
+ return apiCall<never, RunnerConfigsResponse>(
147
+ config,
148
+ "GET",
149
+ `/runner-configs?runner_name=${name}`,
150
+ );
151
+ }
152
+
110
153
  // MARK: Update runner config
111
154
  export interface RegistryConfigRequest {
112
155
  datacenters: Record<
113
156
  string,
114
157
  {
115
- normal?: Record<string, unknown>;
158
+ normal?: {
159
+ drain_on_version_upgrade?: boolean;
160
+ actor_eviction_period?: number;
161
+ actor_eviction_rate?: number;
162
+ };
116
163
  serverless?: {
117
164
  url: string;
118
165
  headers: Record<string, string>;
@@ -123,9 +170,11 @@ export interface RegistryConfigRequest {
123
170
  runners_margin: number;
124
171
  slots_per_runner: number;
125
172
  metadata_poll_interval?: number;
173
+ drain_on_version_upgrade?: boolean;
174
+ actor_eviction_period?: number;
175
+ actor_eviction_rate?: number;
126
176
  };
127
177
  metadata?: Record<string, unknown>;
128
- drain_on_version_upgrade?: boolean;
129
178
  }
130
179
  >;
131
180
  }
@@ -1,10 +1,10 @@
1
1
  import { z } from "zod/v4";
2
+ import { RivetError } from "@/actor/errors";
2
3
  import type { ClientConfig } from "@/client/config";
3
4
  import { sendHttpRequest } from "@/client/utils";
4
- import { RivetError } from "@/actor/errors";
5
+ import type { RegistryConfig } from "@/registry/config";
5
6
  import { combineUrlPath } from "@/utils";
6
7
  import { logger } from "./log";
7
- import { RegistryConfig } from "@/registry/config";
8
8
 
9
9
  export { RivetError as EngineApiError };
10
10
 
@@ -1,8 +1,8 @@
1
1
  import type { Hono, Context as HonoContext } from "hono";
2
2
  import type { ActorKey, Encoding, UniversalWebSocket } from "@/actor/mod";
3
+ import type { ActorQuery, CrashPolicy } from "@/client/query";
3
4
  import type { RegistryConfig } from "@/registry/config";
4
5
  import type { GetUpgradeWebSocket } from "@/utils";
5
- import type { ActorQuery, CrashPolicy } from "@/client/query";
6
6
 
7
7
  export type GatewayTarget = { directId: string } | ActorQuery;
8
8
 
@@ -7,9 +7,9 @@ import {
7
7
  PATH_WEBSOCKET_BASE,
8
8
  PATH_WEBSOCKET_PREFIX,
9
9
  } from "@/common/actor-router-consts";
10
+ import type { JsonCompatValue } from "@/common/encoding";
10
11
  import { noopNext } from "@/common/utils";
11
12
  import type { Actor as ApiActor } from "@/engine-api/actors";
12
- import { shouldSkipReadyWait } from "@/engine-client/driver";
13
13
  import type {
14
14
  ActorOutput,
15
15
  CreateInput,
@@ -22,8 +22,8 @@ import type {
22
22
  ListActorsInput,
23
23
  RuntimeDisplayInformation,
24
24
  } from "@/engine-client/driver";
25
+ import { shouldSkipReadyWait } from "@/engine-client/driver";
25
26
  import type { Encoding, UniversalWebSocket } from "@/mod";
26
- import type { JsonCompatValue } from "@/common/encoding";
27
27
  import { encodeCborCompat, uint8ArrayToBase64 } from "@/serde";
28
28
  import { combineUrlPath, type GetUpgradeWebSocket } from "@/utils";
29
29
  import { getNextPhase } from "@/utils/env-vars";
@@ -182,7 +182,9 @@ export class RemoteEngineControlClient implements EngineControlClient {
182
182
  key: serializeActorKey(key),
183
183
  runner_name_selector: this.#config.poolName,
184
184
  input: actorInput
185
- ? uint8ArrayToBase64(encodeCborCompat(actorInput as JsonCompatValue))
185
+ ? uint8ArrayToBase64(
186
+ encodeCborCompat(actorInput as JsonCompatValue),
187
+ )
186
188
  : undefined,
187
189
  crash_policy: crashPolicy ?? "sleep",
188
190
  });
@@ -9,7 +9,7 @@ import { logger } from "./log";
9
9
  * Returns Hono `upgradeWebSocket` args that will proxy requests from the client to a destination address.
10
10
  */
11
11
  export async function createWebSocketProxy(
12
- c: HonoContext,
12
+ _c: HonoContext,
13
13
  targetUrl: string,
14
14
  protocols: string[],
15
15
  ): Promise<UpgradeWebSocketArgs> {
@@ -23,7 +23,7 @@ export async function createWebSocketProxy(
23
23
  const state: WsState = {};
24
24
 
25
25
  return {
26
- onOpen: async (event: any, clientWs: WSContext) => {
26
+ onOpen: async (_event: any, clientWs: WSContext) => {
27
27
  logger().debug({ msg: "client websocket connected", targetUrl });
28
28
 
29
29
  if (clientWs.readyState !== 1) {
@@ -68,6 +68,11 @@ export async function createWebSocketProxy(
68
68
  reject(error);
69
69
  });
70
70
  });
71
+ // Attach a no-op rejection handler so Node.js does not treat this as
72
+ // an unhandled rejection if onMessage never runs (e.g. the client
73
+ // disconnects before sending a message). The rejection still propagates
74
+ // to any caller that awaits connectPromise directly.
75
+ state.connectPromise.catch(() => {});
71
76
 
72
77
  // Setup bidirectional forwarding
73
78
  state.targetWs.addEventListener("message", (event) => {
@@ -137,7 +142,7 @@ export async function createWebSocketProxy(
137
142
  }
138
143
  },
139
144
 
140
- onClose: (event: any, clientWs: WSContext) => {
145
+ onClose: (event: any, _clientWs: WSContext) => {
141
146
  logger().debug({
142
147
  msg: "client websocket closed",
143
148
  targetUrl,
@@ -159,7 +164,7 @@ export async function createWebSocketProxy(
159
164
  }
160
165
  },
161
166
 
162
- onError: (event: any, clientWs: WSContext) => {
167
+ onError: (event: any, _clientWs: WSContext) => {
163
168
  logger().error({ msg: "client websocket error", targetUrl, event });
164
169
 
165
170
  if (state.targetWs) {
@@ -198,7 +198,9 @@ const v3ToServerToV4 = (v3Data: v3.ToServer): v4.ToServer =>
198
198
 
199
199
  const v4ToServerToV3 = (v4Data: v4.ToServer): v3.ToServer => {
200
200
  if (v4Data.body.tag === "WorkflowReplayRequest") {
201
- throw new Error("Cannot convert v4-only workflow replay requests to v3");
201
+ throw new Error(
202
+ "Cannot convert v4-only workflow replay requests to v3",
203
+ );
202
204
  }
203
205
 
204
206
  return v4Data as unknown as v3.ToServer;
@@ -238,11 +240,7 @@ export const TO_SERVER_VERSIONED = createVersionedDataHandler<v4.ToServer>({
238
240
  v2ToServerToV3,
239
241
  v3ToServerToV4,
240
242
  ],
241
- serializeConverters: () => [
242
- v4ToServerToV3,
243
- v3ToServerToV2,
244
- v2ToServerToV1,
245
- ],
243
+ serializeConverters: () => [v4ToServerToV3, v3ToServerToV2, v2ToServerToV1],
246
244
  });
247
245
 
248
246
  export const TO_CLIENT_VERSIONED = createVersionedDataHandler<v4.ToClient>({
@@ -279,9 +277,5 @@ export const TO_CLIENT_VERSIONED = createVersionedDataHandler<v4.ToClient>({
279
277
  v2ToClientToV3,
280
278
  v3ToClientToV4,
281
279
  ],
282
- serializeConverters: () => [
283
- v4ToClientToV3,
284
- v3ToClientToV2,
285
- v2ToClientToV1,
286
- ],
280
+ serializeConverters: () => [v4ToClientToV3, v3ToClientToV2, v2ToClientToV1],
287
281
  });