rivetkit 0.0.0-2-3-0-rc-rollback.f0e199e → 0.0.0-bisect-sync-sqlite-1.910d1c7

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 (308) hide show
  1. package/dist/browser/client.d.ts +1265 -97
  2. package/dist/browser/client.js +1723 -758
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +252 -129
  5. package/dist/browser/inspector/client.js +2081 -235
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/actor/errors.cjs +8 -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 +7 -1
  12. package/dist/tsup/agent-os/index.cjs +3 -2291
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +1 -1834
  15. package/dist/tsup/agent-os/index.d.ts +1 -1834
  16. package/dist/tsup/agent-os/index.js +3 -2291
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/chunk-2JJU7IQ7.cjs +14 -0
  19. package/dist/tsup/chunk-2JJU7IQ7.cjs.map +1 -0
  20. package/dist/tsup/{chunk-SVJ4AIKO.js → chunk-2MXBZGUP.js} +2 -2
  21. package/dist/tsup/{chunk-TV5KMIWT.js → chunk-47IS5ZFI.js} +6 -6
  22. package/dist/tsup/chunk-47IS5ZFI.js.map +1 -0
  23. package/dist/tsup/{chunk-2LZSBIO2.js → chunk-5XWY5CBA.js} +70 -8
  24. package/dist/tsup/chunk-5XWY5CBA.js.map +1 -0
  25. package/dist/tsup/{chunk-C6E5O6DI.cjs → chunk-6XVNZKKP.cjs} +503 -30
  26. package/dist/tsup/chunk-6XVNZKKP.cjs.map +1 -0
  27. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-A2CF6PFH.js} +20 -12
  28. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  29. package/dist/tsup/{chunk-SRNOPUC6.cjs → chunk-AQJFKHBK.cjs} +274 -27
  30. package/dist/tsup/chunk-AQJFKHBK.cjs.map +1 -0
  31. package/dist/tsup/chunk-DPWLASMC.cjs +244 -0
  32. package/dist/tsup/chunk-DPWLASMC.cjs.map +1 -0
  33. package/dist/tsup/{chunk-DPXDV63C.cjs → chunk-DYJOU3MF.cjs} +10 -10
  34. package/dist/tsup/chunk-DYJOU3MF.cjs.map +1 -0
  35. package/dist/tsup/{chunk-M7CSS3KQ.cjs → chunk-ELZ6MT3V.cjs} +18 -11
  36. package/dist/tsup/chunk-ELZ6MT3V.cjs.map +1 -0
  37. package/dist/tsup/chunk-HYIVSH5X.js +244 -0
  38. package/dist/tsup/chunk-HYIVSH5X.js.map +1 -0
  39. package/dist/tsup/{chunk-D5G75T7J.js → chunk-IHEO5OT3.js} +273 -26
  40. package/dist/tsup/chunk-IHEO5OT3.js.map +1 -0
  41. package/dist/tsup/chunk-IWACVNN5.js +14 -0
  42. package/dist/tsup/chunk-IWACVNN5.js.map +1 -0
  43. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
  44. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  45. package/dist/tsup/{chunk-V6GVHWI7.js → chunk-K3AJOPSF.js} +495 -22
  46. package/dist/tsup/chunk-K3AJOPSF.js.map +1 -0
  47. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
  48. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  49. package/dist/tsup/{chunk-63WNTDRC.cjs → chunk-MGI2VVF6.cjs} +43 -7
  50. package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
  51. package/dist/tsup/{chunk-F4MU22ZG.js → chunk-NPHTIUUJ.js} +1289 -394
  52. package/dist/tsup/chunk-NPHTIUUJ.js.map +1 -0
  53. package/dist/tsup/{chunk-UQPM7B6T.cjs → chunk-POCSZXPQ.cjs} +72 -10
  54. package/dist/tsup/chunk-POCSZXPQ.cjs.map +1 -0
  55. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-RTWH3AX3.cjs} +19 -11
  56. package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
  57. package/dist/tsup/{chunk-KQGJI6VY.cjs → chunk-X76BM5JS.cjs} +1425 -530
  58. package/dist/tsup/chunk-X76BM5JS.cjs.map +1 -0
  59. package/dist/tsup/{chunk-4CKZEGYR.js → chunk-X7SYKFPM.js} +16 -9
  60. package/dist/tsup/chunk-X7SYKFPM.js.map +1 -0
  61. package/dist/tsup/{chunk-4W6KZC6M.cjs → chunk-XLDJSZ3B.cjs} +3 -3
  62. package/dist/tsup/{chunk-4W6KZC6M.cjs.map → chunk-XLDJSZ3B.cjs.map} +1 -1
  63. package/dist/tsup/{chunk-TMLOKTRB.js → chunk-ZOVJDAOW.js} +42 -6
  64. package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
  65. package/dist/tsup/client/mod.cjs +8 -9
  66. package/dist/tsup/client/mod.cjs.map +1 -1
  67. package/dist/tsup/client/mod.d.cts +33 -7
  68. package/dist/tsup/client/mod.d.ts +33 -7
  69. package/dist/tsup/client/mod.js +7 -8
  70. package/dist/tsup/common/log.cjs +5 -3
  71. package/dist/tsup/common/log.cjs.map +1 -1
  72. package/dist/tsup/common/log.d.cts +5 -1
  73. package/dist/tsup/common/log.d.ts +5 -1
  74. package/dist/tsup/common/log.js +6 -4
  75. package/dist/tsup/common/websocket.cjs +4 -4
  76. package/dist/tsup/common/websocket.js +3 -3
  77. package/dist/tsup/{config-DU_xj4qZ.d.cts → config-BMGUEKMZ.d.cts} +1242 -86
  78. package/dist/tsup/config-CBTr4IhE.d.cts +224 -0
  79. package/dist/tsup/config-CBTr4IhE.d.ts +224 -0
  80. package/dist/tsup/{config-Ak1lv4gF.d.ts → config-iBpXyITj.d.ts} +1242 -86
  81. package/dist/tsup/context-hyVakgnU.d.ts +136 -0
  82. package/dist/tsup/context-qfvLuF0P.d.cts +136 -0
  83. package/dist/tsup/db/drizzle.cjs +127 -67
  84. package/dist/tsup/db/drizzle.cjs.map +1 -1
  85. package/dist/tsup/db/drizzle.d.cts +8 -4
  86. package/dist/tsup/db/drizzle.d.ts +8 -4
  87. package/dist/tsup/db/drizzle.js +127 -67
  88. package/dist/tsup/db/drizzle.js.map +1 -1
  89. package/dist/tsup/db/mod.cjs +6 -124
  90. package/dist/tsup/db/mod.cjs.map +1 -1
  91. package/dist/tsup/db/mod.d.cts +12 -4
  92. package/dist/tsup/db/mod.d.ts +12 -4
  93. package/dist/tsup/db/mod.js +5 -123
  94. package/dist/tsup/db/mod.js.map +1 -1
  95. package/dist/tsup/dynamic/mod.cjs +24 -0
  96. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  97. package/dist/tsup/dynamic/mod.d.cts +39 -0
  98. package/dist/tsup/dynamic/mod.d.ts +39 -0
  99. package/dist/tsup/dynamic/mod.js +24 -0
  100. package/dist/tsup/dynamic/mod.js.map +1 -0
  101. package/dist/tsup/inspector/mod.cjs +47 -12
  102. package/dist/tsup/inspector/mod.cjs.map +1 -1
  103. package/dist/tsup/inspector/mod.d.cts +26 -136
  104. package/dist/tsup/inspector/mod.d.ts +26 -136
  105. package/dist/tsup/inspector/mod.js +46 -11
  106. package/dist/tsup/inspector/mod.js.map +1 -1
  107. package/dist/tsup/inspector/workflow.cjs +21 -0
  108. package/dist/tsup/inspector/workflow.cjs.map +1 -0
  109. package/dist/tsup/inspector/workflow.d.cts +144 -0
  110. package/dist/tsup/inspector/workflow.d.ts +144 -0
  111. package/dist/tsup/inspector/workflow.js +21 -0
  112. package/dist/tsup/inspector/workflow.js.map +1 -0
  113. package/dist/tsup/inspector-tab/mod.cjs +162 -0
  114. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  115. package/dist/tsup/inspector-tab/mod.d.cts +242 -0
  116. package/dist/tsup/inspector-tab/mod.d.ts +242 -0
  117. package/dist/tsup/inspector-tab/mod.js +162 -0
  118. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  119. package/dist/tsup/mod.cjs +3511 -923
  120. package/dist/tsup/mod.cjs.map +1 -1
  121. package/dist/tsup/mod.d.cts +11 -7
  122. package/dist/tsup/mod.d.ts +11 -7
  123. package/dist/tsup/mod.js +3452 -864
  124. package/dist/tsup/mod.js.map +1 -1
  125. package/dist/tsup/test/mod.cjs +26 -21
  126. package/dist/tsup/test/mod.cjs.map +1 -1
  127. package/dist/tsup/test/mod.d.cts +7 -5
  128. package/dist/tsup/test/mod.d.ts +7 -5
  129. package/dist/tsup/test/mod.js +25 -20
  130. package/dist/tsup/test/mod.js.map +1 -1
  131. package/dist/tsup/unstable/migrations.cjs +101 -0
  132. package/dist/tsup/unstable/migrations.cjs.map +1 -0
  133. package/dist/tsup/unstable/migrations.d.cts +29 -0
  134. package/dist/tsup/unstable/migrations.d.ts +29 -0
  135. package/dist/tsup/unstable/migrations.js +101 -0
  136. package/dist/tsup/unstable/migrations.js.map +1 -0
  137. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-3rsE0JvI.d.cts} +26 -2
  138. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-3rsE0JvI.d.ts} +26 -2
  139. package/dist/tsup/utils-C1O-SklO.d.ts +162 -0
  140. package/dist/tsup/utils-C6b0aYUM.d.cts +162 -0
  141. package/dist/tsup/utils.cjs +7 -3
  142. package/dist/tsup/utils.cjs.map +1 -1
  143. package/dist/tsup/utils.d.cts +4 -147
  144. package/dist/tsup/utils.d.ts +4 -147
  145. package/dist/tsup/utils.js +6 -2
  146. package/dist/tsup/workflow/mod.cjs +556 -434
  147. package/dist/tsup/workflow/mod.cjs.map +1 -1
  148. package/dist/tsup/workflow/mod.d.cts +11 -9
  149. package/dist/tsup/workflow/mod.d.ts +11 -9
  150. package/dist/tsup/workflow/mod.js +551 -429
  151. package/dist/tsup/workflow/mod.js.map +1 -1
  152. package/package.json +65 -17
  153. package/src/actor/actions.ts +155 -0
  154. package/src/actor/config.ts +676 -101
  155. package/src/actor/contexts/index.ts +9 -2
  156. package/src/actor/definition.ts +75 -26
  157. package/src/actor/errors.ts +106 -7
  158. package/src/actor/keys.ts +87 -1
  159. package/src/actor/mod.ts +36 -20
  160. package/src/actor/schema.ts +6 -2
  161. package/src/actor/tracing.ts +28 -0
  162. package/src/agent-os/index.ts +5 -64
  163. package/src/client/actor-common.ts +84 -54
  164. package/src/client/actor-conn.ts +232 -41
  165. package/src/client/actor-handle.ts +283 -90
  166. package/src/client/actor-query.ts +13 -6
  167. package/src/client/auth.ts +37 -0
  168. package/src/client/client.ts +182 -21
  169. package/src/client/config.ts +28 -3
  170. package/src/client/errors.ts +15 -2
  171. package/src/client/lifecycle-errors.ts +63 -5
  172. package/src/client/mod.ts +10 -0
  173. package/src/client/outbound-telemetry.ts +66 -0
  174. package/src/client/query.ts +3 -1
  175. package/src/client/queue.ts +13 -4
  176. package/src/client/raw-utils.ts +59 -14
  177. package/src/client/resolve-gateway-target.ts +3 -1
  178. package/src/client/retry-budget.ts +81 -0
  179. package/src/client/token-provider.ts +93 -0
  180. package/src/client/utils.ts +22 -8
  181. package/src/common/actor-router-consts.ts +6 -0
  182. package/src/common/actor-telemetry-context.ts +19 -0
  183. package/src/common/actor-websocket.ts +3 -1
  184. package/src/common/bare/actor-persist/v1.ts +205 -163
  185. package/src/common/bare/actor-persist/v2.ts +265 -213
  186. package/src/common/bare/actor-persist/v3.ts +176 -172
  187. package/src/common/bare/actor-persist/v4.ts +254 -253
  188. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  189. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  190. package/src/common/bare/transport/v1.ts +694 -542
  191. package/src/common/client-protocol-versioned.ts +66 -64
  192. package/src/common/database/config.ts +175 -9
  193. package/src/common/database/mod.ts +262 -77
  194. package/src/common/database/native-database.ts +442 -20
  195. package/src/common/database/shared.ts +25 -0
  196. package/src/common/encoding.ts +41 -35
  197. package/src/common/engine.ts +28 -1
  198. package/src/common/eventsource.ts +1 -1
  199. package/src/common/fetch-like.ts +63 -0
  200. package/src/common/inline-websocket-adapter.ts +3 -2
  201. package/src/common/inspector-transport.ts +12 -2
  202. package/src/common/log.ts +14 -8
  203. package/src/common/otel-context.ts +99 -0
  204. package/src/common/router.ts +14 -18
  205. package/src/common/utils.ts +8 -21
  206. package/src/common/websocket-interface.ts +1 -1
  207. package/src/db/drizzle.ts +182 -80
  208. package/src/db/mod.ts +5 -1
  209. package/src/devtools-loader/index.ts +4 -7
  210. package/src/devtools-loader/serve-devtools.ts +26 -0
  211. package/src/dynamic/instance.ts +32 -0
  212. package/src/dynamic/internal.ts +50 -0
  213. package/src/dynamic/isolate-runtime.ts +64 -0
  214. package/src/dynamic/mod.ts +32 -0
  215. package/src/engine-api/actors.ts +15 -3
  216. package/src/engine-client/actor-http-client.ts +37 -22
  217. package/src/engine-client/actor-websocket-client.ts +36 -9
  218. package/src/engine-client/api-endpoints.ts +128 -5
  219. package/src/engine-client/api-utils.ts +2 -2
  220. package/src/engine-client/driver.ts +21 -16
  221. package/src/engine-client/mod.ts +280 -112
  222. package/src/engine-client/ws-proxy.ts +9 -4
  223. package/src/inspector/client.browser.ts +127 -15
  224. package/src/inspector/mod.ts +2 -4
  225. package/src/inspector/workflow.ts +61 -0
  226. package/src/inspector-tab/mod.ts +301 -0
  227. package/src/registry/config/envoy.ts +3 -20
  228. package/src/registry/config/index.ts +90 -71
  229. package/src/registry/index.ts +758 -115
  230. package/src/registry/napi-runtime.ts +665 -50
  231. package/src/registry/native-http.ts +225 -0
  232. package/src/registry/native-validation.ts +10 -12
  233. package/src/registry/native.ts +1765 -555
  234. package/src/registry/run-handler-coordinator.ts +219 -0
  235. package/src/registry/runtime.ts +450 -12
  236. package/src/registry/wasm-runtime.ts +528 -24
  237. package/src/registry/write-through-proxy.ts +101 -0
  238. package/src/serde.ts +1 -1
  239. package/src/serverless/configure.ts +18 -7
  240. package/src/test/mod.ts +2 -17
  241. package/src/test/ready.ts +22 -0
  242. package/src/unstable/migrations.ts +141 -0
  243. package/src/utils/endpoint-parser.ts +1 -1
  244. package/src/utils/env-vars.ts +50 -2
  245. package/src/utils/node.ts +44 -28
  246. package/src/utils/router.ts +1 -1
  247. package/src/utils.ts +4 -2
  248. package/src/workflow/context.ts +703 -269
  249. package/src/workflow/driver.ts +284 -125
  250. package/src/workflow/inspector.ts +24 -25
  251. package/src/workflow/mod.ts +76 -84
  252. package/dist/tsup/chunk-2LZSBIO2.js.map +0 -1
  253. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  254. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  255. package/dist/tsup/chunk-4CKZEGYR.js.map +0 -1
  256. package/dist/tsup/chunk-63WNTDRC.cjs.map +0 -1
  257. package/dist/tsup/chunk-C6E5O6DI.cjs.map +0 -1
  258. package/dist/tsup/chunk-D5G75T7J.js.map +0 -1
  259. package/dist/tsup/chunk-DPXDV63C.cjs.map +0 -1
  260. package/dist/tsup/chunk-F4MU22ZG.js.map +0 -1
  261. package/dist/tsup/chunk-KQGJI6VY.cjs.map +0 -1
  262. package/dist/tsup/chunk-LD5YASJU.cjs.map +0 -1
  263. package/dist/tsup/chunk-M7CSS3KQ.cjs.map +0 -1
  264. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  265. package/dist/tsup/chunk-QKFHZ2JS.js +0 -396
  266. package/dist/tsup/chunk-QKFHZ2JS.js.map +0 -1
  267. package/dist/tsup/chunk-SRNOPUC6.cjs.map +0 -1
  268. package/dist/tsup/chunk-TMLOKTRB.js.map +0 -1
  269. package/dist/tsup/chunk-TV5KMIWT.js.map +0 -1
  270. package/dist/tsup/chunk-UQPM7B6T.cjs.map +0 -1
  271. package/dist/tsup/chunk-UZGWGYKU.cjs +0 -396
  272. package/dist/tsup/chunk-UZGWGYKU.cjs.map +0 -1
  273. package/dist/tsup/chunk-V6GVHWI7.js.map +0 -1
  274. package/dist/tsup/config-CxjGYf4K.d.cts +0 -121
  275. package/dist/tsup/config-CxjGYf4K.d.ts +0 -121
  276. package/dist/tsup/context-DAAp4Lpg.d.ts +0 -92
  277. package/dist/tsup/context-Dt_L55q8.d.cts +0 -92
  278. package/dist/tsup/process-metrics-NW754INA.js +0 -118
  279. package/dist/tsup/process-metrics-NW754INA.js.map +0 -1
  280. package/dist/tsup/process-metrics-TYAGKCEJ.cjs +0 -118
  281. package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +0 -1
  282. package/src/actor/driver.ts +0 -141
  283. package/src/actor/instance/mod.ts +0 -2492
  284. package/src/actor/keys.test.ts +0 -275
  285. package/src/actor/utils.test.ts +0 -48
  286. package/src/agent-os/actor/cron.ts +0 -84
  287. package/src/agent-os/actor/db.ts +0 -54
  288. package/src/agent-os/actor/filesystem.ts +0 -131
  289. package/src/agent-os/actor/index.ts +0 -265
  290. package/src/agent-os/actor/network.ts +0 -58
  291. package/src/agent-os/actor/preview.ts +0 -191
  292. package/src/agent-os/actor/process.ts +0 -177
  293. package/src/agent-os/actor/session.ts +0 -518
  294. package/src/agent-os/actor/shell.ts +0 -60
  295. package/src/agent-os/config.ts +0 -79
  296. package/src/agent-os/fs/database-vfs.ts +0 -624
  297. package/src/agent-os/types.ts +0 -148
  298. package/src/client/test.ts +0 -44
  299. package/src/common/database/mod.test.ts +0 -137
  300. package/src/common/database/native-database.test.ts +0 -211
  301. package/src/common/inline-websocket-adapter.test.ts +0 -51
  302. package/src/drivers/engine/actor-driver.ts +0 -2471
  303. package/src/registry/process-metrics.ts +0 -183
  304. package/src/registry/runtime.test.ts +0 -50
  305. package/src/utils/endpoint-parser.test.ts +0 -206
  306. package/src/utils/serve.ts +0 -217
  307. package/src/utils.test.ts +0 -34
  308. /package/dist/tsup/{chunk-SVJ4AIKO.js.map → chunk-2MXBZGUP.js.map} +0 -0
