rivetkit 2.3.0-rc.9 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/dist/browser/client.d.ts +498 -62
  2. package/dist/browser/client.js +227 -171
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +50 -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.d.cts +1 -1
  8. package/dist/tsup/actor/errors.d.ts +1 -1
  9. package/dist/tsup/actor/errors.js +1 -1
  10. package/dist/tsup/agent-os/index.cjs +2163 -2087
  11. package/dist/tsup/agent-os/index.cjs.map +1 -1
  12. package/dist/tsup/agent-os/index.d.cts +496 -69
  13. package/dist/tsup/agent-os/index.d.ts +496 -69
  14. package/dist/tsup/agent-os/index.js +2163 -2087
  15. package/dist/tsup/agent-os/index.js.map +1 -1
  16. package/dist/tsup/{chunk-W7EYSYVI.js → chunk-2OTRTA3J.js} +134 -20
  17. package/dist/tsup/chunk-2OTRTA3J.js.map +1 -0
  18. package/dist/tsup/{chunk-VJFRBJVQ.cjs → chunk-3677IIOV.cjs} +138 -24
  19. package/dist/tsup/chunk-3677IIOV.cjs.map +1 -0
  20. package/dist/tsup/{chunk-4CGA6QJO.cjs → chunk-47HHIEXH.cjs} +24 -9
  21. package/dist/tsup/chunk-47HHIEXH.cjs.map +1 -0
  22. package/dist/tsup/{chunk-F3Q5BFQ6.js → chunk-4JDSFJS5.js} +66 -79
  23. package/dist/tsup/chunk-4JDSFJS5.js.map +1 -0
  24. package/dist/tsup/{chunk-GVTOE34S.cjs → chunk-7QKCIVAY.cjs} +222 -235
  25. package/dist/tsup/chunk-7QKCIVAY.cjs.map +1 -0
  26. package/dist/tsup/{chunk-CPA4Y3RG.cjs → chunk-B6VUNZUD.cjs} +10 -10
  27. package/dist/tsup/chunk-B6VUNZUD.cjs.map +1 -0
  28. package/dist/tsup/{chunk-H37XQU3I.js → chunk-BEI24WTI.js} +2 -2
  29. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-BRP62GZC.js} +3 -3
  30. package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
  31. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-DPIMKYNB.js} +63 -2
  32. package/dist/tsup/chunk-DPIMKYNB.js.map +1 -0
  33. package/dist/tsup/{chunk-Y5NSCZA2.cjs → chunk-DXXJPH55.cjs} +44 -15
  34. package/dist/tsup/chunk-DXXJPH55.cjs.map +1 -0
  35. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  36. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  37. package/dist/tsup/{chunk-4WPEZBK4.cjs → chunk-I4LN3FNT.cjs} +10 -10
  38. package/dist/tsup/chunk-I4LN3FNT.cjs.map +1 -0
  39. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  40. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  41. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-KORQB2IR.cjs} +3 -3
  42. package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
  43. package/dist/tsup/{chunk-MALSPBAF.cjs → chunk-LVTBW2RE.cjs} +3 -3
  44. package/dist/tsup/{chunk-MALSPBAF.cjs.map → chunk-LVTBW2RE.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-H7P7WR2Y.js → chunk-MEHBWPLJ.js} +6 -6
  46. package/dist/tsup/chunk-MEHBWPLJ.js.map +1 -0
  47. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-NIY3RSPX.cjs} +64 -3
  48. package/dist/tsup/chunk-NIY3RSPX.cjs.map +1 -0
  49. package/dist/tsup/{chunk-MMMEZM5J.js → chunk-P2GNQ4RN.js} +4 -4
  50. package/dist/tsup/chunk-P2GNQ4RN.js.map +1 -0
  51. package/dist/tsup/{chunk-KJTA3ATT.js → chunk-UMZVD6DQ.js} +22 -7
  52. package/dist/tsup/chunk-UMZVD6DQ.js.map +1 -0
  53. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  54. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  55. package/dist/tsup/{chunk-VRCIXJRN.js → chunk-VTTFNQQI.js} +36 -7
  56. package/dist/tsup/chunk-VTTFNQQI.js.map +1 -0
  57. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  58. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  59. package/dist/tsup/client/mod.cjs +9 -9
  60. package/dist/tsup/client/mod.d.cts +5 -5
  61. package/dist/tsup/client/mod.d.ts +5 -5
  62. package/dist/tsup/client/mod.js +8 -8
  63. package/dist/tsup/common/log.cjs +3 -3
  64. package/dist/tsup/common/log.js +2 -2
  65. package/dist/tsup/common/websocket.cjs +4 -4
  66. package/dist/tsup/common/websocket.js +3 -3
  67. package/dist/tsup/{config-0Ta55UV0.d.ts → config-BxWAw3iH.d.ts} +529 -23
  68. package/dist/tsup/{config-Ca8dN4cS.d.cts → config-CZQQ-mso.d.cts} +529 -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/{context-B_IWbWne.d.ts → context-Bw7xq8w3.d.cts} +8 -8
  72. package/dist/tsup/{context-CUrQ9MHc.d.cts → context-D8QA76sV.d.ts} +8 -8
  73. package/dist/tsup/db/drizzle.cjs +3 -3
  74. package/dist/tsup/db/drizzle.d.cts +1 -1
  75. package/dist/tsup/db/drizzle.d.ts +1 -1
  76. package/dist/tsup/db/drizzle.js +1 -1
  77. package/dist/tsup/db/mod.cjs +2 -2
  78. package/dist/tsup/db/mod.d.cts +2 -2
  79. package/dist/tsup/db/mod.d.ts +2 -2
  80. package/dist/tsup/db/mod.js +1 -1
  81. package/dist/tsup/dynamic/mod.cjs +24 -0
  82. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  83. package/dist/tsup/dynamic/mod.d.cts +37 -0
  84. package/dist/tsup/dynamic/mod.d.ts +37 -0
  85. package/dist/tsup/dynamic/mod.js +24 -0
  86. package/dist/tsup/dynamic/mod.js.map +1 -0
  87. package/dist/tsup/inspector/mod.cjs +6 -6
  88. package/dist/tsup/inspector/mod.js +5 -5
  89. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  90. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  91. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  92. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  93. package/dist/tsup/inspector-tab/mod.js +173 -0
  94. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  95. package/dist/tsup/mod.cjs +730 -336
  96. package/dist/tsup/mod.cjs.map +1 -1
  97. package/dist/tsup/mod.d.cts +5 -5
  98. package/dist/tsup/mod.d.ts +5 -5
  99. package/dist/tsup/mod.js +633 -239
  100. package/dist/tsup/mod.js.map +1 -1
  101. package/dist/tsup/test/mod.cjs +21 -18
  102. package/dist/tsup/test/mod.cjs.map +1 -1
  103. package/dist/tsup/test/mod.d.cts +4 -4
  104. package/dist/tsup/test/mod.d.ts +4 -4
  105. package/dist/tsup/test/mod.js +18 -15
  106. package/dist/tsup/test/mod.js.map +1 -1
  107. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-DQosb24I.d.cts} +1 -1
  108. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-DQosb24I.d.ts} +1 -1
  109. package/dist/tsup/utils.cjs +3 -3
  110. package/dist/tsup/utils.d.cts +1 -1
  111. package/dist/tsup/utils.d.ts +1 -1
  112. package/dist/tsup/utils.js +2 -2
  113. package/dist/tsup/workflow/mod.cjs +307 -282
  114. package/dist/tsup/workflow/mod.cjs.map +1 -1
  115. package/dist/tsup/workflow/mod.d.cts +6 -6
  116. package/dist/tsup/workflow/mod.d.ts +6 -6
  117. package/dist/tsup/workflow/mod.js +501 -476
  118. package/dist/tsup/workflow/mod.js.map +1 -1
  119. package/package.json +32 -11
  120. package/src/actor/config.ts +159 -51
  121. package/src/actor/contexts/index.ts +7 -2
  122. package/src/actor/definition.ts +17 -19
  123. package/src/actor/driver.ts +3 -3
  124. package/src/actor/errors.ts +9 -3
  125. package/src/actor/instance/mod.ts +26 -34
  126. package/src/actor/keys.ts +1 -1
  127. package/src/actor/mod.ts +22 -20
  128. package/src/actor/schema.ts +2 -2
  129. package/src/agent-os/actor/index.ts +38 -18
  130. package/src/agent-os/actor/preview.ts +1 -2
  131. package/src/agent-os/actor/session.ts +2 -2
  132. package/src/agent-os/config.ts +1 -1
  133. package/src/agent-os/fs/database-vfs.ts +1 -1
  134. package/src/agent-os/index.ts +16 -15
  135. package/src/client/actor-common.ts +87 -54
  136. package/src/client/actor-conn.ts +8 -36
  137. package/src/client/actor-handle.ts +69 -51
  138. package/src/client/actor-query.ts +5 -5
  139. package/src/client/errors.ts +1 -1
  140. package/src/client/lifecycle-errors.ts +2 -4
  141. package/src/client/query.ts +1 -1
  142. package/src/client/queue.ts +8 -3
  143. package/src/client/raw-utils.ts +8 -6
  144. package/src/client/resolve-gateway-target.ts +1 -1
  145. package/src/client/utils.ts +2 -7
  146. package/src/common/actor-websocket.ts +3 -1
  147. package/src/common/bare/actor-persist/v1.ts +205 -163
  148. package/src/common/bare/actor-persist/v2.ts +265 -213
  149. package/src/common/bare/actor-persist/v3.ts +176 -172
  150. package/src/common/bare/actor-persist/v4.ts +254 -253
  151. package/src/common/bare/transport/v1.ts +659 -543
  152. package/src/common/client-protocol-versioned.ts +66 -64
  153. package/src/common/database/config.ts +2 -8
  154. package/src/common/database/native-database.ts +1 -1
  155. package/src/common/database/shared.ts +1 -0
  156. package/src/common/encoding.ts +250 -16
  157. package/src/common/engine.ts +28 -1
  158. package/src/common/eventsource.ts +1 -1
  159. package/src/common/inline-websocket-adapter.ts +14 -13
  160. package/src/common/log.ts +1 -0
  161. package/src/common/router.ts +13 -17
  162. package/src/common/utils.ts +1 -150
  163. package/src/common/websocket-interface.ts +1 -1
  164. package/src/db/mod.ts +1 -1
  165. package/src/devtools-loader/index.ts +4 -7
  166. package/src/devtools-loader/serve-devtools.ts +26 -0
  167. package/src/drivers/engine/actor-driver.ts +58 -56
  168. package/src/dynamic/instance.ts +32 -0
  169. package/src/dynamic/internal.ts +50 -0
  170. package/src/dynamic/isolate-runtime.ts +66 -0
  171. package/src/dynamic/mod.ts +32 -0
  172. package/src/engine-client/actor-http-client.ts +3 -3
  173. package/src/engine-client/actor-websocket-client.ts +6 -5
  174. package/src/engine-client/api-endpoints.ts +51 -2
  175. package/src/engine-client/api-utils.ts +2 -2
  176. package/src/engine-client/driver.ts +1 -1
  177. package/src/engine-client/mod.ts +6 -3
  178. package/src/engine-client/ws-proxy.ts +9 -4
  179. package/src/inspector/client.browser.ts +5 -11
  180. package/src/inspector/mod.ts +1 -3
  181. package/src/inspector-tab/mod.ts +315 -0
  182. package/src/registry/config/envoy.ts +1 -2
  183. package/src/registry/config/index.ts +40 -16
  184. package/src/registry/index.ts +154 -74
  185. package/src/registry/napi-runtime.ts +13 -2
  186. package/src/registry/native-validation.ts +10 -12
  187. package/src/registry/native.ts +367 -181
  188. package/src/registry/process-metrics.ts +250 -0
  189. package/src/registry/runtime.ts +41 -1
  190. package/src/registry/wasm-runtime.ts +18 -2
  191. package/src/registry/write-through-proxy.ts +40 -0
  192. package/src/serde.ts +2 -2
  193. package/src/serverless/configure.ts +18 -7
  194. package/src/test/mod.ts +11 -8
  195. package/src/utils/endpoint-parser.ts +1 -1
  196. package/src/utils/env-vars.ts +6 -0
  197. package/src/utils/router.ts +1 -1
  198. package/src/utils/serve.ts +4 -5
  199. package/src/utils.ts +1 -2
  200. package/src/workflow/context.ts +61 -33
  201. package/src/workflow/driver.ts +4 -6
  202. package/src/workflow/inspector.ts +4 -3
  203. package/src/workflow/mod.ts +15 -17
  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-T6YVRM4K.js.map +0 -1
  217. package/dist/tsup/chunk-VJFRBJVQ.cjs.map +0 -1
  218. package/dist/tsup/chunk-VRCIXJRN.js.map +0 -1
  219. package/dist/tsup/chunk-W7EYSYVI.js.map +0 -1
  220. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  221. package/dist/tsup/chunk-Y5NSCZA2.cjs.map +0 -1
  222. /package/dist/tsup/{chunk-H37XQU3I.js.map → chunk-BEI24WTI.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 ? {
422
+ send: ActorQueueSend<Q>;
423
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
413
424
  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 ? {
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 ? {
434
+ on: ActorEventSubscribe<E>;
435
+ once: ActorEventSubscribe<E>;
436
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
416
437
  on: ActorEventSubscribe<E>;
417
438
  once: ActorEventSubscribe<E>;
418
- } : never : never;
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
+ queue: "queue";
1220
+ workflow: "workflow";
1221
+ database: "database";
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,335 @@ 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 RuntimeServerlessRequest {
1852
+ method: string;
1853
+ url: string;
1854
+ headers: Record<string, string>;
1855
+ body: RuntimeBytes;
1856
+ }
1857
+ interface RuntimeServerlessResponseHead {
1858
+ status: number;
1859
+ headers: Record<string, string>;
1860
+ }
1861
+ interface RuntimeRegistryRouteResponse {
1862
+ status: number;
1863
+ headers: Record<string, string>;
1864
+ body: RuntimeBytes;
1865
+ }
1866
+ type RuntimeServerlessStreamEvent = {
1867
+ kind: "chunk";
1868
+ chunk?: RuntimeBytes;
1869
+ } | {
1870
+ kind: "end";
1871
+ error?: {
1872
+ group: string;
1873
+ code: string;
1874
+ message: string;
1875
+ };
1876
+ };
1877
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
1878
+ type RuntimeWebSocketEvent = {
1879
+ kind: "message";
1880
+ data: string | RuntimeBytes;
1881
+ binary: boolean;
1882
+ messageIndex?: number;
1883
+ } | {
1884
+ kind: "close";
1885
+ code: number;
1886
+ reason: string;
1887
+ wasClean: boolean;
1888
+ };
1889
+ interface CoreRuntime {
1890
+ readonly kind: "napi" | "wasm";
1891
+ createRegistry(): RegistryHandle;
1892
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
1893
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
1894
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
1895
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
1896
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
1897
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1898
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1899
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1900
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
1901
+ createCancellationToken(): CancellationTokenHandle;
1902
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
1903
+ cancelCancellationToken(token: CancellationTokenHandle): void;
1904
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
1905
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
1906
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
1907
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
1908
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
1909
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
1910
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
1911
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
1912
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
1913
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
1914
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
1915
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
1916
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
1917
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
1918
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
1919
+ actorId(ctx: ActorContextHandle): string;
1920
+ actorName(ctx: ActorContextHandle): string;
1921
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
1922
+ actorRegion(ctx: ActorContextHandle): string;
1923
+ actorSleep(ctx: ActorContextHandle): void;
1924
+ actorDestroy(ctx: ActorContextHandle): void;
1925
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
1926
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
1927
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
1928
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
1929
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1930
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
1931
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
1932
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1933
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
1934
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
1935
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1936
+ actorRuntimeState(ctx: ActorContextHandle): object;
1937
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
1938
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
1939
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
1940
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
1941
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
1942
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
1943
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
1944
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
1945
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1946
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1947
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
1948
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
1949
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
1950
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
1951
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
1952
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
1953
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
1954
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
1955
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
1956
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
1957
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
1958
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
1959
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
1960
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
1961
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
1962
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
1963
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
1964
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
1965
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
1966
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
1967
+ connId(conn: ConnHandle): string;
1968
+ connParams(conn: ConnHandle): RuntimeBytes;
1969
+ connState(conn: ConnHandle): RuntimeBytes;
1970
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
1971
+ connIsHibernatable(conn: ConnHandle): boolean;
1972
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
1973
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
1974
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
1975
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
1976
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
1977
+ }
1978
+
1979
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
1980
+ runtime: CoreRuntime;
1981
+ registry: RegistryHandle;
1982
+ serveConfig: RuntimeServeConfig;
1983
+ }>;
1984
+
1597
1985
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
1598
1986
  interface ServerlessHandler {
1599
1987
  fetch: FetchHandler;
@@ -1603,12 +1991,20 @@ interface RegistryRoutes {
1603
1991
  metadata(): Promise<Response>;
1604
1992
  prometheusMetrics(request?: Request): Promise<Response>;
1605
1993
  }
1994
+ /**
1995
+ * Injectable dependencies for {@link Registry}. Production code uses the
1996
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
1997
+ * orchestration against a fake `CoreRuntime` without an engine.
1998
+ */
1999
+ interface RegistryDeps {
2000
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
2001
+ }
1606
2002
  declare class Registry<A extends RegistryActors> {
1607
2003
  #private;
1608
2004
  readonly routes: RegistryRoutes;
1609
2005
  get config(): RegistryConfigInput<A>;
1610
2006
  parseConfig(): RegistryConfig;
1611
- constructor(config: RegistryConfigInput<A>);
2007
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
1612
2008
  /**
1613
2009
  * Handle an incoming HTTP request for serverless deployments.
1614
2010
  *
@@ -1629,6 +2025,46 @@ declare class Registry<A extends RegistryActors> {
1629
2025
  * ```
1630
2026
  */
1631
2027
  serve(): ServerlessHandler;
2028
+ /**
2029
+ * Starts an HTTP server that dispatches every request through the
2030
+ * serverless handler. Uses `crossPlatformServe` to pick the right
2031
+ * runtime (Node, Bun, Deno).
2032
+ *
2033
+ * @param opts.port Port to listen on. Defaults to 3000.
2034
+ * @param opts.publicDir If set, serves static files from this directory
2035
+ * before falling through to the registry handler.
2036
+ *
2037
+ * @example
2038
+ * ```ts
2039
+ * await registry.listen();
2040
+ * await registry.listen({ port: 8080, publicDir: "./public" });
2041
+ * ```
2042
+ */
2043
+ listen(opts?: {
2044
+ port?: number;
2045
+ publicDir?: string;
2046
+ }): Promise<void>;
2047
+ /**
2048
+ * Gracefully drains all live registries.
2049
+ *
2050
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
2051
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
2052
+ * waits for the serve promise to resolve, all bounded by the shutdown
2053
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
2054
+ * signal or exit the process. The caller owns process lifetime.
2055
+ *
2056
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
2057
+ * call even if nothing has been started.
2058
+ *
2059
+ * @example
2060
+ * ```ts
2061
+ * const registry = setup({ use: { counter } });
2062
+ * registry.start();
2063
+ * // ...later, on your own shutdown trigger:
2064
+ * await registry.shutdown();
2065
+ * ```
2066
+ */
2067
+ shutdown(): Promise<void>;
1632
2068
  startEnvoy(): void;
1633
2069
  /**
1634
2070
  * Starts the actor envoy for standalone server deployments.