rivetkit 2.3.0-rc.9 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/dist/browser/client.d.ts +511 -62
  2. package/dist/browser/client.js +230 -174
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +53 -23
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +4 -2
  7. package/dist/tsup/actor/errors.cjs.map +1 -1
  8. package/dist/tsup/actor/errors.d.cts +1 -1
  9. package/dist/tsup/actor/errors.d.ts +1 -1
  10. package/dist/tsup/actor/errors.js +3 -1
  11. package/dist/tsup/agent-os/index.cjs +2163 -2087
  12. package/dist/tsup/agent-os/index.cjs.map +1 -1
  13. package/dist/tsup/agent-os/index.d.cts +509 -69
  14. package/dist/tsup/agent-os/index.d.ts +509 -69
  15. package/dist/tsup/agent-os/index.js +2163 -2087
  16. package/dist/tsup/agent-os/index.js.map +1 -1
  17. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-3MHDOUD7.cjs} +73 -3
  18. package/dist/tsup/chunk-3MHDOUD7.cjs.map +1 -0
  19. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-4FC7TVS6.cjs} +8 -4
  20. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  21. package/dist/tsup/{chunk-4CGA6QJO.cjs → chunk-4UUEB43Y.cjs} +24 -9
  22. package/dist/tsup/chunk-4UUEB43Y.cjs.map +1 -0
  23. package/dist/tsup/{chunk-GVTOE34S.cjs → chunk-5IWLUJ6W.cjs} +222 -235
  24. package/dist/tsup/chunk-5IWLUJ6W.cjs.map +1 -0
  25. package/dist/tsup/{chunk-MMMEZM5J.js → chunk-H6VVZMWN.js} +4 -4
  26. package/dist/tsup/chunk-H6VVZMWN.js.map +1 -0
  27. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  28. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  29. package/dist/tsup/{chunk-H7P7WR2Y.js → chunk-I35VSLEM.js} +6 -6
  30. package/dist/tsup/chunk-I35VSLEM.js.map +1 -0
  31. package/dist/tsup/{chunk-H37XQU3I.js → chunk-JBUZRPY5.js} +2 -2
  32. package/dist/tsup/{chunk-CPA4Y3RG.cjs → chunk-JLJJZYCJ.cjs} +10 -10
  33. package/dist/tsup/chunk-JLJJZYCJ.cjs.map +1 -0
  34. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  35. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  36. package/dist/tsup/{chunk-VRCIXJRN.js → chunk-L2X3YFER.js} +64 -10
  37. package/dist/tsup/chunk-L2X3YFER.js.map +1 -0
  38. package/dist/tsup/{chunk-Y5NSCZA2.cjs → chunk-MNHKOS6L.cjs} +72 -18
  39. package/dist/tsup/chunk-MNHKOS6L.cjs.map +1 -0
  40. package/dist/tsup/{chunk-KJTA3ATT.js → chunk-NERUIBOT.js} +22 -7
  41. package/dist/tsup/chunk-NERUIBOT.js.map +1 -0
  42. package/dist/tsup/{chunk-4WPEZBK4.cjs → chunk-OST76LRW.cjs} +10 -10
  43. package/dist/tsup/chunk-OST76LRW.cjs.map +1 -0
  44. package/dist/tsup/{chunk-MALSPBAF.cjs → chunk-OZBCXBVP.cjs} +3 -3
  45. package/dist/tsup/{chunk-MALSPBAF.cjs.map → chunk-OZBCXBVP.cjs.map} +1 -1
  46. package/dist/tsup/{chunk-F3Q5BFQ6.js → chunk-PT6OIW5E.js} +66 -79
  47. package/dist/tsup/chunk-PT6OIW5E.js.map +1 -0
  48. package/dist/tsup/{chunk-W7EYSYVI.js → chunk-R6KPN5EW.js} +134 -20
  49. package/dist/tsup/chunk-R6KPN5EW.js.map +1 -0
  50. package/dist/tsup/{chunk-VJFRBJVQ.cjs → chunk-V5KMAMX3.cjs} +138 -24
  51. package/dist/tsup/chunk-V5KMAMX3.cjs.map +1 -0
  52. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  53. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  54. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-XIX5DOZN.js} +72 -2
  55. package/dist/tsup/chunk-XIX5DOZN.js.map +1 -0
  56. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  57. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  58. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-ZZ3WBRPD.js} +7 -3
  59. package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
  60. package/dist/tsup/client/mod.cjs +9 -9
  61. package/dist/tsup/client/mod.d.cts +5 -5
  62. package/dist/tsup/client/mod.d.ts +5 -5
  63. package/dist/tsup/client/mod.js +8 -8
  64. package/dist/tsup/common/log.cjs +3 -3
  65. package/dist/tsup/common/log.js +2 -2
  66. package/dist/tsup/common/websocket.cjs +4 -4
  67. package/dist/tsup/common/websocket.js +3 -3
  68. package/dist/tsup/{config-Ca8dN4cS.d.cts → config-CzvopP5m.d.cts} +544 -23
  69. package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.cts} +1 -2
  70. package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.ts} +1 -2
  71. package/dist/tsup/{config-0Ta55UV0.d.ts → config-DZuT7tcp.d.ts} +544 -23
  72. package/dist/tsup/context-CyAdY-aA.d.ts +128 -0
  73. package/dist/tsup/context-sNB28g0N.d.cts +128 -0
  74. package/dist/tsup/db/drizzle.cjs +3 -3
  75. package/dist/tsup/db/drizzle.d.cts +1 -1
  76. package/dist/tsup/db/drizzle.d.ts +1 -1
  77. package/dist/tsup/db/drizzle.js +1 -1
  78. package/dist/tsup/db/mod.cjs +2 -2
  79. package/dist/tsup/db/mod.d.cts +2 -2
  80. package/dist/tsup/db/mod.d.ts +2 -2
  81. package/dist/tsup/db/mod.js +1 -1
  82. package/dist/tsup/dynamic/mod.cjs +24 -0
  83. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  84. package/dist/tsup/dynamic/mod.d.cts +37 -0
  85. package/dist/tsup/dynamic/mod.d.ts +37 -0
  86. package/dist/tsup/dynamic/mod.js +24 -0
  87. package/dist/tsup/dynamic/mod.js.map +1 -0
  88. package/dist/tsup/inspector/mod.cjs +6 -6
  89. package/dist/tsup/inspector/mod.js +5 -5
  90. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  91. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  92. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  93. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  94. package/dist/tsup/inspector-tab/mod.js +173 -0
  95. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  96. package/dist/tsup/mod.cjs +758 -348
  97. package/dist/tsup/mod.cjs.map +1 -1
  98. package/dist/tsup/mod.d.cts +5 -5
  99. package/dist/tsup/mod.d.ts +5 -5
  100. package/dist/tsup/mod.js +662 -252
  101. package/dist/tsup/mod.js.map +1 -1
  102. package/dist/tsup/test/mod.cjs +21 -18
  103. package/dist/tsup/test/mod.cjs.map +1 -1
  104. package/dist/tsup/test/mod.d.cts +4 -4
  105. package/dist/tsup/test/mod.d.ts +4 -4
  106. package/dist/tsup/test/mod.js +18 -15
  107. package/dist/tsup/test/mod.js.map +1 -1
  108. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-CqDnC_PS.d.cts} +2 -1
  109. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-CqDnC_PS.d.ts} +2 -1
  110. package/dist/tsup/utils.cjs +3 -3
  111. package/dist/tsup/utils.d.cts +1 -1
  112. package/dist/tsup/utils.d.ts +1 -1
  113. package/dist/tsup/utils.js +2 -2
  114. package/dist/tsup/workflow/mod.cjs +383 -322
  115. package/dist/tsup/workflow/mod.cjs.map +1 -1
  116. package/dist/tsup/workflow/mod.d.cts +8 -8
  117. package/dist/tsup/workflow/mod.d.ts +8 -8
  118. package/dist/tsup/workflow/mod.js +360 -299
  119. package/dist/tsup/workflow/mod.js.map +1 -1
  120. package/package.json +35 -14
  121. package/src/actor/config.ts +173 -51
  122. package/src/actor/contexts/index.ts +7 -2
  123. package/src/actor/definition.ts +17 -19
  124. package/src/actor/driver.ts +3 -3
  125. package/src/actor/errors.ts +20 -3
  126. package/src/actor/instance/mod.ts +26 -34
  127. package/src/actor/keys.ts +1 -1
  128. package/src/actor/mod.ts +22 -20
  129. package/src/actor/schema.ts +2 -2
  130. package/src/agent-os/actor/index.ts +38 -18
  131. package/src/agent-os/actor/preview.ts +1 -2
  132. package/src/agent-os/actor/session.ts +2 -2
  133. package/src/agent-os/config.ts +1 -1
  134. package/src/agent-os/fs/database-vfs.ts +1 -1
  135. package/src/agent-os/index.ts +16 -15
  136. package/src/client/actor-common.ts +87 -54
  137. package/src/client/actor-conn.ts +8 -36
  138. package/src/client/actor-handle.ts +69 -51
  139. package/src/client/actor-query.ts +5 -5
  140. package/src/client/errors.ts +1 -1
  141. package/src/client/lifecycle-errors.ts +2 -4
  142. package/src/client/query.ts +1 -1
  143. package/src/client/queue.ts +8 -3
  144. package/src/client/raw-utils.ts +8 -6
  145. package/src/client/resolve-gateway-target.ts +1 -1
  146. package/src/client/utils.ts +2 -7
  147. package/src/common/actor-websocket.ts +3 -1
  148. package/src/common/bare/actor-persist/v1.ts +205 -163
  149. package/src/common/bare/actor-persist/v2.ts +265 -213
  150. package/src/common/bare/actor-persist/v3.ts +176 -172
  151. package/src/common/bare/actor-persist/v4.ts +254 -253
  152. package/src/common/bare/transport/v1.ts +659 -543
  153. package/src/common/client-protocol-versioned.ts +66 -64
  154. package/src/common/database/config.ts +2 -8
  155. package/src/common/database/native-database.ts +1 -1
  156. package/src/common/database/shared.ts +1 -0
  157. package/src/common/encoding.ts +250 -16
  158. package/src/common/engine.ts +28 -1
  159. package/src/common/eventsource.ts +1 -1
  160. package/src/common/inline-websocket-adapter.ts +14 -13
  161. package/src/common/log.ts +1 -0
  162. package/src/common/router.ts +13 -17
  163. package/src/common/utils.ts +1 -150
  164. package/src/common/websocket-interface.ts +1 -1
  165. package/src/db/mod.ts +1 -1
  166. package/src/devtools-loader/index.ts +4 -7
  167. package/src/devtools-loader/serve-devtools.ts +26 -0
  168. package/src/drivers/engine/actor-driver.ts +58 -56
  169. package/src/dynamic/instance.ts +32 -0
  170. package/src/dynamic/internal.ts +50 -0
  171. package/src/dynamic/isolate-runtime.ts +66 -0
  172. package/src/dynamic/mod.ts +32 -0
  173. package/src/engine-client/actor-http-client.ts +3 -3
  174. package/src/engine-client/actor-websocket-client.ts +6 -5
  175. package/src/engine-client/api-endpoints.ts +51 -2
  176. package/src/engine-client/api-utils.ts +2 -2
  177. package/src/engine-client/driver.ts +1 -1
  178. package/src/engine-client/mod.ts +6 -3
  179. package/src/engine-client/ws-proxy.ts +9 -4
  180. package/src/inspector/client.browser.ts +5 -11
  181. package/src/inspector/mod.ts +1 -3
  182. package/src/inspector-tab/mod.ts +315 -0
  183. package/src/registry/config/envoy.ts +1 -2
  184. package/src/registry/config/index.ts +40 -16
  185. package/src/registry/index.ts +209 -73
  186. package/src/registry/napi-runtime.ts +29 -2
  187. package/src/registry/native-validation.ts +10 -12
  188. package/src/registry/native.ts +433 -198
  189. package/src/registry/process-metrics.ts +250 -0
  190. package/src/registry/runtime.ts +52 -1
  191. package/src/registry/wasm-runtime.ts +29 -2
  192. package/src/registry/write-through-proxy.ts +40 -0
  193. package/src/serde.ts +2 -2
  194. package/src/serverless/configure.ts +18 -7
  195. package/src/test/mod.ts +11 -8
  196. package/src/utils/endpoint-parser.ts +1 -1
  197. package/src/utils/env-vars.ts +37 -0
  198. package/src/utils/router.ts +1 -1
  199. package/src/utils.ts +1 -2
  200. package/src/workflow/context.ts +699 -240
  201. package/src/workflow/driver.ts +23 -12
  202. package/src/workflow/inspector.ts +4 -3
  203. package/src/workflow/mod.ts +37 -23
  204. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  205. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  206. package/dist/tsup/chunk-4CGA6QJO.cjs.map +0 -1
  207. package/dist/tsup/chunk-4WPEZBK4.cjs.map +0 -1
  208. package/dist/tsup/chunk-CPA4Y3RG.cjs.map +0 -1
  209. package/dist/tsup/chunk-F3Q5BFQ6.js.map +0 -1
  210. package/dist/tsup/chunk-GVTOE34S.cjs.map +0 -1
  211. package/dist/tsup/chunk-H7P7WR2Y.js.map +0 -1
  212. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  213. package/dist/tsup/chunk-KJTA3ATT.js.map +0 -1
  214. package/dist/tsup/chunk-MMMEZM5J.js.map +0 -1
  215. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  216. package/dist/tsup/chunk-QAZLM4WT.cjs.map +0 -1
  217. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  218. package/dist/tsup/chunk-VJFRBJVQ.cjs.map +0 -1
  219. package/dist/tsup/chunk-VRCIXJRN.js.map +0 -1
  220. package/dist/tsup/chunk-W7EYSYVI.js.map +0 -1
  221. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  222. package/dist/tsup/chunk-Y5NSCZA2.cjs.map +0 -1
  223. package/dist/tsup/context-B_IWbWne.d.ts +0 -92
  224. package/dist/tsup/context-CUrQ9MHc.d.cts +0 -92
  225. package/src/utils/serve.ts +0 -217
  226. /package/dist/tsup/{chunk-H37XQU3I.js.map → chunk-JBUZRPY5.js.map} +0 -0
