rivetkit 0.0.0-skip-ready-wait-flatten-client-options.1cae221 → 0.0.0-sqlite-uds.4e59a38
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 +561 -89
- package/dist/browser/client.js +1063 -430
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +22 -2
- package/dist/browser/inspector/client.js +1036 -232
- 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 +2218 -2082
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +556 -85
- package/dist/tsup/agent-os/index.d.ts +556 -85
- package/dist/tsup/agent-os/index.js +2220 -2084
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-NFC5VU36.cjs → chunk-3GC3EP6D.cjs} +18 -10
- package/dist/tsup/chunk-3GC3EP6D.cjs.map +1 -0
- package/dist/tsup/{chunk-7MRGNVSR.js → chunk-3GLNEWGY.js} +78 -6
- package/dist/tsup/chunk-3GLNEWGY.js.map +1 -0
- package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-4FC7TVS6.cjs} +35 -10
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
- package/dist/tsup/{chunk-POTPHU3P.cjs → chunk-62LSMTP2.cjs} +3 -3
- package/dist/tsup/{chunk-POTPHU3P.cjs.map → chunk-62LSMTP2.cjs.map} +1 -1
- package/dist/tsup/{chunk-OIKOPSXQ.js → chunk-7IVUT2JT.js} +12 -4
- package/dist/tsup/chunk-7IVUT2JT.js.map +1 -0
- package/dist/tsup/{chunk-22XU3BVY.cjs → chunk-GEYQLGXC.cjs} +925 -328
- package/dist/tsup/chunk-GEYQLGXC.cjs.map +1 -0
- package/dist/tsup/{chunk-D2TLG75Y.cjs → chunk-GMN45CQ6.cjs} +10 -10
- package/dist/tsup/chunk-GMN45CQ6.cjs.map +1 -0
- package/dist/tsup/{chunk-3BFYSYRU.js → chunk-HXUEHHJF.js} +3 -2
- package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
- package/dist/tsup/{chunk-IOYKCB6Y.cjs → chunk-I336PMWT.cjs} +44 -9
- package/dist/tsup/chunk-I336PMWT.cjs.map +1 -0
- package/dist/tsup/{chunk-RZEJJJKU.js → chunk-IB73AMGJ.js} +42 -7
- package/dist/tsup/chunk-IB73AMGJ.js.map +1 -0
- package/dist/tsup/{chunk-4ZIWB4CQ.js → chunk-ITWJ6Y7G.js} +2 -2
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-W54QCENI.js → chunk-KTNBYGRU.js} +134 -20
- package/dist/tsup/chunk-KTNBYGRU.js.map +1 -0
- package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-OAPVVVTX.cjs} +79 -7
- package/dist/tsup/chunk-OAPVVVTX.cjs.map +1 -0
- package/dist/tsup/{chunk-TPBHXFB2.cjs → chunk-OUDV3ITX.cjs} +138 -24
- package/dist/tsup/chunk-OUDV3ITX.cjs.map +1 -0
- package/dist/tsup/{chunk-XNZR7UD2.cjs → chunk-PRXTIERO.cjs} +90 -65
- package/dist/tsup/chunk-PRXTIERO.cjs.map +1 -0
- package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-VE2X4KMG.cjs} +3 -2
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -0
- package/dist/tsup/{chunk-KSG2COSQ.js → chunk-WRZEVVLL.js} +6 -6
- package/dist/tsup/chunk-WRZEVVLL.js.map +1 -0
- package/dist/tsup/{chunk-LNMB25HW.js → chunk-XAIMHUPG.js} +780 -183
- package/dist/tsup/chunk-XAIMHUPG.js.map +1 -0
- package/dist/tsup/{chunk-D4TSTM6C.js → chunk-XZ62SWSC.js} +83 -58
- package/dist/tsup/chunk-XZ62SWSC.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/{chunk-K34B3OVG.js → chunk-ZZ3WBRPD.js} +34 -9
- package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +8 -9
- package/dist/tsup/client/mod.d.ts +8 -9
- package/dist/tsup/client/mod.js +8 -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.js +3 -3
- package/dist/tsup/{config-CRdGwwbr.d.cts → config-CxG53eQo.d.cts} +577 -36
- package/dist/tsup/{config-kxXbtrJU.d.ts → config-DLOxy81E.d.cts} +5 -5
- package/dist/tsup/{config-kxXbtrJU.d.cts → config-DLOxy81E.d.ts} +5 -5
- package/dist/tsup/{config-DIpBWm5C.d.ts → config-Ds6DCRhV.d.ts} +577 -36
- package/dist/tsup/context-8KlcOYIs.d.cts +129 -0
- package/dist/tsup/context-Cfbm4QLr.d.ts +129 -0
- package/dist/tsup/db/drizzle.cjs +151 -79
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +2 -2
- package/dist/tsup/db/drizzle.d.ts +2 -2
- package/dist/tsup/db/drizzle.js +151 -79
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +79 -24
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +78 -23
- 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 +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 +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +37 -15
- package/dist/tsup/inspector/mod.d.ts +37 -15
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- 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 +240 -0
- package/dist/tsup/inspector-tab/mod.d.ts +240 -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 +1078 -479
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -6
- package/dist/tsup/mod.d.ts +5 -6
- package/dist/tsup/mod.js +996 -397
- 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 -5
- package/dist/tsup/test/mod.d.ts +4 -5
- package/dist/tsup/test/mod.js +18 -15
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
- package/dist/tsup/utils-CqDnC_PS.d.ts +104 -0
- 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 +386 -322
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +8 -9
- package/dist/tsup/workflow/mod.d.ts +8 -9
- package/dist/tsup/workflow/mod.js +363 -299
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +35 -14
- package/src/actor/config.ts +188 -59
- 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 +70 -7
- package/src/actor/instance/mod.ts +39 -56
- package/src/actor/keys.ts +2 -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 +88 -62
- package/src/client/actor-conn.ts +58 -63
- package/src/client/actor-handle.ts +125 -71
- package/src/client/actor-query.ts +5 -5
- package/src/client/config.ts +3 -3
- package/src/client/errors.ts +2 -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 +10 -10
- package/src/client/resolve-gateway-target.ts +1 -1
- package/src/client/utils.ts +34 -10
- package/src/common/actor-router-consts.ts +7 -4
- 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/client-protocol/v4.ts +599 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -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 +16 -5
- package/src/common/database/mod.test.ts +83 -16
- package/src/common/database/mod.ts +86 -30
- package/src/common/database/native-database.test.ts +35 -22
- package/src/common/database/native-database.ts +26 -10
- 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 +15 -8
- package/src/common/router.ts +49 -23
- package/src/common/utils.ts +10 -202
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.ts +173 -96
- 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 +76 -73
- 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 +6 -9
- package/src/engine-client/actor-websocket-client.ts +14 -13
- package/src/engine-client/api-endpoints.ts +51 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +3 -4
- package/src/engine-client/mod.ts +17 -10
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +66 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector-tab/mod.ts +300 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +46 -20
- package/src/registry/index.ts +364 -87
- package/src/registry/napi-runtime.ts +97 -8
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +592 -343
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/runtime.ts +85 -6
- package/src/registry/wasm-runtime.ts +72 -3
- package/src/registry/write-through-proxy.ts +40 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +19 -8
- package/src/test/mod.ts +11 -8
- package/src/utils/crypto.ts +14 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +37 -0
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +1 -2
- package/src/workflow/context.ts +703 -240
- package/src/workflow/driver.ts +23 -12
- package/src/workflow/inspector.ts +12 -3
- package/src/workflow/mod.ts +37 -23
- package/dist/tsup/chunk-22XU3BVY.cjs.map +0 -1
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
- package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
- package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
- package/dist/tsup/chunk-D2TLG75Y.cjs.map +0 -1
- package/dist/tsup/chunk-D4TSTM6C.js.map +0 -1
- package/dist/tsup/chunk-IOYKCB6Y.cjs.map +0 -1
- package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
- package/dist/tsup/chunk-KSG2COSQ.js.map +0 -1
- package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
- package/dist/tsup/chunk-LNMB25HW.js.map +0 -1
- package/dist/tsup/chunk-NFC5VU36.cjs.map +0 -1
- package/dist/tsup/chunk-OIKOPSXQ.js.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-RZEJJJKU.js.map +0 -1
- package/dist/tsup/chunk-TPBHXFB2.cjs.map +0 -1
- package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
- package/dist/tsup/chunk-W54QCENI.js.map +0 -1
- package/dist/tsup/chunk-XNZR7UD2.cjs.map +0 -1
- package/dist/tsup/context-B7G6sk7x.d.ts +0 -92
- package/dist/tsup/context-DzMRHkjC.d.cts +0 -92
- package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
- package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
- package/src/utils/serve.ts +0 -217
- /package/dist/tsup/{chunk-4ZIWB4CQ.js.map → chunk-ITWJ6Y7G.js.map} +0 -0
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
|
@@ -62,20 +62,16 @@ export function configureBaseLogger(logger: Logger): void {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Create the default logger with optional log level.
|
|
66
66
|
*/
|
|
67
|
-
export function
|
|
68
|
-
|
|
69
|
-
if (logLevel) {
|
|
70
|
-
configuredLogLevel = logLevel;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
baseLogger = pino(
|
|
67
|
+
export function makeDefaultLogger(logLevel?: LogLevel): Logger {
|
|
68
|
+
return pino(
|
|
74
69
|
{
|
|
75
70
|
level: getPinoLevel(logLevel),
|
|
76
71
|
messageKey: "msg",
|
|
77
72
|
// Do not include pid/hostname in output
|
|
78
73
|
base: {},
|
|
74
|
+
errorKey: "error",
|
|
79
75
|
// Keep the numeric level so the logfmt sink can match Pino's levels.
|
|
80
76
|
formatters: {
|
|
81
77
|
level(_label: string, number: number) {
|
|
@@ -86,7 +82,18 @@ export function configureDefaultLogger(logLevel?: LogLevel) {
|
|
|
86
82
|
},
|
|
87
83
|
createLogfmtDestination(),
|
|
88
84
|
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Configure the default logger with optional log level.
|
|
89
|
+
*/
|
|
90
|
+
export function configureDefaultLogger(logLevel?: LogLevel) {
|
|
91
|
+
// Store the configured log level
|
|
92
|
+
if (logLevel) {
|
|
93
|
+
configuredLogLevel = logLevel;
|
|
94
|
+
}
|
|
89
95
|
|
|
96
|
+
baseLogger = makeDefaultLogger(logLevel);
|
|
90
97
|
loggerCache.clear();
|
|
91
98
|
}
|
|
92
99
|
|
package/src/common/router.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Context as HonoContext, Next } from "hono";
|
|
2
1
|
import * as envoyProtocol from "@rivetkit/engine-envoy-protocol";
|
|
3
|
-
import type {
|
|
2
|
+
import type { Context as HonoContext, Next } from "hono";
|
|
3
|
+
import type { ActorSpecifier } from "@/actor/errors";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
HEADER_ACTOR_GENERATION,
|
|
6
|
+
HEADER_ACTOR_ID,
|
|
7
|
+
HEADER_ACTOR_KEY,
|
|
8
|
+
} from "@/common/actor-router-consts";
|
|
9
9
|
import type * as protocol from "@/common/client-protocol";
|
|
10
10
|
import {
|
|
11
11
|
CURRENT_VERSION as CLIENT_PROTOCOL_CURRENT_VERSION,
|
|
@@ -15,15 +15,17 @@ import {
|
|
|
15
15
|
type HttpResponseError as HttpResponseErrorJson,
|
|
16
16
|
HttpResponseErrorSchema,
|
|
17
17
|
} from "@/common/client-protocol-zod";
|
|
18
|
+
import type { Encoding, JsonCompatValue } from "@/common/encoding";
|
|
18
19
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from "@/
|
|
20
|
+
getRequestEncoding,
|
|
21
|
+
getRequestExposeInternalError,
|
|
22
|
+
} from "@/common/router-request";
|
|
23
|
+
import { buildActorNames, type RegistryConfig } from "@/registry/config";
|
|
24
|
+
import { encodeCborCompat, serializeWithEncoding } from "@/serde";
|
|
23
25
|
import { bufferToArrayBuffer, VERSION } from "@/utils";
|
|
24
26
|
import { getLogHeaders } from "@/utils/env-vars";
|
|
25
27
|
import { getLogger, type Logger } from "./log";
|
|
26
|
-
import { deconstructError
|
|
28
|
+
import { deconstructError } from "./utils";
|
|
27
29
|
|
|
28
30
|
export function logger() {
|
|
29
31
|
return getLogger("router");
|
|
@@ -61,15 +63,19 @@ export function handleRouteNotFound(c: HonoContext) {
|
|
|
61
63
|
export function handleRouteError(error: unknown, c: HonoContext) {
|
|
62
64
|
const exposeInternalError = getRequestExposeInternalError(c.req.raw);
|
|
63
65
|
|
|
64
|
-
const { statusCode, group, code, message, metadata } =
|
|
65
|
-
error,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
const { statusCode, group, code, message, metadata, actor } =
|
|
67
|
+
deconstructError(error, exposeInternalError);
|
|
68
|
+
|
|
69
|
+
if (actor) {
|
|
70
|
+
logger().warn({
|
|
71
|
+
msg: "actor http error response",
|
|
72
|
+
actorId: actor.actorId,
|
|
73
|
+
generation: actor.generation,
|
|
74
|
+
actorKey: actor.key,
|
|
75
|
+
group,
|
|
76
|
+
code,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
73
79
|
|
|
74
80
|
let encoding: Encoding;
|
|
75
81
|
try {
|
|
@@ -78,7 +84,7 @@ export function handleRouteError(error: unknown, c: HonoContext) {
|
|
|
78
84
|
encoding = "json";
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
const errorData = { group, code, message, metadata };
|
|
87
|
+
const errorData = { group, code, message, metadata, actor };
|
|
82
88
|
const output = serializeWithEncoding(
|
|
83
89
|
encoding,
|
|
84
90
|
errorData,
|
|
@@ -91,6 +97,7 @@ export function handleRouteError(error: unknown, c: HonoContext) {
|
|
|
91
97
|
code: value.code,
|
|
92
98
|
message: value.message,
|
|
93
99
|
metadata: value.metadata,
|
|
100
|
+
actor: value.actor,
|
|
94
101
|
}),
|
|
95
102
|
// BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer
|
|
96
103
|
(value): protocol.HttpResponseError => ({
|
|
@@ -98,13 +105,32 @@ export function handleRouteError(error: unknown, c: HonoContext) {
|
|
|
98
105
|
code: value.code,
|
|
99
106
|
message: value.message,
|
|
100
107
|
metadata: value.metadata
|
|
101
|
-
? bufferToArrayBuffer(
|
|
108
|
+
? bufferToArrayBuffer(
|
|
109
|
+
encodeCborCompat(value.metadata as JsonCompatValue),
|
|
110
|
+
)
|
|
111
|
+
: null,
|
|
112
|
+
actor: value.actor
|
|
113
|
+
? {
|
|
114
|
+
actorId: value.actor.actorId,
|
|
115
|
+
generation: BigInt(value.actor.generation),
|
|
116
|
+
key: value.actor.key ?? null,
|
|
117
|
+
}
|
|
102
118
|
: null,
|
|
103
119
|
}),
|
|
104
120
|
);
|
|
105
121
|
|
|
122
|
+
const headers = actor ? actorResponseHeaders(actor) : undefined;
|
|
123
|
+
|
|
106
124
|
// TODO: Remove any
|
|
107
|
-
return c.body(output as any, { status: statusCode });
|
|
125
|
+
return c.body(output as any, { status: statusCode, headers });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function actorResponseHeaders(actor: ActorSpecifier): Record<string, string> {
|
|
129
|
+
return {
|
|
130
|
+
[HEADER_ACTOR_ID]: actor.actorId,
|
|
131
|
+
[HEADER_ACTOR_GENERATION]: String(actor.generation),
|
|
132
|
+
...(actor.key ? { [HEADER_ACTOR_KEY]: actor.key } : {}),
|
|
133
|
+
};
|
|
108
134
|
}
|
|
109
135
|
|
|
110
136
|
export type MetadataEnvoyKind =
|
package/src/common/utils.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Next } from "hono";
|
|
2
2
|
import type { ContentfulStatusCode } from "hono/utils/http-status";
|
|
3
3
|
import * as errors from "@/actor/errors";
|
|
4
|
-
import { EXTRA_ERROR_LOG } from "@/utils";
|
|
5
4
|
import { getLogErrorStack } from "@/utils/env-vars";
|
|
6
|
-
import type { Logger } from "./log";
|
|
7
5
|
|
|
8
6
|
export function assertUnreachable(x: never): never {
|
|
9
7
|
throw new Error(`Unreachable case: ${x}`);
|
|
@@ -38,155 +36,6 @@ export function safeStringify(obj: unknown, maxSize: number) {
|
|
|
38
36
|
return JSON.stringify(obj, replacer);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
// TODO: Instead of doing this, use a temp var for state and attempt to write
|
|
42
|
-
// it. Roll back state if fails to serialize.
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Check if a value is CBOR serializable.
|
|
46
|
-
* Optionally pass an onInvalid callback to receive the path to invalid values.
|
|
47
|
-
*
|
|
48
|
-
* For a complete list of supported CBOR tags, see:
|
|
49
|
-
* https://github.com/kriszyp/cbor-x/blob/cc1cf9df8ba72288c7842af1dd374d73e34cdbc1/README.md#list-of-supported-tags-for-decoding
|
|
50
|
-
*/
|
|
51
|
-
export function isCborSerializable(
|
|
52
|
-
value: unknown,
|
|
53
|
-
onInvalid?: (path: string) => void,
|
|
54
|
-
currentPath = "",
|
|
55
|
-
): boolean {
|
|
56
|
-
// Handle primitive types directly
|
|
57
|
-
if (value === null || value === undefined) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (typeof value === "number") {
|
|
62
|
-
if (!Number.isFinite(value)) {
|
|
63
|
-
onInvalid?.(currentPath);
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (typeof value === "boolean" || typeof value === "string") {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Handle BigInt (CBOR tags 2 and 3)
|
|
74
|
-
if (typeof value === "bigint") {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Handle Date objects (CBOR tags 0 and 1)
|
|
79
|
-
if (value instanceof Date) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Handle typed arrays (CBOR tags 64-82)
|
|
84
|
-
if (
|
|
85
|
-
value instanceof Uint8Array ||
|
|
86
|
-
value instanceof Uint8ClampedArray ||
|
|
87
|
-
value instanceof Uint16Array ||
|
|
88
|
-
value instanceof Uint32Array ||
|
|
89
|
-
value instanceof BigUint64Array ||
|
|
90
|
-
value instanceof Int8Array ||
|
|
91
|
-
value instanceof Int16Array ||
|
|
92
|
-
value instanceof Int32Array ||
|
|
93
|
-
value instanceof BigInt64Array ||
|
|
94
|
-
value instanceof Float32Array ||
|
|
95
|
-
value instanceof Float64Array
|
|
96
|
-
) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Handle Map (CBOR tag 259)
|
|
101
|
-
if (value instanceof Map) {
|
|
102
|
-
for (const [key, val] of value.entries()) {
|
|
103
|
-
const keyPath = currentPath
|
|
104
|
-
? `${currentPath}.key(${String(key)})`
|
|
105
|
-
: `key(${String(key)})`;
|
|
106
|
-
const valPath = currentPath
|
|
107
|
-
? `${currentPath}.value(${String(key)})`
|
|
108
|
-
: `value(${String(key)})`;
|
|
109
|
-
if (
|
|
110
|
-
!isCborSerializable(key, onInvalid, keyPath) ||
|
|
111
|
-
!isCborSerializable(val, onInvalid, valPath)
|
|
112
|
-
) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Handle Set (CBOR tag 258)
|
|
120
|
-
if (value instanceof Set) {
|
|
121
|
-
let index = 0;
|
|
122
|
-
for (const item of value.values()) {
|
|
123
|
-
const itemPath = currentPath
|
|
124
|
-
? `${currentPath}.set[${index}]`
|
|
125
|
-
: `set[${index}]`;
|
|
126
|
-
if (!isCborSerializable(item, onInvalid, itemPath)) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
index++;
|
|
130
|
-
}
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Handle RegExp (CBOR tag 27)
|
|
135
|
-
if (value instanceof RegExp) {
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Handle Error objects (CBOR tag 27)
|
|
140
|
-
if (value instanceof Error) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Handle arrays
|
|
145
|
-
if (Array.isArray(value)) {
|
|
146
|
-
for (let i = 0; i < value.length; i++) {
|
|
147
|
-
const itemPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;
|
|
148
|
-
if (!isCborSerializable(value[i], onInvalid, itemPath)) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Handle plain objects and records (CBOR tags 105, 51, 57344-57599)
|
|
156
|
-
if (typeof value === "object") {
|
|
157
|
-
// Allow plain objects and objects with prototypes (for records and named objects)
|
|
158
|
-
const proto = Object.getPrototypeOf(value);
|
|
159
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
160
|
-
// Check if it's a known serializable object type
|
|
161
|
-
const protoConstructor = value.constructor;
|
|
162
|
-
if (protoConstructor && typeof protoConstructor.name === "string") {
|
|
163
|
-
// Allow objects with named constructors (records, named objects)
|
|
164
|
-
// This includes user-defined classes and built-in objects
|
|
165
|
-
// that CBOR can serialize with tag 27 or record tags
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Check all properties recursively
|
|
170
|
-
for (const key in value) {
|
|
171
|
-
const propPath = currentPath ? `${currentPath}.${key}` : key;
|
|
172
|
-
if (
|
|
173
|
-
!isCborSerializable(
|
|
174
|
-
value[key as keyof typeof value],
|
|
175
|
-
onInvalid,
|
|
176
|
-
propPath,
|
|
177
|
-
)
|
|
178
|
-
) {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Not serializable
|
|
186
|
-
onInvalid?.(currentPath);
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
39
|
export interface DeconstructedError {
|
|
191
40
|
__type: "ActorError";
|
|
192
41
|
statusCode: ContentfulStatusCode;
|
|
@@ -195,6 +44,7 @@ export interface DeconstructedError {
|
|
|
195
44
|
code: string;
|
|
196
45
|
message: string;
|
|
197
46
|
metadata?: unknown;
|
|
47
|
+
actor?: errors.ActorSpecifier;
|
|
198
48
|
}
|
|
199
49
|
|
|
200
50
|
function isCanonicalStructuredRivetError(
|
|
@@ -221,19 +71,16 @@ function isCanonicalStructuredRivetError(
|
|
|
221
71
|
*/
|
|
222
72
|
export function deconstructError(
|
|
223
73
|
error: unknown,
|
|
224
|
-
logger: Logger,
|
|
225
|
-
extraLog: Record<string, unknown>,
|
|
226
74
|
exposeInternalError = false,
|
|
227
75
|
): DeconstructedError {
|
|
228
76
|
// Build response error information. Only return errors if flagged as public in order to prevent leaking internal behavior.
|
|
229
|
-
//
|
|
230
|
-
// We log the error here instead of after generating the code & message because we need to log the original error, not the masked internal error.
|
|
231
77
|
let statusCode: ContentfulStatusCode;
|
|
232
78
|
let public_: boolean;
|
|
233
79
|
let group: string;
|
|
234
80
|
let code: string;
|
|
235
81
|
let message: string;
|
|
236
82
|
let metadata: unknown;
|
|
83
|
+
let actor: errors.ActorSpecifier | undefined;
|
|
237
84
|
// Structured errors from core or from pre-built `RivetError` instances are canonical.
|
|
238
85
|
// Only unstructured errors go through the classifier below.
|
|
239
86
|
if (isCanonicalStructuredRivetError(error)) {
|
|
@@ -249,15 +96,7 @@ export function deconstructError(
|
|
|
249
96
|
code = error.code;
|
|
250
97
|
message = error.message;
|
|
251
98
|
metadata = error.metadata;
|
|
252
|
-
|
|
253
|
-
logger.info({
|
|
254
|
-
msg: "structured error passthrough",
|
|
255
|
-
group,
|
|
256
|
-
code,
|
|
257
|
-
message,
|
|
258
|
-
...EXTRA_ERROR_LOG,
|
|
259
|
-
...extraLog,
|
|
260
|
-
});
|
|
99
|
+
actor = error.actor;
|
|
261
100
|
} else if (errors.ActorError.isActorError(error) && error.public) {
|
|
262
101
|
// Check if error has statusCode (could be ActorError instance or DeconstructedError)
|
|
263
102
|
statusCode = (
|
|
@@ -268,15 +107,7 @@ export function deconstructError(
|
|
|
268
107
|
code = error.code;
|
|
269
108
|
message = getErrorMessage(error);
|
|
270
109
|
metadata = error.metadata;
|
|
271
|
-
|
|
272
|
-
logger.info({
|
|
273
|
-
msg: "public error",
|
|
274
|
-
group,
|
|
275
|
-
code,
|
|
276
|
-
message,
|
|
277
|
-
...EXTRA_ERROR_LOG,
|
|
278
|
-
...extraLog,
|
|
279
|
-
});
|
|
110
|
+
actor = error.actor;
|
|
280
111
|
} else if (exposeInternalError) {
|
|
281
112
|
if (errors.ActorError.isActorError(error)) {
|
|
282
113
|
statusCode = 500;
|
|
@@ -285,32 +116,13 @@ export function deconstructError(
|
|
|
285
116
|
code = error.code;
|
|
286
117
|
message = getErrorMessage(error);
|
|
287
118
|
metadata = error.metadata;
|
|
288
|
-
|
|
289
|
-
logger.info({
|
|
290
|
-
msg: "internal error",
|
|
291
|
-
group,
|
|
292
|
-
code,
|
|
293
|
-
message,
|
|
294
|
-
stack: (error as Error)?.stack,
|
|
295
|
-
...EXTRA_ERROR_LOG,
|
|
296
|
-
...extraLog,
|
|
297
|
-
});
|
|
119
|
+
actor = error.actor;
|
|
298
120
|
} else {
|
|
299
121
|
statusCode = 500;
|
|
300
122
|
public_ = false;
|
|
301
123
|
group = "rivetkit";
|
|
302
124
|
code = errors.INTERNAL_ERROR_CODE;
|
|
303
125
|
message = getErrorMessage(error);
|
|
304
|
-
|
|
305
|
-
logger.info({
|
|
306
|
-
msg: "internal error",
|
|
307
|
-
group,
|
|
308
|
-
code,
|
|
309
|
-
message,
|
|
310
|
-
stack: (error as Error)?.stack,
|
|
311
|
-
...EXTRA_ERROR_LOG,
|
|
312
|
-
...extraLog,
|
|
313
|
-
});
|
|
314
126
|
}
|
|
315
127
|
} else {
|
|
316
128
|
statusCode = 500;
|
|
@@ -318,17 +130,12 @@ export function deconstructError(
|
|
|
318
130
|
group = "rivetkit";
|
|
319
131
|
code = errors.INTERNAL_ERROR_CODE;
|
|
320
132
|
message = errors.INTERNAL_ERROR_DESCRIPTION;
|
|
133
|
+
if (errors.ActorError.isActorError(error)) {
|
|
134
|
+
actor = error.actor;
|
|
135
|
+
}
|
|
321
136
|
metadata = {
|
|
322
|
-
//url: `https://
|
|
137
|
+
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
323
138
|
} satisfies errors.InternalErrorMetadata;
|
|
324
|
-
|
|
325
|
-
logger.warn({
|
|
326
|
-
msg: "internal error",
|
|
327
|
-
error: getErrorMessage(error),
|
|
328
|
-
stack: (error as Error)?.stack,
|
|
329
|
-
...EXTRA_ERROR_LOG,
|
|
330
|
-
...extraLog,
|
|
331
|
-
});
|
|
332
139
|
}
|
|
333
140
|
|
|
334
141
|
return {
|
|
@@ -339,6 +146,7 @@ export function deconstructError(
|
|
|
339
146
|
code,
|
|
340
147
|
message,
|
|
341
148
|
metadata,
|
|
149
|
+
actor,
|
|
342
150
|
};
|
|
343
151
|
}
|
|
344
152
|
|