rivetkit 2.3.0-rc.9 → 2.3.1

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 (226) hide show
  1. package/dist/browser/client.d.ts +511 -62
  2. package/dist/browser/client.js +230 -174
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +53 -23
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +4 -2
  7. package/dist/tsup/actor/errors.cjs.map +1 -1
  8. package/dist/tsup/actor/errors.d.cts +1 -1
  9. package/dist/tsup/actor/errors.d.ts +1 -1
  10. package/dist/tsup/actor/errors.js +3 -1
  11. package/dist/tsup/agent-os/index.cjs +2163 -2087
  12. package/dist/tsup/agent-os/index.cjs.map +1 -1
  13. package/dist/tsup/agent-os/index.d.cts +509 -69
  14. package/dist/tsup/agent-os/index.d.ts +509 -69
  15. package/dist/tsup/agent-os/index.js +2163 -2087
  16. package/dist/tsup/agent-os/index.js.map +1 -1
  17. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-3MHDOUD7.cjs} +73 -3
  18. package/dist/tsup/chunk-3MHDOUD7.cjs.map +1 -0
  19. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-4FC7TVS6.cjs} +8 -4
  20. package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
  21. package/dist/tsup/{chunk-4CGA6QJO.cjs → chunk-4UUEB43Y.cjs} +24 -9
  22. package/dist/tsup/chunk-4UUEB43Y.cjs.map +1 -0
  23. package/dist/tsup/{chunk-GVTOE34S.cjs → chunk-5IWLUJ6W.cjs} +222 -235
  24. package/dist/tsup/chunk-5IWLUJ6W.cjs.map +1 -0
  25. package/dist/tsup/{chunk-MMMEZM5J.js → chunk-H6VVZMWN.js} +4 -4
  26. package/dist/tsup/chunk-H6VVZMWN.js.map +1 -0
  27. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
  28. package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
  29. package/dist/tsup/{chunk-H7P7WR2Y.js → chunk-I35VSLEM.js} +6 -6
  30. package/dist/tsup/chunk-I35VSLEM.js.map +1 -0
  31. package/dist/tsup/{chunk-H37XQU3I.js → chunk-JBUZRPY5.js} +2 -2
  32. package/dist/tsup/{chunk-CPA4Y3RG.cjs → chunk-JLJJZYCJ.cjs} +10 -10
  33. package/dist/tsup/chunk-JLJJZYCJ.cjs.map +1 -0
  34. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
  35. package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
  36. package/dist/tsup/{chunk-VRCIXJRN.js → chunk-L2X3YFER.js} +64 -10
  37. package/dist/tsup/chunk-L2X3YFER.js.map +1 -0
  38. package/dist/tsup/{chunk-Y5NSCZA2.cjs → chunk-MNHKOS6L.cjs} +72 -18
  39. package/dist/tsup/chunk-MNHKOS6L.cjs.map +1 -0
  40. package/dist/tsup/{chunk-KJTA3ATT.js → chunk-NERUIBOT.js} +22 -7
  41. package/dist/tsup/chunk-NERUIBOT.js.map +1 -0
  42. package/dist/tsup/{chunk-4WPEZBK4.cjs → chunk-OST76LRW.cjs} +10 -10
  43. package/dist/tsup/chunk-OST76LRW.cjs.map +1 -0
  44. package/dist/tsup/{chunk-MALSPBAF.cjs → chunk-OZBCXBVP.cjs} +3 -3
  45. package/dist/tsup/{chunk-MALSPBAF.cjs.map → chunk-OZBCXBVP.cjs.map} +1 -1
  46. package/dist/tsup/{chunk-F3Q5BFQ6.js → chunk-PT6OIW5E.js} +66 -79
  47. package/dist/tsup/chunk-PT6OIW5E.js.map +1 -0
  48. package/dist/tsup/{chunk-W7EYSYVI.js → chunk-R6KPN5EW.js} +134 -20
  49. package/dist/tsup/chunk-R6KPN5EW.js.map +1 -0
  50. package/dist/tsup/{chunk-VJFRBJVQ.cjs → chunk-V5KMAMX3.cjs} +138 -24
  51. package/dist/tsup/chunk-V5KMAMX3.cjs.map +1 -0
  52. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
  53. package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
  54. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-XIX5DOZN.js} +72 -2
  55. package/dist/tsup/chunk-XIX5DOZN.js.map +1 -0
  56. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
  57. package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
  58. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-ZZ3WBRPD.js} +7 -3
  59. package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
  60. package/dist/tsup/client/mod.cjs +9 -9
  61. package/dist/tsup/client/mod.d.cts +5 -5
  62. package/dist/tsup/client/mod.d.ts +5 -5
  63. package/dist/tsup/client/mod.js +8 -8
  64. package/dist/tsup/common/log.cjs +3 -3
  65. package/dist/tsup/common/log.js +2 -2
  66. package/dist/tsup/common/websocket.cjs +4 -4
  67. package/dist/tsup/common/websocket.js +3 -3
  68. package/dist/tsup/{config-Ca8dN4cS.d.cts → config-CzvopP5m.d.cts} +544 -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/{config-0Ta55UV0.d.ts → config-DZuT7tcp.d.ts} +544 -23
  72. package/dist/tsup/context-CyAdY-aA.d.ts +128 -0
  73. package/dist/tsup/context-sNB28g0N.d.cts +128 -0
  74. package/dist/tsup/db/drizzle.cjs +3 -3
  75. package/dist/tsup/db/drizzle.d.cts +1 -1
  76. package/dist/tsup/db/drizzle.d.ts +1 -1
  77. package/dist/tsup/db/drizzle.js +1 -1
  78. package/dist/tsup/db/mod.cjs +2 -2
  79. package/dist/tsup/db/mod.d.cts +2 -2
  80. package/dist/tsup/db/mod.d.ts +2 -2
  81. package/dist/tsup/db/mod.js +1 -1
  82. package/dist/tsup/dynamic/mod.cjs +24 -0
  83. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  84. package/dist/tsup/dynamic/mod.d.cts +37 -0
  85. package/dist/tsup/dynamic/mod.d.ts +37 -0
  86. package/dist/tsup/dynamic/mod.js +24 -0
  87. package/dist/tsup/dynamic/mod.js.map +1 -0
  88. package/dist/tsup/inspector/mod.cjs +6 -6
  89. package/dist/tsup/inspector/mod.js +5 -5
  90. package/dist/tsup/inspector-tab/mod.cjs +173 -0
  91. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  92. package/dist/tsup/inspector-tab/mod.d.cts +250 -0
  93. package/dist/tsup/inspector-tab/mod.d.ts +250 -0
  94. package/dist/tsup/inspector-tab/mod.js +173 -0
  95. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  96. package/dist/tsup/mod.cjs +758 -348
  97. package/dist/tsup/mod.cjs.map +1 -1
  98. package/dist/tsup/mod.d.cts +5 -5
  99. package/dist/tsup/mod.d.ts +5 -5
  100. package/dist/tsup/mod.js +662 -252
  101. package/dist/tsup/mod.js.map +1 -1
  102. package/dist/tsup/test/mod.cjs +21 -18
  103. package/dist/tsup/test/mod.cjs.map +1 -1
  104. package/dist/tsup/test/mod.d.cts +4 -4
  105. package/dist/tsup/test/mod.d.ts +4 -4
  106. package/dist/tsup/test/mod.js +18 -15
  107. package/dist/tsup/test/mod.js.map +1 -1
  108. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-CqDnC_PS.d.cts} +2 -1
  109. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-CqDnC_PS.d.ts} +2 -1
  110. package/dist/tsup/utils.cjs +3 -3
  111. package/dist/tsup/utils.d.cts +1 -1
  112. package/dist/tsup/utils.d.ts +1 -1
  113. package/dist/tsup/utils.js +2 -2
  114. package/dist/tsup/workflow/mod.cjs +383 -322
  115. package/dist/tsup/workflow/mod.cjs.map +1 -1
  116. package/dist/tsup/workflow/mod.d.cts +8 -8
  117. package/dist/tsup/workflow/mod.d.ts +8 -8
  118. package/dist/tsup/workflow/mod.js +360 -299
  119. package/dist/tsup/workflow/mod.js.map +1 -1
  120. package/package.json +35 -14
  121. package/src/actor/config.ts +173 -51
  122. package/src/actor/contexts/index.ts +7 -2
  123. package/src/actor/definition.ts +17 -19
  124. package/src/actor/driver.ts +3 -3
  125. package/src/actor/errors.ts +20 -3
  126. package/src/actor/instance/mod.ts +26 -34
  127. package/src/actor/keys.ts +1 -1
  128. package/src/actor/mod.ts +22 -20
  129. package/src/actor/schema.ts +2 -2
  130. package/src/agent-os/actor/index.ts +38 -18
  131. package/src/agent-os/actor/preview.ts +1 -2
  132. package/src/agent-os/actor/session.ts +2 -2
  133. package/src/agent-os/config.ts +1 -1
  134. package/src/agent-os/fs/database-vfs.ts +1 -1
  135. package/src/agent-os/index.ts +16 -15
  136. package/src/client/actor-common.ts +87 -54
  137. package/src/client/actor-conn.ts +8 -36
  138. package/src/client/actor-handle.ts +69 -51
  139. package/src/client/actor-query.ts +5 -5
  140. package/src/client/errors.ts +1 -1
  141. package/src/client/lifecycle-errors.ts +2 -4
  142. package/src/client/query.ts +1 -1
  143. package/src/client/queue.ts +8 -3
  144. package/src/client/raw-utils.ts +8 -6
  145. package/src/client/resolve-gateway-target.ts +1 -1
  146. package/src/client/utils.ts +2 -7
  147. package/src/common/actor-websocket.ts +3 -1
  148. package/src/common/bare/actor-persist/v1.ts +205 -163
  149. package/src/common/bare/actor-persist/v2.ts +265 -213
  150. package/src/common/bare/actor-persist/v3.ts +176 -172
  151. package/src/common/bare/actor-persist/v4.ts +254 -253
  152. package/src/common/bare/transport/v1.ts +659 -543
  153. package/src/common/client-protocol-versioned.ts +66 -64
  154. package/src/common/database/config.ts +2 -8
  155. package/src/common/database/native-database.ts +1 -1
  156. package/src/common/database/shared.ts +1 -0
  157. package/src/common/encoding.ts +250 -16
  158. package/src/common/engine.ts +28 -1
  159. package/src/common/eventsource.ts +1 -1
  160. package/src/common/inline-websocket-adapter.ts +14 -13
  161. package/src/common/log.ts +1 -0
  162. package/src/common/router.ts +13 -17
  163. package/src/common/utils.ts +1 -150
  164. package/src/common/websocket-interface.ts +1 -1
  165. package/src/db/mod.ts +1 -1
  166. package/src/devtools-loader/index.ts +4 -7
  167. package/src/devtools-loader/serve-devtools.ts +26 -0
  168. package/src/drivers/engine/actor-driver.ts +58 -56
  169. package/src/dynamic/instance.ts +32 -0
  170. package/src/dynamic/internal.ts +50 -0
  171. package/src/dynamic/isolate-runtime.ts +66 -0
  172. package/src/dynamic/mod.ts +32 -0
  173. package/src/engine-client/actor-http-client.ts +3 -3
  174. package/src/engine-client/actor-websocket-client.ts +6 -5
  175. package/src/engine-client/api-endpoints.ts +51 -2
  176. package/src/engine-client/api-utils.ts +2 -2
  177. package/src/engine-client/driver.ts +1 -1
  178. package/src/engine-client/mod.ts +6 -3
  179. package/src/engine-client/ws-proxy.ts +9 -4
  180. package/src/inspector/client.browser.ts +5 -11
  181. package/src/inspector/mod.ts +1 -3
  182. package/src/inspector-tab/mod.ts +315 -0
  183. package/src/registry/config/envoy.ts +1 -2
  184. package/src/registry/config/index.ts +40 -16
  185. package/src/registry/index.ts +209 -73
  186. package/src/registry/napi-runtime.ts +29 -2
  187. package/src/registry/native-validation.ts +10 -12
  188. package/src/registry/native.ts +433 -198
  189. package/src/registry/process-metrics.ts +250 -0
  190. package/src/registry/runtime.ts +52 -1
  191. package/src/registry/wasm-runtime.ts +29 -2
  192. package/src/registry/write-through-proxy.ts +40 -0
  193. package/src/serde.ts +2 -2
  194. package/src/serverless/configure.ts +18 -7
  195. package/src/test/mod.ts +11 -8
  196. package/src/utils/endpoint-parser.ts +1 -1
  197. package/src/utils/env-vars.ts +37 -0
  198. package/src/utils/router.ts +1 -1
  199. package/src/utils.ts +1 -2
  200. package/src/workflow/context.ts +699 -240
  201. package/src/workflow/driver.ts +23 -12
  202. package/src/workflow/inspector.ts +4 -3
  203. package/src/workflow/mod.ts +37 -23
  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-QAZLM4WT.cjs.map +0 -1
  217. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  218. package/dist/tsup/chunk-VJFRBJVQ.cjs.map +0 -1
  219. package/dist/tsup/chunk-VRCIXJRN.js.map +0 -1
  220. package/dist/tsup/chunk-W7EYSYVI.js.map +0 -1
  221. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  222. package/dist/tsup/chunk-Y5NSCZA2.cjs.map +0 -1
  223. package/dist/tsup/context-B_IWbWne.d.ts +0 -92
  224. package/dist/tsup/context-CUrQ9MHc.d.cts +0 -92
  225. package/src/utils/serve.ts +0 -217
  226. /package/dist/tsup/{chunk-H37XQU3I.js.map → chunk-JBUZRPY5.js.map} +0 -0