@@ -1,24 +1,18 @@
1
1
  import { z } from "zod/v4";
2
- import type { UniversalWebSocket } from "@/common/websocket-interface";
2
+ import type { Client } from "@/client/client";
3
3
  import type {
4
4
  AnyDatabaseProvider,
5
5
  InferDatabaseClient,
6
- RawDatabaseClient,
7
- DrizzleDatabaseClient,
8
- NativeDatabaseProvider,
9
6
  } from "@/common/database/config";
10
- import type { Client } from "@/client/client";
7
+ import type { UniversalWebSocket } from "@/common/websocket-interface";
11
8
  import type { Registry } from "@/registry";
12
9
  import type { BaseActorDefinition } from "./definition";
13
10
  import type {
14
11
  EventSchemaConfig,
15
- PrimitiveSchema,
16
- QueueSchemaConfig,
17
- } from "./schema";
18
- import type {
19
- InferEventArgs,
20
12
  InferQueueCompleteMap,
21
13
  InferSchemaMap,
14
+ PrimitiveSchema,
15
+ QueueSchemaConfig,
22
16
  } from "./schema";
23
17
 
24
18
  export const DEFAULT_SLEEP_GRACE_PERIOD = 15_000;
@@ -26,6 +20,7 @@ export const DEFAULT_SLEEP_GRACE_PERIOD = 15_000;
26
20
  export const ACTOR_CONTEXT_INTERNAL_SYMBOL = Symbol(
27
21
  "rivetkit.actor_context_internal",
28
22
  );
