rivetkit 0.0.0-main.337772d → 0.0.0-main.4994268

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 (270) hide show
  1. package/dist/browser/client.d.ts +731 -88
  2. package/dist/browser/client.js +1379 -737
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +121 -2
  5. package/dist/browser/inspector/client.js +2064 -232
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/actor/errors.cjs +6 -2
  8. package/dist/tsup/actor/errors.cjs.map +1 -1
  9. package/dist/tsup/actor/errors.d.cts +1 -74
  10. package/dist/tsup/actor/errors.d.ts +1 -74
  11. package/dist/tsup/actor/errors.js +5 -1
  12. package/dist/tsup/agent-os/index.cjs +2355 -2099
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +729 -87
  15. package/dist/tsup/agent-os/index.d.ts +729 -87
  16. package/dist/tsup/agent-os/index.js +2343 -2087
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-RH4D7BO3.js → chunk-2PVIX6B3.js} +13 -7
  19. package/dist/tsup/chunk-2PVIX6B3.js.map +1 -0
  20. package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-4FC7TVS6.cjs} +35 -10
  21. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  22. package/dist/tsup/{chunk-LGZR4WHX.js → chunk-54VWHRG7.js} +6 -6
  23. package/dist/tsup/chunk-54VWHRG7.js.map +1 -0
  24. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-7AFZMFPQ.js} +15 -1
  25. package/dist/tsup/chunk-7AFZMFPQ.js.map +1 -0
  26. package/dist/tsup/{chunk-CQYUHACN.js → chunk-ALCCSOCU.js} +476 -58
  27. package/dist/tsup/chunk-ALCCSOCU.js.map +1 -0
  28. package/dist/tsup/{chunk-3OCAQD6G.cjs → chunk-CFA5ZRWA.cjs} +10 -10
  29. package/dist/tsup/chunk-CFA5ZRWA.cjs.map +1 -0
  30. package/dist/tsup/{chunk-XAMXMPDR.cjs → chunk-DFRCAEKM.cjs} +17 -11
  31. package/dist/tsup/chunk-DFRCAEKM.cjs.map +1 -0
  32. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-HNHLBM3Y.cjs} +192 -15
  33. package/dist/tsup/chunk-HNHLBM3Y.cjs.map +1 -0
  34. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-JI6GZ2C2.js} +3 -12
  35. package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
  36. package/dist/tsup/{chunk-RLAOOSJD.js → chunk-L3KD2YPI.js} +42 -7
  37. package/dist/tsup/chunk-L3KD2YPI.js.map +1 -0
  38. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-MYWZCDML.cjs} +3 -12
  39. package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
  40. package/dist/tsup/{chunk-2VLNKGGO.cjs → chunk-OE3QIP5X.cjs} +484 -66
  41. package/dist/tsup/chunk-OE3QIP5X.cjs.map +1 -0
  42. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-QWLJCP3X.js} +190 -13
  43. package/dist/tsup/chunk-QWLJCP3X.js.map +1 -0
  44. package/dist/tsup/{chunk-RSSGGFQA.js → chunk-R3SZNBUQ.js} +918 -329
  45. package/dist/tsup/chunk-R3SZNBUQ.js.map +1 -0
  46. package/dist/tsup/{chunk-5VMFWRHI.cjs → chunk-SUV5DP6T.cjs} +44 -9
  47. package/dist/tsup/chunk-SUV5DP6T.cjs.map +1 -0
  48. package/dist/tsup/{chunk-B4XQ4QIY.cjs → chunk-TJ3B4I5P.cjs} +1043 -454
  49. package/dist/tsup/chunk-TJ3B4I5P.cjs.map +1 -0
  50. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-UEULFXUI.cjs} +16 -2
  51. package/dist/tsup/chunk-UEULFXUI.cjs.map +1 -0
  52. package/dist/tsup/{chunk-7J7EWOUD.cjs → chunk-YBTLEVA2.cjs} +3 -3
  53. package/dist/tsup/{chunk-7J7EWOUD.cjs.map → chunk-YBTLEVA2.cjs.map} +1 -1
  54. package/dist/tsup/{chunk-VKWY7G34.js → chunk-YNNR7QDA.js} +2 -2
  55. package/dist/tsup/{chunk-K34B3OVG.js → chunk-ZZ3WBRPD.js} +34 -9
  56. package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
  57. package/dist/tsup/client/mod.cjs +8 -9
  58. package/dist/tsup/client/mod.cjs.map +1 -1
  59. package/dist/tsup/client/mod.d.cts +7 -7
  60. package/dist/tsup/client/mod.d.ts +7 -7
  61. package/dist/tsup/client/mod.js +7 -8
  62. package/dist/tsup/common/log.cjs +5 -3
  63. package/dist/tsup/common/log.cjs.map +1 -1
  64. package/dist/tsup/common/log.d.cts +5 -1
  65. package/dist/tsup/common/log.d.ts +5 -1
  66. package/dist/tsup/common/log.js +6 -4
  67. package/dist/tsup/common/websocket.cjs +4 -4
  68. package/dist/tsup/common/websocket.js +3 -3
  69. package/dist/tsup/{config-CxjGYf4K.d.cts → config-BxOimoGX.d.cts} +17 -2
  70. package/dist/tsup/{config-CxjGYf4K.d.ts → config-BxOimoGX.d.ts} +17 -2
  71. package/dist/tsup/{config-C-a9vrke.d.cts → config-CUymbyM6.d.ts} +758 -56
  72. package/dist/tsup/{config-CvQUtDp9.d.ts → config-CpB-e4I9.d.cts} +758 -56
  73. package/dist/tsup/context-YBUBTwTS.d.ts +129 -0
  74. package/dist/tsup/context-c-6G4mjk.d.cts +129 -0
  75. package/dist/tsup/db/drizzle.cjs +120 -68
  76. package/dist/tsup/db/drizzle.cjs.map +1 -1
  77. package/dist/tsup/db/drizzle.d.cts +8 -3
  78. package/dist/tsup/db/drizzle.d.ts +8 -3
  79. package/dist/tsup/db/drizzle.js +120 -68
  80. package/dist/tsup/db/drizzle.js.map +1 -1
  81. package/dist/tsup/db/mod.cjs +74 -22
  82. package/dist/tsup/db/mod.cjs.map +1 -1
  83. package/dist/tsup/db/mod.d.cts +4 -3
  84. package/dist/tsup/db/mod.d.ts +4 -3
  85. package/dist/tsup/db/mod.js +74 -22
  86. package/dist/tsup/db/mod.js.map +1 -1
  87. package/dist/tsup/dynamic/mod.cjs +24 -0
  88. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  89. package/dist/tsup/dynamic/mod.d.cts +37 -0
  90. package/dist/tsup/dynamic/mod.d.ts +37 -0
  91. package/dist/tsup/dynamic/mod.js +24 -0
  92. package/dist/tsup/dynamic/mod.js.map +1 -0
  93. package/dist/tsup/inspector/mod.cjs +46 -12
  94. package/dist/tsup/inspector/mod.cjs.map +1 -1
  95. package/dist/tsup/inspector/mod.d.cts +37 -15
  96. package/dist/tsup/inspector/mod.d.ts +37 -15
  97. package/dist/tsup/inspector/mod.js +45 -11
  98. package/dist/tsup/inspector/mod.js.map +1 -1
  99. package/dist/tsup/inspector-tab/mod.cjs +162 -0
  100. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  101. package/dist/tsup/inspector-tab/mod.d.cts +240 -0
  102. package/dist/tsup/inspector-tab/mod.d.ts +240 -0
  103. package/dist/tsup/inspector-tab/mod.js +162 -0
  104. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  105. package/dist/tsup/mod.cjs +2028 -625
  106. package/dist/tsup/mod.cjs.map +1 -1
  107. package/dist/tsup/mod.d.cts +6 -7
  108. package/dist/tsup/mod.d.ts +6 -7
  109. package/dist/tsup/mod.js +1953 -550
  110. package/dist/tsup/mod.js.map +1 -1
  111. package/dist/tsup/test/mod.cjs +26 -21
  112. package/dist/tsup/test/mod.cjs.map +1 -1
  113. package/dist/tsup/test/mod.d.cts +5 -6
  114. package/dist/tsup/test/mod.d.ts +5 -6
  115. package/dist/tsup/test/mod.js +25 -20
  116. package/dist/tsup/test/mod.js.map +1 -1
  117. package/dist/tsup/unstable/migrations.cjs +101 -0
  118. package/dist/tsup/unstable/migrations.cjs.map +1 -0
  119. package/dist/tsup/unstable/migrations.d.cts +29 -0
  120. package/dist/tsup/unstable/migrations.d.ts +29 -0
  121. package/dist/tsup/unstable/migrations.js +101 -0
  122. package/dist/tsup/unstable/migrations.js.map +1 -0
  123. package/dist/tsup/utils-CV0akuDD.d.ts +162 -0
  124. package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
  125. package/dist/tsup/utils-CqDnC_PS.d.ts +104 -0
  126. package/dist/tsup/utils-DQDCphrl.d.cts +162 -0
  127. package/dist/tsup/utils.cjs +7 -3
  128. package/dist/tsup/utils.cjs.map +1 -1
  129. package/dist/tsup/utils.d.cts +4 -147
  130. package/dist/tsup/utils.d.ts +4 -147
  131. package/dist/tsup/utils.js +6 -2
  132. package/dist/tsup/workflow/mod.cjs +486 -375
  133. package/dist/tsup/workflow/mod.cjs.map +1 -1
  134. package/dist/tsup/workflow/mod.d.cts +9 -10
  135. package/dist/tsup/workflow/mod.d.ts +9 -10
  136. package/dist/tsup/workflow/mod.js +478 -367
  137. package/dist/tsup/workflow/mod.js.map +1 -1
  138. package/package.json +45 -14
  139. package/src/actor/actions.ts +119 -0
  140. package/src/actor/config.test.ts +14 -0
  141. package/src/actor/config.ts +338 -85
  142. package/src/actor/contexts/index.ts +7 -2
  143. package/src/actor/definition.ts +38 -26
  144. package/src/actor/errors.ts +70 -7
  145. package/src/actor/keys.ts +1 -1
  146. package/src/actor/mod.ts +22 -20
  147. package/src/actor/schema.ts +2 -2
  148. package/src/agent-os/actor/index.ts +39 -19
  149. package/src/agent-os/actor/preview.ts +1 -2
  150. package/src/agent-os/actor/session.ts +2 -2
  151. package/src/agent-os/config.ts +1 -1
  152. package/src/agent-os/fs/database-vfs.ts +1 -1
  153. package/src/agent-os/index.ts +16 -15
  154. package/src/client/actor-common.ts +89 -54
  155. package/src/client/actor-conn.ts +58 -63
  156. package/src/client/actor-handle.ts +124 -70
  157. package/src/client/actor-query.ts +5 -5
  158. package/src/client/client.ts +24 -11
  159. package/src/client/errors.ts +2 -1
  160. package/src/client/lifecycle-errors.ts +2 -4
  161. package/src/client/query.ts +1 -1
  162. package/src/client/queue.ts +8 -3
  163. package/src/client/raw-utils.ts +21 -12
  164. package/src/client/resolve-gateway-target.ts +1 -1
  165. package/src/client/utils.ts +34 -10
  166. package/src/common/actor-router-consts.ts +5 -0
  167. package/src/common/actor-websocket.ts +3 -1
  168. package/src/common/bare/actor-persist/v1.ts +205 -163
  169. package/src/common/bare/actor-persist/v2.ts +265 -213
  170. package/src/common/bare/actor-persist/v3.ts +176 -172
  171. package/src/common/bare/actor-persist/v4.ts +254 -253
  172. package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
  173. package/src/common/bare/generated/client-protocol/v4.ts +599 -0
  174. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  175. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  176. package/src/common/bare/transport/v1.ts +694 -542
  177. package/src/common/client-protocol-versioned.ts +176 -67
  178. package/src/common/client-protocol-zod.ts +7 -0
  179. package/src/common/client-protocol.ts +1 -1
  180. package/src/common/database/config.ts +26 -8
  181. package/src/common/database/mod.test.ts +148 -59
  182. package/src/common/database/mod.ts +93 -23
  183. package/src/common/database/native-database.test.ts +44 -0
  184. package/src/common/database/native-database.ts +158 -3
  185. package/src/common/database/shared.ts +16 -0
  186. package/src/common/encoding.ts +278 -34
  187. package/src/common/engine.ts +28 -1
  188. package/src/common/eventsource.ts +1 -1
  189. package/src/common/fetch-like.ts +49 -0
  190. package/src/common/inline-websocket-adapter.ts +14 -13
  191. package/src/common/log.ts +15 -8
  192. package/src/common/router.ts +49 -23
  193. package/src/common/utils.ts +10 -202
  194. package/src/common/websocket-interface.ts +1 -1
  195. package/src/db/drizzle.test.ts +157 -0
  196. package/src/db/drizzle.ts +170 -79
  197. package/src/db/mod.ts +1 -1
  198. package/src/devtools-loader/index.ts +4 -7
  199. package/src/devtools-loader/serve-devtools.ts +26 -0
  200. package/src/dynamic/instance.ts +32 -0
  201. package/src/dynamic/internal.ts +50 -0
  202. package/src/dynamic/isolate-runtime.ts +64 -0
  203. package/src/dynamic/mod.ts +32 -0
  204. package/src/engine-client/actor-http-client.ts +8 -24
  205. package/src/engine-client/actor-websocket-client.ts +6 -5
  206. package/src/engine-client/api-endpoints.ts +51 -2
  207. package/src/engine-client/api-utils.ts +2 -2
  208. package/src/engine-client/driver.ts +1 -16
  209. package/src/engine-client/mod.ts +6 -44
  210. package/src/engine-client/ws-proxy.ts +9 -4
  211. package/src/inspector/client.browser.ts +127 -15
  212. package/src/inspector/mod.ts +2 -4
  213. package/src/inspector-tab/mod.ts +301 -0
  214. package/src/registry/config/envoy.ts +1 -2
  215. package/src/registry/config/index.ts +41 -55
  216. package/src/registry/index.ts +595 -92
  217. package/src/registry/napi-runtime.ts +365 -23
  218. package/src/registry/native-http.ts +208 -0
  219. package/src/registry/native-validation.ts +10 -12
  220. package/src/registry/native.ts +882 -461
  221. package/src/registry/process-metrics.ts +250 -0
  222. package/src/registry/runtime.ts +250 -8
  223. package/src/registry/wasm-runtime.ts +289 -9
  224. package/src/registry/write-through-proxy.ts +40 -0
  225. package/src/serde.ts +2 -2
  226. package/src/serverless/configure.ts +18 -7
  227. package/src/test/mod.ts +2 -17
  228. package/src/test/ready.ts +22 -0
  229. package/src/unstable/migrations.test.ts +170 -0
  230. package/src/unstable/migrations.ts +141 -0
  231. package/src/utils/endpoint-parser.ts +1 -1
  232. package/src/utils/env-vars.ts +37 -0
  233. package/src/utils/router.ts +1 -1
  234. package/src/utils.ts +4 -2
  235. package/src/workflow/context.ts +683 -242
  236. package/src/workflow/driver.test.ts +62 -0
  237. package/src/workflow/driver.ts +248 -119
  238. package/src/workflow/inspector.ts +12 -3
  239. package/src/workflow/mod.ts +39 -25
  240. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  241. package/dist/tsup/chunk-2VLNKGGO.cjs.map +0 -1
  242. package/dist/tsup/chunk-3OCAQD6G.cjs.map +0 -1
  243. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  244. package/dist/tsup/chunk-5VMFWRHI.cjs.map +0 -1
  245. package/dist/tsup/chunk-5VUPNZ5I.cjs +0 -268
  246. package/dist/tsup/chunk-5VUPNZ5I.cjs.map +0 -1
  247. package/dist/tsup/chunk-B4XQ4QIY.cjs.map +0 -1
  248. package/dist/tsup/chunk-CQYUHACN.js.map +0 -1
  249. package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
  250. package/dist/tsup/chunk-LD5YASJU.cjs.map +0 -1
  251. package/dist/tsup/chunk-LGZR4WHX.js.map +0 -1
  252. package/dist/tsup/chunk-NETDFNJW.js +0 -268
  253. package/dist/tsup/chunk-NETDFNJW.js.map +0 -1
  254. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  255. package/dist/tsup/chunk-RH4D7BO3.js.map +0 -1
  256. package/dist/tsup/chunk-RLAOOSJD.js.map +0 -1
  257. package/dist/tsup/chunk-RSSGGFQA.js.map +0 -1
  258. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  259. package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
  260. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  261. package/dist/tsup/chunk-XAMXMPDR.cjs.map +0 -1
  262. package/dist/tsup/context-A7R0bsZL.d.ts +0 -92
  263. package/dist/tsup/context-CA3r-pf2.d.cts +0 -92
  264. package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
  265. package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
  266. package/src/actor/driver.ts +0 -141
  267. package/src/actor/instance/mod.ts +0 -2492
  268. package/src/drivers/engine/actor-driver.ts +0 -2470
  269. package/src/utils/serve.ts +0 -217
  270. /package/dist/tsup/{chunk-VKWY7G34.js.map → chunk-YNNR7QDA.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';
@@ -23,6 +23,10 @@ interface SqliteExecuteResult extends SqliteQueryResult {
23
23
  changes: number;
24
24
  lastInsertRowId?: number | null;
25
25
  }
26
+ interface SqliteBatchStatement {
27
+ sql: string;
28
+ params?: SqliteBindings;
29
+ }
26
30
  interface SqliteNativeMetrics {
27
31
  requestBuildNs: number;
28
32
  serializeNs: number;
@@ -39,11 +43,19 @@ interface SqliteNativeMetrics {
39
43
  interface SqliteDatabase {
40
44
  exec(sql: string, callback?: (row: unknown[], columns: string[]) => void): Promise<void>;
41
45
  execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
46
+ executeBatch(statements: SqliteBatchStatement[]): Promise<SqliteExecuteResult[]>;
47
+ beginTransaction(timeoutMs?: number): Promise<SqliteTransactionDatabase>;
42
48
  run(sql: string, params?: SqliteBindings): Promise<void>;
43
49
  query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
44
50
  nativeMetrics?(): SqliteNativeMetrics | Promise<SqliteNativeMetrics | null> | null;
45
51
  close(): Promise<void>;
46
52
  }
53
+ interface SqliteTransactionDatabase {
54
+ exec(sql: string, callback?: (row: unknown[], columns: string[]) => void): Promise<void>;
55
+ execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
56
+ commit(): Promise<void>;
57
+ rollback(): Promise<void>;
58
+ }
47
59
  /**
48
60
  * Provider for opening native databases from the active runtime.
49
61
  */
@@ -103,14 +115,17 @@ type DatabaseProvider<DB extends RawAccess> = {
103
115
  /**
104
116
  * Drizzle database client interface (will be extended by drizzle-orm types)
105
117
  */
106
- interface DrizzleDatabaseClient {
107
- }
118
+ type DrizzleDatabaseClient = {};
108
119
  type ExecuteFunction = <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]>;
109
120
  type RawAccess = {
110
121
  /**
111
122
  * Executes a raw SQL query.
112
123
  */
113
124
  execute: ExecuteFunction;
125
+ /** Runs a callback in an isolated SQLite transaction. */
126
+ transaction: <T>(callback: (tx: RawAccess) => Promise<T> | T, options?: {
127
+ timeout?: number;
128
+ }) => Promise<T>;
114
129
  /**
115
130
  * Returns native SQLite metrics when the active runtime supports them.
116
131
  */
@@ -182,6 +197,44 @@ type ActorQuery = z.infer<typeof ActorQuerySchema>;
182
197
  */
183
198
  type CreateRequest = z.infer<typeof CreateRequestSchema>;
184
199
 
200
+ type SchemaHookResult = boolean | Promise<boolean>;
201
+ type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
202
+ interface EventTypeToken<T, TContext = any> {
203
+ readonly _eventType?: T;
204
+ readonly canSubscribe?: SchemaHook<TContext>;
205
+ readonly schema?: PrimitiveSchema;
206
+ }
207
+ interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
208
+ readonly _queueMessage?: TMessage;
209
+ readonly _queueComplete?: TComplete;
210
+ readonly canPublish?: SchemaHook<TContext>;
211
+ readonly message?: PrimitiveSchema;
212
+ readonly complete?: PrimitiveSchema;
213
+ }
214
+ type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
215
+ interface EventSchemaDefinition<TContext = any> {
216
+ schema: PrimitiveSchema;
217
+ canSubscribe?: SchemaHook<TContext>;
218
+ }
219
+ interface QueueSchemaDefinition<TContext = any> {
220
+ message: PrimitiveSchema;
221
+ complete?: PrimitiveSchema;
222
+ canPublish?: SchemaHook<TContext>;
223
+ }
224
+ type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
225
+ type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
226
+ type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
227
+ type QueueSchemaConfig<_TContext = any> = Record<string, QueueSchema>;
228
+ 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;
229
+ type InferSchemaMap<T extends Record<string, unknown>> = {
230
+ [K in keyof T]: InferSchema<T[K]>;
231
+ };
232
+ 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;
233
+ type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
234
+ [K in keyof T]: InferQueueComplete<T[K]>;
235
+ };
236
+ type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
237
+
185
238
  interface DeconstructedError {
186
239
  __type: "ActorError";
187
240
  statusCode: ContentfulStatusCode;
@@ -190,6 +243,7 @@ interface DeconstructedError {
190
243
  code: string;
191
244
  message: string;
192
245
  metadata?: unknown;
246
+ actor?: ActorSpecifier;
193
247
  }
194
248
 
195
249
  interface RivetErrorOptions extends ErrorOptions {
@@ -199,6 +253,14 @@ interface RivetErrorOptions extends ErrorOptions {
199
253
  metadata?: unknown;
200
254
  /** Explicit HTTP status override for router responses. */
201
255
  statusCode?: number;
256
+ /** Actor context associated with this error. */
257
+ actor?: ActorSpecifier;
258
+ }
259
+ /** Identifies the actor that was handling work when an error was produced. */
260
+ interface ActorSpecifier {
261
+ actorId: string;
262
+ generation: number;
263
+ key?: string;
202
264
  }
203
265
  interface UserErrorOptions extends ErrorOptions {
204
266
  /**
@@ -217,6 +279,7 @@ declare class RivetError extends Error {
217
279
  public: boolean;
218
280
  metadata?: unknown;
219
281
  statusCode: number;
282
+ actor?: ActorSpecifier;
220
283
  readonly group: string;
221
284
  readonly code: string;
222
285
  static isRivetError(error: unknown): error is RivetError | DeconstructedError;
@@ -229,44 +292,6 @@ declare class UserError extends RivetError {
229
292
  constructor(message: string, options?: UserErrorOptions);
230
293
  }
231
294
 
232
- type SchemaHookResult = boolean | Promise<boolean>;
233
- type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
234
- interface EventTypeToken<T, TContext = any> {
235
- readonly _eventType?: T;
236
- readonly canSubscribe?: SchemaHook<TContext>;
237
- readonly schema?: PrimitiveSchema;
238
- }
239
- interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
240
- readonly _queueMessage?: TMessage;
241
- readonly _queueComplete?: TComplete;
242
- readonly canPublish?: SchemaHook<TContext>;
243
- readonly message?: PrimitiveSchema;
244
- readonly complete?: PrimitiveSchema;
245
- }
246
- type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
247
- interface EventSchemaDefinition<TContext = any> {
248
- schema: PrimitiveSchema;
249
- canSubscribe?: SchemaHook<TContext>;
250
- }
251
- interface QueueSchemaDefinition<TContext = any> {
252
- message: PrimitiveSchema;
253
- complete?: PrimitiveSchema;
254
- canPublish?: SchemaHook<TContext>;
255
- }
256
- type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
257
- type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
258
- type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
259
- type QueueSchemaConfig<TContext = any> = Record<string, QueueSchema>;
260
- 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;
261
- type InferSchemaMap<T extends Record<string, unknown>> = {
262
- [K in keyof T]: InferSchema<T[K]>;
263
- };
264
- 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;
265
- type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
266
- [K in keyof T]: InferQueueComplete<T[K]>;
267
- };
268
- type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
269
-
270
295
  type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
271
296
  type GetUpgradeWebSocket = () => UpgradeWebSocket;
272
297
 
@@ -296,11 +321,6 @@ interface EngineControlClient {
296
321
  * Test-only helper that simulates an abrupt actor crash.
297
322
  */
298
323
  hardCrashActor?(actorId: string): Promise<void>;
299
- kvGet(actorId: string, key: Uint8Array): Promise<string | null>;
300
- kvBatchGet(actorId: string, keys: Uint8Array[]): Promise<(Uint8Array | null)[]>;
301
- kvBatchPut(actorId: string, entries: [Uint8Array, Uint8Array][]): Promise<void>;
302
- kvBatchDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
303
- kvDeleteRange(actorId: string, start: Uint8Array, end: Uint8Array): Promise<void>;
304
324
  }
305
325
  interface RuntimeDisplayInformation {
306
326
  properties: Record<string, string>;
@@ -374,6 +394,12 @@ interface QueueSendResult<TResponse = unknown> {
374
394
  * @returns {Promise<Response>}
375
395
  */
376
396
  type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
397
+ type IsAny<T> = 0 extends 1 & T ? true : false;
398
+ type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
399
+ type ActorActionMap<R> = {
400
+ [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : NonNullable<R>[K] extends Record<string, unknown> ? ActorActionMap<NonNullable<R>[K]> : never;
401
+ };
402
+ type ActionsOf<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? R : never;
377
403
  interface ActorGatewayOptions {
378
404
  skipReadyWait?: boolean;
379
405
  }
@@ -386,9 +412,7 @@ type ActorWebSocketOptions = ActorGatewayOptions;
386
412
  /**
387
413
  * Maps action methods from actor definition to typed function signatures.
388
414
  */
389
- type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? {
390
- [K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
391
- } : never;
415
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
392
416
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
393
417
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
394
418
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
@@ -399,13 +423,31 @@ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
399
423
  <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
400
424
  (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
401
425
  };
402
- type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
426
+ type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
427
+ send: ActorQueueSend<Record<string, any>>;
428
+ } : AD extends {
429
+ config: {
430
+ queues?: infer Q;
431
+ };
432
+ } ? Q extends QueueSchemaConfig ? {
433
+ send: ActorQueueSend<Q>;
434
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
403
435
  send: ActorQueueSend<Q>;
404
- } : never : never;
405
- type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
436
+ } : {} : {};
437
+ type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
438
+ on: LooseEventSubscribe;
439
+ once: LooseEventSubscribe;
440
+ } : AD extends {
441
+ config: {
442
+ events?: infer E;
443
+ };
444
+ } ? E extends EventSchemaConfig ? {
406
445
  on: ActorEventSubscribe<E>;
407
446
  once: ActorEventSubscribe<E>;
408
- } : never : never;
447
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
448
+ on: ActorEventSubscribe<E>;
449
+ once: ActorEventSubscribe<E>;
450
+ } : {} : {};
409
451
 
410
452
  declare class ActorClientError extends Error {
411
453
  }
@@ -919,6 +961,7 @@ type Client<A extends Registry<any>> = ClientRaw & {
919
961
  };
920
962
 
921
963
  declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
964
+ declare const RAW_STATE_SYMBOL: unique symbol;
922
965
  interface ActorLogger {
923
966
  level: any;
924
967
  fatal: any;
@@ -951,6 +994,10 @@ type ActorKvListOptions<T extends ActorKvValueType = "text", K extends ActorKvKe
951
994
  limit?: number;
952
995
  };
953
996
  type ActorClientFor<T> = T extends Registry<any> ? Client<T> : T;
997
+ /**
998
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`c.db` / `c.sql`)
999
+ * or actor state instead.
1000
+ */
954
1001
  interface ActorKv {
955
1002
  get<T extends ActorKvValueType = "text">(key: Uint8Array | string, options?: ActorKvValueOptions<T>): Promise<ActorKvValueTypeMap[T] | null>;
956
1003
  put<T extends ActorKvValueType = "text">(key: Uint8Array | string, value: Uint8Array | string | ArrayBuffer, options?: ActorKvValueOptions<T>): Promise<void>;
@@ -965,10 +1012,76 @@ interface ActorKv {
965
1012
  [key: string]: any;
966
1013
  }
967
1014
  interface ActorSchedule {
968
- after(duration: number, action: string, ...args: unknown[]): Promise<void>;
969
- at(timestamp: number, action: string, ...args: unknown[]): Promise<void>;
1015
+ after(duration: number, action: string, ...args: unknown[]): Promise<string>;
1016
+ at(timestamp: number, action: string, ...args: unknown[]): Promise<string>;
1017
+ cancel(id: string): Promise<boolean>;
1018
+ get(id: string): Promise<ScheduledEventInfo | undefined>;
1019
+ list(): Promise<ScheduledEventInfo[]>;
1020
+ [key: string]: any;
1021
+ }
1022
+ interface ActorCronSetOptions {
1023
+ name: string;
1024
+ expression: string;
1025
+ action: string;
1026
+ args?: unknown[];
1027
+ timezone?: string;
1028
+ /** Defaults to 100. Set to 0 to disable and clear history. Maximum 1,000. */
1029
+ maxHistory?: number;
1030
+ }
1031
+ interface ActorCronEveryOptions {
1032
+ name: string;
1033
+ /** Fixed interval in milliseconds. Minimum 5,000. */
1034
+ interval: number;
1035
+ action: string;
1036
+ args?: unknown[];
1037
+ /** Defaults to 100. Set to 0 to disable and clear history. Maximum 1,000. */
1038
+ maxHistory?: number;
1039
+ }
1040
+ interface ActorCron {
1041
+ set(options: ActorCronSetOptions): Promise<void>;
1042
+ every(options: ActorCronEveryOptions): Promise<void>;
1043
+ get(name: string): Promise<CronJobInfo | undefined>;
1044
+ list(): Promise<CronJobInfo[]>;
1045
+ delete(name: string): Promise<boolean>;
1046
+ history(name: string, options?: {
1047
+ limit?: number;
1048
+ }): Promise<CronFire[]>;
970
1049
  [key: string]: any;
971
1050
  }
1051
+ interface ScheduledEventInfo {
1052
+ id: string;
1053
+ action: string;
1054
+ args: unknown[];
1055
+ runAt: number;
1056
+ }
1057
+ type CronJobInfo = {
1058
+ name: string;
1059
+ action: string;
1060
+ args: unknown[];
1061
+ nextRunAt: number;
1062
+ lastRunAt?: number;
1063
+ maxHistory: number;
1064
+ } & ({
1065
+ kind: "cron";
1066
+ expression: string;
1067
+ timezone: string;
1068
+ } | {
1069
+ kind: "every";
1070
+ interval: number;
1071
+ });
1072
+ interface CronFire {
1073
+ action: string;
1074
+ scheduledAt: number;
1075
+ firedAt: number;
1076
+ finishedAt?: number;
1077
+ result: "running" | "ok" | "error" | "skipped";
1078
+ error?: {
1079
+ group: string;
1080
+ code: string;
1081
+ message: string;
1082
+ metadata?: unknown;
1083
+ };
1084
+ }
972
1085
  type QueueMessageOf<Name extends string, Body> = {
973
1086
  id: number | bigint;
974
1087
  name: Name;
@@ -1027,7 +1140,7 @@ interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1027
1140
  iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
1028
1141
  [key: string]: any;
1029
1142
  }
1030
- 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>> {
1143
+ 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>> {
1031
1144
  id: string;
1032
1145
  params: TConnParams;
1033
1146
  state: TConnState;
@@ -1038,16 +1151,27 @@ interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TV
1038
1151
  }
1039
1152
  interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1040
1153
  [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
1154
+ /** Returns the raw unwrapped state without the write-through proxy. */
1155
+ [RAW_STATE_SYMBOL](): TState;
1041
1156
  state: TState;
1042
1157
  vars: TVars;
1158
+ /**
1159
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
1160
+ * or actor state instead.
1161
+ */
1043
1162
  readonly kv: ActorKv;
1044
1163
  readonly db: InferDatabaseClient<TDatabase>;
1045
1164
  readonly schedule: ActorSchedule;
1165
+ readonly cron: ActorCron;
1046
1166
  readonly queue: ActorQueue<TQueues>;
1047
1167
  readonly actorId: string;
1048
1168
  readonly name: string;
1049
1169
  readonly key: string[];
1050
1170
  readonly region: string;
1171
+ /** Provisions the experimental Actor Runtime Socket for this actor generation. */
1172
+ actorRuntimeSocket(): Promise<{
1173
+ path: string;
1174
+ }>;
1051
1175
  readonly conns: Map<string, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>>;
1052
1176
  readonly log: ActorLogger;
1053
1177
  readonly abortSignal: AbortSignal;
@@ -1129,7 +1253,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1129
1253
  onBeforeActionResponse: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1130
1254
  onRequest: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1131
1255
  onWebSocket: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1132
- actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>>;
1256
+ actions: z.ZodDefault<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
1133
1257
  actionInputSchemas: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1134
1258
  connParamsSchema: z.ZodOptional<z.ZodAny>;
1135
1259
  events: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
@@ -1144,6 +1268,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1144
1268
  options: z.ZodPrefault<z.ZodObject<{
1145
1269
  name: z.ZodOptional<z.ZodString>;
1146
1270
  icon: z.ZodOptional<z.ZodString>;
1271
+ enableActorRuntimeSocket: z.ZodDefault<z.ZodBoolean>;
1147
1272
  canHibernateWebSocket: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<(request: Request) => boolean, (request: Request) => boolean>]>>;
1148
1273
  createVarsTimeout: z.ZodDefault<z.ZodNumber>;
1149
1274
  createConnStateTimeout: z.ZodDefault<z.ZodNumber>;
@@ -1160,12 +1285,33 @@ declare const ActorConfigSchema: z.ZodObject<{
1160
1285
  noSleep: z.ZodDefault<z.ZodBoolean>;
1161
1286
  sleepTimeout: z.ZodDefault<z.ZodNumber>;
1162
1287
  maxQueueSize: z.ZodDefault<z.ZodNumber>;
1288
+ maxSchedules: z.ZodDefault<z.ZodNumber>;
1163
1289
  maxQueueMessageSize: z.ZodDefault<z.ZodNumber>;
1164
1290
  preloadMaxWorkflowBytes: z.ZodOptional<z.ZodNumber>;
1165
1291
  preloadMaxConnectionsBytes: z.ZodOptional<z.ZodNumber>;
1166
1292
  }, z.core.$strict>>;
1293
+ inspector: z.ZodOptional<z.ZodObject<{
1294
+ tabs: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
1295
+ id: z.ZodString;
1296
+ label: z.ZodString;
1297
+ source: z.ZodString;
1298
+ icon: z.ZodOptional<z.ZodString>;
1299
+ hidden: z.ZodOptional<z.ZodLiteral<false>>;
1300
+ }, z.core.$strict>, z.ZodObject<{
1301
+ id: z.ZodEnum<{
1302
+ state: "state";
1303
+ workflow: "workflow";
1304
+ database: "database";
1305
+ queue: "queue";
1306
+ schedules: "schedules";
1307
+ connections: "connections";
1308
+ console: "console";
1309
+ }>;
1310
+ hidden: z.ZodLiteral<true>;
1311
+ }, z.core.$strict>]>>>;
1312
+ }, z.core.$strict>>;
1167
1313
  }, z.core.$strict>;
1168
- type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1314
+ type CreateState<TState, _TConnParams, _TConnState, _TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1169
1315
  state: TState;
1170
1316
  } | {
1171
1317
  createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
@@ -1178,7 +1324,7 @@ type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase e
1178
1324
  /**
1179
1325
  * @experimental
1180
1326
  */
1181
- type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1327
+ type CreateVars<TState, _TConnParams, _TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1182
1328
  /**
1183
1329
  * @experimental
1184
1330
  */
@@ -1190,7 +1336,10 @@ type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extend
1190
1336
  createVars: (c: CreateVarsContext<TState, TInput, TDatabase, TEvents, TQueues>, driverCtx: any) => TVars | Promise<TVars>;
1191
1337
  } | Record<never, never>;
1192
1338
  interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1193
- [Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, ...args: any[]) => any;
1339
+ [Action: string]: ((c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, ...args: any[]) => any) | Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1340
+ }
1341
+ interface ActionInputSchemas {
1342
+ [Action: string]: PrimitiveSchema | ActionInputSchemas;
1194
1343
  }
1195
1344
  interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> {
1196
1345
  /**
@@ -1342,9 +1491,10 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1342
1491
  onWebSocket?: (c: WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, websocket: UniversalWebSocket) => void | Promise<void>;
1343
1492
  actions?: TActions;
1344
1493
  /**
1345
- * Optional schema map for validating action argument tuples in native runtimes.
1494
+ * Optional schemas for validating action argument tuples in native runtimes.
1495
+ * May mirror nested action groups or use dot-separated low-level action names.
1346
1496
  */
1347
- actionInputSchemas?: Record<string, PrimitiveSchema>;
1497
+ actionInputSchemas?: ActionInputSchemas;
1348
1498
  /**
1349
1499
  * Optional schema for validating connection params in native runtimes.
1350
1500
  */
@@ -1364,19 +1514,21 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1364
1514
  */
1365
1515
  db: TDatabase;
1366
1516
  } | Record<never, never>;
1367
- 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>;
1517
+ 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>;
1368
1518
 
1369
- 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>> {
1370
- readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
1519
+ 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>> {
1520
+ readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
1521
+ }
1522
+ interface AnyActorDefinition {
1523
+ readonly config: any;
1371
1524
  }
1372
- type AnyActorDefinition = BaseActorDefinition<any, any, any, any, any, any, any, any, any>;
1373
1525
  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> {
1374
1526
  #private;
1375
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
1376
- get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
1527
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>);
1528
+ get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
1377
1529
  }
1378
1530
 
1379
- 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>>>;
1531
+ declare const ActorsSchema: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
1380
1532
  type RegistryActors = z$2.infer<typeof ActorsSchema>;
1381
1533
  declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1382
1534
  use: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
@@ -1396,11 +1548,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1396
1548
  }>>, z$2.ZodTransform<"auto" | "native" | "wasm", "auto" | "native" | "wasm" | undefined>>;
1397
1549
  wasm: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1398
1550
  bindings: z$2.ZodOptional<z$2.ZodCustom<typeof _rivetkit_rivetkit_wasm, typeof _rivetkit_rivetkit_wasm>>;
1399
- initInput: z$2.ZodOptional<z$2.ZodCustom<{
1400
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1401
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined, {
1402
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1403
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined>>;
1551
+ 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>>;
1404
1552
  }, z$2.core.$strip>>>;
1405
1553
  sqlite: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodUnion<readonly [z$2.ZodEnum<{
1406
1554
  local: "local";
@@ -1437,6 +1585,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1437
1585
  httpPort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1438
1586
  httpHost: z$2.ZodOptional<z$2.ZodString>;
1439
1587
  startEngine: z$2.ZodDefault<z$2.ZodBoolean>;
1588
+ engineHost: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
1589
+ enginePort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1440
1590
  engineVersion: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
1441
1591
  configurePool: z$2.ZodOptional<z$2.ZodOptional<z$2.ZodObject<{
1442
1592
  name: z$2.ZodOptional<z$2.ZodString>;
@@ -1461,7 +1611,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1461
1611
  envoyKey: z$2.ZodOptional<z$2.ZodString>;
1462
1612
  }, z$2.core.$strip>>>;
1463
1613
  shutdown: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1464
- gracePeriodMs: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1614
+ gracePeriodMs: z$2.ZodOptional<z$2.ZodNumber>;
1465
1615
  disableSignalHandlers: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
1466
1616
  }, z$2.core.$strip>>>;
1467
1617
  }, z$2.core.$strip>, z$2.ZodTransform<{
@@ -1491,9 +1641,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1491
1641
  runtime: "auto" | "native" | "wasm";
1492
1642
  wasm: {
1493
1643
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1494
- initInput?: {
1495
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1496
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1644
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1497
1645
  };
1498
1646
  noWelcome: boolean;
1499
1647
  logging: {
@@ -1504,6 +1652,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1504
1652
  httpBasePath: string;
1505
1653
  httpPort: number;
1506
1654
  startEngine: boolean;
1655
+ engineHost: string;
1656
+ enginePort: number;
1507
1657
  engineVersion: string;
1508
1658
  envoy: {
1509
1659
  poolName: string;
@@ -1512,8 +1662,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1512
1662
  envoyKey?: string | undefined;
1513
1663
  };
1514
1664
  shutdown: {
1515
- gracePeriodMs: number;
1516
1665
  disableSignalHandlers: boolean;
1666
+ gracePeriodMs?: number | undefined;
1517
1667
  };
1518
1668
  staticDir?: string | undefined;
1519
1669
  httpHost?: string | undefined;
@@ -1538,9 +1688,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1538
1688
  runtime: "auto" | "native" | "wasm";
1539
1689
  wasm: {
1540
1690
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1541
- initInput?: {
1542
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1543
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1691
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1544
1692
  };
1545
1693
  sqlite: {
1546
1694
  backend: "local" | "remote";
@@ -1557,6 +1705,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1557
1705
  httpBasePath: string;
1558
1706
  httpPort: number;
1559
1707
  startEngine: boolean;
1708
+ engineHost: string;
1709
+ enginePort: number;
1560
1710
  engineVersion: string;
1561
1711
  serverless: {
1562
1712
  basePath: string;
@@ -1571,8 +1721,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1571
1721
  envoyKey?: string | undefined;
1572
1722
  };
1573
1723
  shutdown: {
1574
- gracePeriodMs: number;
1575
1724
  disableSignalHandlers: boolean;
1725
+ gracePeriodMs?: number | undefined;
1576
1726
  };
1577
1727
  staticDir?: string | undefined;
1578
1728
  httpHost?: string | undefined;
@@ -1592,19 +1742,459 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1592
1742
  use: A;
1593
1743
  };
1594
1744
 
1745
+ declare const handleBrand: unique symbol;
1746
+ type OpaqueHandle<Name extends string> = {
1747
+ readonly [handleBrand]: Name;
1748
+ };
1749
+ type RegistryHandle = OpaqueHandle<"registry">;
1750
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
1751
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
1752
+ type ConnHandle = OpaqueHandle<"conn">;
1753
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
1754
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
1755
+ type SqliteTransactionHandle = OpaqueHandle<"sqliteTransaction">;
1756
+ type RuntimeBytes = Uint8Array;
1757
+ interface RuntimeActorKeySegment {
1758
+ kind: string;
1759
+ stringValue?: string;
1760
+ numberValue?: number;
1761
+ }
1762
+ interface RuntimeHttpRequest {
1763
+ method: string;
1764
+ uri: string;
1765
+ headers?: Record<string, string>;
1766
+ body?: RuntimeBytes;
1767
+ }
1768
+ interface RuntimeHttpResponseBodyStream {
1769
+ cancelled(): Promise<void>;
1770
+ write(chunk: Uint8Array): Promise<void>;
1771
+ end(): Promise<void>;
1772
+ error(message: string): Promise<void>;
1773
+ }
1774
+ interface RuntimeStateDeltaPayload {
1775
+ state?: RuntimeBytes;
1776
+ connHibernation: Array<{
1777
+ connId: string;
1778
+ bytes: RuntimeBytes;
1779
+ }>;
1780
+ connHibernationRemoved: string[];
1781
+ }
1782
+ interface RuntimeWorkflowKvWrite {
1783
+ key: RuntimeBytes;
1784
+ value: RuntimeBytes;
1785
+ }
1786
+ interface RuntimeRequestSaveOpts {
1787
+ immediate?: boolean;
1788
+ maxWaitMs?: number;
1789
+ }
1790
+ interface RuntimeInspectorSnapshot {
1791
+ stateRevision: number;
1792
+ connectionsRevision: number;
1793
+ queueRevision: number;
1794
+ activeConnections: number;
1795
+ queueSize: number;
1796
+ connectedClients: number;
1797
+ }
1798
+ interface RuntimeQueueMessage {
1799
+ id(): bigint;
1800
+ name(): string;
1801
+ body(): RuntimeBytes;
1802
+ createdAt(): number;
1803
+ isCompletable(): boolean;
1804
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
1805
+ }
1806
+ interface RuntimeQueueInspectMessage {
1807
+ id: number;
1808
+ name: string;
1809
+ createdAtMs: number;
1810
+ }
1811
+ interface RuntimeScheduledEventInfo {
1812
+ id: string;
1813
+ action: string;
1814
+ args: RuntimeBytes;
1815
+ runAt: number;
1816
+ }
1817
+ interface RuntimeCronJobInfo {
1818
+ name: string;
1819
+ kind: "cron" | "every";
1820
+ action: string;
1821
+ args: RuntimeBytes;
1822
+ nextRunAt: number;
1823
+ lastRunAt?: number;
1824
+ expression?: string;
1825
+ timezone?: string;
1826
+ intervalMs?: number;
1827
+ maxHistory: number;
1828
+ }
1829
+ interface RuntimeScheduleErrorInfo {
1830
+ group: string;
1831
+ code: string;
1832
+ message: string;
1833
+ metadata?: unknown;
1834
+ }
1835
+ interface RuntimeCronFire {
1836
+ action: string;
1837
+ scheduledAt: number;
1838
+ firedAt: number;
1839
+ finishedAt?: number;
1840
+ result: "running" | "ok" | "error" | "skipped";
1841
+ error?: RuntimeScheduleErrorInfo;
1842
+ }
1843
+ interface RuntimeQueueNextBatchOptions {
1844
+ names?: string[];
1845
+ count?: number;
1846
+ timeoutMs?: number;
1847
+ completable?: boolean;
1848
+ }
1849
+ interface RuntimeQueueWaitOptions {
1850
+ timeoutMs?: number;
1851
+ completable?: boolean;
1852
+ }
1853
+ interface RuntimeQueueEnqueueAndWaitOptions {
1854
+ timeoutMs?: number;
1855
+ }
1856
+ interface RuntimeQueueTryNextBatchOptions {
1857
+ names?: string[];
1858
+ count?: number;
1859
+ completable?: boolean;
1860
+ }
1861
+ interface RuntimeKvListOptions {
1862
+ reverse?: boolean;
1863
+ limit?: number;
1864
+ }
1865
+ interface RuntimeKvEntry {
1866
+ key: RuntimeBytes;
1867
+ value: RuntimeBytes;
1868
+ }
1869
+ type RuntimeSqlBindNoValues = {
1870
+ intValue?: never;
1871
+ floatValue?: never;
1872
+ textValue?: never;
1873
+ blobValue?: never;
1874
+ };
1875
+ type RuntimeSqlBindParam = ({
1876
+ kind: "null";
1877
+ } & RuntimeSqlBindNoValues) | {
1878
+ kind: "int";
1879
+ intValue: number;
1880
+ floatValue?: never;
1881
+ textValue?: never;
1882
+ blobValue?: never;
1883
+ } | {
1884
+ kind: "float";
1885
+ intValue?: never;
1886
+ floatValue: number;
1887
+ textValue?: never;
1888
+ blobValue?: never;
1889
+ } | {
1890
+ kind: "text";
1891
+ intValue?: never;
1892
+ floatValue?: never;
1893
+ textValue: string;
1894
+ blobValue?: never;
1895
+ } | {
1896
+ kind: "blob";
1897
+ intValue?: never;
1898
+ floatValue?: never;
1899
+ textValue?: never;
1900
+ blobValue: RuntimeBytes;
1901
+ };
1902
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
1903
+ interface RuntimeActorRuntimeSocketEndpointInfo {
1904
+ path: string;
1905
+ }
1906
+ interface RuntimeSqlQueryResult {
1907
+ columns: string[];
1908
+ rows: unknown[][];
1909
+ }
1910
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
1911
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
1912
+ changes: number;
1913
+ lastInsertRowId?: number | null;
1914
+ }
1915
+ interface RuntimeSqlBatchStatement {
1916
+ sql: string;
1917
+ params?: RuntimeSqlBindParams;
1918
+ }
1919
+ interface RuntimeSqlRunResult {
1920
+ changes: number;
1921
+ }
1922
+ interface RuntimeActorConfig {
1923
+ name?: string;
1924
+ icon?: string;
1925
+ hasDatabase?: boolean;
1926
+ remoteSqlite?: boolean;
1927
+ enableActorRuntimeSocket?: boolean;
1928
+ hasState?: boolean;
1929
+ canHibernateWebsocket?: boolean;
1930
+ stateSaveIntervalMs?: number;
1931
+ createStateTimeoutMs?: number;
1932
+ onCreateTimeoutMs?: number;
1933
+ createVarsTimeoutMs?: number;
1934
+ createConnStateTimeoutMs?: number;
1935
+ onBeforeConnectTimeoutMs?: number;
1936
+ onConnectTimeoutMs?: number;
1937
+ onMigrateTimeoutMs?: number;
1938
+ onWakeTimeoutMs?: number;
1939
+ onBeforeActorStartTimeoutMs?: number;
1940
+ actionTimeoutMs?: number;
1941
+ onRequestTimeoutMs?: number;
1942
+ sleepTimeoutMs?: number;
1943
+ noSleep?: boolean;
1944
+ sleepGracePeriodMs?: number;
1945
+ connectionLivenessTimeoutMs?: number;
1946
+ connectionLivenessIntervalMs?: number;
1947
+ maxQueueSize?: number;
1948
+ maxSchedules?: number;
1949
+ maxQueueMessageSize?: number;
1950
+ maxIncomingMessageSize?: number;
1951
+ maxOutgoingMessageSize?: number;
1952
+ preloadMaxWorkflowBytes?: number;
1953
+ preloadMaxConnectionsBytes?: number;
1954
+ actions?: Array<{
1955
+ name: string;
1956
+ }>;
1957
+ inspectorTabs?: Array<RuntimeInspectorTabEntry>;
1958
+ }
1959
+ interface RuntimeInspectorTabEntry {
1960
+ id: string;
1961
+ /** Required for custom entries; omitted for built-in hides. */
1962
+ label?: string;
1963
+ /**
1964
+ * Required for custom entries — absolute path to the source directory.
1965
+ * Resolved on the TS side before being handed to the runtime.
1966
+ */
1967
+ source?: string;
1968
+ /** Optional icon id for custom entries. */
1969
+ icon?: string;
1970
+ /** Set to true for built-in hide entries. */
1971
+ hidden?: boolean;
1972
+ }
1973
+ interface RuntimeServeConfig {
1974
+ version: number;
1975
+ endpoint: string;
1976
+ token?: string;
1977
+ namespace: string;
1978
+ poolName: string;
1979
+ engineBinaryPath?: string;
1980
+ engineHost?: string;
1981
+ enginePort?: number;
1982
+ handleInspectorHttpInRuntime?: boolean;
1983
+ inspectorTestToken?: string;
1984
+ serverlessBasePath?: string;
1985
+ serverlessPackageVersion: string;
1986
+ serverlessClientEndpoint?: string;
1987
+ serverlessClientNamespace?: string;
1988
+ serverlessClientToken?: string;
1989
+ serverlessValidateEndpoint: boolean;
1990
+ serverlessMaxStartPayloadBytes: number;
1991
+ }
1992
+ interface RuntimeListenerConfig {
1993
+ port: number;
1994
+ host?: string;
1995
+ publicDir?: string;
1996
+ application?: RuntimeApplicationFetch;
1997
+ }
1998
+ interface RuntimeServerlessRequest {
1999
+ method: string;
2000
+ url: string;
2001
+ headers: Record<string, string>;
2002
+ body: RuntimeBytes;
2003
+ }
2004
+ interface RuntimeApplicationRequest extends RuntimeServerlessRequest {
2005
+ cancelToken?: CancellationTokenHandle;
2006
+ }
2007
+ interface RuntimeApplicationResponse {
2008
+ status: number;
2009
+ headers: Record<string, string>;
2010
+ body?: RuntimeBytes;
2011
+ stream?: boolean;
2012
+ }
2013
+ type RuntimeApplicationFetch = (request: RuntimeApplicationRequest, responseBodyStream?: RuntimeHttpResponseBodyStream) => Promise<RuntimeApplicationResponse>;
2014
+ interface RuntimeApplicationListenerConfig extends RuntimeListenerConfig {
2015
+ application: RuntimeApplicationFetch;
2016
+ }
2017
+ interface RuntimeServerlessResponseHead {
2018
+ status: number;
2019
+ headers: Record<string, string>;
2020
+ }
2021
+ interface RuntimeRegistryRouteResponse {
2022
+ status: number;
2023
+ headers: Record<string, string>;
2024
+ body: RuntimeBytes;
2025
+ }
2026
+ type RuntimeServerlessStreamEvent = {
2027
+ kind: "chunk";
2028
+ chunk?: RuntimeBytes;
2029
+ } | {
2030
+ kind: "end";
2031
+ error?: {
2032
+ group: string;
2033
+ code: string;
2034
+ message: string;
2035
+ };
2036
+ };
2037
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
2038
+ type RuntimeWebSocketEvent = {
2039
+ kind: "message";
2040
+ data: string | RuntimeBytes;
2041
+ binary: boolean;
2042
+ messageIndex?: number;
2043
+ } | {
2044
+ kind: "close";
2045
+ code: number;
2046
+ reason: string;
2047
+ wasClean: boolean;
2048
+ };
2049
+ interface CoreRuntime {
2050
+ readonly kind: "napi" | "wasm";
2051
+ createRegistry(): RegistryHandle;
2052
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
2053
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
2054
+ waitRegistryReady(registry: RegistryHandle): Promise<void>;
2055
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
2056
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
2057
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
2058
+ serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
2059
+ serveApplicationListener(registry: RegistryHandle, listener: RuntimeApplicationListenerConfig, config: RuntimeServeConfig): Promise<void>;
2060
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
2061
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
2062
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
2063
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
2064
+ createCancellationToken(): CancellationTokenHandle;
2065
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
2066
+ cancelCancellationToken(token: CancellationTokenHandle): void;
2067
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
2068
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
2069
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
2070
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
2071
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
2072
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
2073
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
2074
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
2075
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
2076
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
2077
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
2078
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
2079
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
2080
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
2081
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
2082
+ actorSaveStateAndWorkflowBatch(ctx: ActorContextHandle, writes: RuntimeWorkflowKvWrite[]): Promise<void>;
2083
+ actorId(ctx: ActorContextHandle): string;
2084
+ actorName(ctx: ActorContextHandle): string;
2085
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
2086
+ actorRegion(ctx: ActorContextHandle): string;
2087
+ actorSleep(ctx: ActorContextHandle): void;
2088
+ actorDestroy(ctx: ActorContextHandle): void;
2089
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
2090
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
2091
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
2092
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
2093
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
2094
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
2095
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
2096
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
2097
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
2098
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
2099
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
2100
+ actorRuntimeState(ctx: ActorContextHandle): object;
2101
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
2102
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
2103
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
2104
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
2105
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
2106
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
2107
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
2108
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
2109
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
2110
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
2111
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
2112
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
2113
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
2114
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
2115
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
2116
+ actorSqlExecuteBatch(ctx: ActorContextHandle, statements: RuntimeSqlBatchStatement[]): Promise<RuntimeSqlExecuteResult[]>;
2117
+ actorSqlBeginTransaction(ctx: ActorContextHandle, timeoutMs?: number): Promise<SqliteTransactionHandle>;
2118
+ actorSqlTransactionExec(transaction: SqliteTransactionHandle, sql: string): Promise<RuntimeSqlExecResult>;
2119
+ actorSqlTransactionExecute(transaction: SqliteTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
2120
+ actorSqlTransactionCommit(transaction: SqliteTransactionHandle): Promise<void>;
2121
+ actorSqlTransactionRollback(transaction: SqliteTransactionHandle): Promise<void>;
2122
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
2123
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
2124
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
2125
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
2126
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
2127
+ actorRuntimeSocketProvision(ctx: ActorContextHandle): Promise<RuntimeActorRuntimeSocketEndpointInfo>;
2128
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
2129
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
2130
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
2131
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
2132
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
2133
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
2134
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
2135
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
2136
+ actorQueueReset(ctx: ActorContextHandle): Promise<void>;
2137
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
2138
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
2139
+ actorScheduleCancel(ctx: ActorContextHandle, id: string): Promise<boolean>;
2140
+ actorScheduleGet(ctx: ActorContextHandle, id: string): Promise<RuntimeScheduledEventInfo | undefined>;
2141
+ actorScheduleList(ctx: ActorContextHandle): Promise<RuntimeScheduledEventInfo[]>;
2142
+ actorCronSet(ctx: ActorContextHandle, name: string, expression: string, timezone: string | undefined, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
2143
+ actorCronEvery(ctx: ActorContextHandle, name: string, intervalMs: number, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
2144
+ actorCronGet(ctx: ActorContextHandle, name: string): Promise<RuntimeCronJobInfo | undefined>;
2145
+ actorCronList(ctx: ActorContextHandle): Promise<RuntimeCronJobInfo[]>;
2146
+ actorCronDelete(ctx: ActorContextHandle, name: string): Promise<boolean>;
2147
+ actorCronHistory(ctx: ActorContextHandle, name: string, limit: number | undefined): Promise<RuntimeCronFire[]>;
2148
+ connId(conn: ConnHandle): string;
2149
+ connParams(conn: ConnHandle): RuntimeBytes;
2150
+ connState(conn: ConnHandle): RuntimeBytes;
2151
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
2152
+ connIsHibernatable(conn: ConnHandle): boolean;
2153
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
2154
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
2155
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
2156
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
2157
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
2158
+ }
2159
+
2160
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
2161
+ runtime: CoreRuntime;
2162
+ registry: RegistryHandle;
2163
+ serveConfig: RuntimeServeConfig;
2164
+ }>;
2165
+
1595
2166
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
1596
2167
  interface ServerlessHandler {
1597
2168
  fetch: FetchHandler;
1598
2169
  }
1599
- interface RegistryDiagnostics {
1600
- mode: string;
1601
- envoyActiveActorCount?: number | null;
2170
+ interface RegistryApplication {
2171
+ fetch: FetchHandler;
2172
+ }
2173
+ interface RegistryListenOptions {
2174
+ port?: number;
2175
+ host?: string;
2176
+ publicDir?: string;
2177
+ application?: RegistryApplication;
2178
+ }
2179
+ interface RegistryRoutes {
2180
+ health(): Promise<Response>;
2181
+ metadata(): Promise<Response>;
2182
+ prometheusMetrics(request?: Request): Promise<Response>;
2183
+ }
2184
+ /**
2185
+ * Injectable dependencies for {@link Registry}. Production code uses the
2186
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
2187
+ * orchestration against a fake `CoreRuntime` without an engine.
2188
+ */
2189
+ interface RegistryDeps {
2190
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
1602
2191
  }
1603
2192
  declare class Registry<A extends RegistryActors> {
1604
2193
  #private;
2194
+ readonly routes: RegistryRoutes;
1605
2195
  get config(): RegistryConfigInput<A>;
1606
2196
  parseConfig(): RegistryConfig;
1607
- constructor(config: RegistryConfigInput<A>);
2197
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
1608
2198
  /**
1609
2199
  * Handle an incoming HTTP request for serverless deployments.
1610
2200
  *
@@ -1625,11 +2215,64 @@ declare class Registry<A extends RegistryActors> {
1625
2215
  * ```
1626
2216
  */
1627
2217
  serve(): ServerlessHandler;
1628
- diagnostics(): Promise<RegistryDiagnostics>;
2218
+ /**
2219
+ * Bind an HTTP listener provided by the native (Rust) runtime and serve
2220
+ * the registry's serverless endpoints over it. Resolves only after the
2221
+ * registry is shut down (SIGINT/SIGTERM or `nativeRegistry.shutdown()`).
2222
+ *
2223
+ * @param opts.port Port to listen on. Defaults to `process.env.RIVET_PORT`
2224
+ * if set, otherwise 3000.
2225
+ * @param opts.host Address to bind. Defaults to `0.0.0.0`.
2226
+ * @param opts.publicDir If set, serves static files from this directory
2227
+ * as a fallback below the framework routes.
2228
+ * @param opts.application If set, handles requests that do not match a
2229
+ * framework route.
2230
+ *
2231
+ * @example
2232
+ * ```ts
2233
+ * await registry.listen();
2234
+ * await registry.listen({ application: app });
2235
+ * ```
2236
+ */
2237
+ listen(opts?: RegistryListenOptions): Promise<void>;
2238
+ /**
2239
+ * Gracefully drains all live registries.
2240
+ *
2241
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
2242
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
2243
+ * waits for the serve promise to resolve, all bounded by the shutdown
2244
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
2245
+ * signal or exit the process. The caller owns process lifetime.
2246
+ *
2247
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
2248
+ * call even if nothing has been started.
2249
+ *
2250
+ * @example
2251
+ * ```ts
2252
+ * const registry = setup({ use: { counter } });
2253
+ * registry.start();
2254
+ * // ...later, on your own shutdown trigger:
2255
+ * await registry.shutdown();
2256
+ * ```
2257
+ */
2258
+ shutdown(): Promise<void>;
1629
2259
  startEnvoy(): void;
2260
+ /**
2261
+ * Starts the serverful registry if needed and waits until its envoy has
2262
+ * registered with the Engine. Repeated and concurrent calls share one
2263
+ * startup lifecycle and readiness promise.
2264
+ *
2265
+ * Unlike {@link start}, this reports startup failures and does not resolve
2266
+ * merely because an HTTP health endpoint is listening.
2267
+ */
2268
+ startAndWait(): Promise<void>;
1630
2269
  /**
1631
2270
  * Starts the actor envoy for standalone server deployments.
1632
2271
  *
2272
+ * Set `RIVETKIT_RUNTIME_MODE=serverless` to instead bind an HTTP listener
2273
+ * via `listen()` (Mode B). Mode A (envoy) and Mode B (listener) are
2274
+ * mutually exclusive per registry instance.
2275
+ *
1633
2276
  * @example
1634
2277
  * ```ts
1635
2278
  * const registry = setup({ use: { counter } });