rivetkit 0.0.0-main.9809768 → 0.0.0-main.9d355a2

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 (250) hide show
  1. package/dist/browser/client.d.ts +643 -92
  2. package/dist/browser/client.js +1335 -439
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +55 -23
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +6 -2
  7. package/dist/tsup/actor/errors.cjs.map +1 -1
  8. package/dist/tsup/actor/errors.d.cts +1 -74
  9. package/dist/tsup/actor/errors.d.ts +1 -74
  10. package/dist/tsup/actor/errors.js +5 -1
  11. package/dist/tsup/agent-os/index.cjs +2159 -2030
  12. package/dist/tsup/agent-os/index.cjs.map +1 -1
  13. package/dist/tsup/agent-os/index.d.cts +645 -102
  14. package/dist/tsup/agent-os/index.d.ts +645 -102
  15. package/dist/tsup/agent-os/index.js +2161 -2032
  16. package/dist/tsup/agent-os/index.js.map +1 -1
  17. package/dist/tsup/{chunk-JTL6Y2UN.cjs → chunk-4FC7TVS6.cjs} +37 -72
  18. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  19. package/dist/tsup/{chunk-IB2WXKSP.cjs → chunk-CMDPRD3X.cjs} +152 -23
  20. package/dist/tsup/chunk-CMDPRD3X.cjs.map +1 -0
  21. package/dist/tsup/{chunk-7MRGNVSR.js → chunk-DPIMKYNB.js} +69 -6
  22. package/dist/tsup/chunk-DPIMKYNB.js.map +1 -0
  23. package/dist/tsup/{chunk-OK3MOUEF.js → chunk-EXEKTBVU.js} +942 -174
  24. package/dist/tsup/chunk-EXEKTBVU.js.map +1 -0
  25. package/dist/tsup/{chunk-W3S624JL.cjs → chunk-EXZJTRTN.cjs} +24 -9
  26. package/dist/tsup/chunk-EXZJTRTN.cjs.map +1 -0
  27. package/dist/tsup/{chunk-OAGTS3GU.cjs → chunk-FLOSVQBU.cjs} +10 -10
  28. package/dist/tsup/chunk-FLOSVQBU.cjs.map +1 -0
  29. package/dist/tsup/{chunk-3BFYSYRU.js → chunk-HXUEHHJF.js} +3 -2
  30. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  31. package/dist/tsup/{chunk-TUNCAI56.cjs → chunk-JRLWD7AW.cjs} +1085 -317
  32. package/dist/tsup/chunk-JRLWD7AW.cjs.map +1 -0
  33. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  34. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  35. package/dist/tsup/{chunk-K6GMCOF4.js → chunk-KKTIM7P5.js} +22 -7
  36. package/dist/tsup/chunk-KKTIM7P5.js.map +1 -0
  37. package/dist/tsup/{chunk-Y7LG4UKO.js → chunk-KQP6XJSD.js} +4 -4
  38. package/dist/tsup/chunk-KQP6XJSD.js.map +1 -0
  39. package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-NIY3RSPX.cjs} +70 -7
  40. package/dist/tsup/chunk-NIY3RSPX.cjs.map +1 -0
  41. package/dist/tsup/{chunk-DFFHOIWF.cjs → chunk-RWNMGGME.cjs} +188 -78
  42. package/dist/tsup/chunk-RWNMGGME.cjs.map +1 -0
  43. package/dist/tsup/{chunk-JY23WU6R.js → chunk-SO6QFSXQ.js} +6 -6
  44. package/dist/tsup/chunk-SO6QFSXQ.js.map +1 -0
  45. package/dist/tsup/{chunk-HECICUBQ.cjs → chunk-TCMRYK4L.cjs} +10 -10
  46. package/dist/tsup/chunk-TCMRYK4L.cjs.map +1 -0
  47. package/dist/tsup/{chunk-H674SHCQ.cjs → chunk-UGJ2N3ES.cjs} +3 -3
  48. package/dist/tsup/{chunk-H674SHCQ.cjs.map → chunk-UGJ2N3ES.cjs.map} +1 -1
  49. package/dist/tsup/{chunk-JFXD4KY5.js → chunk-UITIGXJ3.js} +147 -18
  50. package/dist/tsup/chunk-UITIGXJ3.js.map +1 -0
  51. package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-VE2X4KMG.cjs} +3 -2
  52. package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -0
  53. package/dist/tsup/{chunk-O23MJ2Z5.js → chunk-VHIVDKNT.js} +2 -2
  54. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  55. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  56. package/dist/tsup/{chunk-OZEWPNG5.js → chunk-ZOYSONXS.js} +181 -71
  57. package/dist/tsup/chunk-ZOYSONXS.js.map +1 -0
  58. package/dist/tsup/{chunk-ZGWSH7YV.js → chunk-ZZ3WBRPD.js} +36 -71
  59. package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
  60. package/dist/tsup/client/mod.cjs +9 -9
  61. package/dist/tsup/client/mod.d.cts +15 -6
  62. package/dist/tsup/client/mod.d.ts +15 -6
  63. package/dist/tsup/client/mod.js +8 -8
  64. package/dist/tsup/common/log.cjs +3 -3
  65. package/dist/tsup/common/log.js +2 -2
  66. package/dist/tsup/common/websocket.cjs +4 -4
  67. package/dist/tsup/common/websocket.js +3 -3
  68. package/dist/tsup/{config-B9qUIHX4.d.ts → config-D49x8NpL.d.cts} +25 -14
  69. package/dist/tsup/{config-B9qUIHX4.d.cts → config-D49x8NpL.d.ts} +25 -14
  70. package/dist/tsup/{config-D6WxBYjV.d.cts → config-De_5Yadw.d.cts} +686 -45
  71. package/dist/tsup/{config-B3RIidaJ.d.ts → config-YgOAQBRh.d.ts} +686 -45
  72. package/dist/tsup/context-D3jrAiNn.d.ts +128 -0
  73. package/dist/tsup/context-Dgkn8rni.d.cts +128 -0
  74. package/dist/tsup/db/drizzle.cjs +112 -107
  75. package/dist/tsup/db/drizzle.cjs.map +1 -1
  76. package/dist/tsup/db/drizzle.d.cts +1 -1
  77. package/dist/tsup/db/drizzle.d.ts +1 -1
  78. package/dist/tsup/db/drizzle.js +112 -107
  79. package/dist/tsup/db/drizzle.js.map +1 -1
  80. package/dist/tsup/db/mod.cjs +63 -102
  81. package/dist/tsup/db/mod.cjs.map +1 -1
  82. package/dist/tsup/db/mod.d.cts +2 -2
  83. package/dist/tsup/db/mod.d.ts +2 -2
  84. package/dist/tsup/db/mod.js +62 -101
  85. package/dist/tsup/db/mod.js.map +1 -1
  86. package/dist/tsup/dynamic/mod.cjs +24 -0
  87. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  88. package/dist/tsup/dynamic/mod.d.cts +37 -0
  89. package/dist/tsup/dynamic/mod.d.ts +37 -0
  90. package/dist/tsup/dynamic/mod.js +24 -0
  91. package/dist/tsup/dynamic/mod.js.map +1 -0
  92. package/dist/tsup/inspector/mod.cjs +6 -6
  93. package/dist/tsup/inspector/mod.js +5 -5
  94. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  95. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  96. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  97. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  98. package/dist/tsup/inspector-tab/mod.js +173 -0
  99. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  100. package/dist/tsup/mod.cjs +2675 -759
  101. package/dist/tsup/mod.cjs.map +1 -1
  102. package/dist/tsup/mod.d.cts +6 -6
  103. package/dist/tsup/mod.d.ts +6 -6
  104. package/dist/tsup/mod.js +2622 -706
  105. package/dist/tsup/mod.js.map +1 -1
  106. package/dist/tsup/test/mod.cjs +21 -18
  107. package/dist/tsup/test/mod.cjs.map +1 -1
  108. package/dist/tsup/test/mod.d.cts +5 -5
  109. package/dist/tsup/test/mod.d.ts +5 -5
  110. package/dist/tsup/test/mod.js +18 -15
  111. package/dist/tsup/test/mod.js.map +1 -1
  112. package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
  113. package/dist/tsup/utils-CqDnC_PS.d.ts +104 -0
  114. package/dist/tsup/utils.cjs +3 -3
  115. package/dist/tsup/utils.d.cts +1 -1
  116. package/dist/tsup/utils.d.ts +1 -1
  117. package/dist/tsup/utils.js +2 -2
  118. package/dist/tsup/workflow/mod.cjs +377 -322
  119. package/dist/tsup/workflow/mod.cjs.map +1 -1
  120. package/dist/tsup/workflow/mod.d.cts +9 -9
  121. package/dist/tsup/workflow/mod.d.ts +9 -9
  122. package/dist/tsup/workflow/mod.js +354 -299
  123. package/dist/tsup/workflow/mod.js.map +1 -1
  124. package/package.json +36 -13
  125. package/src/actor/config.ts +172 -59
  126. package/src/actor/contexts/index.ts +7 -2
  127. package/src/actor/definition.ts +17 -19
  128. package/src/actor/driver.ts +3 -3
  129. package/src/actor/errors.ts +74 -89
  130. package/src/actor/instance/mod.ts +39 -56
  131. package/src/actor/keys.ts +2 -1
  132. package/src/actor/mod.ts +22 -20
  133. package/src/actor/schema.ts +2 -2
  134. package/src/agent-os/actor/cron.ts +37 -2
  135. package/src/agent-os/actor/index.ts +38 -18
  136. package/src/agent-os/actor/preview.ts +1 -2
  137. package/src/agent-os/actor/session.ts +2 -2
  138. package/src/agent-os/config.ts +1 -1
  139. package/src/agent-os/fs/database-vfs.ts +1 -1
  140. package/src/agent-os/index.ts +16 -15
  141. package/src/agent-os/types.ts +11 -0
  142. package/src/client/actor-common.ts +106 -46
  143. package/src/client/actor-conn.ts +88 -40
  144. package/src/client/actor-handle.ts +172 -76
  145. package/src/client/actor-query.ts +5 -5
  146. package/src/client/client.ts +8 -4
  147. package/src/client/config.ts +8 -0
  148. package/src/client/errors.ts +2 -1
  149. package/src/client/lifecycle-errors.ts +28 -4
  150. package/src/client/mod.ts +9 -4
  151. package/src/client/query.ts +1 -1
  152. package/src/client/queue.ts +8 -3
  153. package/src/client/raw-utils.ts +20 -11
  154. package/src/client/resolve-gateway-target.ts +1 -1
  155. package/src/client/utils.ts +34 -10
  156. package/src/common/actor-router-consts.ts +7 -0
  157. package/src/common/actor-websocket.ts +3 -1
  158. package/src/common/bare/actor-persist/v1.ts +205 -163
  159. package/src/common/bare/actor-persist/v2.ts +265 -213
  160. package/src/common/bare/actor-persist/v3.ts +176 -172
  161. package/src/common/bare/actor-persist/v4.ts +254 -253
  162. package/src/common/bare/generated/client-protocol/v4.ts +599 -0
  163. package/src/common/bare/transport/v1.ts +659 -543
  164. package/src/common/client-protocol-versioned.ts +176 -67
  165. package/src/common/client-protocol-zod.ts +7 -0
  166. package/src/common/client-protocol.ts +1 -1
  167. package/src/common/database/config.ts +31 -9
  168. package/src/common/database/mod.test.ts +137 -0
  169. package/src/common/database/mod.ts +73 -126
  170. package/src/common/database/native-database.test.ts +211 -0
  171. package/src/common/database/native-database.ts +207 -61
  172. package/src/common/database/shared.ts +1 -0
  173. package/src/common/encoding.ts +274 -20
  174. package/src/common/engine.ts +28 -1
  175. package/src/common/eventsource.ts +1 -1
  176. package/src/common/inline-websocket-adapter.ts +14 -13
  177. package/src/common/log.ts +108 -11
  178. package/src/common/router.ts +49 -23
  179. package/src/common/utils.ts +17 -203
  180. package/src/common/websocket-interface.ts +1 -1
  181. package/src/db/drizzle.ts +100 -116
  182. package/src/db/mod.ts +3 -1
  183. package/src/devtools-loader/index.ts +4 -7
  184. package/src/devtools-loader/serve-devtools.ts +26 -0
  185. package/src/drivers/engine/actor-driver.ts +76 -73
  186. package/src/dynamic/instance.ts +32 -0
  187. package/src/dynamic/internal.ts +50 -0
  188. package/src/dynamic/isolate-runtime.ts +66 -0
  189. package/src/dynamic/mod.ts +32 -0
  190. package/src/engine-client/actor-http-client.ts +23 -4
  191. package/src/engine-client/actor-websocket-client.ts +32 -5
  192. package/src/engine-client/api-endpoints.ts +52 -2
  193. package/src/engine-client/api-utils.ts +2 -2
  194. package/src/engine-client/driver.ts +17 -2
  195. package/src/engine-client/mod.ts +103 -19
  196. package/src/engine-client/ws-proxy.ts +9 -4
  197. package/src/globals.d.ts +4 -0
  198. package/src/inspector/client.browser.ts +5 -11
  199. package/src/inspector/mod.ts +1 -3
  200. package/src/inspector-tab/mod.ts +315 -0
  201. package/src/registry/config/envoy.ts +1 -2
  202. package/src/registry/config/index.ts +164 -21
  203. package/src/registry/config/serverless.ts +7 -1
  204. package/src/registry/index.ts +468 -95
  205. package/src/registry/napi-runtime.ts +836 -0
  206. package/src/registry/native-validation.ts +10 -12
  207. package/src/registry/native.ts +1200 -805
  208. package/src/registry/process-metrics.ts +250 -0
  209. package/src/registry/runtime.test.ts +50 -0
  210. package/src/registry/runtime.ts +640 -0
  211. package/src/registry/wasm-runtime.ts +945 -0
  212. package/src/registry/write-through-proxy.ts +40 -0
  213. package/src/serde.ts +8 -2
  214. package/src/serverless/configure.ts +102 -49
  215. package/src/test/mod.ts +11 -8
  216. package/src/utils/crypto.ts +14 -0
  217. package/src/utils/endpoint-parser.ts +1 -1
  218. package/src/utils/env-vars.ts +39 -0
  219. package/src/utils/router.ts +1 -1
  220. package/src/utils.ts +1 -2
  221. package/src/workflow/context.ts +699 -240
  222. package/src/workflow/driver.ts +23 -12
  223. package/src/workflow/inspector.ts +4 -3
  224. package/src/workflow/mod.ts +30 -23
  225. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  226. package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
  227. package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
  228. package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
  229. package/dist/tsup/chunk-DFFHOIWF.cjs.map +0 -1
  230. package/dist/tsup/chunk-HECICUBQ.cjs.map +0 -1
  231. package/dist/tsup/chunk-IB2WXKSP.cjs.map +0 -1
  232. package/dist/tsup/chunk-JFXD4KY5.js.map +0 -1
  233. package/dist/tsup/chunk-JTL6Y2UN.cjs.map +0 -1
  234. package/dist/tsup/chunk-JY23WU6R.js.map +0 -1
  235. package/dist/tsup/chunk-K6GMCOF4.js.map +0 -1
  236. package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
  237. package/dist/tsup/chunk-OAGTS3GU.cjs.map +0 -1
  238. package/dist/tsup/chunk-OK3MOUEF.js.map +0 -1
  239. package/dist/tsup/chunk-OZEWPNG5.js.map +0 -1
  240. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  241. package/dist/tsup/chunk-TUNCAI56.cjs.map +0 -1
  242. package/dist/tsup/chunk-W3S624JL.cjs.map +0 -1
  243. package/dist/tsup/chunk-Y7LG4UKO.js.map +0 -1
  244. package/dist/tsup/chunk-ZGWSH7YV.js.map +0 -1
  245. package/dist/tsup/context-BxvHh9wi.d.cts +0 -92
  246. package/dist/tsup/context-CNIZBIKl.d.ts +0 -92
  247. package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
  248. package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
  249. package/src/utils/serve.ts +0 -217
  250. /package/dist/tsup/{chunk-O23MJ2Z5.js.map → chunk-VHIVDKNT.js.map} +0 -0
