rivetkit 0.0.0-active-actors-fix-active-count.253e406 → 0.0.0-bisect-sync-sqlite-1.910d1c7

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 (303) hide show
  1. package/dist/browser/client.d.ts +1286 -89
  2. package/dist/browser/client.js +1699 -704
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.d.ts +252 -129
  5. package/dist/browser/inspector/client.js +2083 -236
  6. package/dist/browser/inspector/client.js.map +1 -1
  7. package/dist/tsup/actor/errors.cjs +8 -2
  8. package/dist/tsup/actor/errors.cjs.map +1 -1
  9. package/dist/tsup/actor/errors.d.cts +1 -1
  10. package/dist/tsup/actor/errors.d.ts +1 -1
  11. package/dist/tsup/actor/errors.js +7 -1
  12. package/dist/tsup/agent-os/index.cjs +3 -2289
  13. package/dist/tsup/agent-os/index.cjs.map +1 -1
  14. package/dist/tsup/agent-os/index.d.cts +1 -1813
  15. package/dist/tsup/agent-os/index.d.ts +1 -1813
  16. package/dist/tsup/agent-os/index.js +3 -2289
  17. package/dist/tsup/agent-os/index.js.map +1 -1
  18. package/dist/tsup/chunk-2JJU7IQ7.cjs +14 -0
  19. package/dist/tsup/chunk-2JJU7IQ7.cjs.map +1 -0
  20. package/dist/tsup/{chunk-DZJZLZ4R.js → chunk-2MXBZGUP.js} +2 -2
  21. package/dist/tsup/{chunk-L4FVS7GY.js → chunk-47IS5ZFI.js} +6 -6
  22. package/dist/tsup/chunk-47IS5ZFI.js.map +1 -0
  23. package/dist/tsup/{chunk-DXWOGCZY.js → chunk-5XWY5CBA.js} +70 -8
  24. package/dist/tsup/chunk-5XWY5CBA.js.map +1 -0
  25. package/dist/tsup/{chunk-OQEEZDIK.cjs → chunk-6XVNZKKP.cjs} +506 -31
  26. package/dist/tsup/chunk-6XVNZKKP.cjs.map +1 -0
  27. package/dist/tsup/{chunk-3YY5S6TV.js → chunk-A2CF6PFH.js} +20 -12
  28. package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
  29. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-AQJFKHBK.cjs} +276 -27
  30. package/dist/tsup/chunk-AQJFKHBK.cjs.map +1 -0
  31. package/dist/tsup/chunk-DPWLASMC.cjs +244 -0
  32. package/dist/tsup/chunk-DPWLASMC.cjs.map +1 -0
  33. package/dist/tsup/{chunk-VUF2YEF4.cjs → chunk-DYJOU3MF.cjs} +10 -10
  34. package/dist/tsup/chunk-DYJOU3MF.cjs.map +1 -0
  35. package/dist/tsup/{chunk-7WXCRV25.cjs → chunk-ELZ6MT3V.cjs} +18 -11
  36. package/dist/tsup/chunk-ELZ6MT3V.cjs.map +1 -0
  37. package/dist/tsup/chunk-HYIVSH5X.js +244 -0
  38. package/dist/tsup/chunk-HYIVSH5X.js.map +1 -0
  39. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-IHEO5OT3.js} +275 -26
  40. package/dist/tsup/chunk-IHEO5OT3.js.map +1 -0
  41. package/dist/tsup/chunk-IWACVNN5.js +14 -0
  42. package/dist/tsup/chunk-IWACVNN5.js.map +1 -0
  43. package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
  44. package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
  45. package/dist/tsup/{chunk-V4JUWAT6.js → chunk-K3AJOPSF.js} +498 -23
  46. package/dist/tsup/chunk-K3AJOPSF.js.map +1 -0
  47. package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
  48. package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
  49. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-MGI2VVF6.cjs} +45 -9
  50. package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
  51. package/dist/tsup/{chunk-QNLGOTQP.js → chunk-NPHTIUUJ.js} +1291 -420
  52. package/dist/tsup/chunk-NPHTIUUJ.js.map +1 -0
  53. package/dist/tsup/{chunk-7GKQJFSB.cjs → chunk-POCSZXPQ.cjs} +72 -10
  54. package/dist/tsup/chunk-POCSZXPQ.cjs.map +1 -0
  55. package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-RTWH3AX3.cjs} +19 -11
  56. package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
  57. package/dist/tsup/{chunk-ARRBQTAR.cjs → chunk-X76BM5JS.cjs} +1420 -549
  58. package/dist/tsup/chunk-X76BM5JS.cjs.map +1 -0
  59. package/dist/tsup/{chunk-AGBP757I.js → chunk-X7SYKFPM.js} +16 -9
  60. package/dist/tsup/chunk-X7SYKFPM.js.map +1 -0
  61. package/dist/tsup/{chunk-GKAMEBTZ.cjs → chunk-XLDJSZ3B.cjs} +3 -3
  62. package/dist/tsup/{chunk-GKAMEBTZ.cjs.map → chunk-XLDJSZ3B.cjs.map} +1 -1
  63. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-ZOVJDAOW.js} +44 -8
  64. package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
  65. package/dist/tsup/client/mod.cjs +8 -9
  66. package/dist/tsup/client/mod.cjs.map +1 -1
  67. package/dist/tsup/client/mod.d.cts +33 -7
  68. package/dist/tsup/client/mod.d.ts +33 -7
  69. package/dist/tsup/client/mod.js +7 -8
  70. package/dist/tsup/common/log.cjs +5 -3
  71. package/dist/tsup/common/log.cjs.map +1 -1
  72. package/dist/tsup/common/log.d.cts +5 -1
  73. package/dist/tsup/common/log.d.ts +5 -1
  74. package/dist/tsup/common/log.js +6 -4
  75. package/dist/tsup/common/websocket.cjs +4 -4
  76. package/dist/tsup/common/websocket.js +3 -3
  77. package/dist/tsup/{config-nlTlOKaE.d.cts → config-BMGUEKMZ.d.cts} +1252 -75
  78. package/dist/tsup/config-CBTr4IhE.d.cts +224 -0
  79. package/dist/tsup/config-CBTr4IhE.d.ts +224 -0
  80. package/dist/tsup/{config-D7ykAntK.d.ts → config-iBpXyITj.d.ts} +1252 -75
  81. package/dist/tsup/context-hyVakgnU.d.ts +136 -0
  82. package/dist/tsup/context-qfvLuF0P.d.cts +136 -0
  83. package/dist/tsup/db/drizzle.cjs +127 -67
  84. package/dist/tsup/db/drizzle.cjs.map +1 -1
  85. package/dist/tsup/db/drizzle.d.cts +8 -4
  86. package/dist/tsup/db/drizzle.d.ts +8 -4
  87. package/dist/tsup/db/drizzle.js +127 -67
  88. package/dist/tsup/db/drizzle.js.map +1 -1
  89. package/dist/tsup/db/mod.cjs +6 -124
  90. package/dist/tsup/db/mod.cjs.map +1 -1
  91. package/dist/tsup/db/mod.d.cts +12 -4
  92. package/dist/tsup/db/mod.d.ts +12 -4
  93. package/dist/tsup/db/mod.js +5 -123
  94. package/dist/tsup/db/mod.js.map +1 -1
  95. package/dist/tsup/dynamic/mod.cjs +24 -0
  96. package/dist/tsup/dynamic/mod.cjs.map +1 -0
  97. package/dist/tsup/dynamic/mod.d.cts +39 -0
  98. package/dist/tsup/dynamic/mod.d.ts +39 -0
  99. package/dist/tsup/dynamic/mod.js +24 -0
  100. package/dist/tsup/dynamic/mod.js.map +1 -0
  101. package/dist/tsup/inspector/mod.cjs +47 -12
  102. package/dist/tsup/inspector/mod.cjs.map +1 -1
  103. package/dist/tsup/inspector/mod.d.cts +26 -136
  104. package/dist/tsup/inspector/mod.d.ts +26 -136
  105. package/dist/tsup/inspector/mod.js +46 -11
  106. package/dist/tsup/inspector/mod.js.map +1 -1
  107. package/dist/tsup/inspector/workflow.cjs +21 -0
  108. package/dist/tsup/inspector/workflow.cjs.map +1 -0
  109. package/dist/tsup/inspector/workflow.d.cts +144 -0
  110. package/dist/tsup/inspector/workflow.d.ts +144 -0
  111. package/dist/tsup/inspector/workflow.js +21 -0
  112. package/dist/tsup/inspector/workflow.js.map +1 -0
  113. package/dist/tsup/inspector-tab/mod.cjs +162 -0
  114. package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
  115. package/dist/tsup/inspector-tab/mod.d.cts +242 -0
  116. package/dist/tsup/inspector-tab/mod.d.ts +242 -0
  117. package/dist/tsup/inspector-tab/mod.js +162 -0
  118. package/dist/tsup/inspector-tab/mod.js.map +1 -0
  119. package/dist/tsup/mod.cjs +3527 -753
  120. package/dist/tsup/mod.cjs.map +1 -1
  121. package/dist/tsup/mod.d.cts +11 -7
  122. package/dist/tsup/mod.d.ts +11 -7
  123. package/dist/tsup/mod.js +3468 -694
  124. package/dist/tsup/mod.js.map +1 -1
  125. package/dist/tsup/test/mod.cjs +26 -21
  126. package/dist/tsup/test/mod.cjs.map +1 -1
  127. package/dist/tsup/test/mod.d.cts +7 -5
  128. package/dist/tsup/test/mod.d.ts +7 -5
  129. package/dist/tsup/test/mod.js +25 -20
  130. package/dist/tsup/test/mod.js.map +1 -1
  131. package/dist/tsup/unstable/migrations.cjs +101 -0
  132. package/dist/tsup/unstable/migrations.cjs.map +1 -0
  133. package/dist/tsup/unstable/migrations.d.cts +29 -0
  134. package/dist/tsup/unstable/migrations.d.ts +29 -0
  135. package/dist/tsup/unstable/migrations.js +101 -0
  136. package/dist/tsup/unstable/migrations.js.map +1 -0
  137. package/dist/tsup/{utils-DVekpm4I.d.ts → utils-3rsE0JvI.d.cts} +26 -2
  138. package/dist/tsup/{utils-DVekpm4I.d.cts → utils-3rsE0JvI.d.ts} +26 -2
  139. package/dist/tsup/utils-C1O-SklO.d.ts +162 -0
  140. package/dist/tsup/utils-C6b0aYUM.d.cts +162 -0
  141. package/dist/tsup/utils.cjs +7 -3
  142. package/dist/tsup/utils.cjs.map +1 -1
  143. package/dist/tsup/utils.d.cts +4 -147
  144. package/dist/tsup/utils.d.ts +4 -147
  145. package/dist/tsup/utils.js +6 -2
  146. package/dist/tsup/workflow/mod.cjs +557 -410
  147. package/dist/tsup/workflow/mod.cjs.map +1 -1
  148. package/dist/tsup/workflow/mod.d.cts +11 -9
  149. package/dist/tsup/workflow/mod.d.ts +11 -9
  150. package/dist/tsup/workflow/mod.js +551 -404
  151. package/dist/tsup/workflow/mod.js.map +1 -1
  152. package/package.json +67 -18
  153. package/src/actor/actions.ts +155 -0
  154. package/src/actor/config.ts +679 -101
  155. package/src/actor/contexts/index.ts +9 -2
  156. package/src/actor/definition.ts +75 -26
  157. package/src/actor/errors.ts +107 -8
  158. package/src/actor/keys.ts +87 -1
  159. package/src/actor/mod.ts +36 -20
  160. package/src/actor/schema.ts +6 -2
  161. package/src/actor/tracing.ts +28 -0
  162. package/src/agent-os/index.ts +5 -64
  163. package/src/client/actor-common.ts +84 -54
  164. package/src/client/actor-conn.ts +231 -68
  165. package/src/client/actor-handle.ts +283 -89
  166. package/src/client/actor-query.ts +13 -6
  167. package/src/client/auth.ts +37 -0
  168. package/src/client/client.ts +182 -21
  169. package/src/client/config.ts +28 -3
  170. package/src/client/errors.ts +15 -2
  171. package/src/client/lifecycle-errors.ts +63 -5
  172. package/src/client/mod.ts +10 -0
  173. package/src/client/outbound-telemetry.ts +66 -0
  174. package/src/client/query.ts +3 -1
  175. package/src/client/queue.ts +13 -3
  176. package/src/client/raw-utils.ts +59 -14
  177. package/src/client/resolve-gateway-target.ts +3 -1
  178. package/src/client/retry-budget.ts +81 -0
  179. package/src/client/token-provider.ts +93 -0
  180. package/src/client/utils.ts +22 -9
  181. package/src/common/actor-router-consts.ts +6 -0
  182. package/src/common/actor-telemetry-context.ts +19 -0
  183. package/src/common/actor-websocket.ts +3 -1
  184. package/src/common/bare/actor-persist/v1.ts +205 -163
  185. package/src/common/bare/actor-persist/v2.ts +265 -213
  186. package/src/common/bare/actor-persist/v3.ts +176 -172
  187. package/src/common/bare/actor-persist/v4.ts +254 -253
  188. package/src/common/bare/generated/inspector/v5.ts +1016 -0
  189. package/src/common/bare/generated/inspector/v6.ts +1367 -0
  190. package/src/common/bare/transport/v1.ts +694 -542
  191. package/src/common/client-protocol-versioned.ts +66 -64
  192. package/src/common/database/config.ts +175 -9
  193. package/src/common/database/mod.ts +262 -77
  194. package/src/common/database/native-database.ts +442 -20
  195. package/src/common/database/shared.ts +25 -0
  196. package/src/common/encoding.ts +278 -34
  197. package/src/common/engine.ts +28 -1
  198. package/src/common/eventsource.ts +1 -1
  199. package/src/common/fetch-like.ts +63 -0
  200. package/src/common/inline-websocket-adapter.ts +14 -13
  201. package/src/common/inspector-transport.ts +12 -2
  202. package/src/common/log.ts +15 -8
  203. package/src/common/otel-context.ts +99 -0
  204. package/src/common/router.ts +14 -18
  205. package/src/common/utils.ts +8 -169
  206. package/src/common/websocket-interface.ts +1 -1
  207. package/src/db/drizzle.ts +182 -80
  208. package/src/db/mod.ts +5 -1
  209. package/src/devtools-loader/index.ts +4 -7
  210. package/src/devtools-loader/serve-devtools.ts +26 -0
  211. package/src/dynamic/instance.ts +32 -0
  212. package/src/dynamic/internal.ts +50 -0
  213. package/src/dynamic/isolate-runtime.ts +64 -0
  214. package/src/dynamic/mod.ts +32 -0
  215. package/src/engine-api/actors.ts +15 -3
  216. package/src/engine-client/actor-http-client.ts +37 -22
  217. package/src/engine-client/actor-websocket-client.ts +37 -9
  218. package/src/engine-client/api-endpoints.ts +128 -5
  219. package/src/engine-client/api-utils.ts +2 -2
  220. package/src/engine-client/driver.ts +21 -16
  221. package/src/engine-client/mod.ts +280 -111
  222. package/src/engine-client/ws-proxy.ts +9 -4
  223. package/src/inspector/client.browser.ts +127 -15
  224. package/src/inspector/mod.ts +2 -4
  225. package/src/inspector/workflow.ts +61 -0
  226. package/src/inspector-tab/mod.ts +301 -0
  227. package/src/registry/config/envoy.ts +3 -20
  228. package/src/registry/config/index.ts +91 -74
  229. package/src/registry/index.ts +702 -80
  230. package/src/registry/napi-runtime.ts +643 -42
  231. package/src/registry/native-http.ts +225 -0
  232. package/src/registry/native-validation.ts +10 -12
  233. package/src/registry/native.ts +1881 -582
  234. package/src/registry/run-handler-coordinator.ts +219 -0
  235. package/src/registry/runtime.ts +441 -7
  236. package/src/registry/wasm-runtime.ts +516 -23
  237. package/src/registry/write-through-proxy.ts +141 -0
  238. package/src/serde.ts +2 -2
  239. package/src/serverless/configure.ts +18 -7
  240. package/src/test/mod.ts +2 -17
  241. package/src/test/ready.ts +22 -0
  242. package/src/unstable/migrations.ts +141 -0
  243. package/src/utils/endpoint-parser.ts +1 -1
  244. package/src/utils/env-vars.ts +50 -2
  245. package/src/utils/node.ts +44 -28
  246. package/src/utils/router.ts +1 -1
  247. package/src/utils.ts +4 -2
  248. package/src/workflow/context.ts +703 -242
  249. package/src/workflow/driver.ts +284 -125
  250. package/src/workflow/inspector.ts +24 -24
  251. package/src/workflow/mod.ts +76 -84
  252. package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
  253. package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
  254. package/dist/tsup/chunk-6NT2LIFN.cjs +0 -268
  255. package/dist/tsup/chunk-6NT2LIFN.cjs.map +0 -1
  256. package/dist/tsup/chunk-7GKQJFSB.cjs.map +0 -1
  257. package/dist/tsup/chunk-7WXCRV25.cjs.map +0 -1
  258. package/dist/tsup/chunk-AGBP757I.js.map +0 -1
  259. package/dist/tsup/chunk-ARRBQTAR.cjs.map +0 -1
  260. package/dist/tsup/chunk-DXWOGCZY.js.map +0 -1
  261. package/dist/tsup/chunk-JGIPV3QU.js +0 -268
  262. package/dist/tsup/chunk-JGIPV3QU.js.map +0 -1
  263. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  264. package/dist/tsup/chunk-L4FVS7GY.js.map +0 -1
  265. package/dist/tsup/chunk-LD5YASJU.cjs.map +0 -1
  266. package/dist/tsup/chunk-OQEEZDIK.cjs.map +0 -1
  267. package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
  268. package/dist/tsup/chunk-QAZLM4WT.cjs.map +0 -1
  269. package/dist/tsup/chunk-QNLGOTQP.js.map +0 -1
  270. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  271. package/dist/tsup/chunk-V4JUWAT6.js.map +0 -1
  272. package/dist/tsup/chunk-VUF2YEF4.cjs.map +0 -1
  273. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  274. package/dist/tsup/config-CxjGYf4K.d.cts +0 -121
  275. package/dist/tsup/config-CxjGYf4K.d.ts +0 -121
  276. package/dist/tsup/context-88opQsfZ.d.cts +0 -92
  277. package/dist/tsup/context-CVEG5zfg.d.ts +0 -92
  278. package/src/actor/driver.ts +0 -141
  279. package/src/actor/instance/mod.ts +0 -2492
  280. package/src/actor/keys.test.ts +0 -275
  281. package/src/actor/utils.test.ts +0 -48
  282. package/src/agent-os/actor/cron.ts +0 -84
  283. package/src/agent-os/actor/db.ts +0 -54
  284. package/src/agent-os/actor/filesystem.ts +0 -131
  285. package/src/agent-os/actor/index.ts +0 -265
  286. package/src/agent-os/actor/network.ts +0 -58
  287. package/src/agent-os/actor/preview.ts +0 -191
  288. package/src/agent-os/actor/process.ts +0 -177
  289. package/src/agent-os/actor/session.ts +0 -518
  290. package/src/agent-os/actor/shell.ts +0 -60
  291. package/src/agent-os/config.ts +0 -79
  292. package/src/agent-os/fs/database-vfs.ts +0 -624
  293. package/src/agent-os/types.ts +0 -148
  294. package/src/client/test.ts +0 -44
  295. package/src/common/database/mod.test.ts +0 -137
  296. package/src/common/database/native-database.test.ts +0 -211
  297. package/src/common/inline-websocket-adapter.test.ts +0 -51
  298. package/src/drivers/engine/actor-driver.ts +0 -2460
  299. package/src/registry/runtime.test.ts +0 -50
  300. package/src/utils/endpoint-parser.test.ts +0 -206
  301. package/src/utils/serve.ts +0 -217
  302. package/src/utils.test.ts +0 -34
  303. /package/dist/tsup/{chunk-DZJZLZ4R.js.map → chunk-2MXBZGUP.js.map} +0 -0
