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
@@ -122,71 +122,73 @@ const v4HttpResponseErrorToV3 = (
122
122
  return rest;
123
123
  };
124
124
 
125
- export const CLIENT_PROTOCOL_TO_SERVER = createVersionedDataHandler<v4.ToServer>({
126
- deserializeVersion: (bytes, version) => {
127
- switch (version) {
128
- case 1:
129
- return v1.decodeToServer(bytes);
130
- case 2:
131
- return v2.decodeToServer(bytes);
132
- case 3:
133
- return v3.decodeToServer(bytes);
134
- case 4:
135
- return v4.decodeToServer(bytes);
136
- default:
137
- throw new Error(`Unknown version ${version}`);
138
- }
139
- },
140
- serializeVersion: (data, version) => {
141
- switch (version) {
142
- case 1:
143
- return v1.encodeToServer(data as v1.ToServer);
144
- case 2:
145
- return v2.encodeToServer(data as v2.ToServer);
146
- case 3:
147
- return v3.encodeToServer(data as v3.ToServer);
148
- case 4:
149
- return v4.encodeToServer(data as v4.ToServer);
150
- default:
151
- throw new Error(`Unknown version ${version}`);
152
- }
153
- },
154
- deserializeConverters: () => [v1ToServerV2, v2ToServerV3, v3ToServerV4],
155
- serializeConverters: () => [v4ToServerV3, v3ToServerV2, v2ToServerV1],
156
- });
125
+ export const CLIENT_PROTOCOL_TO_SERVER =
126
+ createVersionedDataHandler<v4.ToServer>({
127
+ deserializeVersion: (bytes, version) => {
128
+ switch (version) {
129
+ case 1:
130
+ return v1.decodeToServer(bytes);
131
+ case 2:
132
+ return v2.decodeToServer(bytes);
133
+ case 3:
134
+ return v3.decodeToServer(bytes);
135
+ case 4:
136
+ return v4.decodeToServer(bytes);
137
+ default:
138
+ throw new Error(`Unknown version ${version}`);
139
+ }
140
+ },
141
+ serializeVersion: (data, version) => {
142
+ switch (version) {
143
+ case 1:
144
+ return v1.encodeToServer(data as v1.ToServer);
145
+ case 2:
146
+ return v2.encodeToServer(data as v2.ToServer);
147
+ case 3:
148
+ return v3.encodeToServer(data as v3.ToServer);
149
+ case 4:
150
+ return v4.encodeToServer(data as v4.ToServer);
151
+ default:
152
+ throw new Error(`Unknown version ${version}`);
153
+ }
154
+ },
155
+ deserializeConverters: () => [v1ToServerV2, v2ToServerV3, v3ToServerV4],
156
+ serializeConverters: () => [v4ToServerV3, v3ToServerV2, v2ToServerV1],
157
+ });
157
158
 
158
- export const CLIENT_PROTOCOL_TO_CLIENT = createVersionedDataHandler<v4.ToClient>({
159
- deserializeVersion: (bytes, version) => {
160
- switch (version) {
161
- case 1:
162
- return v1.decodeToClient(bytes);
163
- case 2:
164
- return v2.decodeToClient(bytes);
165
- case 3:
166
- return v3.decodeToClient(bytes);
167
- case 4:
168
- return v4.decodeToClient(bytes);
169
- default:
170
- throw new Error(`Unknown version ${version}`);
171
- }
172
- },
173
- serializeVersion: (data, version) => {
174
- switch (version) {
175
- case 1:
176
- return v1.encodeToClient(data as v1.ToClient);
177
- case 2:
178
- return v2.encodeToClient(data as v2.ToClient);
179
- case 3:
180
- return v3.encodeToClient(data as v3.ToClient);
181
- case 4:
182
- return v4.encodeToClient(data as v4.ToClient);
183
- default:
184
- throw new Error(`Unknown version ${version}`);
185
- }
186
- },
187
- deserializeConverters: () => [v1ToV2, v2ToV3, v3ToV4],
188
- serializeConverters: () => [v4ToV3, v3ToV2, v2ToV1],
189
- });
159
+ export const CLIENT_PROTOCOL_TO_CLIENT =
160
+ createVersionedDataHandler<v4.ToClient>({
161
+ deserializeVersion: (bytes, version) => {
162
+ switch (version) {
163
+ case 1:
164
+ return v1.decodeToClient(bytes);
165
+ case 2:
166
+ return v2.decodeToClient(bytes);
167
+ case 3:
168
+ return v3.decodeToClient(bytes);
169
+ case 4:
170
+ return v4.decodeToClient(bytes);
171
+ default:
172
+ throw new Error(`Unknown version ${version}`);
173
+ }
174
+ },
175
+ serializeVersion: (data, version) => {
176
+ switch (version) {
177
+ case 1:
178
+ return v1.encodeToClient(data as v1.ToClient);
179
+ case 2:
180
+ return v2.encodeToClient(data as v2.ToClient);
181
+ case 3:
182
+ return v3.encodeToClient(data as v3.ToClient);
183
+ case 4:
184
+ return v4.encodeToClient(data as v4.ToClient);
185
+ default:
186
+ throw new Error(`Unknown version ${version}`);
187
+ }
188
+ },
189
+ deserializeConverters: () => [v1ToV2, v2ToV3, v3ToV4],
190
+ serializeConverters: () => [v4ToV3, v3ToV2, v2ToV1],
191
+ });
190
192
 