@@ -1,26 +1,17 @@
1
+ import * as _rivetkit_rivetkit_wasm from '@rivetkit/rivetkit-wasm';
1
2
  import { z as z$2 } from 'zod';
2
3
  import z$1, { z } from 'zod/v4';
3
- import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
4
4
  import { Context, Handler, Hono } from 'hono';
5
+ import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
5
6
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
7
  import { ContentfulStatusCode } from 'hono/utils/http-status';
7
8
  import { Logger } from 'pino';
8
9
 
9
- interface SqliteVfsMetrics {
10
- requestBuildNs: number;
11
- serializeNs: number;
12
- transportNs: number;
13
- stateUpdateNs: number;
14
- totalNs: number;
15
- commitCount: number;
16
- }
17
-
18
10
  type AnyDatabaseProvider = DatabaseProvider<any> | undefined;
19
11
  interface ActorMetricsLike {
20
12
  totalKvReads: number;
21
13
  totalKvWrites: number;
22
14
  trackSql(query: string, durationMs: number): void;
23
- setSqliteVfsMetricsSource(source?: () => SqliteVfsMetrics | null): void;
24
15
  }
25
16
  type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : never;
26
17
  type SqliteBindings = unknown[] | Record<string, unknown>;
@@ -28,11 +19,29 @@ interface SqliteQueryResult {
28
19
  columns: string[];
29
20
  rows: unknown[][];
30
21
  }