@@ -1,5 +1,5 @@
1
- import { z } from "zod/v4";
2
1
  import type { VersionedDataHandler } from "vbare";
2
+ import { z } from "zod/v4";
3
3
  import { serializeWithEncoding } from "@/serde";
4
4
  import { assertUnreachable } from "./utils";
5
5
 
@@ -13,6 +13,171 @@ const JSON_COMPAT_BIGINT = "$BigInt";
13
13
  const JSON_COMPAT_ARRAY_BUFFER = "$ArrayBuffer";
14
14
  const JSON_COMPAT_UINT8_ARRAY = "$Uint8Array";
15
15
  const JSON_COMPAT_UNDEFINED = "$Undefined";
16
+ const JSON_COMPAT_SET = "$Set";
17
+
18
+ /**
19
+ * Types that cbor-x encodes natively without any compat transforms.
20
+ */
21
+ export type CborSerializable =
22
+ | string
23
+ | number
24
+ | boolean
25
+ | null
26
+ | undefined
27
+ | bigint
28
+ | Date
29
+ | RegExp
30
+ | Error
31
+ | ArrayBuffer
32
+ | Uint8Array
33
+ | Uint8ClampedArray
34
+ | Uint16Array
35
+ | Uint32Array
36
+ | BigUint64Array
37
+ | Int8Array
38
+ | Int16Array
39
+ | Int32Array
40
+ | BigInt64Array
41
+ | Float32Array
42
+ | Float64Array
43
+ | CborSerializable[]
44
+ | Map<CborSerializable, CborSerializable>
45
+ | { [key: string]: CborSerializable };
46
+
47
+ /**
48
+ * User-facing serializable type. Extends CborSerializable with Set (encoded
49
+ * as a `$Set` tagged array by the JSON compat layer).
50
+ */
51
+ export type JsonCompatValue =
52
+ | CborSerializable
53
+ | Set<JsonCompatValue>
54
+ | JsonCompatValue[]
55
+ | Map<JsonCompatValue, JsonCompatValue>
56
+ | { [key: string]: JsonCompatValue };
57
+
58
+ function isTypedArray(value: unknown): boolean {
59
+ return (
60
+ value instanceof Uint8ClampedArray ||
61
+ value instanceof Uint16Array ||
62
+ value instanceof Uint32Array ||
63
+ value instanceof BigUint64Array ||
64
+ value instanceof Int8Array ||
65
+ value instanceof Int16Array ||
66
+ value instanceof Int32Array ||
67
+ value instanceof BigInt64Array ||
68
+ value instanceof Float32Array ||
69
+ value instanceof Float64Array
70
+ );
71
+ }
72
+
73
+ /**
74
+ * Recursively validates that a value is CBOR serializable. Throws TypeError
75
+ * with a descriptive message for non-serializable values.
76
+ */
77
+ export function assertJsonCompatValue(
78
+ value: unknown,
79
+ path = "",
80
+ ): asserts value is JsonCompatValue {
81
+ if (
82
+ value === null ||
83
+ value === undefined ||
84
+ typeof value === "string" ||
85
+ typeof value === "number" ||
86
+ typeof value === "boolean" ||
87
+ typeof value === "bigint"
88
+ ) {
89
+ return;
90
+ }
91
+
92
+ if (typeof value === "function") {
93
+ throw new TypeError(
94
+ `Value at ${path || "root"} is a function and is not CBOR serializable`,
95
+ );
96
+ }
97
+
98
+ if (typeof value === "symbol") {
99
+ throw new TypeError(
100
+ `Value at ${path || "root"} is a symbol and is not CBOR serializable`,
101
+ );
102
+ }
103
+
104
+ if (
105
+ value instanceof Date ||
106
+ value instanceof RegExp ||
107
+ value instanceof Error ||
108
+ value instanceof ArrayBuffer ||
109
+ value instanceof Uint8Array ||
110
+ isTypedArray(value)
111
+ ) {
112
+ return;
113
+ }
114
+
115
+ if (value instanceof WeakMap) {
116
+ throw new TypeError(
117
+ `Value at ${path || "root"} is a WeakMap and is not CBOR serializable`,
118
+ );
119
+ }
120
+
121
+ if (value instanceof WeakSet) {
122
+ throw new TypeError(
123
+ `Value at ${path || "root"} is a WeakSet and is not CBOR serializable`,
124
+ );
125
+ }
126
+
127
+ if (value instanceof WeakRef) {
128
+ throw new TypeError(
129
+ `Value at ${path || "root"} is a WeakRef and is not CBOR serializable`,
130
+ );
131
+ }
132
+
133
+ if (value instanceof Promise) {
134
+ throw new TypeError(
135
+ `Value at ${path || "root"} is a Promise and is not CBOR serializable`,
136
+ );
137
+ }
138
+
139
+ if (value instanceof Map) {
140
+ for (const [k, v] of value.entries()) {
141
+ assertJsonCompatValue(k, `${path || "root"}.key(${String(k)})`);
142
+ assertJsonCompatValue(v, `${path || "root"}.value(${String(k)})`);
143
+ }
144
+ return;
145
+ }
146
+
147
+ if (value instanceof Set) {
148
+ let index = 0;
149
+ for (const item of value.values()) {
150
+ assertJsonCompatValue(item, `${path || "root"}.set[${index}]`);
151
+ index++;
152
+ }
153
+ return;
154
+ }
155
+
156
+ if (Array.isArray(value)) {
157
+ for (let i = 0; i < value.length; i++) {
158
+ assertJsonCompatValue(value[i], `${path || "root"}[${i}]`);
159
+ }
160
+ return;
161
+ }
162
+
163
+ if (isPlainObject(value)) {
164
+ for (const key in value) {
165
+ assertJsonCompatValue(
166
+ value[key as keyof typeof value],
167
+ path ? `${path}.${key}` : key,
168
+ );
169
+ }
170
+ return;
171
+ }
172
+
173
+ const typeName =
174
+ typeof value === "object" && value !== null
175
+ ? (value.constructor?.name ?? typeof value)
176
+ : typeof value;
177
+ throw new TypeError(
178
+ `Value at ${path || "root"} of type "${typeName}" is not CBOR serializable`,
179
+ );
180
+ }
16
181
 
