rivetkit 0.0.0-main.72cbc7c → 0.0.0-main.79e97f1

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 (265) hide show
  1. package/dist/browser/client.d.ts +721 -88
  2. package/dist/browser/client.js +684 -604
  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 +4 -2
  8. package/dist/tsup/actor/errors.cjs.map +1 -1
  9. package/dist/tsup/actor/errors.d.cts +1 -1
  10. package/dist/tsup/actor/errors.d.ts +1 -1
  11. package/dist/tsup/actor/errors.js +3 -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 +719 -87
  15. package/dist/tsup/agent-os/index.d.ts +719 -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-OFP533QU.cjs → chunk-42QKF4NL.cjs} +3 -3
  19. package/dist/tsup/{chunk-OFP533QU.cjs.map → chunk-42QKF4NL.cjs.map} +1 -1
  20. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-4FC7TVS6.cjs} +8 -4
  21. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  22. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-7AFZMFPQ.js} +15 -1
  23. package/dist/tsup/chunk-7AFZMFPQ.js.map +1 -0
  24. package/dist/tsup/{chunk-HSTK7OBI.js → chunk-AXDEBZFM.js} +13 -7
  25. package/dist/tsup/chunk-AXDEBZFM.js.map +1 -0
  26. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-HNHLBM3Y.cjs} +192 -15
  27. package/dist/tsup/chunk-HNHLBM3Y.cjs.map +1 -0
  28. package/dist/tsup/{chunk-EI55QOUB.js → chunk-J2TA4HLA.js} +235 -245
  29. package/dist/tsup/chunk-J2TA4HLA.js.map +1 -0
  30. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-JI6GZ2C2.js} +3 -12
  31. package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
  32. package/dist/tsup/{chunk-4KSYSQHX.js → chunk-KUWK4UNH.js} +2 -2
  33. package/dist/tsup/{chunk-YQQ2ZDKT.cjs → chunk-L3YK4JAQ.cjs} +378 -388
  34. package/dist/tsup/chunk-L3YK4JAQ.cjs.map +1 -0
  35. package/dist/tsup/{chunk-WDO5Y6PO.cjs → chunk-LSLRMWDP.cjs} +17 -11
  36. package/dist/tsup/chunk-LSLRMWDP.cjs.map +1 -0
  37. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-MYWZCDML.cjs} +3 -12
  38. package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
  39. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-QWLJCP3X.js} +190 -13
  40. package/dist/tsup/chunk-QWLJCP3X.js.map +1 -0
  41. package/dist/tsup/{chunk-OQSBGFIB.cjs → chunk-ROANIJSQ.cjs} +10 -10
  42. package/dist/tsup/chunk-ROANIJSQ.cjs.map +1 -0
  43. package/dist/tsup/{chunk-5DGOZZKE.cjs → chunk-SHGGJE3M.cjs} +44 -9
  44. package/dist/tsup/chunk-SHGGJE3M.cjs.map +1 -0
  45. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-UEULFXUI.cjs} +16 -2
  46. package/dist/tsup/chunk-UEULFXUI.cjs.map +1 -0
  47. package/dist/tsup/{chunk-O25KOT5C.cjs → chunk-ULWCXOND.cjs} +475 -24
  48. package/dist/tsup/chunk-ULWCXOND.cjs.map +1 -0
  49. package/dist/tsup/{chunk-DFHHCPH7.js → chunk-ULYPJPHB.js} +42 -7
  50. package/dist/tsup/chunk-ULYPJPHB.js.map +1 -0
  51. package/dist/tsup/{chunk-GDKM56PU.js → chunk-Y5BCFECV.js} +466 -15
  52. package/dist/tsup/chunk-Y5BCFECV.js.map +1 -0
  53. package/dist/tsup/{chunk-PJSE5ZGN.js → chunk-YTE3YP7Q.js} +6 -6
  54. package/dist/tsup/chunk-YTE3YP7Q.js.map +1 -0
  55. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-ZZ3WBRPD.js} +7 -3
  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 -6
  60. package/dist/tsup/client/mod.d.ts +7 -6
  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-CRwCN3Ok.d.ts → config-CUymbyM6.d.ts} +758 -56
  72. package/dist/tsup/{config-voObiSep.d.cts → 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 +2031 -533
  106. package/dist/tsup/mod.cjs.map +1 -1
  107. package/dist/tsup/mod.d.cts +6 -6
  108. package/dist/tsup/mod.d.ts +6 -6
  109. package/dist/tsup/mod.js +1953 -455
  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 -5
  114. package/dist/tsup/test/mod.d.ts +5 -5
  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-DVekpm4I.d.cts → utils-CqDnC_PS.d.cts} +2 -1
  125. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-CqDnC_PS.d.ts} +2 -1
  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 -9
  135. package/dist/tsup/workflow/mod.d.ts +9 -9
  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 +20 -3
  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 +11 -36
  156. package/src/client/actor-handle.ts +72 -52
  157. package/src/client/actor-query.ts +5 -5
  158. package/src/client/client.ts +24 -11
  159. package/src/client/errors.ts +1 -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 +19 -8
  164. package/src/client/resolve-gateway-target.ts +1 -1
  165. package/src/client/utils.ts +2 -7
  166. package/src/common/actor-router-consts.ts +1 -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/inspector/v5.ts +1016 -0
  174. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  175. package/src/common/bare/transport/v1.ts +694 -542
  176. package/src/common/client-protocol-versioned.ts +66 -64
  177. package/src/common/database/config.ts +26 -8
  178. package/src/common/database/mod.test.ts +148 -59
  179. package/src/common/database/mod.ts +93 -23
  180. package/src/common/database/native-database.test.ts +9 -0
  181. package/src/common/database/native-database.ts +152 -1
  182. package/src/common/database/shared.ts +16 -0
  183. package/src/common/encoding.ts +278 -34
  184. package/src/common/engine.ts +28 -1
  185. package/src/common/eventsource.ts +1 -1
  186. package/src/common/fetch-like.ts +49 -0
  187. package/src/common/inline-websocket-adapter.ts +14 -13
  188. package/src/common/log.ts +15 -8
  189. package/src/common/router.ts +13 -17
  190. package/src/common/utils.ts +1 -150
  191. package/src/common/websocket-interface.ts +1 -1
  192. package/src/db/drizzle.test.ts +157 -0
  193. package/src/db/drizzle.ts +170 -79
  194. package/src/db/mod.ts +1 -1
  195. package/src/devtools-loader/index.ts +4 -7
  196. package/src/devtools-loader/serve-devtools.ts +26 -0
  197. package/src/dynamic/instance.ts +32 -0
  198. package/src/dynamic/internal.ts +50 -0
  199. package/src/dynamic/isolate-runtime.ts +64 -0
  200. package/src/dynamic/mod.ts +32 -0
  201. package/src/engine-client/actor-http-client.ts +8 -24
  202. package/src/engine-client/actor-websocket-client.ts +6 -5
  203. package/src/engine-client/api-endpoints.ts +51 -2
  204. package/src/engine-client/api-utils.ts +2 -2
  205. package/src/engine-client/driver.ts +1 -16
  206. package/src/engine-client/mod.ts +6 -44
  207. package/src/engine-client/ws-proxy.ts +9 -4
  208. package/src/inspector/client.browser.ts +127 -15
  209. package/src/inspector/mod.ts +2 -4
  210. package/src/inspector-tab/mod.ts +301 -0
  211. package/src/registry/config/envoy.ts +1 -2
  212. package/src/registry/config/index.ts +41 -55
  213. package/src/registry/index.ts +595 -92
  214. package/src/registry/napi-runtime.ts +359 -23
  215. package/src/registry/native-http.ts +208 -0
  216. package/src/registry/native-validation.ts +10 -12
  217. package/src/registry/native.ts +879 -311
  218. package/src/registry/process-metrics.ts +250 -0
  219. package/src/registry/runtime.ts +249 -8
  220. package/src/registry/wasm-runtime.ts +280 -9
  221. package/src/registry/write-through-proxy.ts +40 -0
  222. package/src/serde.ts +2 -2
  223. package/src/serverless/configure.ts +18 -7
  224. package/src/test/mod.ts +2 -17
  225. package/src/test/ready.ts +22 -0
  226. package/src/unstable/migrations.test.ts +170 -0
  227. package/src/unstable/migrations.ts +141 -0
  228. package/src/utils/endpoint-parser.ts +1 -1
  229. package/src/utils/env-vars.ts +37 -0
  230. package/src/utils/router.ts +1 -1
  231. package/src/utils.ts +4 -2
  232. package/src/workflow/context.ts +683 -242
  233. package/src/workflow/driver.test.ts +62 -0
  234. package/src/workflow/driver.ts +248 -119
  235. package/src/workflow/inspector.ts +12 -3
  236. package/src/workflow/mod.ts +39 -25
  237. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  238. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  239. package/dist/tsup/chunk-5DGOZZKE.cjs.map +0 -1
  240. package/dist/tsup/chunk-DFHHCPH7.js.map +0 -1
  241. package/dist/tsup/chunk-EI55QOUB.js.map +0 -1
  242. package/dist/tsup/chunk-GDKM56PU.js.map +0 -1
  243. package/dist/tsup/chunk-HSTK7OBI.js.map +0 -1
  244. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  245. package/dist/tsup/chunk-LD5YASJU.cjs.map +0 -1
  246. package/dist/tsup/chunk-LI5MR5BD.js +0 -268
  247. package/dist/tsup/chunk-LI5MR5BD.js.map +0 -1
  248. package/dist/tsup/chunk-NDY6IZJ3.cjs +0 -268
  249. package/dist/tsup/chunk-NDY6IZJ3.cjs.map +0 -1
  250. package/dist/tsup/chunk-O25KOT5C.cjs.map +0 -1
  251. package/dist/tsup/chunk-OQSBGFIB.cjs.map +0 -1
  252. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  253. package/dist/tsup/chunk-PJSE5ZGN.js.map +0 -1
  254. package/dist/tsup/chunk-QAZLM4WT.cjs.map +0 -1
  255. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  256. package/dist/tsup/chunk-WDO5Y6PO.cjs.map +0 -1
  257. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  258. package/dist/tsup/chunk-YQQ2ZDKT.cjs.map +0 -1
  259. package/dist/tsup/context-BPFYVZ5g.d.ts +0 -92
  260. package/dist/tsup/context-D0YF1MQq.d.cts +0 -92
  261. package/src/actor/driver.ts +0 -141
  262. package/src/actor/instance/mod.ts +0 -2492
  263. package/src/drivers/engine/actor-driver.ts +0 -2460
  264. package/src/utils/serve.ts +0 -217
  265. /package/dist/tsup/{chunk-4KSYSQHX.js.map → chunk-KUWK4UNH.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;
@@ -239,44 +292,6 @@ declare class UserError extends RivetError {
239
292
  constructor(message: string, options?: UserErrorOptions);
240
293
  }
241
294
 
242
- type SchemaHookResult = boolean | Promise<boolean>;
243
- type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
244
- interface EventTypeToken<T, TContext = any> {
245
- readonly _eventType?: T;
246
- readonly canSubscribe?: SchemaHook<TContext>;
247
- readonly schema?: PrimitiveSchema;
248
- }
249
- interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
250
- readonly _queueMessage?: TMessage;
251
- readonly _queueComplete?: TComplete;
252
- readonly canPublish?: SchemaHook<TContext>;
253
- readonly message?: PrimitiveSchema;
254
- readonly complete?: PrimitiveSchema;
255
- }
256
- type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
257
- interface EventSchemaDefinition<TContext = any> {
258
- schema: PrimitiveSchema;
259
- canSubscribe?: SchemaHook<TContext>;
260
- }
261
- interface QueueSchemaDefinition<TContext = any> {
262
- message: PrimitiveSchema;
263
- complete?: PrimitiveSchema;
264
- canPublish?: SchemaHook<TContext>;
265
- }
266
- type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
267
- type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
268
- type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
269
- type QueueSchemaConfig<TContext = any> = Record<string, QueueSchema>;
270
- type InferSchema<T> = T extends QueueSchemaDefinition<any> ? InferSchema<T["message"]> : T extends QueueTypeToken<infer M, unknown, any> ? M : T extends EventSchemaDefinition<any> ? InferSchema<T["schema"]> : T extends StandardSchemaV1<any, infer O> ? O : T extends EventTypeToken<infer R, any> ? R : never;
271
- type InferSchemaMap<T extends Record<string, unknown>> = {
272
- [K in keyof T]: InferSchema<T[K]>;
273
- };
274
- type InferQueueComplete<T> = T extends QueueTypeToken<unknown, infer C, any> ? [C] extends [never] ? never : C : T extends QueueSchemaDefinition<any> ? T["complete"] extends PrimitiveSchema ? InferSchema<T["complete"]> : never : never;
275
- type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
276
- [K in keyof T]: InferQueueComplete<T[K]>;
277
- };
278
- type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
279
-
280
295
  type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