22
+ interface SqliteExecuteResult extends SqliteQueryResult {
23
+ changes: number;
24
+ lastInsertRowId?: number | null;
25
+ }
26
+ interface SqliteNativeMetrics {
27
+ requestBuildNs: number;
28
+ serializeNs: number;
29
+ transportNs: number;
30
+ stateUpdateNs: number;
31
+ totalNs: number;
32
+ commitCount: number;
33
+ pageCacheEntries: number;
34
+ pageCacheWeightedSize: number;
35
+ pageCacheCapacityPages: number;
36
+ writeBufferDirtyPages: number;
37
+ dbSizePages: number;
38
+ }
31
39
  interface SqliteDatabase {
32
40
  exec(sql: string, callback?: (row: unknown[], columns: string[]) => void): Promise<void>;
41
+ execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
33
42
  run(sql: string, params?: SqliteBindings): Promise<void>;
34
43
  query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
35
- getSqliteVfsMetrics?: () => SqliteVfsMetrics | null;
44
+ nativeMetrics?(): SqliteNativeMetrics | Promise<SqliteNativeMetrics | null> | null;
36
45
  close(): Promise<void>;
37
46
  }
38
47
  /**
@@ -94,14 +103,17 @@ type DatabaseProvider<DB extends RawAccess> = {
94
103
  /**
95
104
  * Drizzle database client interface (will be extended by drizzle-orm types)
96
105
  */
97
- interface DrizzleDatabaseClient {
98
- }
106
+ type DrizzleDatabaseClient = {};
99
107
  type ExecuteFunction = <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]>;
