rivetkit 2.3.0-rc.10 → 2.3.0-rc.12

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 (205) hide show
  1. package/dist/browser/client.d.ts +448 -62
  2. package/dist/browser/client.js +131 -89
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +40 -20
  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.js +1 -1
  8. package/dist/tsup/agent-os/index.cjs +2103 -2090
  9. package/dist/tsup/agent-os/index.cjs.map +1 -1
  10. package/dist/tsup/agent-os/index.d.cts +446 -69
  11. package/dist/tsup/agent-os/index.d.ts +446 -69
  12. package/dist/tsup/agent-os/index.js +2102 -2089
  13. package/dist/tsup/agent-os/index.js.map +1 -1
  14. package/dist/tsup/{chunk-TE4VCDNY.cjs → chunk-2U6RLFKX.cjs} +219 -234
  15. package/dist/tsup/chunk-2U6RLFKX.cjs.map +1 -0
  16. package/dist/tsup/{chunk-4K3MV2MW.cjs → chunk-2ZTBRZRS.cjs} +10 -10
  17. package/dist/tsup/chunk-2ZTBRZRS.cjs.map +1 -0
  18. package/dist/tsup/{chunk-KU6VKVEK.js → chunk-3EVVOYFD.js} +19 -7
  19. package/dist/tsup/chunk-3EVVOYFD.js.map +1 -0
  20. package/dist/tsup/{chunk-3LGP4JSO.cjs → chunk-6KTMKPNU.cjs} +8 -8
  21. package/dist/tsup/{chunk-3LGP4JSO.cjs.map → chunk-6KTMKPNU.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-WU2O2KIE.js → chunk-7UZF56RS.js} +63 -78
  23. package/dist/tsup/chunk-7UZF56RS.js.map +1 -0
  24. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-BRP62GZC.js} +3 -3
  25. package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
  26. package/dist/tsup/{chunk-G5RULGYQ.cjs → chunk-C7AAIILH.cjs} +24 -9
  27. package/dist/tsup/chunk-C7AAIILH.cjs.map +1 -0
  28. package/dist/tsup/{chunk-XV52XUWU.js → chunk-EWVOWEMD.js} +4 -4
  29. package/dist/tsup/chunk-EWVOWEMD.js.map +1 -0
  30. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  31. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  32. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  33. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  34. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-KORQB2IR.cjs} +3 -3
  35. package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
  36. package/dist/tsup/{chunk-CMYS77J6.js → chunk-OLIJHKLL.js} +3 -3
  37. package/dist/tsup/{chunk-BM3EOY7M.js → chunk-OOB32JVG.js} +134 -20
  38. package/dist/tsup/chunk-OOB32JVG.js.map +1 -0
  39. package/dist/tsup/{chunk-G34LIR7S.js → chunk-QKSGGKGQ.js} +22 -7
  40. package/dist/tsup/chunk-QKSGGKGQ.js.map +1 -0
  41. package/dist/tsup/{chunk-PWFGP2US.cjs → chunk-SS56HFM2.cjs} +138 -24
  42. package/dist/tsup/chunk-SS56HFM2.cjs.map +1 -0
  43. package/dist/tsup/{chunk-Z4C3W2CQ.cjs → chunk-UETC5RF7.cjs} +3 -3
  44. package/dist/tsup/{chunk-Z4C3W2CQ.cjs.map → chunk-UETC5RF7.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  46. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  47. package/dist/tsup/{chunk-6BI2MS3S.js → chunk-VLXRFJ7P.js} +2 -2
  48. package/dist/tsup/{chunk-J5P6S2LC.cjs → chunk-VNMIAPPF.cjs} +26 -14
  49. package/dist/tsup/chunk-VNMIAPPF.cjs.map +1 -0
  50. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-WHYBAEWG.cjs} +4 -2
  51. package/dist/tsup/chunk-WHYBAEWG.cjs.map +1 -0
  52. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-WIMUFZVJ.js} +3 -1
  53. package/dist/tsup/chunk-WIMUFZVJ.js.map +1 -0
  54. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  55. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  56. package/dist/tsup/client/mod.cjs +9 -9
  57. package/dist/tsup/client/mod.d.cts +4 -4
  58. package/dist/tsup/client/mod.d.ts +4 -4
  59. package/dist/tsup/client/mod.js +8 -8
  60. package/dist/tsup/common/log.cjs +3 -3
  61. package/dist/tsup/common/log.js +2 -2
  62. package/dist/tsup/common/websocket.cjs +4 -4
  63. package/dist/tsup/common/websocket.js +3 -3
  64. package/dist/tsup/{config-Ca8dN4cS.d.cts → config-BtAh7oBu.d.cts} +409 -22
  65. package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.cts} +1 -2
  66. package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.ts} +1 -2
  67. package/dist/tsup/{config-0Ta55UV0.d.ts → config-DKgPGC0f.d.ts} +409 -22
  68. package/dist/tsup/{context-B_IWbWne.d.ts → context-C-6dGebY.d.ts} +8 -8
  69. package/dist/tsup/{context-CUrQ9MHc.d.cts → context-Cfjl5pgz.d.cts} +8 -8
  70. package/dist/tsup/db/drizzle.cjs +3 -3
  71. package/dist/tsup/db/drizzle.d.cts +1 -1
  72. package/dist/tsup/db/drizzle.d.ts +1 -1
  73. package/dist/tsup/db/drizzle.js +1 -1
  74. package/dist/tsup/db/mod.cjs +2 -2
  75. package/dist/tsup/db/mod.d.cts +2 -2
  76. package/dist/tsup/db/mod.d.ts +2 -2
  77. package/dist/tsup/db/mod.js +1 -1
  78. package/dist/tsup/dynamic/mod.cjs +24 -0
  79. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  80. package/dist/tsup/dynamic/mod.d.cts +37 -0
  81. package/dist/tsup/dynamic/mod.d.ts +37 -0
  82. package/dist/tsup/dynamic/mod.js +24 -0
  83. package/dist/tsup/dynamic/mod.js.map +1 -0
  84. package/dist/tsup/inspector/mod.cjs +6 -6
  85. package/dist/tsup/inspector/mod.js +5 -5
  86. package/dist/tsup/mod.cjs +606 -325
  87. package/dist/tsup/mod.cjs.map +1 -1
  88. package/dist/tsup/mod.d.cts +4 -4
  89. package/dist/tsup/mod.d.ts +4 -4
  90. package/dist/tsup/mod.js +510 -229
  91. package/dist/tsup/mod.js.map +1 -1
  92. package/dist/tsup/test/mod.cjs +21 -18
  93. package/dist/tsup/test/mod.cjs.map +1 -1
  94. package/dist/tsup/test/mod.d.cts +3 -3
  95. package/dist/tsup/test/mod.d.ts +3 -3
  96. package/dist/tsup/test/mod.js +18 -15
  97. package/dist/tsup/test/mod.js.map +1 -1
  98. package/dist/tsup/utils.cjs +3 -3
  99. package/dist/tsup/utils.d.cts +1 -1
  100. package/dist/tsup/utils.d.ts +1 -1
  101. package/dist/tsup/utils.js +2 -2
  102. package/dist/tsup/workflow/mod.cjs +307 -282
  103. package/dist/tsup/workflow/mod.cjs.map +1 -1
  104. package/dist/tsup/workflow/mod.d.cts +5 -5
  105. package/dist/tsup/workflow/mod.d.ts +5 -5
  106. package/dist/tsup/workflow/mod.js +501 -476
  107. package/dist/tsup/workflow/mod.js.map +1 -1
  108. package/package.json +22 -11
  109. package/src/actor/config.ts +68 -51
  110. package/src/actor/contexts/index.ts +7 -2
  111. package/src/actor/definition.ts +17 -19
  112. package/src/actor/driver.ts +3 -3
  113. package/src/actor/errors.ts +9 -3
  114. package/src/actor/instance/mod.ts +22 -30
  115. package/src/actor/keys.ts +1 -1
  116. package/src/actor/mod.ts +20 -20
  117. package/src/actor/schema.ts +2 -2
  118. package/src/agent-os/actor/index.ts +38 -18
  119. package/src/agent-os/actor/preview.ts +1 -2
  120. package/src/agent-os/actor/session.ts +2 -2
  121. package/src/agent-os/config.ts +1 -1
  122. package/src/agent-os/fs/database-vfs.ts +1 -1
  123. package/src/agent-os/index.ts +16 -15
  124. package/src/client/actor-common.ts +87 -54
  125. package/src/client/actor-conn.ts +8 -36
  126. package/src/client/actor-handle.ts +69 -51
  127. package/src/client/actor-query.ts +5 -5
  128. package/src/client/errors.ts +1 -1
  129. package/src/client/lifecycle-errors.ts +2 -4
  130. package/src/client/query.ts +1 -1
  131. package/src/client/queue.ts +8 -3
  132. package/src/client/raw-utils.ts +8 -6
  133. package/src/client/resolve-gateway-target.ts +1 -1
  134. package/src/client/utils.ts +2 -7
  135. package/src/common/actor-websocket.ts +3 -1
  136. package/src/common/bare/actor-persist/v1.ts +205 -163
  137. package/src/common/bare/actor-persist/v2.ts +265 -213
  138. package/src/common/bare/actor-persist/v3.ts +176 -172
  139. package/src/common/bare/actor-persist/v4.ts +254 -253
  140. package/src/common/bare/transport/v1.ts +659 -543
  141. package/src/common/client-protocol-versioned.ts +66 -64
  142. package/src/common/database/config.ts +2 -8
  143. package/src/common/database/native-database.ts +1 -1
  144. package/src/common/database/shared.ts +1 -0
  145. package/src/common/encoding.ts +250 -16
  146. package/src/common/eventsource.ts +1 -1
  147. package/src/common/inline-websocket-adapter.ts +14 -13
  148. package/src/common/log.ts +1 -0
  149. package/src/common/router.ts +13 -17
  150. package/src/common/utils.ts +1 -150
  151. package/src/common/websocket-interface.ts +1 -1
  152. package/src/db/mod.ts +1 -1
  153. package/src/drivers/engine/actor-driver.ts +58 -56
  154. package/src/dynamic/instance.ts +32 -0
  155. package/src/dynamic/internal.ts +50 -0
  156. package/src/dynamic/isolate-runtime.ts +66 -0
  157. package/src/dynamic/mod.ts +32 -0
  158. package/src/engine-client/actor-http-client.ts +1 -1
  159. package/src/engine-client/actor-websocket-client.ts +6 -5
  160. package/src/engine-client/api-endpoints.ts +51 -2
  161. package/src/engine-client/api-utils.ts +2 -2
  162. package/src/engine-client/driver.ts +1 -1
  163. package/src/engine-client/mod.ts +6 -3
  164. package/src/engine-client/ws-proxy.ts +4 -4
  165. package/src/inspector/client.browser.ts +5 -11
  166. package/src/inspector/mod.ts +1 -3
  167. package/src/registry/config/envoy.ts +1 -2
  168. package/src/registry/config/index.ts +3 -9
  169. package/src/registry/index.ts +150 -72
  170. package/src/registry/napi-runtime.ts +13 -2
  171. package/src/registry/native-validation.ts +10 -12
  172. package/src/registry/native.ts +231 -173
  173. package/src/registry/process-metrics.ts +250 -0
  174. package/src/registry/runtime.ts +4 -0
  175. package/src/registry/wasm-runtime.ts +18 -2
  176. package/src/registry/write-through-proxy.ts +40 -0
  177. package/src/serde.ts +2 -2
  178. package/src/serverless/configure.ts +18 -7
  179. package/src/test/mod.ts +11 -8
  180. package/src/utils/endpoint-parser.ts +1 -1
  181. package/src/utils/router.ts +1 -1
  182. package/src/utils/serve.ts +4 -5
  183. package/src/utils.ts +1 -2
  184. package/src/workflow/context.ts +61 -33
  185. package/src/workflow/driver.ts +4 -6
  186. package/src/workflow/inspector.ts +4 -3
  187. package/src/workflow/mod.ts +15 -17
  188. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  189. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  190. package/dist/tsup/chunk-4K3MV2MW.cjs.map +0 -1
  191. package/dist/tsup/chunk-BM3EOY7M.js.map +0 -1
  192. package/dist/tsup/chunk-G34LIR7S.js.map +0 -1
  193. package/dist/tsup/chunk-G5RULGYQ.cjs.map +0 -1
  194. package/dist/tsup/chunk-J5P6S2LC.cjs.map +0 -1
  195. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  196. package/dist/tsup/chunk-KU6VKVEK.js.map +0 -1
  197. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  198. package/dist/tsup/chunk-PWFGP2US.cjs.map +0 -1
  199. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  200. package/dist/tsup/chunk-TE4VCDNY.cjs.map +0 -1
  201. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  202. package/dist/tsup/chunk-WU2O2KIE.js.map +0 -1
  203. package/dist/tsup/chunk-XV52XUWU.js.map +0 -1
  204. /package/dist/tsup/{chunk-CMYS77J6.js.map → chunk-OLIJHKLL.js.map} +0 -0
  205. /package/dist/tsup/{chunk-6BI2MS3S.js.map → chunk-VLXRFJ7P.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;
@@ -1037,7 +1059,7 @@ interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1037
1059
  iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
1038
1060
  [key: string]: any;
1039
1061
  }
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>> {
1062
+ 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
1063
  id: string;
1042
1064
  params: TConnParams;
1043
1065
  state: TConnState;
@@ -1048,6 +1070,8 @@ interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TV
1048
1070
  }