281
296
  type GetUpgradeWebSocket = () => UpgradeWebSocket;
282
297
 
@@ -306,11 +321,6 @@ interface EngineControlClient {
306
321
  * Test-only helper that simulates an abrupt actor crash.
307
322
  */
308
323
  hardCrashActor?(actorId: string): Promise<void>;
309
- kvGet(actorId: string, key: Uint8Array): Promise<string | null>;
310
- kvBatchGet(actorId: string, keys: Uint8Array[]): Promise<(Uint8Array | null)[]>;
311
- kvBatchPut(actorId: string, entries: [Uint8Array, Uint8Array][]): Promise<void>;
312
- kvBatchDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
313
- kvDeleteRange(actorId: string, start: Uint8Array, end: Uint8Array): Promise<void>;
314
324
  }
315
325
  interface RuntimeDisplayInformation {
316
326
  properties: Record<string, string>;
@@ -384,6 +394,12 @@ interface QueueSendResult<TResponse = unknown> {
384
394
  * @returns {Promise<Response>}
385
395
  */
386
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;
387
403
  interface ActorGatewayOptions {
388
404
  skipReadyWait?: boolean;
389
405
  }
@@ -396,9 +412,7 @@ type ActorWebSocketOptions = ActorGatewayOptions;
396
412
  /**
397
413
  * Maps action methods from actor definition to typed function signatures.
398
414
  */
399
- type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? {
400
- [K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
401
- } : never;
415
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
402
416
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
403
417
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
404
418
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
@@ -409,13 +423,31 @@ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
409
423
  <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
410
424
  (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
411
425
  };
412
- 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 ? {
413
433
  send: ActorQueueSend<Q>;
414
- } : never : never;
415
- type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
434
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
435
+ send: ActorQueueSend<Q>;
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 ? {
445
+ on: ActorEventSubscribe<E>;
446
+ once: ActorEventSubscribe<E>;
447
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
416
448
  on: ActorEventSubscribe<E>;
417
449
  once: ActorEventSubscribe<E>;
418
- } : never : never;
450
+ } : {} : {};
419
451
 
420
452
  declare class ActorClientError extends Error {
421
453
  }
@@ -929,6 +961,7 @@ type Client<A extends Registry<any>> = ClientRaw & {
929
961
  };
930
962
 
931
963
  declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
964
+ declare const RAW_STATE_SYMBOL: unique symbol;
932
965
  interface ActorLogger {
933
966
  level: any;
934
967
  fatal: any;
@@ -961,6 +994,10 @@ type ActorKvListOptions<T extends ActorKvValueType = "text", K extends ActorKvKe
961
994
  limit?: number;
962
995
  };
963
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
+ */
964
1001
  interface ActorKv {
965
1002
  get<T extends ActorKvValueType = "text">(key: Uint8Array | string, options?: ActorKvValueOptions<T>): Promise<ActorKvValueTypeMap[T] | null>;
966
1003
  put<T extends ActorKvValueType = "text">(key: Uint8Array | string, value: Uint8Array | string | ArrayBuffer, options?: ActorKvValueOptions<T>): Promise<void>;
@@ -975,10 +1012,76 @@ interface ActorKv {
975
1012
  [key: string]: any;
976
1013
  }
977
1014
  interface ActorSchedule {
978
- after(duration: number, action: string, ...args: unknown[]): Promise<void>;
979
- 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[]>;
980
1049
  [key: string]: any;
981
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
+ }
982
1085
  type QueueMessageOf<Name extends string, Body> = {
983
1086
  id: number | bigint;
984
1087
  name: Name;
@@ -1037,7 +1140,7 @@ interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1037
1140
  iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
1038
1141
  [key: string]: any;
1039
1142
  }
1040
- interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TVars = unknown, TInput = unknown, TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
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>> {
1041
1144
  id: string;
1042
1145
  params: TConnParams;
1043
1146
  state: TConnState;
@@ -1048,16 +1151,27 @@ interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TV
1048
1151
  }
1049
1152
  interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1050
1153
  [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
1154
+ /** Returns the raw unwrapped state without the write-through proxy. */
1155
+ [RAW_STATE_SYMBOL](): TState;
1051
1156
  state: TState;
1052
1157
  vars: TVars;
1158
+ /**
1159
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
1160
+ * or actor state instead.
1161
+ */
1053
1162
  readonly kv: ActorKv;
1054
1163
  readonly db: InferDatabaseClient<TDatabase>;
1055
1164
  readonly schedule: ActorSchedule;
1165
+ readonly cron: ActorCron;
1056
1166
  readonly queue: ActorQueue<TQueues>;
1057
1167
  readonly actorId: string;
1058
1168
  readonly name: string;
1059
1169
  readonly key: string[];
1060
1170
  readonly region: string;
1171
+ /** Provisions the experimental Actor Runtime Socket for this actor generation. */
1172
+ actorRuntimeSocket(): Promise<{
1173
+ path: string;
1174
+ }>;
1061
1175
  readonly conns: Map<string, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>>;
1062
1176
  readonly log: ActorLogger;
1063
1177
  readonly abortSignal: AbortSignal;
@@ -1139,7 +1253,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1139
1253
  onBeforeActionResponse: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1140
1254
  onRequest: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1141
1255
  onWebSocket: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1142
- 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>>>;
1143
1257
  actionInputSchemas: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1144
1258
  connParamsSchema: z.ZodOptional<z.ZodAny>;
1145
1259
  events: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
@@ -1154,6 +1268,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1154
1268
  options: z.ZodPrefault<z.ZodObject<{
1155
1269
  name: z.ZodOptional<z.ZodString>;
1156
1270
  icon: z.ZodOptional<z.ZodString>;
1271
+ enableActorRuntimeSocket: z.ZodDefault<z.ZodBoolean>;
1157
1272
  canHibernateWebSocket: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<(request: Request) => boolean, (request: Request) => boolean>]>>;
1158
1273
  createVarsTimeout: z.ZodDefault<z.ZodNumber>;
1159
1274
  createConnStateTimeout: z.ZodDefault<z.ZodNumber>;
@@ -1170,12 +1285,33 @@ declare const ActorConfigSchema: z.ZodObject<{
1170
1285
  noSleep: z.ZodDefault<z.ZodBoolean>;
1171
1286
  sleepTimeout: z.ZodDefault<z.ZodNumber>;
1172
1287
  maxQueueSize: z.ZodDefault<z.ZodNumber>;
1288
+ maxSchedules: z.ZodDefault<z.ZodNumber>;
1173
1289
  maxQueueMessageSize: z.ZodDefault<z.ZodNumber>;
1174
1290
  preloadMaxWorkflowBytes: z.ZodOptional<z.ZodNumber>;
1175
1291
  preloadMaxConnectionsBytes: z.ZodOptional<z.ZodNumber>;
1176
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>>;
1177
1313
  }, z.core.$strict>;
1178
- 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> = {
1179
1315
  state: TState;
1180
1316
  } | {
1181
1317
  createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
@@ -1188,7 +1324,7 @@ type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase e
1188
1324
  /**
1189
1325
  * @experimental
1190
1326
  */
1191
- 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> = {
1192
1328
  /**
1193
1329
  * @experimental
1194
1330
  */
@@ -1200,7 +1336,10 @@ type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extend
1200
1336
  createVars: (c: CreateVarsContext<TState, TInput, TDatabase, TEvents, TQueues>, driverCtx: any) => TVars | Promise<TVars>;
1201
1337
  } | Record<never, never>;
1202
1338
  interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1203
- [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;
1204
1343
  }
1205
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>> {
1206
1345
  /**
@@ -1352,9 +1491,10 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1352
1491
  onWebSocket?: (c: WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, websocket: UniversalWebSocket) => void | Promise<void>;
1353
1492
  actions?: TActions;
1354
1493
  /**
1355
- * 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.
1356
1496
  */
1357
- actionInputSchemas?: Record<string, PrimitiveSchema>;
1497
+ actionInputSchemas?: ActionInputSchemas;
1358
1498
  /**
1359
1499
  * Optional schema for validating connection params in native runtimes.
1360
1500
  */
@@ -1374,19 +1514,21 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1374
1514
  */
1375
1515
  db: TDatabase;
1376
1516
  } | Record<never, never>;
1377
- type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onMigrate" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
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>;
1378
1518
 
1379
- interface BaseActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> {
1380
- readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
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;
1381
1524
  }
1382
- type AnyActorDefinition = BaseActorDefinition<any, any, any, any, any, any, any, any, any>;
1383
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> {
1384
1526
  #private;
1385
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
1386
- get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
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>;
1387
1529
  }
1388
1530
 
1389
- declare const ActorsSchema: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<BaseActorDefinition<any, any, any, any, any, any, any, any, any>, BaseActorDefinition<any, any, any, any, any, any, any, any, any>>>;
1531
+ declare const ActorsSchema: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
1390
1532
  type RegistryActors = z$2.infer<typeof ActorsSchema>;
1391
1533
  declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1392
1534
  use: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
@@ -1406,11 +1548,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1406
1548
  }>>, z$2.ZodTransform<"auto" | "native" | "wasm", "auto" | "native" | "wasm" | undefined>>;
1407
1549
  wasm: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1408
1550
  bindings: z$2.ZodOptional<z$2.ZodCustom<typeof _rivetkit_rivetkit_wasm, typeof _rivetkit_rivetkit_wasm>>;
1409
- initInput: z$2.ZodOptional<z$2.ZodCustom<{
1410
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1411
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined, {
1412
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1413
- } | _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>>;
1414
1552
  }, z$2.core.$strip>>>;
1415
1553
  sqlite: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodUnion<readonly [z$2.ZodEnum<{
1416
1554
  local: "local";
@@ -1447,6 +1585,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1447
1585
  httpPort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1448
1586
  httpHost: z$2.ZodOptional<z$2.ZodString>;
1449
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>>;
1450
1590
  engineVersion: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
1451
1591
  configurePool: z$2.ZodOptional<z$2.ZodOptional<z$2.ZodObject<{
1452
1592
  name: z$2.ZodOptional<z$2.ZodString>;
@@ -1471,7 +1611,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1471
1611
  envoyKey: z$2.ZodOptional<z$2.ZodString>;
1472
1612
  }, z$2.core.$strip>>>;
1473
1613
  shutdown: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1474
- gracePeriodMs: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1614
+ gracePeriodMs: z$2.ZodOptional<z$2.ZodNumber>;
1475
1615
  disableSignalHandlers: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
1476
1616
  }, z$2.core.$strip>>>;
1477
1617
  }, z$2.core.$strip>, z$2.ZodTransform<{
@@ -1501,9 +1641,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1501
1641
  runtime: "auto" | "native" | "wasm";
1502
1642
  wasm: {
1503
1643
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1504
- initInput?: {
1505
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1506
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1644
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1507
1645
  };
1508
1646
  noWelcome: boolean;
1509
1647
  logging: {
@@ -1514,6 +1652,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1514
1652
  httpBasePath: string;
1515
1653
  httpPort: number;
1516
1654
  startEngine: boolean;
1655
+ engineHost: string;
1656
+ enginePort: number;
1517
1657
  engineVersion: string;
1518
1658
  envoy: {
1519
1659
  poolName: string;
@@ -1522,8 +1662,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1522
1662
  envoyKey?: string | undefined;
1523
1663
  };
1524
1664
  shutdown: {
1525
- gracePeriodMs: number;
1526
1665
  disableSignalHandlers: boolean;
1666
+ gracePeriodMs?: number | undefined;
1527
1667
  };
1528
1668
  staticDir?: string | undefined;
1529
1669
  httpHost?: string | undefined;
@@ -1548,9 +1688,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1548
1688
  runtime: "auto" | "native" | "wasm";
1549
1689
  wasm: {
1550
1690
  bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1551
- initInput?: {
1552
- module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
1553
- } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1691
+ initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1554
1692
  };
1555
1693
  sqlite: {
1556
1694
  backend: "local" | "remote";
@@ -1567,6 +1705,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1567
1705
  httpBasePath: string;
1568
1706
  httpPort: number;
1569
1707
  startEngine: boolean;
1708
+ engineHost: string;
1709
+ enginePort: number;
1570
1710
  engineVersion: string;
1571
1711
  serverless: {
1572
1712
  basePath: string;
@@ -1581,8 +1721,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1581
1721
  envoyKey?: string | undefined;
1582
1722
  };
1583
1723
  shutdown: {
1584
- gracePeriodMs: number;
1585
1724
  disableSignalHandlers: boolean;
1725
+ gracePeriodMs?: number | undefined;
1586
1726
  };
1587
1727
  staticDir?: string | undefined;
1588
1728
  httpHost?: string | undefined;
@@ -1602,19 +1742,459 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1602
1742
  use: A;
1603
1743
  };
1604
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
+
1605
2166
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
1606
2167
  interface ServerlessHandler {
1607
2168
  fetch: FetchHandler;
1608
2169
  }
1609
- interface RegistryDiagnostics {
1610
- mode: string;
1611
- 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;
1612
2191
  }
1613
2192
  declare class Registry<A extends RegistryActors> {
1614
2193
  #private;
2194
+ readonly routes: RegistryRoutes;
1615
2195
  get config(): RegistryConfigInput<A>;
1616
2196
  parseConfig(): RegistryConfig;
1617
- constructor(config: RegistryConfigInput<A>);
2197
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
1618
2198
  /**
1619
2199
  * Handle an incoming HTTP request for serverless deployments.
1620
2200
  *
@@ -1635,11 +2215,64 @@ declare class Registry<A extends RegistryActors> {
1635
2215
  * ```
1636
2216
  */
1637
2217
  serve(): ServerlessHandler;
1638
- 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>;
1639
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>;
1640
2269
  /**
1641
2270
  * Starts the actor envoy for standalone server deployments.
1642
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
+ *
1643
2276
  * @example
1644
2277
  * ```ts
1645
2278
  * const registry = setup({ use: { counter } });