100
108
  type RawAccess = {
101
109
  /**
102
110
  * Executes a raw SQL query.
103
111
  */
104
112
  execute: ExecuteFunction;
113
+ /**
114
+ * Returns native SQLite metrics when the active runtime supports them.
115
+ */
116
+ nativeMetrics?: () => SqliteNativeMetrics | Promise<SqliteNativeMetrics | null> | null;
105
117
  /**
106
118
  * Closes the database connection and releases resources.
107
119
  */
@@ -169,6 +181,44 @@ type ActorQuery = z.infer<typeof ActorQuerySchema>;
169
181
  */
170
182
  type CreateRequest = z.infer<typeof CreateRequestSchema>;
171
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
+
172
222
  interface DeconstructedError {
173
223
  __type: "ActorError";
174
224
  statusCode: ContentfulStatusCode;
@@ -177,6 +227,7 @@ interface DeconstructedError {
177
227
  code: string;
178
228
  message: string;
179
229
  metadata?: unknown;
230
+ actor?: ActorSpecifier;
180
231
  }
181
232
 
182
233
  interface RivetErrorOptions extends ErrorOptions {
@@ -186,6 +237,14 @@ interface RivetErrorOptions extends ErrorOptions {
186
237
  metadata?: unknown;
187
238
  /** Explicit HTTP status override for router responses. */
188
239
  statusCode?: number;
240
+ /** Actor context associated with this error. */
241
+ actor?: ActorSpecifier;
242
+ }
243
+ /** Identifies the actor that was handling work when an error was produced. */
244
+ interface ActorSpecifier {
245
+ actorId: string;
246
+ generation: number;
247
+ key?: string;
189
248
  }
190
249
  interface UserErrorOptions extends ErrorOptions {
191
250
  /**
@@ -204,6 +263,7 @@ declare class RivetError extends Error {
204
263
  public: boolean;
205
264
  metadata?: unknown;
206
265
  statusCode: number;
266
+ actor?: ActorSpecifier;
207
267
  readonly group: string;
208
268
  readonly code: string;
209
269
  static isRivetError(error: unknown): error is RivetError | DeconstructedError;
@@ -216,61 +276,26 @@ declare class UserError extends RivetError {
216
276
  constructor(message: string, options?: UserErrorOptions);
217
277
  }
218
278
 
219
- type SchemaHookResult = boolean | Promise<boolean>;
220
- type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
221
- interface EventTypeToken<T, TContext = any> {
222
- readonly _eventType?: T;
223
- readonly canSubscribe?: SchemaHook<TContext>;
224
- readonly schema?: PrimitiveSchema;
225
- }
226
- interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
227
- readonly _queueMessage?: TMessage;
228
- readonly _queueComplete?: TComplete;
229
- readonly canPublish?: SchemaHook<TContext>;
230
- readonly message?: PrimitiveSchema;
231
- readonly complete?: PrimitiveSchema;
232
- }
233
- type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
234
- interface EventSchemaDefinition<TContext = any> {
235
- schema: PrimitiveSchema;
236
- canSubscribe?: SchemaHook<TContext>;
237
- }
238
- interface QueueSchemaDefinition<TContext = any> {
239
- message: PrimitiveSchema;
240
- complete?: PrimitiveSchema;
241
- canPublish?: SchemaHook<TContext>;
242
- }
243
- type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
244
- type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
245
- type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
246
- type QueueSchemaConfig<TContext = any> = Record<string, QueueSchema>;
247
- 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;
248
- type InferSchemaMap<T extends Record<string, unknown>> = {
249
- [K in keyof T]: InferSchema<T[K]>;
250
- };
251
- 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;
252
- type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
253
- [K in keyof T]: InferQueueComplete<T[K]>;
254
- };
255
- type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
256
-
257
279
  type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
258
280
  type GetUpgradeWebSocket = () => UpgradeWebSocket;
259
281
 
260
282
  type GatewayTarget = {
261
283
  directId: string;
262
284
  } | ActorQuery;
285
+ interface GatewayRequestOptions {
286
+ skipReadyWait?: boolean;
287
+ }
263
288
  interface EngineControlClient {
264
289
  getForId(input: GetForIdInput): Promise<ActorOutput | undefined>;
265
290
  getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined>;
266
291
  getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput>;
267
292
  createActor(input: CreateInput): Promise<ActorOutput>;
268
293
  listActors(input: ListActorsInput): Promise<ActorOutput[]>;
269
- sendRequest(target: GatewayTarget, actorRequest: Request): Promise<Response>;
270
- openWebSocket(path: string, target: GatewayTarget, encoding: Encoding, params: unknown): Promise<UniversalWebSocket>;
294
+ sendRequest(target: GatewayTarget, actorRequest: Request, options?: GatewayRequestOptions): Promise<Response>;
295
+ openWebSocket(path: string, target: GatewayTarget, encoding: Encoding, params: unknown, options?: GatewayRequestOptions): Promise<UniversalWebSocket>;
271
296
  proxyRequest(c: Context, actorRequest: Request, actorId: string): Promise<Response>;
272
297
  proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown): Promise<Response>;
273
- buildGatewayUrl(target: GatewayTarget): Promise<string>;
298
+ buildGatewayUrl(target: GatewayTarget, options?: GatewayRequestOptions): Promise<string>;
274
299
  displayInformation(): RuntimeDisplayInformation;
275
300
  extraStartupLog?: () => Record<string, unknown>;
276
301
  modifyRuntimeRouter?: (config: RegistryConfig, router: Hono) => void;
@@ -358,12 +383,25 @@ interface QueueSendResult<TResponse = unknown> {
358
383
  * @returns {Promise<Response>}
359
384
  */
360
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;
392
+ interface ActorGatewayOptions {
393
+ skipReadyWait?: boolean;
394
+ }
395
+ interface ActorActionOptions extends ActorGatewayOptions {
396
+ signal?: AbortSignal;
397
+ }
398
+ type ActorConnectOptions = ActorGatewayOptions;
399
+ type ActorFetchInit = RequestInit & ActorGatewayOptions;
400
+ type ActorWebSocketOptions = ActorGatewayOptions;
361
401
  /**
362
402
  * Maps action methods from actor definition to typed function signatures.
363
403
  */
364
- type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? {
365
- [K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
366
- } : never;
404
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
367
405
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
368
406
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
369
407
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
@@ -374,13 +412,31 @@ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
374
412
  <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
375
413
  (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
376
414
  };
377
- 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 ? {
378
424
  send: ActorQueueSend<Q>;
379
- } : never : never;
380
- 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 ? {
381
434
  on: ActorEventSubscribe<E>;
382
435
  once: ActorEventSubscribe<E>;
383
- } : 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
+ } : {} : {};
384
440
 
385
441
  declare class ActorClientError extends Error {
386
442
  }
@@ -445,7 +501,7 @@ declare class ActorConnRaw {
445
501
  *
446
502
  * @protected
447
503
  */
448
- constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState);
504
+ constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions);
449
505
  send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
450
506
  send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
451
507
  /**
@@ -510,6 +566,10 @@ declare class ActorConnRaw {
510
566
  * @returns {boolean} - True if the connection is open, false otherwise.
511
567
  */
512
568
  get isConnected(): boolean;
569
+ /**
570
+ * Resolves when this connection first reaches the connected state.
571
+ */
572
+ get ready(): Promise<void>;
513
573
  /**
514
574
  * Subscribes to connection open events.
515
575
  *
@@ -577,7 +637,7 @@ declare class ActorHandleRaw {
577
637
  *
578
638
  * @protected
579
639
  */
580
- constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState);
640
+ constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions);
581
641
  send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
582
642
  send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
583
643
  /**
@@ -590,24 +650,23 @@ declare class ActorHandleRaw {
590
650
  action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
591
651
  name: string;
592
652
  args: Args;
593
- signal?: AbortSignal;
594
- }): Promise<Response>;
653
+ } & ActorActionOptions): Promise<Response>;
595
654
  /**
596
655
  * Establishes a persistent connection to the actor.
597
656
  *
598
657
  * @template AD The actor class that this connection is for.
599
658
  * @returns {ActorConn<AD>} A connection to the actor.
600
659
  */
601
- connect(params?: unknown): ActorConn<AnyActorDefinition>;
660
+ connect(params?: unknown, options?: ActorConnectOptions): ActorConn<AnyActorDefinition>;
602
661
  /**
603
662
  * Fetches a resource from this actor via the /request endpoint. This is a
604
663
  * convenience wrapper around the raw HTTP API.
605
664
  */
606
- fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
665
+ fetch(input: string | URL | Request, init?: ActorFetchInit): Promise<Response>;
607
666
  /**
608
667
  * Opens a raw WebSocket connection to this actor.
609
668
  */
610
- webSocket(path?: string, protocols?: string | string[]): Promise<any>;
669
+ webSocket(path?: string, protocols?: string | string[], options?: ActorWebSocketOptions): Promise<any>;
611
670
  /**
612
671
  * Resolves the actor to get its unique actor ID.
613
672
  */
@@ -635,7 +694,7 @@ declare class ActorHandleRaw {
635
694
  * @see {@link ActorHandleRaw}
636
695
  */
637
696
  type ActorHandle<AD extends AnyActorDefinition> = Omit<ActorHandleRaw, "connect" | "send"> & {
638
- connect(params?: unknown): ActorConn<AD>;
697
+ connect(params?: unknown, options?: ActorConnectOptions): ActorConn<AD>;
639
698
  resolve(): Promise<string>;
640
699
  } & ActorDefinitionQueueSend<AD> & ActorDefinitionActions<AD>;
641
700
 
@@ -650,6 +709,9 @@ declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
650
709
  bare: "bare";
651
710
  }>>;
652
711
  headers: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>>;
712
+ gateway: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
713
+ skipReadyWait: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
714
+ }, z$1.core.$strip>>>;
653
715
  getUpgradeWebSocket: z$1.ZodOptional<z$1.ZodCustom<GetUpgradeWebSocket, GetUpgradeWebSocket>>;
654
716
  disableMetadataLookup: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
655
717
  maxInputSize: z$1.ZodDefault<z$1.ZodNumber>;
@@ -661,6 +723,9 @@ declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
661
723
  poolName: string;
662
724
  encoding: "json" | "cbor" | "bare";
663
725
  headers: Record<string, string>;
726
+ gateway: {
727
+ skipReadyWait: boolean;
728
+ };
664
729
  disableMetadataLookup: boolean;
665
730
  maxInputSize: number;
666
731
  devtools: boolean;
@@ -672,6 +737,9 @@ declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
672
737
  poolName: string;
673
738
  encoding: "json" | "cbor" | "bare";
674
739
  headers: Record<string, string>;