17
182
  export const EncodingSchema = z.enum(["json", "cbor", "bare"]);
18
183
 
@@ -112,38 +277,97 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
112
277
  return proto === Object.prototype || proto === null;
113
278
  }
114
279
 
115
- export function encodeJsonCompatValue(input: any): any {
280
+ export function encodeJsonCompatValue(input: JsonCompatValue): unknown {
281
+ // Primitives
282
+ if (input === null) {
283
+ return input;
284
+ }
116
285
  if (input === undefined) {
117
286
  return [JSON_COMPAT_UNDEFINED, 0];
118
287
  }
288
+ if (
289
+ typeof input === "string" ||
290
+ typeof input === "number" ||
291
+ typeof input === "boolean"
292
+ ) {
293
+ return input;
294
+ }
119
295
  if (typeof input === "bigint") {
120
296
  return [JSON_COMPAT_BIGINT, input.toString()];
121
297
  }
298
+
299
+ // Binary types with custom encoding
122
300
  if (input instanceof ArrayBuffer) {
123
301
  return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];
124
302
  }
125
303
  if (input instanceof Uint8Array) {
126
304
  return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];
127
305
  }
306
+
307
+ // TypedArrays pass through for cbor-x native handling
308
+ if (isTypedArray(input)) {
309
+ return input;
310
+ }
311
+
312
+ // Date, RegExp, and Error pass through for cbor-x native handling
313
+ if (
314
+ input instanceof Date ||
315
+ input instanceof RegExp ||
316
+ input instanceof Error
317
+ ) {
318
+ return input;
319
+ }
320
+
321
+ // Set uses custom tag encoding
322
+ if (input instanceof Set) {
323
+ const encoded = [...input.values()].map((v) =>
324
+ encodeJsonCompatValue(v as JsonCompatValue),
325
+ );
326
+ return [JSON_COMPAT_SET, encoded];
327
+ }
328
+
329
+ // Map recurses into keys and values
330
+ if (input instanceof Map) {
331
+ const encoded = new Map<unknown, unknown>();
332
+ for (const [k, v] of input.entries()) {
333
+ encoded.set(
334
+ encodeJsonCompatValue(k as JsonCompatValue),
335
+ encodeJsonCompatValue(v as JsonCompatValue),
336
+ );
337
+ }
338
+ return encoded;
339
+ }
340
+
341
+ // Arrays
128
342
  if (Array.isArray(input)) {
129
- const encoded = input.map((value) => encodeJsonCompatValue(value));
343
+ const encoded = input.map((value) =>
344
+ encodeJsonCompatValue(value as JsonCompatValue),
345
+ );
130
346
  if (
131
347
  encoded.length === 2 &&
132
348
  typeof encoded[0] === "string" &&
133
- encoded[0].startsWith("$")
349
+ (encoded[0] as string).startsWith("$")
134
350
  ) {
135
- return ["$" + encoded[0], encoded[1]];
351
+ return [`$${encoded[0]}`, encoded[1]];
136
352
  }
137
353
  return encoded;
138
354
  }
