rivetkit 0.0.0-sqlite-profiling-compat.4a9a623 → 0.0.0-sqlite-sync-3-0-0-release.14341d0

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 +1433 -692
  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-AGDY6TKH.js → chunk-2EQ2WCO7.js} +1054 -364
  19. package/dist/tsup/chunk-2EQ2WCO7.js.map +1 -0
  20. package/dist/tsup/{chunk-7QKCGUTJ.cjs → chunk-4H2LT2WB.cjs} +444 -29
  21. package/dist/tsup/chunk-4H2LT2WB.cjs.map +1 -0
  22. package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
  23. package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
  24. package/dist/tsup/{chunk-QAVN4QNO.cjs → chunk-6WYQ3NJI.cjs} +7 -7
  25. package/dist/tsup/chunk-6WYQ3NJI.cjs.map +1 -0
  26. package/dist/tsup/{chunk-75UE45DE.js → chunk-6ZJX3KXW.js} +436 -21
  27. package/dist/tsup/chunk-6ZJX3KXW.js.map +1 -0
  28. package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
  29. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  30. package/dist/tsup/{chunk-RIT7N3TX.js → chunk-AIGW2SKA.js} +50 -3
  31. package/dist/tsup/chunk-AIGW2SKA.js.map +1 -0
  32. package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
  33. package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
  34. package/dist/tsup/{chunk-2CICCOBL.cjs → chunk-HU4F7H3F.cjs} +52 -5
  35. package/dist/tsup/chunk-HU4F7H3F.cjs.map +1 -0
  36. package/dist/tsup/{chunk-4PX3ZKJR.js → chunk-JNJEWQZL.js} +3 -3
  37. package/dist/tsup/chunk-JNJEWQZL.js.map +1 -0
  38. package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
  39. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  40. package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
  41. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  42. package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
  43. package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
  44. package/dist/tsup/{chunk-NHUTYWKU.cjs → chunk-NE5CUQRN.cjs} +1173 -483
  45. package/dist/tsup/chunk-NE5CUQRN.cjs.map +1 -0
  46. package/dist/tsup/{chunk-IICIOTML.js → chunk-OX5MX7TO.js} +2 -2
  47. package/dist/tsup/{chunk-ND567FR5.cjs → chunk-PSIBTOAR.cjs} +3 -3
  48. package/dist/tsup/chunk-PSIBTOAR.cjs.map +1 -0
  49. package/dist/tsup/chunk-PW6FYEIV.cjs +14 -0
  50. package/dist/tsup/chunk-PW6FYEIV.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-SLICBKAU.js +14 -0
  54. package/dist/tsup/chunk-SLICBKAU.js.map +1 -0
  55. package/dist/tsup/{chunk-XFYEVYHG.js → chunk-WCVYMFWJ.js} +16 -9
  56. package/dist/tsup/chunk-WCVYMFWJ.js.map +1 -0
  57. package/dist/tsup/chunk-WX3JS4XU.cjs +243 -0
  58. package/dist/tsup/chunk-WX3JS4XU.cjs.map +1 -0
  59. package/dist/tsup/chunk-X32L7FDD.js +243 -0
  60. package/dist/tsup/chunk-X32L7FDD.js.map +1 -0
  61. package/dist/tsup/{chunk-2WMYYG4R.cjs → chunk-XAY2HIZN.cjs} +18 -11
  62. package/dist/tsup/chunk-XAY2HIZN.cjs.map +1 -0
  63. package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
  64. package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
  65. package/dist/tsup/client/mod.cjs +8 -9
  66. package/dist/tsup/client/mod.cjs.map +1 -1
  67. package/dist/tsup/client/mod.d.cts +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 +2728 -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 +2645 -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 +178 -25
  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 +29 -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 +54 -61
  211. package/src/registry/index.ts +324 -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-OX5MX7TO.js.map} +0 -0
@@ -1,2278 +1,2 @@
1
- import * as _rivet_dev_agent_os_core from '@rivet-dev/agent-os-core';
2
- import { AgentOs, JsonRpcNotification, PermissionRequest, CronEvent, AgentCapabilities, AgentInfo, JsonRpcResponse, AgentOsOptions, BatchReadResult, BatchWriteEntry, BatchWriteResult, ReaddirRecursiveOptions, DirEntry, AgentRegistryEntry, SpawnedProcessInfo, ProcessInfo, ProcessTreeNode, SessionModeState, SessionConfigOption, GetEventsOptions, SequencedEvent, PermissionReply, AgentType, CreateSessionOptions, SessionInfo, OpenShellOptions } from '@rivet-dev/agent-os-core';
3
- import { z as z$1 } from 'zod/v4';
4
- import { StandardSchemaV1 } from '@standard-schema/spec';
5
- import { Context, Handler, Hono } from 'hono';
6
- import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
7
- import * as _rivetkit_rivetkit_wasm from '@rivetkit/rivetkit-wasm';
8
- import { z } from 'zod';
9
- import { Logger } from 'pino';
10
- import { ContentfulStatusCode } from 'hono/utils/http-status';
11
1
 