740
+ gateway: {
741
+ skipReadyWait: boolean;
742
+ };
675
743
  disableMetadataLookup: boolean;
676
744
  maxInputSize: number;
677
745
  devtools: boolean;
@@ -821,7 +889,7 @@ declare class ClientRaw {
821
889
  /**
822
890
  * Creates an instance of Client.
823
891
  */
824
- constructor(driver: EngineControlClient, encoding: Encoding | undefined);
892
+ constructor(driver: EngineControlClient, encoding: Encoding | undefined, gatewayOptions?: ActorGatewayOptions);
825
893
  /**
826
894
  * Gets a stateless handle to a actor by its ID.
827
895
  *
@@ -882,6 +950,7 @@ type Client<A extends Registry<any>> = ClientRaw & {
882
950
  };
883
951
 
884
952
  declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
953
+ declare const RAW_STATE_SYMBOL: unique symbol;
885
954
  interface ActorLogger {
886
955
  level: any;
887
956
  fatal: any;
@@ -914,6 +983,10 @@ type ActorKvListOptions<T extends ActorKvValueType = "text", K extends ActorKvKe
914
983
  limit?: number;
915
984
  };
916
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
+ */
917
990
  interface ActorKv {
918
991
  get<T extends ActorKvValueType = "text">(key: Uint8Array | string, options?: ActorKvValueOptions<T>): Promise<ActorKvValueTypeMap[T] | null>;
919
992
  put<T extends ActorKvValueType = "text">(key: Uint8Array | string, value: Uint8Array | string | ArrayBuffer, options?: ActorKvValueOptions<T>): Promise<void>;
@@ -990,7 +1063,7 @@ interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
990
1063
  iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
991
1064
  [key: string]: any;
992
1065
  }
993
- 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>> {
994
1067
  id: string;
995
1068
  params: TConnParams;
996
1069
  state: TConnState;
@@ -1001,8 +1074,14 @@ interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TV
1001
1074
  }
1002
1075
  interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1003
1076
  [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
1077
+ /** Returns the raw unwrapped state without the write-through proxy. */
1078
+ [RAW_STATE_SYMBOL](): TState;
1004
1079
  state: TState;
1005
1080
  vars: TVars;
1081
+ /**
1082
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
1083
+ * or actor state instead.
1084
+ */
1006
1085
  readonly kv: ActorKv;
1007
1086
  readonly db: InferDatabaseClient<TDatabase>;
1008
1087
  readonly schedule: ActorSchedule;
@@ -1127,8 +1206,27 @@ declare const ActorConfigSchema: z.ZodObject<{
1127
1206
  preloadMaxWorkflowBytes: z.ZodOptional<z.ZodNumber>;
1128
1207
  preloadMaxConnectionsBytes: z.ZodOptional<z.ZodNumber>;
1129
1208
  }, z.core.$strict>>;
1209
+ inspector: z.ZodOptional<z.ZodObject<{
1210
+ tabs: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
1211
+ id: z.ZodString;
1212
+ label: z.ZodString;
1213
+ source: z.ZodString;
1214
+ icon: z.ZodOptional<z.ZodString>;
1215
+ hidden: z.ZodOptional<z.ZodLiteral<false>>;
1216
+ }, z.core.$strict>, z.ZodObject<{
1217
+ id: z.ZodEnum<{
1218
+ state: "state";
1219
+ workflow: "workflow";
1220
+ database: "database";
1221
+ queue: "queue";
1222
+ connections: "connections";
1223
+ console: "console";
1224
+ }>;
1225
+ hidden: z.ZodLiteral<true>;
1226
+ }, z.core.$strict>]>>>;
1227
+ }, z.core.$strict>>;
1130
1228
  }, z.core.$strict>;
1131
- 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> = {
1132
1230
  state: TState;
1133
1231
  } | {
1134
1232
  createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
@@ -1141,7 +1239,7 @@ type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase e
1141
1239
  /**
1142
1240
  * @experimental
1143
1241
  */
1144
- 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> = {
1145
1243
  /**
1146
1244
  * @experimental
1147
1245
  */
@@ -1209,7 +1307,7 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1209
1307
  * shutdown window (`sleepGracePeriod`) cover deferred work.
1210
1308
  *
1211
1309
  * The handler receives an abort signal via `c.abortSignal` and a
1212
- * `c.aborted` alias for loop checks. Use these to gracefully exit.
1310
+ * `c.aborted` alias. Use these to gracefully exit when shutdown starts.
1213
1311
  *
1214
1312
  * If this handler exits, the actor will follow the normal idle sleep timeout
1215
1313
  * once it becomes idle.
@@ -1238,10 +1336,11 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1238
1336
  * Called before a client connects to the actor.
1239
1337
  *
1240
1338
  * Use this hook to determine if a connection should be accepted
1241
- * and to initialize connection-specific state.
1339
+ * and to validate client-provided parameters. The pending connection
1340
+ * is not visible in `c.conns` while this hook runs.
1242
1341
  *
1243
1342
  * @param opts Connection parameters including client-provided data
1244
- * @returns The initial connection state or a Promise that resolves to it
1343
+ * @returns Void or a Promise.
1245
1344
  * @throws Throw an error to reject the connection
1246
1345
  */
1247
1346
  onBeforeConnect?: (c: BeforeConnectContext<TState, TVars, TInput, TDatabase, TEvents, TQueues>, params: TConnParams) => void | Promise<void>;
@@ -1249,7 +1348,8 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1249
1348
  * Called when a client successfully connects to the actor.
1250
1349
  *
1251
1350
  * Use this hook to perform actions when a connection is established,
1252
- * such as sending initial data or updating the actor's state.
1351
+ * such as sending initial data or updating the actor's state. The
1352
+ * connection is visible in `c.conns` before this hook runs.
1253
1353
  *
1254
1354
  * @param conn The connection object
1255
1355
  * @returns Void or a Promise that resolves when connection handling is complete
@@ -1325,27 +1425,55 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1325
1425
  */
1326
1426
  db: TDatabase;
1327
1427
  } | Record<never, never>;
1328
- 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>;
1329
1429
 
1330
- 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>> {
1331
- 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;
1332
1435
  }
1333
- type AnyActorDefinition = BaseActorDefinition<any, any, any, any, any, any, any, any, any>;
1334
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> {
1335
1437
  #private;
1336
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
1337
- 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>;
1338
1440
  }
1339
1441
 
1340
- 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>>;
1341
1443
  type RegistryActors = z$2.infer<typeof ActorsSchema>;
1342
1444
  declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1343
1445
  use: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
1344
1446
  test: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1345
- enabled: z$2.ZodBoolean;
1447
+ enabled: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
1448
+ sqliteBackend: z$2.ZodOptional<z$2.ZodEnum<{
1449
+ local: "local";
1450
+ remote: "remote";
1451
+ }>>;
1346
1452
  }, z$2.core.$strip>>>;
1347
1453
  maxIncomingMessageSize: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1348
1454
  maxOutgoingMessageSize: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1455
