rivetkit 2.3.0-rc.10 → 2.3.0-rc.12

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 (205) hide show
  1. package/dist/browser/client.d.ts +448 -62
  2. package/dist/browser/client.js +131 -89
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +40 -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.js +1 -1
  8. package/dist/tsup/agent-os/index.cjs +2103 -2090
  9. package/dist/tsup/agent-os/index.cjs.map +1 -1
  10. package/dist/tsup/agent-os/index.d.cts +446 -69
  11. package/dist/tsup/agent-os/index.d.ts +446 -69
  12. package/dist/tsup/agent-os/index.js +2102 -2089
  13. package/dist/tsup/agent-os/index.js.map +1 -1
  14. package/dist/tsup/{chunk-TE4VCDNY.cjs → chunk-2U6RLFKX.cjs} +219 -234
  15. package/dist/tsup/chunk-2U6RLFKX.cjs.map +1 -0
  16. package/dist/tsup/{chunk-4K3MV2MW.cjs → chunk-2ZTBRZRS.cjs} +10 -10
  17. package/dist/tsup/chunk-2ZTBRZRS.cjs.map +1 -0
  18. package/dist/tsup/{chunk-KU6VKVEK.js → chunk-3EVVOYFD.js} +19 -7
  19. package/dist/tsup/chunk-3EVVOYFD.js.map +1 -0
  20. package/dist/tsup/{chunk-3LGP4JSO.cjs → chunk-6KTMKPNU.cjs} +8 -8
  21. package/dist/tsup/{chunk-3LGP4JSO.cjs.map → chunk-6KTMKPNU.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-WU2O2KIE.js → chunk-7UZF56RS.js} +63 -78
  23. package/dist/tsup/chunk-7UZF56RS.js.map +1 -0
  24. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-BRP62GZC.js} +3 -3
  25. package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
  26. package/dist/tsup/{chunk-G5RULGYQ.cjs → chunk-C7AAIILH.cjs} +24 -9
  27. package/dist/tsup/chunk-C7AAIILH.cjs.map +1 -0
  28. package/dist/tsup/{chunk-XV52XUWU.js → chunk-EWVOWEMD.js} +4 -4
  29. package/dist/tsup/chunk-EWVOWEMD.js.map +1 -0
  30. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  31. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  32. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  33. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  34. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-KORQB2IR.cjs} +3 -3
  35. package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
  36. package/dist/tsup/{chunk-CMYS77J6.js → chunk-OLIJHKLL.js} +3 -3
  37. package/dist/tsup/{chunk-BM3EOY7M.js → chunk-OOB32JVG.js} +134 -20
  38. package/dist/tsup/chunk-OOB32JVG.js.map +1 -0
  39. package/dist/tsup/{chunk-G34LIR7S.js → chunk-QKSGGKGQ.js} +22 -7
  40. package/dist/tsup/chunk-QKSGGKGQ.js.map +1 -0
  41. package/dist/tsup/{chunk-PWFGP2US.cjs → chunk-SS56HFM2.cjs} +138 -24
  42. package/dist/tsup/chunk-SS56HFM2.cjs.map +1 -0
  43. package/dist/tsup/{chunk-Z4C3W2CQ.cjs → chunk-UETC5RF7.cjs} +3 -3
  44. package/dist/tsup/{chunk-Z4C3W2CQ.cjs.map → chunk-UETC5RF7.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  46. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  47. package/dist/tsup/{chunk-6BI2MS3S.js → chunk-VLXRFJ7P.js} +2 -2
  48. package/dist/tsup/{chunk-J5P6S2LC.cjs → chunk-VNMIAPPF.cjs} +26 -14
  49. package/dist/tsup/chunk-VNMIAPPF.cjs.map +1 -0
  50. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-WHYBAEWG.cjs} +4 -2
  51. package/dist/tsup/chunk-WHYBAEWG.cjs.map +1 -0
  52. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-WIMUFZVJ.js} +3 -1
  53. package/dist/tsup/chunk-WIMUFZVJ.js.map +1 -0
  54. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  55. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  56. package/dist/tsup/client/mod.cjs +9 -9
  57. package/dist/tsup/client/mod.d.cts +4 -4
  58. package/dist/tsup/client/mod.d.ts +4 -4
  59. package/dist/tsup/client/mod.js +8 -8
  60. package/dist/tsup/common/log.cjs +3 -3
  61. package/dist/tsup/common/log.js +2 -2
  62. package/dist/tsup/common/websocket.cjs +4 -4
  63. package/dist/tsup/common/websocket.js +3 -3
  64. package/dist/tsup/{config-Ca8dN4cS.d.cts → config-BtAh7oBu.d.cts} +409 -22
  65. package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.cts} +1 -2
  66. package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.ts} +1 -2
  67. package/dist/tsup/{config-0Ta55UV0.d.ts → config-DKgPGC0f.d.ts} +409 -22
  68. package/dist/tsup/{context-B_IWbWne.d.ts → context-C-6dGebY.d.ts} +8 -8
  69. package/dist/tsup/{context-CUrQ9MHc.d.cts → context-Cfjl5pgz.d.cts} +8 -8
  70. package/dist/tsup/db/drizzle.cjs +3 -3
  71. package/dist/tsup/db/drizzle.d.cts +1 -1
  72. package/dist/tsup/db/drizzle.d.ts +1 -1
  73. package/dist/tsup/db/drizzle.js +1 -1
  74. package/dist/tsup/db/mod.cjs +2 -2
  75. package/dist/tsup/db/mod.d.cts +2 -2
  76. package/dist/tsup/db/mod.d.ts +2 -2
  77. package/dist/tsup/db/mod.js +1 -1
  78. package/dist/tsup/dynamic/mod.cjs +24 -0
  79. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  80. package/dist/tsup/dynamic/mod.d.cts +37 -0
  81. package/dist/tsup/dynamic/mod.d.ts +37 -0
  82. package/dist/tsup/dynamic/mod.js +24 -0
  83. package/dist/tsup/dynamic/mod.js.map +1 -0
  84. package/dist/tsup/inspector/mod.cjs +6 -6
  85. package/dist/tsup/inspector/mod.js +5 -5
  86. package/dist/tsup/mod.cjs +606 -325
  87. package/dist/tsup/mod.cjs.map +1 -1
  88. package/dist/tsup/mod.d.cts +4 -4
  89. package/dist/tsup/mod.d.ts +4 -4
  90. package/dist/tsup/mod.js +510 -229
  91. package/dist/tsup/mod.js.map +1 -1
  92. package/dist/tsup/test/mod.cjs +21 -18
  93. package/dist/tsup/test/mod.cjs.map +1 -1
  94. package/dist/tsup/test/mod.d.cts +3 -3
  95. package/dist/tsup/test/mod.d.ts +3 -3
  96. package/dist/tsup/test/mod.js +18 -15
  97. package/dist/tsup/test/mod.js.map +1 -1
  98. package/dist/tsup/utils.cjs +3 -3
  99. package/dist/tsup/utils.d.cts +1 -1
  100. package/dist/tsup/utils.d.ts +1 -1
  101. package/dist/tsup/utils.js +2 -2
  102. package/dist/tsup/workflow/mod.cjs +307 -282
  103. package/dist/tsup/workflow/mod.cjs.map +1 -1
  104. package/dist/tsup/workflow/mod.d.cts +5 -5
  105. package/dist/tsup/workflow/mod.d.ts +5 -5
  106. package/dist/tsup/workflow/mod.js +501 -476
  107. package/dist/tsup/workflow/mod.js.map +1 -1
  108. package/package.json +22 -11
  109. package/src/actor/config.ts +68 -51
  110. package/src/actor/contexts/index.ts +7 -2
  111. package/src/actor/definition.ts +17 -19
  112. package/src/actor/driver.ts +3 -3
  113. package/src/actor/errors.ts +9 -3
  114. package/src/actor/instance/mod.ts +22 -30
  115. package/src/actor/keys.ts +1 -1
  116. package/src/actor/mod.ts +20 -20
  117. package/src/actor/schema.ts +2 -2
  118. package/src/agent-os/actor/index.ts +38 -18
  119. package/src/agent-os/actor/preview.ts +1 -2
  120. package/src/agent-os/actor/session.ts +2 -2
  121. package/src/agent-os/config.ts +1 -1
  122. package/src/agent-os/fs/database-vfs.ts +1 -1
  123. package/src/agent-os/index.ts +16 -15
  124. package/src/client/actor-common.ts +87 -54
  125. package/src/client/actor-conn.ts +8 -36
  126. package/src/client/actor-handle.ts +69 -51
  127. package/src/client/actor-query.ts +5 -5
  128. package/src/client/errors.ts +1 -1
  129. package/src/client/lifecycle-errors.ts +2 -4
  130. package/src/client/query.ts +1 -1
  131. package/src/client/queue.ts +8 -3
  132. package/src/client/raw-utils.ts +8 -6
  133. package/src/client/resolve-gateway-target.ts +1 -1
  134. package/src/client/utils.ts +2 -7
  135. package/src/common/actor-websocket.ts +3 -1
  136. package/src/common/bare/actor-persist/v1.ts +205 -163
  137. package/src/common/bare/actor-persist/v2.ts +265 -213
  138. package/src/common/bare/actor-persist/v3.ts +176 -172
  139. package/src/common/bare/actor-persist/v4.ts +254 -253
  140. package/src/common/bare/transport/v1.ts +659 -543
  141. package/src/common/client-protocol-versioned.ts +66 -64
  142. package/src/common/database/config.ts +2 -8
  143. package/src/common/database/native-database.ts +1 -1
  144. package/src/common/database/shared.ts +1 -0
  145. package/src/common/encoding.ts +250 -16
  146. package/src/common/eventsource.ts +1 -1
  147. package/src/common/inline-websocket-adapter.ts +14 -13
  148. package/src/common/log.ts +1 -0
  149. package/src/common/router.ts +13 -17
  150. package/src/common/utils.ts +1 -150
  151. package/src/common/websocket-interface.ts +1 -1
  152. package/src/db/mod.ts +1 -1
  153. package/src/drivers/engine/actor-driver.ts +58 -56
  154. package/src/dynamic/instance.ts +32 -0
  155. package/src/dynamic/internal.ts +50 -0
  156. package/src/dynamic/isolate-runtime.ts +66 -0
  157. package/src/dynamic/mod.ts +32 -0
  158. package/src/engine-client/actor-http-client.ts +1 -1
  159. package/src/engine-client/actor-websocket-client.ts +6 -5
  160. package/src/engine-client/api-endpoints.ts +51 -2
  161. package/src/engine-client/api-utils.ts +2 -2
  162. package/src/engine-client/driver.ts +1 -1
  163. package/src/engine-client/mod.ts +6 -3
  164. package/src/engine-client/ws-proxy.ts +4 -4
  165. package/src/inspector/client.browser.ts +5 -11
  166. package/src/inspector/mod.ts +1 -3
  167. package/src/registry/config/envoy.ts +1 -2
  168. package/src/registry/config/index.ts +3 -9
  169. package/src/registry/index.ts +150 -72
  170. package/src/registry/napi-runtime.ts +13 -2
  171. package/src/registry/native-validation.ts +10 -12
  172. package/src/registry/native.ts +231 -173
  173. package/src/registry/process-metrics.ts +250 -0
  174. package/src/registry/runtime.ts +4 -0
  175. package/src/registry/wasm-runtime.ts +18 -2
  176. package/src/registry/write-through-proxy.ts +40 -0
  177. package/src/serde.ts +2 -2
  178. package/src/serverless/configure.ts +18 -7
  179. package/src/test/mod.ts +11 -8
  180. package/src/utils/endpoint-parser.ts +1 -1
  181. package/src/utils/router.ts +1 -1
  182. package/src/utils/serve.ts +4 -5
  183. package/src/utils.ts +1 -2
  184. package/src/workflow/context.ts +61 -33
  185. package/src/workflow/driver.ts +4 -6
  186. package/src/workflow/inspector.ts +4 -3
  187. package/src/workflow/mod.ts +15 -17
  188. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  189. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  190. package/dist/tsup/chunk-4K3MV2MW.cjs.map +0 -1
  191. package/dist/tsup/chunk-BM3EOY7M.js.map +0 -1
  192. package/dist/tsup/chunk-G34LIR7S.js.map +0 -1
  193. package/dist/tsup/chunk-G5RULGYQ.cjs.map +0 -1
  194. package/dist/tsup/chunk-J5P6S2LC.cjs.map +0 -1
  195. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  196. package/dist/tsup/chunk-KU6VKVEK.js.map +0 -1
  197. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  198. package/dist/tsup/chunk-PWFGP2US.cjs.map +0 -1
  199. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  200. package/dist/tsup/chunk-TE4VCDNY.cjs.map +0 -1
  201. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  202. package/dist/tsup/chunk-WU2O2KIE.js.map +0 -1
  203. package/dist/tsup/chunk-XV52XUWU.js.map +0 -1
  204. /package/dist/tsup/{chunk-CMYS77J6.js.map → chunk-OLIJHKLL.js.map} +0 -0
  205. /package/dist/tsup/{chunk-6BI2MS3S.js.map → chunk-VLXRFJ7P.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>>;
@@ -374,7 +357,7 @@ interface QueueSchemaDefinition<TContext = any> {
374
357
  type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
375
358
  type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
376
359
  type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
377
- type QueueSchemaConfig<TContext = any> = Record<string, QueueSchema>;
360
+ type QueueSchemaConfig<_TContext = any> = Record<string, QueueSchema>;
378
361
  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
362
  type InferSchemaMap<T extends Record<string, unknown>> = {
380
363
  [K in keyof T]: InferSchema<T[K]>;
@@ -385,14 +368,16 @@ type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
385
368
  };
386
369
  type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
387
370
 
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>;
371
+ 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>> {
372
+ readonly config: ActorConfig<S, CP, CS, V, I, DB, E, Q, _R>;
373
+ }
374
+ interface AnyActorDefinition {
375
+ readonly config: any;
390
376
  }
391
- type AnyActorDefinition = BaseActorDefinition<any, any, any, any, any, any, any, any, any>;
392
377
  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
378
  #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>;
379
+ constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q, R>);
380
+ get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q, R>;
396
381
  }