12
- type AnyDatabaseProvider = DatabaseProvider<any> | undefined;
13
- interface ActorMetricsLike {
14
- totalKvReads: number;
15
- totalKvWrites: number;
16
- trackSql(query: string, durationMs: number): void;
17
- }
18
- type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : never;
19
- type SqliteBindings = unknown[] | Record<string, unknown>;
20
- /**
21
- * SQLite profiling controls.
22
- *
23
- * @experimental This entire configuration surface is subject to change.
24
- */
25
- interface SqliteProfilingOptions {
26
- enabled?: boolean;
27
- maxTrackedStatementFingerprints?: number;
28
- maxTrackedTransactionFingerprints?: number;
29
- maxPrometheusSeries?: number;
30
- maxStatementsPerTransactionTrace?: number;
31
- maxGetPagesRequestsPerTrace?: number;
32
- maxTransactionNameBytes?: number;
33
- slowOperationThresholdMs?: number;
34
- baselineSampleRate?: number;
35
- maxDiagnosticEventsPerMinute?: number;
36
- diagnosticEventQueueCapacity?: number;
37
- }
38
- interface SqliteQueryResult {
39
- columns: string[];
40
- rows: unknown[][];
41
- }
42
- interface SqliteExecuteResult extends SqliteQueryResult {
43
- changes: number;
44
- lastInsertRowId?: number | null;
45
- }
46
- interface SqliteNativeMetrics {
47
- requestBuildNs: number;
48
- serializeNs: number;
49
- transportNs: number;
50
- stateUpdateNs: number;
51
- totalNs: number;
52
- commitCount: number;
53
- pageCacheEntries: number;
54
- pageCacheWeightedSize: number;
55
- pageCacheCapacityPages: number;
56
- writeBufferDirtyPages: number;
57
- dbSizePages: number;
58
- }
59
- interface SqliteDatabase {
60
- exec(sql: string, callback?: (row: unknown[], columns: string[]) => void): Promise<void>;
61
- execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
62
- run(sql: string, params?: SqliteBindings): Promise<void>;
63
- query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
64
- nativeMetrics?(): SqliteNativeMetrics | Promise<SqliteNativeMetrics | null> | null;
65
- close(): Promise<void>;
66
- }
67
- /**
68
- * Provider for opening native databases from the active runtime.
69
- */
70
- interface NativeDatabaseProvider {
71
- open(actorId: string): Promise<SqliteDatabase>;
72
- }
73
- /**
74
- * Context provided to database providers for creating database clients
75
- */
76
- interface DatabaseProviderContext {
77
- /**
78
- * Actor ID
79
- */
80
- actorId: string;
81
- /**
82
- * Override the default Drizzle database client (optional).
83
- * If not provided, a KV-backed client will be constructed.
84
- */
85
- overrideDrizzleDatabaseClient?: () => Promise<DrizzleDatabaseClient | undefined>;
86
- /** KV operations exposed for custom database providers. */
87
- kv: {
88
- batchPut: (entries: [Uint8Array, Uint8Array][]) => Promise<void>;
89
- batchGet: (keys: Uint8Array[]) => Promise<(Uint8Array | null)[]>;
90
- batchDelete: (keys: Uint8Array[]) => Promise<void>;
91
- deleteRange: (start: Uint8Array, end: Uint8Array) => Promise<void>;
92
- };
93
- /**
94
- * Actor metrics instance. When provided, KV and SQL operations are tracked.
95
- */
96
- metrics?: ActorMetricsLike;
97
- /**
98
- * Logger for debug output. When provided, SQL queries are logged with
99
- * duration and KV call count.
100
- */
101
- log?: {
102
- debug(obj: Record<string, unknown>): void;
103
- };
104
- /**
105
- * Provider for opening native databases from the active runtime.
106
- */
107
- nativeDatabaseProvider?: NativeDatabaseProvider;
108
- }
109
- type DatabaseProvider<DB extends RawAccess> = {
110
- /**
111
- * @experimental This entire configuration surface is subject to change.
112
- */
113
- sqliteProfiling?: SqliteProfilingOptions;
114
- /**
115
- * Creates a new database client for the actor.
116
- * The result is passed to the actor context as `c.db`.
117
- * @experimental
118
- */
119
- createClient: (ctx: DatabaseProviderContext) => Promise<DB>;
120
- /**
121
- * Runs before the actor has started.
122
- * Use this to run migrations or other setup tasks.
123
- * @experimental
124
- */
125
- onMigrate: (client: DB) => void | Promise<void>;
126
- };
127
- /**
128
- * Drizzle database client interface (will be extended by drizzle-orm types)
129
- */
130
- type DrizzleDatabaseClient = {};
131
- type ExecuteFunction = <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]>;
132
- type RawAccess = {
133
- /**
134
- * Executes a raw SQL query.
135
- */
136
- execute: ExecuteFunction;
137
- /**
138
- * Returns native SQLite metrics when the active runtime supports them.
139
- */
140
- nativeMetrics?: () => SqliteNativeMetrics | Promise<SqliteNativeMetrics | null> | null;
141
- /**
142
- * Closes the database connection and releases resources.
143
- */
144
- close: () => Promise<void>;
145
- };
146
-
147
- declare const ActorsSchema: z.ZodRecord<z.ZodString, z.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
148
- type RegistryActors = z.infer<typeof ActorsSchema>;
149
- declare const RegistryConfigSchema: z.ZodPipe<z.ZodObject<{
150
- use: z.ZodRecord<z.ZodString, z.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
151
- test: z.ZodDefault<z.ZodOptional<z.ZodObject<{
152
- enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
153
- sqliteBackend: z.ZodOptional<z.ZodEnum<{
154
- local: "local";
155
- remote: "remote";
156
- }>>;
157
- }, z.core.$strip>>>;
158
- maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
159
- maxOutgoingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
160
- runtime: z.ZodPipe<z.ZodOptional<z.ZodEnum<{
161
- auto: "auto";
162
- native: "native";
163
- wasm: "wasm";
164
- }>>, z.ZodTransform<"auto" | "native" | "wasm", "auto" | "native" | "wasm" | undefined>>;
165
- wasm: z.ZodDefault<z.ZodOptional<z.ZodObject<{
166
- bindings: z.ZodOptional<z.ZodCustom<typeof _rivetkit_rivetkit_wasm, typeof _rivetkit_rivetkit_wasm>>;
167
- initInput: z.ZodOptional<z.ZodCustom<any, any>>;
168
- }, z.core.$strip>>>;
169
- sqlite: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
170
- local: "local";
171
- remote: "remote";
172
- }>, z.ZodObject<{
173
- backend: z.ZodEnum<{
174
- local: "local";
175
- remote: "remote";
176
- }>;
177
- }, z.core.$strip>]>>, z.ZodTransform<{
178
- backend: "local" | "remote";
179
- } | undefined, "local" | "remote" | {
180
- backend: "local" | "remote";
181
- } | undefined>>;
182
- noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
183
- logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
184
- baseLogger: z.ZodOptional<z.ZodCustom<Logger, Logger>>;
185
- level: z.ZodOptional<z.ZodEnum<{
186
- fatal: "fatal";
187
- error: "error";
188
- warn: "warn";
189
- info: "info";
190
- debug: "debug";
191
- trace: "trace";
192
- silent: "silent";
193
- }>>;
194
- }, z.core.$strip>>>;
195
- endpoint: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
196
- token: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
197
- namespace: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
198
- headers: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
199
- staticDir: z.ZodOptional<z.ZodString>;
200
- httpBasePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
201
- httpPort: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
202
- httpHost: z.ZodOptional<z.ZodString>;
203
- startEngine: z.ZodDefault<z.ZodBoolean>;
204
- engineHost: z.ZodDefault<z.ZodOptional<z.ZodString>>;
205
- enginePort: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
206
- engineVersion: z.ZodDefault<z.ZodOptional<z.ZodString>>;
207
- configurePool: z.ZodOptional<z.ZodOptional<z.ZodObject<{
208
- name: z.ZodOptional<z.ZodString>;
209
- url: z.ZodString;
210
- headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
211
- requestLifespan: z.ZodOptional<z.ZodNumber>;
212
- drainGracePeriod: z.ZodOptional<z.ZodNumber>;
213
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
214
- metadataPollInterval: z.ZodOptional<z.ZodNumber>;
215
- drainOnVersionUpgrade: z.ZodOptional<z.ZodBoolean>;
216
- }, z.core.$strip>>>;
217
- serverless: z.ZodDefault<z.ZodOptional<z.ZodObject<{
218
- basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
219
- maxStartPayloadBytes: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
220
- publicEndpoint: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
221
- publicToken: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
222
- }, z.core.$strip>>>;
223
- envoy: z.ZodDefault<z.ZodOptional<z.ZodObject<{
224
- poolName: z.ZodDefault<z.ZodString>;
225
- version: z.ZodDefault<z.ZodNumber>;
226
- totalSlots: z.ZodDefault<z.ZodNumber>;
227
- envoyKey: z.ZodOptional<z.ZodString>;
228
- }, z.core.$strip>>>;
229
- shutdown: z.ZodDefault<z.ZodOptional<z.ZodObject<{
230
- gracePeriodMs: z.ZodOptional<z.ZodNumber>;
231
- disableSignalHandlers: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
232
- }, z.core.$strip>>>;
233
- }, z.core.$strip>, z.ZodTransform<{
234
- sqlite: {
235
- backend: "local" | "remote";
236
- } | undefined;
237
- endpoint: string | undefined;
238
- namespace: string;
239
- token: string | undefined;
240
- publicEndpoint: string | undefined;
241
- publicNamespace: string | undefined;
242
- publicToken: string | undefined;
243
- validateServerlessEndpoint: boolean;
244
- serverless: {
245
- publicEndpoint: string | undefined;
246
- basePath: string;
247
- maxStartPayloadBytes: number;
248
- publicToken: string | undefined;
249
- };
250
- use: Record<string, AnyActorDefinition>;
251
- test: {
252
- enabled: boolean;
253
- sqliteBackend?: "local" | "remote" | undefined;
254
- };
255
- maxIncomingMessageSize: number;
256
- maxOutgoingMessageSize: number;
257
- runtime: "auto" | "native" | "wasm";
258
- wasm: {
259
- bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
260
- initInput?: any;
261
- };
262
- noWelcome: boolean;
263
- logging: {
264
- baseLogger?: Logger | undefined;
265
- level?: "fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent" | undefined;
266
- };
267
- headers: Record<string, string>;
268
- httpBasePath: string;
269
- httpPort: number;
270
- startEngine: boolean;
271
- engineHost: string;
272
- enginePort: number;
273
- engineVersion: string;
274
- envoy: {
275
- poolName: string;
276
- version: number;
277
- totalSlots: number;
278
- envoyKey?: string | undefined;
279
- };
280
- shutdown: {
281
- disableSignalHandlers: boolean;
282
- gracePeriodMs?: number | undefined;
283
- };
284
- staticDir?: string | undefined;
285
- httpHost?: string | undefined;
286
- configurePool?: {
287
- url: string;
288
- name?: string | undefined;
289
- headers?: Record<string, string> | undefined;
290
- requestLifespan?: number | undefined;
291
- drainGracePeriod?: number | undefined;
292
- metadata?: Record<string, unknown> | undefined;
293
- metadataPollInterval?: number | undefined;
294
- drainOnVersionUpgrade?: boolean | undefined;
295
- } | undefined;
296
- }, {
297
- use: Record<string, AnyActorDefinition>;
298
- test: {
299
- enabled: boolean;
300
- sqliteBackend?: "local" | "remote" | undefined;
301
- };
302
- maxIncomingMessageSize: number;
303
- maxOutgoingMessageSize: number;
304
- runtime: "auto" | "native" | "wasm";
305
- wasm: {
306
- bindings?: typeof _rivetkit_rivetkit_wasm | undefined;
307
- initInput?: any;
308
- };
309
- sqlite: {
310
- backend: "local" | "remote";
311
- } | undefined;
312
- noWelcome: boolean;
313
- logging: {
314
- baseLogger?: Logger | undefined;
315
- level?: "fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent" | undefined;
316
- };
317
- endpoint: string | undefined;
318
- token: string | undefined;
319
- namespace: string | undefined;
320
- headers: Record<string, string>;
321
- httpBasePath: string;
322
- httpPort: number;
323
- startEngine: boolean;
324
- engineHost: string;
325
- enginePort: number;
326
- engineVersion: string;
327
- serverless: {
328
- basePath: string;
329
- maxStartPayloadBytes: number;
330
- publicEndpoint: string | undefined;
331
- publicToken: string | undefined;
332
- };
333
- envoy: {
334
- poolName: string;
335
- version: number;
336
- totalSlots: number;
337
- envoyKey?: string | undefined;
338
- };
339
- shutdown: {
340
- disableSignalHandlers: boolean;
341
- gracePeriodMs?: number | undefined;
342
- };
343
- staticDir?: string | undefined;
344
- httpHost?: string | undefined;
345
- configurePool?: {
346
- url: string;
347
- name?: string | undefined;
348
- headers?: Record<string, string> | undefined;
349
- requestLifespan?: number | undefined;
350
- drainGracePeriod?: number | undefined;
351
- metadata?: Record<string, unknown> | undefined;
352
- metadataPollInterval?: number | undefined;
353
- drainOnVersionUpgrade?: boolean | undefined;
354
- } | undefined;
355
- }>>;
356
- type RegistryConfig = z.infer<typeof RegistryConfigSchema>;
357
- type RegistryConfigInput<A extends RegistryActors> = Omit<z.input<typeof RegistryConfigSchema>, "use"> & {
358
- use: A;
359
- };
360
-
361
- type SchemaHookResult = boolean | Promise<boolean>;
362
- type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
363
- interface EventTypeToken<T, TContext = any> {
364
- readonly _eventType?: T;
365
- readonly canSubscribe?: SchemaHook<TContext>;
366
- readonly schema?: PrimitiveSchema;
367
- }
368
- interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
369
- readonly _queueMessage?: TMessage;
370
- readonly _queueComplete?: TComplete;
371
- readonly canPublish?: SchemaHook<TContext>;
372
- readonly message?: PrimitiveSchema;
373
- readonly complete?: PrimitiveSchema;
374
- }
375
- type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
376
- interface EventSchemaDefinition<TContext = any> {
377
- schema: PrimitiveSchema;
378
- canSubscribe?: SchemaHook<TContext>;
379
- }
380
- interface QueueSchemaDefinition<TContext = any> {
381
- message: PrimitiveSchema;
382
- complete?: PrimitiveSchema;
383
- canPublish?: SchemaHook<TContext>;
384
- }
385
- type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
386
- type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
387
- type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
388
- type QueueSchemaConfig<_TContext = any> = Record<string, QueueSchema>;
389
- type InferSchema<T> = T extends QueueSchemaDefinition<any> ? InferSchema<T["message"]> : T extends QueueTypeToken<infer M, unknown, any> ? M : T extends EventSchemaDefinition<any> ? InferSchema<T["schema"]> : T extends StandardSchemaV1<any, infer O> ? O : T extends EventTypeToken<infer R, any> ? R : never;
390
- type InferSchemaMap<T extends Record<string, unknown>> = {
391
- [K in keyof T]: InferSchema<T[K]>;
392
- };
393
- type InferQueueComplete<T> = T extends QueueTypeToken<unknown, infer C, any> ? [C] extends [never] ? never : C : T extends QueueSchemaDefinition<any> ? T["complete"] extends PrimitiveSchema ? InferSchema<T["complete"]> : never : never;
394
- type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
395
- [K in keyof T]: InferQueueComplete<T[K]>;
396
- };
397
- type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
398
-
399
- interface BaseActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, _R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> {
400
- readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
401
- }
402
- interface AnyActorDefinition {
403
- readonly config: any;
404
- }
405
- declare class ActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> implements BaseActorDefinition<S, CP, CS, V, I, DB, E, Q, R> {
406
- #private;
407
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>);
408
- get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
409
- }
410
-
411
- declare const EncodingSchema: z$1.ZodEnum<{
412
- json: "json";
413
- cbor: "cbor";
414
- bare: "bare";
415
- }>;
416
- /**
417
- * Encoding used to communicate between the client & actor.
418
- */
419
- type Encoding = z$1.infer<typeof EncodingSchema>;
420
-
421
- declare const ActorKeySchema: z$1.ZodArray<z$1.ZodString>;
422
- type ActorKey = z$1.infer<typeof ActorKeySchema>;
423
- /**
424
- * Crash policy for actor lifecycle management.
425
- *
426
- * This schema is only used by the engine driver for actor creation. The manager
427
- * driver ignores crash policy and passes it through to the engine unchanged.
428
- */
429
- declare const CrashPolicySchema: z$1.ZodEnum<{
430
- restart: "restart";
431
- sleep: "sleep";
432
- destroy: "destroy";
433
- }>;
434
- type CrashPolicy = z$1.infer<typeof CrashPolicySchema>;
435
- declare const ActorQuerySchema: z$1.ZodUnion<readonly [z$1.ZodObject<{
436
- getForId: z$1.ZodObject<{
437
- name: z$1.ZodString;
438
- actorId: z$1.ZodString;
439
- }, z$1.core.$strip>;
440
- }, z$1.core.$strip>, z$1.ZodObject<{
441
- getForKey: z$1.ZodObject<{
442
- name: z$1.ZodString;
443
- key: z$1.ZodArray<z$1.ZodString>;
444
- }, z$1.core.$strip>;
445
- }, z$1.core.$strip>, z$1.ZodObject<{
446
- getOrCreateForKey: z$1.ZodObject<{
447
- name: z$1.ZodString;
448
- key: z$1.ZodArray<z$1.ZodString>;
449
- input: z$1.ZodOptional<z$1.ZodUnknown>;
450
- region: z$1.ZodOptional<z$1.ZodString>;
451
- }, z$1.core.$strip>;
452
- }, z$1.core.$strip>, z$1.ZodObject<{
453
- create: z$1.ZodObject<{
454
- name: z$1.ZodString;
455
- key: z$1.ZodArray<z$1.ZodString>;
456
- input: z$1.ZodOptional<z$1.ZodUnknown>;
457
- region: z$1.ZodOptional<z$1.ZodString>;
458
- }, z$1.core.$strip>;
459
- }, z$1.core.$strip>]>;
460
- type ActorQuery = z$1.infer<typeof ActorQuerySchema>;
461
-
462
- interface DeconstructedError {
463
- __type: "ActorError";
464
- statusCode: ContentfulStatusCode;
465
- public: boolean;
466
- group: string;
467
- code: string;
468
- message: string;
469
- metadata?: unknown;
470
- actor?: ActorSpecifier;
471
- }
472
-
473
- interface RivetErrorOptions extends ErrorOptions {
474
- /** Error data can safely be serialized in a response to the client. */
475
- public?: boolean;
476
- /** Metadata associated with this error. */
477
- metadata?: unknown;
478
- /** Explicit HTTP status override for router responses. */
479
- statusCode?: number;
480
- /** Actor context associated with this error. */
481
- actor?: ActorSpecifier;
482
- }
483
- /** Identifies the actor that was handling work when an error was produced. */
484
- interface ActorSpecifier {
485
- actorId: string;
486
- generation: number;
487
- key?: string;
488
- }
489
- declare class RivetError extends Error {
490
- __type: "RivetError";
491
- public: boolean;
492
- metadata?: unknown;
493
- statusCode: number;
494
- actor?: ActorSpecifier;
495
- readonly group: string;
496
- readonly code: string;
497
- static isRivetError(error: unknown): error is RivetError | DeconstructedError;
498
- static isActorError(error: unknown): error is RivetError | DeconstructedError;
499
- constructor(group: string, code: string, message: string, options?: RivetErrorOptions | unknown);
500
- toString(): string;
501
- }
502
-
503
- type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
504
- type GetUpgradeWebSocket = () => UpgradeWebSocket;
505
-
506
- type GatewayTarget = {
507
- directId: string;
508
- } | ActorQuery;
509
- interface GatewayRequestOptions {
510
- skipReadyWait?: boolean;
511
- }
512
- interface EngineControlClient {
513
- getForId(input: GetForIdInput): Promise<ActorOutput | undefined>;
514
- getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined>;
515
- getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput>;
516
- createActor(input: CreateInput): Promise<ActorOutput>;
517
- listActors(input: ListActorsInput): Promise<ActorOutput[]>;
518
- sendRequest(target: GatewayTarget, actorRequest: Request, options?: GatewayRequestOptions): Promise<Response>;
519
- openWebSocket(path: string, target: GatewayTarget, encoding: Encoding, params: unknown, options?: GatewayRequestOptions): Promise<UniversalWebSocket>;
520
- proxyRequest(c: Context, actorRequest: Request, actorId: string): Promise<Response>;
521
- proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown): Promise<Response>;
522
- buildGatewayUrl(target: GatewayTarget, options?: GatewayRequestOptions): Promise<string>;
523
- displayInformation(): RuntimeDisplayInformation;
524
- extraStartupLog?: () => Record<string, unknown>;
525
- modifyRuntimeRouter?: (config: RegistryConfig, router: Hono) => void;
526
- setGetUpgradeWebSocket(getUpgradeWebSocket: GetUpgradeWebSocket): void;
527
- shutdown?(): void;
528
- /**
529
- * Test-only helper that simulates an abrupt actor crash.
530
- */
531
- hardCrashActor?(actorId: string): Promise<void>;
532
- kvGet(actorId: string, key: Uint8Array): Promise<string | null>;
533
- kvBatchGet(actorId: string, keys: Uint8Array[]): Promise<(Uint8Array | null)[]>;
534
- kvBatchPut(actorId: string, entries: [Uint8Array, Uint8Array][]): Promise<void>;
535
- kvBatchDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
536
- kvDeleteRange(actorId: string, start: Uint8Array, end: Uint8Array): Promise<void>;
537
- }
538
- interface RuntimeDisplayInformation {
539
- properties: Record<string, string>;
540
- }
541
- interface GetForIdInput {
542
- c?: Context | undefined;
543
- name: string;
544
- actorId: string;
545
- }
546
- interface GetWithKeyInput {
547
- c?: Context | undefined;
548
- name: string;
549
- key: ActorKey;
550
- }
551
- interface GetOrCreateWithKeyInput {
552
- c?: Context | undefined;
553
- name: string;
554
- key: ActorKey;
555
- input?: unknown;
556
- region?: string;
557
- crashPolicy?: CrashPolicy;
558
- }
559
- interface CreateInput {
560
- c?: Context | undefined;
561
- name: string;
562
- key: ActorKey;
563
- input?: unknown;
564
- region?: string;
565
- crashPolicy?: CrashPolicy;
566
- }
567
- interface ListActorsInput {
568
- c?: Context | undefined;
569
- name: string;
570
- key?: string;
571
- includeDestroyed?: boolean;
572
- }
573
- interface ActorOutput {
574
- actorId: string;
575
- name: string;
576
- key: ActorKey;
577
- createTs?: number;
578
- startTs?: number | null;
579
- connectableTs?: number | null;
580
- sleepTs?: number | null;
581
- destroyTs?: number | null;
582
- error?: unknown;
583
- }
584
-
585
- declare const handleBrand: unique symbol;
586
- type OpaqueHandle<Name extends string> = {
587
- readonly [handleBrand]: Name;
588
- };
589
- type RegistryHandle = OpaqueHandle<"registry">;
590
- type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
591
- type ActorContextHandle = OpaqueHandle<"actorContext">;
592
- type ConnHandle = OpaqueHandle<"conn">;
593
- type WebSocketHandle = OpaqueHandle<"webSocket">;
594
- type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
595
- type RuntimeBytes = Uint8Array;
596
- interface RuntimeActorKeySegment {
597
- kind: string;
598
- stringValue?: string;
599
- numberValue?: number;
600
- }
601
- interface RuntimeHttpRequest {
602
- method: string;
603
- uri: string;
604
- headers?: Record<string, string>;
605
- body?: RuntimeBytes;
606
- }
607
- interface RuntimeStateDeltaPayload {
608
- state?: RuntimeBytes;
609
- connHibernation: Array<{
610
- connId: string;
611
- bytes: RuntimeBytes;
612
- }>;
613
- connHibernationRemoved: string[];
614
- }
615
- interface RuntimeRequestSaveOpts {
616
- immediate?: boolean;
617
- maxWaitMs?: number;
618
- }
619
- interface RuntimeInspectorSnapshot {
620
- stateRevision: number;
621
- connectionsRevision: number;
622
- queueRevision: number;
623
- activeConnections: number;
624
- queueSize: number;
625
- connectedClients: number;
626
- }
627
- interface RuntimeQueueMessage {
628
- id(): bigint;
629
- name(): string;
630
- body(): RuntimeBytes;
631
- createdAt(): number;
632
- isCompletable(): boolean;
633
- complete(response?: RuntimeBytes | undefined | null): Promise<void>;
634
- }
635
- interface RuntimeQueueInspectMessage {
636
- id: number;
637
- name: string;
638
- createdAtMs: number;
639
- }
640
- interface RuntimeQueueNextBatchOptions {
641
- names?: string[];
642
- count?: number;
643
- timeoutMs?: number;
644
- completable?: boolean;
645
- }
646
- interface RuntimeQueueWaitOptions {
647
- timeoutMs?: number;
648
- completable?: boolean;
649
- }
650
- interface RuntimeQueueEnqueueAndWaitOptions {
651
- timeoutMs?: number;
652
- }
653
- interface RuntimeQueueTryNextBatchOptions {
654
- names?: string[];
655
- count?: number;
656
- completable?: boolean;
657
- }
658
- interface RuntimeKvListOptions {
659
- reverse?: boolean;
660
- limit?: number;
661
- }
662
- interface RuntimeKvEntry {
663
- key: RuntimeBytes;
664
- value: RuntimeBytes;
665
- }
666
- type RuntimeSqlBindNoValues = {
667
- intValue?: never;
668
- floatValue?: never;
669
- textValue?: never;
670
- blobValue?: never;
671
- };
672
- type RuntimeSqlBindParam = ({
673
- kind: "null";
674
- } & RuntimeSqlBindNoValues) | {
675
- kind: "int";
676
- intValue: number;
677
- floatValue?: never;
678
- textValue?: never;
679
- blobValue?: never;
680
- } | {
681
- kind: "float";
682
- intValue?: never;
683
- floatValue: number;
684
- textValue?: never;
685
- blobValue?: never;
686
- } | {
687
- kind: "text";
688
- intValue?: never;
689
- floatValue?: never;
690
- textValue: string;
691
- blobValue?: never;
692
- } | {
693
- kind: "blob";
694
- intValue?: never;
695
- floatValue?: never;
696
- textValue?: never;
697
- blobValue: RuntimeBytes;
698
- };
699
- type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
700
- interface RuntimeSqlQueryResult {
701
- columns: string[];
702
- rows: unknown[][];
703
- }
704
- type RuntimeSqlExecResult = RuntimeSqlQueryResult;
705
- interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
706
- changes: number;
707
- lastInsertRowId?: number | null;
708
- }
709
- interface RuntimeSqlRunResult {
710
- changes: number;
711
- }
712
- interface RuntimeActorConfig {
713
- name?: string;
714
- icon?: string;
715
- hasDatabase?: boolean;
716
- remoteSqlite?: boolean;
717
- /** @experimental This entire configuration surface is subject to change. */
718
- sqliteProfiling?: SqliteProfilingOptions;
719
- hasState?: boolean;
720
- canHibernateWebsocket?: boolean;
721
- stateSaveIntervalMs?: number;
722
- createStateTimeoutMs?: number;
723
- onCreateTimeoutMs?: number;
724
- createVarsTimeoutMs?: number;
725
- createConnStateTimeoutMs?: number;
726
- onBeforeConnectTimeoutMs?: number;
727
- onConnectTimeoutMs?: number;
728
- onMigrateTimeoutMs?: number;
729
- onWakeTimeoutMs?: number;
730
- onBeforeActorStartTimeoutMs?: number;
731
- actionTimeoutMs?: number;
732
- onRequestTimeoutMs?: number;
733
- sleepTimeoutMs?: number;
734
- noSleep?: boolean;
735
- sleepGracePeriodMs?: number;
736
- connectionLivenessTimeoutMs?: number;
737
- connectionLivenessIntervalMs?: number;
738
- maxQueueSize?: number;
739
- maxQueueMessageSize?: number;
740
- maxIncomingMessageSize?: number;
741
- maxOutgoingMessageSize?: number;
742
- preloadMaxWorkflowBytes?: number;
743
- preloadMaxConnectionsBytes?: number;
744
- actions?: Array<{
745
- name: string;
746
- }>;
747
- inspectorTabs?: Array<RuntimeInspectorTabEntry>;
748
- }
749
- interface RuntimeInspectorTabEntry {
750
- id: string;
751
- /** Required for custom entries; omitted for built-in hides. */
752
- label?: string;
753
- /**
754
- * Required for custom entries — absolute path to the source directory.
755
- * Resolved on the TS side before being handed to the runtime.
756
- */
757
- source?: string;
758
- /** Optional icon id for custom entries. */
759
- icon?: string;
760
- /** Set to true for built-in hide entries. */
761
- hidden?: boolean;
762
- }
763
- interface RuntimeServeConfig {
764
- version: number;
765
- endpoint: string;
766
- token?: string;
767
- namespace: string;
768
- poolName: string;
769
- engineBinaryPath?: string;
770
- engineHost?: string;
771
- enginePort?: number;
772
- handleInspectorHttpInRuntime?: boolean;
773
- inspectorTestToken?: string;
774
- serverlessBasePath?: string;
775
- serverlessPackageVersion: string;
776
- serverlessClientEndpoint?: string;
777
- serverlessClientNamespace?: string;
778
- serverlessClientToken?: string;
779
- serverlessValidateEndpoint: boolean;
780
- serverlessMaxStartPayloadBytes: number;
781
- }
782
- interface RuntimeListenerConfig {
783
- port: number;
784
- host?: string;
785
- publicDir?: string;
786
- }
787
- interface RuntimeServerlessRequest {
788
- method: string;
789
- url: string;
790
- headers: Record<string, string>;
791
- body: RuntimeBytes;
792
- }
793
- interface RuntimeServerlessResponseHead {
794
- status: number;
795
- headers: Record<string, string>;
796
- }
797
- interface RuntimeRegistryRouteResponse {
798
- status: number;
799
- headers: Record<string, string>;
800
- body: RuntimeBytes;
801
- }
802
- type RuntimeServerlessStreamEvent = {
803
- kind: "chunk";
804
- chunk?: RuntimeBytes;
805
- } | {
806
- kind: "end";
807
- error?: {
808
- group: string;
809
- code: string;
810
- message: string;
811
- };
812
- };
813
- type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
814
- type RuntimeWebSocketEvent = {
815
- kind: "message";
816
- data: string | RuntimeBytes;
817
- binary: boolean;
818
- messageIndex?: number;
819
- } | {
820
- kind: "close";
821
- code: number;
822
- reason: string;
823
- wasClean: boolean;
824
- };
825
- interface CoreRuntime {
826
- readonly kind: "napi" | "wasm";
827
- createRegistry(): RegistryHandle;
828
- registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
829
- serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
830
- shutdownRegistry(registry: RegistryHandle): Promise<void>;
831
- registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
832
- handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
833
- serveListener(registry: RegistryHandle, listener: RuntimeListenerConfig, config: RuntimeServeConfig): Promise<void>;
834
- registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
835
- registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
836
- registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
837
- createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
838
- createCancellationToken(): CancellationTokenHandle;
839
- cancellationTokenAborted(token: CancellationTokenHandle): boolean;
840
- cancelCancellationToken(token: CancellationTokenHandle): void;
841
- onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
842
- actorState(ctx: ActorContextHandle): RuntimeBytes;
843
- actorBeginOnStateChange(ctx: ActorContextHandle): void;
844
- actorEndOnStateChange(ctx: ActorContextHandle): void;
845
- actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
846
- actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
847
- actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
848
- actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
849
- actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
850
- actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
851
- actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
852
- actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
853
- actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
854
- actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
855
- actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
856
- actorId(ctx: ActorContextHandle): string;
857
- actorName(ctx: ActorContextHandle): string;
858
- actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
859
- actorRegion(ctx: ActorContextHandle): string;
860
- actorSleep(ctx: ActorContextHandle): void;
861
- actorDestroy(ctx: ActorContextHandle): void;
862
- actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
863
- actorConns(ctx: ActorContextHandle): ConnHandle[];
864
- actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
865
- actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
866
- actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
867
- actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
868
- actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
869
- actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
870
- actorBeginKeepAwake(ctx: ActorContextHandle): number;
871
- actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
872
- actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
873
- actorRuntimeState(ctx: ActorContextHandle): object;
874
- actorClearRuntimeState(ctx: ActorContextHandle): void;
875
- actorRestartRunHandler(ctx: ActorContextHandle): void;
876
- actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
877
- actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
878
- actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
879
- actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
880
- actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
881
- actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
882
- actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
883
- actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
884
- actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
885
- actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
886
- actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
887
- actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
888
- actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
889
- actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
890
- actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
891
- actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
892
- actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
893
- actorSqlClose(ctx: ActorContextHandle): Promise<void>;
894
- actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
895
- actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
896
- actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
897
- actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
898
- actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
899
- actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
900
- actorQueueMaxSize(ctx: ActorContextHandle): number;
901
- actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
902
- actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
903
- actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
904
- connId(conn: ConnHandle): string;
905
- connParams(conn: ConnHandle): RuntimeBytes;
906
- connState(conn: ConnHandle): RuntimeBytes;
907
- connSetState(conn: ConnHandle, state: RuntimeBytes): void;
908
- connIsHibernatable(conn: ConnHandle): boolean;
909
- connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
910
- connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
911
- webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
912
- webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
913
- webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
914
- }
915
-
916
- declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
917
- runtime: CoreRuntime;
918
- registry: RegistryHandle;
919
- serveConfig: RuntimeServeConfig;
920
- }>;
921
-
922
- type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
923
- interface ServerlessHandler {
924
- fetch: FetchHandler;
925
- }
926
- interface RegistryRoutes {
927
- health(): Promise<Response>;
928
- metadata(): Promise<Response>;
929
- prometheusMetrics(request?: Request): Promise<Response>;
930
- }
931
- /**
932
- * Injectable dependencies for {@link Registry}. Production code uses the
933
- * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
934
- * orchestration against a fake `CoreRuntime` without an engine.
935
- */
936
- interface RegistryDeps {
937
- buildConfiguredRegistry: typeof buildConfiguredRegistry;
938
- }
939
- declare class Registry<A extends RegistryActors> {
940
- #private;
941
- readonly routes: RegistryRoutes;
942
- get config(): RegistryConfigInput<A>;
943
- parseConfig(): RegistryConfig;
944
- constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
945
- /**
946
- * Handle an incoming HTTP request for serverless deployments.
947
- *
948
- * @example
949
- * ```ts
950
- * const app = new Hono();
951
- * app.all("/api/rivet/*", (c) => registry.handler(c.req.raw));
952
- * export default app;
953
- * ```
954
- */
955
- handler(request: Request): Promise<Response>;
956
- /**
957
- * Returns a fetch handler for serverless deployments.
958
- *
959
- * @example
960
- * ```ts
961
- * export default registry.serve();
962
- * ```
963
- */
964
- serve(): ServerlessHandler;
965
- /**
966
- * Bind an HTTP listener provided by the native (Rust) runtime and serve
967
- * the registry's serverless endpoints over it. Resolves only after the
968
- * registry is shut down (SIGINT/SIGTERM or `nativeRegistry.shutdown()`).
969
- *
970
- * @param opts.port Port to listen on. Defaults to `process.env.RIVET_PORT`
971
- * if set, otherwise 3000.
972
- * @param opts.host Address to bind. Defaults to `0.0.0.0`.
973
- * @param opts.publicDir If set, serves static files from this directory
974
- * as a fallback below the framework routes.
975
- *
976
- * @example
977
- * ```ts
978
- * await registry.listen();
979
- * await registry.listen({ port: 8080, publicDir: "./public" });
980
- * ```
981
- */
982
- listen(opts?: {
983
- port?: number;
984
- host?: string;
985
- publicDir?: string;
986
- }): Promise<void>;
987
- /**
988
- * Gracefully drains all live registries.
989
- *
990
- * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
991
- * every live `CoreRegistry` (both `start()` and `handler()` modes) and
992
- * waits for the serve promise to resolve, all bounded by the shutdown
993
- * grace period. Unlike a signal-driven shutdown, this does not re-raise a
994
- * signal or exit the process. The caller owns process lifetime.
995
- *
996
- * Idempotent: concurrent or repeated calls share a single drain. Safe to
997
- * call even if nothing has been started.
998
- *
999
- * @example
1000
- * ```ts
1001
- * const registry = setup({ use: { counter } });
1002
- * registry.start();
1003
- * // ...later, on your own shutdown trigger:
1004
- * await registry.shutdown();
1005
- * ```
1006
- */
1007
- shutdown(): Promise<void>;
1008
- startEnvoy(): void;
1009
- /**
1010
- * Starts the actor envoy for standalone server deployments.
1011
- *
1012
- * Set `RIVETKIT_RUNTIME_MODE=serverless` to instead bind an HTTP listener
1013
- * via `listen()` (Mode B). Mode A (envoy) and Mode B (listener) are
1014
- * mutually exclusive per registry instance.
1015
- *
1016
- * @example
1017
- * ```ts
1018
- * const registry = setup({ use: { counter } });
1019
- * registry.start();
1020
- * ```
1021
- */
1022
- start(): void;
1023
- }
1024
-
1025
- interface QueueSendWaitOptions {
1026
- wait: true;
1027
- timeout?: number;
1028
- signal?: AbortSignal;
1029
- }
1030
- interface QueueSendNoWaitOptions {
1031
- wait?: false;
1032
- timeout?: never;
1033
- signal?: AbortSignal;
1034
- }
1035
- interface QueueSendResult<TResponse = unknown> {
1036
- status: "completed" | "timedOut";
1037
- response?: TResponse;
1038
- }
1039
-
1040
- /**
1041
- * Action function returned by Actor connections and handles.
1042
- *
1043
- * @typedef {Function} ActorActionFunction
1044
- * @template Args
1045
- * @template Response
1046
- * @param {...Args} args - Arguments for the action function.
1047
- * @returns {Promise<Response>}
1048
- */
1049
- type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
1050
- type IsAny<T> = 0 extends 1 & T ? true : false;
1051
- type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
1052
- type ActorActionMap<R> = {
1053
- [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : never;
1054
- };
1055
- type ActionsOf<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? R : never;
1056
- interface ActorGatewayOptions {
1057
- skipReadyWait?: boolean;
1058
- }
1059
- interface ActorActionOptions extends ActorGatewayOptions {
1060
- signal?: AbortSignal;
1061
- }
1062
- type ActorConnectOptions = ActorGatewayOptions;
1063
- type ActorFetchInit = RequestInit & ActorGatewayOptions;
1064
- type ActorWebSocketOptions = ActorGatewayOptions;
1065
- /**
1066
- * Maps action methods from actor definition to typed function signatures.
1067
- */
1068
- type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
1069
- type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
1070
- <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
1071
- <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
1072
- (name: keyof TQueues extends never ? string : never, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1073
- (name: keyof TQueues extends never ? string : never, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
1074
- };
1075
- type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
1076
- <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
1077
- (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
1078
- };
1079
- type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1080
- send: ActorQueueSend<Record<string, any>>;
1081
- } : AD extends {
1082
- config: {
1083
- queues?: infer Q;
1084
- };
1085
- } ? Q extends QueueSchemaConfig ? {
1086
- send: ActorQueueSend<Q>;
1087
- } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
1088
- send: ActorQueueSend<Q>;
1089
- } : {} : {};
1090
- type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1091
- on: LooseEventSubscribe;
1092
- once: LooseEventSubscribe;
1093
- } : AD extends {
1094
- config: {
1095
- events?: infer E;
1096
- };
1097
- } ? E extends EventSchemaConfig ? {
1098
- on: ActorEventSubscribe<E>;
1099
- once: ActorEventSubscribe<E>;
1100
- } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
1101
- on: ActorEventSubscribe<E>;
1102
- once: ActorEventSubscribe<E>;
1103
- } : {} : {};
1104
-
1105
- type ActorResolutionState = ActorQuery;
1106
-
1107
- /**
1108
- * Connection status for an actor connection.
1109
- *
1110
- * - `"idle"`: Not connected, no auto-reconnect (initial state, after dispose, or disabled)
1111
- * - `"connecting"`: Attempting to establish connection
1112
- * - `"connected"`: Connection is active
1113
- * - `"disconnected"`: Connection was lost, will auto-reconnect
1114
- */
1115
- type ActorConnStatus = "idle" | "connecting" | "connected" | "disconnected";
1116
- /**
1117
- * A function that unsubscribes from an event.
1118
- *
1119
- * @typedef {Function} EventUnsubscribe
1120
- */
1121
- type EventUnsubscribe = () => void;
1122
- /**
1123
- * A function that handles connection errors.
1124
- *
1125
- * @typedef {Function} ActorErrorCallback
1126
- */
1127
- type ActorErrorCallback = (error: RivetError) => void;
1128
- /**
1129
- * A callback for connection state changes.
1130
- *
1131
- * @typedef {Function} ConnectionStateCallback
1132
- */
1133
- type ConnectionStateCallback = () => void;
1134
- /**
1135
- * A callback for connection status changes.
1136
- *
1137
- * @typedef {Function} StatusChangeCallback
1138
- */
1139
- type StatusChangeCallback = (status: ActorConnStatus) => void;
1140
- declare const CONNECT_SYMBOL: unique symbol;
1141
- /**
1142
- * Provides underlying functions for {@link ActorConn}. See {@link ActorConn} for using type-safe remote procedure calls.
1143
- *
1144
- * @see {@link ActorConn}
1145
- */
1146
- declare class ActorConnRaw {
1147
- #private;
1148
- /**
1149
- * Do not call this directly.
1150
- *
1151
- * Creates an instance of ActorConnRaw.
1152
- *
1153
- * @protected
1154
- */
1155
- constructor(client: ClientRaw, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions);
1156
- send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1157
- send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
1158
- /**
1159
- * Call a raw action connection. See {@link ActorConn} for type-safe action calls.
1160
- *
1161
- * @see {@link ActorConn}
1162
- * @template Args - The type of arguments to pass to the action function.
1163
- * @template Response - The type of the response returned by the action function.
1164
- * @param {string} name - The name of the action function to call.
1165
- * @param {...Args} args - The arguments to pass to the action function.
1166
- * @returns {Promise<Response>} - A promise that resolves to the response of the action function.
1167
- */
1168
- action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
1169
- name: string;
1170
- args: Args;
1171
- signal?: AbortSignal;
1172
- }): Promise<Response>;
1173
- /**
1174
- * Do not call this directly.
1175
- * Establishes a connection to the server using the specified endpoint & encoding & driver.
1176
- *
1177
- * @protected
1178
- */
1179
- [CONNECT_SYMBOL](): void;
1180
- /**
1181
- * Subscribes to an event that will happen repeatedly.
1182
- *
1183
- * @template Args - The type of arguments the event callback will receive.
1184
- * @param {string} eventName - The name of the event to subscribe to.
1185
- * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
1186
- * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
1187
- * @see {@link https://rivet.dev/docs/events|Events Documentation}
1188
- */
1189
- on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
1190
- /**
1191
- * Subscribes to an event that will be triggered only once.
1192
- *
1193
- * @template Args - The type of arguments the event callback will receive.
1194
- * @param {string} eventName - The name of the event to subscribe to.
1195
- * @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
1196
- * @returns {EventUnsubscribe} - A function to unsubscribe from the event.
1197
- * @see {@link https://rivet.dev/docs/events|Events Documentation}
1198
- */
1199
- once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
1200
- /**
1201
- * Subscribes to connection errors.
1202
- *
1203
- * @param {ActorErrorCallback} callback - The callback function to execute when a connection error occurs.
1204
- * @returns {() => void} - A function to unsubscribe from the error handler.
1205
- */
1206
- onError(callback: ActorErrorCallback): () => void;
1207
- /**
1208
- * Returns the current connection status.
1209
- *
1210
- * @returns {ActorConnStatus} - The current connection status.
1211
- */
1212
- get connStatus(): ActorConnStatus;
1213
- /**
1214
- * Returns whether the connection is currently open.
1215
- *
1216
- * @deprecated Use `connStatus` instead.
1217
- * @returns {boolean} - True if the connection is open, false otherwise.
1218
- */
1219
- get isConnected(): boolean;
1220
- /**
1221
- * Resolves when this connection first reaches the connected state.
1222
- */
1223
- get ready(): Promise<void>;
1224
- /**
1225
- * Subscribes to connection open events.
1226
- *
1227
- * This is called when the WebSocket connection is established and the Init message is received.
1228
- *
1229
- * @param {ConnectionStateCallback} callback - The callback function to execute when the connection opens.
1230
- * @returns {() => void} - A function to unsubscribe from the open handler.
1231
- */
1232
- onOpen(callback: ConnectionStateCallback): () => void;
1233
- /**
1234
- * Subscribes to connection close events.
1235
- *
1236
- * This is called when the WebSocket connection is closed. The connection will automatically
1237
- * attempt to reconnect unless disposed.
1238
- *
1239
- * @param {ConnectionStateCallback} callback - The callback function to execute when the connection closes.
1240
- * @returns {() => void} - A function to unsubscribe from the close handler.
1241
- */
1242
- onClose(callback: ConnectionStateCallback): () => void;
1243
- /**
1244
- * Subscribes to connection status changes.
1245
- *
1246
- * This is called whenever the connection status changes between Disconnected, Connecting, and Connected.
1247
- *
1248
- * @param {StatusChangeCallback} callback - The callback function to execute when the status changes.
1249
- * @returns {() => void} - A function to unsubscribe from the status change handler.
1250
- */
1251
- onStatusChange(callback: StatusChangeCallback): () => void;
1252
- /**
1253
- * Disconnects from the actor.
1254
- *
1255
- * @returns {Promise<void>} A promise that resolves when the socket is gracefully closed.
1256
- */
1257
- dispose(): Promise<void>;
1258
- }
1259
- /**
1260
- * Connection to a actor. Allows calling actor's remote procedure calls with inferred types. See {@link ActorConnRaw} for underlying methods.
1261
- *
1262
- * @example
1263
- * ```
1264
- * const room = client.connect<ChatRoom>(...etc...);
1265
- * // This calls the action named `sendMessage` on the `ChatRoom` actor.
1266
- * await room.sendMessage('Hello, world!');
1267
- * ```
1268
- *
1269
- * Private methods (e.g. those starting with `_`) are automatically excluded.
1270
- *
1271
- * @template AD The actor class that this connection is for.
1272
- * @see {@link ActorConnRaw}
1273
- */
1274
- type ActorConn<AD extends AnyActorDefinition> = Omit<ActorConnRaw, "send" | "on" | "once"> & ActorDefinitionQueueSend<AD> & ActorDefinitionEventSubscriptions<AD> & ActorDefinitionActions<AD>;
1275
-
1276
- /**
1277
- * Provides underlying functions for stateless {@link ActorHandle} for action calls.
1278
- * Similar to ActorConnRaw but doesn't maintain a connection.
1279
- *
1280
- * @see {@link ActorHandle}
1281
- */
1282
- declare class ActorHandleRaw {
1283
- #private;
1284
- /**
1285
- * Do not call this directly.
1286
- *
1287
- * Creates an instance of ActorHandleRaw.
1288
- *
1289
- * @protected
1290
- */
1291
- constructor(client: any, driver: EngineControlClient, params: unknown, getParams: (() => Promise<unknown>) | undefined, encoding: Encoding, actorResolutionState: ActorResolutionState, gatewayOptions?: ActorGatewayOptions);
1292
- send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
1293
- send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
1294
- /**
1295
- * Call a raw action. This method sends an HTTP request to invoke the named action.
1296
- *
1297
- * @see {@link ActorHandle}
1298
- * @template Args - The type of arguments to pass to the action function.
1299
- * @template Response - The type of the response returned by the action function.
1300
- */
1301
- action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
1302
- name: string;
1303
- args: Args;
1304
- } & ActorActionOptions): Promise<Response>;
1305
- /**
1306
- * Establishes a persistent connection to the actor.
1307
- *
1308
- * @template AD The actor class that this connection is for.
1309
- * @returns {ActorConn<AD>} A connection to the actor.
1310
- */
1311
- connect(params?: unknown, options?: ActorConnectOptions): ActorConn<AnyActorDefinition>;
1312
- /**
1313
- * Fetches a resource from this actor via the /request endpoint. This is a
1314
- * convenience wrapper around the raw HTTP API.
1315
- */
1316
- fetch(input: string | URL | Request, init?: ActorFetchInit): Promise<Response>;
1317
- /**
1318
- * Opens a raw WebSocket connection to this actor.
1319
- */
1320
- webSocket(path?: string, protocols?: string | string[], options?: ActorWebSocketOptions): Promise<any>;
1321
- /**
1322
- * Resolves the actor to get its unique actor ID.
1323
- */
1324
- resolve(): Promise<string>;
1325
- /**
1326
- * Returns the raw URL for routing traffic to the actor.
1327
- */
1328
- getGatewayUrl(): Promise<string>;
1329
- reload(): Promise<void>;
1330
- }
1331
- /**
1332
- * Stateless handle to a actor. Allows calling actor's remote procedure calls with inferred types
1333
- * without establishing a persistent connection.
1334
- *
1335
- * @example
1336
- * ```
1337
- * const room = client.get<ChatRoom>(...etc...);
1338
- * // This calls the action named `sendMessage` on the `ChatRoom` actor without a connection.
1339
- * await room.sendMessage('Hello, world!');
1340
- * ```
1341
- *
1342
- * Private methods (e.g. those starting with `_`) are automatically excluded.
1343
- *
1344
- * @template AD The actor class that this handle is for.
1345
- * @see {@link ActorHandleRaw}
1346
- */
1347
- type ActorHandle<AD extends AnyActorDefinition> = Omit<ActorHandleRaw, "connect" | "send"> & {
1348
- connect(params?: unknown, options?: ActorConnectOptions): ActorConn<AD>;
1349
- resolve(): Promise<string>;
1350
- } & ActorDefinitionQueueSend<AD> & ActorDefinitionActions<AD>;
1351
-
1352
- /** Extract the actor registry from the registry definition. */
1353
- type ExtractActorsFromRegistry<A extends Registry<any>> = A extends Registry<infer Actors> ? Actors : never;
1354
- /**
1355
- * Represents a actor accessor that provides methods to interact with a specific actor.
1356
- */
1357
- interface ActorAccessor<AD extends AnyActorDefinition> {
1358
- /**
1359
- * Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
1360
- * The actor name is automatically injected from the property accessor.
1361
- *
1362
- * Each operation resolves the current actor for the key before sending the
1363
- * request.
1364
- *
1365
- * @template AD The actor class that this handle is for.
1366
- * @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
1367
- * @param {GetWithIdOptions} [opts] - Options for getting the actor.
1368
- * @returns {ActorHandle<AD>} - A handle to the actor.
1369
- */
1370
- get(key?: string | string[], opts?: GetWithIdOptions): ActorHandle<AD>;
1371
- /**
1372
- * Gets a stateless handle to a actor by its key, creating it if necessary.
1373
- * The actor name is automatically injected from the property accessor.
1374
- *
1375
- * Each operation resolves the current actor for the key before sending the
1376
- * request.
1377
- *
1378
- * @template AD The actor class that this handle is for.
1379
- * @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
1380
- * @param {GetOptions} [opts] - Options for getting the actor.
1381
- * @returns {ActorHandle<AD>} - A handle to the actor.
1382
- */
1383
- getOrCreate(key?: string | string[], opts?: GetOrCreateOptions): ActorHandle<AD>;
1384
- /**
1385
- * Gets a stateless handle to a actor by its ID.
1386
- *
1387
- * If the actor is destroyed, operations will throw without retrying since
1388
- * there is no key to re-resolve.
1389
- *
1390
- * @template AD The actor class that this handle is for.
1391
- * @param {string} actorId - The ID of the actor.
1392
- * @param {GetWithIdOptions} [opts] - Options for getting the actor.
1393
- * @returns {ActorHandle<AD>} - A handle to the actor.
1394
- */
1395
- getForId(actorId: string, opts?: GetWithIdOptions): ActorHandle<AD>;
1396
- /**
1397
- * Creates a new actor with the name automatically injected from the property accessor,
1398
- * and returns a stateless handle to it with the actor ID resolved.
1399
- *
1400
- * If the actor is destroyed, operations will throw without retrying since
1401
- * creation is a one-shot operation.
1402
- *
1403
- * @template AD The actor class that this handle is for.
1404
- * @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
1405
- * @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
1406
- * @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
1407
- */
1408
- create(key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
1409
- }
1410
- /**
1411
- * Options for querying actors.
1412
- * @typedef {Object} QueryOptions
1413
- * @property {unknown} [parameters] - Parameters to pass to the connection.
1414
- */
1415
- interface QueryOptions {
1416
- /** Parameters to pass to the connection. */
1417
- params?: unknown;
1418
- /**
1419
- * Lazily resolves connection parameters for `.connect()` and `.webSocket()`.
1420
- * This is called each time a new connection is opened.
1421
- */
1422
- getParams?: () => Promise<unknown>;
1423
- /** Signal to abort the request. */
1424
- signal?: AbortSignal;
1425
- }
1426
- /**
1427
- * Options for getting a actor by ID.
1428
- * @typedef {QueryOptions} GetWithIdOptions
1429
- */
1430
- interface GetWithIdOptions extends QueryOptions {
1431
- }
1432
- /**
1433
- * Options for getting or creating a actor.
1434
- * @typedef {QueryOptions} GetOrCreateOptions
1435
- * @property {string} [createInRegion] - Region to create the actor in if it doesn't exist.
1436
- */
1437
- interface GetOrCreateOptions extends QueryOptions {
1438
- /** Region to create the actor in if it doesn't exist. */
1439
- createInRegion?: string;
1440
- /** Input data to pass to the actor. */
1441
- createWithInput?: unknown;
1442
- }
1443
- /**
1444
- * Options for creating a actor.
1445
- * @typedef {QueryOptions} CreateOptions
1446
- * @property {string} [region] - The region to create the actor in.
1447
- */
1448
- interface CreateOptions extends QueryOptions {
1449
- /** The region to create the actor in. */
1450
- region?: string;
1451
- /** Input data to pass to the actor. */
1452
- input?: unknown;
1453
- }
1454
- declare const ACTOR_CONNS_SYMBOL: unique symbol;
1455
- declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
1456
- /**
1457
- * Client for managing & connecting to actors.
1458
- *
1459
- * @template A The actors map type that defines the available actors.
1460
- * @see {@link https://rivet.dev/docs/manage|Create & Manage Actors}
1461
- */
1462
- declare class ClientRaw {
1463
- #private;
1464
- [ACTOR_CONNS_SYMBOL]: Set<ActorConnRaw>;
1465
- /**
1466
- * Creates an instance of Client.
1467
- */
1468
- constructor(driver: EngineControlClient, encoding: Encoding | undefined, gatewayOptions?: ActorGatewayOptions);
1469
- /**
1470
- * Gets a stateless handle to a actor by its ID.
1471
- *
1472
- * @template AD The actor class that this handle is for.
1473
- * @param {string} name - The name of the actor.
1474
- * @param {string} actorId - The ID of the actor.
1475
- * @param {GetWithIdOptions} [opts] - Options for getting the actor.
1476
- * @returns {ActorHandle<AD>} - A handle to the actor.
1477
- */
1478
- getForId<AD extends AnyActorDefinition>(name: string, actorId: string, opts?: GetWithIdOptions): ActorHandle<AD>;
1479
- /**
1480
- * Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
1481
- *
1482
- * @template AD The actor class that this handle is for.
1483
- * @param {string} name - The name of the actor.
1484
- * @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
1485
- * @param {GetWithIdOptions} [opts] - Options for getting the actor.
1486
- * @returns {ActorHandle<AD>} - A handle to the actor.
1487
- */
1488
- get<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: GetWithIdOptions): ActorHandle<AD>;
1489
- /**
1490
- * Gets a stateless handle to a actor by its key, creating it if necessary.
1491
- *
1492
- * @template AD The actor class that this handle is for.
1493
- * @param {string} name - The name of the actor.
1494
- * @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
1495
- * @param {GetOptions} [opts] - Options for getting the actor.
1496
- * @returns {ActorHandle<AD>} - A handle to the actor.
1497
- */
1498
- getOrCreate<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: GetOrCreateOptions): ActorHandle<AD>;
1499
- /**
1500
- * Creates a new actor with the provided key and returns a stateless handle to it.
1501
- * Resolves the actor ID and returns a handle with getForId query.
1502
- *
1503
- * @template AD The actor class that this handle is for.
1504
- * @param {string} name - The name of the actor.
1505
- * @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
1506
- * @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
1507
- * @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
1508
- */
1509
- create<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
1510
- [CREATE_ACTOR_CONN_PROXY]<AD extends AnyActorDefinition>(conn: ActorConnRaw): ActorConn<AD>;
1511
- /**
1512
- * Disconnects from all actors.
1513
- *
1514
- * @returns {Promise<void>} A promise that resolves when all connections are closed.
1515
- */
1516
- dispose(): Promise<void>;
1517
- }
1518
- /**
1519
- * Client type with actor accessors.
1520
- * This adds property accessors for actor names to the ClientRaw base class.
1521
- *
1522
- * @template A The actor registry type.
1523
- */
1524
- type Client<A extends Registry<any>> = ClientRaw & {
1525
- [K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<ExtractActorsFromRegistry<A>[K]>;
1526
- };
1527
-
1528
- declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
1529
- declare const RAW_STATE_SYMBOL: unique symbol;
1530
- interface ActorLogger {
1531
- level: any;
1532
- fatal: any;
1533
- trace: any;
1534
- silent: any;
1535
- msgPrefix: any;
1536
- debug: any;
1537
- info: any;
1538
- warn: any;
1539
- error: any;
1540
- [key: string]: any;
1541
- }
1542
- type ActorKvValueType = "text" | "arrayBuffer" | "binary";
1543
- type ActorKvKeyType = "text" | "binary";
1544
- type ActorKvValueTypeMap = {
1545
- text: string;
1546
- arrayBuffer: ArrayBuffer;
1547
- binary: Uint8Array;
1548
- };
1549
- type ActorKvKeyTypeMap = {
1550
- text: string;
1551
- binary: Uint8Array;
1552
- };
1553
- type ActorKvValueOptions<T extends ActorKvValueType = "text"> = {
1554
- type?: T;
1555
- };
1556
- type ActorKvListOptions<T extends ActorKvValueType = "text", K extends ActorKvKeyType = "text"> = ActorKvValueOptions<T> & {
1557
- keyType?: K;
1558
- reverse?: boolean;
1559
- limit?: number;
1560
- };
1561
- type ActorClientFor<T> = T extends Registry<any> ? Client<T> : T;
1562
- /**
1563
- * @deprecated Actor KV is deprecated. Use embedded SQLite (`c.db` / `c.sql`)
1564
- * or actor state instead.
1565
- */
1566
- interface ActorKv {
1567
- get<T extends ActorKvValueType = "text">(key: Uint8Array | string, options?: ActorKvValueOptions<T>): Promise<ActorKvValueTypeMap[T] | null>;
1568
- put<T extends ActorKvValueType = "text">(key: Uint8Array | string, value: Uint8Array | string | ArrayBuffer, options?: ActorKvValueOptions<T>): Promise<void>;
1569
- delete(key: Uint8Array | string): Promise<void>;
1570
- batchPut(entries: [Uint8Array, Uint8Array][]): Promise<void>;
1571
- batchGet(keys: Uint8Array[]): Promise<(Uint8Array | null)[]>;
1572
- batchDelete(keys: Uint8Array[]): Promise<void>;
1573
- deleteRange(start: Uint8Array, end: Uint8Array): Promise<void>;
1574
- listPrefix<T extends ActorKvValueType = "text", K extends ActorKvKeyType = "text">(prefix: Uint8Array | string, options?: ActorKvListOptions<T, K>): Promise<Array<[ActorKvKeyTypeMap[K], ActorKvValueTypeMap[T]]>>;
1575
- listRange<T extends ActorKvValueType = "text", K extends ActorKvKeyType = "text">(start: Uint8Array | string, end: Uint8Array | string, options?: ActorKvListOptions<T, K>): Promise<Array<[ActorKvKeyTypeMap[K], ActorKvValueTypeMap[T]]>>;
1576
- list<T extends ActorKvValueType = "text", K extends ActorKvKeyType = "text">(prefix: Uint8Array | string, options?: ActorKvListOptions<T, K>): Promise<Array<[ActorKvKeyTypeMap[K], ActorKvValueTypeMap[T]]>>;
1577
- [key: string]: any;
1578
- }
1579
- interface ActorSchedule {
1580
- after(duration: number, action: string, ...args: unknown[]): Promise<void>;
1581
- at(timestamp: number, action: string, ...args: unknown[]): Promise<void>;
1582
- [key: string]: any;
1583
- }
1584
- type QueueMessageOf<Name extends string, Body> = {
1585
- id: number | bigint;
1586
- name: Name;
1587
- body: Body;
1588
- createdAt: number;
1589
- [key: string]: unknown;
1590
- };
1591
- type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues & string;
1592
- type QueueFilterName<TQueues extends QueueSchemaConfig> = keyof TQueues extends never ? string : QueueName<TQueues>;
1593
- 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;
1594
- 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;
1595
- interface QueueNextOptions<TName extends string = string, TCompletable extends boolean = boolean> {
1596
- names?: readonly TName[];
1597
- timeout?: number;
1598
- signal?: AbortSignal;
1599
- completable?: TCompletable;
1600
- }
1601
- interface QueueNextBatchOptions<TName extends string = string, TCompletable extends boolean = boolean> {
1602
- names?: readonly TName[];
1603
- count?: number;
1604
- timeout?: number;
1605
- signal?: AbortSignal;
1606
- completable?: TCompletable;
1607
- }
1608
- interface QueueWaitOptions<TCompletable extends boolean = boolean> {
1609
- timeout?: number;
1610
- signal?: AbortSignal;
1611
- completable?: TCompletable;
1612
- }
1613
- interface QueueEnqueueAndWaitOptions {
1614
- timeout?: number;
1615
- signal?: AbortSignal;
1616
- }
1617
- interface QueueTryNextOptions<TName extends string = string, TCompletable extends boolean = boolean> {
1618
- names?: readonly TName[];
1619
- completable?: TCompletable;
1620
- }
1621
- interface QueueTryNextBatchOptions<TName extends string = string, TCompletable extends boolean = boolean> {
1622
- names?: readonly TName[];
1623
- count?: number;
1624
- completable?: TCompletable;
1625
- }
1626
- interface QueueIterOptions<TName extends string = string, TCompletable extends boolean = boolean> {
1627
- names?: readonly TName[];
1628
- signal?: AbortSignal;
1629
- completable?: TCompletable;
1630
- }
1631
- interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1632
- send<TName extends QueueFilterName<TQueues>>(name: TName, body: QueueMessageForName<TQueues, TName>["body"]): Promise<any>;
1633
- next<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueNextOptions<TName, TCompletable>): Promise<any>;
1634
- nextBatch<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueNextBatchOptions<TName, TCompletable>): Promise<any[]>;
1635
- waitForNames<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(names: readonly TName[], opts?: QueueWaitOptions<TCompletable>): Promise<any>;
1636
- enqueueAndWait<const TName extends QueueFilterName<TQueues>>(name: TName, body: QueueMessageForName<TQueues, TName>["body"], opts?: QueueEnqueueAndWaitOptions): Promise<QueueCompletionResultForName<TQueues, TName>>;
1637
- tryNext<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueTryNextOptions<TName, TCompletable>): Promise<any>;
1638
- tryNextBatch<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueTryNextBatchOptions<TName, TCompletable>): Promise<any[]>;
1639
- iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
1640
- [key: string]: any;
1641
- }
1642
- interface Conn<_TState = unknown, TConnParams = unknown, TConnState = unknown, _TVars = unknown, _TInput = unknown, _TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider, _TEvents extends EventSchemaConfig = Record<never, never>, _TQueues extends QueueSchemaConfig = Record<never, never>> {
1643
- id: string;
1644
- params: TConnParams;
1645
- state: TConnState;
1646
- isHibernatable: boolean;
1647
- send(name: string, ...args: any[]): void;
1648
- disconnect(reason?: string): Promise<void>;
1649
- [key: string]: any;
1650
- }
1651
- interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1652
- [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
1653
- /** Returns the raw unwrapped state without the write-through proxy. */
1654
- [RAW_STATE_SYMBOL](): TState;
1655
- state: TState;
1656
- vars: TVars;
1657
- /**
1658
- * @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
1659
- * or actor state instead.
1660
- */
1661
- readonly kv: ActorKv;
1662
- readonly db: InferDatabaseClient<TDatabase>;
1663
- readonly schedule: ActorSchedule;
1664
- readonly queue: ActorQueue<TQueues>;
1665
- readonly actorId: string;
1666
- readonly name: string;
1667
- readonly key: string[];
1668
- readonly region: string;
1669
- readonly conns: Map<string, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>>;
1670
- readonly log: ActorLogger;
1671
- readonly abortSignal: AbortSignal;
1672
- readonly aborted: boolean;
1673
- readonly request?: Request;
1674
- /** @deprecated No-op. Always returns `false`. Use `keepAwake(promise)` or `waitUntil(promise)` instead. Will be removed in 2.2.0. */
1675
- readonly preventSleep: boolean;
1676
- broadcast(name: string, ...args: any[]): void;
1677
- saveState(opts?: {
1678
- immediate?: boolean;
1679
- maxWait?: number;
1680
- }): Promise<void>;
1681
- keepAwake<T>(promise: Promise<T>): Promise<T>;
1682
- waitUntil(promise: Promise<unknown>): void;
1683
- /** @deprecated No-op. Use `keepAwake(promise)` to hold the actor awake for a specific promise. Will be removed in 2.2.0. */
1684
- setPreventSleep(preventSleep: boolean): void;
1685
- sleep(): void;
1686
- destroy(): void;
1687
- client<T = any>(): ActorClientFor<T>;
1688
- [key: string]: any;
1689
- }
1690
- 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> & {
1691
- conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1692
- };
1693
- type BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1694
- type BeforeConnectContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, unknown, unknown, TVars, TInput, TDatabase, TEvents, TQueues>;
1695
- type ConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1696
- type CreateConnStateContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, unknown, unknown, TVars, TInput, TDatabase, TEvents, TQueues>;
1697
- type CreateContext<TState, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, unknown, unknown, unknown, TInput, TDatabase, TEvents, TQueues>;
1698
- type CreateVarsContext<TState, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = CreateContext<TState, TInput, TDatabase, TEvents, TQueues>;
1699
- type DestroyContext<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>;
1700
- type DisconnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1701
- type RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1702
- type RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1703
- type SleepContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1704
- type StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1705
- type WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1706
- type MigrateContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1707
- type WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1708
- type InspectorUnsubscribe = () => void;
1709
- declare const RunConfigSchema: z$1.ZodObject<{
1710
- name: z$1.ZodOptional<z$1.ZodString>;
1711
- icon: z$1.ZodOptional<z$1.ZodString>;
1712
- run: z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;
1713
- inspector: z$1.ZodOptional<z$1.ZodOptional<z$1.ZodObject<{
1714
- workflow: z$1.ZodOptional<z$1.ZodObject<{
1715
- getHistory: z$1.ZodCustom<() => unknown, () => unknown>;
1716
- onHistoryUpdated: z$1.ZodOptional<z$1.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
1717
- replayFromStep: z$1.ZodOptional<z$1.ZodCustom<(entryId?: string) => Promise<unknown>, (entryId?: string) => Promise<unknown>>>;
1718
- }, z$1.core.$strip>>;
1719
- }, z$1.core.$strip>>>;
1720
- }, z$1.core.$strip>;
1721
- type RunConfigRuntime = z$1.infer<typeof RunConfigSchema>;
1722
- type RunConfig<TState = unknown, TConnParams = unknown, TConnState = unknown, TVars = unknown, TInput = unknown, TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = Omit<RunConfigRuntime, "run"> & {
1723
- run: (c: RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
1724
- };
1725
- declare const ActorConfigSchema: z$1.ZodObject<{
1726
- onCreate: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1727
- onDestroy: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1728
- onMigrate: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1729
- onWake: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1730
- onSleep: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1731
- run: z$1.ZodOptional<z$1.ZodUnion<readonly [z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>, z$1.ZodObject<{
1732
- name: z$1.ZodOptional<z$1.ZodString>;
1733
- icon: z$1.ZodOptional<z$1.ZodString>;
1734
- run: z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;
1735
- inspector: z$1.ZodOptional<z$1.ZodOptional<z$1.ZodObject<{
1736
- workflow: z$1.ZodOptional<z$1.ZodObject<{
1737
- getHistory: z$1.ZodCustom<() => unknown, () => unknown>;
1738
- onHistoryUpdated: z$1.ZodOptional<z$1.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
1739
- replayFromStep: z$1.ZodOptional<z$1.ZodCustom<(entryId?: string) => Promise<unknown>, (entryId?: string) => Promise<unknown>>>;
1740
- }, z$1.core.$strip>>;
1741
- }, z$1.core.$strip>>>;
1742
- }, z$1.core.$strip>]>>;
1743
- onStateChange: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1744
- onBeforeConnect: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1745
- onConnect: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1746
- onDisconnect: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1747
- onBeforeActionResponse: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1748
- onRequest: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1749
- onWebSocket: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1750
- actions: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>>;
1751
- actionInputSchemas: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
1752
- connParamsSchema: z$1.ZodOptional<z$1.ZodAny>;
1753
- events: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
1754
- queues: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodAny>>;
1755
- state: z$1.ZodOptional<z$1.ZodAny>;
1756
- createState: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1757
- connState: z$1.ZodOptional<z$1.ZodAny>;
1758
- createConnState: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1759
- vars: z$1.ZodOptional<z$1.ZodAny>;
1760
- db: z$1.ZodOptional<z$1.ZodAny>;
1761
- createVars: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
1762
- options: z$1.ZodPrefault<z$1.ZodObject<{
1763
- name: z$1.ZodOptional<z$1.ZodString>;
1764
- icon: z$1.ZodOptional<z$1.ZodString>;
1765
- canHibernateWebSocket: z$1.ZodDefault<z$1.ZodUnion<readonly [z$1.ZodBoolean, z$1.ZodCustom<(request: Request) => boolean, (request: Request) => boolean>]>>;
1766
- createVarsTimeout: z$1.ZodDefault<z$1.ZodNumber>;
1767
- createConnStateTimeout: z$1.ZodDefault<z$1.ZodNumber>;
1768
- onBeforeConnectTimeout: z$1.ZodDefault<z$1.ZodNumber>;
1769
- onConnectTimeout: z$1.ZodDefault<z$1.ZodNumber>;
1770
- onMigrateTimeout: z$1.ZodDefault<z$1.ZodNumber>;
1771
- sleepGracePeriod: z$1.ZodDefault<z$1.ZodNumber>;
1772
- onDestroyTimeout: z$1.ZodOptional<z$1.ZodNumber>;
1773
- waitUntilTimeout: z$1.ZodOptional<z$1.ZodNumber>;
1774
- stateSaveInterval: z$1.ZodDefault<z$1.ZodNumber>;
1775
- actionTimeout: z$1.ZodDefault<z$1.ZodNumber>;
1776
- connectionLivenessTimeout: z$1.ZodDefault<z$1.ZodNumber>;
1777
- connectionLivenessInterval: z$1.ZodDefault<z$1.ZodNumber>;
1778
- noSleep: z$1.ZodDefault<z$1.ZodBoolean>;
1779
- sleepTimeout: z$1.ZodDefault<z$1.ZodNumber>;
1780
- maxQueueSize: z$1.ZodDefault<z$1.ZodNumber>;
1781
- maxQueueMessageSize: z$1.ZodDefault<z$1.ZodNumber>;
1782
- preloadMaxWorkflowBytes: z$1.ZodOptional<z$1.ZodNumber>;
1783
- preloadMaxConnectionsBytes: z$1.ZodOptional<z$1.ZodNumber>;
1784
- }, z$1.core.$strict>>;
1785
- inspector: z$1.ZodOptional<z$1.ZodObject<{
1786
- tabs: z$1.ZodDefault<z$1.ZodArray<z$1.ZodUnion<readonly [z$1.ZodObject<{
1787
- id: z$1.ZodString;
1788
- label: z$1.ZodString;
1789
- source: z$1.ZodString;
1790
- icon: z$1.ZodOptional<z$1.ZodString>;
1791
- hidden: z$1.ZodOptional<z$1.ZodLiteral<false>>;
1792
- }, z$1.core.$strict>, z$1.ZodObject<{
1793
- id: z$1.ZodEnum<{
1794
- state: "state";
1795
- queue: "queue";
1796
- workflow: "workflow";
1797
- database: "database";
1798
- connections: "connections";
1799
- console: "console";
1800
- }>;
1801
- hidden: z$1.ZodLiteral<true>;
1802
- }, z$1.core.$strict>]>>>;
1803
- }, z$1.core.$strict>>;
1804
- }, z$1.core.$strict>;
1805
- type CreateState<TState, _TConnParams, _TConnState, _TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1806
- state: TState;
1807
- } | {
1808
- createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
1809
- } | Record<never, never>;
1810
- type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1811
- connState: TConnState;
1812
- } | {
1813
- createConnState: (c: CreateConnStateContext<TState, TVars, TInput, TDatabase, TEvents, TQueues>, params: TConnParams) => TConnState | Promise<TConnState>;
1814
- } | Record<never, never>;
1815
- /**
1816
- * @experimental
1817
- */
1818
- type CreateVars<TState, _TConnParams, _TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1819
- /**
1820
- * @experimental
1821
- */
1822
- vars: TVars;
1823
- } | {
1824
- /**
1825
- * @experimental
1826
- */
1827
- createVars: (c: CreateVarsContext<TState, TInput, TDatabase, TEvents, TQueues>, driverCtx: any) => TVars | Promise<TVars>;
1828
- } | Record<never, never>;
1829
- interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1830
- [Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, ...args: any[]) => any;
1831
- }
1832
- 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>> {
1833
- /**
1834
- * Called when the actor is first initialized.
1835
- *
1836
- * Use this hook to initialize your actor's state.
1837
- * This is called before any other lifecycle hooks.
1838
- */
1839
- onCreate?: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => void | Promise<void>;
1840
- /**
1841
- * Called when the actor is destroyed.
1842
- */
1843
- onDestroy?: (c: DestroyContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
1844
- /**
1845
- * Called on every actor start after persisted state loads and before onWake.
1846
- *
1847
- * Use this hook for repeatable schema migrations or other startup work that
1848
- * must run on both first boot and wake.
1849
- */
1850
- onMigrate?: (c: MigrateContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, isNew: boolean) => void | Promise<void>;
1851
- /**
1852
- * Called when the actor is started and ready to receive connections and action.
1853
- *
1854
- * Use this hook to initialize resources needed for the actor's operation
1855
- * (timers, external connections, etc.)
1856
- *
1857
- * @returns Void or a Promise that resolves when startup is complete
1858
- */
1859
- onWake?: (c: WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
1860
- /**
1861
- * Called when the actor is stopping or sleeping.
1862
- *
1863
- * Use this hook to clean up resources, save state, or perform
1864
- * any shutdown operations before the actor sleeps or stops.
1865
- *
1866
- * Not supported on all platforms.
1867
- *
1868
- * @returns Void or a Promise that resolves when shutdown is complete
1869
- */
1870
- onSleep?: (c: SleepContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
1871
- /**
1872
- * Called after the actor starts up. Does not block actor startup.
1873
- *
1874
- * Use this for background tasks like:
1875
- * - Reading from queues in a loop
1876
- * - Tick loops for periodic work
1877
- * - Custom workflow logic
1878
- *
1879
- * **Important:** The actor may go to sleep at any time during the `run`
1880
- * handler. Wrap work that must keep the actor awake with
1881
- * `c.keepAwake(promise)` to block idle sleep and shutdown finalize until
1882
- * the promise settles, or use `c.waitUntil(promise)` to let the graceful
1883
- * shutdown window (`sleepGracePeriod`) cover deferred work.
1884
- *
1885
- * The handler receives an abort signal via `c.abortSignal` and a
1886
- * `c.aborted` alias. Use these to gracefully exit when shutdown starts.
1887
- *
1888
- * If this handler exits, the actor will follow the normal idle sleep timeout
1889
- * once it becomes idle.
1890
- * If this handler throws, the actor logs the error and then sleeps once it
1891
- * becomes idle.
1892
- * Call `c.destroy()` explicitly if a run handler should destroy the actor.
1893
- *
1894
- * Can be either a function or a RunConfig object with optional name/icon metadata.
1895
- *
1896
- * @returns Void or a Promise.
1897
- */
1898
- run?: ((c: RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>) | RunConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
1899
- /**
1900
- * Called when the actor's state changes.
1901
- *
1902
- * Use this hook to react to state changes, such as updating
1903
- * external systems or triggering events.
1904
- *
1905
- * State changes made within this hook will NOT trigger
1906
- * another onStateChange call, preventing infinite recursion.
1907
- *
1908
- * @param newState The updated state
1909
- */
1910
- onStateChange?: (c: StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, newState: TState) => void;
1911
- /**
1912
- * Called before a client connects to the actor.
1913
- *
1914
- * Use this hook to determine if a connection should be accepted
1915
- * and to validate client-provided parameters. The pending connection
1916
- * is not visible in `c.conns` while this hook runs.
1917
- *
1918
- * @param opts Connection parameters including client-provided data
1919
- * @returns Void or a Promise.
1920
- * @throws Throw an error to reject the connection
1921
- */
1922
- onBeforeConnect?: (c: BeforeConnectContext<TState, TVars, TInput, TDatabase, TEvents, TQueues>, params: TConnParams) => void | Promise<void>;
1923
- /**
1924
- * Called when a client successfully connects to the actor.
1925
- *
1926
- * Use this hook to perform actions when a connection is established,
1927
- * such as sending initial data or updating the actor's state. The
1928
- * connection is visible in `c.conns` before this hook runs.
1929
- *
1930
- * @param conn The connection object
1931
- * @returns Void or a Promise that resolves when connection handling is complete
1932
- */
1933
- onConnect?: (c: ConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
1934
- /**
1935
- * Called when a client disconnects from the actor.
1936
- *
1937
- * Use this hook to clean up resources associated with the connection
1938
- * or update the actor's state.
1939
- *
1940
- * @param conn The connection that is being closed
1941
- * @returns Void or a Promise that resolves when disconnect handling is complete
1942
- */
1943
- onDisconnect?: (c: DisconnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
1944
- /**
1945
- * Called before sending an action response to the client.
1946
- *
1947
- * Use this hook to modify or transform the output of an action before it's sent
1948
- * to the client. This is useful for formatting responses, adding metadata,
1949
- * or applying transformations to the output.
1950
- *
1951
- * @param name The name of the action that was called
1952
- * @param args The arguments that were passed to the action
1953
- * @param output The output that will be sent to the client
1954
- * @returns The modified output to send to the client
1955
- */
1956
- onBeforeActionResponse?: <Out>(c: BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, name: string, args: unknown[], output: Out) => Out | Promise<Out>;
1957
- /**
1958
- * Called when a raw HTTP request is made to the actor.
1959
- *
1960
- * This handler receives raw HTTP requests made to `/actors/{actorName}/http/*` endpoints.
1961
- * Use this hook to handle custom HTTP patterns, REST APIs, or other HTTP-based protocols.
1962
- *
1963
- * @param c The request context with access to the connection
1964
- * @param request The raw HTTP request object
1965
- * @param opts Additional options
1966
- * @returns A Response object to send back, or void to continue with default routing
1967
- */
1968
- onRequest?: (c: RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, request: Request) => Response | Promise<Response>;
1969
- /**
1970
- * Called when a raw WebSocket connection is established to the actor.
1971
- *
1972
- * This handler receives WebSocket connections made to `/actors/{actorName}/websocket/*` endpoints.
1973
- * Use this hook to handle custom WebSocket protocols, binary streams, or other WebSocket-based communication.
1974
- *
1975
- * @param c The WebSocket context with access to the connection
1976
- * @param websocket The actor-facing raw WebSocket connection
1977
- * @param opts Additional options including the original HTTP upgrade request
1978
- */
1979
- onWebSocket?: (c: WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, websocket: UniversalWebSocket) => void | Promise<void>;
1980
- actions?: TActions;
1981
- /**
1982
- * Optional schema map for validating action argument tuples in native runtimes.
1983
- */
1984
- actionInputSchemas?: Record<string, PrimitiveSchema>;
1985
- /**
1986
- * Optional schema for validating connection params in native runtimes.
1987
- */
1988
- connParamsSchema?: PrimitiveSchema;
1989
- /**
1990
- * Schema map for events broadcasted by this actor.
1991
- */
1992
- events?: TEvents;
1993
- /**
1994
- * Schema map for queue payloads sent by this actor.
1995
- */
1996
- queues?: TQueues;
1997
- }
1998
- type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1999
- /**
2000
- * @experimental
2001
- */
2002
- db: TDatabase;
2003
- } | Record<never, never>;
2004
- type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> = Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> = Omit<z$1.infer<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onMigrate" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, TActions> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
2005
-
2006
- type AgentOsActorState = {};
2007
- interface AgentOsActorVars {
2008
- agentOs: AgentOs | null;
2009
- activeSessionIds: Set<string>;
2010
- activeProcesses: Set<number>;
2011
- activeHooks: Set<Promise<void>>;
2012
- activeShells: Set<string>;
2013
- sessions: Set<string>;
2014
- }
2015
- interface SessionEventPayload {
2016
- sessionId: string;
2017
- event: JsonRpcNotification;
2018
- }
2019
- interface PermissionRequestPayload {
2020
- sessionId: string;
2021
- request: PermissionRequest;
2022
- }
2023
- type VmBootedPayload = Record<string, never>;
2024
- interface VmShutdownPayload {
2025
- reason: "sleep" | "destroy" | "error";
2026
- }
2027
- interface ProcessOutputPayload {
2028
- pid: number;
2029
- stream: "stdout" | "stderr";
2030
- data: Uint8Array;
2031
- }
2032
- interface ProcessExitPayload {
2033
- pid: number;
2034
- exitCode: number;
2035
- }
2036
- interface ShellDataPayload {
2037
- shellId: string;
2038
- data: Uint8Array;
2039
- }
2040
- interface CronEventPayload {
2041
- event: CronEvent;
2042
- }
2043
- interface AgentOsEvents {
2044
- sessionEvent: SessionEventPayload;
2045
- permissionRequest: PermissionRequestPayload;
2046
- vmBooted: VmBootedPayload;
2047
- vmShutdown: VmShutdownPayload;
2048
- processOutput: ProcessOutputPayload;
2049
- processExit: ProcessExitPayload;
2050
- shellData: ShellDataPayload;
2051
- cronEvent: CronEventPayload;
2052
- }
2053
- /** Result from sendPrompt. */
2054
- interface PromptResult {
2055
- /** Raw JSON-RPC response from the ACP adapter. */
2056
- response: JsonRpcResponse;
2057
- /** Accumulated agent text output from streamed message chunks. */
2058
- text: string;
2059
- }
2060
- interface SessionRecord {
2061
- sessionId: string;
2062
- agentType: string;
2063
- capabilities: AgentCapabilities;
2064
- agentInfo: AgentInfo | null;
2065
- }
2066
- interface PersistedSessionRecord {
2067
- sessionId: string;
2068
- agentType: string;
2069
- capabilities: AgentCapabilities;
2070
- agentInfo: AgentInfo | null;
2071
- createdAt: number;
2072
- }
2073
- interface PersistedSessionEvent {
2074
- sessionId: string;
2075
- seq: number;
2076
- event: JsonRpcNotification;
2077
- createdAt: number;
2078
- }
2079
- type SerializableCronAction = {
2080
- type: "session";
2081
- agentType: string;
2082
- prompt: string;
2083
- cwd?: string;
2084
- } | {
2085
- type: "exec";
2086
- command: string;
2087
- args?: string[];
2088
- };
2089
- interface SerializableCronJobOptions {
2090
- id?: string;
2091
- schedule: string;
2092
- action: SerializableCronAction;
2093
- overlap?: "allow" | "skip" | "queue";
2094
- }
2095
- interface SerializableCronJobInfo {
2096
- id: string;
2097
- schedule: string;
2098
- action: SerializableCronAction;
2099
- overlap: "allow" | "skip" | "queue";
2100
- lastRun?: string;
2101
- nextRun?: string;
2102
- runCount: number;
2103
- running: boolean;
2104
- }
2105
- type AgentOsActionContext<TConnParams = undefined> = ActionContext<AgentOsActorState, TConnParams, undefined, AgentOsActorVars, undefined, any>;
2106
-
2107
- declare const agentOsActorConfigSchema: z$1.ZodObject<{
2108
- options: z$1.ZodOptional<z$1.ZodCustom<AgentOsOptions, AgentOsOptions>>;
2109
- preview: z$1.ZodPrefault<z$1.ZodObject<{
2110
- defaultExpiresInSeconds: z$1.ZodDefault<z$1.ZodNumber>;
2111
- maxExpiresInSeconds: z$1.ZodDefault<z$1.ZodNumber>;
2112
- }, z$1.core.$strict>>;
2113
- onBeforeConnect: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
2114
- onSessionEvent: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
2115
- onPermissionRequest: z$1.ZodOptional<z$1.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
2116
- }, z$1.core.$strict>;
2117
- type AgentOsActorContext<TConnParams> = ActorContext<AgentOsActorState, TConnParams, undefined, AgentOsActorVars, undefined, any>;
2118
- interface AgentOsActorConfigCallbacks<TConnParams> {
2119
- onBeforeConnect?: (c: BeforeConnectContext<AgentOsActorState, AgentOsActorVars, undefined, any>, params: TConnParams) => void | Promise<void>;
2120
- onSessionEvent?: (c: AgentOsActorContext<TConnParams>, sessionId: string, event: JsonRpcNotification) => void | Promise<void>;
2121
- onPermissionRequest?: (c: AgentOsActorContext<TConnParams>, sessionId: string, request: PermissionRequest) => void | Promise<void>;
2122
- }
2123
- type AgentOsActorConfig<TConnParams = undefined> = Omit<z$1.infer<typeof agentOsActorConfigSchema>, "onBeforeConnect" | "onSessionEvent" | "onPermissionRequest"> & AgentOsActorConfigCallbacks<TConnParams>;
2124
- type AgentOsActorConfigInput<TConnParams = undefined> = Omit<z$1.input<typeof agentOsActorConfigSchema>, "onBeforeConnect" | "onSessionEvent" | "onPermissionRequest"> & AgentOsActorConfigCallbacks<TConnParams>;
2125
-
2126
- declare function buildCronActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2127
- scheduleCron: (c: AgentOsActionContext<TConnParams>, options: SerializableCronJobOptions) => Promise<{
2128
- id: string;
2129
- }>;
2130
- listCronJobs: (c: AgentOsActionContext<TConnParams>) => Promise<SerializableCronJobInfo[]>;
2131
- cancelCronJob: (c: AgentOsActionContext<TConnParams>, id: string) => Promise<void>;
2132
- };
2133
-
2134
- declare function migrateAgentOsTables(db: RawAccess): Promise<void>;
2135
-
2136
- type VirtualStat = Awaited<ReturnType<_rivet_dev_agent_os_core.AgentOs["stat"]>>;
2137
- type DeleteOptions = Parameters<_rivet_dev_agent_os_core.AgentOs["delete"]>[1];
2138
- declare function buildFilesystemActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2139
- readFile: (c: AgentOsActionContext<TConnParams>, path: string) => Promise<Uint8Array>;
2140
- writeFile: (c: AgentOsActionContext<TConnParams>, path: string, content: string | Uint8Array) => Promise<void>;
2141
- readFiles: (c: AgentOsActionContext<TConnParams>, paths: string[]) => Promise<BatchReadResult[]>;
2142
- writeFiles: (c: AgentOsActionContext<TConnParams>, entries: BatchWriteEntry[]) => Promise<BatchWriteResult[]>;
2143
- mkdir: (c: AgentOsActionContext<TConnParams>, path: string, options?: {
2144
- recursive?: boolean;
2145
- }) => Promise<void>;
2146
- readdir: (c: AgentOsActionContext<TConnParams>, path: string) => Promise<string[]>;
2147
- readdirRecursive: (c: AgentOsActionContext<TConnParams>, path: string, options?: ReaddirRecursiveOptions) => Promise<DirEntry[]>;
2148
- stat: (c: AgentOsActionContext<TConnParams>, path: string) => Promise<VirtualStat>;
2149
- exists: (c: AgentOsActionContext<TConnParams>, path: string) => Promise<boolean>;
2150
- move: (c: AgentOsActionContext<TConnParams>, from: string, to: string) => Promise<void>;
2151
- deleteFile: (c: AgentOsActionContext<TConnParams>, path: string, options?: DeleteOptions) => Promise<void>;
2152
- listAgents: (c: AgentOsActionContext<TConnParams>) => Promise<AgentRegistryEntry[]>;
2153
- };
2154
-
2155
- declare function ensureVm<TConnParams>(c: AgentOsActionContext<TConnParams>, config: AgentOsActorConfig<TConnParams>): Promise<AgentOs>;
2156
- declare function syncPreventSleep<TConnParams>(c: AgentOsActionContext<TConnParams>): void;
2157
- declare function runHook<TConnParams>(c: AgentOsActionContext<TConnParams>, name: string, callback: () => void | Promise<void>): void;
2158
- declare function agentOs<TConnParams = undefined>(config: AgentOsActorConfigInput<TConnParams>): ActorDefinition<AgentOsActorState, TConnParams, undefined, AgentOsActorVars, undefined, DatabaseProvider<RawAccess>, {
2159
- sessionEvent: typeof sessionEventToken;
2160
- permissionRequest: typeof permissionRequestToken;
2161
- vmBooted: typeof vmBootedToken;
2162
- vmShutdown: typeof vmShutdownToken;
2163
- processOutput: typeof processOutputToken;
2164
- processExit: typeof processExitToken;
2165
- shellData: typeof shellDataToken;
2166
- cronEvent: typeof cronEventToken;
2167
- }, Record<never, never>, any>;
2168
- declare const sessionEventToken: EventTypeToken<SessionEventPayload, any>;
2169
- declare const permissionRequestToken: EventTypeToken<PermissionRequestPayload, any>;
2170
- declare const vmBootedToken: EventTypeToken<VmBootedPayload, any>;
2171
- declare const vmShutdownToken: EventTypeToken<VmShutdownPayload, any>;
2172
- declare const processOutputToken: EventTypeToken<ProcessOutputPayload, any>;
2173
- declare const processExitToken: EventTypeToken<ProcessExitPayload, any>;
2174
- declare const shellDataToken: EventTypeToken<ShellDataPayload, any>;
2175
- declare const cronEventToken: EventTypeToken<CronEventPayload, any>;
2176
-
2177
- interface VmFetchOptions {
2178
- method?: string;
2179
- headers?: Record<string, string>;
2180
- body?: string | Uint8Array;
2181
- }
2182
- interface VmFetchResult {
2183
- status: number;
2184
- statusText: string;
2185
- headers: Record<string, string>;
2186
- body: Uint8Array;
2187
- }
2188
- declare function buildNetworkActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2189
- vmFetch: (c: AgentOsActionContext<TConnParams>, port: number, url: string, options?: VmFetchOptions) => Promise<VmFetchResult>;
2190
- };
2191
-
2192
- declare function generateToken(): string;
2193
- type AgentOsRequestContext<TConnParams> = RequestContext<AgentOsActorState, TConnParams, undefined, AgentOsActorVars, undefined, DatabaseProvider<RawAccess>>;
2194
- declare function buildOnRequestHandler<TConnParams>(config: AgentOsActorConfig<TConnParams>): (c: AgentOsRequestContext<TConnParams>, request: Request) => Promise<Response>;
2195
- declare function buildPreviewActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2196
- createSignedPreviewUrl: (c: AgentOsActionContext<TConnParams>, port: number, expiresInSeconds?: number) => Promise<{
2197
- path: string;
2198
- token: string;
2199
- port: number;
2200
- expiresAt: number;
2201
- }>;
2202
- expireSignedPreviewUrl: (c: AgentOsActionContext<TConnParams>, token: string) => Promise<void>;
2203
- };
2204
-
2205
- type ExecResult = Awaited<ReturnType<_rivet_dev_agent_os_core.AgentOs["exec"]>>;
2206
- type ExecOptions = Parameters<_rivet_dev_agent_os_core.AgentOs["exec"]>[1];
2207
- type SpawnOptions = Parameters<_rivet_dev_agent_os_core.AgentOs["spawn"]>[2];
2208
- declare function buildProcessActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2209
- exec: (c: AgentOsActionContext<TConnParams>, command: string, options?: ExecOptions) => Promise<ExecResult>;
2210
- spawn: (c: AgentOsActionContext<TConnParams>, command: string, args: string[], options?: SpawnOptions) => Promise<{
2211
- pid: number;
2212
- }>;
2213
- writeProcessStdin: (c: AgentOsActionContext<TConnParams>, pid: number, data: string | Uint8Array) => Promise<void>;
2214
- closeProcessStdin: (c: AgentOsActionContext<TConnParams>, pid: number) => Promise<void>;
2215
- waitProcess: (c: AgentOsActionContext<TConnParams>, pid: number) => Promise<number>;
2216
- listProcesses: (c: AgentOsActionContext<TConnParams>) => Promise<SpawnedProcessInfo[]>;
2217
- allProcesses: (c: AgentOsActionContext<TConnParams>) => Promise<ProcessInfo[]>;
2218
- processTree: (c: AgentOsActionContext<TConnParams>) => Promise<ProcessTreeNode[]>;
2219
- getProcess: (c: AgentOsActionContext<TConnParams>, pid: number) => Promise<SpawnedProcessInfo>;
2220
- stopProcess: (c: AgentOsActionContext<TConnParams>, pid: number) => Promise<void>;
2221
- killProcess: (c: AgentOsActionContext<TConnParams>, pid: number) => Promise<void>;
2222
- };
2223
-
2224
- declare function subscribeToSession<TConnParams>(c: AgentOsActionContext<TConnParams>, agentOs: AgentOs, sessionId: string, parsedConfig: AgentOsActorConfig<TConnParams>): void;
2225
- declare function buildSessionActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2226
- createSession: (c: AgentOsActionContext<TConnParams>, agentType: AgentType, options?: CreateSessionOptions) => Promise<SessionRecord>;
2227
- listSessions: (c: AgentOsActionContext<TConnParams>) => Promise<SessionInfo[]>;
2228
- getSession: (c: AgentOsActionContext<TConnParams>, sessionId: string) => Promise<SessionRecord>;
2229
- destroySession: (c: AgentOsActionContext<TConnParams>, sessionId: string) => Promise<void>;
2230
- resumeSession: (c: AgentOsActionContext<TConnParams>, sessionId: string) => Promise<{
2231
- sessionId: string;
2232
- }>;
2233
- closeSession: (c: AgentOsActionContext<TConnParams>, sessionId: string) => Promise<void>;
2234
- };
2235
- declare function buildPromptActions<TConnParams>(_config: AgentOsActorConfig<TConnParams>): {
2236
- sendPrompt: (c: AgentOsActionContext<TConnParams>, sessionId: string, text: string) => Promise<PromptResult>;
2237
- cancelPrompt: (c: AgentOsActionContext<TConnParams>, sessionId: string) => Promise<JsonRpcResponse>;
2238
- respondPermission: (c: AgentOsActionContext<TConnParams>, sessionId: string, permissionId: string, reply: PermissionReply) => Promise<JsonRpcResponse>;
2239
- };
2240
- declare function buildConfigActions<TConnParams>(_config: AgentOsActorConfig<TConnParams>): {
2241
- setMode: (c: AgentOsActionContext<TConnParams>, sessionId: string, modeId: string) => Promise<JsonRpcResponse>;
2242
- getModes: (c: AgentOsActionContext<TConnParams>, sessionId: string) => Promise<SessionModeState | null>;
2243
- setModel: (c: AgentOsActionContext<TConnParams>, sessionId: string, model: string) => Promise<JsonRpcResponse>;
2244
- setThoughtLevel: (c: AgentOsActionContext<TConnParams>, sessionId: string, level: string) => Promise<JsonRpcResponse>;
2245
- getConfigOptions: (c: AgentOsActionContext<TConnParams>, sessionId: string) => Promise<SessionConfigOption[]>;
2246
- getEvents: (c: AgentOsActionContext<TConnParams>, sessionId: string, options?: GetEventsOptions) => Promise<JsonRpcNotification[]>;
2247
- getSequencedEvents: (c: AgentOsActionContext<TConnParams>, sessionId: string, options?: GetEventsOptions) => Promise<SequencedEvent[]>;
2248
- rawSend: (c: AgentOsActionContext<TConnParams>, sessionId: string, method: string, params?: Record<string, unknown>) => Promise<JsonRpcResponse>;
2249
- };
2250
- declare function buildSessionPersistenceActions<TConnParams>(_config: AgentOsActorConfig<TConnParams>): {
2251
- listPersistedSessions: (c: AgentOsActionContext<TConnParams>) => Promise<PersistedSessionRecord[]>;
2252
- getSessionEvents: (c: AgentOsActionContext<TConnParams>, sessionId: string) => Promise<PersistedSessionEvent[]>;
2253
- };
2254
-
2255
- declare function buildShellActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2256
- openShell: (c: AgentOsActionContext<TConnParams>, options?: OpenShellOptions) => Promise<{
2257
- shellId: string;
2258
- }>;
2259
- writeShell: (c: AgentOsActionContext<TConnParams>, shellId: string, data: string | Uint8Array) => Promise<void>;
2260
- resizeShell: (c: AgentOsActionContext<TConnParams>, shellId: string, cols: number, rows: number) => Promise<void>;
2261
- closeShell: (c: AgentOsActionContext<TConnParams>, shellId: string) => Promise<void>;
2262
- };
2263
-
2264
- type VirtualFileSystem = _rivet_dev_agent_os_core.PlainMountConfig["driver"];
2265
- interface DatabaseVfsOptions {
2266
- /** The RawAccess database handle from the actor's db provider. */
2267
- db: RawAccess;
2268
- }
2269
- /**
2270
- * Create a VirtualFileSystem backed by SQLite.
2271
- *
2272
- * The returned filesystem stores all content and metadata in the
2273
- * `agent_os_fs_entries` table. The table must be created beforehand
2274
- * via `migrateAgentOsTables()`.
2275
- */
2276
- declare function createDatabaseVfs(options: DatabaseVfsOptions): VirtualFileSystem;
2277
-
2278
- export { type AgentOsActionContext, type AgentOsActorConfig, type AgentOsActorConfigInput, type AgentOsActorState, type AgentOsActorVars, type AgentOsEvents, type CronEventPayload, type DatabaseVfsOptions, type PermissionRequestPayload, type PersistedSessionEvent, type PersistedSessionRecord, type ProcessExitPayload, type ProcessOutputPayload, type PromptResult, type SerializableCronAction, type SerializableCronJobOptions, type SessionEventPayload, type SessionRecord, type ShellDataPayload, type VmBootedPayload, type VmFetchOptions, type VmFetchResult, type VmShutdownPayload, agentOs, agentOsActorConfigSchema, buildConfigActions, buildCronActions, buildFilesystemActions, buildNetworkActions, buildOnRequestHandler, buildPreviewActions, buildProcessActions, buildPromptActions, buildSessionActions, buildSessionPersistenceActions, buildShellActions, createDatabaseVfs, ensureVm, generateToken, migrateAgentOsTables, runHook, subscribeToSession, syncPreventSleep };
2
+ export { }