1049
1071
  interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1050
1072
  [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
1073
+ /** Returns the raw unwrapped state without the write-through proxy. */
1074
+ [RAW_STATE_SYMBOL](): TState;
1051
1075
  state: TState;
1052
1076
  vars: TVars;
1053
1077
  readonly kv: ActorKv;
@@ -1175,7 +1199,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1175
1199
  preloadMaxConnectionsBytes: z.ZodOptional<z.ZodNumber>;
1176
1200
  }, z.core.$strict>>;
1177
1201
  }, z.core.$strict>;
1178
- type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1202
+ type CreateState<TState, _TConnParams, _TConnState, _TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1179
1203
  state: TState;
1180
1204
  } | {
1181
1205
  createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
@@ -1188,7 +1212,7 @@ type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase e
1188
1212
  /**
1189
1213
  * @experimental
1190
1214
  */
1191
- type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1215
+ type CreateVars<TState, _TConnParams, _TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1192
1216
  /**
1193
1217
  * @experimental
1194
1218
  */
@@ -1374,19 +1398,21 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1374
1398
  */
1375
1399
  db: TDatabase;
1376
1400
  } | 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>;
1401
+ 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
1402
 
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>;
1403
+ 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>> {
1404
+ readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
1405
+ }
1406
+ interface AnyActorDefinition {
1407
+ readonly config: any;
1381
1408
  }
