rivetkit 2.3.0-rc.10 → 2.3.0-rc.11

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 +105 -56
  2. package/dist/browser/client.js +128 -87
  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 +106 -66
  11. package/dist/tsup/agent-os/index.d.ts +106 -66
  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-4K3MV2MW.cjs → chunk-2NXFKPRB.cjs} +10 -10
  15. package/dist/tsup/chunk-2NXFKPRB.cjs.map +1 -0
  16. package/dist/tsup/{chunk-6BI2MS3S.js → chunk-3P2JUHWJ.js} +2 -2
  17. package/dist/tsup/{chunk-KU6VKVEK.js → chunk-4FP4FFB5.js} +18 -6
  18. package/dist/tsup/chunk-4FP4FFB5.js.map +1 -0
  19. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-BRP62GZC.js} +3 -3
  20. package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
  21. package/dist/tsup/{chunk-G34LIR7S.js → chunk-GRFBV2U7.js} +22 -7
  22. package/dist/tsup/chunk-GRFBV2U7.js.map +1 -0
  23. package/dist/tsup/{chunk-PWFGP2US.cjs → chunk-GX6W4MW3.cjs} +138 -24
  24. package/dist/tsup/chunk-GX6W4MW3.cjs.map +1 -0
  25. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  26. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  27. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  28. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  29. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-KORQB2IR.cjs} +3 -3
  30. package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
  31. package/dist/tsup/{chunk-BM3EOY7M.js → chunk-KRC4L3YB.js} +134 -20
  32. package/dist/tsup/chunk-KRC4L3YB.js.map +1 -0
  33. package/dist/tsup/{chunk-G5RULGYQ.cjs → chunk-LNP7Q6I6.cjs} +24 -9
  34. package/dist/tsup/chunk-LNP7Q6I6.cjs.map +1 -0
  35. package/dist/tsup/{chunk-Z4C3W2CQ.cjs → chunk-LW5HNCWD.cjs} +3 -3
  36. package/dist/tsup/{chunk-Z4C3W2CQ.cjs.map → chunk-LW5HNCWD.cjs.map} +1 -1
  37. package/dist/tsup/{chunk-J5P6S2LC.cjs → chunk-RDBGKI66.cjs} +25 -13
  38. package/dist/tsup/chunk-RDBGKI66.cjs.map +1 -0
  39. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-T3VCJ4PV.js} +3 -1
  40. package/dist/tsup/chunk-T3VCJ4PV.js.map +1 -0
  41. package/dist/tsup/{chunk-WU2O2KIE.js → chunk-TTLUIDVH.js} +61 -77
  42. package/dist/tsup/chunk-TTLUIDVH.js.map +1 -0
  43. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  44. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  45. package/dist/tsup/{chunk-XV52XUWU.js → chunk-WXYWDLJY.js} +4 -4
  46. package/dist/tsup/chunk-WXYWDLJY.js.map +1 -0
  47. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-XCDCURZ4.cjs} +4 -2
  48. package/dist/tsup/chunk-XCDCURZ4.cjs.map +1 -0
  49. package/dist/tsup/{chunk-TE4VCDNY.cjs → chunk-XG25CGSW.cjs} +217 -233
  50. package/dist/tsup/chunk-XG25CGSW.cjs.map +1 -0
  51. package/dist/tsup/{chunk-3LGP4JSO.cjs → chunk-Y3JBOFBG.cjs} +8 -8
  52. package/dist/tsup/{chunk-3LGP4JSO.cjs.map → chunk-Y3JBOFBG.cjs.map} +1 -1
  53. package/dist/tsup/{chunk-CMYS77J6.js → chunk-YRQ4F5CD.js} +3 -3
  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-CTwe3WwC.d.cts} +69 -19
  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-De5UVu0V.d.ts} +69 -19
  68. package/dist/tsup/{context-B_IWbWne.d.ts → context-DPHISlUi.d.ts} +8 -8
  69. package/dist/tsup/{context-CUrQ9MHc.d.cts → context-Dmj477Uh.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 +501 -315
  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 +405 -219
  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 +48 -41
  110. package/src/actor/contexts/index.ts +7 -2
  111. package/src/actor/definition.ts +11 -14
  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 +90 -54
  125. package/src/client/actor-conn.ts +8 -36
  126. package/src/client/actor-handle.ts +67 -50
  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 +0 -149
  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 +63 -72
  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 +47 -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 +7 -7
  169. package/src/registry/index.ts +70 -71
  170. package/src/registry/napi-runtime.ts +7 -2
  171. package/src/registry/native-validation.ts +10 -12
  172. package/src/registry/native.ts +179 -153
  173. package/src/registry/process-metrics.ts +238 -0
  174. package/src/registry/runtime.ts +1 -3
  175. package/src/registry/wasm-runtime.ts +3 -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-6BI2MS3S.js.map → chunk-3P2JUHWJ.js.map} +0 -0
  205. /package/dist/tsup/{chunk-CMYS77J6.js.map → chunk-YRQ4F5CD.js.map} +0 -0