23
+ export const RAW_STATE_SYMBOL = Symbol("rivetkit.raw_state");
29
24
  export const CONN_DRIVER_SYMBOL = Symbol("rivetkit.conn_driver");
30
25
  export const CONN_STATE_MANAGER_SYMBOL = Symbol("rivetkit.conn_state_manager");
31
26
 
@@ -67,6 +62,10 @@ type ActorKvListOptions<
67
62
 
68
63
  type ActorClientFor<T> = T extends Registry<any> ? Client<T> : T;
69
64
 
65
+ /**
66
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`c.db` / `c.sql`)
67
+ * or actor state instead.
68
+ */
70
69
  export interface ActorKv {
71
70
  get<T extends ActorKvValueType = "text">(
72
71
  key: Uint8Array | string,
@@ -97,7 +96,10 @@ export interface ActorKv {
97
96
  end: Uint8Array | string,
98
97
  options?: ActorKvListOptions<T, K>,
99
98
  ): Promise<Array<[ActorKvKeyTypeMap[K], ActorKvValueTypeMap[T]]>>;
100
- list<T extends ActorKvValueType = "text", K extends ActorKvKeyType = "text">(
99
+ list<
100
+ T extends ActorKvValueType = "text",
101
+ K extends ActorKvKeyType = "text",
102
+ >(
101
103
  prefix: Uint8Array | string,
102
104
  options?: ActorKvListOptions<T, K>,
103
105
  ): Promise<Array<[ActorKvKeyTypeMap[K], ActorKvValueTypeMap[T]]>>;
@@ -118,7 +120,8 @@ export type QueueMessageOf<Name extends string, Body> = {
118
120
  [key: string]: unknown;
119
121
  };
120
122
 
121
- export type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues & string;
123
+ export type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues &
124
+ string;
122
125
  export type QueueFilterName<TQueues extends QueueSchemaConfig> =
123
126
  keyof TQueues extends never ? string : QueueName<TQueues>;
124
127
 
@@ -228,7 +231,9 @@ export interface QueueIterOptions<
228
231
  completable?: TCompletable;
229
232
  }
230
233
 
231
- export interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
234
+ export interface ActorQueue<
235
+ TQueues extends QueueSchemaConfig = Record<never, never>,
236
+ > {
232
237
  send<TName extends QueueFilterName<TQueues>>(
233
238
  name: TName,
234
239
  body: QueueMessageForName<TQueues, TName>["body"],
@@ -236,15 +241,11 @@ export interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, ne
236
241
  next<
237
242
  const TName extends QueueFilterName<TQueues>,
238
243
  const TCompletable extends boolean = false,
239
- >(
240
- opts?: QueueNextOptions<TName, TCompletable>,
241
- ): Promise<any>;
244
+ >(opts?: QueueNextOptions<TName, TCompletable>): Promise<any>;
242
245
  nextBatch<
243
246
  const TName extends QueueFilterName<TQueues>,
244
247
  const TCompletable extends boolean = false,
245
- >(
246
- opts?: QueueNextBatchOptions<TName, TCompletable>,
247
- ): Promise<any[]>;
248
+ >(opts?: QueueNextBatchOptions<TName, TCompletable>): Promise<any[]>;
248
249
  waitForNames<
249
250
  const TName extends QueueFilterName<TQueues>,
250
251
  const TCompletable extends boolean = false,
@@ -260,33 +261,27 @@ export interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, ne
260
261
  tryNext<
261
262
  const TName extends QueueFilterName<TQueues>,
262
263
  const TCompletable extends boolean = false,
263
- >(
264
- opts?: QueueTryNextOptions<TName, TCompletable>,
265
- ): Promise<any>;
264
+ >(opts?: QueueTryNextOptions<TName, TCompletable>): Promise<any>;
266
265
  tryNextBatch<
267
266
  const TName extends QueueFilterName<TQueues>,
268
267
  const TCompletable extends boolean = false,
269
- >(
270
- opts?: QueueTryNextBatchOptions<TName, TCompletable>,
271
- ): Promise<any[]>;
268
+ >(opts?: QueueTryNextBatchOptions<TName, TCompletable>): Promise<any[]>;
272
269
  iter<
273
270
  const TName extends QueueFilterName<TQueues>,
274
271
  const TCompletable extends boolean = false,
275
- >(
276
- opts?: QueueIterOptions<TName, TCompletable>,
277
- ): AsyncIterable<any>;
272
+ >(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
278
273
  [key: string]: any;
279
274
  }
280
275
 
281
276
  export interface Conn<
282
- TState = unknown,
277
+ _TState = unknown,
283
278
  TConnParams = unknown,
284
279
  TConnState = unknown,
285
- TVars = unknown,
286
- TInput = unknown,
287
- TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider,
288
- TEvents extends EventSchemaConfig = Record<never, never>,
289
- TQueues extends QueueSchemaConfig = Record<never, never>,
280
+ _TVars = unknown,
281
+ _TInput = unknown,
282
+ _TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider,
283
+ _TEvents extends EventSchemaConfig = Record<never, never>,
284
+ _TQueues extends QueueSchemaConfig = Record<never, never>,
290
285
  > {
291
286
  id: string;
292
287
  params: TConnParams;
@@ -310,8 +305,14 @@ export interface ActorContext<
310
305
  TQueues extends QueueSchemaConfig = Record<never, never>,
311
306
  > {
312
307
  [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
308
+ /** Returns the raw unwrapped state without the write-through proxy. */
309
+ [RAW_STATE_SYMBOL](): TState;
313
310
  state: TState;
314
311
  vars: TVars;
312
+ /**
313
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
314
+ * or actor state instead.
315
+ */
315
316
  readonly kv: ActorKv;
316
317
  readonly db: InferDatabaseClient<TDatabase>;
317
318
  readonly schedule: ActorSchedule;
@@ -320,7 +321,19 @@ export interface ActorContext<
320
321
  readonly name: string;
321
322
  readonly key: string[];
322
323
  readonly region: string;
323
- readonly conns: Map<string, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>>;
324
+ readonly conns: Map<
325
+ string,
326
+ Conn<
327
+ TState,
328
+ TConnParams,
329
+ TConnState,
330
+ TVars,
331
+ TInput,
332
+ TDatabase,
333
+ TEvents,
334
+ TQueues
335
+ >
336
+ >;
324
337
  readonly log: ActorLogger;
325
338
  readonly abortSignal: AbortSignal;
326
339
  readonly aborted: boolean;
@@ -651,7 +664,9 @@ export type WebSocketContext<
651
664
  TQueues
652
665
  >;
653
666
 
654
- export type ActorContextOf<AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, any>> =
667
+ export type ActorContextOf<
668
+ AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, any>,
669
+ > =
655
670
  AD extends BaseActorDefinition<
656
671
  infer TState,
657
672
  infer TConnParams,
@@ -728,6 +743,88 @@ const RunInspectorConfigSchema = z
728
743
  })
729
744
  .optional();
730
745
 
746
+ /**
747
+ * Built-in inspector tabs the dashboard ships. Used to validate
748
+ * `hidden: true` entries and reject custom-tab ids that collide with
749
+ * a built-in.
750
+ */
751
+ export const BUILTIN_INSPECTOR_TAB_IDS = [
752
+ "workflow",
753
+ "database",
754
+ "state",
755
+ "queue",
756
+ "connections",
757
+ "console",
758
+ ] as const;
759
+
760
+ export const BuiltinInspectorTabIdSchema = z.enum(BUILTIN_INSPECTOR_TAB_IDS);
761
+
762
+ // Custom tab id grammar — mirrored in Rust at
763
+ // `rivetkit-rust/packages/rivetkit-core/src/inspector/tabs.rs`. Slashes are
764
+ // forbidden because the runtime splits `/inspector/custom-tabs/<id>/<rest>`
765
+ // on the first `/`.
766
+ const CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
767
+
768
+ export const CustomInspectorTabEntrySchema = z
769
+ .object({
770
+ id: z
771
+ .string()
772
+ .regex(
773
+ CUSTOM_INSPECTOR_TAB_ID_RE,
774
+ "inspector.tabs[].id must contain only letters, digits, underscore, or dash",
775
+ ),
776
+ label: z.string().min(1),
777
+ source: z.string().min(1),
778
+ /**
779
+ * Optional icon id. The dashboard maps strings to glyphs (see its
780
+ * icon registry); unknown ids fall back to a generic icon.
781
+ */
782
+ icon: z.string().min(1).optional(),
783
+ hidden: z.literal(false).optional(),
784
+ })
785
+ .strict();
786
+
787
+ export const HideInspectorTabEntrySchema = z
788
+ .object({
789
+ id: BuiltinInspectorTabIdSchema,
790
+ hidden: z.literal(true),
791
+ })
792
+ .strict();
793
+
794
+ export const InspectorTabEntrySchema = z.union([
795
+ CustomInspectorTabEntrySchema,
796
+ HideInspectorTabEntrySchema,
797
+ ]);
798
+
799
+ export const ActorInspectorConfigSchema = z
800
+ .object({
801
+ tabs: z.array(InspectorTabEntrySchema).default(() => []),
802
+ })
803
+ .strict()
804
+ .refine(
805
+ (data) => {
806
+ const ids = data.tabs.map((t) => t.id);
807
+ return new Set(ids).size === ids.length;
808
+ },
809
+ { message: "Duplicate id in inspector.tabs", path: ["tabs"] },
810
+ )
811
+ .refine(
812
+ (data) => {
813
+ // A custom entry's id must not collide with a built-in id.
814
+ const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
815
+ return data.tabs.every(
816
+ (t) => t.hidden === true || !builtinSet.has(t.id as any),
817
+ );
818
+ },
819
+ {
820
+ message:
821
+ "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
822
+ path: ["tabs"],
823
+ },
824
+ );
825
+
826
+ export type ActorInspectorConfig = z.input<typeof ActorInspectorConfigSchema>;
827
+
731
828
  // Schema for run handler with metadata
732
829
  export const RunConfigSchema = z.object({
733
830
  /** Display name for the actor in the Inspector UI. */
@@ -784,6 +881,8 @@ interface RunFunctionConfig {
784
881
  icon?: string;
785
882
  inspector?: RunInspectorConfig;
786
883
  inspectorFactory?: (actor: unknown) => RunInspectorConfig | undefined;
884
+ /** Release any per-actor inspector state held for this actor id. */
885
+ disposeInspector?: (actorId: string) => void;
787
886
  }
788
887
 
789
888
  type RunFunctionWithConfig = ((...args: any[]) => any) & {
@@ -834,6 +933,18 @@ export function getRunInspectorConfig(
834
933
  return run.inspector;
835
934
  }
836
935
 
936
+ /** Release per-actor inspector state for a destroyed actor, if the run handler registered a disposer. */
937
+ export function disposeRunInspector(
938
+ run: ((...args: any[]) => any) | AnyRunConfig | undefined,
939
+ actorId: string,
940
+ ): void {
941
+ if (!run || typeof run !== "function") {
942
+ return;
943
+ }
944
+ const config = (run as RunFunctionWithConfig)[RUN_FUNCTION_CONFIG_SYMBOL];
945
+ config?.disposeInspector?.(actorId);
946
+ }
947
+
837
948
  // This schema is used to validate the input at runtime. The generic types are defined below in `ActorConfig`.
838
949
  //
839
950
  // We don't use Zod generics with `z.custom` because:
@@ -944,6 +1055,7 @@ export const ActorConfigSchema = z
944
1055
  db: z.any().optional(),
945
1056
  createVars: zFunction().optional(),
946
1057
  options: ActorOptionsSchema,
1058
+ inspector: ActorInspectorConfigSchema.optional(),
947
1059
  })
948
1060
  .strict()
949
1061
  .refine(
@@ -979,9 +1091,9 @@ export const ActorConfigSchema = z
979
1091
  // Data returned from this handler will be available on `c.state`.
980
1092
  type CreateState<
981
1093
  TState,
982
- TConnParams,
983
- TConnState,
984
- TVars,
1094
+ _TConnParams,
1095
+ _TConnState,
1096
+ _TVars,
985
1097
  TInput,
986
1098
  TDatabase extends AnyDatabaseProvider,
987
1099
  TEvents extends EventSchemaConfig,
@@ -1036,8 +1148,8 @@ type CreateConnState<
1036
1148
  */
1037
1149
  type CreateVars<
1038
1150
  TState,
1039
- TConnParams,
1040
- TConnState,
1151
+ _TConnParams,
1152
+ _TConnState,
1041
1153
  TVars,
1042
1154
  TInput,
1043
1155
  TDatabase extends AnyDatabaseProvider,
@@ -1498,6 +1610,25 @@ export type ActorConfig<
1498
1610
  TDatabase extends AnyDatabaseProvider,
1499
1611
  TEvents extends EventSchemaConfig = Record<never, never>,
1500
1612
  TQueues extends QueueSchemaConfig = Record<never, never>,
1613
+ TActions extends Actions<
1614
+ TState,
1615
+ TConnParams,
1616
+ TConnState,
1617
+ TVars,
1618
+ TInput,
1619
+ TDatabase,
1620
+ TEvents,
1621
+ TQueues
1622
+ > = Actions<
1623
+ TState,
1624
+ TConnParams,
1625
+ TConnState,
1626
+ TVars,
1627
+ TInput,
1628
+ TDatabase,
1629
+ TEvents,
1630
+ TQueues
1631
+ >,
1501
1632
  > = Omit<
1502
1633
  z.infer<typeof ActorConfigSchema>,
1503
1634
  | "actions"
@@ -1533,16 +1664,7 @@ export type ActorConfig<
1533
1664
  TDatabase,
1534
1665
  TEvents,
1535
1666
  TQueues,
1536
- Actions<
1537
- TState,
1538
- TConnParams,
1539
- TConnState,
1540
- TVars,
1541
- TInput,
1542
- TDatabase,
1543
- TEvents,
1544
- TQueues
1545
- >
1667
+ TActions
1546
1668
  > &
1547
1669
  CreateState<
1548
1670
  TState,
@@ -16,10 +16,15 @@ import type {
16
16
  WakeContext,
17
17
  WebSocketContext,
18
18
  } from "@/actor/config";
19
+
19
20
  export type { ActorContextOf } from "@/actor/config";
20
- import type { AnyActorDefinition, BaseActorDefinition } from "@/actor/definition";
21
- import type { AnyDatabaseProvider } from "@/common/database/config";
21
+
22
+ import type {
23
+ AnyActorDefinition,
24
+ BaseActorDefinition,
25
+ } from "@/actor/definition";
22
26
  import type { EventSchemaConfig, QueueSchemaConfig } from "@/actor/schema";
27
+ import type { AnyDatabaseProvider } from "@/common/database/config";
23
28
 
24
29
  export type ActionContextOf<AD extends AnyActorDefinition> =
25
30
  AD extends BaseActorDefinition<
@@ -1,7 +1,12 @@
1
+ import type { AnyDatabaseProvider } from "@/common/database/config";
1
2
  import type { RegistryConfig } from "@/registry/config";
2
- import { ActorConfigSchema, type Actions, type ActorConfig, type ActorConfigInput } from "./config";
3
+ import {
4
+ type Actions,
5
+ type ActorConfig,
6
+ type ActorConfigInput,
7
+ ActorConfigSchema,
8
+ } from "./config";
3
9
  import { loggerWithoutContext } from "./log";
4
- import type { AnyDatabaseProvider } from "@/common/database/config";
5
10
  import type { EventSchemaConfig, QueueSchemaConfig } from "./schema";
6
11
 
7
12
  const warnedDeprecatedTimeoutKeys = new Set<string>();
@@ -28,7 +33,7 @@ export interface BaseActorDefinition<
28
33
  DB extends AnyDatabaseProvider,
29
34
  E extends EventSchemaConfig = Record<never, never>,
30
35
  Q extends QueueSchemaConfig = Record<never, never>,
31
- R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<
36
+ _R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<
32
37
  S,
33
38
  CP,
34
39
  CS,
@@ -39,20 +44,12 @@ export interface BaseActorDefinition<
39
44
  Q
40
45
  >,
41
46
  > {
42
- readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
47
+ readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
43
48
  }
44
49
 
45
- export type AnyActorDefinition = BaseActorDefinition<
46
- any,
47
- any,
48
- any,
49
- any,
50
- any,
51
- any,
52
- any,
53
- any,
54
- any
55
- >;
50
+ export interface AnyActorDefinition {
51
+ readonly config: any;
52
+ }
56
53
 
57
54
  export type AnyStaticActorDefinition = ActorDefinition<
58
55
  any,
@@ -87,13 +84,13 @@ export class ActorDefinition<
87
84
  >,
88
85
  > implements BaseActorDefinition<S, CP, CS, V, I, DB, E, Q, R>
89
86
  {
90
- #config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
87
+ #config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
91
88
 
92
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>) {
89
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>) {
93
90
  this.#config = config;
94
91
  }
95
92
 
96
- get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q> {
93
+ get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R> {
97
94
  return this.#config;
98
95
  }
99
96
  }
@@ -195,7 +192,8 @@ export function actor<
195
192
  TInput,
196
193
  TDatabase,
197
194
  TEvents,
198
- TQueues
195
+ TQueues,
196
+ TActions
199
197
  >;
200
198
  return new ActorDefinition(config);
201
199
  }
@@ -1,12 +1,12 @@
1
1
  import type { Context as HonoContext } from "hono";
2
2
  import type { AnyClient } from "@/client/client";
3
- import type { EngineControlClient } from "@/engine-client/driver";
4
- import type { AnyActorInstance, AnyStaticActorInstance } from "./definition";
5
- import type { RegistryConfig } from "@/registry/config";
6
3
  import type {
7
4
  DrizzleDatabaseClient,
8
5
  NativeDatabaseProvider,
9
6
  } from "@/common/database/config";
7
+ import type { EngineControlClient } from "@/engine-client/driver";
8
+ import type { RegistryConfig } from "@/registry/config";
9
+ import type { AnyActorInstance, AnyStaticActorInstance } from "./definition";
10
10
 
11
11
  export type ActorDriverBuilder = (
12
12
  config: RegistryConfig,
@@ -98,6 +98,17 @@ export function isRivetErrorLike(
98
98
  );
99
99
  }
100
100
 
101
+ // Matches the `actor`/`aborted` error that core raises when an in-flight queue
102
+ // wait is interrupted because the actor is going to sleep. This is the expected
103
+ // way a parked `run` handler unwinds during sleep, not a failure.
104
+ export function isActorAbortedError(error: unknown): boolean {
105
+ return (
106
+ isRivetErrorLike(error) &&
107
+ error.group === "actor" &&
108
+ error.code === "aborted"
109
+ );
110
+ }
111
+
101
112
  function isActorSpecifier(value: unknown): value is ActorSpecifier {
102
113
  return (
103
114
  typeof value === "object" &&
@@ -106,7 +117,9 @@ function isActorSpecifier(value: unknown): value is ActorSpecifier {
106
117
  typeof value.actorId === "string" &&
107
118
  "generation" in value &&
108
119
  typeof value.generation === "number" &&
109
- (!("key" in value) || value.key === undefined || typeof value.key === "string")
120
+ (!("key" in value) ||
121
+ value.key === undefined ||
122
+ typeof value.key === "string")
110
123
  );
111
124
  }
112
125
 
@@ -237,7 +250,11 @@ export function decodeBridgeRivetErrorPayload(
237
250
  if (!isRivetErrorLike(payload)) {
238
251
  return undefined;
239
252
  }
240
- if (payload.actor !== undefined && !isActorSpecifier(payload.actor)) {
253
+ if (
254
+ payload.actor !== undefined &&
255
+ payload.actor !== null &&
256
+ !isActorSpecifier(payload.actor)
257
+ ) {
241
258
  return undefined;
242
259
  }
243
260
 
@@ -257,7 +274,7 @@ export function decodeBridgeRivetError(value: string): RivetError | undefined {
257
274
  metadata: payload.metadata,
258
275
  public: payload.public,
259
276
  statusCode: payload.statusCode,
260
- actor: payload.actor,
277
+ actor: payload.actor ?? undefined,
261
278
  });
262
279
  }
263
280
 
@@ -9,22 +9,21 @@ import {
9
9
  type SpanStatusInput,
10
10
  type Traces,
11
11
  } from "@rivetkit/traces";
12
- import { ActorMetrics, type StartupTimingKey } from "@/actor/metrics";
13
12
  import invariant from "invariant";
13
+ import { ActorMetrics, type StartupTimingKey } from "@/actor/metrics";
14
14
  import type { Client } from "@/client/client";
15
+ import type { ActorKey } from "@/client/query";
15
16
  import { getBaseLogger, getIncludeTarget, type Logger } from "@/common/log";
16
17
  import { stringifyError } from "@/common/utils";
17
18
  import type { UniversalWebSocket } from "@/common/websocket-interface";
18
19
  import { ActorInspector } from "@/inspector/actor-inspector";
19
- import type { ActorKey } from "@/client/query";
20
20
  import type { Registry } from "@/mod";
21
21
  import {
22
22
  ACTOR_VERSIONED,
23
23
  CONN_VERSIONED,
24
24
  } from "@/schemas/actor-persist/versioned";
25
- import { EXTRA_ERROR_LOG } from "@/utils";
25
+ import { EXTRA_ERROR_LOG, promiseWithResolvers } from "@/utils";
26
26
  import { getRivetExperimentalOtel } from "@/utils/env-vars";
27
- import { promiseWithResolvers } from "@/utils";
28
27
  import {
29
28
  type Actions,
30
29
  type ActorConfig,
@@ -32,16 +31,13 @@ import {
32
31
  ActorConfigSchema,
33
32
  getRunFunction,
34
33
  } from "../config";
35
- import type { ConnDriver } from "../conn/driver";
36
- import { createHttpDriver } from "../conn/drivers/http";
37
34
  import {
38
- HibernatableWebSocketAckState,
39
35
  handleInboundHibernatableWebSocketMessage as applyInboundHibernatableWebSocketMessage,
36
+ HibernatableWebSocketAckState,
40
37
  } from "../conn/hibernatable-websocket-ack-state";
41
38
  import {
42
- CONN_DRIVER_SYMBOL,
43
- CONN_STATE_MANAGER_SYMBOL,
44
39
  type AnyConn,
40
+ CONN_STATE_MANAGER_SYMBOL,
45
41
  type Conn,
46
42
  type ConnId,
47
43
  } from "../conn/mod";
@@ -50,7 +46,7 @@ import {
50
46
  type PersistedConn,
51
47
  } from "../conn/persisted";
52
48
  import {
53
- ActionContext,
49
+ type ActionContext,
54
50
  ActorContext,
55
51
  RequestContext,
56
52
  WebSocketContext,
@@ -79,20 +75,16 @@ import {
79
75
  import { ConnectionManager } from "./connection-manager";
80
76
  import { EventManager } from "./event-manager";
81
77
  import { KEYS, workflowStoragePrefix } from "./keys";
82
- import {
83
- type PreloadedEntries,
84
- type PreloadHit,
85
- type PreloadMap,
86
- } from "./preload-map";
87
78
  import {
88
79
  convertActorFromBarePersisted,
89
80
  type PersistedActor,
90
81
  } from "./persisted";
82
+ import type { PreloadedEntries, PreloadMap } from "./preload-map";
91
83
  import { QueueManager } from "./queue-manager";
92
84
  import { ScheduleManager } from "./schedule-manager";
93
85
  import { type SaveStateOptions, StateManager } from "./state-manager";
94
- import { TrackedWebSocket } from "./tracked-websocket";
95
86
  import { ActorTracesDriver } from "./traces-driver";
87
+ import { TrackedWebSocket } from "./tracked-websocket";
96
88
  import { WriteCollector } from "./write-collector";
97
89
 
98
90
  export type { SaveStateOptions };
@@ -215,14 +207,14 @@ const ACTIVE_ASYNC_REGION_ERROR_MESSAGES: Record<
215
207
  * only on `ActorInstance`.
216
208
  */
217
209
  export interface BaseActorInstance<
218
- S = any,
219
- CP = any,
220
- CS = any,
221
- V = any,
222
- I = any,
223
- DB extends AnyDatabaseProvider = AnyDatabaseProvider,
224
- E extends EventSchemaConfig = Record<never, never>,
225
- Q extends QueueSchemaConfig = Record<never, never>,
210
+ _S = any,
211
+ _CP = any,
212
+ _CS = any,
213
+ _V = any,
214
+ _I = any,
215
+ _DB extends AnyDatabaseProvider = AnyDatabaseProvider,
216
+ _E extends EventSchemaConfig = Record<never, never>,
217
+ _Q extends QueueSchemaConfig = Record<never, never>,
226
218
  > {
227
219
  readonly id: string;
228
220
  readonly isStopping: boolean;
@@ -1274,7 +1266,7 @@ export class ActorInstance<
1274
1266
  "actor.onBeforeActionResponse",
1275
1267
  { "rivet.action.name": actionName },
1276
1268
  () =>
1277
- this.#config.onBeforeActionResponse!(
1269
+ this.#config.onBeforeActionResponse?.(
1278
1270
  this.actorContext,
1279
1271
  actionName,
1280
1272
  args,
@@ -1406,7 +1398,7 @@ export class ActorInstance<
1406
1398
 
1407
1399
  // NOTE: This is async and will run in the background
1408
1400
  const voidOrPromise = this.#traces.withSpan(span, () =>
1409
- this.#config.onWebSocket!(ctx, trackedWebSocket),
1401
+ this.#config.onWebSocket?.(ctx, trackedWebSocket),
1410
1402
  );
1411
1403
 
1412
1404
  // Save changes from the WebSocket open
@@ -1645,10 +1637,10 @@ export class ActorInstance<
1645
1637
  attributes?: Record<string, unknown>,
1646
1638
  ): Record<string, unknown> {
1647
1639
  return {
1648
- "rivet.actor.id": this.#actorId,
1649
- "rivet.actor.name": this.#name,
1650
- "rivet.actor.key": this.#actorKeyString,
1651
- "rivet.actor.region": this.#region,
1640
+ "rivet.actors.actor.id": this.#actorId,
1641
+ "rivet.actors.actor.name": this.#name,
1642
+ "rivet.actors.actor.key": this.#actorKeyString,
1643
+ "rivet.actors.actor.region": this.#region,
1652
1644
  ...(attributes ?? {}),
1653
1645
  };
1654
1646
  }
@@ -1882,7 +1874,7 @@ export class ActorInstance<
1882
1874
  "actor.createVars",
1883
1875
  undefined,
1884
1876
  () => {
1885
- const dataOrPromise = createVars!(
1877
+ const dataOrPromise = createVars?.(
1886
1878
  this.actorContext as any,
1887
1879
  this.driver.getContext(this.#actorId),
1888
1880
  );
@@ -2084,7 +2076,7 @@ export class ActorInstance<
2084
2076
  }
2085
2077
  }
2086
2078
 
2087
- async #setupDatabase(preload?: PreloadMap) {
2079
+ async #setupDatabase(_preload?: PreloadMap) {
2088
2080
  if (!("db" in this.#config) || !this.#config.db) {
2089
2081
  return;
2090
2082
  }
@@ -2099,14 +2091,14 @@ export class ActorInstance<
2099
2091
  overrideRawDatabaseClient: this.driver
2100
2092
  .overrideRawDatabaseClient
2101
2093
  ? () =>
2102
- this.driver.overrideRawDatabaseClient!(
2094
+ this.driver.overrideRawDatabaseClient?.(
2103
2095
  this.#actorId,
2104
2096
  )
2105
2097
  : undefined,
2106
2098
  overrideDrizzleDatabaseClient: this.driver
2107
2099
  .overrideDrizzleDatabaseClient
2108
2100
  ? () =>
2109
- this.driver.overrideDrizzleDatabaseClient!(
2101
+ this.driver.overrideDrizzleDatabaseClient?.(
2110
2102
  this.#actorId,
2111
2103
  )
2112
2104
  : undefined,