+ runtime: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodEnum<{
1456
+ auto: "auto";
1457
+ native: "native";
1458
+ wasm: "wasm";
1459
+ }>>, z$2.ZodTransform<"auto" | "native" | "wasm", "auto" | "native" | "wasm" | undefined>>;
1460
+ wasm: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1461
+ bindings: z$2.ZodOptional<z$2.ZodCustom<typeof _rivetkit_rivetkit_wasm, typeof _rivetkit_rivetkit_wasm>>;
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>>;
1463
+ }, z$2.core.$strip>>>;
1464
+ sqlite: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodUnion<readonly [z$2.ZodEnum<{
1465
+ local: "local";
1466
+ remote: "remote";
1467
+ }>, z$2.ZodObject<{
1468
+ backend: z$2.ZodEnum<{
1469
+ local: "local";
1470
+ remote: "remote";
1471
+ }>;
1472
+ }, z$2.core.$strip>]>>, z$2.ZodTransform<{
1473
+ backend: "local" | "remote";
1474
+ } | undefined, "local" | "remote" | {
1475
+ backend: "local" | "remote";
1476
+ } | undefined>>;
1349
1477
  noWelcome: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
1350
1478
  logging: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1351
1479
  baseLogger: z$2.ZodOptional<z$2.ZodCustom<Logger, Logger>>;
@@ -1368,12 +1496,15 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1368
1496
  httpPort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1369
1497
  httpHost: z$2.ZodOptional<z$2.ZodString>;
1370
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>>;
1371
1501
  engineVersion: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
1372
1502
  configurePool: z$2.ZodOptional<z$2.ZodOptional<z$2.ZodObject<{
1373
1503
  name: z$2.ZodOptional<z$2.ZodString>;
1374
1504
  url: z$2.ZodString;
1375
1505
  headers: z$2.ZodOptional<z$2.ZodRecord<z$2.ZodString, z$2.ZodString>>;
1376
1506
  requestLifespan: z$2.ZodOptional<z$2.ZodNumber>;
1507
+ drainGracePeriod: z$2.ZodOptional<z$2.ZodNumber>;
1377
1508
  metadata: z$2.ZodOptional<z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>>;
1378
1509
  metadataPollInterval: z$2.ZodOptional<z$2.ZodNumber>;
1379
1510
  drainOnVersionUpgrade: z$2.ZodOptional<z$2.ZodBoolean>;
@@ -1391,10 +1522,13 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1391
1522
  envoyKey: z$2.ZodOptional<z$2.ZodString>;
1392
1523
  }, z$2.core.$strip>>>;
1393
1524
  shutdown: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1394
- gracePeriodMs: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1525
+ gracePeriodMs: z$2.ZodOptional<z$2.ZodNumber>;
1395
1526
  disableSignalHandlers: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
1396
1527
  }, z$2.core.$strip>>>;