397
382
 
398
383
  declare const EncodingSchema: z$1.ZodEnum<{
@@ -569,6 +554,318 @@ interface ActorOutput {
569
554
  error?: unknown;
570
555
  }
571
556
 
557
+ declare const handleBrand: unique symbol;
558
+ type OpaqueHandle<Name extends string> = {
559
+ readonly [handleBrand]: Name;
560
+ };
561
+ type RegistryHandle = OpaqueHandle<"registry">;
562
+ type ActorFactoryHandle = OpaqueHandle<"actorFactory">;
563
+ type ActorContextHandle = OpaqueHandle<"actorContext">;
564
+ type ConnHandle = OpaqueHandle<"conn">;
565
+ type WebSocketHandle = OpaqueHandle<"webSocket">;
566
+ type CancellationTokenHandle = OpaqueHandle<"cancellationToken">;
567
+ type RuntimeBytes = Uint8Array;
568
+ interface RuntimeActorKeySegment {
569
+ kind: string;
570
+ stringValue?: string;
571
+ numberValue?: number;
572
+ }
573
+ interface RuntimeHttpRequest {
574
+ method: string;
575
+ uri: string;
576
+ headers?: Record<string, string>;
577
+ body?: RuntimeBytes;
578
+ }
579
+ interface RuntimeStateDeltaPayload {
580
+ state?: RuntimeBytes;
581
+ connHibernation: Array<{
582
+ connId: string;
583
+ bytes: RuntimeBytes;
584
+ }>;
585
+ connHibernationRemoved: string[];
586
+ }
587
+ interface RuntimeRequestSaveOpts {
588
+ immediate?: boolean;
589
+ maxWaitMs?: number;
590
+ }
591
+ interface RuntimeInspectorSnapshot {
592
+ stateRevision: number;
593
+ connectionsRevision: number;
594
+ queueRevision: number;
595
+ activeConnections: number;
596
+ queueSize: number;
597
+ connectedClients: number;
598
+ }
599
+ interface RuntimeQueueMessage {
600
+ id(): bigint;
601
+ name(): string;
602
+ body(): RuntimeBytes;
603
+ createdAt(): number;
604
+ isCompletable(): boolean;
605
+ complete(response?: RuntimeBytes | undefined | null): Promise<void>;
606
+ }
607
+ interface RuntimeQueueInspectMessage {
608
+ id: number;
609
+ name: string;
610
+ createdAtMs: number;
611
+ }
612
+ interface RuntimeQueueNextBatchOptions {
613
+ names?: string[];
614
+ count?: number;
615
+ timeoutMs?: number;
616
+ completable?: boolean;
617
+ }
618
+ interface RuntimeQueueWaitOptions {
619
+ timeoutMs?: number;
620
+ completable?: boolean;
621
+ }
622
+ interface RuntimeQueueEnqueueAndWaitOptions {
623
+ timeoutMs?: number;
624
+ }
625
+ interface RuntimeQueueTryNextBatchOptions {
626
+ names?: string[];
627
+ count?: number;
628
+ completable?: boolean;
629
+ }
630
+ interface RuntimeKvListOptions {
631
+ reverse?: boolean;
632
+ limit?: number;
633
+ }
634
+ interface RuntimeKvEntry {
635
+ key: RuntimeBytes;
636
+ value: RuntimeBytes;
637
+ }
638
+ type RuntimeSqlBindNoValues = {
639
+ intValue?: never;
640
+ floatValue?: never;
641
+ textValue?: never;
642
+ blobValue?: never;
643
+ };
644
+ type RuntimeSqlBindParam = ({
645
+ kind: "null";
646
+ } & RuntimeSqlBindNoValues) | {
647
+ kind: "int";
648
+ intValue: number;
649
+ floatValue?: never;
650
+ textValue?: never;
651
+ blobValue?: never;
652
+ } | {
653
+ kind: "float";
654
+ intValue?: never;
655
+ floatValue: number;
656
+ textValue?: never;
657
+ blobValue?: never;
658
+ } | {
659
+ kind: "text";
660
+ intValue?: never;
661
+ floatValue?: never;
662
+ textValue: string;
663
+ blobValue?: never;
664
+ } | {
665
+ kind: "blob";
666
+ intValue?: never;
667
+ floatValue?: never;
668
+ textValue?: never;
669
+ blobValue: RuntimeBytes;
670
+ };
671
+ type RuntimeSqlBindParams = RuntimeSqlBindParam[] | null;
672
+ interface RuntimeSqlQueryResult {
673
+ columns: string[];
674
+ rows: unknown[][];
675
+ }
676
+ type RuntimeSqlExecResult = RuntimeSqlQueryResult;
677
+ interface RuntimeSqlExecuteResult extends RuntimeSqlQueryResult {
678
+ changes: number;
679
+ lastInsertRowId?: number | null;
680
+ }
681
+ interface RuntimeSqlRunResult {
682
+ changes: number;
683
+ }
684
+ interface RuntimeActorConfig {
685
+ name?: string;
686
+ icon?: string;
687
+ hasDatabase?: boolean;
688
+ remoteSqlite?: boolean;
689
+ hasState?: boolean;
690
+ canHibernateWebsocket?: boolean;
691
+ stateSaveIntervalMs?: number;
692
+ createStateTimeoutMs?: number;
693
+ onCreateTimeoutMs?: number;
694
+ createVarsTimeoutMs?: number;
695
+ createConnStateTimeoutMs?: number;
696
+ onBeforeConnectTimeoutMs?: number;
697
+ onConnectTimeoutMs?: number;
698
+ onMigrateTimeoutMs?: number;
699
+ onWakeTimeoutMs?: number;
700
+ onBeforeActorStartTimeoutMs?: number;
701
+ actionTimeoutMs?: number;
702
+ onRequestTimeoutMs?: number;
703
+ sleepTimeoutMs?: number;
704
+ noSleep?: boolean;
705
+ sleepGracePeriodMs?: number;
706
+ connectionLivenessTimeoutMs?: number;
707
+ connectionLivenessIntervalMs?: number;
708
+ maxQueueSize?: number;
709
+ maxQueueMessageSize?: number;
710
+ maxIncomingMessageSize?: number;
711
+ maxOutgoingMessageSize?: number;
712
+ preloadMaxWorkflowBytes?: number;
713
+ preloadMaxConnectionsBytes?: number;
714
+ actions?: Array<{
715
+ name: string;
716
+ }>;
717
+ }
718
+ interface RuntimeServeConfig {
719
+ version: number;
720
+ endpoint: string;
721
+ token?: string;
722
+ namespace: string;
723
+ poolName: string;
724
+ engineBinaryPath?: string;
725
+ handleInspectorHttpInRuntime?: boolean;
726
+ inspectorTestToken?: string;
727
+ serverlessBasePath?: string;
728
+ serverlessPackageVersion: string;
729
+ serverlessClientEndpoint?: string;
730
+ serverlessClientNamespace?: string;
731
+ serverlessClientToken?: string;
732
+ serverlessValidateEndpoint: boolean;
733
+ serverlessMaxStartPayloadBytes: number;
734
+ }
735
+ interface RuntimeServerlessRequest {
736
+ method: string;
737
+ url: string;
738
+ headers: Record<string, string>;
739
+ body: RuntimeBytes;
740
+ }
741
+ interface RuntimeServerlessResponseHead {
742
+ status: number;
743
+ headers: Record<string, string>;
744
+ }
745
+ interface RuntimeRegistryRouteResponse {
746
+ status: number;
747
+ headers: Record<string, string>;
748
+ body: RuntimeBytes;
749
+ }
750
+ type RuntimeServerlessStreamEvent = {
751
+ kind: "chunk";
752
+ chunk?: RuntimeBytes;
753
+ } | {
754
+ kind: "end";
755
+ error?: {
756
+ group: string;
757
+ code: string;
758
+ message: string;
759
+ };
760
+ };
761
+ type RuntimeServerlessStreamCallback = (error: unknown, event?: RuntimeServerlessStreamEvent) => unknown;
762
+ type RuntimeWebSocketEvent = {
763
+ kind: "message";
764
+ data: string | RuntimeBytes;
765
+ binary: boolean;
766
+ messageIndex?: number;
767
+ } | {
768
+ kind: "close";
769
+ code: number;
770
+ reason: string;
771
+ wasClean: boolean;
772
+ };
773
+ interface CoreRuntime {
774
+ readonly kind: "napi" | "wasm";
775
+ createRegistry(): RegistryHandle;
776
+ registerActor(registry: RegistryHandle, name: string, factory: ActorFactoryHandle): void;
777
+ serveRegistry(registry: RegistryHandle, config: RuntimeServeConfig): Promise<void>;
778
+ shutdownRegistry(registry: RegistryHandle): Promise<void>;
779
+ registryActorStopThresholdMs?(registry: RegistryHandle): Promise<number | undefined>;
780
+ handleServerlessRequest(registry: RegistryHandle, req: RuntimeServerlessRequest, onStreamEvent: RuntimeServerlessStreamCallback, cancelToken: CancellationTokenHandle, config: RuntimeServeConfig): Promise<RuntimeServerlessResponseHead>;
781
+ registryHealth?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
782
+ registryMetadata?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
783
+ registryMetrics?(registry: RegistryHandle): Promise<RuntimeRegistryRouteResponse>;
784
+ createActorFactory(callbacks: object, config?: RuntimeActorConfig | undefined | null): ActorFactoryHandle;
785
+ createCancellationToken(): CancellationTokenHandle;
786
+ cancellationTokenAborted(token: CancellationTokenHandle): boolean;
787
+ cancelCancellationToken(token: CancellationTokenHandle): void;
788
+ onCancellationTokenCancelled(token: CancellationTokenHandle, callback: (...args: unknown[]) => unknown): void;
789
+ actorState(ctx: ActorContextHandle): RuntimeBytes;
790
+ actorBeginOnStateChange(ctx: ActorContextHandle): void;
791
+ actorEndOnStateChange(ctx: ActorContextHandle): void;
792
+ actorSetAlarm(ctx: ActorContextHandle, timestampMs?: number | undefined | null): void;
793
+ actorRequestSave(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): void;
794
+ actorRequestSaveAndWait(ctx: ActorContextHandle, opts?: RuntimeRequestSaveOpts | undefined | null): Promise<void>;
795
+ actorInspectorSnapshot(ctx: ActorContextHandle): RuntimeInspectorSnapshot;
796
+ actorDecodeInspectorRequest(ctx: ActorContextHandle, bytes: RuntimeBytes, advertisedVersion: number): RuntimeBytes;
797
+ actorEncodeInspectorResponse(ctx: ActorContextHandle, bytes: RuntimeBytes, targetVersion: number): RuntimeBytes;
798
+ actorVerifyInspectorAuth(ctx: ActorContextHandle, bearerToken?: string | undefined | null): Promise<void>;
799
+ actorQueueHibernationRemoval(ctx: ActorContextHandle, connId: string): void;
800
+ actorTakePendingHibernationChanges(ctx: ActorContextHandle): string[];
801
+ actorDirtyHibernatableConns(ctx: ActorContextHandle): ConnHandle[];
802
+ actorSaveState(ctx: ActorContextHandle, payload: RuntimeStateDeltaPayload): Promise<void>;
803
+ actorId(ctx: ActorContextHandle): string;
804
+ actorName(ctx: ActorContextHandle): string;
805
+ actorKey(ctx: ActorContextHandle): RuntimeActorKeySegment[];
806
+ actorRegion(ctx: ActorContextHandle): string;
807
+ actorSleep(ctx: ActorContextHandle): void;
808
+ actorDestroy(ctx: ActorContextHandle): void;
809
+ actorAbortSignal(ctx: ActorContextHandle): AbortSignal;
810
+ actorConns(ctx: ActorContextHandle): ConnHandle[];
811
+ actorConnectConn(ctx: ActorContextHandle, params: RuntimeBytes, request?: RuntimeHttpRequest | undefined | null): Promise<ConnHandle>;
812
+ actorBroadcast(ctx: ActorContextHandle, name: string, args: RuntimeBytes): void;
813
+ actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void;
814
+ actorWaitForTrackedShutdownWork(ctx: ActorContextHandle): Promise<boolean>;
815
+ actorWaitForTrackedShutdownWorkUnbounded(ctx: ActorContextHandle): Promise<void>;
816
+ actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void;
817
+ actorBeginKeepAwake(ctx: ActorContextHandle): number;
818
+ actorEndKeepAwake(ctx: ActorContextHandle, regionId: number): void;
819
+ actorRegisterTask(ctx: ActorContextHandle, promise: Promise<unknown>): void;
820
+ actorRuntimeState(ctx: ActorContextHandle): object;
821
+ actorClearRuntimeState(ctx: ActorContextHandle): void;
822
+ actorRestartRunHandler(ctx: ActorContextHandle): void;
823
+ actorBeginWebsocketCallback(ctx: ActorContextHandle): number;
824
+ actorEndWebsocketCallback(ctx: ActorContextHandle, regionId: number): void;
825
+ actorKvGet(ctx: ActorContextHandle, key: RuntimeBytes): Promise<RuntimeBytes | null>;
826
+ actorKvPut(ctx: ActorContextHandle, key: RuntimeBytes, value: RuntimeBytes): Promise<void>;
827
+ actorKvDelete(ctx: ActorContextHandle, key: RuntimeBytes): Promise<void>;
828
+ actorKvDeleteRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes): Promise<void>;
829
+ actorKvListPrefix(ctx: ActorContextHandle, prefix: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
830
+ actorKvListRange(ctx: ActorContextHandle, start: RuntimeBytes, end: RuntimeBytes, options?: RuntimeKvListOptions | undefined | null): Promise<RuntimeKvEntry[]>;
831
+ actorKvBatchGet(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<Array<RuntimeBytes | undefined | null>>;
832
+ actorKvBatchPut(ctx: ActorContextHandle, entries: RuntimeKvEntry[]): Promise<void>;
833
+ actorKvBatchDelete(ctx: ActorContextHandle, keys: RuntimeBytes[]): Promise<void>;
834
+ actorSqlExec(ctx: ActorContextHandle, sql: string): Promise<RuntimeSqlExecResult>;
835
+ actorSqlExecute(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlExecuteResult>;
836
+ actorSqlQuery(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlQueryResult>;
837
+ actorSqlRun(ctx: ActorContextHandle, sql: string, params?: RuntimeSqlBindParams): Promise<RuntimeSqlRunResult>;
838
+ actorSqlMetrics(ctx: ActorContextHandle): SqliteNativeMetrics | null;
839
+ actorSqlTakeLastKvError(ctx: ActorContextHandle): string | null;
840
+ actorSqlClose(ctx: ActorContextHandle): Promise<void>;
841
+ actorQueueSend(ctx: ActorContextHandle, name: string, body: RuntimeBytes): Promise<RuntimeQueueMessage>;
842
+ actorQueueNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueNextBatchOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage[]>;
843
+ actorQueueWaitForNames(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeQueueMessage>;
844
+ actorQueueWaitForNamesAvailable(ctx: ActorContextHandle, names: string[], options?: RuntimeQueueWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<void>;
845
+ actorQueueEnqueueAndWait(ctx: ActorContextHandle, name: string, body: RuntimeBytes, options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationTokenHandle | undefined | null): Promise<RuntimeBytes | null>;
846
+ actorQueueTryNextBatch(ctx: ActorContextHandle, options?: RuntimeQueueTryNextBatchOptions | undefined | null): RuntimeQueueMessage[];
847
+ actorQueueMaxSize(ctx: ActorContextHandle): number;
848
+ actorQueueInspectMessages(ctx: ActorContextHandle): Promise<RuntimeQueueInspectMessage[]>;
849
+ actorScheduleAfter(ctx: ActorContextHandle, durationMs: number, actionName: string, args: RuntimeBytes): void;
850
+ actorScheduleAt(ctx: ActorContextHandle, timestampMs: number, actionName: string, args: RuntimeBytes): void;
851
+ connId(conn: ConnHandle): string;
852
+ connParams(conn: ConnHandle): RuntimeBytes;
853
+ connState(conn: ConnHandle): RuntimeBytes;
854
+ connSetState(conn: ConnHandle, state: RuntimeBytes): void;
855
+ connIsHibernatable(conn: ConnHandle): boolean;
856
+ connSend(conn: ConnHandle, name: string, args: RuntimeBytes): void;
857
+ connDisconnect(conn: ConnHandle, reason?: string | undefined | null): Promise<void>;
858
+ webSocketSend(ws: WebSocketHandle, data: RuntimeBytes, binary: boolean): void;
859
+ webSocketClose(ws: WebSocketHandle, code?: number | undefined | null, reason?: string | undefined | null): Promise<void>;
860
+ webSocketSetEventCallback(ws: WebSocketHandle, callback: (event: RuntimeWebSocketEvent) => void): void;
861
+ }
862
+
863
+ declare function buildConfiguredRegistry(config: RegistryConfig): Promise<{
864
+ runtime: CoreRuntime;
865
+ registry: RegistryHandle;
866
+ serveConfig: RuntimeServeConfig;
867
+ }>;
868
+
572
869
  type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
573
870
  interface ServerlessHandler {
574
871
  fetch: FetchHandler;
@@ -578,12 +875,20 @@ interface RegistryRoutes {
578
875
  metadata(): Promise<Response>;
579
876
  prometheusMetrics(request?: Request): Promise<Response>;
580
877
  }
878
+ /**
879
+ * Injectable dependencies for {@link Registry}. Production code uses the
880
+ * defaults. Tests override `buildConfiguredRegistry` to drive lifecycle
881
+ * orchestration against a fake `CoreRuntime` without an engine.
882
+ */
883
+ interface RegistryDeps {
884
+ buildConfiguredRegistry: typeof buildConfiguredRegistry;
885
+ }
581
886
  declare class Registry<A extends RegistryActors> {
582
887
  #private;
583
888
  readonly routes: RegistryRoutes;
584
889
  get config(): RegistryConfigInput<A>;
585
890
  parseConfig(): RegistryConfig;
586
- constructor(config: RegistryConfigInput<A>);
891
+ constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>);
587
892
  /**
588
893
  * Handle an incoming HTTP request for serverless deployments.
589
894
  *
@@ -604,6 +909,46 @@ declare class Registry<A extends RegistryActors> {
604
909
  * ```
605
910
  */
606
911
  serve(): ServerlessHandler;
912
+ /**
913
+ * Starts an HTTP server that dispatches every request through the
914
+ * serverless handler. Uses `crossPlatformServe` to pick the right
915
+ * runtime (Node, Bun, Deno).
916
+ *
917
+ * @param opts.port Port to listen on. Defaults to 3000.
918
+ * @param opts.publicDir If set, serves static files from this directory
919
+ * before falling through to the registry handler.
920
+ *
921
+ * @example
922
+ * ```ts
923
+ * await registry.listen();
924
+ * await registry.listen({ port: 8080, publicDir: "./public" });
925
+ * ```
926
+ */
927
+ listen(opts?: {
928
+ port?: number;
929
+ publicDir?: string;
930
+ }): Promise<void>;
931
+ /**
932
+ * Gracefully drains all live registries.
933
+ *
934
+ * Programmatic counterpart to the SIGINT/SIGTERM handlers: tears down
935
+ * every live `CoreRegistry` (both `start()` and `handler()` modes) and
936
+ * waits for the serve promise to resolve, all bounded by the shutdown
937
+ * grace period. Unlike a signal-driven shutdown, this does not re-raise a
938
+ * signal or exit the process. The caller owns process lifetime.
939
+ *
940
+ * Idempotent: concurrent or repeated calls share a single drain. Safe to
941
+ * call even if nothing has been started.
942
+ *
943
+ * @example
944
+ * ```ts
945
+ * const registry = setup({ use: { counter } });
946
+ * registry.start();
947
+ * // ...later, on your own shutdown trigger:
948
+ * await registry.shutdown();
949
+ * ```
950
+ */
951
+ shutdown(): Promise<void>;
607
952
  startEnvoy(): void;
608
953
  /**
609
954
  * Starts the actor envoy for standalone server deployments.
@@ -642,6 +987,12 @@ interface QueueSendResult<TResponse = unknown> {
642
987
  * @returns {Promise<Response>}
643
988
  */
644
989
  type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
990
+ type IsAny<T> = 0 extends 1 & T ? true : false;
991
+ type LooseEventSubscribe = (eventName: string, callback: (...args: any[]) => void) => () => void;
992
+ type ActorActionMap<R> = {
993
+ [K in keyof NonNullable<R>]: NonNullable<R>[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Awaited<Return>> : never;
994
+ };
995
+ type ActionsOf<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, any, infer R> ? R : never;
645
996
  interface ActorGatewayOptions {
646
997
  skipReadyWait?: boolean;
647
998
  }
@@ -654,9 +1005,7 @@ type ActorWebSocketOptions = ActorGatewayOptions;
654
1005
  /**
655
1006
  * Maps action methods from actor definition to typed function signatures.
656
1007
  */
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;
1008
+ type ActorDefinitionActions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? Record<string, ActorActionFunction<any[], any>> : ActorActionMap<ActionsOf<AD>>;
660
1009
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
661
1010
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options: QueueSendWaitOptions): Promise<QueueSendResult<InferQueueCompleteMap<TQueues>[K]>>;
662
1011
  <K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K], options?: QueueSendNoWaitOptions): Promise<void>;
@@ -667,13 +1016,31 @@ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
667
1016
  <K extends keyof TEvents & string>(eventName: K, callback: (...args: InferEventArgs<InferSchemaMap<TEvents>[K]>) => void): () => void;
668
1017
  (eventName: keyof TEvents extends never ? string : never, callback: (...args: any[]) => void): () => void;
669
1018
  };
670
- type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
1019
+ type ActorDefinitionQueueSend<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1020
+ send: ActorQueueSend<Record<string, any>>;
1021
+ } : AD extends {
1022
+ config: {
1023
+ queues?: infer Q;
1024
+ };
1025
+ } ? Q extends QueueSchemaConfig ? {
671
1026
  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 ? {
1027
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, any, infer Q, any> ? Q extends QueueSchemaConfig ? {
1028
+ send: ActorQueueSend<Q>;
1029
+ } : {} : {};
1030
+ type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> = IsAny<AD> extends true ? {
1031
+ on: LooseEventSubscribe;
1032
+ once: LooseEventSubscribe;
1033
+ } : AD extends {
1034
+ config: {
1035
+ events?: infer E;
1036
+ };
1037
+ } ? E extends EventSchemaConfig ? {
674
1038
  on: ActorEventSubscribe<E>;
675
1039
  once: ActorEventSubscribe<E>;
676
- } : never : never;
1040
+ } : {} : AD extends BaseActorDefinition<any, any, any, any, any, any, infer E, any, any> ? E extends EventSchemaConfig ? {
1041
+ on: ActorEventSubscribe<E>;
1042
+ once: ActorEventSubscribe<E>;
1043
+ } : {} : {};
677
1044
 
678
1045
  type ActorResolutionState = ActorQuery;
679
1046
 
@@ -1099,6 +1466,7 @@ type Client<A extends Registry<any>> = ClientRaw & {
1099
1466
  };
1100
1467
 
1101
1468
  declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
1469
+ declare const RAW_STATE_SYMBOL: unique symbol;
1102
1470
  interface ActorLogger {
1103
1471
  level: any;
1104
1472
  fatal: any;
@@ -1207,7 +1575,7 @@ interface ActorQueue<TQueues extends QueueSchemaConfig = Record<never, never>> {
1207
1575
  iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterable<any>;
1208
1576
  [key: string]: any;
1209
1577
  }
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>> {
1578
+ 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
1579
  id: string;
1212
1580
  params: TConnParams;
1213
1581
  state: TConnState;
@@ -1218,6 +1586,8 @@ interface Conn<TState = unknown, TConnParams = unknown, TConnState = unknown, TV
1218
1586
  }
1219
1587
  interface ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
1220
1588
  [ACTOR_CONTEXT_INTERNAL_SYMBOL]?: unknown;
1589
+ /** Returns the raw unwrapped state without the write-through proxy. */
1590
+ [RAW_STATE_SYMBOL](): TState;
1221
1591
  state: TState;
1222
1592
  vars: TVars;
1223
1593
  readonly kv: ActorKv;
@@ -1345,7 +1715,7 @@ declare const ActorConfigSchema: z$1.ZodObject<{
1345
1715
  preloadMaxConnectionsBytes: z$1.ZodOptional<z$1.ZodNumber>;
1346
1716
  }, z$1.core.$strict>>;
1347
1717
  }, z$1.core.$strict>;
1348
- type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1718
+ type CreateState<TState, _TConnParams, _TConnState, _TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1349
1719
  state: TState;
1350
1720
  } | {
1351
1721
  createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
@@ -1358,7 +1728,7 @@ type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase e
1358
1728
  /**
1359
1729
  * @experimental
1360
1730
  */
1361
- type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1731
+ type CreateVars<TState, _TConnParams, _TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
1362
1732
  /**
1363
1733
  * @experimental
1364
1734
  */
@@ -1544,7 +1914,7 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
1544
1914
  */
1545
1915
  db: TDatabase;
1546
1916
  } | 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>;
1917
+ 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
1918
 
1549
1919
  type AgentOsActorState = {};
1550
1920
  interface AgentOsActorVars {
@@ -1666,6 +2036,16 @@ interface AgentOsActorConfigCallbacks<TConnParams> {
1666
2036
  type AgentOsActorConfig<TConnParams = undefined> = Omit<z$1.infer<typeof agentOsActorConfigSchema>, "onBeforeConnect" | "onSessionEvent" | "onPermissionRequest"> & AgentOsActorConfigCallbacks<TConnParams>;
1667
2037
  type AgentOsActorConfigInput<TConnParams = undefined> = Omit<z$1.input<typeof agentOsActorConfigSchema>, "onBeforeConnect" | "onSessionEvent" | "onPermissionRequest"> & AgentOsActorConfigCallbacks<TConnParams>;
1668
2038
 
2039
+ declare function buildCronActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2040
+ scheduleCron: (c: AgentOsActionContext<TConnParams>, options: SerializableCronJobOptions) => Promise<{
2041
+ id: string;
2042
+ }>;
2043
+ listCronJobs: (c: AgentOsActionContext<TConnParams>) => Promise<SerializableCronJobInfo[]>;
2044
+ cancelCronJob: (c: AgentOsActionContext<TConnParams>, id: string) => Promise<void>;
2045
+ };
2046
+
2047
+ declare function migrateAgentOsTables(db: RawAccess): Promise<void>;
2048
+
1669
2049
  type VirtualStat = Awaited<ReturnType<_rivet_dev_agent_os_core.AgentOs["stat"]>>;
1670
2050
  type DeleteOptions = Parameters<_rivet_dev_agent_os_core.AgentOs["delete"]>[1];
1671
2051
  declare function buildFilesystemActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
@@ -1697,16 +2077,7 @@ declare function agentOs<TConnParams = undefined>(config: AgentOsActorConfigInpu
1697
2077
  processExit: typeof processExitToken;
1698
2078
  shellData: typeof shellDataToken;
1699
2079
  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>>>;
2080
+ }, Record<never, never>, any>;
1710
2081
  declare const sessionEventToken: EventTypeToken<SessionEventPayload, any>;
1711
2082
  declare const permissionRequestToken: EventTypeToken<PermissionRequestPayload, any>;
1712
2083
  declare const vmBootedToken: EventTypeToken<VmBootedPayload, any>;
@@ -1716,6 +2087,21 @@ declare const processExitToken: EventTypeToken<ProcessExitPayload, any>;
1716
2087
  declare const shellDataToken: EventTypeToken<ShellDataPayload, any>;
1717
2088
  declare const cronEventToken: EventTypeToken<CronEventPayload, any>;
1718
2089
 
2090
+ interface VmFetchOptions {
2091
+ method?: string;
2092
+ headers?: Record<string, string>;
2093
+ body?: string | Uint8Array;
2094
+ }
2095
+ interface VmFetchResult {
2096
+ status: number;
2097
+ statusText: string;
2098
+ headers: Record<string, string>;
2099
+ body: Uint8Array;
2100
+ }
2101
+ declare function buildNetworkActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
2102
+ vmFetch: (c: AgentOsActionContext<TConnParams>, port: number, url: string, options?: VmFetchOptions) => Promise<VmFetchResult>;
2103
+ };
2104
+
1719
2105
  declare function generateToken(): string;
1720
2106
  type AgentOsRequestContext<TConnParams> = RequestContext<AgentOsActorState, TConnParams, undefined, AgentOsActorVars, undefined, DatabaseProvider<RawAccess>>;
1721
2107
  declare function buildOnRequestHandler<TConnParams>(config: AgentOsActorConfig<TConnParams>): (c: AgentOsRequestContext<TConnParams>, request: Request) => Promise<Response>;
@@ -1788,27 +2174,18 @@ declare function buildShellActions<TConnParams>(config: AgentOsActorConfig<TConn
1788
2174
  closeShell: (c: AgentOsActionContext<TConnParams>, shellId: string) => Promise<void>;
1789
2175
  };
1790
2176
 
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;
2177
+ type VirtualFileSystem = _rivet_dev_agent_os_core.PlainMountConfig["driver"];
2178
+ interface DatabaseVfsOptions {
2179
+ /** The RawAccess database handle from the actor's db provider. */
2180
+ db: RawAccess;
1809
2181
  }
1810
- declare function buildNetworkActions<TConnParams>(config: AgentOsActorConfig<TConnParams>): {
1811
- vmFetch: (c: AgentOsActionContext<TConnParams>, port: number, url: string, options?: VmFetchOptions) => Promise<VmFetchResult>;
1812
- };
2182
+ /**
2183
+ * Create a VirtualFileSystem backed by SQLite.
2184
+ *
2185
+ * The returned filesystem stores all content and metadata in the
2186
+ * `agent_os_fs_entries` table. The table must be created beforehand
2187
+ * via `migrateAgentOsTables()`.
2188
+ */
2189
+ declare function createDatabaseVfs(options: DatabaseVfsOptions): VirtualFileSystem;
1813
2190
 
1814
2191
  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 };