rivetkit 2.3.0-rc.7 → 2.3.0-rc.9

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 (122) hide show
  1. package/dist/browser/client.d.ts +8 -37
  2. package/dist/browser/client.js +34 -64
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +3 -4
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +2 -2
  7. package/dist/tsup/actor/errors.js +1 -1
  8. package/dist/tsup/agent-os/index.cjs +5 -7
  9. package/dist/tsup/agent-os/index.cjs.map +1 -1
  10. package/dist/tsup/agent-os/index.d.cts +5 -26
  11. package/dist/tsup/agent-os/index.d.ts +5 -26
  12. package/dist/tsup/agent-os/index.js +5 -7
  13. package/dist/tsup/agent-os/index.js.map +1 -1
  14. package/dist/tsup/{chunk-55E7IR6D.cjs → chunk-4CGA6QJO.cjs} +4 -4
  15. package/dist/tsup/{chunk-55E7IR6D.cjs.map → chunk-4CGA6QJO.cjs.map} +1 -1
  16. package/dist/tsup/{chunk-G5HUSWP4.cjs → chunk-4WPEZBK4.cjs} +8 -8
  17. package/dist/tsup/{chunk-G5HUSWP4.cjs.map → chunk-4WPEZBK4.cjs.map} +1 -1
  18. package/dist/tsup/{chunk-2H4ISA4Y.cjs → chunk-CPA4Y3RG.cjs} +10 -10
  19. package/dist/tsup/chunk-CPA4Y3RG.cjs.map +1 -0
  20. package/dist/tsup/{chunk-VJ4Y4WBT.js → chunk-F3Q5BFQ6.js} +34 -10
  21. package/dist/tsup/chunk-F3Q5BFQ6.js.map +1 -0
  22. package/dist/tsup/{chunk-ZGPX6KAH.cjs → chunk-GVTOE34S.cjs} +193 -169
  23. package/dist/tsup/chunk-GVTOE34S.cjs.map +1 -0
  24. package/dist/tsup/{chunk-4DJMFOSU.js → chunk-H37XQU3I.js} +2 -2
  25. package/dist/tsup/{chunk-CMV6N5OX.js → chunk-H7P7WR2Y.js} +3 -3
  26. package/dist/tsup/{chunk-TMLOKTRB.js → chunk-KIWH5H3K.js} +3 -3
  27. package/dist/tsup/chunk-KIWH5H3K.js.map +1 -0
  28. package/dist/tsup/{chunk-52TPEKEC.js → chunk-KJTA3ATT.js} +2 -2
  29. package/dist/tsup/{chunk-SJLPZEA3.cjs → chunk-MALSPBAF.cjs} +3 -3
  30. package/dist/tsup/{chunk-SJLPZEA3.cjs.map → chunk-MALSPBAF.cjs.map} +1 -1
  31. package/dist/tsup/{chunk-VFIY6GWO.js → chunk-MMMEZM5J.js} +4 -4
  32. package/dist/tsup/chunk-MMMEZM5J.js.map +1 -0
  33. package/dist/tsup/{chunk-63WNTDRC.cjs → chunk-QAZLM4WT.cjs} +3 -3
  34. package/dist/tsup/{chunk-63WNTDRC.cjs.map → chunk-QAZLM4WT.cjs.map} +1 -1
  35. package/dist/tsup/{chunk-D5G75T7J.js → chunk-T6YVRM4K.js} +1 -3
  36. package/dist/tsup/chunk-T6YVRM4K.js.map +1 -0
  37. package/dist/tsup/{chunk-FEOG44WH.cjs → chunk-VJFRBJVQ.cjs} +9 -137
  38. package/dist/tsup/chunk-VJFRBJVQ.cjs.map +1 -0
  39. package/dist/tsup/{chunk-HERL2VQ2.js → chunk-VRCIXJRN.js} +5 -7
  40. package/dist/tsup/chunk-VRCIXJRN.js.map +1 -0
  41. package/dist/tsup/{chunk-4LTY5TOO.js → chunk-W7EYSYVI.js} +4 -132
  42. package/dist/tsup/chunk-W7EYSYVI.js.map +1 -0
  43. package/dist/tsup/{chunk-SRNOPUC6.cjs → chunk-WQ4HNA4W.cjs} +2 -4
  44. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +1 -0
  45. package/dist/tsup/{chunk-X6HIFXNK.cjs → chunk-Y5NSCZA2.cjs} +12 -14
  46. package/dist/tsup/chunk-Y5NSCZA2.cjs.map +1 -0
  47. package/dist/tsup/client/mod.cjs +7 -7
  48. package/dist/tsup/client/mod.d.cts +2 -2
  49. package/dist/tsup/client/mod.d.ts +2 -2
  50. package/dist/tsup/client/mod.js +6 -6
  51. package/dist/tsup/common/log.cjs +3 -3
  52. package/dist/tsup/common/log.js +2 -2
  53. package/dist/tsup/common/websocket.cjs +4 -4
  54. package/dist/tsup/common/websocket.js +3 -3
  55. package/dist/tsup/{config-Ak1lv4gF.d.ts → config-0Ta55UV0.d.ts} +6 -27
  56. package/dist/tsup/{config-DU_xj4qZ.d.cts → config-Ca8dN4cS.d.cts} +6 -27
  57. package/dist/tsup/{context-DAAp4Lpg.d.ts → context-B_IWbWne.d.ts} +1 -1
  58. package/dist/tsup/{context-Dt_L55q8.d.cts → context-CUrQ9MHc.d.cts} +1 -1
  59. package/dist/tsup/inspector/mod.cjs +6 -6
  60. package/dist/tsup/inspector/mod.js +5 -5
  61. package/dist/tsup/mod.cjs +355 -482
  62. package/dist/tsup/mod.cjs.map +1 -1
  63. package/dist/tsup/mod.d.cts +3 -3
  64. package/dist/tsup/mod.d.ts +3 -3
  65. package/dist/tsup/mod.js +276 -403
  66. package/dist/tsup/mod.js.map +1 -1
  67. package/dist/tsup/test/mod.cjs +10 -10
  68. package/dist/tsup/test/mod.d.cts +1 -1
  69. package/dist/tsup/test/mod.d.ts +1 -1
  70. package/dist/tsup/test/mod.js +6 -6
  71. package/dist/tsup/utils.cjs +3 -3
  72. package/dist/tsup/utils.js +2 -2
  73. package/dist/tsup/workflow/mod.cjs +16 -41
  74. package/dist/tsup/workflow/mod.cjs.map +1 -1
  75. package/dist/tsup/workflow/mod.d.cts +3 -3
  76. package/dist/tsup/workflow/mod.d.ts +3 -3
  77. package/dist/tsup/workflow/mod.js +10 -35
  78. package/dist/tsup/workflow/mod.js.map +1 -1
  79. package/package.json +10 -11
  80. package/src/actor/config.ts +0 -3
  81. package/src/actor/errors.ts +2 -2
  82. package/src/agent-os/actor/session.ts +2 -2
  83. package/src/client/actor-conn.ts +34 -6
  84. package/src/client/actor-handle.ts +1 -2
  85. package/src/client/queue.ts +1 -2
  86. package/src/client/utils.ts +1 -0
  87. package/src/common/encoding.ts +5 -243
  88. package/src/common/inline-websocket-adapter.ts +12 -12
  89. package/src/common/log.ts +0 -1
  90. package/src/common/router.ts +2 -2
  91. package/src/common/utils.ts +148 -0
  92. package/src/drivers/engine/actor-driver.ts +11 -11
  93. package/src/engine-client/actor-websocket-client.ts +1 -2
  94. package/src/engine-client/mod.ts +2 -3
  95. package/src/registry/index.ts +109 -46
  96. package/src/registry/napi-runtime.ts +34 -11
  97. package/src/registry/native.ts +162 -205
  98. package/src/registry/runtime.ts +12 -5
  99. package/src/registry/wasm-runtime.ts +13 -2
  100. package/src/serde.ts +2 -2
  101. package/src/workflow/context.ts +5 -32
  102. package/src/workflow/inspector.ts +1 -2
  103. package/dist/tsup/chunk-2H4ISA4Y.cjs.map +0 -1
  104. package/dist/tsup/chunk-4LTY5TOO.js.map +0 -1
  105. package/dist/tsup/chunk-D5G75T7J.js.map +0 -1
  106. package/dist/tsup/chunk-FEOG44WH.cjs.map +0 -1
  107. package/dist/tsup/chunk-HERL2VQ2.js.map +0 -1
  108. package/dist/tsup/chunk-SRNOPUC6.cjs.map +0 -1
  109. package/dist/tsup/chunk-TMLOKTRB.js.map +0 -1
  110. package/dist/tsup/chunk-VFIY6GWO.js.map +0 -1
  111. package/dist/tsup/chunk-VJ4Y4WBT.js.map +0 -1
  112. package/dist/tsup/chunk-X6HIFXNK.cjs.map +0 -1
  113. package/dist/tsup/chunk-ZGPX6KAH.cjs.map +0 -1
  114. package/dist/tsup/process-metrics-NW754INA.js +0 -118
  115. package/dist/tsup/process-metrics-NW754INA.js.map +0 -1
  116. package/dist/tsup/process-metrics-TYAGKCEJ.cjs +0 -118
  117. package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +0 -1
  118. package/src/registry/process-metrics.ts +0 -183
  119. package/src/registry/write-through-proxy.ts +0 -40
  120. /package/dist/tsup/{chunk-4DJMFOSU.js.map → chunk-H37XQU3I.js.map} +0 -0
  121. /package/dist/tsup/{chunk-CMV6N5OX.js.map → chunk-H7P7WR2Y.js.map} +0 -0
  122. /package/dist/tsup/{chunk-52TPEKEC.js.map → chunk-KJTA3ATT.js.map} +0 -0
