rivetkit 0.0.0-sqlite-profiling-compat.4a9a623 → 0.0.0-sqlite-sync-3x-release.a00b07f

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 (277) hide show
  1. package/dist/browser/client.d.ts +1317 -765
  2. package/dist/browser/client.js +1457 -737
  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 +2042 -228
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/actor/errors.cjs +6 -2
  8. package/dist/tsup/actor/errors.cjs.map +1 -1
  9. package/dist/tsup/actor/errors.d.cts +1 -1
  10. package/dist/tsup/actor/errors.d.ts +1 -1
  11. package/dist/tsup/actor/errors.js +5 -1
  12. package/dist/tsup/agent-os/index.cjs +3 -2367
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +1 -2277
  15. package/dist/tsup/agent-os/index.d.ts +1 -2277
  16. package/dist/tsup/agent-os/index.js +3 -2367
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/{chunk-7QKCGUTJ.cjs → chunk-2MOLY6AM.cjs} +444 -29
  19. package/dist/tsup/chunk-2MOLY6AM.cjs.map +1 -0
  20. package/dist/tsup/{chunk-IICIOTML.js → chunk-3DONDAMG.js} +2 -2
  21. package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
  22. package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
  23. package/dist/tsup/chunk-6KXVLIXL.cjs +14 -0
  24. package/dist/tsup/chunk-6KXVLIXL.cjs.map +1 -0
  25. package/dist/tsup/chunk-73RNTXHB.cjs +243 -0
  26. package/dist/tsup/chunk-73RNTXHB.cjs.map +1 -0
  27. package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
  28. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  29. package/dist/tsup/{chunk-75UE45DE.js → chunk-BRH4PQS5.js} +436 -21
  30. package/dist/tsup/chunk-BRH4PQS5.js.map +1 -0
  31. package/dist/tsup/{chunk-2WMYYG4R.cjs → chunk-BTSDFFDC.cjs} +18 -11
  32. package/dist/tsup/chunk-BTSDFFDC.cjs.map +1 -0
  33. package/dist/tsup/{chunk-RIT7N3TX.js → chunk-D5WUPE47.js} +50 -3
  34. package/dist/tsup/chunk-D5WUPE47.js.map +1 -0
  35. package/dist/tsup/{chunk-4PX3ZKJR.js → chunk-DJUBJQEQ.js} +3 -3
  36. package/dist/tsup/chunk-DJUBJQEQ.js.map +1 -0
  37. package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
  38. package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
  39. package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
  40. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  41. package/dist/tsup/{chunk-ND567FR5.cjs → chunk-JUHXV3HF.cjs} +3 -3
  42. package/dist/tsup/chunk-JUHXV3HF.cjs.map +1 -0
  43. package/dist/tsup/chunk-JUWMP5O3.js +14 -0
  44. package/dist/tsup/chunk-JUWMP5O3.js.map +1 -0
  45. package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
  46. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  47. package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
  48. package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
  49. package/dist/tsup/{chunk-NHUTYWKU.cjs → chunk-OTVJYZ2L.cjs} +1139 -470
  50. package/dist/tsup/chunk-OTVJYZ2L.cjs.map +1 -0
  51. package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-RTWH3AX3.cjs} +18 -10
  52. package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
  53. package/dist/tsup/{chunk-QAVN4QNO.cjs → chunk-TM76Z7XT.cjs} +7 -7
  54. package/dist/tsup/chunk-TM76Z7XT.cjs.map +1 -0
  55. package/dist/tsup/{chunk-AGDY6TKH.js → chunk-TRUHDXOU.js} +1023 -354
  56. package/dist/tsup/chunk-TRUHDXOU.js.map +1 -0
  57. package/dist/tsup/{chunk-XFYEVYHG.js → chunk-TSQTI6H6.js} +16 -9
  58. package/dist/tsup/chunk-TSQTI6H6.js.map +1 -0
  59. package/dist/tsup/{chunk-2CICCOBL.cjs → chunk-Z7E2G3JZ.cjs} +52 -5
  60. package/dist/tsup/chunk-Z7E2G3JZ.cjs.map +1 -0
  61. package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
  62. package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
  63. package/dist/tsup/chunk-ZYK4B5WV.js +243 -0
  64. package/dist/tsup/chunk-ZYK4B5WV.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 +32 -6
  68. package/dist/tsup/client/mod.d.ts +32 -6
  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.cjs.map +1 -1
  77. package/dist/tsup/common/websocket.js +3 -3
  78. package/dist/tsup/{config-BR1Nn0QQ.d.ts → config-B4erdavw.d.ts} +571 -65
  79. package/dist/tsup/{config-B0LNDrLY.d.ts → config-BfG1qpYz.d.cts} +80 -14
  80. package/dist/tsup/{config-B0LNDrLY.d.cts → config-BfG1qpYz.d.ts} +80 -14
  81. package/dist/tsup/{config-tCvkwzyN.d.cts → config-DK144OAw.d.cts} +571 -65
  82. package/dist/tsup/{context-oc9zhA3x.d.ts → context-Cvnf3BRe.d.cts} +3 -2
  83. package/dist/tsup/{context-D4WDwf9m.d.cts → context-Oxi6YWcG.d.ts} +3 -2
  84. package/dist/tsup/db/drizzle.cjs +127 -67
  85. package/dist/tsup/db/drizzle.cjs.map +1 -1
  86. package/dist/tsup/db/drizzle.d.cts +8 -4
  87. package/dist/tsup/db/drizzle.d.ts +8 -4
  88. package/dist/tsup/db/drizzle.js +127 -67
  89. package/dist/tsup/db/drizzle.js.map +1 -1
  90. package/dist/tsup/db/mod.cjs +6 -126
  91. package/dist/tsup/db/mod.cjs.map +1 -1
  92. package/dist/tsup/db/mod.d.cts +8 -4
  93. package/dist/tsup/db/mod.d.ts +8 -4
  94. package/dist/tsup/db/mod.js +5 -125
  95. package/dist/tsup/db/mod.js.map +1 -1
  96. package/dist/tsup/dynamic/mod.cjs +2 -2
  97. package/dist/tsup/dynamic/mod.cjs.map +1 -1
  98. package/dist/tsup/dynamic/mod.d.cts +6 -4
  99. package/dist/tsup/dynamic/mod.d.ts +6 -4
  100. package/dist/tsup/dynamic/mod.js +1 -1
  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 +2 -13
  114. package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
  115. package/dist/tsup/inspector-tab/mod.d.cts +9 -17
  116. package/dist/tsup/inspector-tab/mod.d.ts +9 -17
  117. package/dist/tsup/inspector-tab/mod.js +1 -12
  118. package/dist/tsup/inspector-tab/mod.js.map +1 -1
  119. package/dist/tsup/mod.cjs +2724 -611
  120. package/dist/tsup/mod.cjs.map +1 -1
  121. package/dist/tsup/mod.d.cts +9 -7
  122. package/dist/tsup/mod.d.ts +9 -7
  123. package/dist/tsup/mod.js +2641 -528
  124. package/dist/tsup/mod.js.map +1 -1
  125. package/dist/tsup/test/mod.cjs +19 -17
  126. package/dist/tsup/test/mod.cjs.map +1 -1
  127. package/dist/tsup/test/mod.d.cts +6 -4
  128. package/dist/tsup/test/mod.d.ts +6 -4
  129. package/dist/tsup/test/mod.js +18 -16
  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-CqDnC_PS.d.cts → utils-3rsE0JvI.d.cts} +25 -2
  138. package/dist/tsup/{utils-CqDnC_PS.d.ts → utils-3rsE0JvI.d.ts} +25 -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 +260 -200
  147. package/dist/tsup/workflow/mod.cjs.map +1 -1
  148. package/dist/tsup/workflow/mod.d.cts +8 -6
  149. package/dist/tsup/workflow/mod.d.ts +8 -6
  150. package/dist/tsup/workflow/mod.js +249 -189
  151. package/dist/tsup/workflow/mod.js.map +1 -1
  152. package/package.json +34 -14
  153. package/src/actor/actions.ts +155 -0
  154. package/src/actor/config.ts +403 -43
  155. package/src/actor/definition.ts +26 -7
  156. package/src/actor/errors.ts +87 -5
  157. package/src/actor/keys.ts +86 -0
  158. package/src/actor/mod.ts +15 -1
  159. package/src/actor/tracing.ts +28 -0
  160. package/src/agent-os/index.ts +5 -65
  161. package/src/client/actor-common.ts +8 -15
  162. package/src/client/actor-conn.ts +135 -8
  163. package/src/client/actor-handle.ts +180 -42
  164. package/src/client/actor-query.ts +8 -1
  165. package/src/client/auth.ts +37 -0
  166. package/src/client/client.ts +89 -21
  167. package/src/client/config.ts +27 -2
  168. package/src/client/errors.ts +2 -1
  169. package/src/client/lifecycle-errors.ts +16 -1
  170. package/src/client/mod.ts +9 -0
  171. package/src/client/outbound-telemetry.ts +66 -0
  172. package/src/client/query.ts +2 -0
  173. package/src/client/queue.ts +3 -0
  174. package/src/client/raw-utils.ts +37 -8
  175. package/src/client/resolve-gateway-target.ts +2 -0
  176. package/src/client/retry-budget.ts +78 -0
  177. package/src/client/token-provider.ts +93 -0
  178. package/src/client/utils.ts +16 -2
  179. package/src/common/actor-router-consts.ts +5 -0
  180. package/src/common/actor-telemetry-context.ts +19 -0
  181. package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
  182. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  183. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  184. package/src/common/bare/transport/v1.ts +36 -0
  185. package/src/common/database/config.ts +108 -15
  186. package/src/common/database/mod.ts +247 -76
  187. package/src/common/database/native-database.ts +433 -23
  188. package/src/common/database/shared.ts +24 -0
  189. package/src/common/encoding.ts +31 -21
  190. package/src/common/fetch-like.ts +63 -0
  191. package/src/common/inspector-transport.ts +12 -2
  192. package/src/common/log.ts +14 -8
  193. package/src/common/otel-context.ts +99 -0
  194. package/src/common/router.ts +1 -1
  195. package/src/common/utils.ts +7 -19
  196. package/src/db/drizzle.ts +182 -80
  197. package/src/db/mod.ts +2 -0
  198. package/src/dynamic/isolate-runtime.ts +0 -2
  199. package/src/engine-api/actors.ts +3 -3
  200. package/src/engine-client/actor-http-client.ts +29 -20
  201. package/src/engine-client/actor-websocket-client.ts +6 -3
  202. package/src/engine-client/api-endpoints.ts +72 -14
  203. package/src/engine-client/driver.ts +8 -15
  204. package/src/engine-client/mod.ts +248 -112
  205. package/src/inspector/client.browser.ts +134 -16
  206. package/src/inspector/mod.ts +1 -1
  207. package/src/inspector/workflow.ts +61 -0
  208. package/src/inspector-tab/mod.ts +1 -15
  209. package/src/registry/config/envoy.ts +2 -18
  210. package/src/registry/config/index.ts +53 -61
  211. package/src/registry/index.ts +311 -21
  212. package/src/registry/napi-runtime.ts +583 -39
  213. package/src/registry/native-http.ts +225 -0
  214. package/src/registry/native.ts +1365 -414
  215. package/src/registry/run-handler-coordinator.ts +219 -0
  216. package/src/registry/runtime.ts +372 -7
  217. package/src/registry/wasm-runtime.ts +490 -21
  218. package/src/registry/write-through-proxy.ts +101 -0
  219. package/src/test/mod.ts +1 -19
  220. package/src/test/ready.ts +22 -0
  221. package/src/unstable/migrations.ts +141 -0
  222. package/src/utils/env-vars.ts +15 -6
  223. package/src/utils/node.ts +44 -28
  224. package/src/utils.ts +3 -0
  225. package/src/workflow/context.ts +9 -27
  226. package/src/workflow/driver.ts +253 -116
  227. package/src/workflow/inspector.ts +23 -24
  228. package/src/workflow/mod.ts +50 -72
  229. package/dist/tsup/chunk-2CICCOBL.cjs.map +0 -1
  230. package/dist/tsup/chunk-2WMYYG4R.cjs.map +0 -1
  231. package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
  232. package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
  233. package/dist/tsup/chunk-4PX3ZKJR.js.map +0 -1
  234. package/dist/tsup/chunk-75UE45DE.js.map +0 -1
  235. package/dist/tsup/chunk-7QKCGUTJ.cjs.map +0 -1
  236. package/dist/tsup/chunk-AGDY6TKH.js.map +0 -1
  237. package/dist/tsup/chunk-HXUEHHJF.js.map +0 -1
  238. package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
  239. package/dist/tsup/chunk-ND567FR5.cjs.map +0 -1
  240. package/dist/tsup/chunk-NHUTYWKU.cjs.map +0 -1
  241. package/dist/tsup/chunk-QAVN4QNO.cjs.map +0 -1
  242. package/dist/tsup/chunk-RIT7N3TX.js.map +0 -1
  243. package/dist/tsup/chunk-RV5MAFDT.cjs +0 -382
  244. package/dist/tsup/chunk-RV5MAFDT.cjs.map +0 -1
  245. package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
  246. package/dist/tsup/chunk-XFYEVYHG.js.map +0 -1
  247. package/dist/tsup/chunk-XHGDS3DZ.js +0 -382
  248. package/dist/tsup/chunk-XHGDS3DZ.js.map +0 -1
  249. package/dist/tsup/chunk-XIX5DOZN.js.map +0 -1
  250. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +0 -1
  251. package/dist/tsup/chunk-ZZ3WBRPD.js.map +0 -1
  252. package/src/actor/driver.ts +0 -141
  253. package/src/actor/instance/mod.ts +0 -2484
  254. package/src/actor/keys.test.ts +0 -275
  255. package/src/actor/utils.test.ts +0 -48
  256. package/src/agent-os/actor/cron.ts +0 -84
  257. package/src/agent-os/actor/db.ts +0 -54
  258. package/src/agent-os/actor/filesystem.ts +0 -131
  259. package/src/agent-os/actor/index.ts +0 -285
  260. package/src/agent-os/actor/network.ts +0 -58
  261. package/src/agent-os/actor/preview.ts +0 -190
  262. package/src/agent-os/actor/process.ts +0 -177
  263. package/src/agent-os/actor/session.ts +0 -518
  264. package/src/agent-os/actor/shell.ts +0 -60
  265. package/src/agent-os/config.ts +0 -79
  266. package/src/agent-os/fs/database-vfs.ts +0 -624
  267. package/src/agent-os/types.ts +0 -148
  268. package/src/client/test.ts +0 -44
  269. package/src/common/database/mod.test.ts +0 -137
  270. package/src/common/database/native-database.test.ts +0 -211
  271. package/src/common/inline-websocket-adapter.test.ts +0 -51
  272. package/src/drivers/engine/actor-driver.ts +0 -2473
  273. package/src/registry/process-metrics.ts +0 -250
  274. package/src/registry/runtime.test.ts +0 -50
  275. package/src/utils/endpoint-parser.test.ts +0 -206
  276. package/src/utils.test.ts +0 -34
  277. /package/dist/tsup/{chunk-IICIOTML.js.map → chunk-3DONDAMG.js.map} +0 -0
@@ -1,6 +1,7 @@
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 { Rivet } from '@rivetkit/engine-api-full';
4
5
  import { Context, Handler, Hono } from 'hono';
5
6
  import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
6
7
  import { StandardSchemaV1 } from '@standard-schema/spec';
