rivetkit 2.3.0-rc.8 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/dist/browser/client.d.ts +481 -74
  2. package/dist/browser/client.js +174 -148
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +47 -18
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +2 -2
  7. package/dist/tsup/actor/errors.d.cts +1 -1
  8. package/dist/tsup/actor/errors.d.ts +1 -1
  9. package/dist/tsup/actor/errors.js +1 -1
  10. package/dist/tsup/agent-os/index.cjs +2160 -2086
  11. package/dist/tsup/agent-os/index.cjs.map +1 -1
  12. package/dist/tsup/agent-os/index.d.cts +479 -73
  13. package/dist/tsup/agent-os/index.d.ts +479 -73
  14. package/dist/tsup/agent-os/index.js +2160 -2086
  15. package/dist/tsup/agent-os/index.js.map +1 -1
  16. package/dist/tsup/{chunk-KY3CERZR.js → chunk-2OTRTA3J.js} +7 -21
  17. package/dist/tsup/chunk-2OTRTA3J.js.map +1 -0
  18. package/dist/tsup/{chunk-HGW6PBWR.cjs → chunk-3677IIOV.cjs} +11 -25
  19. package/dist/tsup/chunk-3677IIOV.cjs.map +1 -0
  20. package/dist/tsup/{chunk-OT7FF6GB.cjs → chunk-47HHIEXH.cjs} +24 -9
  21. package/dist/tsup/chunk-47HHIEXH.cjs.map +1 -0
  22. package/dist/tsup/{chunk-EMFKMVJR.js → chunk-4JDSFJS5.js} +69 -58
  23. package/dist/tsup/chunk-4JDSFJS5.js.map +1 -0
  24. package/dist/tsup/{chunk-7HLFSAJP.cjs → chunk-7QKCIVAY.cjs} +225 -214
  25. package/dist/tsup/chunk-7QKCIVAY.cjs.map +1 -0
  26. package/dist/tsup/{chunk-AWTPTUQ7.cjs → chunk-B6VUNZUD.cjs} +10 -10
  27. package/dist/tsup/{chunk-AWTPTUQ7.cjs.map → chunk-B6VUNZUD.cjs.map} +1 -1
  28. package/dist/tsup/{chunk-D3T3ZBSY.js → chunk-BEI24WTI.js} +2 -2
  29. package/dist/tsup/{chunk-TMLOKTRB.js → chunk-BRP62GZC.js} +1 -1
  30. package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
  31. package/dist/tsup/{chunk-D5G75T7J.js → chunk-DPIMKYNB.js} +61 -2
  32. package/dist/tsup/chunk-DPIMKYNB.js.map +1 -0
  33. package/dist/tsup/{chunk-BATTOVHF.cjs → chunk-DXXJPH55.cjs} +40 -13
  34. package/dist/tsup/chunk-DXXJPH55.cjs.map +1 -0
  35. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  36. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  37. package/dist/tsup/{chunk-4BPKKZJO.cjs → chunk-I4LN3FNT.cjs} +10 -10
  38. package/dist/tsup/chunk-I4LN3FNT.cjs.map +1 -0
  39. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  40. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  41. package/dist/tsup/{chunk-63WNTDRC.cjs → chunk-KORQB2IR.cjs} +1 -1
  42. package/dist/tsup/{chunk-63WNTDRC.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
  43. package/dist/tsup/{chunk-6TQSSJ4F.cjs → chunk-LVTBW2RE.cjs} +3 -3
  44. package/dist/tsup/{chunk-6TQSSJ4F.cjs.map → chunk-LVTBW2RE.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-4JU3IPG2.js → chunk-MEHBWPLJ.js} +6 -6
  46. package/dist/tsup/chunk-MEHBWPLJ.js.map +1 -0
  47. package/dist/tsup/{chunk-SRNOPUC6.cjs → chunk-NIY3RSPX.cjs} +62 -3
  48. package/dist/tsup/chunk-NIY3RSPX.cjs.map +1 -0
  49. package/dist/tsup/{chunk-UZXQEGVJ.js → chunk-P2GNQ4RN.js} +4 -4
  50. package/dist/tsup/{chunk-UZXQEGVJ.js.map → chunk-P2GNQ4RN.js.map} +1 -1
  51. package/dist/tsup/{chunk-VUGENVIK.js → chunk-UMZVD6DQ.js} +22 -7
  52. package/dist/tsup/chunk-UMZVD6DQ.js.map +1 -0
  53. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  54. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  55. package/dist/tsup/{chunk-GBG63SUG.js → chunk-VTTFNQQI.js} +32 -5
  56. package/dist/tsup/chunk-VTTFNQQI.js.map +1 -0
  57. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  58. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  59. package/dist/tsup/client/mod.cjs +9 -9
  60. package/dist/tsup/client/mod.d.cts +5 -5
  61. package/dist/tsup/client/mod.d.ts +5 -5
  62. package/dist/tsup/client/mod.js +8 -8
  63. package/dist/tsup/common/log.cjs +3 -3
  64. package/dist/tsup/common/log.js +2 -2
  65. package/dist/tsup/common/websocket.cjs +4 -4
  66. package/dist/tsup/common/websocket.js +3 -3
  67. package/dist/tsup/{config-Ak1lv4gF.d.ts → config-BxWAw3iH.d.ts} +512 -27
  68. package/dist/tsup/{config-DU_xj4qZ.d.cts → config-CZQQ-mso.d.cts} +512 -27
  69. package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.cts} +1 -2
  70. package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.ts} +1 -2
  71. package/dist/tsup/{context-DAAp4Lpg.d.ts → context-Bw7xq8w3.d.cts} +8 -8
  72. package/dist/tsup/{context-Dt_L55q8.d.cts → context-D8QA76sV.d.ts} +8 -8
  73. package/dist/tsup/db/drizzle.cjs +3 -3
  74. package/dist/tsup/db/drizzle.d.cts +1 -1
  75. package/dist/tsup/db/drizzle.d.ts +1 -1
  76. package/dist/tsup/db/drizzle.js +1 -1
  77. package/dist/tsup/db/mod.cjs +2 -2
  78. package/dist/tsup/db/mod.d.cts +2 -2
  79. package/dist/tsup/db/mod.d.ts +2 -2
  80. package/dist/tsup/db/mod.js +1 -1
  81. package/dist/tsup/dynamic/mod.cjs +24 -0
  82. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  83. package/dist/tsup/dynamic/mod.d.cts +37 -0
  84. package/dist/tsup/dynamic/mod.d.ts +37 -0
  85. package/dist/tsup/dynamic/mod.js +24 -0
  86. package/dist/tsup/dynamic/mod.js.map +1 -0
  87. package/dist/tsup/inspector/mod.cjs +6 -6
  88. package/dist/tsup/inspector/mod.js +5 -5
  89. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  90. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  91. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  92. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  93. package/dist/tsup/inspector-tab/mod.js +173 -0
  94. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  95. package/dist/tsup/mod.cjs +615 -348
  96. package/dist/tsup/mod.cjs.map +1 -1
  97. package/dist/tsup/mod.d.cts +5 -5
  98. package/dist/tsup/mod.d.ts +5 -5
  99. package/dist/tsup/mod.js +511 -244
  100. package/dist/tsup/mod.js.map +1 -1
  101. package/dist/tsup/test/mod.cjs +21 -18
  102. package/dist/tsup/test/mod.cjs.map +1 -1
  103. package/dist/tsup/test/mod.d.cts +4 -4
  104. package/dist/tsup/test/mod.d.ts +4 -4
  105. package/dist/tsup/test/mod.js +18 -15
  106. package/dist/tsup/test/mod.js.map +1 -1
  107. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-DQosb24I.d.cts} +1 -1
  108. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-DQosb24I.d.ts} +1 -1
  109. package/dist/tsup/utils.cjs +3 -3
  110. package/dist/tsup/utils.d.cts +1 -1
  111. package/dist/tsup/utils.d.ts +1 -1
  112. package/dist/tsup/utils.js +2 -2
  113. package/dist/tsup/workflow/mod.cjs +279 -279
  114. package/dist/tsup/workflow/mod.cjs.map +1 -1
  115. package/dist/tsup/workflow/mod.d.cts +6 -6
  116. package/dist/tsup/workflow/mod.d.ts +6 -6
  117. package/dist/tsup/workflow/mod.js +380 -380
  118. package/dist/tsup/workflow/mod.js.map +1 -1
  119. package/package.json +29 -9
  120. package/src/actor/config.ts +156 -51
  121. package/src/actor/contexts/index.ts +7 -2
  122. package/src/actor/definition.ts +17 -19
  123. package/src/actor/driver.ts +3 -3
  124. package/src/actor/errors.ts +8 -2
  125. package/src/actor/instance/mod.ts +26 -34
  126. package/src/actor/keys.ts +1 -1
  127. package/src/actor/mod.ts +22 -20
  128. package/src/actor/schema.ts +2 -2
  129. package/src/agent-os/actor/index.ts +38 -18
  130. package/src/agent-os/actor/preview.ts +1 -2
  131. package/src/agent-os/config.ts +1 -1
  132. package/src/agent-os/fs/database-vfs.ts +1 -1
  133. package/src/agent-os/index.ts +16 -15
  134. package/src/client/actor-common.ts +87 -54
  135. package/src/client/actor-conn.ts +11 -11
  136. package/src/client/actor-handle.ts +69 -52
  137. package/src/client/actor-query.ts +5 -5
  138. package/src/client/errors.ts +1 -1
  139. package/src/client/lifecycle-errors.ts +2 -4
  140. package/src/client/query.ts +1 -1
  141. package/src/client/queue.ts +8 -4
  142. package/src/client/raw-utils.ts +8 -6
  143. package/src/client/resolve-gateway-target.ts +1 -1
  144. package/src/client/utils.ts +2 -6
  145. package/src/common/actor-websocket.ts +3 -1
  146. package/src/common/bare/actor-persist/v1.ts +205 -163
  147. package/src/common/bare/actor-persist/v2.ts +265 -213
  148. package/src/common/bare/actor-persist/v3.ts +176 -172
  149. package/src/common/bare/actor-persist/v4.ts +254 -253
  150. package/src/common/bare/transport/v1.ts +659 -543
  151. package/src/common/client-protocol-versioned.ts +66 -64
  152. package/src/common/database/config.ts +2 -8
  153. package/src/common/database/native-database.ts +1 -1
  154. package/src/common/database/shared.ts +1 -0
  155. package/src/common/encoding.ts +13 -17
  156. package/src/common/engine.ts +28 -1
  157. package/src/common/eventsource.ts +1 -1
  158. package/src/common/inline-websocket-adapter.ts +3 -2
  159. package/src/common/router.ts +13 -17
  160. package/src/common/utils.ts +1 -2
  161. package/src/common/websocket-interface.ts +1 -1
  162. package/src/db/mod.ts +1 -1
  163. package/src/devtools-loader/index.ts +4 -7
  164. package/src/devtools-loader/serve-devtools.ts +26 -0
  165. package/src/drivers/engine/actor-driver.ts +48 -46
  166. package/src/dynamic/instance.ts +32 -0
  167. package/src/dynamic/internal.ts +50 -0
  168. package/src/dynamic/isolate-runtime.ts +66 -0
  169. package/src/dynamic/mod.ts +32 -0
  170. package/src/engine-client/actor-http-client.ts +3 -3
  171. package/src/engine-client/actor-websocket-client.ts +5 -5
  172. package/src/engine-client/api-endpoints.ts +51 -2
  173. package/src/engine-client/api-utils.ts +2 -2
  174. package/src/engine-client/driver.ts +1 -1
  175. package/src/engine-client/mod.ts +5 -3
  176. package/src/engine-client/ws-proxy.ts +9 -4
  177. package/src/inspector/client.browser.ts +5 -11
  178. package/src/inspector/mod.ts +1 -3
  179. package/src/inspector-tab/mod.ts +315 -0
  180. package/src/registry/config/envoy.ts +1 -2
  181. package/src/registry/config/index.ts +40 -16
  182. package/src/registry/index.ts +226 -83
  183. package/src/registry/napi-runtime.ts +46 -12
  184. package/src/registry/native-validation.ts +10 -12
  185. package/src/registry/native.ts +307 -164
  186. package/src/registry/process-metrics.ts +90 -23
  187. package/src/registry/runtime.ts +53 -6
  188. package/src/registry/wasm-runtime.ts +30 -3
  189. package/src/serde.ts +1 -1
  190. package/src/serverless/configure.ts +18 -7
  191. package/src/test/mod.ts +11 -8
  192. package/src/utils/endpoint-parser.ts +1 -1
  193. package/src/utils/env-vars.ts +6 -0
  194. package/src/utils/router.ts +1 -1
  195. package/src/utils/serve.ts +4 -5
  196. package/src/utils.ts +1 -2
  197. package/src/workflow/context.ts +30 -29
  198. package/src/workflow/driver.ts +4 -6
  199. package/src/workflow/inspector.ts +2 -2
  200. package/src/workflow/mod.ts +15 -17
  201. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  202. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  203. package/dist/tsup/chunk-4BPKKZJO.cjs.map +0 -1
  204. package/dist/tsup/chunk-4JU3IPG2.js.map +0 -1
  205. package/dist/tsup/chunk-7HLFSAJP.cjs.map +0 -1
  206. package/dist/tsup/chunk-BATTOVHF.cjs.map +0 -1
  207. package/dist/tsup/chunk-D5G75T7J.js.map +0 -1
  208. package/dist/tsup/chunk-EMFKMVJR.js.map +0 -1
  209. package/dist/tsup/chunk-GBG63SUG.js.map +0 -1
  210. package/dist/tsup/chunk-HGW6PBWR.cjs.map +0 -1
  211. package/dist/tsup/chunk-KY3CERZR.js.map +0 -1
  212. package/dist/tsup/chunk-OT7FF6GB.cjs.map +0 -1
  213. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  214. package/dist/tsup/chunk-SRNOPUC6.cjs.map +0 -1
  215. package/dist/tsup/chunk-TMLOKTRB.js.map +0 -1
  216. package/dist/tsup/chunk-VUGENVIK.js.map +0 -1
  217. package/dist/tsup/process-metrics-NW754INA.js +0 -118
  218. package/dist/tsup/process-metrics-NW754INA.js.map +0 -1
  219. package/dist/tsup/process-metrics-TYAGKCEJ.cjs +0 -118
  220. package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +0 -1
  221. /package/dist/tsup/{chunk-D3T3ZBSY.js.map → chunk-BEI24WTI.js.map} +0 -0