@@ -13,171 +13,6 @@ 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
- }
181
16
 
182
17
  export const EncodingSchema = z.enum(["json", "cbor", "bare"]);
183
18
 
@@ -277,95 +112,38 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
277
112
  return proto === Object.prototype || proto === null;
278
113
  }
279
114
 
280
- export function encodeJsonCompatValue(input: JsonCompatValue): unknown {
281
- // Primitives
282
- if (input === null) {
283
- return input;
284
- }
115
+ export function encodeJsonCompatValue(input: any): any {
285
116
  if (input === undefined) {
286
117
  return [JSON_COMPAT_UNDEFINED, 0];
287
118
  }
288
- if (
289
- typeof input === "string" ||
290
- typeof input === "number" ||
291
- typeof input === "boolean"
292
- ) {
293
- return input;
294
- }
295
119
  if (typeof input === "bigint") {
296
120
  return [JSON_COMPAT_BIGINT, input.toString()];
297
121
  }
298
-
299
- // Binary types with custom encoding
300
122
  if (input instanceof ArrayBuffer) {
301
123
  return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];
302
124
  }
303
125
  if (input instanceof Uint8Array) {
304
126
  return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];
305
127
  }
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 (input instanceof Date || input instanceof RegExp || input instanceof Error) {
314
- return input;
315
- }
316
-
317
- // Set uses custom tag encoding
318
- if (input instanceof Set) {
319
- const encoded = [...input.values()].map((v) =>
320
- encodeJsonCompatValue(v as JsonCompatValue),
321
- );
322
- return [JSON_COMPAT_SET, encoded];
323
- }
324
-
325
- // Map recurses into keys and values
326
- if (input instanceof Map) {
327
- const encoded = new Map<unknown, unknown>();
328
- for (const [k, v] of input.entries()) {
329
- encoded.set(
330
- encodeJsonCompatValue(k as JsonCompatValue),
331
- encodeJsonCompatValue(v as JsonCompatValue),
332
- );
333
- }
334
- return encoded;
335
- }
336
-
337
- // Arrays
338
128
  if (Array.isArray(input)) {
339
- const encoded = input.map((value) =>
340
- encodeJsonCompatValue(value as JsonCompatValue),
341
- );
129
+ const encoded = input.map((value) => encodeJsonCompatValue(value));
342
130
  if (
343
131
  encoded.length === 2 &&
344
132
  typeof encoded[0] === "string" &&
345
- (encoded[0] as string).startsWith("$")
133
+ encoded[0].startsWith("$")
346
134
  ) {
347
135
  return ["$" + encoded[0], encoded[1]];
348
136
  }
349
137
  return encoded;
350
138
  }