191
193
  export const HTTP_ACTION_REQUEST_VERSIONED =
192
194
  createVersionedDataHandler<v4.HttpActionRequest>({
@@ -42,10 +42,7 @@ export interface SqliteDatabase {
42
42
  sql: string,
43
43
  callback?: (row: unknown[], columns: string[]) => void,
44
44
  ): Promise<void>;
45
- execute(
46
- sql: string,
47
- params?: SqliteBindings,
48
- ): Promise<SqliteExecuteResult>;
45
+ execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
49
46
  run(sql: string, params?: SqliteBindings): Promise<void>;
50
47
  query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
51
48
  nativeMetrics?():
@@ -132,10 +129,7 @@ export interface RawDatabaseClient {
132
129
  /**
133
130
  * Drizzle database client interface (will be extended by drizzle-orm types)
134
131
  */
135
- export interface DrizzleDatabaseClient {
136
- // This will be extended by BaseSQLiteDatabase from drizzle-orm
137
- // For now, just a marker interface
138
- }
132
+ export type DrizzleDatabaseClient = {};
139
133
 
140
134
  type ExecuteFunction = <
141
135
  TRow extends Record<string, unknown> = Record<string, unknown>,
@@ -97,7 +97,7 @@ function enrichNativeDatabaseError(
97
97
  ? error
98
98
  : error instanceof Error
99
99
  ? error.message
100
- : undefined;
100
+ : undefined;
101
101
  const bridged =
102
102
  bridgeReason === undefined
103
103
  ? undefined
@@ -1,4 +1,5 @@
1
1
  import type { SqliteBindings } from "./config";
2
+
2
3
  type SqliteBindingObject = Record<string, unknown>;
3
4
 
4
5
  function isSqliteBindingValue(value: unknown): boolean {
@@ -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),
@@ -239,16 +479,10 @@ export function jsonStringifyCompat(input: any): string {
239
479
  return [JSON_COMPAT_BIGINT, value.toString()];
240
480
  }
241
481
  if (value instanceof ArrayBuffer) {
242
- return [
243
- JSON_COMPAT_ARRAY_BUFFER,
244
- base64EncodeArrayBuffer(value),
245
- ];
482
+ return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(value)];
246
483
  }
247
484
  if (value instanceof Uint8Array) {
248
- return [
249
- JSON_COMPAT_UINT8_ARRAY,
250
- base64EncodeUint8Array(value),
251
- ];
485
+ return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
252
486
  }
253
487
  if (
254
488
  Array.isArray(value) &&
@@ -256,7 +490,7 @@ export function jsonStringifyCompat(input: any): string {
256
490
  typeof value[0] === "string" &&
257
491
  value[0].startsWith("$")
258
492
  ) {
259
- return ["$" + value[0], value[1]];
493
+ return [`$${value[0]}`, value[1]];
260
494
  }
261
495
  return value;
262
496
  });
@@ -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() {
@@ -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
 
package/src/common/log.ts CHANGED
@@ -76,6 +76,7 @@ export function configureDefaultLogger(logLevel?: LogLevel) {
76
76
  messageKey: "msg",
77
77
  // Do not include pid/hostname in output
78
78
  base: {},
79
+ errorKey: "error",
79
80
  // Keep the numeric level so the logfmt sink can match Pino's levels.
80
81
  formatters: {
81
82
  level(_label: string, number: number) {