@@ -9,22 +9,21 @@ import {
9
9
  type SpanStatusInput,
10
10
  type Traces,
11
11
  } from "@rivetkit/traces";
12
- import { ActorMetrics, type StartupTimingKey } from "@/actor/metrics";
13
12
  import invariant from "invariant";
13
+ import { ActorMetrics, type StartupTimingKey } from "@/actor/metrics";
14
14
  import type { Client } from "@/client/client";
15
+ import type { ActorKey } from "@/client/query";
15
16
  import { getBaseLogger, getIncludeTarget, type Logger } from "@/common/log";
16
17
  import { stringifyError } from "@/common/utils";
17
18
  import type { UniversalWebSocket } from "@/common/websocket-interface";
18
19
  import { ActorInspector } from "@/inspector/actor-inspector";
19
- import type { ActorKey } from "@/client/query";
20
20
  import type { Registry } from "@/mod";
21
21
  import {
22
22
  ACTOR_VERSIONED,
23
23
  CONN_VERSIONED,
24
24
  } from "@/schemas/actor-persist/versioned";
25
- import { EXTRA_ERROR_LOG } from "@/utils";
25
+ import { EXTRA_ERROR_LOG, promiseWithResolvers } from "@/utils";
26
26
  import { getRivetExperimentalOtel } from "@/utils/env-vars";