1382
- type AnyActorDefinition = BaseActorDefinition<any, any, any, any, any, any, any, any, any>;
1383
1409
  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
1410
  #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>;
1411
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>);
1412
+ get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
1387
1413
  }
1388
1414
 
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>>>;
1415
+ declare const ActorsSchema: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
1390
1416
  type RegistryActors = z$2.infer<typeof ActorsSchema>;
1391
1417
  declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1392
1418
  use: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
@@ -1406,7 +1432,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1406
1432
  }>>, z$2.ZodTransform<"auto" | "native" | "wasm", "auto" | "native" | "wasm" | undefined>>;
1407
1433
  wasm: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1408
1434
  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>>;
1435
+ 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
1436
  }, z$2.core.$strip>>>;
1411
1437
  sqlite: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodUnion<readonly [z$2.ZodEnum<{
1412
1438
  local: "local";
@@ -1497,7 +1523,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1497
1523
  runtime: "auto" | "native" | "wasm";
1498
1524
  wasm: {
1499
1525
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1500
- initInput?: any;
1526
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1501
1527
  };
1502
1528
  noWelcome: boolean;
1503
1529
  logging: {
@@ -1542,7 +1568,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1542
1568
  runtime: "auto" | "native" | "wasm";
1543
1569
  wasm: {
1544
1570
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1545
- initInput?: any;
1571
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1546
1572
  };
1547
1573
  sqlite: {
1548
1574
  backend: "local" | "remote";
@@ -1594,6 +1620,318 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1594
1620
  use: A;
1595
1621
  };
1596
1622
 
1623
+ declare const handleBrand: unique symbol;
1624
+ type OpaqueHandle<Name extends string> = {
1625
+ readonly [handleBrand]: Name;
1626
+ };
1627
+ type RegistryHandle = OpaqueHandle<"registry">;
1628
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
1629
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
1630
+ type ConnHandle = OpaqueHandle<"conn">;
1631
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
1632
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
1633
+ type RuntimeBytes = Uint8Array;
1634
+ interface RuntimeActorKeySegment {
1635
+ kind: string;
1636
+ stringValue?: string;
1637
+ numberValue?: number;
1638
+ }
1639
+ interface RuntimeHttpRequest {
1640
+ method: string;
1641
+ uri: string;
1642
+ headers?: Record<string, string>;
1643
+ body?: RuntimeBytes;
1644
+ }
1645
+ interface RuntimeStateDeltaPayload {
1646
+ state?: RuntimeBytes;
1647
+ connHibernation: Array<{
1648
+ connId: string;
1649
+ bytes: RuntimeBytes;
1650
+ }>;
1651
+ connHibernationRemoved: string[];
1652
+ }
1653
+ interface RuntimeRequestSaveOpts {
1654
+ immediate?: boolean;
1655
+ maxWaitMs?: number;
1656
+ }
1657
+ interface RuntimeInspectorSnapshot {
1658
+ stateRevision: number;
1659
+ connectionsRevision: number;
1660
+ queueRevision: number;
1661
+ activeConnections: number;
1662
+ queueSize: number;
1663
+ connectedClients: number;
1664
+ }
1665
+ interface RuntimeQueueMessage {
1666
+ id(): bigint;
1667
+ name(): string;
1668
+ body(): RuntimeBytes;
1669
+ createdAt(): number;
1670
+ isCompletable(): boolean;
1671
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
1672
+ }
1673
+ interface RuntimeQueueInspectMessage {
1674
+ id: number;
1675
+ name: string;
1676
+ createdAtMs: number;
1677
+ }
1678
+ interface RuntimeQueueNextBatchOptions {
1679
+ names?: string[];
1680
+ count?: number;
1681
+ timeoutMs?: number;
1682
+ completable?: boolean;
1683
+ }
1684
+ interface RuntimeQueueWaitOptions {
1685
+ timeoutMs?: number;
1686
+ completable?: boolean;
1687
+ }
1688
+ interface RuntimeQueueEnqueueAndWaitOptions {
1689
+ timeoutMs?: number;
1690
+ }
1691
+ interface RuntimeQueueTryNextBatchOptions {
1692
+ names?: string[];
1693
+ count?: number;
1694
+ completable?: boolean;
1695
+ }
1696
+ interface RuntimeKvListOptions {
1697
+ reverse?: boolean;
1698
+ limit?: number;
1699
+ }
1700
+ interface RuntimeKvEntry {
1701
+ key: RuntimeBytes;
1702
+ value: RuntimeBytes;
1703
+ }
1704
+ type RuntimeSqlBindNoValues = {
1705
+ intValue?: never;
1706
+ floatValue?: never;
1707
+ textValue?: never;
1708
+ blobValue?: never;
1709
+ };
1710
+ type RuntimeSqlBindParam = ({
1711
+ kind: "null";
1712
+ } & RuntimeSqlBindNoValues) | {
1713
+ kind: "int";
1714
+ intValue: number;
1715
+ floatValue?: never;
1716
+ textValue?: never;
1717
+ blobValue?: never;
1718
+ } | {
1719
+ kind: "float";
1720
+ intValue?: never;
1721
+ floatValue: number;
1722
+ textValue?: never;
1723
+ blobValue?: never;
1724
+ } | {
1725
+ kind: "text";
1726
+ intValue?: never;
1727
+ floatValue?: never;
1728
+ textValue: string;
1729
+ blobValue?: never;
1730
+ } | {
1731
+ kind: "blob";
1732
+ intValue?: never;
1733
+ floatValue?: never;
1734
+ textValue?: never;
1735
+ blobValue: RuntimeBytes;
1736
+ };
1737
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
1738
+ interface RuntimeSqlQueryResult {
1739
+ columns: string[];
1740
+ rows: unknown[][];
1741
+ }
1742
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
1743
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
1744
+ changes: number;
1745
+ lastInsertRowId?: number | null;
1746
+ }
1747
+ interface RuntimeSqlRunResult {
1748
+ changes: number;
1749
+ }
1750
+ interface RuntimeActorConfig {
1751
+ name?: string;
1752
+ icon?: string;
1753
+ hasDatabase?: boolean;
1754
+ remoteSqlite?: boolean;
1755
+ hasState?: boolean;
1756
+ canHibernateWebsocket?: boolean;
1757
+ stateSaveIntervalMs?: number;
1758
+ createStateTimeoutMs?: number;
1759
+ onCreateTimeoutMs?: number;
1760
+ createVarsTimeoutMs?: number;
1761
+ createConnStateTimeoutMs?: number;
1762
+ onBeforeConnectTimeoutMs?: number;
1763
+ onConnectTimeoutMs?: number;
1764
+ onMigrateTimeoutMs?: number;
1765
+ onWakeTimeoutMs?: number;
1766
+ onBeforeActorStartTimeoutMs?: number;
1767
+ actionTimeoutMs?: number;
1768
+ onRequestTimeoutMs?: number;
1769
+ sleepTimeoutMs?: number;
1770
+ noSleep?: boolean;
1771
+ sleepGracePeriodMs?: number;
1772
+ connectionLivenessTimeoutMs?: number;
1773
+ connectionLivenessIntervalMs?: number;
1774
+ maxQueueSize?: number;
1775
+ maxQueueMessageSize?: number;
1776
+ maxIncomingMessageSize?: number;
1777
+ maxOutgoingMessageSize?: number;
1778
+ preloadMaxWorkflowBytes?: number;
1779
+ preloadMaxConnectionsBytes?: number;
1780
+ actions?: Array<{
1781
+ name: string;
1782
+ }>;
1783
+ }
1784
+ interface RuntimeServeConfig {
1785
+ version: number;
1786
+ endpoint: string;
1787
+ token?: string;
1788
+ namespace: string;
1789
+ poolName: string;
1790
+ engineBinaryPath?: string;
1791
+ handleInspectorHttpInRuntime?: boolean;
1792
+ inspectorTestToken?: string;
1793
+ serverlessBasePath?: string;
1794
+ serverlessPackageVersion: string;
1795
+ serverlessClientEndpoint?: string;
1796
+ serverlessClientNamespace?: string;
1797
+ serverlessClientToken?: string;
1798
+ serverlessValidateEndpoint: boolean;
1799
+ serverlessMaxStartPayloadBytes: number;
1800
+ }
1801
+ interface RuntimeServerlessRequest {
1802
+ method: string;
1803
+ url: string;
1804
+ headers: Record<string, string>;
1805
+ body: RuntimeBytes;
1806
+ }
1807
+ interface RuntimeServerlessResponseHead {
1808
+ status: number;
1809
+ headers: Record<string, string>;
1810
+ }
1811
+ interface RuntimeRegistryRouteResponse {
1812
+ status: number;
1813
+ headers: Record<string, string>;
1814
+ body: RuntimeBytes;
1815
+ }
1816
+ type RuntimeServerlessStreamEvent = {
1817
+ kind: "chunk";
1818
+ chunk?: RuntimeBytes;
1819
+ } | {
1820
+ kind: "end";
1821
+ error?: {
1822
+ group: string;
1823
+ code: string;
1824
+ message: string;
1825
+ };
1826
+ };
1827
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
1828
+ type RuntimeWebSocketEvent = {
1829
+ kind: "message";
1830
+ data: string | RuntimeBytes;
1831
+ binary: boolean;
1832
+ messageIndex?: number;
1833
+ } | {
1834
+ kind: "close";
1835
+ code: number;
1836
+ reason: string;
1837
+ wasClean: boolean;
1838
+ };
1839
+ interface CoreRuntime {
1840
+ readonly kind: "napi" | "wasm";
1841
+ createRegistry(): RegistryHandle;
1842
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
1843
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
1844
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
1845
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
1846
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
1847
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1848
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1849
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1850
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
1851
+ createCancellationToken(): CancellationTokenHandle;
1852
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
1853
+ cancelCancellationToken(token: CancellationTokenHandle): void;
1854
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
1855
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
1856
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
1857
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
1858
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
1859
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
1860
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
1861
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
1862
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
1863
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
1864
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
1865
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
1866
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
1867
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
1868
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
1869
+ actorId(ctx: ActorContextHandle): string;
1870
+ actorName(ctx: ActorContextHandle): string;
1871
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
1872
+ actorRegion(ctx: ActorContextHandle): string;
1873
+ actorSleep(ctx: ActorContextHandle): void;
1874
+ actorDestroy(ctx: ActorContextHandle): void;
1875
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
1876
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
1877
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
1878
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
1879
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1880
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
1881
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
1882
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1883
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
1884
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
1885
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1886
+ actorRuntimeState(ctx: ActorContextHandle): object;
1887
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
1888
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
1889
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
1890
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
1891
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
1892
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
1893
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
1894
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
1895
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1896
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1897
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
1898
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
1899
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
1900
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
1901
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
1902
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
1903
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
1904
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
1905
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
1906
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
1907
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
1908
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
1909
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
1910
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
1911
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
1912
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
1913
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
1914
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
1915
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
1916
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
1917
+ connId(conn: ConnHandle): string;
1918
+ connParams(conn: ConnHandle): RuntimeBytes;
1919
+ connState(conn: ConnHandle): RuntimeBytes;
1920
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
1921
+ connIsHibernatable(conn: ConnHandle): boolean;
1922
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
1923
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
1924
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
1925
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
1926
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
1927
+ }
1928
+
1929
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
1930
+ runtime: CoreRuntime;
1931
+ registry: RegistryHandle;
1932
+ serveConfig: RuntimeServeConfig;
1933
+ }>;
1934
+
1597
1935
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
1598
1936
  interface ServerlessHandler {
1599
1937
  fetch: FetchHandler;
@@ -1603,12 +1941,20 @@ interface RegistryRoutes {
1603
1941
  metadata(): Promise<Response>;
1604
1942
  prometheusMetrics(request?: Request): Promise<Response>;
1605
1943
  }
1944
+ /**
1945
+ * Injectable dependencies for {@link Registry}. Production code uses the
1946
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
1947
+ * orchestration against a fake `CoreRuntime` without an engine.
1948
+ */
1949
+ interface RegistryDeps {
1950
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
1951
+ }
1606
1952
  declare class Registry<A extends RegistryActors> {
1607
1953
  #private;
1608
1954
  readonly routes: RegistryRoutes;
1609
1955
  get config(): RegistryConfigInput<A>;
1610
1956
  parseConfig(): RegistryConfig;
1611
- constructor(config: RegistryConfigInput<A>);
1957
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
1612
1958
  /**
1613
1959
  * Handle an incoming HTTP request for serverless deployments.
1614
1960
  *
@@ -1629,6 +1975,46 @@ declare class Registry<A extends RegistryActors> {
1629
1975
  * ```
1630
1976
  */
1631
1977
  serve(): ServerlessHandler;
1978
+ /**
1979
+ * Starts an HTTP server that dispatches every request through the
1980
+ * serverless handler. Uses `crossPlatformServe` to pick the right
1981
+ * runtime (Node, Bun, Deno).
1982
+ *
1983
+ * @param opts.port Port to listen on. Defaults to 3000.
1984
+ * @param opts.publicDir If set, serves static files from this directory
1985
+ * before falling through to the registry handler.
1986
+ *
1987
+ * @example
1988
+ * ```ts
1989
+ * await registry.listen();
1990
+ * await registry.listen({ port: 8080, publicDir: "./public" });
1991
+ * ```
1992
+ */
1993
+ listen(opts?: {
1994
+ port?: number;
1995
+ publicDir?: string;
1996
+ }): Promise<void>;
1997
+ /**
1998
+ * Gracefully drains all live registries.
1999
+ *
2000
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
2001
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
2002
+ * waits for the serve promise to resolve, all bounded by the shutdown
2003
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
2004
+ * signal or exit the process. The caller owns process lifetime.
2005
+ *
2006
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
2007
+ * call even if nothing has been started.
2008
+ *
2009
+ * @example
2010
+ * ```ts
2011
+ * const registry = setup({ use: { counter } });
2012
+ * registry.start();
2013
+ * // ...later, on your own shutdown trigger:
2014
+ * await registry.shutdown();
2015
+ * ```
2016
+ */
2017
+ shutdown(): Promise<void>;
1632
2018
  startEnvoy(): void;
1633
2019
  /**
1634
2020
  * Starts the actor envoy for standalone server deployments.