rivetkit 2.3.0-rc.9 → 2.3.0
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 +498 -62
- package/dist/browser/client.js +227 -171
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +50 -20
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +2 -2
- package/dist/tsup/actor/errors.d.cts +1 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +1 -1
- package/dist/tsup/agent-os/index.cjs +2163 -2087
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +496 -69
- package/dist/tsup/agent-os/index.d.ts +496 -69
- package/dist/tsup/agent-os/index.js +2163 -2087
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-W7EYSYVI.js → chunk-2OTRTA3J.js} +134 -20
- package/dist/tsup/chunk-2OTRTA3J.js.map +1 -0
- package/dist/tsup/{chunk-VJFRBJVQ.cjs → chunk-3677IIOV.cjs} +138 -24
- package/dist/tsup/chunk-3677IIOV.cjs.map +1 -0
- package/dist/tsup/{chunk-4CGA6QJO.cjs → chunk-47HHIEXH.cjs} +24 -9
- package/dist/tsup/chunk-47HHIEXH.cjs.map +1 -0
- package/dist/tsup/{chunk-F3Q5BFQ6.js → chunk-4JDSFJS5.js} +66 -79
- package/dist/tsup/chunk-4JDSFJS5.js.map +1 -0
- package/dist/tsup/{chunk-GVTOE34S.cjs → chunk-7QKCIVAY.cjs} +222 -235
- package/dist/tsup/chunk-7QKCIVAY.cjs.map +1 -0
- package/dist/tsup/{chunk-CPA4Y3RG.cjs → chunk-B6VUNZUD.cjs} +10 -10
- package/dist/tsup/chunk-B6VUNZUD.cjs.map +1 -0
- package/dist/tsup/{chunk-H37XQU3I.js → chunk-BEI24WTI.js} +2 -2
- package/dist/tsup/{chunk-KIWH5H3K.js → chunk-BRP62GZC.js} +3 -3
- package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
- package/dist/tsup/{chunk-T6YVRM4K.js → chunk-DPIMKYNB.js} +63 -2
- package/dist/tsup/chunk-DPIMKYNB.js.map +1 -0
- package/dist/tsup/{chunk-Y5NSCZA2.cjs → chunk-DXXJPH55.cjs} +44 -15
- package/dist/tsup/chunk-DXXJPH55.cjs.map +1 -0
- package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
- package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
- package/dist/tsup/{chunk-4WPEZBK4.cjs → chunk-I4LN3FNT.cjs} +10 -10
- package/dist/tsup/chunk-I4LN3FNT.cjs.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-KORQB2IR.cjs} +3 -3
- package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
- package/dist/tsup/{chunk-MALSPBAF.cjs → chunk-LVTBW2RE.cjs} +3 -3
- package/dist/tsup/{chunk-MALSPBAF.cjs.map → chunk-LVTBW2RE.cjs.map} +1 -1
- package/dist/tsup/{chunk-H7P7WR2Y.js → chunk-MEHBWPLJ.js} +6 -6
- package/dist/tsup/chunk-MEHBWPLJ.js.map +1 -0
- package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-NIY3RSPX.cjs} +64 -3
- package/dist/tsup/chunk-NIY3RSPX.cjs.map +1 -0
- package/dist/tsup/{chunk-MMMEZM5J.js → chunk-P2GNQ4RN.js} +4 -4
- package/dist/tsup/chunk-P2GNQ4RN.js.map +1 -0
- package/dist/tsup/{chunk-KJTA3ATT.js → chunk-UMZVD6DQ.js} +22 -7
- package/dist/tsup/chunk-UMZVD6DQ.js.map +1 -0
- package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
- package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
- package/dist/tsup/{chunk-VRCIXJRN.js → chunk-VTTFNQQI.js} +36 -7
- package/dist/tsup/chunk-VTTFNQQI.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +5 -5
- package/dist/tsup/client/mod.d.ts +5 -5
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-0Ta55UV0.d.ts → config-BxWAw3iH.d.ts} +529 -23
- package/dist/tsup/{config-Ca8dN4cS.d.cts → config-CZQQ-mso.d.cts} +529 -23
- package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.cts} +1 -2
- package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.ts} +1 -2
- package/dist/tsup/{context-B_IWbWne.d.ts → context-Bw7xq8w3.d.cts} +8 -8
- package/dist/tsup/{context-CUrQ9MHc.d.cts → context-D8QA76sV.d.ts} +8 -8
- package/dist/tsup/db/drizzle.cjs +3 -3
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +2 -2
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +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 +37 -0
- package/dist/tsup/dynamic/mod.d.ts +37 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/inspector-tab/mod.cjs +173 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +250 -0
- package/dist/tsup/inspector-tab/mod.d.ts +250 -0
- package/dist/tsup/inspector-tab/mod.js +173 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +730 -336
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -5
- package/dist/tsup/mod.d.ts +5 -5
- package/dist/tsup/mod.js +633 -239
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +21 -18
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -4
- package/dist/tsup/test/mod.d.ts +4 -4
- package/dist/tsup/test/mod.js +18 -15
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/{utils-DVekpm4I.d.cts → utils-DQosb24I.d.cts} +1 -1
- package/dist/tsup/{utils-DVekpm4I.d.ts → utils-DQosb24I.d.ts} +1 -1
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +307 -282
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +6 -6
- package/dist/tsup/workflow/mod.d.ts +6 -6
- package/dist/tsup/workflow/mod.js +501 -476
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +32 -11
- package/src/actor/config.ts +159 -51
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +17 -19
- package/src/actor/driver.ts +3 -3
- package/src/actor/errors.ts +9 -3
- package/src/actor/instance/mod.ts +26 -34
- package/src/actor/keys.ts +1 -1
- package/src/actor/mod.ts +22 -20
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/index.ts +38 -18
- 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/client/actor-common.ts +87 -54
- package/src/client/actor-conn.ts +8 -36
- package/src/client/actor-handle.ts +69 -51
- package/src/client/actor-query.ts +5 -5
- package/src/client/errors.ts +1 -1
- package/src/client/lifecycle-errors.ts +2 -4
- package/src/client/query.ts +1 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +8 -6
- package/src/client/resolve-gateway-target.ts +1 -1
- package/src/client/utils.ts +2 -7
- 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/transport/v1.ts +659 -543
- package/src/common/client-protocol-versioned.ts +66 -64
- package/src/common/database/config.ts +2 -8
- package/src/common/database/native-database.ts +1 -1
- package/src/common/database/shared.ts +1 -0
- package/src/common/encoding.ts +250 -16
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/log.ts +1 -0
- package/src/common/router.ts +13 -17
- package/src/common/utils.ts +1 -150
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/mod.ts +1 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/drivers/engine/actor-driver.ts +58 -56
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +66 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +3 -3
- package/src/engine-client/actor-websocket-client.ts +6 -5
- package/src/engine-client/api-endpoints.ts +51 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +1 -1
- package/src/engine-client/mod.ts +6 -3
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +5 -11
- package/src/inspector/mod.ts +1 -3
- package/src/inspector-tab/mod.ts +315 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +40 -16
- package/src/registry/index.ts +154 -74
- package/src/registry/napi-runtime.ts +13 -2
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +367 -181
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/runtime.ts +41 -1
- package/src/registry/wasm-runtime.ts +18 -2
- package/src/registry/write-through-proxy.ts +40 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +18 -7
- package/src/test/mod.ts +11 -8
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +6 -0
- package/src/utils/router.ts +1 -1
- package/src/utils/serve.ts +4 -5
- package/src/utils.ts +1 -2
- package/src/workflow/context.ts +61 -33
- package/src/workflow/driver.ts +4 -6
- package/src/workflow/inspector.ts +4 -3
- package/src/workflow/mod.ts +15 -17
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
- package/dist/tsup/chunk-4CGA6QJO.cjs.map +0 -1
- package/dist/tsup/chunk-4WPEZBK4.cjs.map +0 -1
- package/dist/tsup/chunk-CPA4Y3RG.cjs.map +0 -1
- package/dist/tsup/chunk-F3Q5BFQ6.js.map +0 -1
- package/dist/tsup/chunk-GVTOE34S.cjs.map +0 -1
- package/dist/tsup/chunk-H7P7WR2Y.js.map +0 -1
- package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
- package/dist/tsup/chunk-KJTA3ATT.js.map +0 -1
- package/dist/tsup/chunk-MMMEZM5J.js.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
- package/dist/tsup/chunk-VJFRBJVQ.cjs.map +0 -1
- package/dist/tsup/chunk-VRCIXJRN.js.map +0 -1
- package/dist/tsup/chunk-W7EYSYVI.js.map +0 -1
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
- package/dist/tsup/chunk-Y5NSCZA2.cjs.map +0 -1
- /package/dist/tsup/{chunk-H37XQU3I.js.map → chunk-BEI24WTI.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 =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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 =
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
|
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>,
|
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,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:
|
|
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`);
|
|
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 [
|
|
493
|
+
return [`$${value[0]}`, value[1]];
|
|
260
494
|
}
|
|
261
495
|
return value;
|
|
262
496
|
});
|
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() {
|
|
@@ -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
|
|
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) {
|