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,8 +1,8 @@
1
1
  import * as _rivetkit_rivetkit_wasm from '@rivetkit/rivetkit-wasm';
2
2
  import { z as z$2 } from 'zod';
3
3
  import z$1, { z } from 'zod/v4';
4
- import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
5
4
  import { Context, Handler, Hono } from 'hono';
5
+ import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
6
6
  import { StandardSchemaV1 } from '@standard-schema/spec';
7
7
  import { ContentfulStatusCode } from 'hono/utils/http-status';
8
8
  import { Logger } from 'pino';
@@ -103,8 +103,7 @@ type DatabaseProvider<DB extends RawAccess> = {
103
103
  /**
104
104
  * Drizzle database client interface (will be extended by drizzle-orm types)
105
105
  */
106
- interface DrizzleDatabaseClient {
107
- }
106
+ type DrizzleDatabaseClient = {};
108
107
  type ExecuteFunction = <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]>;
109
108
  type RawAccess = {
110
109
  /**
@@ -182,6 +181,44 @@ type ActorQuery = z.infer<typeof ActorQuerySchema>;
182
181
  */
183
182
  type CreateRequest = z.infer<typeof CreateRequestSchema>;
184
183
 
184
+ type SchemaHookResult = boolean | Promise<boolean>;
185
+ type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
186
+ interface EventTypeToken<T, TContext = any> {
187
+ readonly _eventType?: T;
188
+ readonly canSubscribe?: SchemaHook<TContext>;
189
+ readonly schema?: PrimitiveSchema;
190
+ }
191
+ interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
192
+ readonly _queueMessage?: TMessage;
193
+ readonly _queueComplete?: TComplete;
194
+ readonly canPublish?: SchemaHook<TContext>;
195
+ readonly message?: PrimitiveSchema;
196
+ readonly complete?: PrimitiveSchema;
197
+ }
198
+ type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
199
+ interface EventSchemaDefinition<TContext = any> {
200
+ schema: PrimitiveSchema;
201
+ canSubscribe?: SchemaHook<TContext>;
202
+ }
203
+ interface QueueSchemaDefinition<TContext = any> {
204
+ message: PrimitiveSchema;
205
+ complete?: PrimitiveSchema;
206
+ canPublish?: SchemaHook<TContext>;
207
+ }
208
+ type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
209
+ type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
210
+ type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
211
+ type QueueSchemaConfig<_TContext = any> = Record<string, QueueSchema>;
212
+ type InferSchema<T> = T extends QueueSchemaDefinition<any> ? InferSchema<T["message"]> : T extends QueueTypeToken<infer M, unknown, any> ? M : T extends EventSchemaDefinition<any> ? InferSchema<T["schema"]> : T extends StandardSchemaV1<any, infer O> ? O : T extends EventTypeToken<infer R, any> ? R : never;
213
+ type InferSchemaMap<T extends Record<string, unknown>> = {
214
+ [K in keyof T]: InferSchema<T[K]>;
215
+ };
216
+ type InferQueueComplete<T> = T extends QueueTypeToken<unknown, infer C, any> ? [C] extends [never] ? never : C : T extends QueueSchemaDefinition<any> ? T["complete"] extends PrimitiveSchema ? InferSchema<T["complete"]> : never : never;
217
+ type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
218
+ [K in keyof T]: InferQueueComplete<T[K]>;
219
+ };
220
+ type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
221
+
185
222
  interface DeconstructedError {
186
223
  __type: "ActorError";
187
224
  statusCode: ContentfulStatusCode;
@@ -239,44 +276,6 @@ declare class UserError extends RivetError {
239
276
  constructor(message: string, options?: UserErrorOptions);
240
277
  }
241
278
 
242
- type SchemaHookResult = boolean | Promise<boolean>;
243
- type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
244
- interface EventTypeToken<T, TContext = any> {
245
- readonly _eventType?: T;
246
- readonly canSubscribe?: SchemaHook<TContext>;
247
- readonly schema?: PrimitiveSchema;
248
- }
249
- interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
250
- readonly _queueMessage?: TMessage;
251
- readonly _queueComplete?: TComplete;
252
- readonly canPublish?: SchemaHook<TContext>;
253
- readonly message?: PrimitiveSchema;
254
- readonly complete?: PrimitiveSchema;
255
- }
256
- type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
257
- interface EventSchemaDefinition<TContext = any> {
258
- schema: PrimitiveSchema;
259
- canSubscribe?: SchemaHook<TContext>;
260
- }
261
- interface QueueSchemaDefinition<TContext = any> {
262
- message: PrimitiveSchema;
263
- complete?: PrimitiveSchema;
264
- canPublish?: SchemaHook<TContext>;
265
- }
266
- type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
267
- type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
268
- type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
269
- type QueueSchemaConfig<TContext = any> = Record<string, QueueSchema>;
270
- type InferSchema<T> = T extends QueueSchemaDefinition<any> ? InferSchema<T["message"]> : T extends QueueTypeToken<infer M, unknown, any> ? M : T extends EventSchemaDefinition<any> ? InferSchema<T["schema"]> : T extends StandardSchemaV1<any, infer O> ? O : T extends EventTypeToken<infer R, any> ? R : never;
271
- type InferSchemaMap<T extends Record<string, unknown>> = {
272
- [K in keyof T]: InferSchema<T[K]>;
273
- };
274
- type InferQueueComplete<T> = T extends QueueTypeToken<unknown, infer C, any> ? [C] extends [never] ? never : C : T extends QueueSchemaDefinition<any> ? T["complete"] extends PrimitiveSchema ? InferSchema<T["complete"]> : never : never;
275
- type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
276
- [K in keyof T]: InferQueueComplete<T[K]>;
277
- };
278
- type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
279
-
280
279
  type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
