rivetkit 2.3.0-rc.9 → 2.3.0

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 (222) hide show
  1. package/dist/browser/client.d.ts +498 -62
  2. package/dist/browser/client.js +227 -171
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +50 -20
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +2 -2
  7. package/dist/tsup/actor/errors.d.cts +1 -1
  8. package/dist/tsup/actor/errors.d.ts +1 -1
  9. package/dist/tsup/actor/errors.js +1 -1
  10. package/dist/tsup/agent-os/index.cjs +2163 -2087
  11. package/dist/tsup/agent-os/index.cjs.map +1 -1
  12. package/dist/tsup/agent-os/index.d.cts +496 -69
  13. package/dist/tsup/agent-os/index.d.ts +496 -69
  14. package/dist/tsup/agent-os/index.js +2163 -2087
  15. package/dist/tsup/agent-os/index.js.map +1 -1
  16. package/dist/tsup/{chunk-W7EYSYVI.js → chunk-2OTRTA3J.js} +134 -20
  17. package/dist/tsup/chunk-2OTRTA3J.js.map +1 -0
  18. package/dist/tsup/{chunk-VJFRBJVQ.cjs → chunk-3677IIOV.cjs} +138 -24
  19. package/dist/tsup/chunk-3677IIOV.cjs.map +1 -0
  20. package/dist/tsup/{chunk-4CGA6QJO.cjs → chunk-47HHIEXH.cjs} +24 -9
  21. package/dist/tsup/chunk-47HHIEXH.cjs.map +1 -0
  22. package/dist/tsup/{chunk-F3Q5BFQ6.js → chunk-4JDSFJS5.js} +66 -79
  23. package/dist/tsup/chunk-4JDSFJS5.js.map +1 -0
  24. package/dist/tsup/{chunk-GVTOE34S.cjs → chunk-7QKCIVAY.cjs} +222 -235
  25. package/dist/tsup/chunk-7QKCIVAY.cjs.map +1 -0
  26. package/dist/tsup/{chunk-CPA4Y3RG.cjs → chunk-B6VUNZUD.cjs} +10 -10
  27. package/dist/tsup/chunk-B6VUNZUD.cjs.map +1 -0
  28. package/dist/tsup/{chunk-H37XQU3I.js → chunk-BEI24WTI.js} +2 -2
  29. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-BRP62GZC.js} +3 -3
  30. package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
  31. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-DPIMKYNB.js} +63 -2
  32. package/dist/tsup/chunk-DPIMKYNB.js.map +1 -0
  33. package/dist/tsup/{chunk-Y5NSCZA2.cjs → chunk-DXXJPH55.cjs} +44 -15
  34. package/dist/tsup/chunk-DXXJPH55.cjs.map +1 -0
  35. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  36. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  37. package/dist/tsup/{chunk-4WPEZBK4.cjs → chunk-I4LN3FNT.cjs} +10 -10
  38. package/dist/tsup/chunk-I4LN3FNT.cjs.map +1 -0
  39. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  40. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  41. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-KORQB2IR.cjs} +3 -3
  42. package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
  43. package/dist/tsup/{chunk-MALSPBAF.cjs → chunk-LVTBW2RE.cjs} +3 -3
  44. package/dist/tsup/{chunk-MALSPBAF.cjs.map → chunk-LVTBW2RE.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-H7P7WR2Y.js → chunk-MEHBWPLJ.js} +6 -6
  46. package/dist/tsup/chunk-MEHBWPLJ.js.map +1 -0
  47. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-NIY3RSPX.cjs} +64 -3
  48. package/dist/tsup/chunk-NIY3RSPX.cjs.map +1 -0
  49. package/dist/tsup/{chunk-MMMEZM5J.js → chunk-P2GNQ4RN.js} +4 -4
  50. package/dist/tsup/chunk-P2GNQ4RN.js.map +1 -0
  51. package/dist/tsup/{chunk-KJTA3ATT.js → chunk-UMZVD6DQ.js} +22 -7
  52. package/dist/tsup/chunk-UMZVD6DQ.js.map +1 -0
  53. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  54. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  55. package/dist/tsup/{chunk-VRCIXJRN.js → chunk-VTTFNQQI.js} +36 -7
  56. package/dist/tsup/chunk-VTTFNQQI.js.map +1 -0
  57. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  58. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  59. package/dist/tsup/client/mod.cjs +9 -9
  60. package/dist/tsup/client/mod.d.cts +5 -5
  61. package/dist/tsup/client/mod.d.ts +5 -5
  62. package/dist/tsup/client/mod.js +8 -8
  63. package/dist/tsup/common/log.cjs +3 -3
  64. package/dist/tsup/common/log.js +2 -2
  65. package/dist/tsup/common/websocket.cjs +4 -4
  66. package/dist/tsup/common/websocket.js +3 -3
  67. package/dist/tsup/{config-0Ta55UV0.d.ts → config-BxWAw3iH.d.ts} +529 -23
  68. package/dist/tsup/{config-Ca8dN4cS.d.cts → config-CZQQ-mso.d.cts} +529 -23
  69. package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.cts} +1 -2
  70. package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.ts} +1 -2
  71. package/dist/tsup/{context-B_IWbWne.d.ts → context-Bw7xq8w3.d.cts} +8 -8
  72. package/dist/tsup/{context-CUrQ9MHc.d.cts → context-D8QA76sV.d.ts} +8 -8
  73. package/dist/tsup/db/drizzle.cjs +3 -3
  74. package/dist/tsup/db/drizzle.d.cts +1 -1
  75. package/dist/tsup/db/drizzle.d.ts +1 -1
  76. package/dist/tsup/db/drizzle.js +1 -1
  77. package/dist/tsup/db/mod.cjs +2 -2
  78. package/dist/tsup/db/mod.d.cts +2 -2
  79. package/dist/tsup/db/mod.d.ts +2 -2
  80. package/dist/tsup/db/mod.js +1 -1
  81. package/dist/tsup/dynamic/mod.cjs +24 -0
  82. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  83. package/dist/tsup/dynamic/mod.d.cts +37 -0
  84. package/dist/tsup/dynamic/mod.d.ts +37 -0
  85. package/dist/tsup/dynamic/mod.js +24 -0
  86. package/dist/tsup/dynamic/mod.js.map +1 -0
  87. package/dist/tsup/inspector/mod.cjs +6 -6
  88. package/dist/tsup/inspector/mod.js +5 -5
  89. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  90. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  91. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  92. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  93. package/dist/tsup/inspector-tab/mod.js +173 -0
  94. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  95. package/dist/tsup/mod.cjs +730 -336
  96. package/dist/tsup/mod.cjs.map +1 -1
  97. package/dist/tsup/mod.d.cts +5 -5
  98. package/dist/tsup/mod.d.ts +5 -5
  99. package/dist/tsup/mod.js +633 -239
  100. package/dist/tsup/mod.js.map +1 -1
  101. package/dist/tsup/test/mod.cjs +21 -18
  102. package/dist/tsup/test/mod.cjs.map +1 -1
  103. package/dist/tsup/test/mod.d.cts +4 -4
  104. package/dist/tsup/test/mod.d.ts +4 -4
  105. package/dist/tsup/test/mod.js +18 -15
  106. package/dist/tsup/test/mod.js.map +1 -1
  107. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-DQosb24I.d.cts} +1 -1
  108. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-DQosb24I.d.ts} +1 -1
  109. package/dist/tsup/utils.cjs +3 -3
  110. package/dist/tsup/utils.d.cts +1 -1
  111. package/dist/tsup/utils.d.ts +1 -1
  112. package/dist/tsup/utils.js +2 -2
  113. package/dist/tsup/workflow/mod.cjs +307 -282
  114. package/dist/tsup/workflow/mod.cjs.map +1 -1
  115. package/dist/tsup/workflow/mod.d.cts +6 -6
  116. package/dist/tsup/workflow/mod.d.ts +6 -6
  117. package/dist/tsup/workflow/mod.js +501 -476
  118. package/dist/tsup/workflow/mod.js.map +1 -1
  119. package/package.json +32 -11
  120. package/src/actor/config.ts +159 -51
  121. package/src/actor/contexts/index.ts +7 -2
  122. package/src/actor/definition.ts +17 -19
  123. package/src/actor/driver.ts +3 -3
  124. package/src/actor/errors.ts +9 -3
  125. package/src/actor/instance/mod.ts +26 -34
  126. package/src/actor/keys.ts +1 -1
  127. package/src/actor/mod.ts +22 -20
  128. package/src/actor/schema.ts +2 -2
  129. package/src/agent-os/actor/index.ts +38 -18
  130. package/src/agent-os/actor/preview.ts +1 -2
  131. package/src/agent-os/actor/session.ts +2 -2
  132. package/src/agent-os/config.ts +1 -1
  133. package/src/agent-os/fs/database-vfs.ts +1 -1
  134. package/src/agent-os/index.ts +16 -15
  135. package/src/client/actor-common.ts +87 -54
  136. package/src/client/actor-conn.ts +8 -36
  137. package/src/client/actor-handle.ts +69 -51
  138. package/src/client/actor-query.ts +5 -5
  139. package/src/client/errors.ts +1 -1
  140. package/src/client/lifecycle-errors.ts +2 -4
  141. package/src/client/query.ts +1 -1
  142. package/src/client/queue.ts +8 -3
  143. package/src/client/raw-utils.ts +8 -6
  144. package/src/client/resolve-gateway-target.ts +1 -1
  145. package/src/client/utils.ts +2 -7
  146. package/src/common/actor-websocket.ts +3 -1
  147. package/src/common/bare/actor-persist/v1.ts +205 -163
  148. package/src/common/bare/actor-persist/v2.ts +265 -213
  149. package/src/common/bare/actor-persist/v3.ts +176 -172
  150. package/src/common/bare/actor-persist/v4.ts +254 -253
  151. package/src/common/bare/transport/v1.ts +659 -543
  152. package/src/common/client-protocol-versioned.ts +66 -64
  153. package/src/common/database/config.ts +2 -8
  154. package/src/common/database/native-database.ts +1 -1
  155. package/src/common/database/shared.ts +1 -0
  156. package/src/common/encoding.ts +250 -16
  157. package/src/common/engine.ts +28 -1
  158. package/src/common/eventsource.ts +1 -1
  159. package/src/common/inline-websocket-adapter.ts +14 -13
  160. package/src/common/log.ts +1 -0
  161. package/src/common/router.ts +13 -17
  162. package/src/common/utils.ts +1 -150
  163. package/src/common/websocket-interface.ts +1 -1
  164. package/src/db/mod.ts +1 -1
  165. package/src/devtools-loader/index.ts +4 -7
  166. package/src/devtools-loader/serve-devtools.ts +26 -0
  167. package/src/drivers/engine/actor-driver.ts +58 -56
  168. package/src/dynamic/instance.ts +32 -0
  169. package/src/dynamic/internal.ts +50 -0
  170. package/src/dynamic/isolate-runtime.ts +66 -0
  171. package/src/dynamic/mod.ts +32 -0
  172. package/src/engine-client/actor-http-client.ts +3 -3
  173. package/src/engine-client/actor-websocket-client.ts +6 -5
  174. package/src/engine-client/api-endpoints.ts +51 -2
  175. package/src/engine-client/api-utils.ts +2 -2
  176. package/src/engine-client/driver.ts +1 -1
  177. package/src/engine-client/mod.ts +6 -3
  178. package/src/engine-client/ws-proxy.ts +9 -4
  179. package/src/inspector/client.browser.ts +5 -11
  180. package/src/inspector/mod.ts +1 -3
  181. package/src/inspector-tab/mod.ts +315 -0
  182. package/src/registry/config/envoy.ts +1 -2
  183. package/src/registry/config/index.ts +40 -16
  184. package/src/registry/index.ts +154 -74
  185. package/src/registry/napi-runtime.ts +13 -2
  186. package/src/registry/native-validation.ts +10 -12
  187. package/src/registry/native.ts +367 -181
  188. package/src/registry/process-metrics.ts +250 -0
  189. package/src/registry/runtime.ts +41 -1
  190. package/src/registry/wasm-runtime.ts +18 -2
  191. package/src/registry/write-through-proxy.ts +40 -0
  192. package/src/serde.ts +2 -2
  193. package/src/serverless/configure.ts +18 -7
  194. package/src/test/mod.ts +11 -8
  195. package/src/utils/endpoint-parser.ts +1 -1
  196. package/src/utils/env-vars.ts +6 -0
  197. package/src/utils/router.ts +1 -1
  198. package/src/utils/serve.ts +4 -5
  199. package/src/utils.ts +1 -2
  200. package/src/workflow/context.ts +61 -33
  201. package/src/workflow/driver.ts +4 -6
  202. package/src/workflow/inspector.ts +4 -3
  203. package/src/workflow/mod.ts +15 -17
  204. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  205. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  206. package/dist/tsup/chunk-4CGA6QJO.cjs.map +0 -1
  207. package/dist/tsup/chunk-4WPEZBK4.cjs.map +0 -1
  208. package/dist/tsup/chunk-CPA4Y3RG.cjs.map +0 -1
  209. package/dist/tsup/chunk-F3Q5BFQ6.js.map +0 -1
  210. package/dist/tsup/chunk-GVTOE34S.cjs.map +0 -1
  211. package/dist/tsup/chunk-H7P7WR2Y.js.map +0 -1
  212. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  213. package/dist/tsup/chunk-KJTA3ATT.js.map +0 -1
  214. package/dist/tsup/chunk-MMMEZM5J.js.map +0 -1
  215. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  216. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  217. package/dist/tsup/chunk-VJFRBJVQ.cjs.map +0 -1
  218. package/dist/tsup/chunk-VRCIXJRN.js.map +0 -1
  219. package/dist/tsup/chunk-W7EYSYVI.js.map +0 -1
  220. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  221. package/dist/tsup/chunk-Y5NSCZA2.cjs.map +0 -1
  222. /package/dist/tsup/{chunk-H37XQU3I.js.map → chunk-BEI24WTI.js.map} +0 -0