@@ -1,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
  }
@@ -962,6 +983,10 @@ type ActorKvListOptions<T extends ActorKvValueType = "text", K extends ActorKvKe
962
983
  limit?: number;
963
984
  };
964
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
+ */
965
990
  interface ActorKv {
966
991
  get<T extends ActorKvValueType = "text">(key: Uint8Array | string, options?: ActorKvValueOptions<T>): Promise<ActorKvValueTypeMap[T] | null>;
967
992
  put<T extends ActorKvValueType = "text">(key: Uint8Array | string, value: Uint8Array | string | ArrayBuffer, options?: ActorKvValueOptions<T>): Promise<void>;
@@ -1038,7 +1063,7 @@ interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1038
1063
  iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
1039
1064
  [key: string]: any;
1040
1065
  }
1041
- 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>> {
1042
1067
  id: string;
1043
1068
  params: TConnParams;
1044
1069
  state: TConnState;
@@ -1053,6 +1078,10 @@ interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase
1053
1078
  [RAW_STATE_SYMBOL](): TState;
1054
1079
  state: TState;
1055
1080
  vars: TVars;
1081
+ /**
1082
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
1083
+ * or actor state instead.
1084
+ */
1056
1085
  readonly kv: ActorKv;
1057
1086
  readonly db: InferDatabaseClient<TDatabase>;
1058
1087
  readonly schedule: ActorSchedule;
@@ -1177,8 +1206,27 @@ declare const ActorConfigSchema: z.ZodObject<{
1177
1206
  preloadMaxWorkflowBytes: z.ZodOptional<z.ZodNumber>;
1178
1207
  preloadMaxConnectionsBytes: z.ZodOptional<z.ZodNumber>;
1179
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>>;
1180
1228
  }, z.core.$strict>;
1181
- 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> = {
1182
1230
  state: TState;
1183
1231
  } | {
1184
1232
  createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
@@ -1191,7 +1239,7 @@ type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase e
1191
1239
  /**
1192
1240
  * @experimental
1193
1241
  */
1194
- 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> = {
1195
1243
  /**
1196
1244
  * @experimental
1197
1245
  */
@@ -1377,19 +1425,21 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1377
1425
  */
1378
1426
  db: TDatabase;
1379
1427
  } | Record<never, never>;
1380
- 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>;
1381
1429
 
1382
- 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>> {
1383
- 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;
1384
1435
  }
1385
- type AnyActorDefinition = BaseActorDefinition<any, any, any, any, any, any, any, any, any>;
1386
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> {
1387
1437
  #private;
1388
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
1389
- 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>;
1390
1440
  }
1391
1441
 
1392
- 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>>;
1393
1443
  type RegistryActors = z$2.infer<typeof ActorsSchema>;
1394
1444
  declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1395
1445
  use: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
@@ -1409,11 +1459,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1409
1459
  }>>, z$2.ZodTransform<"auto" | "native" | "wasm", "auto" | "native" | "wasm" | undefined>>;
1410
1460
  wasm: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1411
1461
  bindings: z$2.ZodOptional<z$2.ZodCustom<typeof _rivetkit_rivetkit_wasm, typeof _rivetkit_rivetkit_wasm>>;
1412
- initInput: z$2.ZodOptional<z$2.ZodCustom<{
1413
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1414
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined, {
1415
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1416
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined>>;
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>>;
1417
1463
  }, z$2.core.$strip>>>;
1418
1464
  sqlite: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodUnion<readonly [z$2.ZodEnum<{
1419
1465
  local: "local";
@@ -1450,6 +1496,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1450
1496
  httpPort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1451
1497
  httpHost: z$2.ZodOptional<z$2.ZodString>;
1452
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>>;
1453
1501
  engineVersion: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
1454
1502
  configurePool: z$2.ZodOptional<z$2.ZodOptional<z$2.ZodObject<{
1455
1503
  name: z$2.ZodOptional<z$2.ZodString>;
@@ -1504,9 +1552,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1504
1552
  runtime: "auto" | "native" | "wasm";
1505
1553
  wasm: {
1506
1554
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1507
- initInput?: {
1508
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1509
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1555
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1510
1556
  };
1511
1557
  noWelcome: boolean;
1512
1558
  logging: {
@@ -1517,6 +1563,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1517
1563
  httpBasePath: string;
1518
1564
  httpPort: number;
1519
1565
  startEngine: boolean;
1566
+ engineHost: string;
1567
+ enginePort: number;
1520
1568
  engineVersion: string;
1521
1569
  envoy: {
1522
1570
  poolName: string;
@@ -1551,9 +1599,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1551
1599
  runtime: "auto" | "native" | "wasm";
1552
1600
  wasm: {
1553
1601
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1554
- initInput?: {
1555
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1556
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1602
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1557
1603
  };
1558
1604
  sqlite: {
1559
1605
  backend: "local" | "remote";
@@ -1570,6 +1616,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1570
1616
  httpBasePath: string;
1571
1617
  httpPort: number;
1572
1618
  startEngine: boolean;
1619
+ engineHost: string;
1620
+ enginePort: number;
1573
1621
  engineVersion: string;
1574
1622
  serverless: {
1575
1623
  basePath: string;
@@ -1605,19 +1653,358 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1605
1653
  use: A;
1606
1654
  };
1607
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
+
1608
1985
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
1609
1986
  interface ServerlessHandler {
1610
1987
  fetch: FetchHandler;
1611
1988
  }
1612
- interface RegistryDiagnostics {
1613
- mode: string;
1614
- envoyActiveActorCount?: number | null;
1989
+ interface RegistryRoutes {
1990
+ health(): Promise<Response>;
1991
+ metadata(): Promise<Response>;
1992
+ prometheusMetrics(request?: Request): Promise<Response>;
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;
1615
2001
  }
1616
2002
  declare class Registry<A extends RegistryActors> {
1617
2003
  #private;
2004
+ readonly routes: RegistryRoutes;
1618
2005
  get config(): RegistryConfigInput<A>;
1619
2006
  parseConfig(): RegistryConfig;
1620
- constructor(config: RegistryConfigInput<A>);
2007
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
1621
2008
  /**
1622
2009
  * Handle an incoming HTTP request for serverless deployments.
1623
2010
  *
@@ -1657,7 +2044,27 @@ declare class Registry<A extends RegistryActors> {
1657
2044
  port?: number;
1658
2045
  publicDir?: string;
1659
2046
  }): Promise<void>;
1660
- diagnostics(): Promise<RegistryDiagnostics>;
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>;
1661
2068
  startEnvoy(): void;
1662
2069
  /**
1663
2070
  * Starts the actor envoy for standalone server deployments.