281
280
  type GetUpgradeWebSocket = () => UpgradeWebSocket;
282
281
 
@@ -384,6 +383,12 @@ interface QueueSendResult<TResponse = unknown> {
384
383
  * @returns {Promise<Response>}
385
384
  */
386
385
  type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
386
+ type IsAny<T> = 0 extends 1 & T ? true : false;
387
+ type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
388
+ type ActorActionMap<R> = {
389
+ [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : never;
390
+ };
391
+ type ActionsOf<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? R : never;
387
392
  interface ActorGatewayOptions {
388
393
  skipReadyWait?: boolean;
389
394
  }
@@ -396,9 +401,7 @@ type ActorWebSocketOptions = ActorGatewayOptions;
396
401
  /**
397
402
  * Maps action methods from actor definition to typed function signatures.
398
403
  */
399
- type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? {
400
- [K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
401
- } : never;
404
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
402
405
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
403
406
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
404
407
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
@@ -409,13 +412,31 @@ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
409
412
  <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
410
413
  (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
411
414
  };
412
- type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
415
+ type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
416
+ send: ActorQueueSend<Record<string, any>>;
417
+ } : AD extends {
418
+ config: {
419
+ queues?: infer Q;
420
+ };
421
+ } ? Q extends QueueSchemaConfig ? {
413
422
  send: ActorQueueSend<Q>;
414
- } : never : never;
415
- type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
423
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
424
+ send: ActorQueueSend<Q>;
425
+ } : {} : {};
426
+ type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
427
+ on: LooseEventSubscribe;
428
+ once: LooseEventSubscribe;
429
+ } : AD extends {
430
+ config: {
431
+ events?: infer E;
432
+ };
433
+ } ? E extends EventSchemaConfig ? {
416
434
  on: ActorEventSubscribe<E>;
417
435
  once: ActorEventSubscribe<E>;
418
- } : never : never;
436
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
437
+ on: ActorEventSubscribe<E>;
438
+ once: ActorEventSubscribe<E>;
439
+ } : {} : {};
419
440
 
420
441
  declare class ActorClientError extends Error {
421
442
  }
@@ -929,6 +950,7 @@ type Client<A extends Registry<any>> = ClientRaw & {
929
950
  };
930
951
 
931
952
  declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
953
+ declare const RAW_STATE_SYMBOL: unique symbol;
932
954
  interface ActorLogger {
933
955
  level: any;
934
956
  fatal: any;
@@ -961,6 +983,10 @@ type ActorKvListOptions<T extends ActorKvValueType = "text", K extends ActorKvKe
961
983
  limit?: number;
962
984
  };
963
985
  type ActorClientFor<T> = T extends Registry<any> ? Client<T> : T;