@@ -1,9 +1,9 @@
1
1
  import * as _rivet_dev_agent_os_core from '@rivet-dev/agent-os-core';
2
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
3
  import { z as z$1 } from 'zod/v4';
4
- import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
5
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
5
  import { Context, Handler, Hono } from 'hono';
6
+ import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
7
7
  import * as _rivetkit_rivetkit_wasm from '@rivetkit/rivetkit-wasm';
8
8
  import { z } from 'zod';
9
9
  import { Logger } from 'pino';
@@ -105,8 +105,7 @@ type DatabaseProvider<DB extends RawAccess> = {
105
105
  /**
106
106
  * Drizzle database client interface (will be extended by drizzle-orm types)
107
107
  */
108
- interface DrizzleDatabaseClient {
109
- }
108
+ type DrizzleDatabaseClient = {};
110
109
  type ExecuteFunction = <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]>;
111
110
  type RawAccess = {
112
111
  /**
@@ -123,23 +122,7 @@ type RawAccess = {
123
122
  close: () => Promise<void>;
124
123
  };
125
124
 
126
- declare function migrateAgentOsTables(db: RawAccess): Promise<void>;
127
-
128
- type VirtualFileSystem = _rivet_dev_agent_os_core.PlainMountConfig["driver"];
129
- interface DatabaseVfsOptions {
130
- /** The RawAccess database handle from the actor's db provider. */
131
- db: RawAccess;
132
- }
133
- /**
134
- * Create a VirtualFileSystem backed by SQLite.
135
- *
136
- * The returned filesystem stores all content and metadata in the
137
- * `agent_os_fs_entries` table. The table must be created beforehand
138
- * via `migrateAgentOsTables()`.
139
- */
140
- declare function createDatabaseVfs(options: DatabaseVfsOptions): VirtualFileSystem;
141
-
142
- declare const ActorsSchema: z.ZodRecord<z.ZodString, z.ZodCustom<BaseActorDefinition<any, any, any, any, any, any, any, any, any>, BaseActorDefinition<any, any, any, any, any, any, any, any, any>>>;
125
+ declare const ActorsSchema: z.ZodRecord<z.ZodString, z.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
143
126
  type RegistryActors = z.infer<typeof ActorsSchema>;