1397
1528
  }, z$2.core.$strip>, z$2.ZodTransform<{
1529
+ sqlite: {
1530
+ backend: "local" | "remote";
1531
+ } | undefined;
1398
1532
  endpoint: string | undefined;
1399
1533
  namespace: string;
1400
1534
  token: string | undefined;
@@ -1411,9 +1545,15 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1411
1545
  use: Record<string, AnyActorDefinition>;
1412
1546
  test: {
1413
1547
  enabled: boolean;
1548
+ sqliteBackend?: "local" | "remote" | undefined;
1414
1549
  };
1415
1550
  maxIncomingMessageSize: number;
1416
1551
  maxOutgoingMessageSize: number;
1552
+ runtime: "auto" | "native" | "wasm";
1553
+ wasm: {
1554
+ bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1555
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1556
+ };
1417
1557
  noWelcome: boolean;
1418
1558
  logging: {
1419
1559
  baseLogger?: Logger | undefined;
@@ -1423,6 +1563,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1423
1563
  httpBasePath: string;
1424
1564
  httpPort: number;
1425
1565
  startEngine: boolean;
1566
+ engineHost: string;
1567
+ enginePort: number;
1426
1568
  engineVersion: string;
1427
1569
  envoy: {
1428
1570
  poolName: string;
@@ -1431,8 +1573,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1431
1573
  envoyKey?: string | undefined;
1432
1574
  };
1433
1575
  shutdown: {
1434
- gracePeriodMs: number;
1435
1576
  disableSignalHandlers: boolean;
1577
+ gracePeriodMs?: number | undefined;
1436
1578
  };
1437
1579
  staticDir?: string | undefined;
1438
1580
  httpHost?: string | undefined;
@@ -1441,6 +1583,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1441
1583
  name?: string | undefined;
1442
1584
  headers?: Record<string, string> | undefined;
1443
1585
  requestLifespan?: number | undefined;
1586
+ drainGracePeriod?: number | undefined;
1444
1587
  metadata?: Record<string, unknown> | undefined;
1445
1588
  metadataPollInterval?: number | undefined;
1446
1589
  drainOnVersionUpgrade?: boolean | undefined;
@@ -1449,9 +1592,18 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1449
1592
  use: Record<string, AnyActorDefinition>;
1450
1593
  test: {
1451
1594
  enabled: boolean;
1595
+ sqliteBackend?: "local" | "remote" | undefined;
1452
1596
  };
1453
1597
  maxIncomingMessageSize: number;
1454
1598
  maxOutgoingMessageSize: number;
1599
+ runtime: "auto" | "native" | "wasm";
1600
+ wasm: {
1601
+ bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1602
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1603
+ };
1604
+ sqlite: {
1605
+ backend: "local" | "remote";
1606
+ } | undefined;
1455
1607
  noWelcome: boolean;
1456
1608
  logging: {
1457
1609
  baseLogger?: Logger | undefined;
@@ -1464,6 +1616,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1464
1616
  httpBasePath: string;
1465
1617
  httpPort: number;
1466
1618
  startEngine: boolean;
1619
+ engineHost: string;
1620
+ enginePort: number;
1467
1621
  engineVersion: string;
1468
1622
  serverless: {
1469
1623
  basePath: string;
@@ -1478,8 +1632,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1478
1632
  envoyKey?: string | undefined;
1479
1633
  };
1480
1634
  shutdown: {
1481
- gracePeriodMs: number;
1482
1635
  disableSignalHandlers: boolean;
1636
+ gracePeriodMs?: number | undefined;
1483
1637
  };
1484
1638
  staticDir?: string | undefined;
1485
1639
  httpHost?: string | undefined;
@@ -1488,6 +1642,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1488
1642
  name?: string | undefined;
1489
1643
  headers?: Record<string, string> | undefined;
1490
1644
  requestLifespan?: number | undefined;
1645
+ drainGracePeriod?: number | undefined;
1491
1646
  metadata?: Record<string, unknown> | undefined;
1492
1647
  metadataPollInterval?: number | undefined;
1493
1648
  drainOnVersionUpgrade?: boolean | undefined;
@@ -1498,15 +1653,364 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1498
1653
  use: A;
1499
1654
  };
1500
1655
 
1656
+ declare const handleBrand: unique symbol;
1657
+ type OpaqueHandle<Name extends string> = {
1658
+ readonly [handleBrand]: Name;
1659
+ };
1660
+ type RegistryHandle = OpaqueHandle<"registry">;
1661
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
1662
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
1663
+ type ConnHandle = OpaqueHandle<"conn">;
1664
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
1665
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
1666
+ type RuntimeBytes = Uint8Array;
1667
+ interface RuntimeActorKeySegment {
1668
+ kind: string;
1669
+ stringValue?: string;
1670
+ numberValue?: number;
1671
+ }
1672
+ interface RuntimeHttpRequest {
1673
+ method: string;
1674
+ uri: string;
1675
+ headers?: Record<string, string>;
1676
+ body?: RuntimeBytes;
1677
+ }
1678
+ interface RuntimeStateDeltaPayload {
1679
+ state?: RuntimeBytes;
1680
+ connHibernation: Array<{
1681
+ connId: string;
1682
+ bytes: RuntimeBytes;
1683
+ }>;
1684
+ connHibernationRemoved: string[];
1685
+ }
1686
+ interface RuntimeRequestSaveOpts {
1687
+ immediate?: boolean;
1688
+ maxWaitMs?: number;
1689
+ }
1690
+ interface RuntimeInspectorSnapshot {
1691
+ stateRevision: number;
1692
+ connectionsRevision: number;
1693
+ queueRevision: number;
1694
+ activeConnections: number;
1695
+ queueSize: number;
1696
+ connectedClients: number;
1697
+ }
1698
+ interface RuntimeQueueMessage {
1699
+ id(): bigint;
1700
+ name(): string;
1701
+ body(): RuntimeBytes;
1702
+ createdAt(): number;
1703
+ isCompletable(): boolean;
1704
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
1705
+ }
1706
+ interface RuntimeQueueInspectMessage {
1707
+ id: number;
1708
+ name: string;
1709
+ createdAtMs: number;
1710
+ }
1711
+ interface RuntimeQueueNextBatchOptions {
1712
+ names?: string[];
1713
+ count?: number;
1714
+ timeoutMs?: number;
1715
+ completable?: boolean;
1716
+ }
1717
+ interface RuntimeQueueWaitOptions {
1718
+ timeoutMs?: number;
1719
+ completable?: boolean;
1720
+ }
1721
+ interface RuntimeQueueEnqueueAndWaitOptions {
1722
+ timeoutMs?: number;
1723
+ }
1724
+ interface RuntimeQueueTryNextBatchOptions {
1725
+ names?: string[];
1726
+ count?: number;
1727
+ completable?: boolean;
1728
+ }
1729
+ interface RuntimeKvListOptions {
1730
+ reverse?: boolean;
1731
+ limit?: number;
1732
+ }
1733
+ interface RuntimeKvEntry {
1734
+ key: RuntimeBytes;
1735
+ value: RuntimeBytes;
1736
+ }
1737
+ type RuntimeSqlBindNoValues = {
1738
+ intValue?: never;
1739
+ floatValue?: never;
1740
+ textValue?: never;
1741
+ blobValue?: never;
1742
+ };
1743
+ type RuntimeSqlBindParam = ({
1744
+ kind: "null";
1745
+ } & RuntimeSqlBindNoValues) | {
1746
+ kind: "int";
1747
+ intValue: number;
1748
+ floatValue?: never;
1749
+ textValue?: never;
1750
+ blobValue?: never;
1751
+ } | {
1752
+ kind: "float";
1753
+ intValue?: never;
1754
+ floatValue: number;
1755
+ textValue?: never;
1756
+ blobValue?: never;
1757
+ } | {
1758
+ kind: "text";
1759
+ intValue?: never;
1760
+ floatValue?: never;
1761
+ textValue: string;
1762
+ blobValue?: never;
1763
+ } | {
1764
+ kind: "blob";
1765
+ intValue?: never;
1766
+ floatValue?: never;
1767
+ textValue?: never;
1768
+ blobValue: RuntimeBytes;
1769
+ };
1770
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
1771
+ interface RuntimeSqlQueryResult {
1772
+ columns: string[];
1773
+ rows: unknown[][];
1774
+ }
1775
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
1776
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
1777
+ changes: number;
1778
+ lastInsertRowId?: number | null;
1779
+ }
1780
+ interface RuntimeSqlRunResult {
1781
+ changes: number;
1782
+ }
1783
+ interface RuntimeActorConfig {
1784
+ name?: string;
1785
+ icon?: string;
1786
+ hasDatabase?: boolean;
1787
+ remoteSqlite?: boolean;
1788
+ hasState?: boolean;
1789
+ canHibernateWebsocket?: boolean;
1790
+ stateSaveIntervalMs?: number;
1791
+ createStateTimeoutMs?: number;
1792
+ onCreateTimeoutMs?: number;
1793
+ createVarsTimeoutMs?: number;
1794
+ createConnStateTimeoutMs?: number;
1795
+ onBeforeConnectTimeoutMs?: number;
1796
+ onConnectTimeoutMs?: number;
1797
+ onMigrateTimeoutMs?: number;
1798
+ onWakeTimeoutMs?: number;
1799
+ onBeforeActorStartTimeoutMs?: number;
1800
+ actionTimeoutMs?: number;
1801
+ onRequestTimeoutMs?: number;
1802
+ sleepTimeoutMs?: number;
1803
+ noSleep?: boolean;
1804
+ sleepGracePeriodMs?: number;
1805
+ connectionLivenessTimeoutMs?: number;
1806
+ connectionLivenessIntervalMs?: number;
1807
+ maxQueueSize?: number;
1808
+ maxQueueMessageSize?: number;
1809
+ maxIncomingMessageSize?: number;
1810
+ maxOutgoingMessageSize?: number;
1811
+ preloadMaxWorkflowBytes?: number;
1812
+ preloadMaxConnectionsBytes?: number;
1813
+ actions?: Array<{
1814
+ name: string;
1815
+ }>;
1816
+ inspectorTabs?: Array<RuntimeInspectorTabEntry>;
1817
+ }
1818
+ interface RuntimeInspectorTabEntry {
1819
+ id: string;
1820
+ /** Required for custom entries; omitted for built-in hides. */
1821
+ label?: string;
1822
+ /**
1823
+ * Required for custom entries — absolute path to the source directory.
1824
+ * Resolved on the TS side before being handed to the runtime.
1825
+ */
1826
+ source?: string;
1827
+ /** Optional icon id for custom entries. */
1828
+ icon?: string;
1829
+ /** Set to true for built-in hide entries. */
1830
+ hidden?: boolean;
1831
+ }
1832
+ interface RuntimeServeConfig {
1833
+ version: number;
1834
+ endpoint: string;
1835
+ token?: string;
1836
+ namespace: string;
1837
+ poolName: string;
1838
+ engineBinaryPath?: string;
1839
+ engineHost?: string;
1840
+ enginePort?: number;
1841
+ handleInspectorHttpInRuntime?: boolean;
1842
+ inspectorTestToken?: string;
1843
+ serverlessBasePath?: string;
1844
+ serverlessPackageVersion: string;
1845
+ serverlessClientEndpoint?: string;
1846
+ serverlessClientNamespace?: string;
1847
+ serverlessClientToken?: string;
1848
+ serverlessValidateEndpoint: boolean;
1849
+ serverlessMaxStartPayloadBytes: number;
1850
+ }
1851
+ interface RuntimeListenerConfig {
1852
+ port: number;
1853
+ host?: string;
1854
+ publicDir?: string;
1855
+ }
1856
+ interface RuntimeServerlessRequest {
1857
+ method: string;
1858
+ url: string;
1859
+ headers: Record<string, string>;
1860
+ body: RuntimeBytes;
1861
+ }
1862
+ interface RuntimeServerlessResponseHead {
1863
+ status: number;
1864
+ headers: Record<string, string>;
1865
+ }
1866
+ interface RuntimeRegistryRouteResponse {
1867
+ status: number;
1868
+ headers: Record<string, string>;
1869
+ body: RuntimeBytes;
1870
+ }
1871
+ type RuntimeServerlessStreamEvent = {
1872
+ kind: "chunk";
1873
+ chunk?: RuntimeBytes;
1874
+ } | {
1875
+ kind: "end";
1876
+ error?: {
1877
+ group: string;
1878
+ code: string;
1879
+ message: string;
1880
+ };
1881
+ };
1882
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
1883
+ type RuntimeWebSocketEvent = {
1884
+ kind: "message";
1885
+ data: string | RuntimeBytes;
1886
+ binary: boolean;
1887
+ messageIndex?: number;
1888
+ } | {
1889
+ kind: "close";
1890
+ code: number;
1891
+ reason: string;
1892
+ wasClean: boolean;
1893
+ };
1894
+ interface CoreRuntime {
1895
+ readonly kind: "napi" | "wasm";
1896
+ createRegistry(): RegistryHandle;
1897
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
1898
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
1899
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
1900
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
1901
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
1902
+ serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
1903
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1904
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1905
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1906
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
1907
+ createCancellationToken(): CancellationTokenHandle;
1908
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
1909
+ cancelCancellationToken(token: CancellationTokenHandle): void;
1910
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
1911
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
1912
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
1913
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
1914
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
1915
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
1916
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
1917
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
1918
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
1919
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
1920
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
1921
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
1922
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
1923
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
1924
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
1925
+ actorId(ctx: ActorContextHandle): string;
1926
+ actorName(ctx: ActorContextHandle): string;
1927
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
1928
+ actorRegion(ctx: ActorContextHandle): string;
1929
+ actorSleep(ctx: ActorContextHandle): void;
1930
+ actorDestroy(ctx: ActorContextHandle): void;
1931
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
1932
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
1933
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
1934
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
1935
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1936
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
1937
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
1938
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1939
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
1940
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
1941
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1942
+ actorRuntimeState(ctx: ActorContextHandle): object;
1943
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
1944
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
1945
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
1946
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
1947
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
1948
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
1949
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
1950
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
1951
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1952
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1953
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
1954
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
1955
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
1956
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
1957
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
1958
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
1959
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
1960
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
1961
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
1962
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
1963
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
1964
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
1965
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
1966
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
1967
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
1968
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
1969
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
1970
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
1971
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
1972
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
1973
+ connId(conn: ConnHandle): string;
1974
+ connParams(conn: ConnHandle): RuntimeBytes;
1975
+ connState(conn: ConnHandle): RuntimeBytes;
1976
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
1977
+ connIsHibernatable(conn: ConnHandle): boolean;
1978
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
1979
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
1980
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
1981
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
1982
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
1983
+ }
1984
+
1985
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
1986
+ runtime: CoreRuntime;
1987
+ registry: RegistryHandle;
1988
+ serveConfig: RuntimeServeConfig;
1989
+ }>;
1990
+
1501
1991
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
1502
1992
  interface ServerlessHandler {
1503
1993
  fetch: FetchHandler;
1504
1994
  }