986
+ /**
987
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`c.db` / `c.sql`)
988
+ * or actor state instead.
989
+ */
964
990
  interface ActorKv {
965
991
  get<T extends ActorKvValueType = "text">(key: Uint8Array | string, options?: ActorKvValueOptions<T>): Promise<ActorKvValueTypeMap[T] | null>;
966
992
  put<T extends ActorKvValueType = "text">(key: Uint8Array | string, value: Uint8Array | string | ArrayBuffer, options?: ActorKvValueOptions<T>): Promise<void>;
@@ -1037,7 +1063,7 @@ interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1037
1063
  iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
1038
1064
  [key: string]: any;
1039
1065
  }
1040
- interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TVars = unknown, TInput = unknown, TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1066
+ interface Conn<_TState = unknown, TConnParams = unknown, TConnState = unknown, _TVars = unknown, _TInput = unknown, _TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider, _TEvents extends EventSchemaConfig = Record<never, never>, _TQueues extends QueueSchemaConfig = Record<never, never>> {
1041
1067
  id: string;
1042
1068
  params: TConnParams;
1043
1069
  state: TConnState;
@@ -1048,8 +1074,14 @@ interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TV
1048
1074
  }
1049
1075
  interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1050
1076
  [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
1077
+ /** Returns the raw unwrapped state without the write-through proxy. */
1078
+ [RAW_STATE_SYMBOL](): TState;
1051
1079
  state: TState;
1052
1080
  vars: TVars;
1081
+ /**
1082
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
1083
+ * or actor state instead.
1084
+ */
1053
1085
  readonly kv: ActorKv;
1054
1086
  readonly db: InferDatabaseClient<TDatabase>;
1055
1087
  readonly schedule: ActorSchedule;
@@ -1174,8 +1206,27 @@ declare const ActorConfigSchema: z.ZodObject<{
1174
1206
  preloadMaxWorkflowBytes: z.ZodOptional<z.ZodNumber>;
1175
1207
  preloadMaxConnectionsBytes: z.ZodOptional<z.ZodNumber>;
1176
1208
  }, z.core.$strict>>;
1209
+ inspector: z.ZodOptional<z.ZodObject<{
1210
+ tabs: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
1211
+ id: z.ZodString;
1212
+ label: z.ZodString;
1213
+ source: z.ZodString;
1214
+ icon: z.ZodOptional<z.ZodString>;
1215
+ hidden: z.ZodOptional<z.ZodLiteral<false>>;
1216
+ }, z.core.$strict>, z.ZodObject<{
1217
+ id: z.ZodEnum<{
1218
+ state: "state";
1219
+ workflow: "workflow";
1220
+ database: "database";
1221
+ queue: "queue";
1222
+ connections: "connections";
1223
+ console: "console";
1224
+ }>;
1225
+ hidden: z.ZodLiteral<true>;
1226
+ }, z.core.$strict>]>>>;
1227
+ }, z.core.$strict>>;
1177
1228
  }, z.core.$strict>;
1178
- type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1229
+ type CreateState<TState, _TConnParams, _TConnState, _TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1179
1230
  state: TState;
1180
1231
  } | {
1181
1232
  createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
@@ -1188,7 +1239,7 @@ type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase e
1188
1239
  /**
1189
1240
  * @experimental
1190
1241
  */
1191
- type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1242
+ type CreateVars<TState, _TConnParams, _TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1192
1243
  /**
1193
1244
  * @experimental
1194
1245
  */
@@ -1374,19 +1425,21 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1374
1425
  */
1375
1426
  db: TDatabase;
1376
1427
  } | Record<never, never>;
1377
- type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onMigrate" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
1428
+ type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> = Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onMigrate" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, TActions> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
1378
1429
 
1379
- interface BaseActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> {
1380
- readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
1430
+ interface BaseActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, _R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> {
1431
+ readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
1432
+ }
1433
+ interface AnyActorDefinition {
1434
+ readonly config: any;
1381
1435
  }
1382
- type AnyActorDefinition = BaseActorDefinition<any, any, any, any, any, any, any, any, any>;
1383
1436
  declare class ActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> implements BaseActorDefinition<S, CP, CS, V, I, DB, E, Q, R> {
1384
1437
  #private;
1385
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
1386
- get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
1438
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>);
1439
+ get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
1387
1440
  }
1388
1441
 
1389
- declare const ActorsSchema: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<BaseActorDefinition<any, any, any, any, any, any, any, any, any>, BaseActorDefinition<any, any, any, any, any, any, any, any, any>>>;
1442
+ declare const ActorsSchema: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
1390
1443
  type RegistryActors = z$2.infer<typeof ActorsSchema>;