351
-
352
- // Plain objects
353
139
  if (isPlainObject(input)) {
354
140
  const encoded: Record<string, unknown> = {};
355
141
  for (const [key, value] of Object.entries(input)) {
356
- encoded[key] = encodeJsonCompatValue(value as JsonCompatValue);
142
+ encoded[key] = encodeJsonCompatValue(value);
357
143
  }
358
144
  return encoded;
359
145
  }
360
-
361
- // Not serializable
362
- const typeName =
363
- typeof input === "object" && input !== null
364
- ? (input as object).constructor?.name ?? typeof input
365
- : typeof input;
366
- throw new TypeError(
367
- `Value of type "${typeName}" is not CBOR serializable`,
368
- );
146
+ return input;
369
147
  }
370
148
 
371
149
  export interface JsonCompatReviveOptions {
@@ -386,16 +164,6 @@ export function reviveJsonCompatValue(
386
164
  }
387
165
  return input;
388
166
  }
389
- if (input instanceof Map) {
390
- const revived = new Map();
391
- for (const [k, v] of input.entries()) {
392
- revived.set(
393
- reviveJsonCompatValue(k, options),
394
- reviveJsonCompatValue(v, options),
395
- );
396
- }
397
- return revived;
398
- }
399
167
  if (Array.isArray(input)) {
400
168
  if (
401
169
  input.length === 2 &&
@@ -414,12 +182,6 @@ export function reviveJsonCompatValue(
414
182
  if (input[0] === JSON_COMPAT_UNDEFINED) {
415
183
  return undefined;
416
184
  }
417
- if (input[0] === JSON_COMPAT_SET) {
418
- const items = (input[1] as unknown[]).map((v) =>
419
- reviveJsonCompatValue(v, options),
420
- );
421
- return new Set(items);
422
- }
423
185
  if (input[0].startsWith("$$")) {
424
186
  return [
425
187
  input[0].substring(1),
@@ -161,28 +161,28 @@ export class InlineWebSocketAdapter {
161
161
  }
162
162
  }
163
163
 
164
- #handleError(error: unknown): void {
165
- console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", error);
164
+ #handleError(err: unknown): void {
165
+ console.error("INLINE_WEBSOCKET_ADAPTER_ERROR", err);
166
166
  logger().error({
167
167
  msg: "error in websocket",
168
- error,
169
- errorMessage: error instanceof Error ? error.message : String(error),
170
- stack: error instanceof Error ? error.stack : undefined,
168
+ error: err,
169
+ errorMessage: err instanceof Error ? err.message : String(err),
170
+ stack: err instanceof Error ? err.stack : undefined,
171
171
  });
172
172
 
173
173
  // Call handler.onError
174
174
  try {
175
- this.#handler.onError(error, this.#wsContext);
176
- } catch (error) {
175
+ this.#handler.onError(err, this.#wsContext);
176
+ } catch (handlerErr) {
177
177
  logger().error({
178
178
  msg: "error in onError handler",
179
- error,
179
+ error: handlerErr,
180
180
  });
181
181
  }
182
182
 
183
183
  // Fire error event to both sides
184
- this.#clientWs.triggerError(error);
185
- this.#actorWs.triggerError(error);
184
+ this.#clientWs.triggerError(err);
185
+ this.#actorWs.triggerError(err);
186
186
  }
187
187
 
188
188
  #close(code: number, reason: string): void {
@@ -199,8 +199,8 @@ export class InlineWebSocketAdapter {
199
199
  { code, reason, wasClean: true },
200
200
  this.#wsContext,
201
201
  );
202
- } catch (error) {
203
- logger().error({ msg: "error closing websocket", error });
202
+ } catch (err) {
203
+ logger().error({ msg: "error closing websocket", error: err });
204
204
  } finally {
205
205
  this.#readyState = 3; // CLOSED
206
206
 
package/src/common/log.ts CHANGED
@@ -76,7 +76,6 @@ export function configureDefaultLogger(logLevel?: LogLevel) {
76
76
  messageKey: "msg",
77
77
  // Do not include pid/hostname in output
78
78
  base: {},
79
- errorKey: "error",
80
79
  // Keep the numeric level so the logfmt sink can match Pino's levels.
81
80
  formatters: {
82
81
  level(_label: string, number: number) {
@@ -6,7 +6,7 @@ import {
6
6
  HEADER_ACTOR_ID,
7
7
  HEADER_ACTOR_KEY,
8
8
  } from "@/common/actor-router-consts";
9
- import type { JsonCompatValue, Encoding } from "@/common/encoding";
9
+ import type { Encoding } from "@/common/encoding";
10
10
  import {
11
11
  getRequestEncoding,
12
12
  getRequestExposeInternalError,
@@ -111,7 +111,7 @@ export function handleRouteError(error: unknown, c: HonoContext) {
111
111
  code: value.code,
112
112
  message: value.message,
113
113
  metadata: value.metadata
114
- ? bufferToArrayBuffer(encodeCborCompat(value.metadata as JsonCompatValue))
114
+ ? bufferToArrayBuffer(encodeCborCompat(value.metadata))
115
115
  : null,
116
116
  actor: value.actor
117
117
  ? {
@@ -36,6 +36,154 @@ 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
+ }
39
187
 
40
188
  export interface DeconstructedError {
41
189
  __type: "ActorError";
@@ -284,7 +284,7 @@ export class EngineActorDriver implements ActorDriver {
284
284
  logger().debug({
285
285
  msg: "actor crash cleanup errored",
286
286
  actorId,
287
- error: stringifyError(err),
287
+ err: stringifyError(err),
288
288
  });
289
289
  }
290
290
  }
@@ -1357,7 +1357,7 @@ export class EngineActorDriver implements ActorDriver {
1357
1357
  logger().warn({
1358
1358
  msg: "failed to rebind dynamic hibernatable runner websocket",
1359
1359
  actorId,
1360
- error: stringifyError(result.reason),
1360
+ err: stringifyError(result.reason),
1361
1361
  });
1362
1362
  }
1363
1363
  }
@@ -1380,7 +1380,7 @@ export class EngineActorDriver implements ActorDriver {
1380
1380
  logger().warn({
1381
1381
  msg: "failed to rebind hibernatable connect socket",
1382
1382
  actorId,
1383
- error: stringifyError(result.reason),
1383
+ err: stringifyError(result.reason),
1384
1384
  });
1385
1385
  }
1386
1386
  }
@@ -1640,7 +1640,7 @@ export class EngineActorDriver implements ActorDriver {
1640
1640
  logger().warn({
1641
1641
  msg: "failed to restore dynamic hibernating requests after actor start",
1642
1642
  actorId,
1643
- error: stringifyError(error),
1643
+ err: stringifyError(error),
1644
1644
  });
1645
1645
  }
1646
1646
  } else if (isStaticActorDefinition(definition)) {
@@ -1707,7 +1707,7 @@ export class EngineActorDriver implements ActorDriver {
1707
1707
  logger().debug({
1708
1708
  msg: "failed to dispose dynamic runtime after actor start failure",
1709
1709
  actorId,
1710
- error: stringifyError(disposeError),
1710
+ err: stringifyError(disposeError),
1711
1711
  });
1712
1712
  }
1713
1713
  this.#dynamicRuntimes.delete(actorId);
@@ -1730,7 +1730,7 @@ export class EngineActorDriver implements ActorDriver {
1730
1730
  actorId,
1731
1731
  name,
1732
1732
  key,
1733
- error: stringifyError(error),
1733
+ err: stringifyError(error),
1734
1734
  });
1735
1735
 
1736
1736
  try {
@@ -1739,7 +1739,7 @@ export class EngineActorDriver implements ActorDriver {
1739
1739
  logger().debug({
1740
1740
  msg: "failed to stop actor after start failure",
1741
1741
  actorId,
1742
- error: stringifyError(stopError),
1742
+ err: stringifyError(stopError),
1743
1743
  });
1744
1744
  }
1745
1745
  }
@@ -1786,7 +1786,7 @@ export class EngineActorDriver implements ActorDriver {
1786
1786
  logger().debug({
1787
1787
  msg: "actor start failed during stop, cleaning up handler",
1788
1788
  actorId,
1789
- error: stringifyError(err),
1789
+ err: stringifyError(err),
1790
1790
  });
1791
1791
  }
1792
1792
  }
@@ -1804,7 +1804,7 @@ export class EngineActorDriver implements ActorDriver {
1804
1804
  } catch (err) {
1805
1805
  logger().error({
1806
1806
  msg: "error in onStop, proceeding with removing actor",
1807
- error: stringifyError(err),
1807
+ err: stringifyError(err),
1808
1808
  });
1809
1809
  }
1810
1810
  }
@@ -1989,8 +1989,8 @@ export class EngineActorDriver implements ActorDriver {
1989
1989
  isHibernatable,
1990
1990
  isRestoringHibernatable,
1991
1991
  );
1992
- } catch (error) {
1993
- logger().error({ msg: "building websocket handlers errored", error });
1992
+ } catch (err) {
1993
+ logger().error({ msg: "building websocket handlers errored", err });
1994
1994
  websocketRaw.close(1011, "ws.route_error");
1995
1995
  return;
1996
1996
  }
@@ -16,7 +16,6 @@ import { importWebSocket } from "@/common/websocket";
16
16
  import { setRemoteHibernatableWebSocketAckTestHooks } from "@/common/websocket-test-hooks";
17
17
  import type { ActorGatewayQuery, CrashPolicy } from "@/client/query";
18
18
  import type { Encoding, UniversalWebSocket } from "@/mod";
19
- import type { JsonCompatValue } from "@/common/encoding";
20
19
  import { encodeCborCompat, uint8ArrayToBase64 } from "@/serde";
21
20
  import { combineUrlPath } from "@/utils";
22
21
  import { shouldSkipReadyWait, type GatewayRequestOptions } from "./driver";
@@ -303,7 +302,7 @@ function pushInputQueryParam(
303
302
  return;
304
303
  }
305
304
 
306
- const encodedInput = encodeCborCompat(input as JsonCompatValue);
305
+ const encodedInput = encodeCborCompat(input);
307
306
  if (encodedInput.byteLength > maxInputSize) {
308
307
  throw new Error(
309
308
  `Actor query input exceeds maxInputSize (${encodedInput.byteLength} > ${maxInputSize} bytes). Increase client maxInputSize to allow larger query payloads.`,
@@ -23,7 +23,6 @@ import type {
23
23
  RuntimeDisplayInformation,
24
24
  } from "@/engine-client/driver";
25
25
  import type { Encoding, UniversalWebSocket } from "@/mod";
26
- import type { JsonCompatValue } from "@/common/encoding";
27
26
  import { encodeCborCompat, uint8ArrayToBase64 } from "@/serde";
28
27
  import { combineUrlPath, type GetUpgradeWebSocket } from "@/utils";
29
28
  import { getNextPhase } from "@/utils/env-vars";
@@ -182,7 +181,7 @@ export class RemoteEngineControlClient implements EngineControlClient {
182
181
  key: serializeActorKey(key),
183
182
  runner_name_selector: this.#config.poolName,
184
183
  input: actorInput
185
- ? uint8ArrayToBase64(encodeCborCompat(actorInput as JsonCompatValue))
184
+ ? uint8ArrayToBase64(encodeCborCompat(actorInput))
186
185
  : undefined,
187
186
  crash_policy: crashPolicy ?? "sleep",
188
187
  });
@@ -216,7 +215,7 @@ export class RemoteEngineControlClient implements EngineControlClient {
216
215
  runner_name_selector: this.#config.poolName,
217
216
  key: serializeActorKey(key),
218
217
  input: input
219
- ? uint8ArrayToBase64(encodeCborCompat(input as JsonCompatValue))
218
+ ? uint8ArrayToBase64(encodeCborCompat(input))
220
219
  : undefined,
221
220
  crash_policy: crashPolicy ?? "sleep",
222
221
  });