1995
+ interface RegistryRoutes {
1996
+ health(): Promise<Response>;
1997
+ metadata(): Promise<Response>;
1998
+ prometheusMetrics(request?: Request): Promise<Response>;
1999
+ }
2000
+ /**
2001
+ * Injectable dependencies for {@link Registry}. Production code uses the
2002
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
2003
+ * orchestration against a fake `CoreRuntime` without an engine.
2004
+ */
2005
+ interface RegistryDeps {
2006
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
2007
+ }
1505
2008
  declare class Registry<A extends RegistryActors> {
1506
2009
  #private;
2010
+ readonly routes: RegistryRoutes;
1507
2011
  get config(): RegistryConfigInput<A>;
1508
2012
  parseConfig(): RegistryConfig;
1509
- constructor(config: RegistryConfigInput<A>);
2013
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
1510
2014
  /**
1511
2015
  * Handle an incoming HTTP request for serverless deployments.
1512
2016
  *
@@ -1527,9 +2031,56 @@ declare class Registry<A extends RegistryActors> {
1527
2031
  * ```
1528
2032
  */
1529
2033
  serve(): ServerlessHandler;
2034
+ /**
2035
+ * Bind an HTTP listener provided by the native (Rust) runtime and serve
2036
+ * the registry's serverless endpoints over it. Resolves only after the
2037
+ * registry is shut down (SIGINT/SIGTERM or `nativeRegistry.shutdown()`).
2038
+ *
2039
+ * @param opts.port Port to listen on. Defaults to `process.env.RIVET_PORT`
2040
+ * if set, otherwise 3000.
2041
+ * @param opts.host Address to bind. Defaults to `0.0.0.0`.
2042
+ * @param opts.publicDir If set, serves static files from this directory
2043
+ * as a fallback below the framework routes.
2044
+ *
2045
+ * @example
2046
+ * ```ts
2047
+ * await registry.listen();
2048
+ * await registry.listen({ port: 8080, publicDir: "./public" });
2049
+ * ```
2050
+ */
2051
+ listen(opts?: {
2052
+ port?: number;
2053
+ host?: string;
2054
+ publicDir?: string;
2055
+ }): Promise<void>;
2056
+ /**
2057
+ * Gracefully drains all live registries.
2058
+ *
2059
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
2060
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
2061
+ * waits for the serve promise to resolve, all bounded by the shutdown
2062
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
2063
+ * signal or exit the process. The caller owns process lifetime.
2064
+ *
2065
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
2066
+ * call even if nothing has been started.
2067
+ *
2068
+ * @example
2069
+ * ```ts
2070
+ * const registry = setup({ use: { counter } });
2071
+ * registry.start();
2072
+ * // ...later, on your own shutdown trigger:
2073
+ * await registry.shutdown();
2074
+ * ```
2075
+ */
2076
+ shutdown(): Promise<void>;
1530
2077
  startEnvoy(): void;
1531
2078
  /**
1532
- * Starts the native actor envoy for standalone server deployments.
2079
+ * Starts the actor envoy for standalone server deployments.
2080
+ *
2081
+ * Set `RIVETKIT_RUNTIME_MODE=serverless` to instead bind an HTTP listener
2082
+ * via `listen()` (Mode B). Mode A (envoy) and Mode B (listener) are
2083
+ * mutually exclusive per registry instance.
1533
2084
  *
1534
2085
  * @example
1535
2086
  * ```ts
@@ -1545,4 +2096,4 @@ declare class Registry<A extends RegistryActors> {
1545
2096
  */
1546
2097
  declare function createClient<A extends Registry<any>>(endpointOrConfig?: string | ClientConfigInput): Client<A>;
1547
2098
 
1548
- export { type ActorAccessor, type ActorActionFunction, ActorClientError, type ActorConn, ActorConnDisposed, ActorConnRaw, type ActorConnStatus, ActorDefinition, RivetError as ActorError, type ActorHandle, ActorHandleRaw, type AnyActorDefinition, type Client, type ClientConfigInput, ClientRaw, type ConnectionStateCallback, type CreateOptions, type CreateRequest, type Encoding, type EventUnsubscribe, type ExtractActorsFromRegistry, type ExtractRegistryFromClient, type GetOptions, type GetWithIdOptions, MalformedResponseMessage, ManagerError, type QueryOptions, type Region, RivetError, type StatusChangeCallback, UserError, createClient };
2099
+ export { type ActorAccessor, type ActorActionFunction, type ActorActionOptions, ActorClientError, type ActorConn, ActorConnDisposed, ActorConnRaw, type ActorConnStatus, type ActorConnectOptions, ActorDefinition, RivetError as ActorError, type ActorGatewayOptions, type ActorHandle, ActorHandleRaw, type AnyActorDefinition, type Client, type ClientConfigInput, ClientRaw, type ConnectionStateCallback, type CreateOptions, type CreateRequest, type Encoding, type EventUnsubscribe, type ExtractActorsFromRegistry, type ExtractRegistryFromClient, type GetOptions, type GetWithIdOptions, MalformedResponseMessage, ManagerError, type QueryOptions, type Region, RivetError, type StatusChangeCallback, UserError, createClient };