1391
1444
  declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1392
1445
  use: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
@@ -1406,7 +1459,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1406
1459
  }>>, z$2.ZodTransform<"auto" | "native" | "wasm", "auto" | "native" | "wasm" | undefined>>;
1407
1460
  wasm: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1408
1461
  bindings: z$2.ZodOptional<z$2.ZodCustom<typeof _rivetkit_rivetkit_wasm, typeof _rivetkit_rivetkit_wasm>>;
1409
- initInput: z$2.ZodOptional<z$2.ZodCustom<any, any>>;
1462
+ initInput: z$2.ZodOptional<z$2.ZodCustom<_rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined, _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined>>;
1410
1463
  }, z$2.core.$strip>>>;
1411
1464
  sqlite: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodUnion<readonly [z$2.ZodEnum<{
1412
1465
  local: "local";
@@ -1443,6 +1496,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1443
1496
  httpPort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1444
1497
  httpHost: z$2.ZodOptional<z$2.ZodString>;
1445
1498
  startEngine: z$2.ZodDefault<z$2.ZodBoolean>;
1499
+ engineHost: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
1500
+ enginePort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1446
1501
  engineVersion: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
1447
1502
  configurePool: z$2.ZodOptional<z$2.ZodOptional<z$2.ZodObject<{
1448
1503
  name: z$2.ZodOptional<z$2.ZodString>;
@@ -1497,7 +1552,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1497
1552
  runtime: "auto" | "native" | "wasm";
1498
1553
  wasm: {
1499
1554
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1500
- initInput?: any;
1555
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1501
1556
  };
1502
1557
  noWelcome: boolean;
1503
1558
  logging: {
@@ -1508,6 +1563,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1508
1563
  httpBasePath: string;
1509
1564
  httpPort: number;
1510
1565
  startEngine: boolean;
1566
+ engineHost: string;
1567
+ enginePort: number;
1511
1568
  engineVersion: string;
1512
1569
  envoy: {
1513
1570
  poolName: string;
@@ -1542,7 +1599,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1542
1599
  runtime: "auto" | "native" | "wasm";
1543
1600
  wasm: {
1544
1601
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1545
- initInput?: any;
1602
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1546
1603
  };
1547
1604
  sqlite: {
1548
1605
  backend: "local" | "remote";
@@ -1559,6 +1616,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1559
1616
  httpBasePath: string;
1560
1617
  httpPort: number;
1561
1618
  startEngine: boolean;
1619
+ engineHost: string;
1620
+ enginePort: number;
1562
1621
  engineVersion: string;
1563
1622
  serverless: {
1564
1623
  basePath: string;
@@ -1594,6 +1653,341 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1594
1653
  use: A;
1595
1654
  };
1596
1655
 
1656
+ declare const handleBrand: unique symbol;
1657
+ type OpaqueHandle<Name extends string> = {
1658
+ readonly [handleBrand]: Name;
1659
+ };
1660
+ type RegistryHandle = OpaqueHandle<"registry">;
1661
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
1662
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
1663
+ type ConnHandle = OpaqueHandle<"conn">;
1664
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
1665
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
1666
+ type RuntimeBytes = Uint8Array;
1667
+ interface RuntimeActorKeySegment {
1668
+ kind: string;
1669
+ stringValue?: string;
1670
+ numberValue?: number;
1671
+ }
1672
+ interface RuntimeHttpRequest {
1673
+ method: string;
1674
+ uri: string;
1675
+ headers?: Record<string, string>;
1676
+ body?: RuntimeBytes;
1677
+ }
1678
+ interface RuntimeStateDeltaPayload {
1679
+ state?: RuntimeBytes;
1680
+ connHibernation: Array<{
1681
+ connId: string;
1682
+ bytes: RuntimeBytes;
1683
+ }>;
1684
+ connHibernationRemoved: string[];
1685
+ }
1686
+ interface RuntimeRequestSaveOpts {
1687
+ immediate?: boolean;
1688
+ maxWaitMs?: number;
1689
+ }
1690
+ interface RuntimeInspectorSnapshot {
1691
+ stateRevision: number;
1692
+ connectionsRevision: number;
1693
+ queueRevision: number;
1694
+ activeConnections: number;
1695
+ queueSize: number;
1696
+ connectedClients: number;
1697
+ }
1698
+ interface RuntimeQueueMessage {
1699
+ id(): bigint;
1700
+ name(): string;
1701
+ body(): RuntimeBytes;
1702
+ createdAt(): number;
1703
+ isCompletable(): boolean;
1704
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
1705
+ }
1706
+ interface RuntimeQueueInspectMessage {
1707
+ id: number;
1708
+ name: string;
1709
+ createdAtMs: number;
1710
+ }
1711
+ interface RuntimeQueueNextBatchOptions {
1712
+ names?: string[];
1713
+ count?: number;
1714
+ timeoutMs?: number;
1715
+ completable?: boolean;
1716
+ }
1717
+ interface RuntimeQueueWaitOptions {
1718
+ timeoutMs?: number;
1719
+ completable?: boolean;
1720
+ }
1721
+ interface RuntimeQueueEnqueueAndWaitOptions {
1722
+ timeoutMs?: number;
1723
+ }
1724
+ interface RuntimeQueueTryNextBatchOptions {
1725
+ names?: string[];
1726
+ count?: number;
1727
+ completable?: boolean;
1728
+ }
1729
+ interface RuntimeKvListOptions {
1730
+ reverse?: boolean;
1731
+ limit?: number;
1732
+ }
1733
+ interface RuntimeKvEntry {
1734
+ key: RuntimeBytes;
1735
+ value: RuntimeBytes;
1736
+ }
1737
+ type RuntimeSqlBindNoValues = {
1738
+ intValue?: never;
1739
+ floatValue?: never;
1740
+ textValue?: never;
1741
+ blobValue?: never;
1742
+ };
1743
+ type RuntimeSqlBindParam = ({
1744
+ kind: "null";
1745
+ } & RuntimeSqlBindNoValues) | {
1746
+ kind: "int";
1747
+ intValue: number;
1748
+ floatValue?: never;
1749
+ textValue?: never;
1750
+ blobValue?: never;
1751
+ } | {
1752
+ kind: "float";
1753
+ intValue?: never;
1754
+ floatValue: number;
1755
+ textValue?: never;
1756
+ blobValue?: never;
1757
+ } | {
1758
+ kind: "text";
1759
+ intValue?: never;
1760
+ floatValue?: never;
1761
+ textValue: string;
1762
+ blobValue?: never;
1763
+ } | {
1764
+ kind: "blob";
1765
+ intValue?: never;
1766
+ floatValue?: never;
1767
+ textValue?: never;
1768
+ blobValue: RuntimeBytes;
1769
+ };
1770
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
1771
+ interface RuntimeSqlQueryResult {
1772
+ columns: string[];
1773
+ rows: unknown[][];
1774
+ }
1775
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
1776
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
1777
+ changes: number;
1778
+ lastInsertRowId?: number | null;
1779
+ }
1780
+ interface RuntimeSqlRunResult {
1781
+ changes: number;
1782
+ }
1783
+ interface RuntimeActorConfig {
1784
+ name?: string;
1785
+ icon?: string;
1786
+ hasDatabase?: boolean;
1787
+ remoteSqlite?: boolean;
1788
+ hasState?: boolean;
1789
+ canHibernateWebsocket?: boolean;
1790
+ stateSaveIntervalMs?: number;
1791
+ createStateTimeoutMs?: number;
1792
+ onCreateTimeoutMs?: number;
1793
+ createVarsTimeoutMs?: number;
1794
+ createConnStateTimeoutMs?: number;
1795
+ onBeforeConnectTimeoutMs?: number;
1796
+ onConnectTimeoutMs?: number;
1797
+ onMigrateTimeoutMs?: number;
1798
+ onWakeTimeoutMs?: number;
1799
+ onBeforeActorStartTimeoutMs?: number;
1800
+ actionTimeoutMs?: number;
1801
+ onRequestTimeoutMs?: number;
1802
+ sleepTimeoutMs?: number;
1803
+ noSleep?: boolean;
1804
+ sleepGracePeriodMs?: number;
1805
+ connectionLivenessTimeoutMs?: number;
1806
+ connectionLivenessIntervalMs?: number;
1807
+ maxQueueSize?: number;
1808
+ maxQueueMessageSize?: number;
1809
+ maxIncomingMessageSize?: number;
1810
+ maxOutgoingMessageSize?: number;
1811
+ preloadMaxWorkflowBytes?: number;
1812
+ preloadMaxConnectionsBytes?: number;
1813
+ actions?: Array<{
1814
+ name: string;
1815
+ }>;
1816
+ inspectorTabs?: Array<RuntimeInspectorTabEntry>;
1817
+ }
1818
+ interface RuntimeInspectorTabEntry {
1819
+ id: string;
1820
+ /** Required for custom entries; omitted for built-in hides. */
1821
+ label?: string;
1822
+ /**
1823
+ * Required for custom entries — absolute path to the source directory.
1824
+ * Resolved on the TS side before being handed to the runtime.
1825
+ */
1826
+ source?: string;
1827
+ /** Optional icon id for custom entries. */
1828
+ icon?: string;
1829
+ /** Set to true for built-in hide entries. */
1830
+ hidden?: boolean;
1831
+ }
1832
+ interface RuntimeServeConfig {
1833
+ version: number;
1834
+ endpoint: string;
1835
+ token?: string;
1836
+ namespace: string;
1837
+ poolName: string;
1838
+ engineBinaryPath?: string;
1839
+ engineHost?: string;
1840
+ enginePort?: number;
1841
+ handleInspectorHttpInRuntime?: boolean;
1842
+ inspectorTestToken?: string;
1843
+ serverlessBasePath?: string;
1844
+ serverlessPackageVersion: string;
1845
+ serverlessClientEndpoint?: string;
1846
+ serverlessClientNamespace?: string;
1847
+ serverlessClientToken?: string;
1848
+ serverlessValidateEndpoint: boolean;
1849
+ serverlessMaxStartPayloadBytes: number;
1850
+ }
1851
+ interface RuntimeListenerConfig {
1852
+ port: number;
1853
+ host?: string;
1854
+ publicDir?: string;
1855
+ }
1856
+ interface RuntimeServerlessRequest {
1857
+ method: string;
1858
+ url: string;
1859
+ headers: Record<string, string>;
1860
+ body: RuntimeBytes;
1861
+ }
1862
+ interface RuntimeServerlessResponseHead {
1863
+ status: number;
1864
+ headers: Record<string, string>;
1865
+ }
1866
+ interface RuntimeRegistryRouteResponse {
1867
+ status: number;
1868
+ headers: Record<string, string>;
1869
+ body: RuntimeBytes;
1870
+ }
1871
+ type RuntimeServerlessStreamEvent = {
1872
+ kind: "chunk";
1873
+ chunk?: RuntimeBytes;
1874
+ } | {
1875
+ kind: "end";
1876
+ error?: {
1877
+ group: string;
1878
+ code: string;
1879
+ message: string;
1880
+ };
1881
+ };
1882
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
1883
+ type RuntimeWebSocketEvent = {
1884
+ kind: "message";
1885
+ data: string | RuntimeBytes;
1886
+ binary: boolean;
1887
+ messageIndex?: number;
1888
+ } | {
1889
+ kind: "close";
1890
+ code: number;
1891
+ reason: string;
1892
+ wasClean: boolean;
1893
+ };
1894
+ interface CoreRuntime {
1895
+ readonly kind: "napi" | "wasm";
1896
+ createRegistry(): RegistryHandle;
1897
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
1898
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
1899
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
1900
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
1901
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
1902
+ serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
1903
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1904
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1905
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1906
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
1907
+ createCancellationToken(): CancellationTokenHandle;
1908
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
1909
+ cancelCancellationToken(token: CancellationTokenHandle): void;
1910
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
1911
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
1912
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
1913
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
1914
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
1915
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
1916
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
1917
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
1918
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
1919
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
1920
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
1921
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
1922
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
1923
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
1924
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
1925
+ actorId(ctx: ActorContextHandle): string;
1926
+ actorName(ctx: ActorContextHandle): string;
1927
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
1928
+ actorRegion(ctx: ActorContextHandle): string;
1929
+ actorSleep(ctx: ActorContextHandle): void;
1930
+ actorDestroy(ctx: ActorContextHandle): void;
1931
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
1932
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
1933
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
1934
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
1935
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1936
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
1937
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
1938
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1939
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
1940
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
1941
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1942
+ actorRuntimeState(ctx: ActorContextHandle): object;
1943
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
1944
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
1945
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
1946
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
1947
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
1948
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
1949
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
1950
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
1951
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1952
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1953
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
1954
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
1955
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
1956
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
1957
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
1958
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
1959
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
1960
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
1961
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
1962
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
1963
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
1964
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
1965
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
1966
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
1967
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
1968
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
1969
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
1970
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
1971
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
1972
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
1973
+ connId(conn: ConnHandle): string;
1974
+ connParams(conn: ConnHandle): RuntimeBytes;
1975
+ connState(conn: ConnHandle): RuntimeBytes;
1976
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
1977
+ connIsHibernatable(conn: ConnHandle): boolean;
1978
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
1979
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
1980
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
1981
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
1982
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
1983
+ }
1984
+
1985
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
1986
+ runtime: CoreRuntime;
1987
+ registry: RegistryHandle;
1988
+ serveConfig: RuntimeServeConfig;
1989
+ }>;
1990
+
1597
1991
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
1598
1992
  interface ServerlessHandler {
1599
1993
  fetch: FetchHandler;
@@ -1603,12 +1997,20 @@ interface RegistryRoutes {
1603
1997
  metadata(): Promise<Response>;
1604
1998
  prometheusMetrics(request?: Request): Promise<Response>;
1605
1999
  }
2000
+ /**
2001
+ * Injectable dependencies for {@link Registry}. Production code uses the
2002
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
2003
+ * orchestration against a fake `CoreRuntime` without an engine.
2004
+ */
2005
+ interface RegistryDeps {
2006
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
2007
+ }
1606
2008
  declare class Registry<A extends RegistryActors> {
1607
2009
  #private;
1608
2010
  readonly routes: RegistryRoutes;
1609
2011
  get config(): RegistryConfigInput<A>;
1610
2012
  parseConfig(): RegistryConfig;
1611
- constructor(config: RegistryConfigInput<A>);
2013
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
1612
2014
  /**
1613
2015
  * Handle an incoming HTTP request for serverless deployments.
1614
2016
  *
@@ -1629,10 +2031,57 @@ declare class Registry<A extends RegistryActors> {
1629
2031
  * ```
1630
2032
  */
1631
2033
  serve(): ServerlessHandler;
2034
+ /**
2035
+ * Bind an HTTP listener provided by the native (Rust) runtime and serve
2036
+ * the registry's serverless endpoints over it. Resolves only after the
2037
+ * registry is shut down (SIGINT/SIGTERM or `nativeRegistry.shutdown()`).
2038
+ *
2039
+ * @param opts.port Port to listen on. Defaults to `process.env.RIVET_PORT`
2040
+ * if set, otherwise 3000.
2041
+ * @param opts.host Address to bind. Defaults to `0.0.0.0`.
2042
+ * @param opts.publicDir If set, serves static files from this directory
2043
+ * as a fallback below the framework routes.
2044
+ *
2045
+ * @example
2046
+ * ```ts
2047
+ * await registry.listen();
2048
+ * await registry.listen({ port: 8080, publicDir: "./public" });
2049
+ * ```
2050
+ */
2051
+ listen(opts?: {
2052
+ port?: number;
2053
+ host?: string;
2054
+ publicDir?: string;
2055
+ }): Promise<void>;
2056
+ /**
2057
+ * Gracefully drains all live registries.
2058
+ *
2059
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
2060
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
2061
+ * waits for the serve promise to resolve, all bounded by the shutdown
2062
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
2063
+ * signal or exit the process. The caller owns process lifetime.
2064
+ *
2065
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
2066
+ * call even if nothing has been started.
2067
+ *
2068
+ * @example
2069
+ * ```ts
2070
+ * const registry = setup({ use: { counter } });
2071
+ * registry.start();
2072
+ * // ...later, on your own shutdown trigger:
2073
+ * await registry.shutdown();
2074
+ * ```
2075
+ */
2076
+ shutdown(): Promise<void>;
1632
2077
  startEnvoy(): void;
1633
2078
  /**
1634
2079
  * Starts the actor envoy for standalone server deployments.
1635
2080
  *
2081
+ * Set `RIVETKIT_RUNTIME_MODE=serverless` to instead bind an HTTP listener
2082
+ * via `listen()` (Mode B). Mode A (envoy) and Mode B (listener) are
2083
+ * mutually exclusive per registry instance.
2084
+ *
1636
2085
  * @example
1637
2086
  * ```ts
1638
2087
  * const registry = setup({ use: { counter } });