@@ -1,8 +1,9 @@
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';
4
+ import { Rivet } from '@rivetkit/engine-api-full';
5
5
  import { Context, Handler, Hono } from 'hono';
6
+ import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
6
7
  import { StandardSchemaV1 } from '@standard-schema/spec';
7
8
  import { ContentfulStatusCode } from 'hono/utils/http-status';
8
9
  import { Logger } from 'pino';
@@ -13,7 +14,7 @@ interface ActorMetricsLike {
13
14
  totalKvWrites: number;
14
15
  trackSql(query: string, durationMs: number): void;
15
16
  }
16
- type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : never;
17
+ type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : RawAccess;
17
18
  type SqliteBindings = unknown[] | Record<string, unknown>;
18
19
  interface SqliteQueryResult {
19
20
  columns: string[];
@@ -23,6 +24,93 @@ interface SqliteExecuteResult extends SqliteQueryResult {
23
24
  changes: number;
24
25
  lastInsertRowId?: number | null;
25
26
  }
27
+ interface SqliteBatchStatement {
28
+ sql: string;
29
+ params?: SqliteBindings;
30
+ }
31
+ interface SqliteTransactionOptions {
32
+ /** Static operation name used to aggregate transaction performance. */
33
+ name?: string;
34
+ /** Deadlock-safety timeout in milliseconds. */
35
+ timeout?: number;
36
+ /** @experimental */
37
+ experimental?: {
38
+ /**
39
+ * Atomically includes actor and hibernatable connection state.
40
+ * Only single-statement `execute` calls are supported in the transaction.
41
+ * Concurrent actions that try to mutate state while the transaction is
42
+ * active fail with `actor.state_transaction_conflict`.
43
+ */
44
+ includeState?: boolean;
45
+ };
46
+ }
47
+ /**
48
+ * SQLite profiling configuration.
49
+ *
50
+ * @experimental This entire configuration surface is experimental and subject
51
+ * to change without notice.
52
+ */
53
+ interface SqliteProfilingOptions {
54
+ /** Exact SQL filter. Union with filterQueryFingerprints; both empty means all queries. */
55
+ filterQueries?: string[];
56
+ /** Fingerprint filter, including transaction fingerprints. Filters metrics, not diagnostic logs. */
57
+ filterQueryFingerprints?: string[];
58
+ /** Metric defaults apply even when omitted. Disabled metrics allocate no series. */
59
+ metrics?: SqliteProfilingMetricsOptions;
60
+ /** Duration buckets in seconds. Default [0.01, 0.1, 1]. Positive, finite, strictly increasing.
61
+ * All actors in a process enabling the duration histogram must use identical buckets. */
62
+ durationHistogramBucketsSeconds?: number[];
63
+ /** Maximum distinct statement fingerprints per process. Default: 512. */
64
+ maxTrackedStatementFingerprints?: number;
65
+ maxTrackedTransactionFingerprints?: number;
66
+ maxPrometheusSeries?: number;
67
+ maxStatementsPerTransactionTrace?: number;
68
+ maxGetPagesRequestsPerTrace?: number;
69
+ maxTransactionNameBytes?: number;
70
+ slowOperationThresholdMs?: number;
71
+ baselineSampleRate?: number;
72
+ maxDiagnosticEventsPerMinute?: number;
73
+ diagnosticEventQueueCapacity?: number;
74
+ }
75
+ /** SQLite profiling metrics. Physical-request metrics and gauges have no query labels. */
76
+ interface SqliteProfilingMetricsOptions {
77
+ /** Execution count and cumulative seconds. Uses histogram count/sum when enabled, otherwise counters. Default: true. */
78
+ duration?: boolean;
79
+ /** Execution duration histogram. Only applies when duration is enabled. Default: true. */
80
+ durationHistogram?: boolean;
81
+ /** Outcome counters, including success and errors. Default: true. */
82
+ outcomes?: boolean;
83
+ /** Per-query timing phase histograms. Default: false. */
84
+ phaseDurationHistogram?: boolean;
85
+ /** Storage round trips per operation histogram. Default: false. */
86
+ getPagesRoundTripsHistogram?: boolean;
87
+ /** Statements per transaction histogram. Default: false. */
88
+ transactionStatementCountHistogram?: boolean;
89
+ /** Per-query pages returned from storage, including returned prefetch pages. Default: true. */
90
+ pagesFetched?: boolean;
91
+ /** Actor-level page counters by page kind (no query labels). Default: false. */
92
+ localPages?: boolean;
93
+ /** Actor-level byte counters by byte kind (no query labels). Default: false. */
94
+ localBytes?: boolean;
95
+ /** Actor-level physical storage request duration histogram. Default: false. */
96
+ getPagesDurationHistogram?: boolean;
97
+ /** Actor-level pages per storage request histograms, by page kind. Default: false. */
98
+ getPagesPagesHistogram?: boolean;
99
+ /** Actor-level storage response byte histogram. Default: false. */
100
+ getPagesResponseBytesHistogram?: boolean;
101
+ /** Actor-level missing response page counter. Default: false. */
102
+ getPagesMissingPages?: boolean;
103
+ /** Queued SQLite work, aggregated by actor name. Default: true. */
104
+ workerQueueDepth?: boolean;
105
+ /** Executing SQLite work, aggregated by actor name. Default: true. */
106
+ workerInflight?: boolean;
107
+ /** Transaction waiters, aggregated by actor name. Default: true. */
108
+ coordinatorQueueDepth?: boolean;
109
+ /** Counts observations exceeding fingerprint or series limits. Default: true. */
110
+ fingerprintOverflow?: boolean;
111
+ /** Counts diagnostic events dropped by rate limits or backpressure. Default: true. */
112
+ eventDropped?: boolean;
113
+ }
26
114
  interface SqliteNativeMetrics {
27
115
  requestBuildNs: number;
28
116
  serializeNs: number;
@@ -39,11 +127,19 @@ interface SqliteNativeMetrics {
39
127
  interface SqliteDatabase {
40
128
  exec(sql: string, callback?: (row: unknown[], columns: string[]) => void): Promise<void>;
41
129
  execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
130
+ executeBatch(statements: SqliteBatchStatement[]): Promise<SqliteExecuteResult[]>;
131
+ beginTransaction(timeoutMs?: number, name?: string): Promise<SqliteTransactionDatabase>;
42
132
  run(sql: string, params?: SqliteBindings): Promise<void>;
43
133
  query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
44
134
  nativeMetrics?(): SqliteNativeMetrics | Promise<SqliteNativeMetrics | null> | null;
45
135
  close(): Promise<void>;
46
136
  }
137
+ interface SqliteTransactionDatabase {
138
+ exec(sql: string, callback?: (row: unknown[], columns: string[]) => void): Promise<void>;
139
+ execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
140
+ commit(): Promise<void>;
141
+ rollback(): Promise<void>;
142
+ }
47
143
  /**
48
144
  * Provider for opening native databases from the active runtime.
49
145
  */
@@ -87,6 +183,13 @@ interface DatabaseProviderContext {
87
183
  nativeDatabaseProvider?: NativeDatabaseProvider;
88
184
  }
89
185
  type DatabaseProvider<DB extends RawAccess> = {
186
+ /**
187
+ * Local SQLite profiling controls consumed by the actor runtime.
188
+ *
189
+ * @experimental This entire configuration surface is experimental and
190
+ * subject to change without notice.
191
+ */
192
+ sqliteProfiling?: SqliteProfilingOptions;
90
193
  /**
91
194
  * Creates a new database client for the actor.
92
195
  * The result is passed to the actor context as `c.db`.
@@ -103,14 +206,15 @@ type DatabaseProvider<DB extends RawAccess> = {
103
206
  /**
104
207
  * Drizzle database client interface (will be extended by drizzle-orm types)
105
208
  */
106
- interface DrizzleDatabaseClient {
107
- }
209
+ type DrizzleDatabaseClient = {};
108
210
  type ExecuteFunction = <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]>;
109
211
  type RawAccess = {
110
212
  /**
111
213
  * Executes a raw SQL query.
112
214
  */
113
215
  execute: ExecuteFunction;
216
+ /** Runs a callback in an isolated SQLite transaction. */
217
+ transaction: <T>(callback: (tx: RawAccess) => Promise<T> | T, options?: SqliteTransactionOptions) => Promise<T>;
114
218
  /**
115
219
  * Returns native SQLite metrics when the active runtime supports them.
116
220
  */
@@ -121,6 +225,26 @@ type RawAccess = {
121
225
  close: () => Promise<void>;
122
226
  };
123
227
 
228
+ /** A namespace-scoped Engine grant. The caller must provide every grant explicitly. */
229
+ type TokenGrant = Rivet.AuthTokenGrant;
230
+ /** Options for `client.auth.issueToken()`. `expiresIn` is in seconds. */
231
+ type IssueTokenOptions = Pick<Rivet.AuthTokenCreateRequest, "subject" | "grants"> & {
232
+ expiresIn?: Rivet.AuthTokenCreateRequest["duration"];
233
+ };
234
+ /** Token timestamps are Unix milliseconds. */
235
+ interface IssuedToken {
236
+ token: Rivet.AuthTokenCreateResponse["token"];
237
+ issuedAt: Rivet.AuthTokenCreateResponse["issuedTs"];
238
+ expiresAt: Rivet.AuthTokenCreateResponse["expiresTs"];
239
+ }
240
+ /** Resources that can be scoped to a single actor ID. */
241
+ type ActorTokenResource = Extract<Rivet.AuthTokenGrant["resource"], "actor_gateway" | "actor" | "actor_kv">;
242
+ type ActorTokenPermissions = Partial<Record<ActorTokenResource, Rivet.AuthTokenGrant["operations"]>>;
243
+ /** Options for `actor.issueToken()`. Omit permissions for gateway read access only. */
244
+ type ActorIssueTokenOptions = Pick<IssueTokenOptions, "subject" | "expiresIn"> & {
245
+ permissions?: ActorTokenPermissions;
246
+ };
247
+
124
248
  declare const EncodingSchema: z.ZodEnum<{
125
249
  json: "json";
126
250
  cbor: "cbor";
@@ -150,6 +274,7 @@ declare const CreateRequestSchema: z.ZodObject<{
150
274
  key: z.ZodArray<z.ZodString>;
151
275
  input: z.ZodOptional<z.ZodUnknown>;
152
276
  region: z.ZodOptional<z.ZodString>;
277
+ poolName: z.ZodOptional<z.ZodString>;
153
278
  }, z.core.$strip>;
154
279
  declare const ActorQuerySchema: z.ZodUnion<readonly [z.ZodObject<{
155
280
  getForId: z.ZodObject<{
@@ -167,6 +292,7 @@ declare const ActorQuerySchema: z.ZodUnion<readonly [z.ZodObject<{
167
292
  key: z.ZodArray<z.ZodString>;
168
293
  input: z.ZodOptional<z.ZodUnknown>;
169
294
  region: z.ZodOptional<z.ZodString>;
295
+ poolName: z.ZodOptional<z.ZodString>;
170
296
  }, z.core.$strip>;
171
297
  }, z.core.$strip>, z.ZodObject<{
172
298
  create: z.ZodObject<{
@@ -174,6 +300,7 @@ declare const ActorQuerySchema: z.ZodUnion<readonly [z.ZodObject<{
174
300
  key: z.ZodArray<z.ZodString>;
175
301
  input: z.ZodOptional<z.ZodUnknown>;
176
302
  region: z.ZodOptional<z.ZodString>;
303
+ poolName: z.ZodOptional<z.ZodString>;
177
304
  }, z.core.$strip>;
178
305
  }, z.core.$strip>]>;
179
306
  type ActorQuery = z.infer<typeof ActorQuerySchema>;
@@ -182,6 +309,46 @@ type ActorQuery = z.infer<typeof ActorQuerySchema>;
182
309
  */
183
310
  type CreateRequest = z.infer<typeof CreateRequestSchema>;
184
311
 
312
+ type SchemaHookResult = boolean | Promise<boolean>;
313
+ type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
314
+ interface EventTypeToken<T, TContext = any> {
315
+ readonly _eventType?: T;
316
+ readonly canSubscribe?: SchemaHook<TContext>;
317
+ readonly schema?: PrimitiveSchema;
318
+ }
319
+ interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
320
+ readonly _queueMessage?: TMessage;
321
+ readonly _queueComplete?: TComplete;
322
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
323
+ readonly canPublish?: SchemaHook<TContext>;
324
+ readonly message?: PrimitiveSchema;
325
+ readonly complete?: PrimitiveSchema;
326
+ }
327
+ type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
328
+ interface EventSchemaDefinition<TContext = any> {
329
+ schema: PrimitiveSchema;
330
+ canSubscribe?: SchemaHook<TContext>;
331
+ }
332
+ interface QueueSchemaDefinition<TContext = any> {
333
+ message: PrimitiveSchema;
334
+ complete?: PrimitiveSchema;
335
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
336
+ canPublish?: SchemaHook<TContext>;
337
+ }
338
+ type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
339
+ type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
340
+ type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
341
+ type QueueSchemaConfig<_TContext = any> = Record<string, QueueSchema>;
342
+ 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;
343
+ type InferSchemaMap<T extends Record<string, unknown>> = {
344
+ [K in keyof T]: InferSchema<T[K]>;
345
+ };
346
+ 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;
347
+ type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
348
+ [K in keyof T]: InferQueueComplete<T[K]>;
349
+ };
350
+ type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
351
+
185
352
  interface DeconstructedError {
186
353
  __type: "ActorError";
187
354
  statusCode: ContentfulStatusCode;
@@ -190,6 +357,7 @@ interface DeconstructedError {
190
357
  code: string;
191
358
  message: string;
192
359
  metadata?: unknown;
360
+ rayId?: string;
193
361
  actor?: ActorSpecifier;
194
362
  }
195
363
 
@@ -198,6 +366,8 @@ interface RivetErrorOptions extends ErrorOptions {
198
366
  public?: boolean;
199
367
  /** Metadata associated with this error. */
200
368
  metadata?: unknown;
369
+ /** Request identifier used to correlate this error with engine logs. */
370
+ rayId?: string;
201
371
  /** Explicit HTTP status override for router responses. */
202
372
  statusCode?: number;
203
373
  /** Actor context associated with this error. */
@@ -225,6 +395,7 @@ declare class RivetError extends Error {
225
395
  __type: "RivetError";
226
396
  public: boolean;
227
397
  metadata?: unknown;
398
+ readonly rayId?: string;
228
399
  statusCode: number;
229
400
  actor?: ActorSpecifier;
230
401
  readonly group: string;
@@ -239,43 +410,28 @@ declare class UserError extends RivetError {
239
410
  constructor(message: string, options?: UserErrorOptions);
240
411
  }
241
412
 
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;
413
+ /** Sample rates keyed by action name, nested like the actor's action groups. */
414
+ interface ActionSampleRates {
415
+ readonly [name: string]: number | ActionSampleRates;
255
416
  }
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]>;
417
+ /**
418
+ * {@link ActionSampleRates} limited to the actions of one actor, so a rate for
419
+ * an action that does not exist is a compile error.
420
+ */
421
+ type ActionTraceSamplers<TActions> = {
422
+ readonly [K in keyof TActions]?: TActions[K] extends (...args: never[]) => unknown ? number : ActionTraceSamplers<TActions[K]>;
277
423
  };
278
- type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
424
+ /** Trace sampling for one actor definition. */
425
+ interface ActorTracingOptions<TActions> {
426
+ /**
427
+ * Share of this actor's invocations that are recorded, from 0 to 1. A rate
428
+ * lowers what is recorded and never raises it, so an invocation inside a
429
+ * trace the caller did not record is not recorded at any rate.
430
+ */
431
+ readonly sampler?: number;
432
+ /** Rates that replace `sampler` for single actions. */
433
+ readonly actions?: ActionTraceSamplers<TActions>;
434
+ }
279
435
 
280
436
  type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
281
437
  type GetUpgradeWebSocket = () => UpgradeWebSocket;
@@ -287,13 +443,18 @@ interface GatewayRequestOptions {
287
443
  skipReadyWait?: boolean;
288
444
  }
289
445
  interface EngineControlClient {
446
+ issueToken(options: IssueTokenOptions): Promise<IssuedToken>;
290
447
  getForId(input: GetForIdInput): Promise<ActorOutput | undefined>;
291
448
  getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined>;
292
449
  getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput>;
293
450
  createActor(input: CreateInput): Promise<ActorOutput>;
451
+ /** Forks the actor `actorId` into a new actor of the same name, started on a copy of its database. */
452
+ forkActor(input: ForkInput): Promise<ActorOutput>;
294
453
  listActors(input: ListActorsInput): Promise<ActorOutput[]>;
295
454
  sendRequest(target: GatewayTarget, actorRequest: Request, options?: GatewayRequestOptions): Promise<Response>;
296
455
  openWebSocket(path: string, target: GatewayTarget, encoding: Encoding, params: unknown, options?: GatewayRequestOptions): Promise<UniversalWebSocket>;
456
+ /** Refresh a credential rejected during this WebSocket handshake, if supported. */
457
+ refreshAuthToken?(ws: UniversalWebSocket): Promise<boolean>;
297
458
  proxyRequest(c: Context, actorRequest: Request, actorId: string): Promise<Response>;
298
459
  proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown): Promise<Response>;
299
460
  buildGatewayUrl(target: GatewayTarget, options?: GatewayRequestOptions): Promise<string>;
@@ -306,11 +467,6 @@ interface EngineControlClient {
306
467
  * Test-only helper that simulates an abrupt actor crash.
307
468
  */
308
469
  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
470
  }
315
471
  interface RuntimeDisplayInformation {
316
472
  properties: Record<string, string>;
@@ -332,6 +488,8 @@ interface GetOrCreateWithKeyInput {
332
488
  input?: unknown;
333
489
  region?: string;
334
490
  crashPolicy?: CrashPolicy;
491
+ /** Overrides the client's configured pool name for this actor. */
492
+ poolName?: string;
335
493
  }
336
494
  interface CreateInput {
337
495
  c?: Context | undefined;
@@ -340,6 +498,17 @@ interface CreateInput {
340
498
  input?: unknown;
341
499
  region?: string;
342
500
  crashPolicy?: CrashPolicy;
501
+ /** Overrides the client's configured pool name for this actor. */
502
+ poolName?: string;
503
+ }
504
+ interface ForkInput {
505
+ c?: Context | undefined;
506
+ /** The source actor. */
507
+ actorId: string;
508
+ /** The new actor's key; omitted for a keyless actor. */
509
+ key?: ActorKey;
510
+ /** The fork input, given to the new actor's `onFork` hook. */
511
+ input?: unknown;
343
512
  }
344
513
  interface ListActorsInput {
345
514
  c?: Context | undefined;
@@ -359,6 +528,533 @@ interface ActorOutput {
359
528
  error?: unknown;
360
529
  }
361
530
 
531
+ /** Correlation owned by the currently executing Core actor invocation. */
532
+ interface ActorInvocationTraceContext {
533
+ /** Ray ID the invocation received, absent when nothing upstream supplied one. */
534
+ readonly rayId?: string;
535
+ /** Core-owned invocation span context, absent when tracing is disabled. */
536
+ readonly span?: ActorInvocationSpanContext;
537
+ }
538
+ /** W3C span context of the Core invocation span. */
539
+ interface ActorInvocationSpanContext {
540
+ /** W3C trace identifier. */
541
+ readonly traceId: string;
542
+ /** W3C span identifier for the Core invocation. */
543
+ readonly spanId: string;
544
+ /** OpenTelemetry trace flags encoded as an integer. */
545
+ readonly traceFlags: number;
546
+ /** Optional vendor trace state inherited by the Core invocation. */
547
+ readonly tracestate?: string;
548
+ }
549
+
550
+ declare const handleBrand: unique symbol;
551
+ type OpaqueHandle<Name extends string> = {
552
+ readonly [handleBrand]: Name;
553
+ };
554
+ type RegistryHandle = OpaqueHandle<"registry">;
555
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
556
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
557
+ type ConnHandle = OpaqueHandle<"conn">;
558
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
559
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
560
+ type ActorStateTransactionHandle = OpaqueHandle<"actorStateTransaction">;
561
+ type SqliteTransactionHandle = OpaqueHandle<"sqliteTransaction">;
562
+ type RuntimeBytes = Uint8Array;
563
+ interface RuntimeActorKeySegment {
564
+ kind: string;
565
+ stringValue?: string;
566
+ numberValue?: number;
567
+ }
568
+ /** One individual actor fork behind an actor, as the runtime reports it. */
569
+ interface RuntimeForkLink {
570
+ actorId: string;
571
+ key: RuntimeActorKeySegment[];
572
+ forkedAt: number;
573
+ }
574
+ /** Resolves correlation at operation time so retained clients cannot freeze stale context. */
575
+ type CurrentActorInvocation = () => ActorInvocationTraceContext | undefined;
576
+ /** One open call from an actor out to another actor. */
577
+ interface RuntimeOutboundCall {
578
+ /**
579
+ * W3C context of the call's own span, to send to the callee so it parents to
580
+ * the call. Absent when tracing is disabled.
581
+ */
582
+ readonly span?: ActorInvocationSpanContext;
583
+ /**
584
+ * Records the call's outcome. `error` is the failure encoded the way the
585
+ * bridge encodes errors, so a structured error keeps its group and code.
586
+ */
587
+ finish(error?: string): void;
588
+ }
589
+ /**
590
+ * Opens the span covering one call out to another actor, or returns `undefined`
591
+ * outside an invocation or on a runtime without invocation telemetry. Callers
592
+ * send their own context when it returns nothing.
593
+ */
594
+ type StartCallSpan = (actorName: string, actionName: string) => RuntimeOutboundCall | undefined;
595
+ interface RuntimeHttpRequest {
596
+ method: string;
597
+ uri: string;
598
+ headers?: Record<string, string>;
599
+ body?: RuntimeBytes;
600
+ }
601
+ interface RuntimeHttpResponseBodyStream {
602
+ cancelled(): Promise<void>;
603
+ write(chunk: Uint8Array): Promise<void>;
604
+ end(): Promise<void>;
605
+ error(message: string): Promise<void>;
606
+ }
607
+ interface RuntimeStateDeltaPayload {
608
+ state?: RuntimeBytes;
609
+ connHibernation: Array<{
610
+ connId: string;
611
+ bytes: RuntimeBytes;
612
+ }>;
613
+ connHibernationRemoved: string[];
614
+ }
615
+ interface RuntimeWorkflowKvWrite {
616
+ key: RuntimeBytes;
617
+ value: RuntimeBytes;
618
+ }
619
+ interface RuntimeRequestSaveOpts {
620
+ immediate?: boolean;
621
+ maxWaitMs?: number;
622
+ }
623
+ interface RuntimeInspectorSnapshot {
624
+ stateRevision: number;
625
+ connectionsRevision: number;
626
+ queueRevision: number;
627
+ activeConnections: number;
628
+ queueSize: number;
629
+ connectedClients: number;
630
+ }
631
+ interface RuntimeQueueMessage {
632
+ id(): bigint;
633
+ name(): string;
634
+ body(): RuntimeBytes;
635
+ createdAt(): number;
636
+ isCompletable(): boolean;
637
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
638
+ }
639
+ interface RuntimeQueueInspectMessage {
640
+ id: number;
641
+ name: string;
642
+ createdAtMs: number;
643
+ }
644
+ interface RuntimeScheduledEventInfo {
645
+ id: string;
646
+ action: string;
647
+ args: RuntimeBytes;
648
+ runAt: number;
649
+ }
650
+ interface RuntimeCronJobInfo {
651
+ name: string;
652
+ kind: "cron" | "every";
653
+ action: string;
654
+ args: RuntimeBytes;
655
+ nextRunAt: number;
656
+ lastRunAt?: number;
657
+ expression?: string;
658
+ timezone?: string;
659
+ intervalMs?: number;
660
+ maxHistory: number;
661
+ }
662
+ interface RuntimeScheduleErrorInfo {
663
+ group: string;
664
+ code: string;
665
+ message: string;
666
+ metadata?: unknown;
667
+ }
668
+ interface RuntimeCronFire {
669
+ action: string;
670
+ scheduledAt: number;
671
+ firedAt: number;
672
+ finishedAt?: number;
673
+ result: "running" | "ok" | "error" | "skipped";
674
+ error?: RuntimeScheduleErrorInfo;
675
+ }
676
+ interface RuntimeQueueNextBatchOptions {
677
+ names?: string[];
678
+ count?: number;
679
+ timeoutMs?: number;
680
+ completable?: boolean;
681
+ }
682
+ interface RuntimeQueueWaitOptions {
683
+ timeoutMs?: number;
684
+ completable?: boolean;
685
+ }
686
+ interface RuntimeQueueEnqueueAndWaitOptions {
687
+ timeoutMs?: number;
688
+ }
689
+ interface RuntimeQueueTryNextBatchOptions {
690
+ names?: string[];
691
+ count?: number;
692
+ completable?: boolean;
693
+ }
694
+ interface RuntimeKvListOptions {
695
+ reverse?: boolean;
696
+ limit?: number;
697
+ }
698
+ interface RuntimeKvEntry {
699
+ key: RuntimeBytes;
700
+ value: RuntimeBytes;
701
+ }
702
+ type RuntimeSqlBindNoValues = {
703
+ intValue?: never;
704
+ floatValue?: never;
705
+ textValue?: never;
706
+ blobValue?: never;
707
+ };
708
+ type RuntimeSqlBindParam = ({
709
+ kind: "null";
710
+ } & RuntimeSqlBindNoValues) | {
711
+ kind: "int";
712
+ intValue: number;
713
+ floatValue?: never;
714
+ textValue?: never;
715
+ blobValue?: never;
716
+ } | {
717
+ kind: "float";
718
+ intValue?: never;
719
+ floatValue: number;
720
+ textValue?: never;
721
+ blobValue?: never;
722
+ } | {
723
+ kind: "text";
724
+ intValue?: never;
725
+ floatValue?: never;
726
+ textValue: string;
727
+ blobValue?: never;
728
+ } | {
729
+ kind: "blob";
730
+ intValue?: never;
731
+ floatValue?: never;
732
+ textValue?: never;
733
+ blobValue: RuntimeBytes;
734
+ };
735
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
736
+ interface RuntimeSqlQueryResult {
737
+ columns: string[];
738
+ rows: unknown[][];
739
+ }
740
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
741
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
742
+ changes: number;
743
+ lastInsertRowId?: number | null;
744
+ }
745
+ interface RuntimeSqlBatchStatement {
746
+ sql: string;
747
+ params?: RuntimeSqlBindParams;
748
+ }
749
+ interface RuntimeSqlRunResult {
750
+ changes: number;
751
+ }
752
+ /** Sample rates for the traces an actor starts, in the shape core takes. */
753
+ interface RuntimeActorTracingConfig {
754
+ sampler?: number;
755
+ /** Keyed by flattened, dot-separated action name. */
756
+ actions?: Record<string, number>;
757
+ }
758
+ interface RuntimeActorConfig {
759
+ name?: string;
760
+ icon?: string;
761
+ hasDatabase?: boolean;
762
+ remoteSqlite?: boolean;
763
+ sqliteDeferredCommits?: boolean;
764
+ sqliteProfiling?: SqliteProfilingOptions;
765
+ tracing?: RuntimeActorTracingConfig;
766
+ hasState?: boolean;
767
+ canHibernateWebsocket?: boolean;
768
+ stateSaveIntervalMs?: number;
769
+ createStateTimeoutMs?: number;
770
+ onCreateTimeoutMs?: number;
771
+ createVarsTimeoutMs?: number;
772
+ createConnStateTimeoutMs?: number;
773
+ onBeforeConnectTimeoutMs?: number;
774
+ onConnectTimeoutMs?: number;
775
+ onMigrateTimeoutMs?: number;
776
+ onWakeTimeoutMs?: number;
777
+ onBeforeActorStartTimeoutMs?: number;
778
+ actionTimeoutMs?: number;
779
+ onRequestTimeoutMs?: number;
780
+ sleepTimeoutMs?: number;
781
+ noSleep?: boolean;
782
+ sleepGracePeriodMs?: number;
783
+ connectionLivenessTimeoutMs?: number;
784
+ connectionLivenessIntervalMs?: number;
785
+ maxQueueSize?: number;
786
+ maxSchedules?: number;
787
+ maxQueueMessageSize?: number;
788
+ maxIncomingMessageSize?: number;
789
+ maxOutgoingMessageSize?: number;
790
+ preloadMaxWorkflowBytes?: number;
791
+ preloadMaxConnectionsBytes?: number;
792
+ actions?: Array<{
793
+ name: string;
794
+ }>;
795
+ inspectorTabs?: Array<RuntimeInspectorTabEntry>;
796
+ }
797
+ interface RuntimeInspectorTabEntry {
798
+ id: string;
799
+ /** Required for custom entries; omitted for built-in hides. */
800
+ label?: string;
801
+ /**
802
+ * Required for custom entries — absolute path to the source directory.
803
+ * Resolved on the TS side before being handed to the runtime.
804
+ */
805
+ source?: string;
806
+ /** Optional icon id for custom entries. */
807
+ icon?: string;
808
+ /** Set to true for built-in hide entries. */
809
+ hidden?: boolean;
810
+ }
811
+ interface RuntimeServeConfig {
812
+ version: number;
813
+ endpoint: string;
814
+ token?: string;
815
+ namespace: string;
816
+ poolName: string;
817
+ engineBinaryPath?: string;
818
+ startServices?: boolean;
819
+ servicesBinaryPath?: string;
820
+ /** Whether config resolution selected a managed local development engine. */
821
+ engineSpawn?: boolean;
822
+ engineHost?: string;
823
+ enginePort?: number;
824
+ handleInspectorHttpInRuntime?: boolean;
825
+ inspectorTestToken?: string;
826
+ serverlessBasePath?: string;
827
+ serverlessPackageVersion: string;
828
+ serverlessClientEndpoint?: string;
829
+ serverlessClientNamespace?: string;
830
+ serverlessClientToken?: string;
831
+ serverlessValidateEndpoint: boolean;
832
+ serverlessMaxStartPayloadBytes: number;
833
+ }
834
+ interface RuntimeListenerConfig {
835
+ port: number;
836
+ host?: string;
837
+ publicDir?: string;
838
+ application?: RuntimeApplicationFetch;
839
+ }
840
+ interface RuntimeServerlessRequest {
841
+ method: string;
842
+ url: string;
843
+ headers: Record<string, string>;
844
+ body: RuntimeBytes;
845
+ }
846
+ interface RuntimeApplicationRequest extends RuntimeServerlessRequest {
847
+ cancelToken?: CancellationTokenHandle;
848
+ }
849
+ interface RuntimeApplicationResponse {
850
+ status: number;
851
+ headers: Record<string, string>;
852
+ body?: RuntimeBytes;
853
+ stream?: boolean;
854
+ }
855
+ type RuntimeApplicationFetch = (request: RuntimeApplicationRequest, responseBodyStream?: RuntimeHttpResponseBodyStream) => Promise<RuntimeApplicationResponse>;
856
+ interface RuntimeApplicationListenerConfig extends RuntimeListenerConfig {
857
+ application: RuntimeApplicationFetch;
858
+ }
859
+ interface RuntimeServerlessResponseHead {
860
+ status: number;
861
+ headers: Record<string, string>;
862
+ }
863
+ interface RuntimeRegistryRouteResponse {
864
+ status: number;
865
+ headers: Record<string, string>;
866
+ body: RuntimeBytes;
867
+ }
868
+ type RuntimeServerlessStreamEvent = {
869
+ kind: "chunk";
870
+ chunk?: RuntimeBytes;
871
+ } | {
872
+ kind: "end";
873
+ error?: {
874
+ group: string;
875
+ code: string;
876
+ message: string;
877
+ };
878
+ };
879
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
880
+ type RuntimeWebSocketEvent = {
881
+ kind: "message";
882
+ data: string | RuntimeBytes;
883
+ binary: boolean;
884
+ messageIndex?: number;
885
+ } | {
886
+ kind: "close";
887
+ code: number;
888
+ reason: string;
889
+ wasClean: boolean;
890
+ };
891
+ interface CoreRuntime {
892
+ readonly kind: "napi" | "wasm";
893
+ createRegistry(): RegistryHandle;
894
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
895
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
896
+ waitRegistryReady(registry: RegistryHandle): Promise<void>;
897
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
898
+ shutdownTelemetry?(): Promise<void>;
899
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
900
+ registryActiveActorCount?(registry: RegistryHandle): number;
901
+ onRegistryActiveActorCountChange?(registry: RegistryHandle, callback: (count: number) => void, cancelToken: CancellationTokenHandle): void;
902
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
903
+ serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
904
+ serveApplicationListener(registry: RegistryHandle, listener: RuntimeApplicationListenerConfig, config: RuntimeServeConfig): Promise<void>;
905
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
906
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
907
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
908
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
909
+ createCancellationToken(): CancellationTokenHandle;
910
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
911
+ cancelCancellationToken(token: CancellationTokenHandle): void;
912
+ /**
913
+ * Calls `callback` once when `token` is cancelled. Returns a release
914
+ * function that drops the registration without calling `callback`; call it
915
+ * once cancellation no longer matters so the native listener is freed.
916
+ */
917
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): () => void;
918
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
919
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
920
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
921
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
922
+ actorSetRunWakeAt(ctx: ActorContextHandle, timestampMs?: number | undefined | null): Promise<void>;
923
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
924
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
925
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
926
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
927
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
928
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
929
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
930
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
931
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
932
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
933
+ actorSaveStateAndWorkflowBatch(ctx: ActorContextHandle, writes: RuntimeWorkflowKvWrite[]): Promise<void>;
934
+ actorId(ctx: ActorContextHandle): string;
935
+ /**
936
+ * Runs one actor callback with `ctx` as the current invocation: operations
937
+ * on retained handles for the same actor resolve to it, and its Core span
938
+ * is the active OpenTelemetry span for the duration of `run`. Only actions,
939
+ * raw requests, and queue dispatch run this way; other callbacks have no
940
+ * invocation span.
941
+ */
942
+ runWithActorInvocationContext<T>(ctx: ActorContextHandle, run: () => T): T;
943
+ /**
944
+ * Correlation of the invocation currently executing for this actor, or
945
+ * `undefined` outside an invocation or after it finished. A sampled-out
946
+ * invocation can still expose valid span context for propagation.
947
+ */
948
+ actorInvocationTraceContext(ctx: ActorContextHandle): ActorInvocationTraceContext | undefined;
949
+ /**
950
+ * Opens the span covering one call this actor makes to another actor. See
951
+ * `StartCallSpan` for when this returns nothing.
952
+ */
953
+ startCallSpan(ctx: ActorContextHandle, actorName: string, actionName: string): RuntimeOutboundCall | undefined;
954
+ /** Backs `ActorRun.startWorkflowSpan`. */
955
+ startWorkflowSpan(ctx: ActorContextHandle): Promise<WorkflowSpan>;
956
+ /** Backs `ActorRun.runOutsideWorkflowSpan`. */
957
+ runOutsideActorInvocationContext<T>(run: () => T): T;
958
+ /** Identity of the invocation the caller runs in, usable as a cache key. */
959
+ currentInvocationScope(): object | undefined;
960
+ actorName(ctx: ActorContextHandle): string;
961
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
962
+ /** The individual actor forks behind the actor, oldest first. */
963
+ actorForkChain(ctx: ActorContextHandle): RuntimeForkLink[];
964
+ actorRegion(ctx: ActorContextHandle): string;
965
+ /** The name of the namespace the actor runs in. */
966
+ actorNamespace(ctx: ActorContextHandle): string;
967
+ actorSleep(ctx: ActorContextHandle): void;
968
+ actorDestroy(ctx: ActorContextHandle): void;
969
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
970
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
971
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
972
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
973
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
974
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
975
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
976
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
977
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
978
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
979
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
980
+ actorRuntimeState(ctx: ActorContextHandle): object;
981
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
982
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
983
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
984
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
985
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
986
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
987
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
988
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
989
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
990
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
991
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
992
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
993
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
994
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
995
+ actorSqlExecSync(ctx: ActorContextHandle, sql: string): RuntimeSqlExecResult;
996
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
997
+ actorSqlExecuteSync(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): RuntimeSqlExecuteResult;
998
+ actorSqlExecuteBatch(ctx: ActorContextHandle, statements: RuntimeSqlBatchStatement[]): Promise<RuntimeSqlExecuteResult[]>;
999
+ actorSqlBeginTransaction(ctx: ActorContextHandle, timeoutMs?: number, name?: string): Promise<SqliteTransactionHandle>;
1000
+ actorSqlBeginTransactionSync(ctx: ActorContextHandle, timeoutMs?: number, name?: string): SqliteTransactionHandle;
1001
+ actorSqlTransactionExec(transaction: SqliteTransactionHandle, sql: string): Promise<RuntimeSqlExecResult>;
1002
+ actorSqlTransactionExecSync(transaction: SqliteTransactionHandle, sql: string): RuntimeSqlExecResult;
1003
+ actorSqlTransactionExecute(transaction: SqliteTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
1004
+ actorSqlTransactionExecuteSync(transaction: SqliteTransactionHandle, sql: string, params?: RuntimeSqlBindParams): RuntimeSqlExecuteResult;
1005
+ actorSqlTransactionCommit(transaction: SqliteTransactionHandle): Promise<void>;
1006
+ actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void;
1007
+ actorSqlTransactionRollback(transaction: SqliteTransactionHandle): Promise<void>;
1008
+ actorSqlTransactionRollbackSync(transaction: SqliteTransactionHandle): void;
1009
+ actorBeginStateTransaction(ctx: ActorContextHandle, timeoutMs?: number, name?: string): Promise<ActorStateTransactionHandle>;
1010
+ actorStateTransactionExecute(transaction: ActorStateTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
1011
+ actorStateTransactionCommit(transaction: ActorStateTransactionHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
1012
+ actorStateTransactionRollback(transaction: ActorStateTransactionHandle): Promise<void>;
1013
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
1014
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
1015
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
1016
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
1017
+ /** Opens the actor database so later synchronous calls never fetch its first pages. */
1018
+ actorSqlOpen(ctx: ActorContextHandle): Promise<void>;
1019
+ /** Returns the ticket of the latest local commit. */
1020
+ actorSqlCommitTicket(ctx: ActorContextHandle): number;
1021
+ /** Resolves once the commit `ticket` names and every earlier commit are durable. */
1022
+ actorSqlWhenDurable(ctx: ActorContextHandle, ticket: number): Promise<void>;
1023
+ actorSqlAbortGeneration(ctx: ActorContextHandle, reason: string): void;
1024
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
1025
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
1026
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
1027
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
1028
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
1029
+ actorQueueCompletePersisted(ctx: ActorContextHandle, messageId: bigint, expectedName: string, response?: RuntimeBytes | undefined | null): Promise<boolean>;
1030
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
1031
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
1032
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
1033
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
1034
+ actorQueueReset(ctx: ActorContextHandle): Promise<void>;
1035
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
1036
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
1037
+ actorScheduleCancel(ctx: ActorContextHandle, id: string): Promise<boolean>;
1038
+ actorScheduleGet(ctx: ActorContextHandle, id: string): Promise<RuntimeScheduledEventInfo | undefined>;
1039
+ actorScheduleList(ctx: ActorContextHandle): Promise<RuntimeScheduledEventInfo[]>;
1040
+ actorCronSet(ctx: ActorContextHandle, name: string, expression: string, timezone: string | undefined, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
1041
+ actorCronEvery(ctx: ActorContextHandle, name: string, intervalMs: number, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
1042
+ actorCronGet(ctx: ActorContextHandle, name: string): Promise<RuntimeCronJobInfo | undefined>;
1043
+ actorCronList(ctx: ActorContextHandle): Promise<RuntimeCronJobInfo[]>;
1044
+ actorCronDelete(ctx: ActorContextHandle, name: string): Promise<boolean>;
1045
+ actorCronHistory(ctx: ActorContextHandle, name: string, limit: number | undefined): Promise<RuntimeCronFire[]>;
1046
+ connId(conn: ConnHandle): string;
1047
+ connParams(conn: ConnHandle): RuntimeBytes;
1048
+ connState(conn: ConnHandle): RuntimeBytes;
1049
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
1050
+ connIsHibernatable(conn: ConnHandle): boolean;
1051
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
1052
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
1053
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
1054
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
1055
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
1056
+ }
1057
+
362
1058
  interface QueueSendWaitOptions {
363
1059
  wait: true;
364
1060
  timeout?: number;
@@ -384,6 +1080,14 @@ interface QueueSendResult<TResponse = unknown> {
384
1080
  * @returns {Promise<Response>}
385
1081
  */
386
1082
  type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
1083
+ type IsAny<T> = 0 extends 1 & T ? true : false;
1084
+ type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
1085
+ type ActorActionMap<R> = {
1086
+ [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;
1087
+ };
1088
+ type ActionsOf<AD extends AnyActorDefinition> = AD["config"] extends {
1089
+ actions?: infer R;
1090
+ } ? R : never;
387
1091
  interface ActorGatewayOptions {
388
1092
  skipReadyWait?: boolean;
389
1093
  }
@@ -396,26 +1100,46 @@ type ActorWebSocketOptions = ActorGatewayOptions;
396
1100
  /**
397
1101
  * Maps action methods from actor definition to typed function signatures.
398
1102
  */
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;
1103
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
402
1104
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
1105
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
403
1106
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
1107
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
404
1108
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
1109
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
405
1110
  (name: keyof TQueues extends never ? string : never, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1111
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
406
1112
  (name: keyof TQueues extends never ? string : never, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
407
1113
  };
408
1114
  type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
409
1115
  <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
410
1116
  (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
411
1117
  };
412
- type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
1118
+ type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1119
+ send: ActorQueueSend<Record<string, any>>;
1120
+ } : AD extends {
1121
+ config: {
1122
+ queues?: infer Q;
1123
+ };
1124
+ } ? Q extends QueueSchemaConfig ? {
1125
+ send: ActorQueueSend<Q>;
1126
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
413
1127
  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 ? {
1128
+ } : {} : {};
1129
+ type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1130
+ on: LooseEventSubscribe;
1131
+ once: LooseEventSubscribe;
1132
+ } : AD extends {
1133
+ config: {
1134
+ events?: infer E;
1135
+ };
1136
+ } ? E extends EventSchemaConfig ? {
1137
+ on: ActorEventSubscribe<E>;
1138
+ once: ActorEventSubscribe<E>;
1139
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
416
1140
  on: ActorEventSubscribe<E>;
417
1141
  once: ActorEventSubscribe<E>;
418
- } : never : never;
1142
+ } : {} : {};
419
1143
 
420
1144
  declare class ActorClientError extends Error {
421
1145
  }
@@ -480,8 +1204,10 @@ declare class ActorConnRaw {
480
1204
  *
481
1205
  * @protected
482
1206
  */
483
- constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions);
1207
+ constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions, currentActorInvocation?: CurrentActorInvocation);
1208
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
484
1209
  send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1210
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
485
1211
  send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
486
1212
  /**
487
1213
  * Call a raw action connection. See {@link ActorConn} for type-safe action calls.
@@ -601,6 +1327,27 @@ declare class ActorConnRaw {
601
1327
  */
602
1328
  type ActorConn<AD extends AnyActorDefinition> = Omit<ActorConnRaw, "send" | "on" | "once"> & ActorDefinitionQueueSend<AD> & ActorDefinitionEventSubscriptions<AD> & ActorDefinitionActions<AD>;
603
1329
 
1330
+ /** How many retries a client may spend, as a share of the requests it sends. */
1331
+ interface RetryBudgetOptions {
1332
+ /** Retries allowed per 100 requests (default 10). */
1333
+ percent?: number;
1334
+ /** Retries the client can bank for a burst of refusals; the budget starts full (default 100). */
1335
+ maxTokens?: number;
1336
+ }
1337
+ /**
1338
+ * Bounds the client's retries of refused requests. Each request adds a fraction of a token and
1339
+ * each retry spends one, so retries stay a fixed share of traffic while the service sheds load
1340
+ * instead of multiplying it.
1341
+ */
1342
+ declare class RetryBudget {
1343
+ #private;
1344
+ constructor(options?: RetryBudgetOptions);
1345
+ /** Credits one request sent. */
1346
+ deposit(): void;
1347
+ /** Spends one token. Returns `false` when the budget is spent. */
1348
+ tryWithdraw(): boolean;
1349
+ }
1350
+
604
1351
  /**
605
1352
  * Provides underlying functions for stateless {@link ActorHandle} for action calls.
606
1353
  * Similar to ActorConnRaw but doesn't maintain a connection.
@@ -616,8 +1363,10 @@ declare class ActorHandleRaw {
616
1363
  *
617
1364
  * @protected
618
1365
  */
619
- constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions);
1366
+ constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions, signal?: AbortSignal, currentActorInvocation?: CurrentActorInvocation, startCallSpan?: StartCallSpan, retryBudget?: RetryBudget);
1367
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
620
1368
  send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1369
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
621
1370
  send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
622
1371
  /**
623
1372
  * Call a raw action. This method sends an HTTP request to invoke the named action.
@@ -650,6 +1399,8 @@ declare class ActorHandleRaw {
650
1399
  * Resolves the actor to get its unique actor ID.
651
1400
  */
652
1401
  resolve(): Promise<string>;
1402
+ /** Issue a token scoped to this actor. Defaults to actor gateway read access. */
1403
+ issueToken(options?: ActorIssueTokenOptions): Promise<IssuedToken>;
653
1404
  /**
654
1405
  * Returns the raw URL for routing traffic to the actor.
655
1406
  */
@@ -675,11 +1426,17 @@ declare class ActorHandleRaw {
675
1426
  type ActorHandle<AD extends AnyActorDefinition> = Omit<ActorHandleRaw, "connect" | "send"> & {
676
1427
  connect(params?: unknown, options?: ActorConnectOptions): ActorConn<AD>;
677
1428
  resolve(): Promise<string>;
678
- } & ActorDefinitionQueueSend<AD> & ActorDefinitionActions<AD>;
1429
+ } & ActorDefinitionQueueSend<AD> & Omit<ActorDefinitionActions<AD>, keyof ActorHandleRaw>;
1430
+
1431
+ /** Called when RivetKit needs a credential. Keep issuer secrets on your backend. */
1432
+ type GetToken = (options: {
1433
+ forceRefresh: boolean;
1434
+ }) => Promise<string>;
679
1435
 
680
1436
  declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
681
1437
  endpoint: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string, string | undefined>>;
682
1438
  token: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
1439
+ getToken: z$1.ZodOptional<z$1.ZodCustom<GetToken, GetToken>>;
683
1440
  namespace: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
684
1441
  poolName: z$1.ZodDefault<z$1.ZodString>;
685
1442
  encoding: z$1.ZodDefault<z$1.ZodEnum<{
@@ -692,6 +1449,11 @@ declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
692
1449
  skipReadyWait: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
693
1450
  }, z$1.core.$strip>>>;
694
1451
  getUpgradeWebSocket: z$1.ZodOptional<z$1.ZodCustom<GetUpgradeWebSocket, GetUpgradeWebSocket>>;
1452
+ retryBudget: z$1.ZodOptional<z$1.ZodObject<{
1453
+ percent: z$1.ZodOptional<z$1.ZodNumber>;
1454
+ maxTokens: z$1.ZodOptional<z$1.ZodNumber>;
1455
+ }, z$1.core.$strip>>;
1456
+ fetch: z$1.ZodOptional<z$1.ZodCustom<typeof fetch, typeof fetch>>;
695
1457
  disableMetadataLookup: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
696
1458
  maxInputSize: z$1.ZodDefault<z$1.ZodNumber>;
697
1459
  devtools: z$1.ZodDefault<z$1.ZodBoolean>;
@@ -708,7 +1470,13 @@ declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
708
1470
  disableMetadataLookup: boolean;
709
1471
  maxInputSize: number;
710
1472
  devtools: boolean;
1473
+ getToken?: GetToken | undefined;
711
1474
  getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
1475
+ retryBudget?: {
1476
+ percent?: number | undefined;
1477
+ maxTokens?: number | undefined;
1478
+ } | undefined;
1479
+ fetch?: typeof fetch | undefined;
712
1480
  }, {
713
1481
  endpoint: string;
714
1482
  token: string | undefined;
@@ -722,7 +1490,13 @@ declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
722
1490
  disableMetadataLookup: boolean;
723
1491
  maxInputSize: number;
724
1492
  devtools: boolean;
1493
+ getToken?: GetToken | undefined;
725
1494
  getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
1495
+ retryBudget?: {
1496
+ percent?: number | undefined;
1497
+ maxTokens?: number | undefined;
1498
+ } | undefined;
1499
+ fetch?: typeof fetch | undefined;
726
1500
  }>>;
727
1501
  type ClientConfigInput = z$1.input<typeof ClientConfigSchema>;
728
1502
 
@@ -785,6 +1559,20 @@ interface ActorAccessor<AD extends AnyActorDefinition> {
785
1559
  * @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
786
1560
  */
787
1561
  create(key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
1562
+ /**
1563
+ * Forks the actor `actorId` into a new actor of this name, and returns a
1564
+ * stateless handle to the new actor with its ID resolved.
1565
+ *
1566
+ * The new actor starts at once on a copy of the source's database as of
1567
+ * its last committed write, runs `onFork` once with `opts.input`, and
1568
+ * keeps running independently of the source. A fork is not idempotent:
1569
+ * a `key` already held answers `actor.duplicate_key`.
1570
+ *
1571
+ * @param {string} actorId - The ID of the source actor.
1572
+ * @param {ForkOptions} [opts] - The new actor's key and the fork input.
1573
+ * @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the new actor.
1574
+ */
1575
+ fork(actorId: string, opts?: ForkOptions): Promise<ActorHandle<AD>>;
788
1576
  }
789
1577
  /**
790
1578
  * Options for querying actors.
@@ -824,6 +1612,11 @@ interface GetOrCreateOptions extends QueryOptions {
824
1612
  createInRegion?: string;
825
1613
  /** Input data to pass to the actor. */
826
1614
  createWithInput?: unknown;
1615
+ /**
1616
+ * Name of the envoy pool to select for this actor if it is created.
1617
+ * Overrides the client's configured `poolName` for this call.
1618
+ */
1619
+ poolName?: string;
827
1620
  }
828
1621
  /**
829
1622
  * Options for creating a actor.
@@ -835,6 +1628,20 @@ interface CreateOptions extends QueryOptions {
835
1628
  region?: string;
836
1629
  /** Input data to pass to the actor. */
837
1630
  input?: unknown;
1631
+ /**
1632
+ * Name of the envoy pool to select for this actor.
1633
+ * Overrides the client's configured `poolName` for this call.
1634
+ */
1635
+ poolName?: string;
1636
+ }
1637
+ /**
1638
+ * Options for forking an actor.
1639
+ */
1640
+ interface ForkOptions extends QueryOptions {
1641
+ /** The new actor's key. Omit for a keyless actor. */
1642
+ key?: string | string[];
1643
+ /** The fork input, passed to the new actor's `onFork` hook. */
1644
+ input?: unknown;
838
1645
  }
839
1646
  /**
840
1647
  * Represents a region to connect to.
@@ -856,6 +1663,20 @@ interface Region {
856
1663
  }
857
1664
  declare const ACTOR_CONNS_SYMBOL: unique symbol;
858
1665
  declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
1666
+ /** Options for constructing a raw actor client. */
1667
+ interface ClientRawOptions {
1668
+ encoding?: Encoding;
1669
+ gateway?: ActorGatewayOptions;
1670
+ /** Bounds retries of refused requests across every handle of this client. */
1671
+ retryBudget?: RetryBudgetOptions;
1672
+ }
1673
+ /** Runtime-supplied wiring for clients created inside an actor. Set only by the native runtime. */
1674
+ interface ActorClientRuntimeOptions {
1675
+ /** Supplies the calling actor's invocation so actor-to-actor clients propagate its trace and ray ID. */
1676
+ currentActorInvocation?: CurrentActorInvocation;
1677
+ /** Opens and finishes the Core span covering an actor-to-actor call. */
1678
+ startCallSpan?: StartCallSpan;
1679
+ }
859
1680
  /**
860
1681
  * Client for managing & connecting to actors.
861
1682
  *
@@ -864,11 +1685,15 @@ declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
864
1685
  */
865
1686
  declare class ClientRaw {
866
1687
  #private;
1688
+ /** Issue namespace-scoped tokens with an explicit grant list. */
1689
+ readonly auth: {
1690
+ issueToken(options: IssueTokenOptions): Promise<IssuedToken>;
1691
+ };
867
1692
  [ACTOR_CONNS_SYMBOL]: Set<ActorConnRaw>;
868
1693
  /**
869
1694
  * Creates an instance of Client.
870
1695
  */
871
- constructor(driver: EngineControlClient, encoding: Encoding | undefined, gatewayOptions?: ActorGatewayOptions);
1696
+ constructor(driver: EngineControlClient, options?: ClientRawOptions & ActorClientRuntimeOptions);
872
1697
  /**
873
1698
  * Gets a stateless handle to a actor by its ID.
874
1699
  *
@@ -910,6 +1735,16 @@ declare class ClientRaw {
910
1735
  * @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
911
1736
  */
912
1737
  create<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
1738
+ /**
1739
+ * Forks the actor `actorId` into a new actor and returns a handle to it.
1740
+ *
1741
+ * @template AD The actor class that this handle is for.
1742
+ * @param {string} name - The name of the actor; the source has the same name.
1743
+ * @param {string} actorId - The ID of the source actor.
1744
+ * @param {ForkOptions} [opts] - The new actor's key and the fork input.
1745
+ * @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the new actor.
1746
+ */
1747
+ fork<AD extends AnyActorDefinition>(name: string, actorId: string, opts?: ForkOptions): Promise<ActorHandle<AD>>;
913
1748
  [CREATE_ACTOR_CONN_PROXY]<AD extends AnyActorDefinition>(conn: ActorConnRaw): ActorConn<AD>;
914
1749
  /**
915
1750
  * Disconnects from all actors.
@@ -924,9 +1759,12 @@ declare class ClientRaw {
924
1759
  *
925
1760
  * @template A The actor registry type.
926
1761
  */
927
- type Client<A extends Registry<any>> = ClientRaw & {
1762
+ type Client<A extends Registry<any>> = ClientRaw & Omit<{
928
1763
  [K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<ExtractActorsFromRegistry<A>[K]>;
929
- };
1764
+ }, keyof ClientRaw>;
1765
+
1766
+ /** @experimental State exposed by a durable workflow run handler to the Inspector. */
1767
+ type WorkflowState = "pending" | "running" | "sleeping" | "failed" | "completed" | "cancelled" | "rolling_back";
930
1768
 
931
1769
  declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
932
1770
  declare const RAW_STATE_SYMBOL: unique symbol;
@@ -962,6 +1800,7 @@ type ActorKvListOptions<T extends ActorKvValueType = "text", K extends ActorKvKe
962
1800
  limit?: number;
963
1801
  };
964
1802
  type ActorClientFor<T> = T extends Registry<any> ? Client<T> : T;
1803
+ /** @deprecated Actor KV was deprecated in 3.0 and will be removed in a future version. Store data in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/kv */
965
1804
  interface ActorKv {
966
1805
  get<T extends ActorKvValueType = "text">(key: Uint8Array | string, options?: ActorKvValueOptions<T>): Promise<ActorKvValueTypeMap[T] | null>;
967
1806
  put<T extends ActorKvValueType = "text">(key: Uint8Array | string, value: Uint8Array | string | ArrayBuffer, options?: ActorKvValueOptions<T>): Promise<void>;
@@ -975,11 +1814,101 @@ interface ActorKv {
975
1814
  list<T extends ActorKvValueType = "text", K extends ActorKvKeyType = "text">(prefix: Uint8Array | string, options?: ActorKvListOptions<T, K>): Promise<Array<[ActorKvKeyTypeMap[K], ActorKvValueTypeMap[T]]>>;
976
1815
  [key: string]: any;
977
1816
  }
1817
+ /** One individual actor fork behind an actor, as `c.forkChain` lists it. */
1818
+ interface ActorForkLink {
1819
+ /** The source actor's ID. */
1820
+ actorId: string;
1821
+ /** The source actor's key. */
1822
+ key: string[];
1823
+ /** When the fork was made, in milliseconds since the epoch. */
1824
+ forkedAt: number;
1825
+ }
1826
+ /** The fork an `onFork` hook runs for: the newest entry of `c.forkChain` and the fork input. */
1827
+ interface ActorFork extends ActorForkLink {
1828
+ /**
1829
+ * The `input` passed to `client.<actor>.fork`, or `undefined`. It comes from the caller that
1830
+ * forked the actor, so validate it like any client input.
1831
+ */
1832
+ input: unknown;
1833
+ }
978
1834
  interface ActorSchedule {
979
- after(duration: number, action: string, ...args: unknown[]): Promise<void>;
980
- at(timestamp: number, action: string, ...args: unknown[]): Promise<void>;
1835
+ after(duration: number, action: string, ...args: unknown[]): Promise<string>;
1836
+ at(timestamp: number, action: string, ...args: unknown[]): Promise<string>;
1837
+ cancel(id: string): Promise<boolean>;
1838
+ get(id: string): Promise<ScheduledEventInfo | undefined>;
1839
+ list(): Promise<ScheduledEventInfo[]>;
1840
+ [key: string]: any;
1841
+ }
1842
+ interface ActorCronSetOptions {
1843
+ name: string;
1844
+ expression: string;
1845
+ action: string;
1846
+ args?: unknown[];
1847
+ timezone?: string;
1848
+ /** Defaults to 100. Set to 0 to disable and clear history. Maximum 1,000. */
1849
+ maxHistory?: number;
1850
+ }
1851
+ interface ActorCronEveryOptions {
1852
+ name: string;
1853
+ /** Fixed interval in milliseconds. Minimum 5,000. */
1854
+ interval: number;
1855
+ action: string;
1856
+ args?: unknown[];
1857
+ /** Defaults to 100. Set to 0 to disable and clear history. Maximum 1,000. */
1858
+ maxHistory?: number;
1859
+ }
1860
+ interface ActorCron {
1861
+ set(options: ActorCronSetOptions): Promise<void>;
1862
+ every(options: ActorCronEveryOptions): Promise<void>;
1863
+ get(name: string): Promise<CronJobInfo | undefined>;
1864
+ list(): Promise<CronJobInfo[]>;
1865
+ delete(name: string): Promise<boolean>;
1866
+ history(name: string, options?: {
1867
+ limit?: number;
1868
+ }): Promise<CronFire[]>;
981
1869
  [key: string]: any;
982
1870
  }
1871
+ interface ScheduledEventInfo {
1872
+ id: string;
1873
+ action: string;
1874
+ args: unknown[];
1875
+ runAt: number;
1876
+ }
1877
+ type CronJobInfo = {
1878
+ name: string;
1879
+ action: string;
1880
+ args: unknown[];
1881
+ nextRunAt: number;
1882
+ lastRunAt?: number;
1883
+ maxHistory: number;
1884
+ } & ({
1885
+ kind: "cron";
1886
+ expression: string;
1887
+ timezone: string;
1888
+ } | {
1889
+ kind: "every";
1890
+ interval: number;
1891
+ });
1892
+ interface ScheduledFireInfo {
1893
+ kind: "at" | "cron" | "every";
1894
+ id: string;
1895
+ name?: string;
1896
+ scheduledAt: number;
1897
+ firedAt: number;
1898
+ }
1899
+ interface CronFire {
1900
+ action: string;
1901
+ scheduledAt: number;
1902
+ firedAt: number;
1903
+ finishedAt?: number;
1904
+ result: "running" | "ok" | "error" | "skipped";
1905
+ error?: {
1906
+ group: string;
1907
+ code: string;
1908
+ message: string;
1909
+ metadata?: unknown;
1910
+ };
1911
+ }
983
1912
  type QueueMessageOf<Name extends string, Body> = {
984
1913
  id: number | bigint;
985
1914
  name: Name;
@@ -990,6 +1919,8 @@ type QueueMessageOf<Name extends string, Body> = {
990
1919
  type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues & string;
991
1920
  type QueueFilterName<TQueues extends QueueSchemaConfig> = keyof TQueues extends never ? string : QueueName<TQueues>;
992
1921
  type QueueMessageForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>> = keyof TQueues extends never ? QueueMessageOf<string, unknown> : TName extends QueueName<TQueues> ? QueueMessageOf<TName, InferSchemaMap<TQueues>[TName]> : never;
1922
+ type QueueCompleteArgs<T> = undefined extends T ? [response?: T] : [response: T];
1923
+ type QueueCompleteArgsForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>> = keyof TQueues extends never ? [response?: unknown] : TName extends QueueName<TQueues> ? [InferQueueCompleteMap<TQueues>[TName]] extends [never] ? [response?: unknown] : QueueCompleteArgs<InferQueueCompleteMap<TQueues>[TName]> : [response?: unknown];
993
1924
  type QueueCompletionResultForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>> = keyof TQueues extends never ? unknown | undefined : TName extends QueueName<TQueues> ? InferQueueCompleteMap<TQueues>[TName] | undefined : unknown | undefined;
994
1925
  interface QueueNextOptions<TName extends string = string, TCompletable extends boolean = boolean> {
995
1926
  names?: readonly TName[];
@@ -1027,20 +1958,29 @@ interface QueueIterOptions<TName extends string = string, TCompletable extends b
1027
1958
  signal?: AbortSignal;
1028
1959
  completable?: TCompletable;
1029
1960
  }
1961
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
1030
1962
  interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1031
1963
  send<TName extends QueueFilterName<TQueues>>(name: TName, body: QueueMessageForName<TQueues, TName>["body"]): Promise<any>;
1032
1964
  next<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueNextOptions<TName, TCompletable>): Promise<any>;
1033
1965
  nextBatch<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueNextBatchOptions<TName, TCompletable>): Promise<any[]>;
1034
1966
  waitForNames<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(names: readonly TName[], opts?: QueueWaitOptions<TCompletable>): Promise<any>;
1967
+ /** @experimental */
1968
+ waitForAvailable<const TName extends QueueFilterName<TQueues>>(names?: readonly TName[], opts?: Omit<QueueWaitOptions<false>, "completable">): Promise<void>;
1969
+ /** @experimental */
1970
+ complete<const TName extends QueueFilterName<TQueues>>(message: {
1971
+ id: number | bigint;
1972
+ name: TName;
1973
+ }, ...args: QueueCompleteArgsForName<TQueues, TName>): Promise<void>;
1035
1974
  enqueueAndWait<const TName extends QueueFilterName<TQueues>>(name: TName, body: QueueMessageForName<TQueues, TName>["body"], opts?: QueueEnqueueAndWaitOptions): Promise<QueueCompletionResultForName<TQueues, TName>>;
1036
1975
  tryNext<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueTryNextOptions<TName, TCompletable>): Promise<any>;
1037
1976
  tryNextBatch<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueTryNextBatchOptions<TName, TCompletable>): Promise<any[]>;
1038
1977
  iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
1039
1978
  [key: string]: any;
1040
1979
  }
1041
- interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TVars = unknown, TInput = unknown, TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1980
+ interface Conn<_TState = unknown, TConnParams = unknown, TConnState = unknown, _TVars = unknown, _TInput = unknown, _TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider, _TEvents extends EventSchemaConfig = Record<never, never>, _TQueues extends QueueSchemaConfig = Record<never, never>> {
1042
1981
  id: string;
1043
1982
  params: TConnParams;
1983
+ /** @deprecated Connection state was deprecated in 3.0 and will be removed in a future version. Track live connections in `c.vars` from `onConnect` and `onDisconnect`, and store durable per-connection data in SQLite. See https://rivet.dev/actors/docs/deprecated/state#connection-state */
1044
1984
  state: TConnState;
1045
1985
  isHibernatable: boolean;
1046
1986
  send(name: string, ...args: any[]): void;
@@ -1051,43 +1991,101 @@ interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase
1051
1991
  [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
1052
1992
  /** Returns the raw unwrapped state without the write-through proxy. */
1053
1993
  [RAW_STATE_SYMBOL](): TState;
1994
+ /** @deprecated Actor state was deprecated in 3.0 and will be removed in a future version. Store durable data in SQLite (`c.db`) and in-memory data in `c.vars`. See https://rivet.dev/actors/docs/deprecated/state */
1054
1995
  state: TState;
1055
1996
  vars: TVars;
1997
+ /** @deprecated Actor KV was deprecated in 3.0 and will be removed in a future version. Store data in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/kv */
1056
1998
  readonly kv: ActorKv;
1057
1999
  readonly db: InferDatabaseClient<TDatabase>;
1058
2000
  readonly schedule: ActorSchedule;
2001
+ readonly cron: ActorCron;
2002
+ /** @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues */
1059
2003
  readonly queue: ActorQueue<TQueues>;
2004
+ /** @experimental */
2005
+ readonly run: ActorRun;
1060
2006
  readonly actorId: string;
1061
2007
  readonly name: string;
1062
2008
  readonly key: string[];
2009
+ /**
2010
+ * The individual actor forks behind this actor, oldest first; empty when it was never
2011
+ * forked. Namespace forks are not listed.
2012
+ */
2013
+ readonly forkChain: ActorForkLink[];
1063
2014
  readonly region: string;
2015
+ /**
2016
+ * The name of the namespace the actor runs in. After a namespace fork it differs from the
2017
+ * source actor's namespace while the actor id stays the same, so an actor that owns an
2018
+ * external resource can store this to detect that it was copied.
2019
+ */
2020
+ readonly namespace: string;
1064
2021
  readonly conns: Map<string, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>>;
1065
2022
  readonly log: ActorLogger;
1066
2023
  readonly abortSignal: AbortSignal;
1067
2024
  readonly aborted: boolean;
1068
2025
  readonly request?: Request;
1069
- /** @deprecated No-op. Always returns `false`. Use `keepAwake(promise)` or `waitUntil(promise)` instead. Will be removed in 2.2.0. */
2026
+ /** @deprecated `preventSleep` was deprecated in 3.0 and will be removed in a future version. It is a no-op that always returns `false`. Use `c.keepAwake(promise)` or `c.waitUntil(promise)`. See https://rivet.dev/actors/docs/deprecated/prevent-sleep */
1070
2027
  readonly preventSleep: boolean;
1071
2028
  broadcast(name: string, ...args: any[]): void;
2029
+ /** @deprecated Actor state was deprecated in 3.0 and will be removed in a future version. Store durable data in SQLite (`c.db`) and in-memory data in `c.vars`. See https://rivet.dev/actors/docs/deprecated/state */
1072
2030
  saveState(opts?: {
1073
2031
  immediate?: boolean;
1074
2032
  maxWait?: number;
1075
2033
  }): Promise<void>;
1076
2034
  keepAwake<T>(promise: Promise<T>): Promise<T>;
1077
2035
  waitUntil(promise: Promise<unknown>): void;
1078
- /** @deprecated No-op. Use `keepAwake(promise)` to hold the actor awake for a specific promise. Will be removed in 2.2.0. */
2036
+ /** @deprecated `setPreventSleep` was deprecated in 3.0 and will be removed in a future version. It is a no-op. Use `c.keepAwake(promise)` or `c.waitUntil(promise)`. See https://rivet.dev/actors/docs/deprecated/prevent-sleep */
1079
2037
  setPreventSleep(preventSleep: boolean): void;
1080
2038
  sleep(): void;
1081
2039
  destroy(): void;
1082
2040
  client<T = any>(): ActorClientFor<T>;
1083
2041
  [key: string]: any;
1084
2042
  }
2043
+ /** @experimental How one run of a workflow function ended. */
2044
+ type WorkflowOutcome = "completed" | "sleeping" | "evicted" | "failed" | "cancelled";
2045
+ /** @experimental How one workflow step attempt ended. `retry` will be tried again, `failed` will not. */
2046
+ type WorkflowStepOutcome = "ok" | "retry" | "failed";
2047
+ /** @experimental One open run of a workflow function, traced as its own invocation. */
2048
+ interface WorkflowSpan {
2049
+ /** Runs `body` attributed to this run. */
2050
+ run<T>(body: () => Promise<T>): Promise<T>;
2051
+ /**
2052
+ * Called by a workflow engine before each attempt at a step. Returns
2053
+ * nothing when tracing is off.
2054
+ */
2055
+ startStep(name: string, attempt: number): WorkflowStepSpan | undefined;
2056
+ finish(outcome: WorkflowOutcome): Promise<void>;
2057
+ }
2058
+ /** @experimental One open attempt at one workflow step. */
2059
+ interface WorkflowStepSpan {
2060
+ /** Runs `body` attributed to this attempt. */
2061
+ run<T>(body: () => Promise<T>): Promise<T>;
2062
+ /** `error` is what the step callback threw. */
2063
+ finish(outcome: WorkflowStepOutcome, error?: unknown): void;
2064
+ }
2065
+ /** @experimental */
2066
+ interface ActorRun {
2067
+ /**
2068
+ * @experimental Sets or clears the durable Unix-millisecond deadline that
2069
+ * ensures this actor's run handler is active, starting it if inactive.
2070
+ */
2071
+ setWakeAt(timestamp: number | null): Promise<void>;
2072
+ /** @experimental Called by a workflow engine each time it runs the workflow function. */
2073
+ startWorkflowSpan(): Promise<WorkflowSpan>;
2074
+ /**
2075
+ * @experimental Runs `body` outside the current workflow run, so a workflow
2076
+ * engine's own history storage stays out of the trace.
2077
+ */
2078
+ runOutsideWorkflowSpan<T>(body: () => T): T;
2079
+ }
1085
2080
  type ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & {
2081
+ /** Present only when a durable schedule or cron invokes this action. */
2082
+ readonly scheduledFire?: ScheduledFireInfo;
1086
2083
  conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1087
2084
  };
1088
2085
  type BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1089
2086
  type BeforeConnectContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, unknown, unknown, TVars, TInput, TDatabase, TEvents, TQueues>;
1090
2087
  type ConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
2088
+ /** @deprecated Connection state was deprecated in 3.0 and will be removed in a future version. Track live connections in `c.vars` from `onConnect` and `onDisconnect`, and store durable per-connection data in SQLite. See https://rivet.dev/actors/docs/deprecated/state#connection-state */
1091
2089
  type CreateConnStateContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, unknown, unknown, TVars, TInput, TDatabase, TEvents, TQueues>;
1092
2090
  type CreateContext<TState, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, unknown, unknown, unknown, TInput, TDatabase, TEvents, TQueues>;
1093
2091
  type CreateVarsContext<TState, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = CreateContext<TState, TInput, TDatabase, TEvents, TQueues>;
@@ -1096,6 +2094,7 @@ type DisconnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase
1096
2094
  type RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1097
2095
  type RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1098
2096
  type SleepContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
2097
+ /** @deprecated Actor state was deprecated in 3.0 and will be removed in a future version. See https://rivet.dev/actors/docs/deprecated/state */
1099
2098
  type StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1100
2099
  type WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1101
2100
  type MigrateContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
@@ -1108,6 +2107,7 @@ declare const RunConfigSchema: z.ZodObject<{
1108
2107
  inspector: z.ZodOptional<z.ZodOptional<z.ZodObject<{
1109
2108
  workflow: z.ZodOptional<z.ZodObject<{
1110
2109
  getHistory: z.ZodCustom<() => unknown, () => unknown>;
2110
+ getState: z.ZodOptional<z.ZodCustom<() => Promise<WorkflowState | null>, () => Promise<WorkflowState | null>>>;
1111
2111
  onHistoryUpdated: z.ZodOptional<z.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
1112
2112
  replayFromStep: z.ZodOptional<z.ZodCustom<(entryId?: string) => Promise<unknown>, (entryId?: string) => Promise<unknown>>>;
1113
2113
  }, z.core.$strip>>;
@@ -1122,6 +2122,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1122
2122
  onDestroy: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1123
2123
  onMigrate: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1124
2124
  onWake: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
2125
+ onFork: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1125
2126
  onSleep: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1126
2127
  run: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>, z.ZodObject<{
1127
2128
  name: z.ZodOptional<z.ZodString>;
@@ -1130,6 +2131,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1130
2131
  inspector: z.ZodOptional<z.ZodOptional<z.ZodObject<{
1131
2132
  workflow: z.ZodOptional<z.ZodObject<{
1132
2133
  getHistory: z.ZodCustom<() => unknown, () => unknown>;
2134
+ getState: z.ZodOptional<z.ZodCustom<() => Promise<WorkflowState | null>, () => Promise<WorkflowState | null>>>;
1133
2135
  onHistoryUpdated: z.ZodOptional<z.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
1134
2136
  replayFromStep: z.ZodOptional<z.ZodCustom<(entryId?: string) => Promise<unknown>, (entryId?: string) => Promise<unknown>>>;
1135
2137
  }, z.core.$strip>>;
@@ -1142,8 +2144,12 @@ declare const ActorConfigSchema: z.ZodObject<{
1142
2144
  onBeforeActionResponse: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1143
2145
  onRequest: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1144
2146
  onWebSocket: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1145
- actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>>;
2147
+ actions: z.ZodDefault<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
1146
2148
  actionInputSchemas: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
2149
+ tracing: z.ZodOptional<z.ZodObject<{
2150
+ sampler: z.ZodOptional<z.ZodNumber>;
2151
+ actions: z.ZodOptional<z.ZodType<ActionSampleRates, unknown, z.core.$ZodTypeInternals<ActionSampleRates, unknown>>>;
2152
+ }, z.core.$strict>>;
1147
2153
  connParamsSchema: z.ZodOptional<z.ZodAny>;
1148
2154
  events: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1149
2155
  queues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
@@ -1173,25 +2179,50 @@ declare const ActorConfigSchema: z.ZodObject<{
1173
2179
  noSleep: z.ZodDefault<z.ZodBoolean>;
1174
2180
  sleepTimeout: z.ZodDefault<z.ZodNumber>;
1175
2181
  maxQueueSize: z.ZodDefault<z.ZodNumber>;
2182
+ maxSchedules: z.ZodDefault<z.ZodNumber>;
1176
2183
  maxQueueMessageSize: z.ZodDefault<z.ZodNumber>;
1177
2184
  preloadMaxWorkflowBytes: z.ZodOptional<z.ZodNumber>;
1178
2185
  preloadMaxConnectionsBytes: z.ZodOptional<z.ZodNumber>;
1179
2186
  }, z.core.$strict>>;
2187
+ inspector: z.ZodOptional<z.ZodObject<{
2188
+ tabs: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
2189
+ id: z.ZodString;
2190
+ label: z.ZodString;
2191
+ source: z.ZodString;
2192
+ icon: z.ZodOptional<z.ZodString>;
2193
+ hidden: z.ZodOptional<z.ZodLiteral<false>>;
2194
+ }, z.core.$strict>, z.ZodObject<{
2195
+ id: z.ZodEnum<{
2196
+ state: "state";
2197
+ database: "database";
2198
+ console: "console";
2199
+ queue: "queue";
2200
+ workflow: "workflow";
2201
+ schedules: "schedules";
2202
+ connections: "connections";
2203
+ }>;
2204
+ hidden: z.ZodLiteral<true>;
2205
+ }, z.core.$strict>]>>>;
2206
+ }, z.core.$strict>>;
1180
2207
  }, z.core.$strict>;
1181
- type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
2208
+ type CreateState<TState, _TConnParams, _TConnState, _TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
2209
+ /** @deprecated Actor state was deprecated in 3.0 and will be removed in a future version. Store durable data in SQLite (`c.db`) and in-memory data in `c.vars`. See https://rivet.dev/actors/docs/deprecated/state */
1182
2210
  state: TState;
1183
2211
  } | {
2212
+ /** @deprecated Actor state was deprecated in 3.0 and will be removed in a future version. Store durable data in SQLite (`c.db`) and in-memory data in `c.vars`. See https://rivet.dev/actors/docs/deprecated/state */
1184
2213
  createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
1185
2214
  } | Record<never, never>;
1186
2215
  type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
2216
+ /** @deprecated Connection state was deprecated in 3.0 and will be removed in a future version. Track live connections in `c.vars` from `onConnect` and `onDisconnect`, and store durable per-connection data in SQLite. See https://rivet.dev/actors/docs/deprecated/state#connection-state */
1187
2217
  connState: TConnState;
1188
2218
  } | {
2219
+ /** @deprecated Connection state was deprecated in 3.0 and will be removed in a future version. Track live connections in `c.vars` from `onConnect` and `onDisconnect`, and store durable per-connection data in SQLite. See https://rivet.dev/actors/docs/deprecated/state#connection-state */
1189
2220
  createConnState: (c: CreateConnStateContext<TState, TVars, TInput, TDatabase, TEvents, TQueues>, params: TConnParams) => TConnState | Promise<TConnState>;
1190
2221
  } | Record<never, never>;
1191
2222
  /**
1192
2223
  * @experimental
1193
2224
  */
1194
- type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
2225
+ type CreateVars<TState, _TConnParams, _TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1195
2226
  /**
1196
2227
  * @experimental
1197
2228
  */
@@ -1203,7 +2234,10 @@ type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extend
1203
2234
  createVars: (c: CreateVarsContext<TState, TInput, TDatabase, TEvents, TQueues>, driverCtx: any) => TVars | Promise<TVars>;
1204
2235
  } | Record<never, never>;
1205
2236
  interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1206
- [Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, ...args: any[]) => any;
2237
+ [Action: string]: ((c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, ...args: any[]) => any) | Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
2238
+ }
2239
+ interface ActionInputSchemas {
2240
+ [Action: string]: PrimitiveSchema | ActionInputSchemas;
1207
2241
  }
1208
2242
  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>> {
1209
2243
  /**
@@ -1224,6 +2258,36 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1224
2258
  * must run on both first boot and wake.
1225
2259
  */
1226
2260
  onMigrate?: (c: MigrateContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, isNew: boolean) => void | Promise<void>;
2261
+ /**
2262
+ * Called once at the first start of an actor made by forking another actor
2263
+ * (`client.<actor>.fork`), after its state loads and before `onWake` and any
2264
+ * overdue schedule events run. `createState` and `onCreate` do not run for a fork.
2265
+ *
2266
+ * Use this hook to cancel schedules the fork inherited, drop resources copied
2267
+ * from the source, or record the fork input. `c.forkChain` already ends with
2268
+ * this fork. A throw fails the start, and the hook runs again on the next start.
2269
+ * Forks of a whole namespace do not call it.
2270
+ *
2271
+ * State edits made in this hook are saved in one commit with the record that the
2272
+ * fork ran, so a start that finds the fork recorded also finds the hook's final
2273
+ * state. On native SQLite the hook's `c.db` writes and any save it starts itself
2274
+ * join that commit too, and a failed start drops them. Two limits apply:
2275
+ *
2276
+ * - On remote SQLite (wasm runtimes), `c.db` writes, and state the hook writes
2277
+ * itself in a transaction (for example `c.db.transaction` with
2278
+ * `experimental.includeState`), are committed at once, without the fork record.
2279
+ * A `c.saveState` call is not such a write: the startup save carries its
2280
+ * state. Only state the hook leaves to the startup save is atomic with it. A
2281
+ * crash or a failed start before the record lands runs the hook again on top
2282
+ * of those writes, so the hook must be idempotent there.
2283
+ * - On native SQLite the hook's writes must fit one commit (32,768 pages, 128 MiB
2284
+ * at the default page size). A transaction that would take them past it fails as
2285
+ * too large instead of committing part of them early; a hook that lets the error
2286
+ * throw fails the start, and nothing it wrote lands. Move a backfill that large
2287
+ * into later actions.
2288
+ * `onCreate` differs: its writes held so far are committed early instead.
2289
+ */
2290
+ onFork?: (c: WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, fork: ActorFork) => void | Promise<void>;
1227
2291
  /**
1228
2292
  * Called when the actor is started and ready to receive connections and action.
1229
2293
  *
@@ -1269,6 +2333,12 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1269
2333
  *
1270
2334
  * Can be either a function or a RunConfig object with optional name/icon metadata.
1271
2335
  *
2336
+ * Passing a plain function was deprecated in 3.0 and will be removed in a
2337
+ * future version; it logs a warning at startup. Start background work from
2338
+ * `onWake` with `c.keepAwake` and track it in `c.vars` instead.
2339
+ * `run: workflow(...)` is not deprecated. See
2340
+ * https://rivet.dev/actors/docs/deprecated/run
2341
+ *
1272
2342
  * @returns Void or a Promise.
1273
2343
  */
1274
2344
  run?: ((c: RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>) | RunConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
@@ -1282,6 +2352,7 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1282
2352
  * another onStateChange call, preventing infinite recursion.
1283
2353
  *
1284
2354
  * @param newState The updated state
2355
+ * @deprecated Actor state was deprecated in 3.0 and will be removed in a future version. Store durable data in SQLite (`c.db`) and in-memory data in `c.vars`. See https://rivet.dev/actors/docs/deprecated/state
1285
2356
  */
1286
2357
  onStateChange?: (c: StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, newState: TState) => void;
1287
2358
  /**
@@ -1355,9 +2426,15 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1355
2426
  onWebSocket?: (c: WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, websocket: UniversalWebSocket) => void | Promise<void>;
1356
2427
  actions?: TActions;
1357
2428
  /**
1358
- * Optional schema map for validating action argument tuples in native runtimes.
2429
+ * Optional schemas for validating action argument tuples in native runtimes.
2430
+ * May mirror nested action groups or use dot-separated low-level action names.
1359
2431
  */
1360
- actionInputSchemas?: Record<string, PrimitiveSchema>;
2432
+ actionInputSchemas?: ActionInputSchemas;
2433
+ /**
2434
+ * How much of this actor's work is recorded in traces. Defaults to the
2435
+ * process sampler from `OTEL_TRACES_SAMPLER`.
2436
+ */
2437
+ tracing?: ActorTracingOptions<TActions>;
1361
2438
  /**
1362
2439
  * Optional schema for validating connection params in native runtimes.
1363
2440
  */
@@ -1368,6 +2445,8 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1368
2445
  events?: TEvents;
1369
2446
  /**
1370
2447
  * Schema map for queue payloads sent by this actor.
2448
+ *
2449
+ * @deprecated Queues were deprecated in 3.0 and will be removed in a future version. Use actions and store pending work in SQLite (`c.db`). See https://rivet.dev/actors/docs/deprecated/queues
1371
2450
  */
1372
2451
  queues?: TQueues;
1373
2452
  }
@@ -1377,19 +2456,21 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1377
2456
  */
1378
2457
  db: TDatabase;
1379
2458
  } | Record<never, never>;
1380
- type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onMigrate" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
2459
+ 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" | "onFork" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, TActions> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
1381
2460
 
1382
- interface BaseActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> {
1383
- readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
2461
+ 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>> {
2462
+ readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
2463
+ }
2464
+ interface AnyActorDefinition {
2465
+ readonly config: any;
1384
2466
  }
1385
- type AnyActorDefinition = BaseActorDefinition<any, any, any, any, any, any, any, any, any>;
1386
2467
  declare class ActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> implements BaseActorDefinition<S, CP, CS, V, I, DB, E, Q, R> {
1387
2468
  #private;
1388
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
1389
- get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
2469
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>);
2470
+ get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
1390
2471
  }
1391
2472
 
1392
- declare const ActorsSchema: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<BaseActorDefinition<any, any, any, any, any, any, any, any, any>, BaseActorDefinition<any, any, any, any, any, any, any, any, any>>>;
2473
+ declare const ActorsSchema: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
1393
2474
  type RegistryActors = z$2.infer<typeof ActorsSchema>;
1394
2475
  declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1395
2476
  use: z$2.ZodRecord<z$2.ZodString, z$2.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
@@ -1450,7 +2531,10 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1450
2531
  httpPort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1451
2532
  httpHost: z$2.ZodOptional<z$2.ZodString>;
1452
2533
  startEngine: z$2.ZodDefault<z$2.ZodBoolean>;
2534
+ engineHost: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
2535
+ enginePort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1453
2536
  engineVersion: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
2537
+ startServices: z$2.ZodOptional<z$2.ZodBoolean>;
1454
2538
  configurePool: z$2.ZodOptional<z$2.ZodOptional<z$2.ZodObject<{
1455
2539
  name: z$2.ZodOptional<z$2.ZodString>;
1456
2540
  url: z$2.ZodString;
@@ -1467,11 +2551,11 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1467
2551
  publicEndpoint: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
1468
2552
  publicToken: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
1469
2553
  }, z$2.core.$strip>>>;
1470
- envoy: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
2554
+ node: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1471
2555
  poolName: z$2.ZodDefault<z$2.ZodString>;
1472
2556
  version: z$2.ZodDefault<z$2.ZodNumber>;
1473
2557
  totalSlots: z$2.ZodDefault<z$2.ZodNumber>;
1474
- envoyKey: z$2.ZodOptional<z$2.ZodString>;
2558
+ nodeKey: z$2.ZodOptional<z$2.ZodString>;
1475
2559
  }, z$2.core.$strip>>>;
1476
2560
  shutdown: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1477
2561
  gracePeriodMs: z$2.ZodOptional<z$2.ZodNumber>;
@@ -1482,6 +2566,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1482
2566
  backend: "local" | "remote";
1483
2567
  } | undefined;
1484
2568
  endpoint: string | undefined;
2569
+ engineSpawn: boolean;
2570
+ startServices: boolean;
1485
2571
  namespace: string;
1486
2572
  token: string | undefined;
1487
2573
  publicEndpoint: string | undefined;
@@ -1517,12 +2603,14 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1517
2603
  httpBasePath: string;
1518
2604
  httpPort: number;
1519
2605
  startEngine: boolean;
2606
+ engineHost: string;
2607
+ enginePort: number;
1520
2608
  engineVersion: string;
1521
- envoy: {
2609
+ node: {
1522
2610
  poolName: string;
1523
2611
  version: number;
1524
2612
  totalSlots: number;
1525
- envoyKey?: string | undefined;
2613
+ nodeKey?: string | undefined;
1526
2614
  };
1527
2615
  shutdown: {
1528
2616
  disableSignalHandlers: boolean;
@@ -1570,6 +2658,8 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1570
2658
  httpBasePath: string;
1571
2659
  httpPort: number;
1572
2660
  startEngine: boolean;
2661
+ engineHost: string;
2662
+ enginePort: number;
1573
2663
  engineVersion: string;
1574
2664
  serverless: {
1575
2665
  basePath: string;
@@ -1577,11 +2667,11 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1577
2667
  publicEndpoint: string | undefined;
1578
2668
  publicToken: string | undefined;
1579
2669
  };
1580
- envoy: {
2670
+ node: {
1581
2671
  poolName: string;
1582
2672
  version: number;
1583
2673
  totalSlots: number;
1584
- envoyKey?: string | undefined;
2674
+ nodeKey?: string | undefined;
1585
2675
  };
1586
2676
  shutdown: {
1587
2677
  disableSignalHandlers: boolean;
@@ -1589,6 +2679,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1589
2679
  };
1590
2680
  staticDir?: string | undefined;
1591
2681
  httpHost?: string | undefined;
2682
+ startServices?: boolean | undefined;
1592
2683
  configurePool?: {
1593
2684
  url: string;
1594
2685
  name?: string | undefined;
@@ -1605,19 +2696,44 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof Regis
1605
2696
  use: A;
1606
2697
  };
1607
2698
 
2699
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
2700
+ runtime: CoreRuntime;
2701
+ registry: RegistryHandle;
2702
+ serveConfig: RuntimeServeConfig;
2703
+ }>;
2704
+
1608
2705
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
1609
2706
  interface ServerlessHandler {
1610
2707
  fetch: FetchHandler;
1611
2708
  }
1612
- interface RegistryDiagnostics {
1613
- mode: string;
1614
- envoyActiveActorCount?: number | null;
2709
+ interface RegistryApplication {
2710
+ fetch: FetchHandler;
2711
+ }
2712
+ interface RegistryListenOptions {
2713
+ port?: number;
2714
+ host?: string;
2715
+ publicDir?: string;
2716
+ application?: RegistryApplication;
2717
+ }
2718
+ interface RegistryRoutes {
2719
+ health(): Promise<Response>;
2720
+ metadata(): Promise<Response>;
2721
+ prometheusMetrics(request?: Request): Promise<Response>;
2722
+ }
2723
+ /**
2724
+ * Injectable dependencies for {@link Registry}. Production code uses the
2725
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
2726
+ * orchestration against a fake `CoreRuntime` without an engine.
2727
+ */
2728
+ interface RegistryDeps {
2729
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
1615
2730
  }
1616
2731
  declare class Registry<A extends RegistryActors> {
1617
2732
  #private;
2733
+ readonly routes: RegistryRoutes;
1618
2734
  get config(): RegistryConfigInput<A>;
1619
2735
  parseConfig(): RegistryConfig;
1620
- constructor(config: RegistryConfigInput<A>);
2736
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
1621
2737
  /**
1622
2738
  * Handle an incoming HTTP request for serverless deployments.
1623
2739
  *
@@ -1639,29 +2755,63 @@ declare class Registry<A extends RegistryActors> {
1639
2755
  */
1640
2756
  serve(): ServerlessHandler;
1641
2757
  /**
1642
- * Starts an HTTP server that dispatches every request through the
1643
- * serverless handler. Uses `crossPlatformServe` to pick the right
1644
- * runtime (Node, Bun, Deno).
2758
+ * Bind an HTTP listener provided by the native (Rust) runtime and serve
2759
+ * the registry's serverless endpoints over it. Resolves only after the
2760
+ * registry is shut down (SIGINT/SIGTERM or `nativeRegistry.shutdown()`).
1645
2761
  *
1646
- * @param opts.port Port to listen on. Defaults to 3000.
2762
+ * @param opts.port Port to listen on. Defaults to `process.env.RIVET_PORT`
2763
+ * if set, otherwise 3000.
2764
+ * @param opts.host Address to bind. Defaults to `0.0.0.0`.
1647
2765
  * @param opts.publicDir If set, serves static files from this directory
1648
- * before falling through to the registry handler.
2766
+ * as a fallback below the framework routes.
2767
+ * @param opts.application If set, handles requests that do not match a
2768
+ * framework route.
1649
2769
  *
1650
2770
  * @example
1651
2771
  * ```ts
1652
2772
  * await registry.listen();
1653
- * await registry.listen({ port: 8080, publicDir: "./public" });
2773
+ * await registry.listen({ application: app });
1654
2774
  * ```
1655
2775
  */
1656
- listen(opts?: {
1657
- port?: number;
1658
- publicDir?: string;
1659
- }): Promise<void>;
1660
- diagnostics(): Promise<RegistryDiagnostics>;
2776
+ listen(opts?: RegistryListenOptions): Promise<void>;
2777
+ /**
2778
+ * Gracefully drains all live registries.
2779
+ *
2780
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
2781
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
2782
+ * waits for the serve promise to resolve, all bounded by the shutdown
2783
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
2784
+ * signal or exit the process. The caller owns process lifetime.
2785
+ *
2786
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
2787
+ * call even if nothing has been started.
2788
+ *
2789
+ * @example
2790
+ * ```ts
2791
+ * const registry = setup({ use: { counter } });
2792
+ * registry.start();
2793
+ * // ...later, on your own shutdown trigger:
2794
+ * await registry.shutdown();
2795
+ * ```
2796
+ */
2797
+ shutdown(): Promise<void>;
1661
2798
  startEnvoy(): void;
2799
+ /**
2800
+ * Starts the serverful registry if needed and waits until its envoy has
2801
+ * registered with the Engine. Repeated and concurrent calls share one
2802
+ * startup lifecycle and readiness promise.
2803
+ *
2804
+ * Unlike {@link start}, this reports startup failures and does not resolve
2805
+ * merely because an HTTP health endpoint is listening.
2806
+ */
2807
+ startAndWait(): Promise<void>;
1662
2808
  /**
1663
2809
  * Starts the actor envoy for standalone server deployments.
1664
2810
  *
2811
+ * Set `RIVETKIT_RUNTIME_MODE=serverless` to instead bind an HTTP listener
2812
+ * via `listen()` (Mode B). Mode A (envoy) and Mode B (listener) are
2813
+ * mutually exclusive per registry instance.
2814
+ *
1665
2815
  * @example
1666
2816
  * ```ts
1667
2817
  * const registry = setup({ use: { counter } });
@@ -1669,6 +2819,24 @@ declare class Registry<A extends RegistryActors> {
1669
2819
  * ```
1670
2820
  */
1671
2821
  start(): void;
2822
+ /**
2823
+ * Returns the number of actors hosted by this process's envoy, which is zero
2824
+ * while it is not serving. Requires the native runtime.
2825
+ */
2826
+ activeActorCount(): number;
2827
+ /**
2828
+ * Calls `callback` with the number of actors hosted by this process's envoy
2829
+ * and again whenever it changes. Rapid changes may coalesce.
2830
+ * Returns a function that unsubscribes. Requires the native runtime.
2831
+ *
2832
+ * @example
2833
+ * ```ts
2834
+ * const unsubscribe = registry.onActiveActorCountChange((count) => {
2835
+ * setTaskProtection(count > 0);
2836
+ * });
2837
+ * ```
2838
+ */
2839
+ onActiveActorCountChange(callback: (count: number) => void): () => void;
1672
2840
  }
1673
2841
 
1674
2842
  /**
@@ -1676,4 +2844,4 @@ declare class Registry<A extends RegistryActors> {
1676
2844
  */
1677
2845
  declare function createClient<A extends Registry<any>>(endpointOrConfig?: string | ClientConfigInput): Client<A>;
1678
2846
 
1679
- export { type ActorAccessor, type ActorActionFunction, type ActorActionOptions, ActorClientError, type ActorConn, ActorConnDisposed, ActorConnRaw, type ActorConnStatus, type ActorConnectOptions, ActorDefinition, RivetError as ActorError, type ActorGatewayOptions, type ActorHandle, ActorHandleRaw, type AnyActorDefinition, type Client, type ClientConfigInput, ClientRaw, type ConnectionStateCallback, type CreateOptions, type CreateRequest, type Encoding, type EventUnsubscribe, type ExtractActorsFromRegistry, type ExtractRegistryFromClient, type GetOptions, type GetWithIdOptions, MalformedResponseMessage, ManagerError, type QueryOptions, type Region, RivetError, type StatusChangeCallback, UserError, createClient };
2847
+ export { type ActorAccessor, type ActorActionFunction, type ActorActionOptions, ActorClientError, type ActorConn, ActorConnDisposed, ActorConnRaw, type ActorConnStatus, type ActorConnectOptions, ActorDefinition, RivetError as ActorError, type ActorGatewayOptions, type ActorHandle, ActorHandleRaw, type ActorIssueTokenOptions, type ActorTokenPermissions, type ActorTokenResource, type AnyActorDefinition, type Client, type ClientConfigInput, ClientRaw, type ConnectionStateCallback, type CreateOptions, type CreateRequest, type Encoding, type EventUnsubscribe, type ExtractActorsFromRegistry, type ExtractRegistryFromClient, type ForkOptions, type GetOptions, type GetToken, type GetWithIdOptions, type IssueTokenOptions, type IssuedToken, MalformedResponseMessage, ManagerError, type QueryOptions, type Region, RivetError, type StatusChangeCallback, type TokenGrant, UserError, createClient };