27
- import { promiseWithResolvers } from "@/utils";
28
27
  import {
29
28
  type Actions,
30
29
  type ActorConfig,
@@ -32,16 +31,13 @@ import {
32
31
  ActorConfigSchema,
33
32
  getRunFunction,
34
33
  } from "../config";
35
- import type { ConnDriver } from "../conn/driver";
36
- import { createHttpDriver } from "../conn/drivers/http";
37
34
  import {
38
- HibernatableWebSocketAckState,
39
35
  handleInboundHibernatableWebSocketMessage as applyInboundHibernatableWebSocketMessage,
36
+ HibernatableWebSocketAckState,
40
37
  } from "../conn/hibernatable-websocket-ack-state";
41
38
  import {
42
- CONN_DRIVER_SYMBOL,
43
- CONN_STATE_MANAGER_SYMBOL,
44
39
  type AnyConn,
40
+ CONN_STATE_MANAGER_SYMBOL,
45
41
  type Conn,
46
42
  type ConnId,
47
43
  } from "../conn/mod";
@@ -50,7 +46,7 @@ import {
50
46
  type PersistedConn,
51
47
  } from "../conn/persisted";
52
48
  import {
53
- ActionContext,
49
+ type ActionContext,
54
50
  ActorContext,
55
51
  RequestContext,
56
52
  WebSocketContext,
@@ -79,20 +75,16 @@ import {
79
75
  import { ConnectionManager } from "./connection-manager";
80
76
  import { EventManager } from "./event-manager";
81
77
  import { KEYS, workflowStoragePrefix } from "./keys";
82
- import {
83
- type PreloadedEntries,
84
- type PreloadHit,
85
- type PreloadMap,
86
- } from "./preload-map";
87
78
  import {
88
79
  convertActorFromBarePersisted,
89
80
  type PersistedActor,
90
81
  } from "./persisted";
82
+ import type { PreloadedEntries, PreloadMap } from "./preload-map";
91
83
  import { QueueManager } from "./queue-manager";
92
84
  import { ScheduleManager } from "./schedule-manager";
93
85
  import { type SaveStateOptions, StateManager } from "./state-manager";
94
- import { TrackedWebSocket } from "./tracked-websocket";
95
86
  import { ActorTracesDriver } from "./traces-driver";
87
+ import { TrackedWebSocket } from "./tracked-websocket";
96
88
  import { WriteCollector } from "./write-collector";
97
89
 
98
90
  export type { SaveStateOptions };
@@ -215,14 +207,14 @@ const ACTIVE_ASYNC_REGION_ERROR_MESSAGES: Record<
215
207
  * only on `ActorInstance`.
216
208
  */
217
209
  export interface BaseActorInstance<
218
- S = any,
219
- CP = any,
220
- CS = any,
221
- V = any,
222
- I = any,
223
- DB extends AnyDatabaseProvider = AnyDatabaseProvider,
224
- E extends EventSchemaConfig = Record<never, never>,
225
- Q extends QueueSchemaConfig = Record<never, never>,
210
+ _S = any,
211
+ _CP = any,
212
+ _CS = any,
213
+ _V = any,
214
+ _I = any,
215
+ _DB extends AnyDatabaseProvider = AnyDatabaseProvider,
216
+ _E extends EventSchemaConfig = Record<never, never>,
217
+ _Q extends QueueSchemaConfig = Record<never, never>,
226
218
  > {
227
219
  readonly id: string;
228
220
  readonly isStopping: boolean;
@@ -1274,7 +1266,7 @@ export class ActorInstance<
1274
1266
  "actor.onBeforeActionResponse",
1275
1267
  { "rivet.action.name": actionName },
1276
1268
  () =>
1277
- this.#config.onBeforeActionResponse!(
1269
+ this.#config.onBeforeActionResponse?.(
1278
1270
  this.actorContext,
1279
1271
  actionName,
1280
1272
  args,
@@ -1406,7 +1398,7 @@ export class ActorInstance<
1406
1398
 
1407
1399
  // NOTE: This is async and will run in the background
1408
1400
  const voidOrPromise = this.#traces.withSpan(span, () =>
1409
- this.#config.onWebSocket!(ctx, trackedWebSocket),
1401
+ this.#config.onWebSocket?.(ctx, trackedWebSocket),
1410
1402
  );
1411
1403
 
1412
1404
  // Save changes from the WebSocket open
@@ -1882,7 +1874,7 @@ export class ActorInstance<
1882
1874
  "actor.createVars",
1883
1875
  undefined,
1884
1876
  () => {
1885
- const dataOrPromise = createVars!(
1877
+ const dataOrPromise = createVars?.(
1886
1878
  this.actorContext as any,
1887
1879
  this.driver.getContext(this.#actorId),
1888
1880
  );
@@ -2084,7 +2076,7 @@ export class ActorInstance<
2084
2076
  }
2085
2077
  }
2086
2078
 
2087
- async #setupDatabase(preload?: PreloadMap) {
2079
+ async #setupDatabase(_preload?: PreloadMap) {
2088
2080
  if (!("db" in this.#config) || !this.#config.db) {
2089
2081
  return;
2090
2082
  }
@@ -2099,14 +2091,14 @@ export class ActorInstance<
2099
2091
  overrideRawDatabaseClient: this.driver
2100
2092
  .overrideRawDatabaseClient
2101
2093
  ? () =>
2102
- this.driver.overrideRawDatabaseClient!(
2094
+ this.driver.overrideRawDatabaseClient?.(
2103
2095
  this.#actorId,
2104
2096
  )
2105
2097
  : undefined,
2106
2098
  overrideDrizzleDatabaseClient: this.driver
2107
2099
  .overrideDrizzleDatabaseClient
2108
2100
  ? () =>
2109
- this.driver.overrideDrizzleDatabaseClient!(
2101
+ this.driver.overrideDrizzleDatabaseClient?.(
2110
2102
  this.#actorId,
2111
2103
  )
2112
2104
  : undefined,
package/src/actor/keys.ts CHANGED
@@ -135,7 +135,7 @@ export function deserializeActorKey(keyString: string | undefined): ActorKey {
135
135
  // Add the last part
136
136
  if (escaping) {
137
137
  // Incomplete escape at the end - treat as literal backslash
138
- parts.push(currentPart + "\\");
138
+ parts.push(`${currentPart}\\`);
139
139
  } else if (isEmptyStringMarker) {
140
140
  parts.push("");
141
141
  } else if (currentPart !== "" || parts.length > 0) {
package/src/actor/mod.ts CHANGED
@@ -14,6 +14,26 @@ export type {
14
14
  UniversalWebSocket,
15
15
  } from "@/common/websocket-interface";
16
16
  export type * from "./config";
17
+ export type {
18
+ ActionContextOf,
19
+ BeforeActionResponseContextOf,
20
+ BeforeConnectContextOf,
21
+ ConnContextOf,
22
+ ConnectContextOf,
23
+ ConnInitContextOf,
24
+ CreateConnStateContextOf,
25
+ CreateContextOf,
26
+ CreateVarsContextOf,
27
+ DestroyContextOf,
28
+ DisconnectContextOf,
29
+ MigrateContextOf,
30
+ RequestContextOf,
31
+ RunContextOf,
32
+ SleepContextOf,
33
+ StateChangeContextOf,
34
+ WakeContextOf,
35
+ WebSocketContextOf,
36
+ } from "./contexts";
17
37
  export type {
18
38
  AnyActorDefinition,
19
39
  AnyActorInstance,
@@ -35,24 +55,4 @@ export {
35
55
  UserError,
36
56
  type UserErrorOptions,
37
57
  } from "./errors";
38
- export type {
39
- ActionContextOf,
40
- BeforeActionResponseContextOf,
41
- BeforeConnectContextOf,
42
- ConnectContextOf,
43
- ConnContextOf,
44
- ConnInitContextOf,
45
- CreateConnStateContextOf,
46
- CreateContextOf,
47
- CreateVarsContextOf,
48
- DestroyContextOf,
49
- DisconnectContextOf,
50
- MigrateContextOf,
51
- RequestContextOf,
52
- RunContextOf,
53
- SleepContextOf,
54
- StateChangeContextOf,
55
- WakeContextOf,
56
- WebSocketContextOf,
57
- } from "./contexts";
58
58
  export { event, queue, type Type } from "./schema";
@@ -69,7 +69,7 @@ export type EventSchemaConfig<TContext = any> = Record<
69
69
  string,
70
70
  EventSchema<TContext>
71
71
  >;
72
- export type QueueSchemaConfig<TContext = any> = Record<string, QueueSchema>;
72
+ export type QueueSchemaConfig<_TContext = any> = Record<string, QueueSchema>;
73
73
  export type AnySchemaConfig = EventSchemaConfig | QueueSchemaConfig;
74
74
 
75
75
  /** @deprecated Use `EventSchema` or `QueueSchema`. */
@@ -155,7 +155,7 @@ export function hasSchemaConfigKey<T extends AnySchemaConfig>(
155
155
  if (!schemas) {
156
156
  return false;
157
157
  }
158
- return Object.prototype.hasOwnProperty.call(schemas, key);
158
+ return Object.hasOwn(schemas, key);
159
159
  }
160
160
 
161
161
  export function getEventCanSubscribe<TContext = any>(
@@ -1,8 +1,7 @@
1
- import { AgentOs, createInMemoryFileSystem } from "@rivet-dev/agent-os-core";
2
1
  import type { AgentOsOptions, MountConfig } from "@rivet-dev/agent-os-core";
3
- import type { DatabaseProvider } from "@/common/database/config";
4
- import { actor, event } from "@/actor/mod";
5
- import type { RawAccess } from "@/common/database/config";
2
+ import { AgentOs, createInMemoryFileSystem } from "@rivet-dev/agent-os-core";
3
+ import { actor, event, type ActorDefinition } from "@/actor/mod";
4
+ import type { DatabaseProvider, RawAccess } from "@/common/database/config";
6
5
  import { db } from "@/common/database/mod";
7
6
  import {
8
7
  type AgentOsActorConfig,
@@ -141,10 +140,41 @@ function runHook<TConnParams>(
141
140
 
142
141
  export function agentOs<TConnParams = undefined>(
143
142
  config: AgentOsActorConfigInput<TConnParams>,
144
- ) {
143
+ ): ActorDefinition<
144
+ AgentOsActorState,
145
+ TConnParams,
146
+ undefined,
147
+ AgentOsActorVars,
148
+ undefined,
149
+ DatabaseProvider<RawAccess>,
150
+ {
151
+ sessionEvent: typeof sessionEventToken;
152
+ permissionRequest: typeof permissionRequestToken;
153
+ vmBooted: typeof vmBootedToken;
154
+ vmShutdown: typeof vmShutdownToken;
155
+ processOutput: typeof processOutputToken;
156
+ processExit: typeof processExitToken;
157
+ shellData: typeof shellDataToken;
158
+ cronEvent: typeof cronEventToken;
159
+ },
160
+ Record<never, never>,
161
+ any
162
+ > {
145
163
  const parsedConfig = agentOsActorConfigSchema.parse(
146
164
  config,
147
165
  ) as AgentOsActorConfig<TConnParams>;
166
+ const actions = {
167
+ ...buildSessionActions(parsedConfig),
168
+ ...buildPromptActions(parsedConfig),
169
+ ...buildConfigActions(parsedConfig),
170
+ ...buildSessionPersistenceActions(parsedConfig),
171
+ ...buildProcessActions(parsedConfig),
172
+ ...buildFilesystemActions(parsedConfig),
173
+ ...buildPreviewActions(parsedConfig),
174
+ ...buildShellActions(parsedConfig),
175
+ ...buildCronActions(parsedConfig),
176
+ ...buildNetworkActions(parsedConfig),
177
+ };
148
178
 
149
179
  return actor<
150
180
  AgentOsActorState,
@@ -163,7 +193,8 @@ export function agentOs<TConnParams = undefined>(
163
193
  shellData: typeof shellDataToken;
164
194
  cronEvent: typeof cronEventToken;
165
195
  },
166
- Record<never, never>
196
+ Record<never, never>,
197
+ typeof actions
167
198
  >({
168
199
  options: {
169
200
  sleepGracePeriod: 900_000,
@@ -236,18 +267,7 @@ export function agentOs<TConnParams = undefined>(
236
267
 
237
268
  c.broadcast("vmShutdown", { reason: "destroy" as const });
238
269
  },
239
- actions: {
240
- ...buildSessionActions(parsedConfig),
241
- ...buildPromptActions(parsedConfig),
242
- ...buildConfigActions(parsedConfig),
243
- ...buildSessionPersistenceActions(parsedConfig),
244
- ...buildProcessActions(parsedConfig),
245
- ...buildFilesystemActions(parsedConfig),
246
- ...buildPreviewActions(parsedConfig),
247
- ...buildShellActions(parsedConfig),
248
- ...buildCronActions(parsedConfig),
249
- ...buildNetworkActions(parsedConfig),
250
- },
270
+ actions,
251
271
  });
252
272
  }
253
273
 
@@ -1,7 +1,6 @@
1
1
  import crypto from "node:crypto";
2
- import type { DatabaseProvider } from "@/common/database/config";
3
2
  import type { RequestContext } from "@/actor/config";
4
- import type { RawAccess } from "@/common/database/config";
3
+ import type { DatabaseProvider, RawAccess } from "@/common/database/config";
5
4
  import type { AgentOsActorConfig } from "../config";
6
5
  import type {
7
6
  AgentOsActionContext,
@@ -140,11 +140,11 @@ export function subscribeToSession<TConnParams>(
140
140
  );
141
141
 
142
142
  // Persist event to SQLite for sleep/wake recovery.
143
- persistSessionEvent(c, sessionId, event).catch((err) =>
143
+ persistSessionEvent(c, sessionId, event).catch((error) =>
144
144
  c.log.error({
145
145
  msg: "agent-os failed to persist session event",
146
146
  sessionId,
147
- error: err,
147
+ error,
148
148
  }),
149
149
  );
150
150
 
@@ -3,8 +3,8 @@ import type {
3
3
  JsonRpcNotification,
4
4
  PermissionRequest,
5
5
  } from "@rivet-dev/agent-os-core";
6
- import type { ActorContext, BeforeConnectContext } from "@/actor/config";
7
6
  import { z } from "zod/v4";
7
+ import type { ActorContext, BeforeConnectContext } from "@/actor/config";
8
8
  import type { AgentOsActorState, AgentOsActorVars } from "./types";
9
9
 
10
10
  const zFunction = <
@@ -497,7 +497,7 @@ export function createDatabaseVfs(
497
497
  return backend.stat(p);
498
498
  },
499
499
 
500
- async link(oldPath: string, newPath: string): Promise<void> {
500
+ async link(_oldPath: string, _newPath: string): Promise<void> {
501
501
  throwENOSYS("link");
502
502
  },
503
503
 
@@ -1,14 +1,18 @@
1
1
  // Database migration
2
+
3
+ // Cron actions
4
+ export { buildCronActions } from "./actor/cron";
2
5
  export { migrateAgentOsTables } from "./actor/db";
3
- // Database-backed VFS
4
- export {
5
- createDatabaseVfs,
6
- type DatabaseVfsOptions,
7
- } from "./fs/database-vfs";
8
6
  // Filesystem actions
9
7
  export { buildFilesystemActions } from "./actor/filesystem";
10
8
  // Actor factory and VM lifecycle helpers
11
9
  export { agentOs, ensureVm, runHook, syncPreventSleep } from "./actor/index";
10
+ // Network actions
11
+ export {
12
+ buildNetworkActions,
13
+ type VmFetchOptions,
14
+ type VmFetchResult,
15
+ } from "./actor/network";
12
16
  // Preview actions
13
17
  export {
14
18
  buildOnRequestHandler,
@@ -27,20 +31,17 @@ export {
27
31
  } from "./actor/session";
28
32
  // Shell actions
29
33
  export { buildShellActions } from "./actor/shell";
30
- // Cron actions
31
- export { buildCronActions } from "./actor/cron";
32
- // Network actions
33
- export {
34
- buildNetworkActions,
35
- type VmFetchOptions,
36
- type VmFetchResult,
37
- } from "./actor/network";
38
34
  // Config schema and types
39
35
  export {
40
36
  type AgentOsActorConfig,
41
37
  type AgentOsActorConfigInput,
42
38
  agentOsActorConfigSchema,
43
39
  } from "./config";
40
+ // Database-backed VFS
41
+ export {
42
+ createDatabaseVfs,
43
+ type DatabaseVfsOptions,
44
+ } from "./fs/database-vfs";
44
45
  // Domain types and event payloads
45
46
  export type {
46
47
  AgentOsActionContext,
@@ -48,12 +49,12 @@ export type {
48
49
  AgentOsActorVars,
49
50
  AgentOsEvents,
50
51
  CronEventPayload,
52
+ PermissionRequestPayload,
51
53
  PersistedSessionEvent,
52
54
  PersistedSessionRecord,
53
- PermissionRequestPayload,
54
- PromptResult,
55
55
  ProcessExitPayload,
56
56
  ProcessOutputPayload,
57
+ PromptResult,
57
58
  SerializableCronAction,
58
59
  SerializableCronJobOptions,
59
60
  SessionEventPayload,
@@ -1,6 +1,6 @@
1
1
  import type {
2
- BaseActorDefinition,
3
2
  AnyActorDefinition,
3
+ BaseActorDefinition,
4
4
  } from "@/actor/definition";
5
5
  import type {
6
6
  EventSchemaConfig,
@@ -31,6 +31,13 @@ export type ActorActionFunction<
31
31
  ...args: Args extends [unknown, ...infer Rest] ? Rest : Args
32
32
  ) => Promise<Response>;
33
33
 
34
+ type IsAny<T> = 0 extends 1 & T ? true : false;
35
+
36
+ type LooseEventSubscribe = (
37
+ eventName: string,
38
+ callback: (...args: any[]) => void,
39
+ ) => () => void;
40
+
34
41
  export interface ActorGatewayOptions {
35
42
  skipReadyWait?: boolean;
36
43
  }
@@ -41,7 +48,8 @@ export function resolveActorGatewayOptions(
41
48
  defaults: ActorGatewayOptions = {},
42
49
  overrides?: ActorGatewayOptions,
43
50
  ): ResolvedActorGatewayOptions {
44
- const skipReadyWait = overrides?.skipReadyWait ?? defaults.skipReadyWait ?? false;
51
+ const skipReadyWait =
52
+ overrides?.skipReadyWait ?? defaults.skipReadyWait ?? false;
45
53
 
46
54
  return {
47
55
  skipReadyWait,
@@ -63,25 +71,35 @@ export type ActorWebSocketOptions = ActorGatewayOptions;
63
71
  */
64
72
  export type ActorDefinitionActions<AD extends AnyActorDefinition> =
65
73
  // biome-ignore lint/suspicious/noExplicitAny: safe to use any here
66
- AD extends BaseActorDefinition<
67
- any,
68
- any,
69
- any,
70
- any,
71
- any,
72
- any,
73
- any,
74
- any,
75
- infer R
76
- >
77
- ? {
78
- [K in keyof R]: R[K] extends (
79
- ...args: infer Args
80
- ) => infer Return
81
- ? ActorActionFunction<Args, Return>
82
- : never;
83
- }
84
- : never;
74
+ IsAny<AD> extends true
75
+ ? Record<string, ActorActionFunction<any[], any>>
76
+ : AD extends { config: { actions?: infer R } }
77
+ ? {
78
+ [K in keyof R]: R[K] extends (
79
+ ...args: infer Args
80
+ ) => infer Return
81
+ ? ActorActionFunction<Args, Return>
82
+ : never;
83
+ }
84
+ : AD extends BaseActorDefinition<
85
+ any,
86
+ any,
87
+ any,
88
+ any,
89
+ any,
90
+ any,
91
+ any,
92
+ any,
93
+ infer R
94
+ >
95
+ ? {
96
+ [K in keyof R]: R[K] extends (
97
+ ...args: infer Args
98
+ ) => infer Return
99
+ ? ActorActionFunction<Args, Return>
100
+ : never;
101
+ }
102
+ : {};
85
103
 
86
104
  type ActorQueueSend<TQueues extends QueueSchemaConfig> = {
87
105
  <K extends keyof TQueues & string>(
@@ -119,39 +137,57 @@ type ActorEventSubscribe<TEvents extends EventSchemaConfig> = {
119
137
 
120
138
  export type ActorDefinitionQueueSend<AD extends AnyActorDefinition> =
121
139
  // biome-ignore lint/suspicious/noExplicitAny: safe to use any here
122
- AD extends BaseActorDefinition<
123
- any,
124
- any,
125
- any,
126
- any,
127
- any,
128
- any,
129
- any,
130
- infer Q,
131
- any
132
- >
133
- ? Q extends QueueSchemaConfig
134
- ? { send: ActorQueueSend<Q> }
135
- : never
136
- : never;
140
+ IsAny<AD> extends true
141
+ ? { send: ActorQueueSend<Record<string, any>> }
142
+ : AD extends { config: { queues?: infer Q } }
143
+ ? Q extends QueueSchemaConfig
144
+ ? { send: ActorQueueSend<Q> }
145
+ : {}
146
+ : AD extends BaseActorDefinition<
147
+ any,
148
+ any,
149
+ any,
150
+ any,
151
+ any,
152
+ any,
153
+ any,
154
+ infer Q,
155
+ any
156
+ >
157
+ ? Q extends QueueSchemaConfig
158
+ ? { send: ActorQueueSend<Q> }
159
+ : {}
160
+ : {};
137
161
 
138
162
  export type ActorDefinitionEventSubscriptions<AD extends AnyActorDefinition> =
139
163
  // biome-ignore lint/suspicious/noExplicitAny: safe to use any here
140
- AD extends BaseActorDefinition<
141
- any,
142
- any,
143
- any,
144
- any,
145
- any,
146
- any,
147
- infer E,
148
- any,
149
- any
150
- >
151
- ? E extends EventSchemaConfig
152
- ? {
153
- on: ActorEventSubscribe<E>;
154
- once: ActorEventSubscribe<E>;
155
- }
156
- : never
157
- : never;
164
+ IsAny<AD> extends true
165
+ ? {
166
+ on: LooseEventSubscribe;
167
+ once: LooseEventSubscribe;
168
+ }
169
+ : AD extends { config: { events?: infer E } }
170
+ ? E extends EventSchemaConfig
171
+ ? {
172
+ on: ActorEventSubscribe<E>;
173
+ once: ActorEventSubscribe<E>;
174
+ }
175
+ : {}
176
+ : AD extends BaseActorDefinition<
177
+ any,
178
+ any,
179
+ any,
180
+ any,
181
+ any,
182
+ any,
183
+ infer E,
184
+ any,
185
+ any
186
+ >
187
+ ? E extends EventSchemaConfig
188
+ ? {
189
+ on: ActorEventSubscribe<E>;
190
+ once: ActorEventSubscribe<E>;
191
+ }
192
+ : {}
193
+ : {};
@@ -14,6 +14,7 @@ import {
14
14
  type ToServer as ToServerJson,
15
15
  ToServerSchema,
16
16
  } from "@/common/client-protocol-zod";
17
+ import type { JsonCompatValue } from "@/common/encoding";
17
18
  import {
18
19
  type Encoding,
19
20
  inputDataToBuffer,
@@ -93,8 +94,6 @@ interface EventSubscriptions<Args extends Array<unknown>> {
93
94
  once: boolean;
94
95
  }
95
96
 
96
- const DEFAULT_MAX_INCOMING_MESSAGE_SIZE = 65_536;
97
-
98
97
  /**
99
98
  * A function that unsubscribes from an event.
100
99
  *
@@ -785,12 +784,10 @@ export class ActorConnRaw {
785
784
  }
786
785
 
787
786
  // Check if this is an actor scheduling error and try to get more details
788
- let errorToThrow = new errors.ActorError(
789
- group,
790
- code,
791
- message,
792
- { metadata, actor },
793
- );
787
+ let errorToThrow = new errors.ActorError(group, code, message, {
788
+ metadata,
789
+ actor,
790
+ });
794
791
  if (errors.isSchedulingError(group, code) && this.#actorId) {
795
792
  const schedulingError = await checkForSchedulingError(
796
793
  group,
@@ -1272,7 +1269,8 @@ export class ActorConnRaw {
1272
1269
  name: msg.body.val.name,
1273
1270
  args: bufferToArrayBuffer(
1274
1271
  encodeCborCompat(
1275
- msg.body.val.args,
1272
+ msg.body.val
1273
+ .args as JsonCompatValue,
1276
1274
  ),
1277
1275
  ),
1278
1276
  },
@@ -1283,34 +1281,8 @@ export class ActorConnRaw {
1283
1281
  }
1284
1282
  },
1285
1283
  );
1286
- const serializedLength = messageLength(messageSerialized);
1287
- if (
1288
- serializedLength > DEFAULT_MAX_INCOMING_MESSAGE_SIZE &&
1289
- message.body.tag === "ActionRequest"
1290
- ) {
1291
- const actionId = Number(message.body.val.id);
1292
- const inFlight = this.#takeActionInFlight(actionId);
1293
- const error = new errors.ActorError(
1294
- "message",
1295
- "incoming_too_long",
1296
- "Incoming message too long",
1297
- {
1298
- maxSize: DEFAULT_MAX_INCOMING_MESSAGE_SIZE,
1299
- actualSize: serializedLength,
1300
- },
1301
- );
1302
- logger().warn({
1303
- msg: "rejecting oversized connection action request",
1304
- actionId,
1305
- actionName: inFlight.name,
1306
- actualSize: serializedLength,
1307
- maxSize: DEFAULT_MAX_INCOMING_MESSAGE_SIZE,
1308
- });
1309
- inFlight.reject(error);
1310
- this.#dispatchActorError(error);
1311
- return;
1312
- }
1313
1284
  this.#websocket.send(messageSerialized);
1285
+ const serializedLength = messageLength(messageSerialized);
1314
1286
  logger().trace({
1315
1287
  msg: "sent websocket message",
1316
1288
  len: serializedLength,