@@ -1,17 +1,11 @@
1
- import type { Context as HonoContext, Next } from "hono";
2
1
  import * as envoyProtocol from "@rivetkit/engine-envoy-protocol";
2
+ import type { Context as HonoContext, Next } from "hono";
3
3
  import type { ActorSpecifier } from "@/actor/errors";
4
4
  import {
5
5
  HEADER_ACTOR_GENERATION,
6
6
  HEADER_ACTOR_ID,
7
7
  HEADER_ACTOR_KEY,
8
8
  } from "@/common/actor-router-consts";
9
- import type { Encoding } from "@/common/encoding";
10
- import {
11
- getRequestEncoding,
12
- getRequestExposeInternalError,
13
- } from "@/common/router-request";
14
- import { buildActorNames, type RegistryConfig } from "@/registry/config";
15
9
  import type * as protocol from "@/common/client-protocol";
16
10
  import {
17
11
  CURRENT_VERSION as CLIENT_PROTOCOL_CURRENT_VERSION,
@@ -21,15 +15,17 @@ import {
21
15
  type HttpResponseError as HttpResponseErrorJson,
22
16
  HttpResponseErrorSchema,
23
17
  } from "@/common/client-protocol-zod";
18
+ import type { Encoding, JsonCompatValue } from "@/common/encoding";
24
19
  import {
25
- encodeCborCompat,
26
- encodingIsBinary,
27
- serializeWithEncoding,
28
- } from "@/serde";
20
+ getRequestEncoding,
21
+ getRequestExposeInternalError,
22
+ } from "@/common/router-request";
23
+ import { buildActorNames, type RegistryConfig } from "@/registry/config";
24
+ import { encodeCborCompat, serializeWithEncoding } from "@/serde";
29
25
  import { bufferToArrayBuffer, VERSION } from "@/utils";