144
127
  declare const RegistryConfigSchema: z.ZodPipe<z.ZodObject<{
145
128
  use: z.ZodRecord<z.ZodString, z.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
@@ -196,6 +179,8 @@ declare const RegistryConfigSchema: z.ZodPipe<z.ZodObject<{
196
179
  httpPort: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
197
180
  httpHost: z.ZodOptional<z.ZodString>;
198
181
  startEngine: z.ZodDefault<z.ZodBoolean>;
182
+ engineHost: z.ZodDefault<z.ZodOptional<z.ZodString>>;
183
+ enginePort: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
199
184
  engineVersion: z.ZodDefault<z.ZodOptional<z.ZodString>>;
200
185
  configurePool: z.ZodOptional<z.ZodOptional<z.ZodObject<{
201
186
  name: z.ZodOptional<z.ZodString>;
@@ -261,6 +246,8 @@ declare const RegistryConfigSchema: z.ZodPipe<z.ZodObject<{
261
246
  httpBasePath: string;
262
247
  httpPort: number;
263
248
  startEngine: boolean;
249
+ engineHost: string;
250
+ enginePort: number;
264
251
  engineVersion: string;
265
252
  envoy: {
266
253
  poolName: string;
@@ -312,6 +299,8 @@ declare const RegistryConfigSchema: z.ZodPipe<z.ZodObject<{
312
299
  httpBasePath: string;
313
300
  httpPort: number;
314
301
  startEngine: boolean;
302
+ engineHost: string;
303
+ enginePort: number;
315
304
  engineVersion: string;
316
305
  serverless: {
317
306
  basePath: string;
@@ -374,7 +363,7 @@ interface QueueSchemaDefinition<TContext = any> {
374
363
  type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
375
364
  type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
376
365
  type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
377
- type QueueSchemaConfig<TContext = any> = Record<string, QueueSchema>;
366
+ type QueueSchemaConfig<_TContext = any> = Record<string, QueueSchema>;
378
367
  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;
379
368
  type InferSchemaMap<T extends Record<string, unknown>> = {
380
369
  [K in keyof T]: InferSchema<T[K]>;
@@ -385,14 +374,16 @@ type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
385
374
  };
386
375
  type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
387
376
 
388
- 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>> {
389
- readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q>;
377
+ 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>> {
378
+ readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
379
+ }
380
+ interface AnyActorDefinition {
381
+ readonly config: any;
390
382
  }
391
- type AnyActorDefinition = BaseActorDefinition<any, any, any, any, any, any, any, any, any>;
392
383
  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> {
393
384
  #private;
394
- constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
395
- get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
385
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>);
386
+ get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
396
387
  }
397
388
 
398
389
  declare const EncodingSchema: z$1.ZodEnum<{
@@ -569,6 +560,335 @@ interface ActorOutput {
569
560
  error?: unknown;
570
561
  }
571
562
 
563
+ declare const handleBrand: unique symbol;
564
+ type OpaqueHandle<Name extends string> = {
565
+ readonly [handleBrand]: Name;
566
+ };
567
+ type RegistryHandle = OpaqueHandle<"registry">;
568
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
569
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
570
+ type ConnHandle = OpaqueHandle<"conn">;
571
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
572
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
573
+ type RuntimeBytes = Uint8Array;
574
+ interface RuntimeActorKeySegment {
575
+ kind: string;
576
+ stringValue?: string;
577
+ numberValue?: number;
578
+ }
579
+ interface RuntimeHttpRequest {
580
+ method: string;
581
+ uri: string;
582
+ headers?: Record<string, string>;
583
+ body?: RuntimeBytes;
584
+ }
585
+ interface RuntimeStateDeltaPayload {
586
+ state?: RuntimeBytes;
587
+ connHibernation: Array<{
588
+ connId: string;
589
+ bytes: RuntimeBytes;
590
+ }>;
591
+ connHibernationRemoved: string[];
592
+ }
593
+ interface RuntimeRequestSaveOpts {
594
+ immediate?: boolean;
595
+ maxWaitMs?: number;
596
+ }
597
+ interface RuntimeInspectorSnapshot {
598
+ stateRevision: number;
599
+ connectionsRevision: number;
600
+ queueRevision: number;
601
+ activeConnections: number;
602
+ queueSize: number;
603
+ connectedClients: number;
604
+ }
605
+ interface RuntimeQueueMessage {
606
+ id(): bigint;
607
+ name(): string;
608
+ body(): RuntimeBytes;
609
+ createdAt(): number;
610
+ isCompletable(): boolean;
611
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
612
+ }
613
+ interface RuntimeQueueInspectMessage {
614
+ id: number;
615
+ name: string;
616
+ createdAtMs: number;
617
+ }
618
+ interface RuntimeQueueNextBatchOptions {
619
+ names?: string[];
620
+ count?: number;
621
+ timeoutMs?: number;
622
+ completable?: boolean;
623
+ }
624
+ interface RuntimeQueueWaitOptions {
625
+ timeoutMs?: number;
626
+ completable?: boolean;
627
+ }
628
+ interface RuntimeQueueEnqueueAndWaitOptions {
629
+ timeoutMs?: number;
630
+ }
631
+ interface RuntimeQueueTryNextBatchOptions {
632
+ names?: string[];
633
+ count?: number;
634
+ completable?: boolean;
635
+ }
636
+ interface RuntimeKvListOptions {
637
+ reverse?: boolean;
638
+ limit?: number;
639
+ }
640
+ interface RuntimeKvEntry {
641
+ key: RuntimeBytes;
642
+ value: RuntimeBytes;
643
+ }
644
+ type RuntimeSqlBindNoValues = {
645
+ intValue?: never;
646
+ floatValue?: never;
647
+ textValue?: never;
648
+ blobValue?: never;
649
+ };
650
+ type RuntimeSqlBindParam = ({
651
+ kind: "null";
652
+ } & RuntimeSqlBindNoValues) | {
653
+ kind: "int";
654
+ intValue: number;
655
+ floatValue?: never;
656
+ textValue?: never;
657
+ blobValue?: never;
658
+ } | {
659
+ kind: "float";
660
+ intValue?: never;
661
+ floatValue: number;
662
+ textValue?: never;
663
+ blobValue?: never;
664
+ } | {
665
+ kind: "text";
666
+ intValue?: never;
667
+ floatValue?: never;
668
+ textValue: string;
669
+ blobValue?: never;
670
+ } | {
671
+ kind: "blob";
672
+ intValue?: never;
673
+ floatValue?: never;
674
+ textValue?: never;
675
+ blobValue: RuntimeBytes;
676
+ };
677
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
678
+ interface RuntimeSqlQueryResult {
679
+ columns: string[];
680
+ rows: unknown[][];
681
+ }
682
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
683
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
684
+ changes: number;
685
+ lastInsertRowId?: number | null;
686
+ }
687
+ interface RuntimeSqlRunResult {
688
+ changes: number;
689
+ }
690
+ interface RuntimeActorConfig {
691
+ name?: string;
692
+ icon?: string;
693
+ hasDatabase?: boolean;
694
+ remoteSqlite?: boolean;
695
+ hasState?: boolean;
696
+ canHibernateWebsocket?: boolean;
697
+ stateSaveIntervalMs?: number;
698
+ createStateTimeoutMs?: number;
699
+ onCreateTimeoutMs?: number;
700
+ createVarsTimeoutMs?: number;
701
+ createConnStateTimeoutMs?: number;
702
+ onBeforeConnectTimeoutMs?: number;
703
+ onConnectTimeoutMs?: number;
704
+ onMigrateTimeoutMs?: number;
705
+ onWakeTimeoutMs?: number;
706
+ onBeforeActorStartTimeoutMs?: number;
707
+ actionTimeoutMs?: number;
708
+ onRequestTimeoutMs?: number;
709
+ sleepTimeoutMs?: number;
710
+ noSleep?: boolean;
711
+ sleepGracePeriodMs?: number;
712
+ connectionLivenessTimeoutMs?: number;
713
+ connectionLivenessIntervalMs?: number;
714
+ maxQueueSize?: number;
715
+ maxQueueMessageSize?: number;
716
+ maxIncomingMessageSize?: number;
717
+ maxOutgoingMessageSize?: number;
718
+ preloadMaxWorkflowBytes?: number;
719
+ preloadMaxConnectionsBytes?: number;
720
+ actions?: Array<{
721
+ name: string;
722
+ }>;
723
+ inspectorTabs?: Array<RuntimeInspectorTabEntry>;
724
+ }
725
+ interface RuntimeInspectorTabEntry {
726
+ id: string;
727
+ /** Required for custom entries; omitted for built-in hides. */
728
+ label?: string;
729
+ /**
730
+ * Required for custom entries — absolute path to the source directory.
731
+ * Resolved on the TS side before being handed to the runtime.
732
+ */
733
+ source?: string;
734
+ /** Optional icon id for custom entries. */
735
+ icon?: string;
736
+ /** Set to true for built-in hide entries. */
737
+ hidden?: boolean;
738
+ }
739
+ interface RuntimeServeConfig {
740
+ version: number;
741
+ endpoint: string;
742
+ token?: string;
743
+ namespace: string;
744
+ poolName: string;
745
+ engineBinaryPath?: string;
746
+ engineHost?: string;
747
+ enginePort?: number;
748
+ handleInspectorHttpInRuntime?: boolean;
749
+ inspectorTestToken?: string;
750
+ serverlessBasePath?: string;
751
+ serverlessPackageVersion: string;
752
+ serverlessClientEndpoint?: string;
753
+ serverlessClientNamespace?: string;
754
+ serverlessClientToken?: string;
755
+ serverlessValidateEndpoint: boolean;
756
+ serverlessMaxStartPayloadBytes: number;
757
+ }
758
+ interface RuntimeServerlessRequest {
759
+ method: string;
760
+ url: string;
761
+ headers: Record<string, string>;
762
+ body: RuntimeBytes;
763
+ }
764
+ interface RuntimeServerlessResponseHead {
765
+ status: number;
766
+ headers: Record<string, string>;
767
+ }
768
+ interface RuntimeRegistryRouteResponse {
769
+ status: number;
770
+ headers: Record<string, string>;
771
+ body: RuntimeBytes;
772
+ }
773
+ type RuntimeServerlessStreamEvent = {
774
+ kind: "chunk";
775
+ chunk?: RuntimeBytes;
776
+ } | {
777
+ kind: "end";
778
+ error?: {
779
+ group: string;
780
+ code: string;
781
+ message: string;
782
+ };
783
+ };
784
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
785
+ type RuntimeWebSocketEvent = {
786
+ kind: "message";
787
+ data: string | RuntimeBytes;
788
+ binary: boolean;
789
+ messageIndex?: number;
790
+ } | {
791
+ kind: "close";
792
+ code: number;
793
+ reason: string;
794
+ wasClean: boolean;
795
+ };
796
+ interface CoreRuntime {
797
+ readonly kind: "napi" | "wasm";
798
+ createRegistry(): RegistryHandle;
799
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
800
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
801
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
802
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
803
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
804
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
805
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
806
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
807
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
808
+ createCancellationToken(): CancellationTokenHandle;
809
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
810
+ cancelCancellationToken(token: CancellationTokenHandle): void;
811
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
812
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
813
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
814
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
815
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
816
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
817
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
818
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
819
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
820
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
821
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
822
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
823
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
824
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
825
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
826
+ actorId(ctx: ActorContextHandle): string;
827
+ actorName(ctx: ActorContextHandle): string;
828
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
829
+ actorRegion(ctx: ActorContextHandle): string;
830
+ actorSleep(ctx: ActorContextHandle): void;
831
+ actorDestroy(ctx: ActorContextHandle): void;
832
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
833
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
834
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
835
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
836
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
837
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
838
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
839
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
840
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
841
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
842
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
843
+ actorRuntimeState(ctx: ActorContextHandle): object;
844
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
845
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
846
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
847
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
848
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
849
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
850
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
851
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
852
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
853
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
854
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
855
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
856
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
857
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
858
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
859
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
860
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
861
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
862
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
863
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
864
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
865
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
866
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
867
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
868
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
869
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
870
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
871
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
872
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
873
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
874
+ connId(conn: ConnHandle): string;
875
+ connParams(conn: ConnHandle): RuntimeBytes;
876
+ connState(conn: ConnHandle): RuntimeBytes;
877
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
878
+ connIsHibernatable(conn: ConnHandle): boolean;
879
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
880
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
881
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
882
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
883
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
884
+ }
885
+
886
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
887
+ runtime: CoreRuntime;
888
+ registry: RegistryHandle;
889
+ serveConfig: RuntimeServeConfig;
890
+ }>;
891
+
572
892
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
573
893
  interface ServerlessHandler {
574
894
  fetch: FetchHandler;
@@ -578,12 +898,20 @@ interface RegistryRoutes {
578
898
  metadata(): Promise<Response>;
579
899
  prometheusMetrics(request?: Request): Promise<Response>;
580
900
  }
901
+ /**
902
+ * Injectable dependencies for {@link Registry}. Production code uses the
903
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
904
+ * orchestration against a fake `CoreRuntime` without an engine.
905
+ */
906
+ interface RegistryDeps {
907
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
908
+ }
581
909
  declare class Registry<A extends RegistryActors> {
582
910
  #private;
583
911
  readonly routes: RegistryRoutes;
584
912
  get config(): RegistryConfigInput<A>;
585
913
  parseConfig(): RegistryConfig;
586
- constructor(config: RegistryConfigInput<A>);
914
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
587
915
  /**
588
916
  * Handle an incoming HTTP request for serverless deployments.
589
917
  *
@@ -604,6 +932,46 @@ declare class Registry<A extends RegistryActors> {
604
932
  * ```
605
933
  */
606
934
  serve(): ServerlessHandler;
935
+ /**
936
+ * Starts an HTTP server that dispatches every request through the
937
+ * serverless handler. Uses `crossPlatformServe` to pick the right
938
+ * runtime (Node, Bun, Deno).
939
+ *
940
+ * @param opts.port Port to listen on. Defaults to 3000.
941
+ * @param opts.publicDir If set, serves static files from this directory
942
+ * before falling through to the registry handler.
943
+ *
944
+ * @example
945
+ * ```ts
946
+ * await registry.listen();
947
+ * await registry.listen({ port: 8080, publicDir: "./public" });
948
+ * ```
949
+ */
950
+ listen(opts?: {
951
+ port?: number;
952
+ publicDir?: string;
953
+ }): Promise<void>;
954
+ /**
955
+ * Gracefully drains all live registries.
956
+ *
957
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
958
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
959
+ * waits for the serve promise to resolve, all bounded by the shutdown
960
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
961
+ * signal or exit the process. The caller owns process lifetime.
962
+ *
963
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
964
+ * call even if nothing has been started.
965
+ *
966
+ * @example
967
+ * ```ts
968
+ * const registry = setup({ use: { counter } });
969
+ * registry.start();
970
+ * // ...later, on your own shutdown trigger:
971
+ * await registry.shutdown();
972
+ * ```
973
+ */
974
+ shutdown(): Promise<void>;
607
975
  startEnvoy(): void;
608
976
  /**
609
977
  * Starts the actor envoy for standalone server deployments.
@@ -642,6 +1010,12 @@ interface QueueSendResult<TResponse = unknown> {
642
1010
  * @returns {Promise<Response>}
643
1011
  */
644
1012
  type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
1013
+ type IsAny<T> = 0 extends 1 & T ? true : false;
1014
+ type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
1015
+ type ActorActionMap<R> = {
1016
+ [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : never;
1017
+ };
1018
+ type ActionsOf<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? R : never;
645
1019
  interface ActorGatewayOptions {
646
1020
  skipReadyWait?: boolean;
647
1021
  }
@@ -654,9 +1028,7 @@ type ActorWebSocketOptions = ActorGatewayOptions;
654
1028
  /**
655
1029
  * Maps action methods from actor definition to typed function signatures.
656
1030
  */
657
- type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? {
658
- [K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
659
- } : never;
1031
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
660
1032
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
661
1033
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
662
1034
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
@@ -667,13 +1039,31 @@ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
667
1039
  <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
668
1040
  (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
669
1041
  };
670
- type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
1042
+ type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1043
+ send: ActorQueueSend<Record<string, any>>;
1044
+ } : AD extends {
1045
+ config: {
1046
+ queues?: infer Q;
1047
+ };
1048
+ } ? Q extends QueueSchemaConfig ? {
671
1049
  send: ActorQueueSend<Q>;
672
- } : never : never;
673
- type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
1050
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
1051
+ send: ActorQueueSend<Q>;
1052
+ } : {} : {};
1053
+ type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1054
+ on: LooseEventSubscribe;
1055
+ once: LooseEventSubscribe;
1056
+ } : AD extends {
1057
+ config: {
1058
+ events?: infer E;
1059
+ };
1060
+ } ? E extends EventSchemaConfig ? {
674
1061
  on: ActorEventSubscribe<E>;
675
1062
  once: ActorEventSubscribe<E>;
676
- } : never : never;
1063
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
1064
+ on: ActorEventSubscribe<E>;
1065
+ once: ActorEventSubscribe<E>;
1066
+ } : {} : {};
677
1067
 
678
1068
  type ActorResolutionState = ActorQuery;
679
1069
 
@@ -1099,6 +1489,7 @@ type Client<A extends Registry<any>> = ClientRaw & {
1099
1489
  };
1100
1490
 
1101
1491
  declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
1492
+ declare const RAW_STATE_SYMBOL: unique symbol;
1102
1493
  interface ActorLogger {
1103
1494
  level: any;
1104
1495
  fatal: any;
@@ -1131,6 +1522,10 @@ type ActorKvListOptions<T extends ActorKvValueType = "text", K extends ActorKvKe
1131
1522
  limit?: number;
1132
1523
  };
1133
1524
  type ActorClientFor<T> = T extends Registry<any> ? Client<T> : T;
1525
+ /**
1526
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`c.db` / `c.sql`)
1527
+ * or actor state instead.
1528
+ */
1134
1529
  interface ActorKv {
1135
1530
  get<T extends ActorKvValueType = "text">(key: Uint8Array | string, options?: ActorKvValueOptions<T>): Promise<ActorKvValueTypeMap[T] | null>;
1136
1531
  put<T extends ActorKvValueType = "text">(key: Uint8Array | string, value: Uint8Array | string | ArrayBuffer, options?: ActorKvValueOptions<T>): Promise<void>;
@@ -1207,7 +1602,7 @@ interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1207
1602
  iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
1208
1603
  [key: string]: any;
1209
1604
  }
1210
- 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>> {
1605
+ 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>> {
1211
1606
  id: string;
1212
1607
  params: TConnParams;
1213
1608
  state: TConnState;
@@ -1218,8 +1613,14 @@ interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TV
1218
1613
  }
1219
1614
  interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1220
1615
  [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
1616
+ /** Returns the raw unwrapped state without the write-through proxy. */
1617
+ [RAW_STATE_SYMBOL](): TState;
1221
1618
  state: TState;
1222
1619
  vars: TVars;
1620
+ /**
1621
+ * @deprecated Actor KV is deprecated. Use embedded SQLite (`db` / `sql`)
1622
+ * or actor state instead.
1623
+ */
1223
1624
  readonly kv: ActorKv;
1224
1625
  readonly db: InferDatabaseClient<TDatabase>;
1225
1626
  readonly schedule: ActorSchedule;
@@ -1344,8 +1745,27 @@ declare const ActorConfigSchema: z$1.ZodObject<{
1344
1745
  preloadMaxWorkflowBytes: z$1.ZodOptional<z$1.ZodNumber>;
1345
1746
  preloadMaxConnectionsBytes: z$1.ZodOptional<z$1.ZodNumber>;
1346
1747
  }, z$1.core.$strict>>;
1748
+ inspector: z$1.ZodOptional<z$1.ZodObject<{
1749
+ tabs: z$1.ZodDefault<z$1.ZodArray<z$1.ZodUnion<readonly [z$1.ZodObject<{
1750
+ id: z$1.ZodString;
1751
+ label: z$1.ZodString;
1752
+ source: z$1.ZodString;
1753
+ icon: z$1.ZodOptional<z$1.ZodString>;
1754
+ hidden: z$1.ZodOptional<z$1.ZodLiteral<false>>;
1755
+ }, z$1.core.$strict>, z$1.ZodObject<{
1756
+ id: z$1.ZodEnum<{
1757
+ state: "state";
1758
+ queue: "queue";
1759
+ workflow: "workflow";
1760
+ database: "database";
1761
+ connections: "connections";
1762
+ console: "console";
1763
+ }>;
1764
+ hidden: z$1.ZodLiteral<true>;
1765
+ }, z$1.core.$strict>]>>>;
1766
+ }, z$1.core.$strict>>;
1347
1767
  }, z$1.core.$strict>;
1348
- type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1768
+ type CreateState<TState, _TConnParams, _TConnState, _TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1349
1769
  state: TState;
1350
1770
  } | {
1351
1771
  createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
@@ -1358,7 +1778,7 @@ type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase e
1358
1778
  /**
1359
1779
  * @experimental
1360
1780
  */
1361
- type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1781
+ type CreateVars<TState, _TConnParams, _TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1362
1782
  /**
1363
1783
  * @experimental
1364
1784
  */
@@ -1544,7 +1964,7 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1544
1964
  */
1545
1965
  db: TDatabase;
1546
1966
  } | Record<never, never>;
1547
- type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = 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, Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
1967
+ 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>;
1548
1968
 
1549
1969
  type AgentOsActorState = {};
1550
1970
  interface AgentOsActorVars {
@@ -1666,6 +2086,16 @@ interface AgentOsActorConfigCallbacks<TConnParams> {
1666
2086
  type AgentOsActorConfig<TConnParams = undefined> = Omit<z$1.infer<typeof agentOsActorConfigSchema>, "onBeforeConnect" | "onSessionEvent" | "onPermissionRequest"> & AgentOsActorConfigCallbacks<TConnParams>;
1667
2087
  type AgentOsActorConfigInput<TConnParams = undefined> = Omit<z$1.input<typeof agentOsActorConfigSchema>, "onBeforeConnect" | "onSessionEvent" | "onPermissionRequest"> & AgentOsActorConfigCallbacks<TConnParams>;
1668
2088
 
2089
+ declare function buildCronActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2090
+ scheduleCron: (c: AgentOsActionContext<TConnParams>, options: SerializableCronJobOptions) => Promise<{
2091
+ id: string;
2092
+ }>;
2093
+ listCronJobs: (c: AgentOsActionContext<TConnParams>) => Promise<SerializableCronJobInfo[]>;
2094
+ cancelCronJob: (c: AgentOsActionContext<TConnParams>, id: string) => Promise<void>;
2095
+ };
2096
+
2097
+ declare function migrateAgentOsTables(db: RawAccess): Promise<void>;
2098
+
1669
2099
  type VirtualStat = Awaited<ReturnType<_rivet_dev_agent_os_core.AgentOs["stat"]>>;
1670
2100
  type DeleteOptions = Parameters<_rivet_dev_agent_os_core.AgentOs["delete"]>[1];
1671
2101
  declare function buildFilesystemActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
@@ -1697,16 +2127,7 @@ declare function agentOs<TConnParams = undefined>(config: AgentOsActorConfigInpu
1697
2127
  processExit: typeof processExitToken;
1698
2128
  shellData: typeof shellDataToken;
1699
2129
  cronEvent: typeof cronEventToken;
1700
- }, Record<never, never>, Actions<AgentOsActorState, TConnParams, undefined, AgentOsActorVars, undefined, DatabaseProvider<RawAccess>, {
1701
- sessionEvent: typeof sessionEventToken;
1702
- permissionRequest: typeof permissionRequestToken;
1703
- vmBooted: typeof vmBootedToken;
1704
- vmShutdown: typeof vmShutdownToken;
1705
- processOutput: typeof processOutputToken;
1706
- processExit: typeof processExitToken;
1707
- shellData: typeof shellDataToken;
1708
- cronEvent: typeof cronEventToken;
1709
- }, Record<never, never>>>;
2130
+ }, Record<never, never>, any>;
1710
2131
  declare const sessionEventToken: EventTypeToken<SessionEventPayload, any>;
1711
2132
  declare const permissionRequestToken: EventTypeToken<PermissionRequestPayload, any>;
1712
2133
  declare const vmBootedToken: EventTypeToken<VmBootedPayload, any>;
@@ -1716,6 +2137,21 @@ declare const processExitToken: EventTypeToken<ProcessExitPayload, any>;
1716
2137
  declare const shellDataToken: EventTypeToken<ShellDataPayload, any>;
1717
2138
  declare const cronEventToken: EventTypeToken<CronEventPayload, any>;
1718
2139
 
2140
+ interface VmFetchOptions {
2141
+ method?: string;
2142
+ headers?: Record<string, string>;
2143
+ body?: string | Uint8Array;
2144
+ }
2145
+ interface VmFetchResult {
2146
+ status: number;
2147
+ statusText: string;
2148
+ headers: Record<string, string>;
2149
+ body: Uint8Array;
2150
+ }
2151
+ declare function buildNetworkActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2152
+ vmFetch: (c: AgentOsActionContext<TConnParams>, port: number, url: string, options?: VmFetchOptions) => Promise<VmFetchResult>;
2153
+ };
2154
+
1719
2155
  declare function generateToken(): string;
1720
2156
  type AgentOsRequestContext<TConnParams> = RequestContext<AgentOsActorState, TConnParams, undefined, AgentOsActorVars, undefined, DatabaseProvider<RawAccess>>;
1721
2157
  declare function buildOnRequestHandler<TConnParams>(config: AgentOsActorConfig<TConnParams>): (c: AgentOsRequestContext<TConnParams>, request: Request) => Promise<Response>;
@@ -1788,27 +2224,18 @@ declare function buildShellActions<TConnParams>(config: AgentOsActorConfig<TConn
1788
2224
  closeShell: (c: AgentOsActionContext<TConnParams>, shellId: string) => Promise<void>;
1789
2225
  };
1790
2226
 
1791
- declare function buildCronActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
1792
- scheduleCron: (c: AgentOsActionContext<TConnParams>, options: SerializableCronJobOptions) => Promise<{
1793
- id: string;
1794
- }>;
1795
- listCronJobs: (c: AgentOsActionContext<TConnParams>) => Promise<SerializableCronJobInfo[]>;
1796
- cancelCronJob: (c: AgentOsActionContext<TConnParams>, id: string) => Promise<void>;
1797
- };
1798
-
1799
- interface VmFetchOptions {
1800
- method?: string;
1801
- headers?: Record<string, string>;
1802
- body?: string | Uint8Array;
1803
- }
1804
- interface VmFetchResult {
1805
- status: number;
1806
- statusText: string;
1807
- headers: Record<string, string>;
1808
- body: Uint8Array;
2227
+ type VirtualFileSystem = _rivet_dev_agent_os_core.PlainMountConfig["driver"];
2228
+ interface DatabaseVfsOptions {
2229
+ /** The RawAccess database handle from the actor's db provider. */
2230
+ db: RawAccess;
1809
2231
  }
1810
- declare function buildNetworkActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
1811
- vmFetch: (c: AgentOsActionContext<TConnParams>, port: number, url: string, options?: VmFetchOptions) => Promise<VmFetchResult>;
1812
- };
2232
+ /**
2233
+ * Create a VirtualFileSystem backed by SQLite.
2234
+ *
2235
+ * The returned filesystem stores all content and metadata in the
2236
+ * `agent_os_fs_entries` table. The table must be created beforehand
2237
+ * via `migrateAgentOsTables()`.
2238
+ */
2239
+ declare function createDatabaseVfs(options: DatabaseVfsOptions): VirtualFileSystem;
1813
2240
 
1814
2241
  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 };