rivetkit 0.0.0-main.41efcce → 0.0.0-main.49693dc
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.
- package/dist/browser/client.d.ts +939 -104
- package/dist/browser/client.js +1867 -900
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2079 -233
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +6 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -74
- package/dist/tsup/actor/errors.d.ts +1 -74
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +2408 -2029
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +932 -114
- package/dist/tsup/agent-os/index.d.ts +932 -114
- package/dist/tsup/agent-os/index.js +2412 -2033
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-J27CEW6F.js → chunk-2OBVQZX6.js} +6 -6
- package/dist/tsup/chunk-2OBVQZX6.js.map +1 -0
- package/dist/tsup/chunk-3ZWHWMFJ.js +14 -0
- package/dist/tsup/chunk-3ZWHWMFJ.js.map +1 -0
- package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-4KGXFC6M.cjs} +238 -22
- package/dist/tsup/chunk-4KGXFC6M.cjs.map +1 -0
- package/dist/tsup/{chunk-CVHUXINE.js → chunk-5IU3MI7X.js} +594 -72
- package/dist/tsup/chunk-5IU3MI7X.js.map +1 -0
- package/dist/tsup/{chunk-VD7AZIBR.js → chunk-6CXQMHZR.js} +1161 -361
- package/dist/tsup/chunk-6CXQMHZR.js.map +1 -0
- package/dist/tsup/{chunk-SBEFJ4IQ.js → chunk-6W2UIH3X.js} +70 -8
- package/dist/tsup/chunk-6W2UIH3X.js.map +1 -0
- package/dist/tsup/{chunk-7MRGNVSR.js → chunk-6W5VGLFT.js} +237 -21
- package/dist/tsup/chunk-6W5VGLFT.js.map +1 -0
- package/dist/tsup/{chunk-RF3MEJV6.cjs → chunk-B73TBMMG.cjs} +18 -11
- package/dist/tsup/chunk-B73TBMMG.cjs.map +1 -0
- package/dist/tsup/chunk-D6TORRA4.js +243 -0
- package/dist/tsup/chunk-D6TORRA4.js.map +1 -0
- package/dist/tsup/{chunk-PXLJOMJD.js → chunk-FXT3HN32.js} +2 -2
- package/dist/tsup/{chunk-ZGWSH7YV.js → chunk-IXBD7BXC.js} +48 -72
- package/dist/tsup/chunk-IXBD7BXC.js.map +1 -0
- package/dist/tsup/{chunk-3BFYSYRU.js → chunk-JI6GZ2C2.js} +4 -12
- package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-SPMMF6TR.cjs → chunk-LGOWPZJ5.cjs} +3 -3
- package/dist/tsup/chunk-LGOWPZJ5.cjs.map +1 -0
- package/dist/tsup/chunk-LYNWTX6R.cjs +14 -0
- package/dist/tsup/chunk-LYNWTX6R.cjs.map +1 -0
- package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-MYWZCDML.cjs} +4 -12
- package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
- package/dist/tsup/{chunk-XSC2WWXD.js → chunk-NYDZLWHZ.js} +16 -9
- package/dist/tsup/chunk-NYDZLWHZ.js.map +1 -0
- package/dist/tsup/{chunk-AV54CVAG.cjs → chunk-RB7WUDX6.cjs} +1290 -490
- package/dist/tsup/chunk-RB7WUDX6.cjs.map +1 -0
- package/dist/tsup/{chunk-JTL6Y2UN.cjs → chunk-SPJORZMM.cjs} +49 -73
- package/dist/tsup/chunk-SPJORZMM.cjs.map +1 -0
- package/dist/tsup/chunk-SSMKIYEX.cjs +243 -0
- package/dist/tsup/chunk-SSMKIYEX.cjs.map +1 -0
- package/dist/tsup/{chunk-TQSL4NJ3.cjs → chunk-TQ4HSX2U.cjs} +72 -10
- package/dist/tsup/chunk-TQ4HSX2U.cjs.map +1 -0
- package/dist/tsup/{chunk-EVADNK6Z.cjs → chunk-U6ZQELGJ.cjs} +10 -10
- package/dist/tsup/chunk-U6ZQELGJ.cjs.map +1 -0
- package/dist/tsup/chunk-XLBMKZD3.cjs +1257 -0
- package/dist/tsup/chunk-XLBMKZD3.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +18 -7
- package/dist/tsup/client/mod.d.ts +18 -7
- package/dist/tsup/client/mod.js +7 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-B3RIidaJ.d.ts → config-BXSV17G7.d.cts} +987 -72
- package/dist/tsup/{config-D6WxBYjV.d.cts → config-Bi1r6gI7.d.ts} +987 -72
- package/dist/tsup/{config-B9qUIHX4.d.ts → config-ey2I2zz5.d.cts} +82 -15
- package/dist/tsup/{config-B9qUIHX4.d.cts → config-ey2I2zz5.d.ts} +82 -15
- package/dist/tsup/context-4fJemY0D.d.cts +129 -0
- package/dist/tsup/context-D4sNYboo.d.ts +129 -0
- package/dist/tsup/db/drizzle.cjs +168 -103
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -4
- package/dist/tsup/db/drizzle.d.ts +8 -4
- package/dist/tsup/db/drizzle.js +170 -105
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +6 -163
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +12 -4
- package/dist/tsup/db/mod.d.ts +12 -4
- package/dist/tsup/db/mod.js +5 -162
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +38 -0
- package/dist/tsup/dynamic/mod.d.ts +38 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +26 -136
- package/dist/tsup/inspector/mod.d.ts +26 -136
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector/workflow.cjs +21 -0
- package/dist/tsup/inspector/workflow.cjs.map +1 -0
- package/dist/tsup/inspector/workflow.d.cts +144 -0
- package/dist/tsup/inspector/workflow.d.ts +144 -0
- package/dist/tsup/inspector/workflow.js +21 -0
- package/dist/tsup/inspector/workflow.js.map +1 -0
- package/dist/tsup/inspector-tab/mod.cjs +162 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +241 -0
- package/dist/tsup/inspector-tab/mod.d.ts +241 -0
- package/dist/tsup/inspector-tab/mod.js +162 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +4268 -944
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +9 -8
- package/dist/tsup/mod.d.ts +9 -8
- package/dist/tsup/mod.js +4229 -905
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +26 -21
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +7 -6
- package/dist/tsup/test/mod.d.ts +7 -6
- package/dist/tsup/test/mod.js +25 -20
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/utils-Bbz-3411.d.cts +162 -0
- package/dist/tsup/utils-BqdWVlzm.d.ts +162 -0
- package/dist/tsup/utils-vvJQyygr.d.cts +109 -0
- package/dist/tsup/utils-vvJQyygr.d.ts +109 -0
- package/dist/tsup/utils.cjs +7 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +4 -147
- package/dist/tsup/utils.d.ts +4 -147
- package/dist/tsup/utils.js +6 -2
- package/dist/tsup/workflow/mod.cjs +517 -412
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +11 -10
- package/dist/tsup/workflow/mod.d.ts +11 -10
- package/dist/tsup/workflow/mod.js +511 -406
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +62 -14
- package/src/actor/actions.ts +119 -0
- package/src/actor/config.test.ts +78 -0
- package/src/actor/config.ts +518 -96
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +38 -26
- package/src/actor/errors.ts +101 -89
- package/src/actor/keys.ts +2 -1
- package/src/actor/mod.ts +32 -21
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/cron.ts +37 -2
- package/src/agent-os/actor/index.ts +39 -19
- package/src/agent-os/actor/preview.ts +1 -2
- package/src/agent-os/actor/session.ts +2 -2
- package/src/agent-os/config.ts +1 -1
- package/src/agent-os/fs/database-vfs.ts +1 -1
- package/src/agent-os/index.ts +16 -15
- package/src/agent-os/types.ts +11 -0
- package/src/client/actor-common.ts +106 -53
- package/src/client/actor-conn.ts +94 -45
- package/src/client/actor-handle.ts +198 -79
- package/src/client/actor-query.ts +13 -6
- package/src/client/client.ts +43 -15
- package/src/client/config.ts +8 -0
- package/src/client/errors.ts +4 -2
- package/src/client/lifecycle-errors.ts +28 -4
- package/src/client/mod.ts +9 -4
- package/src/client/query.ts +3 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +24 -16
- package/src/client/resolve-gateway-target.ts +3 -1
- package/src/client/utils.ts +36 -10
- package/src/common/actor-router-consts.ts +7 -0
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- package/src/common/bare/generated/client-protocol/v4.ts +599 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/bare/transport/v1.ts +694 -542
- package/src/common/client-protocol-versioned.ts +176 -67
- package/src/common/client-protocol-zod.ts +7 -0
- package/src/common/client-protocol.ts +1 -1
- package/src/common/database/config.ts +103 -10
- package/src/common/database/mod.test.ts +364 -0
- package/src/common/database/mod.ts +278 -149
- package/src/common/database/native-database.test.ts +220 -0
- package/src/common/database/native-database.ts +394 -58
- package/src/common/database/shared.ts +25 -0
- package/src/common/encoding.ts +302 -38
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/fetch-like.ts +49 -0
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +117 -14
- package/src/common/router.ts +49 -23
- package/src/common/utils.ts +23 -203
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.test.ts +164 -0
- package/src/db/drizzle.ts +207 -121
- package/src/db/mod.ts +6 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +64 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +23 -4
- package/src/engine-client/actor-websocket-client.ts +32 -5
- package/src/engine-client/api-endpoints.ts +52 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +21 -17
- package/src/engine-client/mod.ts +116 -64
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/globals.d.ts +4 -0
- package/src/inspector/client.browser.ts +127 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +301 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +160 -53
- package/src/registry/config/serverless.ts +7 -1
- package/src/registry/index.ts +659 -96
- package/src/registry/napi-runtime.ts +1154 -0
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +2005 -955
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/run-handler-coordinator.test.ts +252 -0
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.test.ts +50 -0
- package/src/registry/runtime.ts +839 -0
- package/src/registry/wasm-runtime.ts +1283 -0
- package/src/registry/write-through-proxy.ts +141 -0
- package/src/serde.ts +8 -2
- package/src/serverless/configure.ts +102 -49
- package/src/test/mod.ts +2 -17
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.test.ts +170 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/crypto.ts +14 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +39 -0
- package/src/utils/node.ts +44 -28
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +4 -2
- package/src/workflow/context.ts +683 -242
- package/src/workflow/driver.test.ts +62 -0
- package/src/workflow/driver.ts +246 -119
- package/src/workflow/inspector.ts +24 -24
- package/src/workflow/mod.ts +76 -84
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
- package/dist/tsup/chunk-6AVUJ52Q.cjs +0 -253
- package/dist/tsup/chunk-6AVUJ52Q.cjs.map +0 -1
- package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
- package/dist/tsup/chunk-7X7RVTFF.cjs +0 -735
- package/dist/tsup/chunk-7X7RVTFF.cjs.map +0 -1
- package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
- package/dist/tsup/chunk-AV54CVAG.cjs.map +0 -1
- package/dist/tsup/chunk-CVHUXINE.js.map +0 -1
- package/dist/tsup/chunk-EVADNK6Z.cjs.map +0 -1
- package/dist/tsup/chunk-J27CEW6F.js.map +0 -1
- package/dist/tsup/chunk-JTL6Y2UN.cjs.map +0 -1
- package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-RF3MEJV6.cjs.map +0 -1
- package/dist/tsup/chunk-SB4MXRN2.js +0 -253
- package/dist/tsup/chunk-SB4MXRN2.js.map +0 -1
- package/dist/tsup/chunk-SBEFJ4IQ.js.map +0 -1
- package/dist/tsup/chunk-SPMMF6TR.cjs.map +0 -1
- package/dist/tsup/chunk-TQSL4NJ3.cjs.map +0 -1
- package/dist/tsup/chunk-VD7AZIBR.js.map +0 -1
- package/dist/tsup/chunk-XSC2WWXD.js.map +0 -1
- package/dist/tsup/chunk-ZGWSH7YV.js.map +0 -1
- package/dist/tsup/context-BxvHh9wi.d.cts +0 -92
- package/dist/tsup/context-CNIZBIKl.d.ts +0 -92
- package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
- package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2501
- package/src/drivers/engine/actor-driver.ts +0 -2470
- package/src/utils/serve.ts +0 -217
- /package/dist/tsup/{chunk-PXLJOMJD.js.map → chunk-FXT3HN32.js.map} +0 -0
package/src/common/encoding.ts
CHANGED
|
@@ -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,41 +277,127 @@ 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:
|
|
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) =>
|
|
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 [
|
|
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
|
-
|
|
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`);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export interface JsonCompatReviveOptions {
|
|
374
|
+
coerceSafeIntegerBigInts?: boolean;
|
|
147
375
|
}
|
|
148
376
|
|
|
149
|
-
export function reviveJsonCompatValue(
|
|
377
|
+
export function reviveJsonCompatValue(
|
|
378
|
+
input: any,
|
|
379
|
+
options: JsonCompatReviveOptions = {},
|
|
380
|
+
): any {
|
|
381
|
+
if (typeof input === "bigint") {
|
|
382
|
+
if (
|
|
383
|
+
options.coerceSafeIntegerBigInts &&
|
|
384
|
+
input >= BigInt(Number.MIN_SAFE_INTEGER) &&
|
|
385
|
+
input <= BigInt(Number.MAX_SAFE_INTEGER)
|
|
386
|
+
) {
|
|
387
|
+
return Number(input);
|
|
388
|
+
}
|
|
389
|
+
return input;
|
|
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
|
+
}
|
|
150
401
|
if (Array.isArray(input)) {
|
|
151
402
|
if (
|
|
152
403
|
input.length === 2 &&
|
|
@@ -165,19 +416,28 @@ export function reviveJsonCompatValue(input: any): any {
|
|
|
165
416
|
if (input[0] === JSON_COMPAT_UNDEFINED) {
|
|
166
417
|
return undefined;
|
|
167
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
|
+
}
|
|
168
425
|
if (input[0].startsWith("$$")) {
|
|
169
|
-
return [
|
|
426
|
+
return [
|
|
427
|
+
input[0].substring(1),
|
|
428
|
+
reviveJsonCompatValue(input[1], options),
|
|
429
|
+
];
|
|
170
430
|
}
|
|
171
431
|
throw new Error(
|
|
172
432
|
`Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`,
|
|
173
433
|
);
|
|
174
434
|
}
|
|
175
|
-
return input.map((value) => reviveJsonCompatValue(value));
|
|
435
|
+
return input.map((value) => reviveJsonCompatValue(value, options));
|
|
176
436
|
}
|
|
177
437
|
if (isPlainObject(input)) {
|
|
178
438
|
const decoded: Record<string, unknown> = {};
|
|
179
439
|
for (const [key, value] of Object.entries(input)) {
|
|
180
|
-
decoded[key] = reviveJsonCompatValue(value);
|
|
440
|
+
decoded[key] = reviveJsonCompatValue(value, options);
|
|
181
441
|
}
|
|
182
442
|
return decoded;
|
|
183
443
|
}
|
|
@@ -213,33 +473,37 @@ function base64DecodeToArrayBuffer(base64: string): ArrayBuffer {
|
|
|
213
473
|
}
|
|
214
474
|
|
|
215
475
|
/** Stringifies with compat for values that BARE & CBOR supports. */
|
|
216
|
-
export function jsonStringifyCompat(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
+
);
|
|
243
507
|
}
|
|
244
508
|
|
|
245
509
|
/** Parses JSON with compat for values that BARE & CBOR supports. */
|
package/src/common/engine.ts
CHANGED
|
@@ -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 =
|
|
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 (
|
|
28
|
+
} catch (_err) {
|
|
29
29
|
// EventSource not available
|
|
30
30
|
_EventSource = class MockEventSource {
|
|
31
31
|
constructor() {
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|
|
@@ -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(
|
|
165
|
-
console.error("INLINE_WEBSOCKET_ADAPTER_ERROR",
|
|
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
|
|
169
|
-
errorMessage:
|
|
170
|
-
|
|
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(
|
|
176
|
-
} catch (
|
|
176
|
+
this.#handler.onError(error, this.#wsContext);
|
|
177
|
+
} catch (error) {
|
|
177
178
|
logger().error({
|
|
178
179
|
msg: "error in onError handler",
|
|
179
|
-
error
|
|
180
|
+
error,
|
|
180
181
|
});
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
// Fire error event to both sides
|
|
184
|
-
this.#clientWs.triggerError(
|
|
185
|
-
this.#actorWs.triggerError(
|
|
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 (
|
|
203
|
-
logger().error({ msg: "error closing websocket", error
|
|
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
|
-
):
|
|
11
|
-
return bufferToArrayBuffer(
|
|
18
|
+
): WorkflowHistoryBytes {
|
|
19
|
+
return bufferToArrayBuffer(
|
|
20
|
+
encodeWorkflowHistory(history),
|
|
21
|
+
) as WorkflowHistoryBytes;
|
|
12
22
|
}
|
|
13
23
|
|
|
14
24
|
export function decodeWorkflowHistoryTransport(
|