355
+
356
+ // Plain objects
139
357
  if (isPlainObject(input)) {
140
358
  const encoded: Record<string, unknown> = {};
141
359
  for (const [key, value] of Object.entries(input)) {
142
- encoded[key] = encodeJsonCompatValue(value);
360
+ encoded[key] = encodeJsonCompatValue(value as JsonCompatValue);
143
361
  }
144
362
  return encoded;
145
363
  }
146
- return input;
364
+
365
+ // Not serializable
366
+ const typeName =
367
+ typeof input === "object" && input !== null
368
+ ? ((input as object).constructor?.name ?? typeof input)
369
+ : typeof input;
370
+ throw new TypeError(`Value of type "${typeName}" is not CBOR serializable`);
147
371
  }
148
372
 
149
373
  export interface JsonCompatReviveOptions {
@@ -164,6 +388,16 @@ export function reviveJsonCompatValue(
164
388
  }
165
389
  return input;
166
390
  }
391
+ if (input instanceof Map) {
392
+ const revived = new Map();
393
+ for (const [k, v] of input.entries()) {
394
+ revived.set(
395
+ reviveJsonCompatValue(k, options),
396
+ reviveJsonCompatValue(v, options),
397
+ );
398
+ }
399
+ return revived;
400
+ }
167
401
  if (Array.isArray(input)) {
168
402
  if (
169
403
  input.length === 2 &&
@@ -182,6 +416,12 @@ export function reviveJsonCompatValue(
182
416
  if (input[0] === JSON_COMPAT_UNDEFINED) {
183
417
  return undefined;
184
418
  }
419
+ if (input[0] === JSON_COMPAT_SET) {
420
+ const items = (input[1] as unknown[]).map((v) =>
421
+ reviveJsonCompatValue(v, options),
422
+ );
423
+ return new Set(items);
424
+ }
185
425
  if (input[0].startsWith("$$")) {
186
426
  return [
187
427
  input[0].substring(1),
@@ -233,33 +473,37 @@ function base64DecodeToArrayBuffer(base64: string): ArrayBuffer {
233
473
  }
234
474
 
235
475
  /** Stringifies with compat for values that BARE & CBOR supports. */
236
- export function jsonStringifyCompat(input: any): string {
237
- return JSON.stringify(input, (_key, value) => {
238
- if (typeof value === "bigint") {
239
- return [JSON_COMPAT_BIGINT, value.toString()];
240
- }
241
- if (value instanceof ArrayBuffer) {
242
- return [
243
- JSON_COMPAT_ARRAY_BUFFER,
244
- base64EncodeArrayBuffer(value),
245
- ];
246
- }
247
- if (value instanceof Uint8Array) {
248
- return [
249
- JSON_COMPAT_UINT8_ARRAY,
250
- base64EncodeUint8Array(value),
251
- ];
252
- }
253
- if (
254
- Array.isArray(value) &&
255
- value.length === 2 &&
256
- typeof value[0] === "string" &&
257
- value[0].startsWith("$")
258
- ) {
259
- return ["$" + value[0], value[1]];
260
- }
261
- return value;
262
- });
476
+ export function jsonStringifyCompat(
477
+ input: any,
478
+ space?: string | number,
479
+ ): string {
480
+ return JSON.stringify(
481
+ input,
482
+ (_key, value) => {
483
+ if (typeof value === "bigint") {
484
+ return [JSON_COMPAT_BIGINT, value.toString()];
485
+ }
486
+ if (value instanceof ArrayBuffer) {
487
+ return [
488
+ JSON_COMPAT_ARRAY_BUFFER,
489
+ base64EncodeArrayBuffer(value),
490
+ ];
491
+ }
492
+ if (value instanceof Uint8Array) {
493
+ return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
494
+ }
495
+ if (
496
+ Array.isArray(value) &&
497
+ value.length === 2 &&
498
+ typeof value[0] === "string" &&
499
+ value[0].startsWith("$")
500
+ ) {
501
+ return [`$${value[0]}`, value[1]];
502
+ }
503
+ return value;
504
+ },
505
+ space,
506
+ );
263
507
  }
264
508
 
265
509
  /** Parses JSON with compat for values that BARE & CBOR supports. */
@@ -1,2 +1,29 @@
1
+ export const ENGINE_HOST = "127.0.0.1";
1
2
  export const ENGINE_PORT = 6420;
2
- export const ENGINE_ENDPOINT = `http://127.0.0.1:${ENGINE_PORT}`;
3
+ export const ENGINE_ENDPOINT = buildEngineEndpoint(ENGINE_HOST, ENGINE_PORT);
4
+
5
+ export function buildEngineEndpoint(host: string, port: number): string {
6
+ const urlHost =
7
+ host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
8
+ return `http://${urlHost}:${port}`;
9
+ }
10
+
11
+ export function isLocalEngineEndpoint(endpoint: string): boolean {
12
+ let url: URL;
13
+ try {
14
+ url = new URL(endpoint);
15
+ } catch {
16
+ return false;
17
+ }
18
+
19
+ const hostname = url.hostname.toLowerCase();
20
+ return (
21
+ hostname === "localhost" ||
22
+ hostname === "0.0.0.0" ||
23
+ hostname === "::" ||
24
+ hostname === "[::]" ||
25
+ hostname === "::1" ||
26
+ hostname === "[::1]" ||
27
+ /^127(?:\.\d{1,3}){0,3}$/.test(hostname)
28
+ );
29
+ }
@@ -25,7 +25,7 @@ export async function importEventSource(): Promise<typeof EventSource> {
25
25
  const es = await import(/* webpackIgnore: true */ moduleName);
26
26
  _EventSource = es.EventSource;
27
27
  logger().debug("using eventsource from npm");
28
- } catch (err) {
28
+ } catch (_err) {
29
29
  // EventSource not available
30
30
  _EventSource = class MockEventSource {
31
31
  constructor() {
@@ -0,0 +1,63 @@
1
+ type HeadersLike = {
2
+ entries(): IterableIterator<[string, string]>;
3
+ };
4
+
5
+ export type RequestLike = Request & {
6
+ readonly headers: HeadersLike & Request["headers"];
7
+ };
8
+
9
+ export type ResponseLike = Response & {
10
+ readonly headers: HeadersLike & Response["headers"];
11
+ };
12
+
13
+ export function isUrlLike(value: unknown): value is URL {
14
+ return (
15
+ typeof value === "object" &&
16
+ value !== null &&
17
+ typeof (value as URL).href === "string" &&
18
+ typeof (value as URL).pathname === "string" &&
19
+ typeof (value as URL).search === "string"
20
+ );
21
+ }
22
+
23
+ export function isRequestLike(value: unknown): value is RequestLike {
24
+ return (
25
+ typeof value === "object" &&
26
+ value !== null &&
27
+ typeof (value as Request).url === "string" &&
28
+ typeof (value as Request).method === "string" &&
29
+ isHeadersLike((value as Request).headers)
30
+ );
31
+ }
32
+
33
+ export function isResponseLike(value: unknown): value is ResponseLike {
34
+ return (
35
+ typeof value === "object" &&
36
+ value !== null &&
37
+ typeof (value as Response).status === "number" &&
38
+ isHeadersLike((value as Response).headers) &&
39
+ typeof (value as Response).arrayBuffer === "function"
40
+ );
41
+ }
42
+
43
+ function isHeadersLike(value: unknown): value is HeadersLike {
44
+ return (
45
+ typeof value === "object" &&
46
+ value !== null &&
47
+ typeof (value as HeadersLike).entries === "function"
48
+ );
49
+ }
50
+
51
+ /**
52
+ * Reads a request body into bytes. Aborting the request's signal cancels the
53
+ * body and rejects the read.
54
+ */
55
+ export function readRequestBody(request: Request): Promise<ArrayBuffer> {
56
+ // Firefox has no Request.body.
57
+ if (!request.body) return request.arrayBuffer();
58
+ return new Response(
59
+ request.body.pipeThrough(new TransformStream(), {
60
+ signal: request.signal,
61
+ }),
62
+ ).arrayBuffer();
63
+ }
@@ -1,7 +1,7 @@
1
+ import { VirtualWebSocket } from "@rivetkit/virtual-websocket";
1
2
  import { WSContext } from "hono/ws";
2
3
  import type { UpgradeWebSocketArgs } from "@/common/actor-websocket";
3
4
  import type { UniversalWebSocket } from "@/common/websocket-interface";
4
- import { VirtualWebSocket } from "@rivetkit/virtual-websocket";
5
5
  import { getLogger } from "./log";
6
6
 
7
7
  function logger() {
@@ -161,28 +161,29 @@ export class InlineWebSocketAdapter {
161
161
  }
162
162
  }
163
163
 
164
- #handleError(err: unknown): void {
165
- console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", err);
164
+ #handleError(error: unknown): void {
165
+ console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", error);
166
166
  logger().error({
167
167
  msg: "error in websocket",
168
- error: err,
169
- errorMessage: err instanceof Error ? err.message : String(err),
170
- stack: err instanceof Error ? err.stack : undefined,
168
+ error,
169
+ errorMessage:
170
+ error instanceof Error ? error.message : String(error),
171
+ stack: error instanceof Error ? error.stack : undefined,
171
172
  });
172
173
 
173
174
  // Call handler.onError
174
175
  try {
175
- this.#handler.onError(err, this.#wsContext);
176
- } catch (handlerErr) {
176
+ this.#handler.onError(error, this.#wsContext);
177
+ } catch (error) {
177
178
  logger().error({
178
179
  msg: "error in onError handler",
179
- error: handlerErr,
180
+ error,
180
181
  });
181
182
  }
182
183
 
183
184
  // Fire error event to both sides
184
- this.#clientWs.triggerError(err);
185
- this.#actorWs.triggerError(err);
185
+ this.#clientWs.triggerError(error);
186
+ this.#actorWs.triggerError(error);
186
187
  }
187
188
 
188
189
  #close(code: number, reason: string): void {
@@ -199,8 +200,8 @@ export class InlineWebSocketAdapter {
199
200
  { code, reason, wasClean: true },
200
201
  this.#wsContext,
201
202
  );
202
- } catch (err) {
203
- logger().error({ msg: "error closing websocket", error: err });
203
+ } catch (error) {
204
+ logger().error({ msg: "error closing websocket", error });
204
205
  } finally {
205
206
  this.#readyState = 3; // CLOSED
206
207
 
@@ -5,10 +5,20 @@ import {
5
5
  } from "@/common/bare/transport/v1";
6
6
  import { bufferToArrayBuffer, toUint8Array } from "@/utils";
7
7
 
8
+ declare const workflowHistoryBare: unique symbol;
9
+
10
+ // Branded so these bytes cannot be handed to the CBOR compat encoder, which
11
+ // would rewrite the buffer as `["$ArrayBuffer", "<base64>"]`.
12
+ export type WorkflowHistoryBytes = ArrayBuffer & {
13
+ readonly [workflowHistoryBare]: true;
14
+ };
15
+
8
16
  export function encodeWorkflowHistoryTransport(
9
17
  history: WorkflowHistory,
10
- ): ArrayBuffer {
11
- return bufferToArrayBuffer(encodeWorkflowHistory(history));
18
+ ): WorkflowHistoryBytes {
19
+ return bufferToArrayBuffer(
20
+ encodeWorkflowHistory(history),
21
+ ) as WorkflowHistoryBytes;
12
22
  }
13
23
 
14
24
  export function decodeWorkflowHistoryTransport(
package/src/common/log.ts CHANGED
@@ -62,20 +62,16 @@ export function configureBaseLogger(logger: Logger): void {
62
62
  }
63
63
 
64
64
  /**
65
- * Configure the default logger with optional log level.
65
+ * Create the default logger with optional log level.
66
66
  */
67
- export function configureDefaultLogger(logLevel?: LogLevel) {
68
- // Store the configured log level
69
- if (logLevel) {
70
- configuredLogLevel = logLevel;
71
- }
72
-
73
- baseLogger = pino(
67
+ export function makeDefaultLogger(logLevel?: LogLevel): Logger {
68
+ return pino(
74
69
  {
75
70
  level: getPinoLevel(logLevel),
76
71
  messageKey: "msg",
77
72
  // Do not include pid/hostname in output
78
73
  base: {},
74
+ errorKey: "error",
79
75
  // Keep the numeric level so the logfmt sink can match Pino's levels.
80
76
  formatters: {
81
77
  level(_label: string, number: number) {
@@ -86,7 +82,18 @@ export function configureDefaultLogger(logLevel?: LogLevel) {
86
82
  },
87
83
  createLogfmtDestination(),
88
84
  );
85
+ }
86
+
87
+ /**
88
+ * Configure the default logger with optional log level.
89
+ */
90
+ export function configureDefaultLogger(logLevel?: LogLevel) {
91
+ // Store the configured log level
92
+ if (logLevel) {
93
+ configuredLogLevel = logLevel;
94
+ }
89
95
 
96
+ baseLogger = makeDefaultLogger(logLevel);
90
97
  loggerCache.clear();
91
98
  }
92
99