30
26
  import { getLogHeaders } from "@/utils/env-vars";
31
27
  import { getLogger, type Logger } from "./log";
32
- import { deconstructError, stringifyError } from "./utils";
28
+ import { deconstructError } from "./utils";
33
29
 
34
30
  export function logger() {
35
31
  return getLogger("router");
@@ -67,10 +63,8 @@ export function handleRouteNotFound(c: HonoContext) {
67
63
  export function handleRouteError(error: unknown, c: HonoContext) {
68
64
  const exposeInternalError = getRequestExposeInternalError(c.req.raw);
69
65
 
70
- const { statusCode, group, code, message, metadata, actor } = deconstructError(
71
- error,
72
- exposeInternalError,
73
- );
66
+ const { statusCode, group, code, message, metadata, actor } =
67
+ deconstructError(error, exposeInternalError);
74
68
 
75
69
  if (actor) {
76
70
  logger().warn({
@@ -111,7 +105,9 @@ export function handleRouteError(error: unknown, c: HonoContext) {
111
105
  code: value.code,
112
106
  message: value.message,
113
107
  metadata: value.metadata
114
- ? bufferToArrayBuffer(encodeCborCompat(value.metadata))
108
+ ? bufferToArrayBuffer(
109
+ encodeCborCompat(value.metadata as JsonCompatValue),
110
+ )
115
111
  : null,
116
112
  actor: value.actor
117
113
  ? {
@@ -36,155 +36,6 @@ export function safeStringify(obj: unknown, maxSize: number) {
36
36
  return JSON.stringify(obj, replacer);
37
37
  }
38
38
 
39
- // TODO: Instead of doing this, use a temp var for state and attempt to write
40
- // it. Roll back state if fails to serialize.
41
-
42
- /**
43
- * Check if a value is CBOR serializable.
44
- * Optionally pass an onInvalid callback to receive the path to invalid values.
45
- *
46
- * For a complete list of supported CBOR tags, see:
47
- * https://github.com/kriszyp/cbor-x/blob/cc1cf9df8ba72288c7842af1dd374d73e34cdbc1/README.md#list-of-supported-tags-for-decoding
48
- */
49
- export function isCborSerializable(
50
- value: unknown,
51
- onInvalid?: (path: string) => void,
52
- currentPath = "",
53
- ): boolean {
54
- // Handle primitive types directly
55
- if (value === null || value === undefined) {
56
- return true;
57
- }
58
-
59
- if (typeof value === "number") {
60
- if (!Number.isFinite(value)) {
61
- onInvalid?.(currentPath);
62
- return false;
63
- }
64
- return true;
65
- }
66
-
67
- if (typeof value === "boolean" || typeof value === "string") {
68
- return true;
69
- }
70
-
71
- // Handle BigInt (CBOR tags 2 and 3)
72
- if (typeof value === "bigint") {
73
- return true;
74
- }
75
-
76
- // Handle Date objects (CBOR tags 0 and 1)
77
- if (value instanceof Date) {
78
- return true;
79
- }
80
-
81
- // Handle typed arrays (CBOR tags 64-82)
82
- if (
83
- value instanceof Uint8Array ||
84
- value instanceof Uint8ClampedArray ||
85
- value instanceof Uint16Array ||
86
- value instanceof Uint32Array ||
87
- value instanceof BigUint64Array ||
88
- value instanceof Int8Array ||
89
- value instanceof Int16Array ||
90
- value instanceof Int32Array ||
91
- value instanceof BigInt64Array ||
92
- value instanceof Float32Array ||
93
- value instanceof Float64Array
94
- ) {
95
- return true;
96
- }
97
-
98
- // Handle Map (CBOR tag 259)
99
- if (value instanceof Map) {
100
- for (const [key, val] of value.entries()) {
101
- const keyPath = currentPath
102
- ? `${currentPath}.key(${String(key)})`
103
- : `key(${String(key)})`;
104
- const valPath = currentPath
105
- ? `${currentPath}.value(${String(key)})`
106
- : `value(${String(key)})`;
107
- if (
108
- !isCborSerializable(key, onInvalid, keyPath) ||
109
- !isCborSerializable(val, onInvalid, valPath)
110
- ) {
111
- return false;
112
- }
113
- }
114
- return true;
115
- }
116
-
117
- // Handle Set (CBOR tag 258)
118
- if (value instanceof Set) {
119
- let index = 0;
120
- for (const item of value.values()) {
121
- const itemPath = currentPath
122
- ? `${currentPath}.set[${index}]`
123
- : `set[${index}]`;
124
- if (!isCborSerializable(item, onInvalid, itemPath)) {
125
- return false;
126
- }
127
- index++;
128
- }
129
- return true;
130
- }
131
-
132
- // Handle RegExp (CBOR tag 27)
133
- if (value instanceof RegExp) {
134
- return true;
135
- }
136
-
137
- // Handle Error objects (CBOR tag 27)
138
- if (value instanceof Error) {
139
- return true;
140
- }
141
-
142
- // Handle arrays
143
- if (Array.isArray(value)) {
144
- for (let i = 0; i < value.length; i++) {
145
- const itemPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;
146
- if (!isCborSerializable(value[i], onInvalid, itemPath)) {
147
- return false;
148
- }
149
- }
150
- return true;
151
- }
152
-
153
- // Handle plain objects and records (CBOR tags 105, 51, 57344-57599)
154
- if (typeof value === "object") {
155
- // Allow plain objects and objects with prototypes (for records and named objects)
156
- const proto = Object.getPrototypeOf(value);
157
- if (proto !== null && proto !== Object.prototype) {
158
- // Check if it's a known serializable object type
159
- const protoConstructor = value.constructor;
160
- if (protoConstructor && typeof protoConstructor.name === "string") {
161
- // Allow objects with named constructors (records, named objects)
162
- // This includes user-defined classes and built-in objects
163
- // that CBOR can serialize with tag 27 or record tags
164
- }
165
- }
166
-
167
- // Check all properties recursively
168
- for (const key in value) {
169
- const propPath = currentPath ? `${currentPath}.${key}` : key;
170
- if (
171
- !isCborSerializable(
172
- value[key as keyof typeof value],
173
- onInvalid,
174
- propPath,
175
- )
176
- ) {
177
- return false;
178
- }
179
- }
180
- return true;
181
- }
182
-
183
- // Not serializable
184
- onInvalid?.(currentPath);
185
- return false;
186
- }
187
-
188
39
  export interface DeconstructedError {
189
40
  __type: "ActorError";
190
41
  statusCode: ContentfulStatusCode;
@@ -283,7 +134,7 @@ export function deconstructError(
283
134
  actor = error.actor;
284
135
  }
285
136
  metadata = {
286
- //url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
137
+ //url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
287
138
  } satisfies errors.InternalErrorMetadata;
288
139
  }
289
140
 
@@ -1,7 +1,7 @@
1
1
  // Re-export everything from the virtual-websocket package
2
2
  export type {
3
+ RivetCloseEvent,
3
4
  RivetEvent,
4
5
  RivetMessageEvent,
5
- RivetCloseEvent,
6
6
  UniversalWebSocket,
7
7
  } from "@rivetkit/virtual-websocket";
package/src/db/mod.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { db } from "@/common/database/mod";
2
1
  export type {
3
2
  AnyDatabaseProvider,
4
3
  DatabaseProvider,
@@ -11,3 +10,4 @@ export type {
11
10
  SqliteNativeMetrics,
12
11
  SqliteQueryResult,
13
12
  } from "@/common/database/config";
13
+ export { db } from "@/common/database/mod";
@@ -1,16 +1,11 @@
1
1
  import type { ClientConfigInput } from "@/client/client";
2
- import { VERSION } from "@/utils";
3
2
  import { logger } from "./log";
4
3
 
5
4
  declare global {
6
5
  // Injected via tsup config
7
- // biome-ignore lint/style/noVar: required for global declaration
8
6
  var CUSTOM_RIVETKIT_DEVTOOLS_URL: string | undefined;
9
7
  }
10
8
 
11
- const DEFAULT_DEVTOOLS_URL = (version = VERSION) =>
12
- `https://releases.rivet.dev/rivet/latest/devtools/mod.js?v=${version}`;
13
-
14
9
  const scriptId = "rivetkit-devtools-script";
15
10
 
16
11
  export function injectDevtools(config: ClientConfigInput) {
@@ -20,10 +15,12 @@ export function injectDevtools(config: ClientConfigInput) {
20
15
  }
21
16
 
22
17
  if (!document.getElementById(scriptId)) {
18
+ const src =
19
+ globalThis.CUSTOM_RIVETKIT_DEVTOOLS_URL ||
20
+ `${config.endpoint?.replace(/\/$/, "")}/devtools/mod.js`;
23
21
  const script = document.createElement("script");
24
22
  script.id = scriptId;
25
- script.src =
26
- globalThis.CUSTOM_RIVETKIT_DEVTOOLS_URL || DEFAULT_DEVTOOLS_URL();
23
+ script.src = src;
27
24
  script.async = true;
28
25
  document.head.appendChild(script);
29
26
  }
@@ -0,0 +1,26 @@
1
+ import { getNodeFs, getNodePath, getNodeUrl } from "@/utils/node";
2
+
3
+ export async function getDevtoolsPath(): Promise<string> {
4
+ const url = getNodeUrl();
5
+ const path = getNodePath();
6
+
7
+ const devtoolsPath = path.join(
8
+ path.dirname(url.fileURLToPath(import.meta.url)),
9
+ "../../dist/devtools/mod.js",
10
+ );
11
+
12
+ try {
13
+ await getNodeFs().access(devtoolsPath);
14
+ } catch {
15
+ throw new Error(
16
+ `Devtools bundle not found at ${devtoolsPath}. Run 'pnpm build:pack-devtools' first.`,
17
+ );
18
+ }
19
+
20
+ return devtoolsPath;
21
+ }
22
+
23
+ export async function readDevtoolsBundle(): Promise<Buffer> {
24
+ const devtoolsPath = await getDevtoolsPath();
25
+ return getNodeFs().readFile(devtoolsPath);
26
+ }
@@ -1,9 +1,9 @@
1
1
  import type { EnvoyConfig } from "@rivetkit/rivetkit-native/wrapper";
2
2
  import {
3
- type HibernatingWebSocketMetadata,
4
3
  type EnvoyHandle,
4
+ type HibernatingWebSocketMetadata,
5
5
  openDatabaseFromEnvoy,
6
- protocol,
6
+ type protocol,
7
7
  startEnvoySync,
8
8
  } from "@rivetkit/rivetkit-native/wrapper";
9
9
  import * as cbor from "cbor-x";
@@ -11,17 +11,19 @@ import type { Context as HonoContext } from "hono";
11
11
  import { streamSSE } from "hono/streaming";
12
12
  import { WSContext, type WSContextInit } from "hono/ws";
13
13
  import invariant from "invariant";
14
- import { type AnyConn, CONN_STATE_MANAGER_SYMBOL } from "@/actor/conn/mod";
14
+ import { CONN_STATE_MANAGER_SYMBOL } from "@/actor/conn/mod";
15
15
  import { isStaticActorDefinition, lookupInRegistry } from "@/actor/definition";
16
+ import type { ActorDriver } from "@/actor/driver";
17
+ import { KEYS } from "@/actor/instance/keys";
18
+ import type { AnyActorInstance } from "@/actor/instance/mod";
16
19
  import {
17
- isStaticActorInstance,
18
20
  type AnyStaticActorInstance,
21
+ isStaticActorInstance,
19
22
  } from "@/actor/instance/mod";
20
- import { KEYS } from "@/actor/instance/keys";
21
23
  import {
22
- type PreloadMap,
23
24
  compareBytes,
24
25
  createPreloadMap,
26
+ type PreloadMap,
25
27
  } from "@/actor/instance/preload-map";
26
28
  import { deserializeActorKey } from "@/actor/keys";
27
29
  import type { Encoding } from "@/actor/protocol/serde";
@@ -41,6 +43,10 @@ import {
41
43
  } from "@/common/actor-router-consts";
42
44
  import { getLogger } from "@/common/log";
43
45
  import { deconstructError } from "@/common/utils";
46
+ import type {
47
+ RivetMessageEvent,
48
+ UniversalWebSocket,
49
+ } from "@/common/websocket-interface";
44
50
  import {
45
51
  buildHibernatableWebSocketAckStateTestResponse,
46
52
  type IndexedWebSocketPayload,
@@ -49,21 +55,19 @@ import {
49
55
  setHibernatableWebSocketAckTestHooks,
50
56
  unregisterRemoteHibernatableWebSocketAckHooks,
51
57
  } from "@/common/websocket-test-hooks";
52
- import type {
53
- RivetMessageEvent,
54
- UniversalWebSocket,
55
- } from "@/common/websocket-interface";
56
- import type { ActorDriver } from "@/actor/driver";
57
- import type { AnyActorInstance } from "@/actor/instance/mod";
58
58
  import {
59
- getInitialActorKvState,
59
+ type JsNativeDatabaseLike,
60
+ wrapJsNativeDatabase,
61
+ } from "@/db/native-database";
62
+ import {
60
63
  type EngineControlClient,
64
+ getInitialActorKvState,
61
65
  } from "@/driver-helpers/mod";
62
66
  import { DynamicActorInstance } from "@/dynamic/instance";
63
- import { DynamicActorIsolateRuntime } from "@/dynamic/isolate-runtime";
64
67
  import { isDynamicActorDefinition } from "@/dynamic/internal";
65
- import { buildActorNames, type RegistryConfig } from "@/registry/config";
68
+ import { DynamicActorIsolateRuntime } from "@/dynamic/isolate-runtime";
66
69
  import { getEndpoint } from "@/engine-client/api-utils";
70
+ import { buildActorNames, type RegistryConfig } from "@/registry/config";
67
71
  import {
68
72
  type LongTimeoutHandle,
69
73
  promiseWithResolvers,
@@ -71,10 +75,6 @@ import {
71
75
  stringifyError,
72
76
  VERSION,
73
77
  } from "@/utils";
74
- import {
75
- wrapJsNativeDatabase,
76
- type JsNativeDatabaseLike,
77
- } from "@/db/native-database";
78
78
  import { logger } from "./log";
79
79
 
80
80
  const ENVOY_SSE_PING_INTERVAL = 1000;
@@ -88,13 +88,13 @@ const REMOTE_ACK_HOOK_QUERY_PARAM = "__rivetkitAckHook";
88
88
  //
89
89
  // See engine/packages/pegboard-gateway/src/shared_state.rs
90
90
  // (HWS_MESSAGE_ACK_TIMEOUT)
91
- const CONN_MESSAGE_ACK_DEADLINE = 5_000;
91
+ const _CONN_MESSAGE_ACK_DEADLINE = 5_000;
92
92
 
93
93
  // Force saveState when cumulative message size reaches this threshold (0.5 MB)
94
94
  //
95
95
  // See engine/packages/pegboard-gateway/src/shared_state.rs
96
96
  // (HWS_MAX_PENDING_MSGS_SIZE_PER_REQ)
97
- const CONN_BUFFERED_MESSAGE_SIZE_THRESHOLD = 500_000;
97
+ const _CONN_BUFFERED_MESSAGE_SIZE_THRESHOLD = 500_000;
98
98
 
99
99
  interface ActorHandler {
100
100
  actor?: AnyActorInstance;
@@ -144,7 +144,6 @@ export type DriverContext = {};
144
144
 
145
145
  export class EngineActorDriver implements ActorDriver {
146
146
  #config: RegistryConfig;
147
- #engineClient: EngineControlClient;
148
147
  #inlineClient: Client<any>;
149
148
  #envoy: EnvoyHandle;
150
149
  #actors: Map<string, ActorHandler> = new Map();
@@ -161,15 +160,6 @@ export class EngineActorDriver implements ActorDriver {
161
160
  string,
162
161
  HibernatableRunnerWebSocketBinding
163
162
  >();
164
- #hwsMessageIndex = new Map<
165
- string,
166
- {
167
- serverMessageIndex: number;
168
- bufferedMessageSize: number;
169
- pendingAckFromMessageIndex: boolean;
170
- pendingAckFromBufferSize: boolean;
171
- }
172
- >();
173
163
  #actorRouter: ActorRouter;
174
164
 
175
165
  #envoyStarted: PromiseWithResolvers<void> = promiseWithResolvers((reason) =>
@@ -284,7 +274,7 @@ export class EngineActorDriver implements ActorDriver {
284
274
  logger().debug({
285
275
  msg: "actor crash cleanup errored",
286
276
  actorId,
287
- err: stringifyError(err),
277
+ error: stringifyError(err),
288
278
  });
289
279
  }
290
280
  }
@@ -376,8 +366,7 @@ export class EngineActorDriver implements ActorDriver {
376
366
  requestId: ArrayBuffer,
377
367
  ): void {
378
368
  const key = this.#hibernatableWebSocketAckKey(gatewayId, requestId);
379
- const binding =
380
- this.#hibernatableRunnerWebSocketBindings.get(key);
369
+ const binding = this.#hibernatableRunnerWebSocketBindings.get(key);
381
370
  if (!binding) {
382
371
  return;
383
372
  }
@@ -397,8 +386,7 @@ export class EngineActorDriver implements ActorDriver {
397
386
  requestId: ArrayBuffer,
398
387
  ): void {
399
388
  const key = this.#hibernatableWebSocketAckKey(gatewayId, requestId);
400
- const binding =
401
- this.#hibernatableRunnerWebSocketBindings.get(key);
389
+ const binding = this.#hibernatableRunnerWebSocketBindings.get(key);
402
390
  binding?.detach?.();
403
391
  this.#hibernatableRunnerWebSocketBindings.delete(key);
404
392
  }
@@ -585,7 +573,7 @@ export class EngineActorDriver implements ActorDriver {
585
573
  return handler;
586
574
  }
587
575
 
588
- getContext(actorId: string): DriverContext {
576
+ getContext(_actorId: string): DriverContext {
589
577
  return {};
590
578
  }
591
579
 
@@ -1140,7 +1128,10 @@ export class EngineActorDriver implements ActorDriver {
1140
1128
  actorId: binding.actorId,
1141
1129
  error: stringifyError(error),
1142
1130
  });
1143
- binding.websocket.close(1011, "dynamic.websocket_forward_failed");
1131
+ binding.websocket.close(
1132
+ 1011,
1133
+ "dynamic.websocket_forward_failed",
1134
+ );
1144
1135
  });
1145
1136
  };
1146
1137
  const onClose = (event: CloseEvent) => {
@@ -1270,7 +1261,10 @@ export class EngineActorDriver implements ActorDriver {
1270
1261
  msg: "dynamic runtime websocket binding is missing after restore",
1271
1262
  actorId: binding.actorId,
1272
1263
  });
1273
- binding.websocket.close(1011, "dynamic.websocket_forward_failed");
1264
+ binding.websocket.close(
1265
+ 1011,
1266
+ "dynamic.websocket_forward_failed",
1267
+ );
1274
1268
  return;
1275
1269
  }
1276
1270
 
@@ -1286,7 +1280,10 @@ export class EngineActorDriver implements ActorDriver {
1286
1280
  actorId: binding.actorId,
1287
1281
  error: stringifyError(error),
1288
1282
  });
1289
- binding.websocket.close(1011, "dynamic.websocket_forward_failed");
1283
+ binding.websocket.close(
1284
+ 1011,
1285
+ "dynamic.websocket_forward_failed",
1286
+ );
1290
1287
  });
1291
1288
  };
1292
1289
  const onClose = (event: CloseEvent) => {
@@ -1357,7 +1354,7 @@ export class EngineActorDriver implements ActorDriver {
1357
1354
  logger().warn({
1358
1355
  msg: "failed to rebind dynamic hibernatable runner websocket",
1359
1356
  actorId,
1360
- err: stringifyError(result.reason),
1357
+ error: stringifyError(result.reason),
1361
1358
  });
1362
1359
  }
1363
1360
  }
@@ -1380,7 +1377,7 @@ export class EngineActorDriver implements ActorDriver {
1380
1377
  logger().warn({
1381
1378
  msg: "failed to rebind hibernatable connect socket",
1382
1379
  actorId,
1383
- err: stringifyError(result.reason),
1380
+ error: stringifyError(result.reason),
1384
1381
  });
1385
1382
  }
1386
1383
  }
@@ -1640,7 +1637,7 @@ export class EngineActorDriver implements ActorDriver {
1640
1637
  logger().warn({
1641
1638
  msg: "failed to restore dynamic hibernating requests after actor start",
1642
1639
  actorId,
1643
- err: stringifyError(error),
1640
+ error: stringifyError(error),
1644
1641
  });
1645
1642
  }
1646
1643
  } else if (isStaticActorDefinition(definition)) {
@@ -1707,7 +1704,7 @@ export class EngineActorDriver implements ActorDriver {
1707
1704
  logger().debug({
1708
1705
  msg: "failed to dispose dynamic runtime after actor start failure",
1709
1706
  actorId,
1710
- err: stringifyError(disposeError),
1707
+ error: stringifyError(disposeError),
1711
1708
  });
1712
1709
  }
1713
1710
  this.#dynamicRuntimes.delete(actorId);
@@ -1730,7 +1727,7 @@ export class EngineActorDriver implements ActorDriver {
1730
1727
  actorId,
1731
1728
  name,
1732
1729
  key,
1733
- err: stringifyError(error),
1730
+ error: stringifyError(error),
1734
1731
  });
1735
1732
 
1736
1733
  try {
@@ -1739,7 +1736,7 @@ export class EngineActorDriver implements ActorDriver {
1739
1736
  logger().debug({
1740
1737
  msg: "failed to stop actor after start failure",
1741
1738
  actorId,
1742
- err: stringifyError(stopError),
1739
+ error: stringifyError(stopError),
1743
1740
  });
1744
1741
  }
1745
1742
  }
@@ -1786,7 +1783,7 @@ export class EngineActorDriver implements ActorDriver {
1786
1783
  logger().debug({
1787
1784
  msg: "actor start failed during stop, cleaning up handler",
1788
1785
  actorId,
1789
- err: stringifyError(err),
1786
+ error: stringifyError(err),
1790
1787
  });
1791
1788
  }
1792
1789
  }
@@ -1804,7 +1801,7 @@ export class EngineActorDriver implements ActorDriver {
1804
1801
  } catch (err) {
1805
1802
  logger().error({
1806
1803
  msg: "error in onStop, proceeding with removing actor",
1807
- err: stringifyError(err),
1804
+ error: stringifyError(err),
1808
1805
  });
1809
1806
  }
1810
1807
  }
@@ -1989,8 +1986,11 @@ export class EngineActorDriver implements ActorDriver {
1989
1986
  isHibernatable,
1990
1987
  isRestoringHibernatable,
1991
1988
  );
1992
- } catch (err) {
1993
- logger().error({ msg: "building websocket handlers errored", err });
1989
+ } catch (error) {
1990
+ logger().error({
1991
+ msg: "building websocket handlers errored",
1992
+ error,
1993
+ });
1994
1994
  websocketRaw.close(1011, "ws.route_error");
1995
1995
  return;
1996
1996
  }
@@ -2005,7 +2005,7 @@ export class EngineActorDriver implements ActorDriver {
2005
2005
  // Get connection and actor from wsHandler (may be undefined for inspector endpoint)
2006
2006
  const conn = wsHandler.conn;
2007
2007
  const actor = wsHandler.actor;
2008
- const connStateManager = conn?.[CONN_STATE_MANAGER_SYMBOL];
2008
+ const _connStateManager = conn?.[CONN_STATE_MANAGER_SYMBOL];
2009
2009
 
2010
2010
  // Bind event listeners to Hono WebSocket handlers
2011
2011
  //
@@ -2044,16 +2044,15 @@ export class EngineActorDriver implements ActorDriver {
2044
2044
 
2045
2045
  const currentActor = this.#actors.get(actorId)?.actor;
2046
2046
  const actorForDispatch =
2047
- currentActor &&
2048
- isStaticActorInstance(currentActor)
2047
+ currentActor && isStaticActorInstance(currentActor)
2049
2048
  ? currentActor
2050
2049
  : actor;
2051
2050
  const connForDispatch =
2052
2051
  isHibernatable && actorForDispatch
2053
- ? actorForDispatch.connectionManager.findHibernatableConn(
2052
+ ? (actorForDispatch.connectionManager.findHibernatableConn(
2054
2053
  gatewayIdBuf,
2055
2054
  requestIdBuf,
2056
- ) ?? conn
2055
+ ) ?? conn)
2057
2056
  : conn;
2058
2057
 
2059
2058
  if (actorForDispatch?.isStopping) {
@@ -2063,7 +2062,10 @@ export class EngineActorDriver implements ActorDriver {
2063
2062
  actorId: actorForDispatch?.id,
2064
2063
  messageIndex: event.rivetMessageIndex,
2065
2064
  });
2066
- if (!isRawWebSocketPath && websocket.readyState !== websocket.CLOSED) {
2065
+ if (
2066
+ !isRawWebSocketPath &&
2067
+ websocket.readyState !== websocket.CLOSED
2068
+ ) {
2067
2069
  websocket.close(1011, "actor.stopping");
2068
2070
  }
2069
2071
  return;
@@ -0,0 +1,32 @@
1
+ import type { DynamicActorIsolateRuntime } from "./isolate-runtime";
2
+
3
+ export class DynamicActorInstance {
4
+ constructor(
5
+ public readonly id: string,
6
+ private readonly runtime: DynamicActorIsolateRuntime,
7
+ ) {}
8
+
9
+ get isStopping(): boolean {
10
+ return this.runtime.isStopping;
11
+ }
12
+
13
+ async onStop(mode: "sleep" | "destroy"): Promise<void> {
14
+ await this.runtime.stop(mode);
15
+ }
16
+
17
+ async onAlarm(): Promise<void> {
18
+ await this.runtime.onAlarm();
19
+ }
20
+
21
+ async cleanupPersistedConnections(reason?: string): Promise<number> {
22
+ return await this.runtime.cleanupPersistedConnections(reason);
23
+ }
24
+
25
+ async getHibernatingWebSockets() {
26
+ return await this.runtime.getHibernatingWebSockets();
27
+ }
28
+
29
+ getHibernatingWebSocketMetadata() {
30
+ return this.runtime.getHibernatingWebSocketMetadata();
31
+ }
32
+ }