@@ -13,15 +14,50 @@ 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>;
19
+ interface SqliteQueryResult {
20
+ columns: string[];
21
+ rows: unknown[][];
22
+ }
23
+ interface SqliteExecuteResult extends SqliteQueryResult {
24
+ changes: number;
25
+ lastInsertRowId?: number | null;
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
+ }
18
47
  /**
19
- * SQLite profiling controls.
48
+ * SQLite profiling configuration.
20
49
  *
21
- * @experimental This entire configuration surface is subject to change.
50
+ * @experimental This entire configuration surface is experimental and subject
51
+ * to change without notice.
22
52
  */
23
53
  interface SqliteProfilingOptions {
24
- enabled?: boolean;
54
+ /** Exact SQL statements to give fingerprint labels. Profiling defaults to actor
55
+ * aggregates without fingerprint labels. Profile logs remain enabled.
56
+ * RIVETKIT_SQLITE_PROFILING overrides selection with a JSON object containing
57
+ * queries and/or fingerprints arrays. An empty object clears fingerprint selection. */
58
+ queries?: string[];
59
+ /** Exact query fingerprints to label separately, as reported in profile logs. */
60
+ fingerprints?: string[];
25
61
  maxTrackedStatementFingerprints?: number;
26
62
  maxTrackedTransactionFingerprints?: number;
27
63
  maxPrometheusSeries?: number;
@@ -33,14 +69,6 @@ interface SqliteProfilingOptions {
33
69
  maxDiagnosticEventsPerMinute?: number;
34
70
  diagnosticEventQueueCapacity?: number;
35
71
  }
36
- interface SqliteQueryResult {
37
- columns: string[];
38
- rows: unknown[][];
39
- }
40
- interface SqliteExecuteResult extends SqliteQueryResult {
41
- changes: number;
42
- lastInsertRowId?: number | null;
43
- }
44
72
  interface SqliteNativeMetrics {
45
73
  requestBuildNs: number;
46
74
  serializeNs: number;
@@ -56,12 +84,46 @@ interface SqliteNativeMetrics {
56
84
  }
57
85
  interface SqliteDatabase {
58
86
  exec(sql: string, callback?: (row: unknown[], columns: string[]) => void): Promise<void>;
87
+ execSync?(sql: string, callback?: (row: unknown[], columns: string[]) => void): void;
59
88
  execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
89
+ executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
90
+ executeBatch(statements: SqliteBatchStatement[]): Promise<SqliteExecuteResult[]>;
91
+ beginTransaction(timeoutMs?: number, name?: string): Promise<SqliteTransactionDatabase>;
92
+ beginTransactionSync?(timeoutMs?: number, name?: string): SynchronousSqliteTransactionDatabase;
60
93
  run(sql: string, params?: SqliteBindings): Promise<void>;
61
94
  query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
62
95
  nativeMetrics?(): SqliteNativeMetrics | Promise<SqliteNativeMetrics | null> | null;
96
+ /**
97
+ * Returns the ticket of the latest local commit. Synchronous writes return before they are
98
+ * durable; pass the ticket to `whenDurable` before releasing output that depends on them.
99
+ */
100
+ commitTicket?(): number;
101
+ /**
102
+ * Resolves once the commit `ticket` names and every earlier commit are durable. Rejects with
103
+ * `sqlite.durability_failed` once the database broke and the actor is restarting.
104
+ */
105
+ whenDurable?(ticket: number): Promise<void>;
106
+ /**
107
+ * Restarts the owning actor from durable state. Every later write fails, including the final
108
+ * state save. For native database providers whose in-memory state can no longer be trusted.
109
+ */
110
+ abortGeneration?(reason: string): void;
63
111
  close(): Promise<void>;
64
112
  }
113
+ interface SqliteTransactionDatabase {
114
+ exec(sql: string, callback?: (row: unknown[], columns: string[]) => void): Promise<void>;
115
+ execSync?(sql: string, callback?: (row: unknown[], columns: string[]) => void): void;
116
+ execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
117
+ executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
118
+ commit(): Promise<void>;
119
+ rollback(): Promise<void>;
120
+ }
121
+ type SynchronousSqliteTransactionDatabase = SqliteTransactionDatabase & {
122
+ execSync(sql: string, callback?: (row: unknown[], columns: string[]) => void): void;
123
+ executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult;
124
+ commitSync(): void;
125
+ rollbackSync(): void;
126
+ };
65
127
  /**
66
128
  * Provider for opening native databases from the active runtime.
67
129
  */
@@ -106,7 +168,10 @@ interface DatabaseProviderContext {
106
168
  }
107
169
  type DatabaseProvider<DB extends RawAccess> = {
108
170
  /**
109
- * @experimental This entire configuration surface is subject to change.
171
+ * Local SQLite profiling controls consumed by the actor runtime.
172
+ *
173
+ * @experimental This entire configuration surface is experimental and
174
+ * subject to change without notice.
110
175
  */
111
176
  sqliteProfiling?: SqliteProfilingOptions;
112
177
  /**
@@ -132,6 +197,8 @@ type RawAccess = {
132
197
  * Executes a raw SQL query.
133
198
  */
134
199
  execute: ExecuteFunction;
200
+ /** Runs a callback in an isolated SQLite transaction. */
201
+ transaction: <T>(callback: (tx: RawAccess) => Promise<T> | T, options?: SqliteTransactionOptions) => Promise<T>;
135
202
  /**
136
203
  * Returns native SQLite metrics when the active runtime supports them.
137
204
  */
@@ -142,6 +209,26 @@ type RawAccess = {
142
209
  close: () => Promise<void>;
143
210
  };
144
211
 
212
+ /** A namespace-scoped Engine grant. The caller must provide every grant explicitly. */
213
+ type TokenGrant = Rivet.AuthTokenGrant;
214
+ /** Options for `client.auth.issueToken()`. `expiresIn` is in seconds. */
215
+ type IssueTokenOptions = Pick<Rivet.AuthTokenCreateRequest, "subject" | "grants"> & {
216
+ expiresIn?: Rivet.AuthTokenCreateRequest["duration"];
217
+ };
218
+ /** Token timestamps are Unix milliseconds. */
219
+ interface IssuedToken {
220
+ token: Rivet.AuthTokenCreateResponse["token"];
221
+ issuedAt: Rivet.AuthTokenCreateResponse["issuedTs"];
222
+ expiresAt: Rivet.AuthTokenCreateResponse["expiresTs"];
223
+ }
224
+ /** Resources that can be scoped to a single actor ID. */
225
+ type ActorTokenResource = Extract<Rivet.AuthTokenGrant["resource"], "actor_gateway" | "actor" | "actor_kv">;
226
+ type ActorTokenPermissions = Partial<Record<ActorTokenResource, Rivet.AuthTokenGrant["operations"]>>;
227
+ /** Options for `actor.issueToken()`. Omit permissions for gateway read access only. */
228
+ type ActorIssueTokenOptions = Pick<IssueTokenOptions, "subject" | "expiresIn"> & {
229
+ permissions?: ActorTokenPermissions;
230
+ };
231
+
145
232
  declare const EncodingSchema: z.ZodEnum<{
146
233
  json: "json";
147
234
  cbor: "cbor";
@@ -171,6 +258,7 @@ declare const CreateRequestSchema: z.ZodObject<{
171
258
  key: z.ZodArray<z.ZodString>;
172
259
  input: z.ZodOptional<z.ZodUnknown>;
173
260
  region: z.ZodOptional<z.ZodString>;
261
+ poolName: z.ZodOptional<z.ZodString>;
174
262
  }, z.core.$strip>;
175
263
  declare const ActorQuerySchema: z.ZodUnion<readonly [z.ZodObject<{
176
264
  getForId: z.ZodObject<{
@@ -188,6 +276,7 @@ declare const ActorQuerySchema: z.ZodUnion<readonly [z.ZodObject<{
188
276
  key: z.ZodArray<z.ZodString>;
189
277
  input: z.ZodOptional<z.ZodUnknown>;
190
278
  region: z.ZodOptional<z.ZodString>;
279
+ poolName: z.ZodOptional<z.ZodString>;
191
280
  }, z.core.$strip>;
192
281
  }, z.core.$strip>, z.ZodObject<{
193
282
  create: z.ZodObject<{
@@ -195,6 +284,7 @@ declare const ActorQuerySchema: z.ZodUnion<readonly [z.ZodObject<{
195
284
  key: z.ZodArray<z.ZodString>;
196
285
  input: z.ZodOptional<z.ZodUnknown>;
197
286
  region: z.ZodOptional<z.ZodString>;
287
+ poolName: z.ZodOptional<z.ZodString>;
198
288
  }, z.core.$strip>;
199
289
  }, z.core.$strip>]>;
200
290
  type ActorQuery = z.infer<typeof ActorQuerySchema>;
@@ -249,6 +339,7 @@ interface DeconstructedError {
249
339
  code: string;
250
340
  message: string;
251
341
  metadata?: unknown;
342
+ rayId?: string;
252
343
  actor?: ActorSpecifier;
253
344
  }
254
345
 
@@ -257,6 +348,8 @@ interface RivetErrorOptions extends ErrorOptions {
257
348
  public?: boolean;
258
349
  /** Metadata associated with this error. */
259
350
  metadata?: unknown;
351
+ /** Request identifier used to correlate this error with engine logs. */
352
+ rayId?: string;
260
353
  /** Explicit HTTP status override for router responses. */
261
354
  statusCode?: number;
262
355
  /** Actor context associated with this error. */
@@ -284,6 +377,7 @@ declare class RivetError extends Error {
284
377
  __type: "RivetError";
285
378
  public: boolean;
286
379
  metadata?: unknown;
380
+ readonly rayId?: string;
287
381
  statusCode: number;
288
382
  actor?: ActorSpecifier;
289
383
  readonly group: string;
@@ -298,6 +392,29 @@ declare class UserError extends RivetError {
298
392
  constructor(message: string, options?: UserErrorOptions);
299
393
  }
300
394
 
395
+ /** Sample rates keyed by action name, nested like the actor's action groups. */
396
+ interface ActionSampleRates {
397
+ readonly [name: string]: number | ActionSampleRates;
398
+ }
399
+ /**
400
+ * {@link ActionSampleRates} limited to the actions of one actor, so a rate for
401
+ * an action that does not exist is a compile error.
402
+ */
403
+ type ActionTraceSamplers<TActions> = {
404
+ readonly [K in keyof TActions]?: TActions[K] extends (...args: never[]) => unknown ? number : ActionTraceSamplers<TActions[K]>;
405
+ };
406
+ /** Trace sampling for one actor definition. */
407
+ interface ActorTracingOptions<TActions> {
408
+ /**
409
+ * Share of this actor's invocations that are recorded, from 0 to 1. A rate
410
+ * lowers what is recorded and never raises it, so an invocation inside a
411
+ * trace the caller did not record is not recorded at any rate.
412
+ */
413
+ readonly sampler?: number;
414
+ /** Rates that replace `sampler` for single actions. */
415
+ readonly actions?: ActionTraceSamplers<TActions>;
416
+ }
417
+
301
418
  type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
302
419
  type GetUpgradeWebSocket = () => UpgradeWebSocket;
303
420
 
@@ -308,6 +425,7 @@ interface GatewayRequestOptions {
308
425
  skipReadyWait?: boolean;
309
426
  }
310
427
  interface EngineControlClient {
428
+ issueToken(options: IssueTokenOptions): Promise<IssuedToken>;
311
429
  getForId(input: GetForIdInput): Promise<ActorOutput | undefined>;
312
430
  getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined>;
313
431
  getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput>;
@@ -315,6 +433,8 @@ interface EngineControlClient {
315
433
  listActors(input: ListActorsInput): Promise<ActorOutput[]>;
316
434
  sendRequest(target: GatewayTarget, actorRequest: Request, options?: GatewayRequestOptions): Promise<Response>;
317
435
  openWebSocket(path: string, target: GatewayTarget, encoding: Encoding, params: unknown, options?: GatewayRequestOptions): Promise<UniversalWebSocket>;
436
+ /** Refresh a credential rejected during this WebSocket handshake, if supported. */
437
+ refreshAuthToken?(ws: UniversalWebSocket): Promise<boolean>;
318
438
  proxyRequest(c: Context, actorRequest: Request, actorId: string): Promise<Response>;
319
439
  proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown): Promise<Response>;
320
440
  buildGatewayUrl(target: GatewayTarget, options?: GatewayRequestOptions): Promise<string>;
@@ -327,11 +447,6 @@ interface EngineControlClient {
327
447
  * Test-only helper that simulates an abrupt actor crash.
328
448
  */
329
449
  hardCrashActor?(actorId: string): Promise<void>;
330
- kvGet(actorId: string, key: Uint8Array): Promise<string | null>;
331
- kvBatchGet(actorId: string, keys: Uint8Array[]): Promise<(Uint8Array | null)[]>;
332
- kvBatchPut(actorId: string, entries: [Uint8Array, Uint8Array][]): Promise<void>;
333
- kvBatchDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
334
- kvDeleteRange(actorId: string, start: Uint8Array, end: Uint8Array): Promise<void>;
335
450
  }
336
451
  interface RuntimeDisplayInformation {
337
452
  properties: Record<string, string>;
@@ -353,6 +468,8 @@ interface GetOrCreateWithKeyInput {
353
468
  input?: unknown;
354
469
  region?: string;
355
470
  crashPolicy?: CrashPolicy;
471
+ /** Overrides the client's configured pool name for this actor. */
472
+ poolName?: string;
356
473
  }
357
474
  interface CreateInput {
358
475
  c?: Context | undefined;
@@ -361,6 +478,8 @@ interface CreateInput {
361
478
  input?: unknown;
362
479
  region?: string;
363
480
  crashPolicy?: CrashPolicy;
481
+ /** Overrides the client's configured pool name for this actor. */
482
+ poolName?: string;
364
483
  }
365
484
  interface ListActorsInput {
366
485
  c?: Context | undefined;
@@ -380,311 +499,854 @@ interface ActorOutput {
380
499
  error?: unknown;
381
500
  }
382
501
 
383
- interface QueueSendWaitOptions {
384
- wait: true;
385
- timeout?: number;
386
- signal?: AbortSignal;
387
- }
388
- interface QueueSendNoWaitOptions {
389
- wait?: false;
390
- timeout?: never;
391
- signal?: AbortSignal;
392
- }
393
- interface QueueSendResult<TResponse = unknown> {
394
- status: "completed" | "timedOut";
395
- response?: TResponse;
502
+ /** Correlation owned by the currently executing Core actor invocation. */
503
+ interface ActorInvocationTraceContext {
504
+ /** Ray ID the invocation received, absent when nothing upstream supplied one. */
505
+ readonly rayId?: string;
506
+ /** Core-owned invocation span context, absent when tracing is disabled. */
507
+ readonly span?: ActorInvocationSpanContext;
508
+ }
509
+ /** W3C span context of the Core invocation span. */
510
+ interface ActorInvocationSpanContext {
511
+ /** W3C trace identifier. */
512
+ readonly traceId: string;
513
+ /** W3C span identifier for the Core invocation. */
514
+ readonly spanId: string;
515
+ /** OpenTelemetry trace flags encoded as an integer. */
516
+ readonly traceFlags: number;
517
+ /** Optional vendor trace state inherited by the Core invocation. */
518
+ readonly tracestate?: string;
396
519
  }
397
520
 
398
- /**
399
- * Action function returned by Actor connections and handles.
400
- *
401
- * @typedef {Function} ActorActionFunction
402
- * @template Args
403
- * @template Response
404
- * @param {...Args} args - Arguments for the action function.
405
- * @returns {Promise<Response>}
406
- */
407
- type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
408
- type IsAny<T> = 0 extends 1 & T ? true : false;
409
- type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
410
- type ActorActionMap<R> = {
411
- [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : never;
521
+ declare const handleBrand: unique symbol;
522
+ type OpaqueHandle<Name extends string> = {
523
+ readonly [handleBrand]: Name;
412
524
  };
413
- type ActionsOf<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? R : never;
414
- interface ActorGatewayOptions {
415
- skipReadyWait?: boolean;
525
+ type RegistryHandle = OpaqueHandle<"registry">;
526
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
527
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
528
+ type ConnHandle = OpaqueHandle<"conn">;
529
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
530
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
531
+ type ActorStateTransactionHandle = OpaqueHandle<"actorStateTransaction">;
532
+ type SqliteTransactionHandle = OpaqueHandle<"sqliteTransaction">;
533
+ type RuntimeBytes = Uint8Array;
534
+ interface RuntimeActorKeySegment {
535
+ kind: string;
536
+ stringValue?: string;
537
+ numberValue?: number;
416
538
  }
417
- interface ActorActionOptions extends ActorGatewayOptions {
418
- signal?: AbortSignal;
539
+ /** Resolves correlation at operation time so retained clients cannot freeze stale context. */
540
+ type CurrentActorInvocation = () => ActorInvocationTraceContext | undefined;
541
+ /** One open call from an actor out to another actor. */
542
+ interface RuntimeOutboundCall {
543
+ /**
544
+ * W3C context of the call's own span, to send to the callee so it parents to
545
+ * the call. Absent when tracing is disabled.
546
+ */
547
+ readonly span?: ActorInvocationSpanContext;
548
+ /**
549
+ * Records the call's outcome. `error` is the failure encoded the way the
550
+ * bridge encodes errors, so a structured error keeps its group and code.
551
+ */
552
+ finish(error?: string): void;
419
553
  }
420
- type ActorConnectOptions = ActorGatewayOptions;
421
- type ActorFetchInit = RequestInit & ActorGatewayOptions;
422
- type ActorWebSocketOptions = ActorGatewayOptions;
423
554
  /**
424
- * Maps action methods from actor definition to typed function signatures.
555
+ * Opens the span covering one call out to another actor, or returns `undefined`
556
+ * outside an invocation or on a runtime without invocation telemetry. Callers
557
+ * send their own context when it returns nothing.
425
558
  */
426
- type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
427
- type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
428
- <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
429
- <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
430
- (name: keyof TQueues extends never ? string : never, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
431
- (name: keyof TQueues extends never ? string : never, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
559
+ type StartCallSpan = (actorName: string, actionName: string) => RuntimeOutboundCall | undefined;
560
+ interface RuntimeHttpRequest {
561
+ method: string;
562
+ uri: string;
563
+ headers?: Record<string, string>;
564
+ body?: RuntimeBytes;
565
+ }
566
+ interface RuntimeHttpResponseBodyStream {
567
+ cancelled(): Promise<void>;
568
+ write(chunk: Uint8Array): Promise<void>;
569
+ end(): Promise<void>;
570
+ error(message: string): Promise<void>;
571
+ }
572
+ interface RuntimeStateDeltaPayload {
573
+ state?: RuntimeBytes;
574
+ connHibernation: Array<{
575
+ connId: string;
576
+ bytes: RuntimeBytes;
577
+ }>;
578
+ connHibernationRemoved: string[];
579
+ }
580
+ interface RuntimeWorkflowKvWrite {
581
+ key: RuntimeBytes;
582
+ value: RuntimeBytes;
583
+ }
584
+ interface RuntimeRequestSaveOpts {
585
+ immediate?: boolean;
586
+ maxWaitMs?: number;
587
+ }
588
+ interface RuntimeInspectorSnapshot {
589
+ stateRevision: number;
590
+ connectionsRevision: number;
591
+ queueRevision: number;
592
+ activeConnections: number;
593
+ queueSize: number;
594
+ connectedClients: number;
595
+ }
596
+ interface RuntimeQueueMessage {
597
+ id(): bigint;
598
+ name(): string;
599
+ body(): RuntimeBytes;
600
+ createdAt(): number;
601
+ isCompletable(): boolean;
602
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
603
+ }
604
+ interface RuntimeQueueInspectMessage {
605
+ id: number;
606
+ name: string;
607
+ createdAtMs: number;
608
+ }
609
+ interface RuntimeScheduledEventInfo {
610
+ id: string;
611
+ action: string;
612
+ args: RuntimeBytes;
613
+ runAt: number;
614
+ }
615
+ interface RuntimeCronJobInfo {
616
+ name: string;
617
+ kind: "cron" | "every";
618
+ action: string;
619
+ args: RuntimeBytes;
620
+ nextRunAt: number;
621
+ lastRunAt?: number;
622
+ expression?: string;
623
+ timezone?: string;
624
+ intervalMs?: number;
625
+ maxHistory: number;
626
+ }
627
+ interface RuntimeScheduleErrorInfo {
628
+ group: string;
629
+ code: string;
630
+ message: string;
631
+ metadata?: unknown;
632
+ }
633
+ interface RuntimeCronFire {
634
+ action: string;
635
+ scheduledAt: number;
636
+ firedAt: number;
637
+ finishedAt?: number;
638
+ result: "running" | "ok" | "error" | "skipped";
639
+ error?: RuntimeScheduleErrorInfo;
640
+ }
641
+ interface RuntimeQueueNextBatchOptions {
642
+ names?: string[];
643
+ count?: number;
644
+ timeoutMs?: number;
645
+ completable?: boolean;
646
+ }
647
+ interface RuntimeQueueWaitOptions {
648
+ timeoutMs?: number;
649
+ completable?: boolean;
650
+ }
651
+ interface RuntimeQueueEnqueueAndWaitOptions {
652
+ timeoutMs?: number;
653
+ }
654
+ interface RuntimeQueueTryNextBatchOptions {
655
+ names?: string[];
656
+ count?: number;
657
+ completable?: boolean;
658
+ }
659
+ interface RuntimeKvListOptions {
660
+ reverse?: boolean;
661
+ limit?: number;
662
+ }
663
+ interface RuntimeKvEntry {
664
+ key: RuntimeBytes;
665
+ value: RuntimeBytes;
666
+ }
667
+ type RuntimeSqlBindNoValues = {
668
+ intValue?: never;
669
+ floatValue?: never;
670
+ textValue?: never;
671
+ blobValue?: never;
432
672
  };
433
- type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
434
- <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
435
- (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
673
+ type RuntimeSqlBindParam = ({
674
+ kind: "null";
675
+ } & RuntimeSqlBindNoValues) | {
676
+ kind: "int";
677
+ intValue: number;
678
+ floatValue?: never;
679
+ textValue?: never;
680
+ blobValue?: never;
681
+ } | {
682
+ kind: "float";
683
+ intValue?: never;
684
+ floatValue: number;
685
+ textValue?: never;
686
+ blobValue?: never;
687
+ } | {
688
+ kind: "text";
689
+ intValue?: never;
690
+ floatValue?: never;
691
+ textValue: string;
692
+ blobValue?: never;
693
+ } | {
694
+ kind: "blob";
695
+ intValue?: never;
696
+ floatValue?: never;
697
+ textValue?: never;
698
+ blobValue: RuntimeBytes;
436
699
  };
437
- type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
438
- send: ActorQueueSend<Record<string, any>>;
439
- } : AD extends {
440
- config: {
441
- queues?: infer Q;
442
- };
443
- } ? Q extends QueueSchemaConfig ? {
444
- send: ActorQueueSend<Q>;
445
- } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
446
- send: ActorQueueSend<Q>;
447
- } : {} : {};
448
- type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
449
- on: LooseEventSubscribe;
450
- once: LooseEventSubscribe;
451
- } : AD extends {
452
- config: {
453
- events?: infer E;
454
- };
455
- } ? E extends EventSchemaConfig ? {
456
- on: ActorEventSubscribe<E>;
457
- once: ActorEventSubscribe<E>;
458
- } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
459
- on: ActorEventSubscribe<E>;
460
- once: ActorEventSubscribe<E>;
461
- } : {} : {};
462
-
463
- declare class ActorClientError extends Error {
700
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
701
+ interface RuntimeActorRuntimeSocketEndpointInfo {
702
+ path: string;
464
703
  }
465
- declare class ManagerError extends ActorClientError {
466
- constructor(error: string, opts?: ErrorOptions);
704
+ interface RuntimeSqlQueryResult {
705
+ columns: string[];
706
+ rows: unknown[][];
467
707
  }
468
- declare class MalformedResponseMessage extends ActorClientError {
469
- constructor(cause?: unknown);
708
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
709
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
710
+ changes: number;
711
+ lastInsertRowId?: number | null;
470
712
  }
471
-
472
- declare class ActorConnDisposed extends ActorClientError {
473
- constructor();
713
+ interface RuntimeSqlBatchStatement {
714
+ sql: string;
715
+ params?: RuntimeSqlBindParams;
474
716
  }
475
-
476
- type ActorResolutionState = ActorQuery;
477
-
478
- /**
479
- * Connection status for an actor connection.
480
- *
481
- * - `"idle"`: Not connected, no auto-reconnect (initial state, after dispose, or disabled)
482
- * - `"connecting"`: Attempting to establish connection
483
- * - `"connected"`: Connection is active
484
- * - `"disconnected"`: Connection was lost, will auto-reconnect
485
- */
486
- type ActorConnStatus = "idle" | "connecting" | "connected" | "disconnected";
487
- /**
488
- * A function that unsubscribes from an event.
489
- *
490
- * @typedef {Function} EventUnsubscribe
491
- */
492
- type EventUnsubscribe = () => void;
493
- /**
494
- * A function that handles connection errors.
495
- *
496
- * @typedef {Function} ActorErrorCallback
497
- */
498
- type ActorErrorCallback = (error: RivetError) => void;
499
- /**
500
- * A callback for connection state changes.
501
- *
502
- * @typedef {Function} ConnectionStateCallback
503
- */
504
- type ConnectionStateCallback = () => void;
505
- /**
506
- * A callback for connection status changes.
507
- *
508
- * @typedef {Function} StatusChangeCallback
509
- */
510
- type StatusChangeCallback = (status: ActorConnStatus) => void;
511
- declare const CONNECT_SYMBOL: unique symbol;
512
- /**
513
- * Provides underlying functions for {@link ActorConn}. See {@link ActorConn} for using type-safe remote procedure calls.
514
- *
515
- * @see {@link ActorConn}
516
- */
517
- declare class ActorConnRaw {
518
- #private;
519
- /**
520
- * Do not call this directly.
521
- *
522
- * Creates an instance of ActorConnRaw.
523
- *
524
- * @protected
525
- */
526
- constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions);
527
- send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
528
- send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
529
- /**
530
- * Call a raw action connection. See {@link ActorConn} for type-safe action calls.
531
- *
532
- * @see {@link ActorConn}
533
- * @template Args - The type of arguments to pass to the action function.
534
- * @template Response - The type of the response returned by the action function.
535
- * @param {string} name - The name of the action function to call.
536
- * @param {...Args} args - The arguments to pass to the action function.
537
- * @returns {Promise<Response>} - A promise that resolves to the response of the action function.
538
- */
539
- action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
717
+ interface RuntimeSqlRunResult {
718
+ changes: number;
719
+ }
720
+ /** Sample rates for the traces an actor starts, in the shape core takes. */
721
+ interface RuntimeActorTracingConfig {
722
+ sampler?: number;
723
+ /** Keyed by flattened, dot-separated action name. */
724
+ actions?: Record<string, number>;
725
+ }
726
+ interface RuntimeActorConfig {
727
+ name?: string;
728
+ icon?: string;
729
+ hasDatabase?: boolean;
730
+ remoteSqlite?: boolean;
731
+ sqliteDeferredCommits?: boolean;
732
+ sqliteProfiling?: SqliteProfilingOptions;
733
+ tracing?: RuntimeActorTracingConfig;
734
+ enableActorRuntimeSocket?: boolean;
735
+ hasState?: boolean;
736
+ canHibernateWebsocket?: boolean;
737
+ stateSaveIntervalMs?: number;
738
+ createStateTimeoutMs?: number;
739
+ onCreateTimeoutMs?: number;
740
+ createVarsTimeoutMs?: number;
741
+ createConnStateTimeoutMs?: number;
742
+ onBeforeConnectTimeoutMs?: number;
743
+ onConnectTimeoutMs?: number;
744
+ onMigrateTimeoutMs?: number;
745
+ onWakeTimeoutMs?: number;
746
+ onBeforeActorStartTimeoutMs?: number;
747
+ actionTimeoutMs?: number;
748
+ onRequestTimeoutMs?: number;
749
+ sleepTimeoutMs?: number;
750
+ noSleep?: boolean;
751
+ sleepGracePeriodMs?: number;
752
+ connectionLivenessTimeoutMs?: number;
753
+ connectionLivenessIntervalMs?: number;
754
+ maxQueueSize?: number;
755
+ maxSchedules?: number;
756
+ maxQueueMessageSize?: number;
757
+ maxIncomingMessageSize?: number;
758
+ maxOutgoingMessageSize?: number;
759
+ preloadMaxWorkflowBytes?: number;
760
+ preloadMaxConnectionsBytes?: number;
761
+ actions?: Array<{
540
762
  name: string;
541
- args: Args;
542
- signal?: AbortSignal;
543
- }): Promise<Response>;
544
- /**
545
- * Do not call this directly.
546
- * Establishes a connection to the server using the specified endpoint & encoding & driver.
547
- *
548
- * @protected
549
- */
550
- [CONNECT_SYMBOL](): void;
551
- /**
552
- * Subscribes to an event that will happen repeatedly.
553
- *
554
- * @template Args - The type of arguments the event callback will receive.
555
- * @param {string} eventName - The name of the event to subscribe to.
556
- * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
557
- * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
558
- * @see {@link https://rivet.dev/docs/events|Events Documentation}
559
- */
560
- on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
763
+ }>;
764
+ inspectorTabs?: Array<RuntimeInspectorTabEntry>;
765
+ }
766
+ interface RuntimeInspectorTabEntry {
767
+ id: string;
768
+ /** Required for custom entries; omitted for built-in hides. */
769
+ label?: string;
561
770
  /**
562
- * Subscribes to an event that will be triggered only once.
563
- *
564
- * @template Args - The type of arguments the event callback will receive.
565
- * @param {string} eventName - The name of the event to subscribe to.
566
- * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
567
- * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
568
- * @see {@link https://rivet.dev/docs/events|Events Documentation}
771
+ * Required for custom entries — absolute path to the source directory.
772
+ * Resolved on the TS side before being handed to the runtime.
569
773
  */
570
- once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
774
+ source?: string;
775
+ /** Optional icon id for custom entries. */
776
+ icon?: string;
777
+ /** Set to true for built-in hide entries. */
778
+ hidden?: boolean;
779
+ }
780
+ interface RuntimeServeConfig {
781
+ version: number;
782
+ endpoint: string;
783
+ token?: string;
784
+ namespace: string;
785
+ poolName: string;
786
+ engineBinaryPath?: string;
787
+ startServices?: boolean;
788
+ servicesBinaryPath?: string;
789
+ /** Whether config resolution selected a managed local development engine. */
790
+ engineSpawn?: boolean;
791
+ engineHost?: string;
792
+ enginePort?: number;
793
+ handleInspectorHttpInRuntime?: boolean;
794
+ inspectorTestToken?: string;
795
+ serverlessBasePath?: string;
796
+ serverlessPackageVersion: string;
797
+ serverlessClientEndpoint?: string;
798
+ serverlessClientNamespace?: string;
799
+ serverlessClientToken?: string;
800
+ serverlessValidateEndpoint: boolean;
801
+ serverlessMaxStartPayloadBytes: number;
802
+ }
803
+ interface RuntimeListenerConfig {
804
+ port: number;
805
+ host?: string;
806
+ publicDir?: string;
807
+ application?: RuntimeApplicationFetch;
808
+ }
809
+ interface RuntimeServerlessRequest {
810
+ method: string;
811
+ url: string;
812
+ headers: Record<string, string>;
813
+ body: RuntimeBytes;
814
+ }
815
+ interface RuntimeApplicationRequest extends RuntimeServerlessRequest {
816
+ cancelToken?: CancellationTokenHandle;
817
+ }
818
+ interface RuntimeApplicationResponse {
819
+ status: number;
820
+ headers: Record<string, string>;
821
+ body?: RuntimeBytes;
822
+ stream?: boolean;
823
+ }
824
+ type RuntimeApplicationFetch = (request: RuntimeApplicationRequest, responseBodyStream?: RuntimeHttpResponseBodyStream) => Promise<RuntimeApplicationResponse>;
825
+ interface RuntimeApplicationListenerConfig extends RuntimeListenerConfig {
826
+ application: RuntimeApplicationFetch;
827
+ }
828
+ interface RuntimeServerlessResponseHead {
829
+ status: number;
830
+ headers: Record<string, string>;
831
+ }
832
+ interface RuntimeRegistryRouteResponse {
833
+ status: number;
834
+ headers: Record<string, string>;
835
+ body: RuntimeBytes;
836
+ }
837
+ type RuntimeServerlessStreamEvent = {
838
+ kind: "chunk";
839
+ chunk?: RuntimeBytes;
840
+ } | {
841
+ kind: "end";
842
+ error?: {
843
+ group: string;
844
+ code: string;
845
+ message: string;
846
+ };
847
+ };
848
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
849
+ type RuntimeWebSocketEvent = {
850
+ kind: "message";
851
+ data: string | RuntimeBytes;
852
+ binary: boolean;
853
+ messageIndex?: number;
854
+ } | {
855
+ kind: "close";
856
+ code: number;
857
+ reason: string;
858
+ wasClean: boolean;
859
+ };
860
+ interface CoreRuntime {
861
+ readonly kind: "napi" | "wasm";
862
+ createRegistry(): RegistryHandle;
863
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
864
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
865
+ waitRegistryReady(registry: RegistryHandle): Promise<void>;
866
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
867
+ shutdownTelemetry?(): Promise<void>;
868
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
869
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
870
+ serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
871
+ serveApplicationListener(registry: RegistryHandle, listener: RuntimeApplicationListenerConfig, config: RuntimeServeConfig): Promise<void>;
872
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
873
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
874
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
875
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
876
+ createCancellationToken(): CancellationTokenHandle;
877
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
878
+ cancelCancellationToken(token: CancellationTokenHandle): void;
571
879
  /**
572
- * Subscribes to connection errors.
573
- *
574
- * @param {ActorErrorCallback} callback - The callback function to execute when a connection error occurs.
575
- * @returns {() => void} - A function to unsubscribe from the error handler.
880
+ * Calls `callback` once when `token` is cancelled. Returns a release
881
+ * function that drops the registration without calling `callback`; call it
882
+ * once cancellation no longer matters so the native listener is freed.
576
883
  */
577
- onError(callback: ActorErrorCallback): () => void;
884
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): () => void;
885
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
886
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
887
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
888
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
889
+ actorSetRunWakeAt(ctx: ActorContextHandle, timestampMs?: number | undefined | null): Promise<void>;
890
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
891
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
892
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
893
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
894
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
895
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
896
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
897
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
898
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
899
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
900
+ actorSaveStateAndWorkflowBatch(ctx: ActorContextHandle, writes: RuntimeWorkflowKvWrite[]): Promise<void>;
901
+ actorId(ctx: ActorContextHandle): string;
578
902
  /**
579
- * Returns the current connection status.
580
- *
581
- * @returns {ActorConnStatus} - The current connection status.
903
+ * Runs one actor callback with `ctx` as the current invocation: operations
904
+ * on retained handles for the same actor resolve to it, and its Core span
905
+ * is the active OpenTelemetry span for the duration of `run`. Only actions,
906
+ * raw requests, and queue dispatch run this way; other callbacks have no
907
+ * invocation span.
582
908
  */
583
- get connStatus(): ActorConnStatus;
909
+ runWithActorInvocationContext<T>(ctx: ActorContextHandle, run: () => T): T;
584
910
  /**
585
- * Returns whether the connection is currently open.
586
- *
587
- * @deprecated Use `connStatus` instead.
588
- * @returns {boolean} - True if the connection is open, false otherwise.
911
+ * Correlation of the invocation currently executing for this actor, or
912
+ * `undefined` outside an invocation or after it finished. A sampled-out
913
+ * invocation can still expose valid span context for propagation.
589
914
  */
590
- get isConnected(): boolean;
915
+ actorInvocationTraceContext(ctx: ActorContextHandle): ActorInvocationTraceContext | undefined;
591
916
  /**
592
- * Resolves when this connection first reaches the connected state.
917
+ * Opens the span covering one call this actor makes to another actor. See
918
+ * `StartCallSpan` for when this returns nothing.
593
919
  */
594
- get ready(): Promise<void>;
595
- /**
596
- * Subscribes to connection open events.
597
- *
598
- * This is called when the WebSocket connection is established and the Init message is received.
599
- *
600
- * @param {ConnectionStateCallback} callback - The callback function to execute when the connection opens.
601
- * @returns {() => void} - A function to unsubscribe from the open handler.
602
- */
603
- onOpen(callback: ConnectionStateCallback): () => void;
604
- /**
605
- * Subscribes to connection close events.
606
- *
607
- * This is called when the WebSocket connection is closed. The connection will automatically
608
- * attempt to reconnect unless disposed.
609
- *
610
- * @param {ConnectionStateCallback} callback - The callback function to execute when the connection closes.
611
- * @returns {() => void} - A function to unsubscribe from the close handler.
612
- */
613
- onClose(callback: ConnectionStateCallback): () => void;
614
- /**
615
- * Subscribes to connection status changes.
616
- *
617
- * This is called whenever the connection status changes between Disconnected, Connecting, and Connected.
618
- *
619
- * @param {StatusChangeCallback} callback - The callback function to execute when the status changes.
620
- * @returns {() => void} - A function to unsubscribe from the status change handler.
621
- */
622
- onStatusChange(callback: StatusChangeCallback): () => void;
623
- /**
624
- * Disconnects from the actor.
625
- *
626
- * @returns {Promise<void>} A promise that resolves when the socket is gracefully closed.
627
- */
628
- dispose(): Promise<void>;
920
+ startCallSpan(ctx: ActorContextHandle, actorName: string, actionName: string): RuntimeOutboundCall | undefined;
921
+ /** Backs `ActorRun.startWorkflowSpan`. */
922
+ startWorkflowSpan(ctx: ActorContextHandle): Promise<WorkflowSpan>;
923
+ /** Backs `ActorRun.runOutsideWorkflowSpan`. */
924
+ runOutsideActorInvocationContext<T>(run: () => T): T;
925
+ /** Identity of the invocation the caller runs in, usable as a cache key. */
926
+ currentInvocationScope(): object | undefined;
927
+ actorName(ctx: ActorContextHandle): string;
928
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
929
+ actorRegion(ctx: ActorContextHandle): string;
930
+ actorSleep(ctx: ActorContextHandle): void;
931
+ actorDestroy(ctx: ActorContextHandle): void;
932
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
933
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
934
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
935
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
936
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
937
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
938
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
939
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
940
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
941
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
942
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
943
+ actorRuntimeState(ctx: ActorContextHandle): object;
944
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
945
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
946
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
947
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
948
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
949
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
950
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
951
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
952
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
953
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
954
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
955
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
956
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
957
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
958
+ actorSqlExecSync(ctx: ActorContextHandle, sql: string): RuntimeSqlExecResult;
959
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
960
+ actorSqlExecuteSync(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): RuntimeSqlExecuteResult;
961
+ actorSqlExecuteBatch(ctx: ActorContextHandle, statements: RuntimeSqlBatchStatement[]): Promise<RuntimeSqlExecuteResult[]>;
962
+ actorSqlBeginTransaction(ctx: ActorContextHandle, timeoutMs?: number, name?: string): Promise<SqliteTransactionHandle>;
963
+ actorSqlBeginTransactionSync(ctx: ActorContextHandle, timeoutMs?: number, name?: string): SqliteTransactionHandle;
964
+ actorSqlTransactionExec(transaction: SqliteTransactionHandle, sql: string): Promise<RuntimeSqlExecResult>;
965
+ actorSqlTransactionExecSync(transaction: SqliteTransactionHandle, sql: string): RuntimeSqlExecResult;
966
+ actorSqlTransactionExecute(transaction: SqliteTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
967
+ actorSqlTransactionExecuteSync(transaction: SqliteTransactionHandle, sql: string, params?: RuntimeSqlBindParams): RuntimeSqlExecuteResult;
968
+ actorSqlTransactionCommit(transaction: SqliteTransactionHandle): Promise<void>;
969
+ actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void;
970
+ actorSqlTransactionRollback(transaction: SqliteTransactionHandle): Promise<void>;
971
+ actorSqlTransactionRollbackSync(transaction: SqliteTransactionHandle): void;
972
+ actorBeginStateTransaction(ctx: ActorContextHandle, timeoutMs?: number): Promise<ActorStateTransactionHandle>;
973
+ actorStateTransactionExecute(transaction: ActorStateTransactionHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
974
+ actorStateTransactionCommit(transaction: ActorStateTransactionHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
975
+ actorStateTransactionRollback(transaction: ActorStateTransactionHandle): Promise<void>;
976
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
977
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
978
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
979
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
980
+ /** Opens the actor database so later synchronous calls never fetch its first pages. */
981
+ actorSqlOpen(ctx: ActorContextHandle): Promise<void>;
982
+ /** Returns the ticket of the latest local commit. */
983
+ actorSqlCommitTicket(ctx: ActorContextHandle): number;
984
+ /** Resolves once the commit `ticket` names and every earlier commit are durable. */
985
+ actorSqlWhenDurable(ctx: ActorContextHandle, ticket: number): Promise<void>;
986
+ actorSqlAbortGeneration(ctx: ActorContextHandle, reason: string): void;
987
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
988
+ actorRuntimeSocketProvision(ctx: ActorContextHandle): Promise<RuntimeActorRuntimeSocketEndpointInfo>;
989
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
990
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
991
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
992
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
993
+ actorQueueCompletePersisted(ctx: ActorContextHandle, messageId: bigint, expectedName: string, response?: RuntimeBytes | undefined | null): Promise<boolean>;
994
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
995
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
996
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
997
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
998
+ actorQueueReset(ctx: ActorContextHandle): Promise<void>;
999
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
1000
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): Promise<string>;
1001
+ actorScheduleCancel(ctx: ActorContextHandle, id: string): Promise<boolean>;
1002
+ actorScheduleGet(ctx: ActorContextHandle, id: string): Promise<RuntimeScheduledEventInfo | undefined>;
1003
+ actorScheduleList(ctx: ActorContextHandle): Promise<RuntimeScheduledEventInfo[]>;
1004
+ actorCronSet(ctx: ActorContextHandle, name: string, expression: string, timezone: string | undefined, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
1005
+ actorCronEvery(ctx: ActorContextHandle, name: string, intervalMs: number, actionName: string, args: RuntimeBytes, maxHistory: number | undefined): Promise<void>;
1006
+ actorCronGet(ctx: ActorContextHandle, name: string): Promise<RuntimeCronJobInfo | undefined>;
1007
+ actorCronList(ctx: ActorContextHandle): Promise<RuntimeCronJobInfo[]>;
1008
+ actorCronDelete(ctx: ActorContextHandle, name: string): Promise<boolean>;
1009
+ actorCronHistory(ctx: ActorContextHandle, name: string, limit: number | undefined): Promise<RuntimeCronFire[]>;
1010
+ connId(conn: ConnHandle): string;
1011
+ connParams(conn: ConnHandle): RuntimeBytes;
1012
+ connState(conn: ConnHandle): RuntimeBytes;
1013
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
1014
+ connIsHibernatable(conn: ConnHandle): boolean;
1015
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
1016
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
1017
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
1018
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
1019
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
1020
+ }
1021
+
1022
+ interface QueueSendWaitOptions {
1023
+ wait: true;
1024
+ timeout?: number;
1025
+ signal?: AbortSignal;
1026
+ }
1027
+ interface QueueSendNoWaitOptions {
1028
+ wait?: false;
1029
+ timeout?: never;
1030
+ signal?: AbortSignal;
1031
+ }
1032
+ interface QueueSendResult<TResponse = unknown> {
1033
+ status: "completed" | "timedOut";
1034
+ response?: TResponse;
629
1035
  }
1036
+
630
1037
  /**
631
- * Connection to a actor. Allows calling actor's remote procedure calls with inferred types. See {@link ActorConnRaw} for underlying methods.
1038
+ * Action function returned by Actor connections and handles.
632
1039
  *
633
- * @example
634
- * ```
635
- * const room = client.connect<ChatRoom>(...etc...);
636
- * // This calls the action named `sendMessage` on the `ChatRoom` actor.
637
- * await room.sendMessage('Hello, world!');
638
- * ```
1040
+ * @typedef {Function} ActorActionFunction
1041
+ * @template Args
1042
+ * @template Response
1043
+ * @param {...Args} args - Arguments for the action function.
1044
+ * @returns {Promise<Response>}
1045
+ */
1046
+ type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
1047
+ type IsAny<T> = 0 extends 1 & T ? true : false;
1048
+ type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
1049
+ type ActorActionMap<R> = {
1050
+ [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;
1051
+ };
1052
+ type ActionsOf<AD extends AnyActorDefinition> = AD["config"] extends {
1053
+ actions?: infer R;
1054
+ } ? R : never;
1055
+ interface ActorGatewayOptions {
1056
+ skipReadyWait?: boolean;
1057
+ }
1058
+ interface ActorActionOptions extends ActorGatewayOptions {
1059
+ signal?: AbortSignal;
1060
+ }
1061
+ type ActorConnectOptions = ActorGatewayOptions;
1062
+ type ActorFetchInit = RequestInit & ActorGatewayOptions;
1063
+ type ActorWebSocketOptions = ActorGatewayOptions;
1064
+ /**
1065
+ * Maps action methods from actor definition to typed function signatures.
1066
+ */
1067
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
1068
+ type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
1069
+ <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
1070
+ <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
1071
+ (name: keyof TQueues extends never ? string : never, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1072
+ (name: keyof TQueues extends never ? string : never, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
1073
+ };
1074
+ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
1075
+ <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
1076
+ (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
1077
+ };
1078
+ type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1079
+ send: ActorQueueSend<Record<string, any>>;
1080
+ } : AD extends {
1081
+ config: {
1082
+ queues?: infer Q;
1083
+ };
1084
+ } ? Q extends QueueSchemaConfig ? {
1085
+ send: ActorQueueSend<Q>;
1086
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
1087
+ send: ActorQueueSend<Q>;
1088
+ } : {} : {};
1089
+ type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1090
+ on: LooseEventSubscribe;
1091
+ once: LooseEventSubscribe;
1092
+ } : AD extends {
1093
+ config: {
1094
+ events?: infer E;
1095
+ };
1096
+ } ? E extends EventSchemaConfig ? {
1097
+ on: ActorEventSubscribe<E>;
1098
+ once: ActorEventSubscribe<E>;
1099
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
1100
+ on: ActorEventSubscribe<E>;
1101
+ once: ActorEventSubscribe<E>;
1102
+ } : {} : {};
1103
+
1104
+ declare class ActorClientError extends Error {
1105
+ }
1106
+ declare class ManagerError extends ActorClientError {
1107
+ constructor(error: string, opts?: ErrorOptions);
1108
+ }
1109
+ declare class MalformedResponseMessage extends ActorClientError {
1110
+ constructor(cause?: unknown);
1111
+ }
1112
+
1113
+ declare class ActorConnDisposed extends ActorClientError {
1114
+ constructor();
1115
+ }
1116
+
1117
+ type ActorResolutionState = ActorQuery;
1118
+
1119
+ /**
1120
+ * Connection status for an actor connection.
639
1121
  *
640
- * Private methods (e.g. those starting with `_`) are automatically excluded.
1122
+ * - `"idle"`: Not connected, no auto-reconnect (initial state, after dispose, or disabled)
1123
+ * - `"connecting"`: Attempting to establish connection
1124
+ * - `"connected"`: Connection is active
1125
+ * - `"disconnected"`: Connection was lost, will auto-reconnect
1126
+ */
1127
+ type ActorConnStatus = "idle" | "connecting" | "connected" | "disconnected";
1128
+ /**
1129
+ * A function that unsubscribes from an event.
641
1130
  *
642
- * @template AD The actor class that this connection is for.
643
- * @see {@link ActorConnRaw}
1131
+ * @typedef {Function} EventUnsubscribe
644
1132
  */
645
- type ActorConn<AD extends AnyActorDefinition> = Omit<ActorConnRaw, "send" | "on" | "once"> & ActorDefinitionQueueSend<AD> & ActorDefinitionEventSubscriptions<AD> & ActorDefinitionActions<AD>;
646
-
1133
+ type EventUnsubscribe = () => void;
647
1134
  /**
648
- * Provides underlying functions for stateless {@link ActorHandle} for action calls.
649
- * Similar to ActorConnRaw but doesn't maintain a connection.
1135
+ * A function that handles connection errors.
650
1136
  *
651
- * @see {@link ActorHandle}
1137
+ * @typedef {Function} ActorErrorCallback
652
1138
  */
653
- declare class ActorHandleRaw {
1139
+ type ActorErrorCallback = (error: RivetError) => void;
1140
+ /**
1141
+ * A callback for connection state changes.
1142
+ *
1143
+ * @typedef {Function} ConnectionStateCallback
1144
+ */
1145
+ type ConnectionStateCallback = () => void;
1146
+ /**
1147
+ * A callback for connection status changes.
1148
+ *
1149
+ * @typedef {Function} StatusChangeCallback
1150
+ */
1151
+ type StatusChangeCallback = (status: ActorConnStatus) => void;
1152
+ declare const CONNECT_SYMBOL: unique symbol;
1153
+ /**
1154
+ * Provides underlying functions for {@link ActorConn}. See {@link ActorConn} for using type-safe remote procedure calls.
1155
+ *
1156
+ * @see {@link ActorConn}
1157
+ */
1158
+ declare class ActorConnRaw {
654
1159
  #private;
655
1160
  /**
656
1161
  * Do not call this directly.
657
1162
  *
658
- * Creates an instance of ActorHandleRaw.
1163
+ * Creates an instance of ActorConnRaw.
659
1164
  *
660
1165
  * @protected
661
1166
  */
662
- constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions);
1167
+ constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions, currentActorInvocation?: CurrentActorInvocation);
663
1168
  send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
664
1169
  send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
665
1170
  /**
666
- * Call a raw action. This method sends an HTTP request to invoke the named action.
1171
+ * Call a raw action connection. See {@link ActorConn} for type-safe action calls.
667
1172
  *
668
- * @see {@link ActorHandle}
1173
+ * @see {@link ActorConn}
669
1174
  * @template Args - The type of arguments to pass to the action function.
670
1175
  * @template Response - The type of the response returned by the action function.
1176
+ * @param {string} name - The name of the action function to call.
1177
+ * @param {...Args} args - The arguments to pass to the action function.
1178
+ * @returns {Promise<Response>} - A promise that resolves to the response of the action function.
671
1179
  */
672
1180
  action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
673
1181
  name: string;
674
1182
  args: Args;
675
- } & ActorActionOptions): Promise<Response>;
1183
+ signal?: AbortSignal;
1184
+ }): Promise<Response>;
676
1185
  /**
677
- * Establishes a persistent connection to the actor.
1186
+ * Do not call this directly.
1187
+ * Establishes a connection to the server using the specified endpoint & encoding & driver.
678
1188
  *
679
- * @template AD The actor class that this connection is for.
680
- * @returns {ActorConn<AD>} A connection to the actor.
681
- */
682
- connect(params?: unknown, options?: ActorConnectOptions): ActorConn<AnyActorDefinition>;
683
- /**
684
- * Fetches a resource from this actor via the /request endpoint. This is a
685
- * convenience wrapper around the raw HTTP API.
1189
+ * @protected
686
1190
  */
687
- fetch(input: string | URL | Request, init?: ActorFetchInit): Promise<Response>;
1191
+ [CONNECT_SYMBOL](): void;
1192
+ /**
1193
+ * Subscribes to an event that will happen repeatedly.
1194
+ *
1195
+ * @template Args - The type of arguments the event callback will receive.
1196
+ * @param {string} eventName - The name of the event to subscribe to.
1197
+ * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
1198
+ * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
1199
+ * @see {@link https://rivet.dev/docs/events|Events Documentation}
1200
+ */
1201
+ on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
1202
+ /**
1203
+ * Subscribes to an event that will be triggered only once.
1204
+ *
1205
+ * @template Args - The type of arguments the event callback will receive.
1206
+ * @param {string} eventName - The name of the event to subscribe to.
1207
+ * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
1208
+ * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
1209
+ * @see {@link https://rivet.dev/docs/events|Events Documentation}
1210
+ */
1211
+ once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
1212
+ /**
1213
+ * Subscribes to connection errors.
1214
+ *
1215
+ * @param {ActorErrorCallback} callback - The callback function to execute when a connection error occurs.
1216
+ * @returns {() => void} - A function to unsubscribe from the error handler.
1217
+ */
1218
+ onError(callback: ActorErrorCallback): () => void;
1219
+ /**
1220
+ * Returns the current connection status.
1221
+ *
1222
+ * @returns {ActorConnStatus} - The current connection status.
1223
+ */
1224
+ get connStatus(): ActorConnStatus;
1225
+ /**
1226
+ * Returns whether the connection is currently open.
1227
+ *
1228
+ * @deprecated Use `connStatus` instead.
1229
+ * @returns {boolean} - True if the connection is open, false otherwise.
1230
+ */
1231
+ get isConnected(): boolean;
1232
+ /**
1233
+ * Resolves when this connection first reaches the connected state.
1234
+ */
1235
+ get ready(): Promise<void>;
1236
+ /**
1237
+ * Subscribes to connection open events.
1238
+ *
1239
+ * This is called when the WebSocket connection is established and the Init message is received.
1240
+ *
1241
+ * @param {ConnectionStateCallback} callback - The callback function to execute when the connection opens.
1242
+ * @returns {() => void} - A function to unsubscribe from the open handler.
1243
+ */
1244
+ onOpen(callback: ConnectionStateCallback): () => void;
1245
+ /**
1246
+ * Subscribes to connection close events.
1247
+ *
1248
+ * This is called when the WebSocket connection is closed. The connection will automatically
1249
+ * attempt to reconnect unless disposed.
1250
+ *
1251
+ * @param {ConnectionStateCallback} callback - The callback function to execute when the connection closes.
1252
+ * @returns {() => void} - A function to unsubscribe from the close handler.
1253
+ */
1254
+ onClose(callback: ConnectionStateCallback): () => void;
1255
+ /**
1256
+ * Subscribes to connection status changes.
1257
+ *
1258
+ * This is called whenever the connection status changes between Disconnected, Connecting, and Connected.
1259
+ *
1260
+ * @param {StatusChangeCallback} callback - The callback function to execute when the status changes.
1261
+ * @returns {() => void} - A function to unsubscribe from the status change handler.
1262
+ */
1263
+ onStatusChange(callback: StatusChangeCallback): () => void;
1264
+ /**
1265
+ * Disconnects from the actor.
1266
+ *
1267
+ * @returns {Promise<void>} A promise that resolves when the socket is gracefully closed.
1268
+ */
1269
+ dispose(): Promise<void>;
1270
+ }
1271
+ /**
1272
+ * Connection to a actor. Allows calling actor's remote procedure calls with inferred types. See {@link ActorConnRaw} for underlying methods.
1273
+ *
1274
+ * @example
1275
+ * ```
1276
+ * const room = client.connect<ChatRoom>(...etc...);
1277
+ * // This calls the action named `sendMessage` on the `ChatRoom` actor.
1278
+ * await room.sendMessage('Hello, world!');
1279
+ * ```
1280
+ *
1281
+ * Private methods (e.g. those starting with `_`) are automatically excluded.
1282
+ *
1283
+ * @template AD The actor class that this connection is for.
1284
+ * @see {@link ActorConnRaw}
1285
+ */
1286
+ type ActorConn<AD extends AnyActorDefinition> = Omit<ActorConnRaw, "send" | "on" | "once"> & ActorDefinitionQueueSend<AD> & ActorDefinitionEventSubscriptions<AD> & ActorDefinitionActions<AD>;
1287
+
1288
+ /** How many retries a client may spend, as a share of the requests it sends. */
1289
+ interface RetryBudgetOptions {
1290
+ /** Retries allowed per 100 requests (default 10). */
1291
+ percent?: number;
1292
+ /** Retries the client can bank for a burst of refusals; the budget starts full (default 100). */
1293
+ maxTokens?: number;
1294
+ }
1295
+ /**
1296
+ * Bounds the client's retries of refused requests. Each request adds a fraction of a token and
1297
+ * each retry spends one, so retries stay a fixed share of traffic while the service sheds load
1298
+ * instead of multiplying it.
1299
+ */
1300
+ declare class RetryBudget {
1301
+ #private;
1302
+ constructor(options?: RetryBudgetOptions);
1303
+ /** Credits one request sent. */
1304
+ deposit(): void;
1305
+ /** Spends one token. Returns `false` when the budget is spent. */
1306
+ tryWithdraw(): boolean;
1307
+ }
1308
+
1309
+ /**
1310
+ * Provides underlying functions for stateless {@link ActorHandle} for action calls.
1311
+ * Similar to ActorConnRaw but doesn't maintain a connection.
1312
+ *
1313
+ * @see {@link ActorHandle}
1314
+ */
1315
+ declare class ActorHandleRaw {
1316
+ #private;
1317
+ /**
1318
+ * Do not call this directly.
1319
+ *
1320
+ * Creates an instance of ActorHandleRaw.
1321
+ *
1322
+ * @protected
1323
+ */
1324
+ 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);
1325
+ send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1326
+ send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
1327
+ /**
1328
+ * Call a raw action. This method sends an HTTP request to invoke the named action.
1329
+ *
1330
+ * @see {@link ActorHandle}
1331
+ * @template Args - The type of arguments to pass to the action function.
1332
+ * @template Response - The type of the response returned by the action function.
1333
+ */
1334
+ action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
1335
+ name: string;
1336
+ args: Args;
1337
+ } & ActorActionOptions): Promise<Response>;
1338
+ /**
1339
+ * Establishes a persistent connection to the actor.
1340
+ *
1341
+ * @template AD The actor class that this connection is for.
1342
+ * @returns {ActorConn<AD>} A connection to the actor.
1343
+ */
1344
+ connect(params?: unknown, options?: ActorConnectOptions): ActorConn<AnyActorDefinition>;
1345
+ /**
1346
+ * Fetches a resource from this actor via the /request endpoint. This is a
1347
+ * convenience wrapper around the raw HTTP API.
1348
+ */
1349
+ fetch(input: string | URL | Request, init?: ActorFetchInit): Promise<Response>;
688
1350
  /**
689
1351
  * Opens a raw WebSocket connection to this actor.
690
1352
  */
@@ -693,6 +1355,8 @@ declare class ActorHandleRaw {
693
1355
  * Resolves the actor to get its unique actor ID.
694
1356
  */
695
1357
  resolve(): Promise<string>;
1358
+ /** Issue a token scoped to this actor. Defaults to actor gateway read access. */
1359
+ issueToken(options?: ActorIssueTokenOptions): Promise<IssuedToken>;
696
1360
  /**
697
1361
  * Returns the raw URL for routing traffic to the actor.
698
1362
  */
@@ -718,11 +1382,17 @@ declare class ActorHandleRaw {
718
1382
  type ActorHandle<AD extends AnyActorDefinition> = Omit<ActorHandleRaw, "connect" | "send"> & {
719
1383
  connect(params?: unknown, options?: ActorConnectOptions): ActorConn<AD>;
720
1384
  resolve(): Promise<string>;
721
- } & ActorDefinitionQueueSend<AD> & ActorDefinitionActions<AD>;
1385
+ } & ActorDefinitionQueueSend<AD> & Omit<ActorDefinitionActions<AD>, keyof ActorHandleRaw>;
1386
+
1387
+ /** Called when RivetKit needs a credential. Keep issuer secrets on your backend. */
1388
+ type GetToken = (options: {
1389
+ forceRefresh: boolean;
1390
+ }) => Promise<string>;
722
1391
 
723
1392
  declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
724
1393
  endpoint: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string, string | undefined>>;
725
1394
  token: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
1395
+ getToken: z$1.ZodOptional<z$1.ZodCustom<GetToken, GetToken>>;
726
1396
  namespace: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
727
1397
  poolName: z$1.ZodDefault<z$1.ZodString>;
728
1398
  encoding: z$1.ZodDefault<z$1.ZodEnum<{
@@ -735,6 +1405,11 @@ declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
735
1405
  skipReadyWait: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
736
1406
  }, z$1.core.$strip>>>;
737
1407
  getUpgradeWebSocket: z$1.ZodOptional<z$1.ZodCustom<GetUpgradeWebSocket, GetUpgradeWebSocket>>;
1408
+ retryBudget: z$1.ZodOptional<z$1.ZodObject<{
1409
+ percent: z$1.ZodOptional<z$1.ZodNumber>;
1410
+ maxTokens: z$1.ZodOptional<z$1.ZodNumber>;
1411
+ }, z$1.core.$strip>>;
1412
+ fetch: z$1.ZodOptional<z$1.ZodCustom<typeof fetch, typeof fetch>>;
738
1413
  disableMetadataLookup: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
739
1414
  maxInputSize: z$1.ZodDefault<z$1.ZodNumber>;
740
1415
  devtools: z$1.ZodDefault<z$1.ZodBoolean>;
@@ -751,7 +1426,13 @@ declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
751
1426
  disableMetadataLookup: boolean;
752
1427
  maxInputSize: number;
753
1428
  devtools: boolean;
1429
+ getToken?: GetToken | undefined;
754
1430
  getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
1431
+ retryBudget?: {
1432
+ percent?: number | undefined;
1433
+ maxTokens?: number | undefined;
1434
+ } | undefined;
1435
+ fetch?: typeof fetch | undefined;
755
1436
  }, {
756
1437
  endpoint: string;
757
1438
  token: string | undefined;
@@ -765,7 +1446,13 @@ declare const ClientConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
765
1446
  disableMetadataLookup: boolean;
766
1447
  maxInputSize: number;
767
1448
  devtools: boolean;
1449
+ getToken?: GetToken | undefined;
768
1450
  getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
1451
+ retryBudget?: {
1452
+ percent?: number | undefined;
1453
+ maxTokens?: number | undefined;
1454
+ } | undefined;
1455
+ fetch?: typeof fetch | undefined;
769
1456
  }>>;
770
1457
  type ClientConfigInput = z$1.input<typeof ClientConfigSchema>;
771
1458
 
@@ -867,6 +1554,11 @@ interface GetOrCreateOptions extends QueryOptions {
867
1554
  createInRegion?: string;
868
1555
  /** Input data to pass to the actor. */
869
1556
  createWithInput?: unknown;
1557
+ /**
1558
+ * Name of the envoy pool to select for this actor if it is created.
1559
+ * Overrides the client's configured `poolName` for this call.
1560
+ */
1561
+ poolName?: string;
870
1562
  }
871
1563
  /**
872
1564
  * Options for creating a actor.
@@ -878,6 +1570,11 @@ interface CreateOptions extends QueryOptions {
878
1570
  region?: string;
879
1571
  /** Input data to pass to the actor. */
880
1572
  input?: unknown;
1573
+ /**
1574
+ * Name of the envoy pool to select for this actor.
1575
+ * Overrides the client's configured `poolName` for this call.
1576
+ */
1577
+ poolName?: string;
881
1578
  }
882
1579
  /**
883
1580
  * Represents a region to connect to.
@@ -899,6 +1596,20 @@ interface Region {
899
1596
  }
900
1597
  declare const ACTOR_CONNS_SYMBOL: unique symbol;
901
1598
  declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
1599
+ /** Options for constructing a raw actor client. */
1600
+ interface ClientRawOptions {
1601
+ encoding?: Encoding;
1602
+ gateway?: ActorGatewayOptions;
1603
+ /** Bounds retries of refused requests across every handle of this client. */
1604
+ retryBudget?: RetryBudgetOptions;
1605
+ }
1606
+ /** Runtime-supplied wiring for clients created inside an actor. Set only by the native runtime. */
1607
+ interface ActorClientRuntimeOptions {
1608
+ /** Supplies the calling actor's invocation so actor-to-actor clients propagate its trace and ray ID. */
1609
+ currentActorInvocation?: CurrentActorInvocation;
1610
+ /** Opens and finishes the Core span covering an actor-to-actor call. */
1611
+ startCallSpan?: StartCallSpan;
1612
+ }
902
1613
  /**
903
1614
  * Client for managing & connecting to actors.
904
1615
  *
@@ -907,11 +1618,15 @@ declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
907
1618
  */
908
1619
  declare class ClientRaw {
909
1620
  #private;
1621
+ /** Issue namespace-scoped tokens with an explicit grant list. */
1622
+ readonly auth: {
1623
+ issueToken(options: IssueTokenOptions): Promise<IssuedToken>;
1624
+ };
910
1625
  [ACTOR_CONNS_SYMBOL]: Set<ActorConnRaw>;
911
1626
  /**
912
1627
  * Creates an instance of Client.
913
1628
  */
914
- constructor(driver: EngineControlClient, encoding: Encoding | undefined, gatewayOptions?: ActorGatewayOptions);
1629
+ constructor(driver: EngineControlClient, options?: ClientRawOptions & ActorClientRuntimeOptions);
915
1630
  /**
916
1631
  * Gets a stateless handle to a actor by its ID.
917
1632
  *
@@ -967,9 +1682,12 @@ declare class ClientRaw {
967
1682
  *
968
1683
  * @template A The actor registry type.
969
1684
  */
970
- type Client<A extends Registry<any>> = ClientRaw & {
1685
+ type Client<A extends Registry<any>> = ClientRaw & Omit<{
971
1686
  [K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<ExtractActorsFromRegistry<A>[K]>;
972
- };
1687
+ }, keyof ClientRaw>;
1688
+
1689
+ /** @experimental State exposed by a durable workflow run handler to the Inspector. */
1690
+ type WorkflowState = "pending" | "running" | "sleeping" | "failed" | "completed" | "cancelled" | "rolling_back";
973
1691
 
974
1692
  declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
975
1693
  declare const RAW_STATE_SYMBOL: unique symbol;
@@ -1006,7 +1724,7 @@ type ActorKvListOptions<T extends ActorKvValueType = "text", K extends ActorKvKe
1006
1724
  };
1007
1725
  type ActorClientFor<T> = T extends Registry<any> ? Client<T> : T;
1008
1726
  /**
1009
- * @deprecated Actor KV is deprecated. Use embedded SQLite (`c.db` / `c.sql`)
1727
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`c.db`)
1010
1728
  * or actor state instead.
1011
1729
  */
1012
1730
  interface ActorKv {
@@ -1023,10 +1741,76 @@ interface ActorKv {
1023
1741
  [key: string]: any;
1024
1742
  }
1025
1743
  interface ActorSchedule {
1026
- after(duration: number, action: string, ...args: unknown[]): Promise<void>;
1027
- at(timestamp: number, action: string, ...args: unknown[]): Promise<void>;
1744
+ after(duration: number, action: string, ...args: unknown[]): Promise<string>;
1745
+ at(timestamp: number, action: string, ...args: unknown[]): Promise<string>;
1746
+ cancel(id: string): Promise<boolean>;
1747
+ get(id: string): Promise<ScheduledEventInfo | undefined>;
1748
+ list(): Promise<ScheduledEventInfo[]>;
1749
+ [key: string]: any;
1750
+ }
1751
+ interface ActorCronSetOptions {
1752
+ name: string;
1753
+ expression: string;
1754
+ action: string;
1755
+ args?: unknown[];
1756
+ timezone?: string;
1757
+ /** Defaults to 100. Set to 0 to disable and clear history. Maximum 1,000. */
1758
+ maxHistory?: number;
1759
+ }
1760
+ interface ActorCronEveryOptions {
1761
+ name: string;
1762
+ /** Fixed interval in milliseconds. Minimum 5,000. */
1763
+ interval: number;
1764
+ action: string;
1765
+ args?: unknown[];
1766
+ /** Defaults to 100. Set to 0 to disable and clear history. Maximum 1,000. */
1767
+ maxHistory?: number;
1768
+ }
1769
+ interface ActorCron {
1770
+ set(options: ActorCronSetOptions): Promise<void>;
1771
+ every(options: ActorCronEveryOptions): Promise<void>;
1772
+ get(name: string): Promise<CronJobInfo | undefined>;
1773
+ list(): Promise<CronJobInfo[]>;
1774
+ delete(name: string): Promise<boolean>;
1775
+ history(name: string, options?: {
1776
+ limit?: number;
1777
+ }): Promise<CronFire[]>;
1028
1778
  [key: string]: any;
1029
1779
  }
1780
+ interface ScheduledEventInfo {
1781
+ id: string;
1782
+ action: string;
1783
+ args: unknown[];
1784
+ runAt: number;
1785
+ }
1786
+ type CronJobInfo = {
1787
+ name: string;
1788
+ action: string;
1789
+ args: unknown[];
1790
+ nextRunAt: number;
1791
+ lastRunAt?: number;
1792
+ maxHistory: number;
1793
+ } & ({
1794
+ kind: "cron";
1795
+ expression: string;
1796
+ timezone: string;
1797
+ } | {
1798
+ kind: "every";
1799
+ interval: number;
1800
+ });
1801
+ interface CronFire {
1802
+ action: string;
1803
+ scheduledAt: number;
1804
+ firedAt: number;
1805
+ finishedAt?: number;
1806
+ result: "running" | "ok" | "error" | "skipped";
1807
+ error?: {
1808
+ group: string;
1809
+ code: string;
1810
+ message: string;
1811
+ metadata?: unknown;
1812
+ };
1813
+ }
1030
1814
  type QueueMessageOf<Name extends string, Body> = {
1031
1815
  id: number | bigint;
1032
1816
  name: Name;
@@ -1037,6 +1821,8 @@ type QueueMessageOf<Name extends string, Body> = {
1037
1821
  type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues & string;
1038
1822
  type QueueFilterName<TQueues extends QueueSchemaConfig> = keyof TQueues extends never ? string : QueueName<TQueues>;
1039
1823
  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;
1824
+ type QueueCompleteArgs<T> = undefined extends T ? [response?: T] : [response: T];
1825
+ 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];
1040
1826
  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;
1041
1827
  interface QueueNextOptions<TName extends string = string, TCompletable extends boolean = boolean> {
1042
1828
  names?: readonly TName[];
@@ -1079,6 +1865,13 @@ interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1079
1865
  next<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueNextOptions<TName, TCompletable>): Promise<any>;
1080
1866
  nextBatch<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueNextBatchOptions<TName, TCompletable>): Promise<any[]>;
1081
1867
  waitForNames<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(names: readonly TName[], opts?: QueueWaitOptions<TCompletable>): Promise<any>;
1868
+ /** @experimental */
1869
+ waitForAvailable<const TName extends QueueFilterName<TQueues>>(names?: readonly TName[], opts?: Omit<QueueWaitOptions<false>, "completable">): Promise<void>;
1870
+ /** @experimental */
1871
+ complete<const TName extends QueueFilterName<TQueues>>(message: {
1872
+ id: number | bigint;
1873
+ name: TName;
1874
+ }, ...args: QueueCompleteArgsForName<TQueues, TName>): Promise<void>;
1082
1875
  enqueueAndWait<const TName extends QueueFilterName<TQueues>>(name: TName, body: QueueMessageForName<TQueues, TName>["body"], opts?: QueueEnqueueAndWaitOptions): Promise<QueueCompletionResultForName<TQueues, TName>>;
1083
1876
  tryNext<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueTryNextOptions<TName, TCompletable>): Promise<any>;
1084
1877
  tryNextBatch<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueTryNextBatchOptions<TName, TCompletable>): Promise<any[]>;
@@ -1101,17 +1894,24 @@ interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase
1101
1894
  state: TState;
1102
1895
  vars: TVars;
1103
1896
  /**
1104
- * @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
1897
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`c.db`)
1105
1898
  * or actor state instead.
1106
1899
  */
1107
1900
  readonly kv: ActorKv;
1108
1901
  readonly db: InferDatabaseClient<TDatabase>;
1109
1902
  readonly schedule: ActorSchedule;
1903
+ readonly cron: ActorCron;
1110
1904
  readonly queue: ActorQueue<TQueues>;
1905
+ /** @experimental */
1906
+ readonly run: ActorRun;
1111
1907
  readonly actorId: string;
1112
1908
  readonly name: string;
1113
1909
  readonly key: string[];
1114
1910
  readonly region: string;
1911
+ /** Provisions the experimental Actor Runtime Socket for this actor generation. */
1912
+ actorRuntimeSocket(): Promise<{
1913
+ path: string;
1914
+ }>;
1115
1915
  readonly conns: Map<string, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>>;
1116
1916
  readonly log: ActorLogger;
1117
1917
  readonly abortSignal: AbortSignal;
@@ -1133,6 +1933,43 @@ interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase
1133
1933
  client<T = any>(): ActorClientFor<T>;
1134
1934
  [key: string]: any;
1135
1935
  }
1936
+ /** @experimental How one run of a workflow function ended. */
1937
+ type WorkflowOutcome = "completed" | "sleeping" | "evicted" | "failed" | "cancelled";
1938
+ /** @experimental How one workflow step attempt ended. `retry` will be tried again, `failed` will not. */
1939
+ type WorkflowStepOutcome = "ok" | "retry" | "failed";
1940
+ /** @experimental One open run of a workflow function, traced as its own invocation. */
1941
+ interface WorkflowSpan {
1942
+ /** Runs `body` attributed to this run. */
1943
+ run<T>(body: () => Promise<T>): Promise<T>;
1944
+ /**
1945
+ * Called by a workflow engine before each attempt at a step. Returns
1946
+ * nothing when tracing is off.
1947
+ */
1948
+ startStep(name: string, attempt: number): WorkflowStepSpan | undefined;
1949
+ finish(outcome: WorkflowOutcome): Promise<void>;
1950
+ }
1951
+ /** @experimental One open attempt at one workflow step. */
1952
+ interface WorkflowStepSpan {
1953
+ /** Runs `body` attributed to this attempt. */
1954
+ run<T>(body: () => Promise<T>): Promise<T>;
1955
+ /** `error` is what the step callback threw. */
1956
+ finish(outcome: WorkflowStepOutcome, error?: unknown): void;
1957
+ }
1958
+ /** @experimental */
1959
+ interface ActorRun {
1960
+ /**
1961
+ * @experimental Sets or clears the durable Unix-millisecond deadline that
1962
+ * ensures this actor's run handler is active, starting it if inactive.
1963
+ */
1964
+ setWakeAt(timestamp: number | null): Promise<void>;
1965
+ /** @experimental Called by a workflow engine each time it runs the workflow function. */
1966
+ startWorkflowSpan(): Promise<WorkflowSpan>;
1967
+ /**
1968
+ * @experimental Runs `body` outside the current workflow run, so a workflow
1969
+ * engine's own history storage stays out of the trace.
1970
+ */
1971
+ runOutsideWorkflowSpan<T>(body: () => T): T;
1972
+ }
1136
1973
  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> & {
1137
1974
  conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1138
1975
  };
@@ -1159,6 +1996,7 @@ declare const RunConfigSchema: z.ZodObject<{
1159
1996
  inspector: z.ZodOptional<z.ZodOptional<z.ZodObject<{
1160
1997
  workflow: z.ZodOptional<z.ZodObject<{
1161
1998
  getHistory: z.ZodCustom<() => unknown, () => unknown>;
1999
+ getState: z.ZodOptional<z.ZodCustom<() => Promise<WorkflowState | null>, () => Promise<WorkflowState | null>>>;
1162
2000
  onHistoryUpdated: z.ZodOptional<z.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
1163
2001
  replayFromStep: z.ZodOptional<z.ZodCustom<(entryId?: string) => Promise<unknown>, (entryId?: string) => Promise<unknown>>>;
1164
2002
  }, z.core.$strip>>;
@@ -1181,6 +2019,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1181
2019
  inspector: z.ZodOptional<z.ZodOptional<z.ZodObject<{
1182
2020
  workflow: z.ZodOptional<z.ZodObject<{
1183
2021
  getHistory: z.ZodCustom<() => unknown, () => unknown>;
2022
+ getState: z.ZodOptional<z.ZodCustom<() => Promise<WorkflowState | null>, () => Promise<WorkflowState | null>>>;
1184
2023
  onHistoryUpdated: z.ZodOptional<z.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
1185
2024
  replayFromStep: z.ZodOptional<z.ZodCustom<(entryId?: string) => Promise<unknown>, (entryId?: string) => Promise<unknown>>>;
1186
2025
  }, z.core.$strip>>;
@@ -1193,8 +2032,12 @@ declare const ActorConfigSchema: z.ZodObject<{
1193
2032
  onBeforeActionResponse: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1194
2033
  onRequest: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1195
2034
  onWebSocket: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1196
- actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>>;
2035
+ actions: z.ZodDefault<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
1197
2036
  actionInputSchemas: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
2037
+ tracing: z.ZodOptional<z.ZodObject<{
2038
+ sampler: z.ZodOptional<z.ZodNumber>;
2039
+ actions: z.ZodOptional<z.ZodType<ActionSampleRates, unknown, z.core.$ZodTypeInternals<ActionSampleRates, unknown>>>;
2040
+ }, z.core.$strict>>;
1198
2041
  connParamsSchema: z.ZodOptional<z.ZodAny>;
1199
2042
  events: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
1200
2043
  queues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
@@ -1208,6 +2051,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1208
2051
  options: z.ZodPrefault<z.ZodObject<{
1209
2052
  name: z.ZodOptional<z.ZodString>;
1210
2053
  icon: z.ZodOptional<z.ZodString>;
2054
+ enableActorRuntimeSocket: z.ZodDefault<z.ZodBoolean>;
1211
2055
  canHibernateWebSocket: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<(request: Request) => boolean, (request: Request) => boolean>]>>;
1212
2056
  createVarsTimeout: z.ZodDefault<z.ZodNumber>;
1213
2057
  createConnStateTimeout: z.ZodDefault<z.ZodNumber>;
@@ -1224,6 +2068,7 @@ declare const ActorConfigSchema: z.ZodObject<{
1224
2068
  noSleep: z.ZodDefault<z.ZodBoolean>;
1225
2069
  sleepTimeout: z.ZodDefault<z.ZodNumber>;
1226
2070
  maxQueueSize: z.ZodDefault<z.ZodNumber>;
2071
+ maxSchedules: z.ZodDefault<z.ZodNumber>;
1227
2072
  maxQueueMessageSize: z.ZodDefault<z.ZodNumber>;
1228
2073
  preloadMaxWorkflowBytes: z.ZodOptional<z.ZodNumber>;
1229
2074
  preloadMaxConnectionsBytes: z.ZodOptional<z.ZodNumber>;
@@ -1238,11 +2083,12 @@ declare const ActorConfigSchema: z.ZodObject<{
1238
2083
  }, z.core.$strict>, z.ZodObject<{
1239
2084
  id: z.ZodEnum<{
1240
2085
  state: "state";
1241
- workflow: "workflow";
1242
2086
  database: "database";
2087
+ console: "console";
1243
2088
  queue: "queue";
2089
+ workflow: "workflow";
2090
+ schedules: "schedules";
1244
2091
  connections: "connections";
1245
- console: "console";
1246
2092
  }>;
1247
2093
  hidden: z.ZodLiteral<true>;
1248
2094
  }, z.core.$strict>]>>>;
@@ -1273,7 +2119,10 @@ type CreateVars<TState, _TConnParams, _TConnState, TVars, TInput, TDatabase exte
1273
2119
  createVars: (c: CreateVarsContext<TState, TInput, TDatabase, TEvents, TQueues>, driverCtx: any) => TVars | Promise<TVars>;
1274
2120
  } | Record<never, never>;
1275
2121
  interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1276
- [Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, ...args: any[]) => any;
2122
+ [Action: string]: ((c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, ...args: any[]) => any) | Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
2123
+ }
2124
+ interface ActionInputSchemas {
2125
+ [Action: string]: PrimitiveSchema | ActionInputSchemas;
1277
2126
  }
1278
2127
  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>> {
1279
2128
  /**
@@ -1425,9 +2274,15 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatab
1425
2274
  onWebSocket?: (c: WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, websocket: UniversalWebSocket) => void | Promise<void>;
1426
2275
  actions?: TActions;
1427
2276
  /**
1428
- * Optional schema map for validating action argument tuples in native runtimes.
2277
+ * Optional schemas for validating action argument tuples in native runtimes.
2278
+ * May mirror nested action groups or use dot-separated low-level action names.
2279
+ */
2280
+ actionInputSchemas?: ActionInputSchemas;
2281
+ /**
2282
+ * How much of this actor's work is recorded in traces. Defaults to the
2283
+ * process sampler from `OTEL_TRACES_SAMPLER`.
1429
2284
  */
1430
- actionInputSchemas?: Record<string, PrimitiveSchema>;
2285
+ tracing?: ActorTracingOptions<TActions>;
1431
2286
  /**
1432
2287
  * Optional schema for validating connection params in native runtimes.
1433
2288
  */
@@ -1481,7 +2336,11 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1481
2336
  }>>, z$2.ZodTransform<"auto" | "native" | "wasm", "auto" | "native" | "wasm" | undefined>>;
1482
2337
  wasm: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1483
2338
  bindings: z$2.ZodOptional<z$2.ZodCustom<typeof _rivetkit_rivetkit_wasm, typeof _rivetkit_rivetkit_wasm>>;
1484
- initInput: z$2.ZodOptional<z$2.ZodCustom<_rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined, _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined>>;
2339
+ initInput: z$2.ZodOptional<z$2.ZodCustom<{
2340
+ module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
2341
+ } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined, {
2342
+ module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
2343
+ } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined>>;
1485
2344
  }, z$2.core.$strip>>>;
1486
2345
  sqlite: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodUnion<readonly [z$2.ZodEnum<{
1487
2346
  local: "local";
@@ -1521,6 +2380,7 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1521
2380
  engineHost: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
1522
2381
  enginePort: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1523
2382
  engineVersion: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
2383
+ startServices: z$2.ZodOptional<z$2.ZodBoolean>;
1524
2384
  configurePool: z$2.ZodOptional<z$2.ZodOptional<z$2.ZodObject<{
1525
2385
  name: z$2.ZodOptional<z$2.ZodString>;
1526
2386
  url: z$2.ZodString;
@@ -1528,483 +2388,159 @@ declare const RegistryConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
1528
2388
  requestLifespan: z$2.ZodOptional<z$2.ZodNumber>;
1529
2389
  drainGracePeriod: z$2.ZodOptional<z$2.ZodNumber>;
1530
2390
  metadata: z$2.ZodOptional<z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>>;
1531
- metadataPollInterval: z$2.ZodOptional<z$2.ZodNumber>;
1532
- drainOnVersionUpgrade: z$2.ZodOptional<z$2.ZodBoolean>;
1533
- }, z$2.core.$strip>>>;
1534
- serverless: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1535
- basePath: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
1536
- maxStartPayloadBytes: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
1537
- publicEndpoint: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
1538
- publicToken: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
1539
- }, z$2.core.$strip>>>;
1540
- envoy: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1541
- poolName: z$2.ZodDefault<z$2.ZodString>;
1542
- version: z$2.ZodDefault<z$2.ZodNumber>;
1543
- totalSlots: z$2.ZodDefault<z$2.ZodNumber>;
1544
- envoyKey: z$2.ZodOptional<z$2.ZodString>;
1545
- }, z$2.core.$strip>>>;
1546
- shutdown: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
1547
- gracePeriodMs: z$2.ZodOptional<z$2.ZodNumber>;
1548
- disableSignalHandlers: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
1549
- }, z$2.core.$strip>>>;
1550
- }, z$2.core.$strip>, z$2.ZodTransform<{
1551
- sqlite: {
1552
- backend: "local" | "remote";
1553
- } | undefined;
1554
- endpoint: string | undefined;
1555
- namespace: string;
1556
- token: string | undefined;
1557
- publicEndpoint: string | undefined;
1558
- publicNamespace: string | undefined;
1559
- publicToken: string | undefined;
1560
- validateServerlessEndpoint: boolean;
1561
- serverless: {
1562
- publicEndpoint: string | undefined;
1563
- basePath: string;
1564
- maxStartPayloadBytes: number;
1565
- publicToken: string | undefined;
1566
- };
1567
- use: Record<string, AnyActorDefinition>;
1568
- test: {
1569
- enabled: boolean;
1570
- sqliteBackend?: "local" | "remote" | undefined;
1571
- };
1572
- maxIncomingMessageSize: number;
1573
- maxOutgoingMessageSize: number;
1574
- runtime: "auto" | "native" | "wasm";
1575
- wasm: {
1576
- bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1577
- initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1578
- };
1579
- noWelcome: boolean;
1580
- logging: {
1581
- baseLogger?: Logger | undefined;
1582
- level?: "fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent" | undefined;
1583
- };
1584
- headers: Record<string, string>;
1585
- httpBasePath: string;
1586
- httpPort: number;
1587
- startEngine: boolean;
1588
- engineHost: string;
1589
- enginePort: number;
1590
- engineVersion: string;
1591
- envoy: {
1592
- poolName: string;
1593
- version: number;
1594
- totalSlots: number;
1595
- envoyKey?: string | undefined;
1596
- };
1597
- shutdown: {
1598
- disableSignalHandlers: boolean;
1599
- gracePeriodMs?: number | undefined;
1600
- };
1601
- staticDir?: string | undefined;
1602
- httpHost?: string | undefined;
1603
- configurePool?: {
1604
- url: string;
1605
- name?: string | undefined;
1606
- headers?: Record<string, string> | undefined;
1607
- requestLifespan?: number | undefined;
1608
- drainGracePeriod?: number | undefined;
1609
- metadata?: Record<string, unknown> | undefined;
1610
- metadataPollInterval?: number | undefined;
1611
- drainOnVersionUpgrade?: boolean | undefined;
1612
- } | undefined;
1613
- }, {
1614
- use: Record<string, AnyActorDefinition>;
1615
- test: {
1616
- enabled: boolean;
1617
- sqliteBackend?: "local" | "remote" | undefined;
1618
- };
1619
- maxIncomingMessageSize: number;
1620
- maxOutgoingMessageSize: number;
1621
- runtime: "auto" | "native" | "wasm";
1622
- wasm: {
1623
- bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
1624
- initInput?: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
1625
- };
1626
- sqlite: {
1627
- backend: "local" | "remote";
1628
- } | undefined;
1629
- noWelcome: boolean;
1630
- logging: {
1631
- baseLogger?: Logger | undefined;
1632
- level?: "fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent" | undefined;
1633
- };
1634
- endpoint: string | undefined;
1635
- token: string | undefined;
1636
- namespace: string | undefined;
1637
- headers: Record<string, string>;
1638
- httpBasePath: string;
1639
- httpPort: number;
1640
- startEngine: boolean;
1641
- engineHost: string;
1642
- enginePort: number;
1643
- engineVersion: string;
1644
- serverless: {
1645
- basePath: string;
1646
- maxStartPayloadBytes: number;
1647
- publicEndpoint: string | undefined;
1648
- publicToken: string | undefined;
1649
- };
1650
- envoy: {
1651
- poolName: string;
1652
- version: number;
1653
- totalSlots: number;
1654
- envoyKey?: string | undefined;
1655
- };
1656
- shutdown: {
1657
- disableSignalHandlers: boolean;
1658
- gracePeriodMs?: number | undefined;
1659
- };
1660
- staticDir?: string | undefined;
1661
- httpHost?: string | undefined;
1662
- configurePool?: {
1663
- url: string;
1664
- name?: string | undefined;
1665
- headers?: Record<string, string> | undefined;
1666
- requestLifespan?: number | undefined;
1667
- drainGracePeriod?: number | undefined;
1668
- metadata?: Record<string, unknown> | undefined;
1669
- metadataPollInterval?: number | undefined;
1670
- drainOnVersionUpgrade?: boolean | undefined;
1671
- } | undefined;
1672
- }>>;
1673
- type RegistryConfig = z$2.infer<typeof RegistryConfigSchema>;
1674
- type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof RegistryConfigSchema>, "use"> & {
1675
- use: A;
1676
- };
1677
-
1678
- declare const handleBrand: unique symbol;
1679
- type OpaqueHandle<Name extends string> = {
1680
- readonly [handleBrand]: Name;
1681
- };
1682
- type RegistryHandle = OpaqueHandle<"registry">;
1683
- type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
1684
- type ActorContextHandle = OpaqueHandle<"actorContext">;
1685
- type ConnHandle = OpaqueHandle<"conn">;
1686
- type WebSocketHandle = OpaqueHandle<"webSocket">;
1687
- type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
1688
- type RuntimeBytes = Uint8Array;
1689
- interface RuntimeActorKeySegment {
1690
- kind: string;
1691
- stringValue?: string;
1692
- numberValue?: number;
1693
- }
1694
- interface RuntimeHttpRequest {
1695
- method: string;
1696
- uri: string;
1697
- headers?: Record<string, string>;
1698
- body?: RuntimeBytes;
1699
- }
1700
- interface RuntimeStateDeltaPayload {
1701
- state?: RuntimeBytes;
1702
- connHibernation: Array<{
1703
- connId: string;
1704
- bytes: RuntimeBytes;
1705
- }>;
1706
- connHibernationRemoved: string[];
1707
- }
1708
- interface RuntimeRequestSaveOpts {
1709
- immediate?: boolean;
1710
- maxWaitMs?: number;
1711
- }
1712
- interface RuntimeInspectorSnapshot {
1713
- stateRevision: number;
1714
- connectionsRevision: number;
1715
- queueRevision: number;
1716
- activeConnections: number;
1717
- queueSize: number;
1718
- connectedClients: number;
1719
- }
1720
- interface RuntimeQueueMessage {
1721
- id(): bigint;
1722
- name(): string;
1723
- body(): RuntimeBytes;
1724
- createdAt(): number;
1725
- isCompletable(): boolean;
1726
- complete(response?: RuntimeBytes | undefined | null): Promise<void>;
1727
- }
1728
- interface RuntimeQueueInspectMessage {
1729
- id: number;
1730
- name: string;
1731
- createdAtMs: number;
1732
- }
1733
- interface RuntimeQueueNextBatchOptions {
1734
- names?: string[];
1735
- count?: number;
1736
- timeoutMs?: number;
1737
- completable?: boolean;
1738
- }
1739
- interface RuntimeQueueWaitOptions {
1740
- timeoutMs?: number;
1741
- completable?: boolean;
1742
- }
1743
- interface RuntimeQueueEnqueueAndWaitOptions {
1744
- timeoutMs?: number;
1745
- }
1746
- interface RuntimeQueueTryNextBatchOptions {
1747
- names?: string[];
1748
- count?: number;
1749
- completable?: boolean;
1750
- }
1751
- interface RuntimeKvListOptions {
1752
- reverse?: boolean;
1753
- limit?: number;
1754
- }
1755
- interface RuntimeKvEntry {
1756
- key: RuntimeBytes;
1757
- value: RuntimeBytes;
1758
- }
1759
- type RuntimeSqlBindNoValues = {
1760
- intValue?: never;
1761
- floatValue?: never;
1762
- textValue?: never;
1763
- blobValue?: never;
1764
- };
1765
- type RuntimeSqlBindParam = ({
1766
- kind: "null";
1767
- } & RuntimeSqlBindNoValues) | {
1768
- kind: "int";
1769
- intValue: number;
1770
- floatValue?: never;
1771
- textValue?: never;
1772
- blobValue?: never;
1773
- } | {
1774
- kind: "float";
1775
- intValue?: never;
1776
- floatValue: number;
1777
- textValue?: never;
1778
- blobValue?: never;
1779
- } | {
1780
- kind: "text";
1781
- intValue?: never;
1782
- floatValue?: never;
1783
- textValue: string;
1784
- blobValue?: never;
1785
- } | {
1786
- kind: "blob";
1787
- intValue?: never;
1788
- floatValue?: never;
1789
- textValue?: never;
1790
- blobValue: RuntimeBytes;
1791
- };
1792
- type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
1793
- interface RuntimeSqlQueryResult {
1794
- columns: string[];
1795
- rows: unknown[][];
1796
- }
1797
- type RuntimeSqlExecResult = RuntimeSqlQueryResult;
1798
- interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
1799
- changes: number;
1800
- lastInsertRowId?: number | null;
1801
- }
1802
- interface RuntimeSqlRunResult {
1803
- changes: number;
1804
- }
1805
- interface RuntimeActorConfig {
1806
- name?: string;
1807
- icon?: string;
1808
- hasDatabase?: boolean;
1809
- remoteSqlite?: boolean;
1810
- /** @experimental This entire configuration surface is subject to change. */
1811
- sqliteProfiling?: SqliteProfilingOptions;
1812
- hasState?: boolean;
1813
- canHibernateWebsocket?: boolean;
1814
- stateSaveIntervalMs?: number;
1815
- createStateTimeoutMs?: number;
1816
- onCreateTimeoutMs?: number;
1817
- createVarsTimeoutMs?: number;
1818
- createConnStateTimeoutMs?: number;
1819
- onBeforeConnectTimeoutMs?: number;
1820
- onConnectTimeoutMs?: number;
1821
- onMigrateTimeoutMs?: number;
1822
- onWakeTimeoutMs?: number;
1823
- onBeforeActorStartTimeoutMs?: number;
1824
- actionTimeoutMs?: number;
1825
- onRequestTimeoutMs?: number;
1826
- sleepTimeoutMs?: number;
1827
- noSleep?: boolean;
1828
- sleepGracePeriodMs?: number;
1829
- connectionLivenessTimeoutMs?: number;
1830
- connectionLivenessIntervalMs?: number;
1831
- maxQueueSize?: number;
1832
- maxQueueMessageSize?: number;
1833
- maxIncomingMessageSize?: number;
1834
- maxOutgoingMessageSize?: number;
1835
- preloadMaxWorkflowBytes?: number;
1836
- preloadMaxConnectionsBytes?: number;
1837
- actions?: Array<{
1838
- name: string;
1839
- }>;
1840
- inspectorTabs?: Array<RuntimeInspectorTabEntry>;
1841
- }
1842
- interface RuntimeInspectorTabEntry {
1843
- id: string;
1844
- /** Required for custom entries; omitted for built-in hides. */
1845
- label?: string;
1846
- /**
1847
- * Required for custom entries — absolute path to the source directory.
1848
- * Resolved on the TS side before being handed to the runtime.
1849
- */
1850
- source?: string;
1851
- /** Optional icon id for custom entries. */
1852
- icon?: string;
1853
- /** Set to true for built-in hide entries. */
1854
- hidden?: boolean;
1855
- }
1856
- interface RuntimeServeConfig {
1857
- version: number;
1858
- endpoint: string;
1859
- token?: string;
1860
- namespace: string;
1861
- poolName: string;
1862
- engineBinaryPath?: string;
1863
- engineHost?: string;
1864
- enginePort?: number;
1865
- handleInspectorHttpInRuntime?: boolean;
1866
- inspectorTestToken?: string;
1867
- serverlessBasePath?: string;
1868
- serverlessPackageVersion: string;
1869
- serverlessClientEndpoint?: string;
1870
- serverlessClientNamespace?: string;
1871
- serverlessClientToken?: string;
1872
- serverlessValidateEndpoint: boolean;
1873
- serverlessMaxStartPayloadBytes: number;
1874
- }
1875
- interface RuntimeListenerConfig {
1876
- port: number;
1877
- host?: string;
1878
- publicDir?: string;
1879
- }
1880
- interface RuntimeServerlessRequest {
1881
- method: string;
1882
- url: string;
1883
- headers: Record<string, string>;
1884
- body: RuntimeBytes;
1885
- }
1886
- interface RuntimeServerlessResponseHead {
1887
- status: number;
2391
+ metadataPollInterval: z$2.ZodOptional<z$2.ZodNumber>;
2392
+ drainOnVersionUpgrade: z$2.ZodOptional<z$2.ZodBoolean>;
2393
+ }, z$2.core.$strip>>>;
2394
+ serverless: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
2395
+ basePath: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodString>>;
2396
+ maxStartPayloadBytes: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodNumber>>;
2397
+ publicEndpoint: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
2398
+ publicToken: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
2399
+ }, z$2.core.$strip>>>;
2400
+ node: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
2401
+ poolName: z$2.ZodDefault<z$2.ZodString>;
2402
+ version: z$2.ZodDefault<z$2.ZodNumber>;
2403
+ totalSlots: z$2.ZodDefault<z$2.ZodNumber>;
2404
+ nodeKey: z$2.ZodOptional<z$2.ZodString>;
2405
+ }, z$2.core.$strip>>>;
2406
+ shutdown: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodObject<{
2407
+ gracePeriodMs: z$2.ZodOptional<z$2.ZodNumber>;
2408
+ disableSignalHandlers: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
2409
+ }, z$2.core.$strip>>>;
2410
+ }, z$2.core.$strip>, z$2.ZodTransform<{
2411
+ sqlite: {
2412
+ backend: "local" | "remote";
2413
+ } | undefined;
2414
+ endpoint: string | undefined;
2415
+ engineSpawn: boolean;
2416
+ startServices: boolean;
2417
+ namespace: string;
2418
+ token: string | undefined;
2419
+ publicEndpoint: string | undefined;
2420
+ publicNamespace: string | undefined;
2421
+ publicToken: string | undefined;
2422
+ validateServerlessEndpoint: boolean;
2423
+ serverless: {
2424
+ publicEndpoint: string | undefined;
2425
+ basePath: string;
2426
+ maxStartPayloadBytes: number;
2427
+ publicToken: string | undefined;
2428
+ };
2429
+ use: Record<string, AnyActorDefinition>;
2430
+ test: {
2431
+ enabled: boolean;
2432
+ sqliteBackend?: "local" | "remote" | undefined;
2433
+ };
2434
+ maxIncomingMessageSize: number;
2435
+ maxOutgoingMessageSize: number;
2436
+ runtime: "auto" | "native" | "wasm";
2437
+ wasm: {
2438
+ bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
2439
+ initInput?: {
2440
+ module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
2441
+ } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
2442
+ };
2443
+ noWelcome: boolean;
2444
+ logging: {
2445
+ baseLogger?: Logger | undefined;
2446
+ level?: "fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent" | undefined;
2447
+ };
1888
2448
  headers: Record<string, string>;
1889
- }
1890
- interface RuntimeRegistryRouteResponse {
1891
- status: number;
2449
+ httpBasePath: string;
2450
+ httpPort: number;
2451
+ startEngine: boolean;
2452
+ engineHost: string;
2453
+ enginePort: number;
2454
+ engineVersion: string;
2455
+ node: {
2456
+ poolName: string;
2457
+ version: number;
2458
+ totalSlots: number;
2459
+ nodeKey?: string | undefined;
2460
+ };
2461
+ shutdown: {
2462
+ disableSignalHandlers: boolean;
2463
+ gracePeriodMs?: number | undefined;
2464
+ };
2465
+ staticDir?: string | undefined;
2466
+ httpHost?: string | undefined;
2467
+ configurePool?: {
2468
+ url: string;
2469
+ name?: string | undefined;
2470
+ headers?: Record<string, string> | undefined;
2471
+ requestLifespan?: number | undefined;
2472
+ drainGracePeriod?: number | undefined;
2473
+ metadata?: Record<string, unknown> | undefined;
2474
+ metadataPollInterval?: number | undefined;
2475
+ drainOnVersionUpgrade?: boolean | undefined;
2476
+ } | undefined;
2477
+ }, {
2478
+ use: Record<string, AnyActorDefinition>;
2479
+ test: {
2480
+ enabled: boolean;
2481
+ sqliteBackend?: "local" | "remote" | undefined;
2482
+ };
2483
+ maxIncomingMessageSize: number;
2484
+ maxOutgoingMessageSize: number;
2485
+ runtime: "auto" | "native" | "wasm";
2486
+ wasm: {
2487
+ bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
2488
+ initInput?: {
2489
+ module_or_path: _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput>;
2490
+ } | _rivetkit_rivetkit_wasm.InitInput | Promise<_rivetkit_rivetkit_wasm.InitInput> | undefined;
2491
+ };
2492
+ sqlite: {
2493
+ backend: "local" | "remote";
2494
+ } | undefined;
2495
+ noWelcome: boolean;
2496
+ logging: {
2497
+ baseLogger?: Logger | undefined;
2498
+ level?: "fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent" | undefined;
2499
+ };
2500
+ endpoint: string | undefined;
2501
+ token: string | undefined;
2502
+ namespace: string | undefined;
1892
2503
  headers: Record<string, string>;
1893
- body: RuntimeBytes;
1894
- }
1895
- type RuntimeServerlessStreamEvent = {
1896
- kind: "chunk";
1897
- chunk?: RuntimeBytes;
1898
- } | {
1899
- kind: "end";
1900
- error?: {
1901
- group: string;
1902
- code: string;
1903
- message: string;
2504
+ httpBasePath: string;
2505
+ httpPort: number;
2506
+ startEngine: boolean;
2507
+ engineHost: string;
2508
+ enginePort: number;
2509
+ engineVersion: string;
2510
+ serverless: {
2511
+ basePath: string;
2512
+ maxStartPayloadBytes: number;
2513
+ publicEndpoint: string | undefined;
2514
+ publicToken: string | undefined;
1904
2515
  };
2516
+ node: {
2517
+ poolName: string;
2518
+ version: number;
2519
+ totalSlots: number;
2520
+ nodeKey?: string | undefined;
2521
+ };
2522
+ shutdown: {
2523
+ disableSignalHandlers: boolean;
2524
+ gracePeriodMs?: number | undefined;
2525
+ };
2526
+ staticDir?: string | undefined;
2527
+ httpHost?: string | undefined;
2528
+ startServices?: boolean | undefined;
2529
+ configurePool?: {
2530
+ url: string;
2531
+ name?: string | undefined;
2532
+ headers?: Record<string, string> | undefined;
2533
+ requestLifespan?: number | undefined;
2534
+ drainGracePeriod?: number | undefined;
2535
+ metadata?: Record<string, unknown> | undefined;
2536
+ metadataPollInterval?: number | undefined;
2537
+ drainOnVersionUpgrade?: boolean | undefined;
2538
+ } | undefined;
2539
+ }>>;
2540
+ type RegistryConfig = z$2.infer<typeof RegistryConfigSchema>;
2541
+ type RegistryConfigInput<A extends RegistryActors> = Omit<z$2.input<typeof RegistryConfigSchema>, "use"> & {
2542
+ use: A;
1905
2543
  };
1906
- type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
1907
- type RuntimeWebSocketEvent = {
1908
- kind: "message";
1909
- data: string | RuntimeBytes;
1910
- binary: boolean;
1911
- messageIndex?: number;
1912
- } | {
1913
- kind: "close";
1914
- code: number;
1915
- reason: string;
1916
- wasClean: boolean;
1917
- };
1918
- interface CoreRuntime {
1919
- readonly kind: "napi" | "wasm";
1920
- createRegistry(): RegistryHandle;
1921
- registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
1922
- serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
1923
- shutdownRegistry(registry: RegistryHandle): Promise<void>;
1924
- registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
1925
- handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
1926
- serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
1927
- registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1928
- registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1929
- registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
1930
- createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
1931
- createCancellationToken(): CancellationTokenHandle;
1932
- cancellationTokenAborted(token: CancellationTokenHandle): boolean;
1933
- cancelCancellationToken(token: CancellationTokenHandle): void;
1934
- onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
1935
- actorState(ctx: ActorContextHandle): RuntimeBytes;
1936
- actorBeginOnStateChange(ctx: ActorContextHandle): void;
1937
- actorEndOnStateChange(ctx: ActorContextHandle): void;
1938
- actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
1939
- actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
1940
- actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
1941
- actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
1942
- actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
1943
- actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
1944
- actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
1945
- actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
1946
- actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
1947
- actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
1948
- actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
1949
- actorId(ctx: ActorContextHandle): string;
1950
- actorName(ctx: ActorContextHandle): string;
1951
- actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
1952
- actorRegion(ctx: ActorContextHandle): string;
1953
- actorSleep(ctx: ActorContextHandle): void;
1954
- actorDestroy(ctx: ActorContextHandle): void;
1955
- actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
1956
- actorConns(ctx: ActorContextHandle): ConnHandle[];
1957
- actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
1958
- actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
1959
- actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1960
- actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
1961
- actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
1962
- actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1963
- actorBeginKeepAwake(ctx: ActorContextHandle): number;
1964
- actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
1965
- actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
1966
- actorRuntimeState(ctx: ActorContextHandle): object;
1967
- actorClearRuntimeState(ctx: ActorContextHandle): void;
1968
- actorRestartRunHandler(ctx: ActorContextHandle): void;
1969
- actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
1970
- actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
1971
- actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
1972
- actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
1973
- actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
1974
- actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
1975
- actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1976
- actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
1977
- actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
1978
- actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
1979
- actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
1980
- actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
1981
- actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
1982
- actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
1983
- actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
1984
- actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
1985
- actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
1986
- actorSqlClose(ctx: ActorContextHandle): Promise<void>;
1987
- actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
1988
- actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
1989
- actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
1990
- actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
1991
- actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
1992
- actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
1993
- actorQueueMaxSize(ctx: ActorContextHandle): number;
1994
- actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
1995
- actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
1996
- actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
1997
- connId(conn: ConnHandle): string;
1998
- connParams(conn: ConnHandle): RuntimeBytes;
1999
- connState(conn: ConnHandle): RuntimeBytes;
2000
- connSetState(conn: ConnHandle, state: RuntimeBytes): void;
2001
- connIsHibernatable(conn: ConnHandle): boolean;
2002
- connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
2003
- connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
2004
- webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
2005
- webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
2006
- webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
2007
- }
2008
2544
 
2009
2545
  declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
2010
2546
  runtime: CoreRuntime;
@@ -2016,6 +2552,15 @@ type FetchHandler = (request: Request, ...args: any) => Response | Promise<Respo
2016
2552
  interface ServerlessHandler {
2017
2553
  fetch: FetchHandler;
2018
2554
  }
2555
+ interface RegistryApplication {
2556
+ fetch: FetchHandler;
2557
+ }
2558
+ interface RegistryListenOptions {
2559
+ port?: number;
2560
+ host?: string;
2561
+ publicDir?: string;
2562
+ application?: RegistryApplication;
2563
+ }
2019
2564
  interface RegistryRoutes {
2020
2565
  health(): Promise<Response>;
2021
2566
  metadata(): Promise<Response>;
@@ -2065,18 +2610,16 @@ declare class Registry<A extends RegistryActors> {
2065
2610
  * @param opts.host Address to bind. Defaults to `0.0.0.0`.
2066
2611
  * @param opts.publicDir If set, serves static files from this directory
2067
2612
  * as a fallback below the framework routes.
2613
+ * @param opts.application If set, handles requests that do not match a
2614
+ * framework route.
2068
2615
  *
2069
2616
  * @example
2070
2617
  * ```ts
2071
2618
  * await registry.listen();
2072
- * await registry.listen({ port: 8080, publicDir: "./public" });
2619
+ * await registry.listen({ application: app });
2073
2620
  * ```
2074
2621
  */
2075
- listen(opts?: {
2076
- port?: number;
2077
- host?: string;
2078
- publicDir?: string;
2079
- }): Promise<void>;
2622
+ listen(opts?: RegistryListenOptions): Promise<void>;
2080
2623
  /**
2081
2624
  * Gracefully drains all live registries.
2082
2625
  *
@@ -2099,6 +2642,15 @@ declare class Registry<A extends RegistryActors> {
2099
2642
  */
2100
2643
  shutdown(): Promise<void>;
2101
2644
  startEnvoy(): void;
2645
+ /**
2646
+ * Starts the serverful registry if needed and waits until its envoy has
2647
+ * registered with the Engine. Repeated and concurrent calls share one
2648
+ * startup lifecycle and readiness promise.
2649
+ *
2650
+ * Unlike {@link start}, this reports startup failures and does not resolve
2651
+ * merely because an HTTP health endpoint is listening.
2652
+ */
2653
+ startAndWait(): Promise<void>;
2102
2654
  /**
2103
2655
  * Starts the actor envoy for standalone server deployments.
2104
2656
  *
@@ -2120,4 +2672,4 @@ declare class Registry<A extends RegistryActors> {
2120
2672
  */
2121
2673
  declare function createClient<A extends Registry<any>>(endpointOrConfig?: string | ClientConfigInput): Client<A>;
2122
2674
 
2123
- 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 };
2675
+ 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 GetOptions, type GetToken, type GetWithIdOptions, type IssueTokenOptions, type IssuedToken, MalformedResponseMessage, ManagerError, type QueryOptions, type Region, RivetError, type StatusChangeCallback, type TokenGrant, UserError, createClient };