rivetkit 2.3.0-rc.5 → 2.3.0-rc.7
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 +35 -3
- package/dist/browser/client.js +795 -200
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +4 -3
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +4 -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 +3 -1
- package/dist/tsup/agent-os/index.cjs +7 -5
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +35 -3
- package/dist/tsup/agent-os/index.d.ts +35 -3
- package/dist/tsup/agent-os/index.js +7 -5
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-2GANBXVP.cjs → chunk-2H4ISA4Y.cjs} +10 -10
- package/dist/tsup/chunk-2H4ISA4Y.cjs.map +1 -0
- package/dist/tsup/{chunk-UXTP4EBU.js → chunk-4DJMFOSU.js} +2 -2
- package/dist/tsup/{chunk-LDTT6WKJ.js → chunk-4LTY5TOO.js} +132 -4
- package/dist/tsup/chunk-4LTY5TOO.js.map +1 -0
- package/dist/tsup/{chunk-PGYEMIOE.js → chunk-52TPEKEC.js} +2 -2
- package/dist/tsup/{chunk-OVJX4IFY.cjs → chunk-55E7IR6D.cjs} +4 -4
- package/dist/tsup/{chunk-OVJX4IFY.cjs.map → chunk-55E7IR6D.cjs.map} +1 -1
- package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-63WNTDRC.cjs} +31 -10
- package/dist/tsup/chunk-63WNTDRC.cjs.map +1 -0
- package/dist/tsup/{chunk-SULB574D.js → chunk-CMV6N5OX.js} +3 -3
- package/dist/tsup/{chunk-T6YVRM4K.js → chunk-D5G75T7J.js} +3 -1
- package/dist/tsup/chunk-D5G75T7J.js.map +1 -0
- package/dist/tsup/{chunk-NW2J4SOL.cjs → chunk-FEOG44WH.cjs} +137 -9
- package/dist/tsup/chunk-FEOG44WH.cjs.map +1 -0
- package/dist/tsup/{chunk-HR547GVH.cjs → chunk-G5HUSWP4.cjs} +8 -8
- package/dist/tsup/{chunk-HR547GVH.cjs.map → chunk-G5HUSWP4.cjs.map} +1 -1
- package/dist/tsup/{chunk-N2DQSJIW.js → chunk-HERL2VQ2.js} +17 -48
- package/dist/tsup/chunk-HERL2VQ2.js.map +1 -0
- package/dist/tsup/{chunk-LELRJK66.cjs → chunk-SJLPZEA3.cjs} +3 -3
- package/dist/tsup/{chunk-LELRJK66.cjs.map → chunk-SJLPZEA3.cjs.map} +1 -1
- package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-SRNOPUC6.cjs} +4 -2
- package/dist/tsup/chunk-SRNOPUC6.cjs.map +1 -0
- package/dist/tsup/{chunk-K34B3OVG.js → chunk-TMLOKTRB.js} +30 -9
- package/dist/tsup/chunk-TMLOKTRB.js.map +1 -0
- package/dist/tsup/{chunk-NATOT3ET.js → chunk-VFIY6GWO.js} +4 -4
- package/dist/tsup/chunk-VFIY6GWO.js.map +1 -0
- package/dist/tsup/{chunk-JY73X7VU.js → chunk-VJ4Y4WBT.js} +692 -114
- package/dist/tsup/chunk-VJ4Y4WBT.js.map +1 -0
- package/dist/tsup/{chunk-JRCZDHXT.cjs → chunk-X6HIFXNK.cjs} +23 -54
- package/dist/tsup/chunk-X6HIFXNK.cjs.map +1 -0
- package/dist/tsup/{chunk-FTZIZ3JG.cjs → chunk-ZGPX6KAH.cjs} +838 -260
- package/dist/tsup/chunk-ZGPX6KAH.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +7 -7
- package/dist/tsup/client/mod.d.cts +3 -4
- package/dist/tsup/client/mod.d.ts +3 -4
- package/dist/tsup/client/mod.js +6 -6
- 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-CvQUtDp9.d.ts → config-Ak1lv4gF.d.ts} +27 -5
- package/dist/tsup/{config-C-a9vrke.d.cts → config-DU_xj4qZ.d.cts} +27 -5
- package/dist/tsup/{context-A7R0bsZL.d.ts → context-DAAp4Lpg.d.ts} +1 -1
- package/dist/tsup/{context-CA3r-pf2.d.cts → context-Dt_L55q8.d.cts} +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/mod.cjs +507 -308
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -5
- package/dist/tsup/mod.d.ts +4 -5
- package/dist/tsup/mod.js +432 -233
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/process-metrics-NW754INA.js +118 -0
- package/dist/tsup/process-metrics-NW754INA.js.map +1 -0
- package/dist/tsup/process-metrics-TYAGKCEJ.cjs +118 -0
- package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +1 -0
- package/dist/tsup/test/mod.cjs +10 -10
- package/dist/tsup/test/mod.d.cts +2 -3
- package/dist/tsup/test/mod.d.ts +2 -3
- package/dist/tsup/test/mod.js +6 -6
- package/dist/tsup/utils-DVekpm4I.d.cts +103 -0
- package/dist/tsup/utils-DVekpm4I.d.ts +103 -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 +41 -16
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +4 -5
- package/dist/tsup/workflow/mod.d.ts +4 -5
- package/dist/tsup/workflow/mod.js +35 -10
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +11 -10
- package/src/actor/config.ts +3 -0
- package/src/actor/errors.ts +53 -7
- package/src/agent-os/actor/session.ts +2 -2
- package/src/client/actor-conn.ts +55 -60
- package/src/client/actor-handle.ts +59 -24
- package/src/client/errors.ts +2 -1
- package/src/client/queue.ts +2 -1
- package/src/client/raw-utils.ts +2 -4
- package/src/client/utils.ts +32 -4
- package/src/common/actor-router-consts.ts +4 -0
- package/src/common/bare/generated/client-protocol/v4.ts +599 -0
- package/src/common/client-protocol-versioned.ts +125 -18
- package/src/common/client-protocol-zod.ts +7 -0
- package/src/common/client-protocol.ts +1 -1
- package/src/common/database/native-database.test.ts +35 -0
- package/src/common/database/native-database.ts +8 -4
- package/src/common/encoding.ts +243 -5
- package/src/common/inline-websocket-adapter.ts +12 -12
- package/src/common/log.ts +1 -0
- package/src/common/router.ts +40 -10
- package/src/common/utils.ts +9 -200
- package/src/drivers/engine/actor-driver.ts +29 -28
- package/src/engine-client/actor-websocket-client.ts +2 -1
- package/src/engine-client/mod.ts +3 -2
- package/src/registry/config/index.ts +3 -5
- package/src/registry/index.ts +90 -16
- package/src/registry/napi-runtime.ts +15 -0
- package/src/registry/native.ts +197 -255
- package/src/registry/process-metrics.ts +183 -0
- package/src/registry/runtime.ts +4 -0
- package/src/registry/wasm-runtime.ts +9 -0
- package/src/registry/write-through-proxy.ts +40 -0
- package/src/serde.ts +2 -2
- package/src/workflow/context.ts +32 -5
- package/src/workflow/inspector.ts +2 -1
- package/dist/tsup/chunk-2GANBXVP.cjs.map +0 -1
- package/dist/tsup/chunk-FTZIZ3JG.cjs.map +0 -1
- package/dist/tsup/chunk-JRCZDHXT.cjs.map +0 -1
- package/dist/tsup/chunk-JY73X7VU.js.map +0 -1
- package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
- package/dist/tsup/chunk-LDTT6WKJ.js.map +0 -1
- package/dist/tsup/chunk-N2DQSJIW.js.map +0 -1
- package/dist/tsup/chunk-NATOT3ET.js.map +0 -1
- package/dist/tsup/chunk-NW2J4SOL.cjs.map +0 -1
- package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
- package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
- package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
- package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
- /package/dist/tsup/{chunk-UXTP4EBU.js.map → chunk-4DJMFOSU.js.map} +0 -0
- /package/dist/tsup/{chunk-PGYEMIOE.js.map → chunk-52TPEKEC.js.map} +0 -0
- /package/dist/tsup/{chunk-SULB574D.js.map → chunk-CMV6N5OX.js.map} +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// src/registry/process-metrics.ts
|
|
2
|
+
import { monitorEventLoopDelay, performance, PerformanceObserver } from "perf_hooks";
|
|
3
|
+
import { getHeapStatistics } from "v8";
|
|
4
|
+
import * as napi from "@rivetkit/rivetkit-napi";
|
|
5
|
+
function callIfFn(fn, ...args) {
|
|
6
|
+
if (typeof fn === "function") {
|
|
7
|
+
fn(...args);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var SCRAPE_INTERVAL_MS = 5e3;
|
|
11
|
+
var HEARTBEAT_INTERVAL_MS = 100;
|
|
12
|
+
var EVENTLOOP_DELAY_RESOLUTION_MS = 20;
|
|
13
|
+
var NS_PER_SECOND = 1e9;
|
|
14
|
+
var US_PER_SECOND = 1e6;
|
|
15
|
+
var GC_KIND_NAMES = {
|
|
16
|
+
1: "minor",
|
|
17
|
+
2: "major",
|
|
18
|
+
4: "incremental",
|
|
19
|
+
8: "weakcb"
|
|
20
|
+
};
|
|
21
|
+
var state;
|
|
22
|
+
function startProcessMetrics() {
|
|
23
|
+
if (state) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const eventLoopHistogram = monitorEventLoopDelay({
|
|
27
|
+
resolution: EVENTLOOP_DELAY_RESOLUTION_MS
|
|
28
|
+
});
|
|
29
|
+
eventLoopHistogram.enable();
|
|
30
|
+
const gcObserver = new PerformanceObserver((list) => {
|
|
31
|
+
var _a;
|
|
32
|
+
for (const entry of list.getEntries()) {
|
|
33
|
+
const kind = ((_a = entry.detail) == null ? void 0 : _a.kind) ?? entry.kind;
|
|
34
|
+
if (typeof kind !== "number") continue;
|
|
35
|
+
const kindName = GC_KIND_NAMES[kind];
|
|
36
|
+
if (!kindName) continue;
|
|
37
|
+
callIfFn(napi.jsObserveGcDuration, kindName, entry.duration / 1e3);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
gcObserver.observe({ entryTypes: ["gc"], buffered: false });
|
|
41
|
+
const lastCpuUsage = process.cpuUsage();
|
|
42
|
+
const lastEventLoopUtilization = performance.eventLoopUtilization();
|
|
43
|
+
const heartbeatInterval = setInterval(() => {
|
|
44
|
+
callIfFn(napi.jsSetEventloopHeartbeatTsMs, Date.now());
|
|
45
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
46
|
+
heartbeatInterval.unref();
|
|
47
|
+
const scrapeInterval = setInterval(() => {
|
|
48
|
+
try {
|
|
49
|
+
collectAndPush();
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}, SCRAPE_INTERVAL_MS);
|
|
53
|
+
scrapeInterval.unref();
|
|
54
|
+
state = {
|
|
55
|
+
scrapeInterval,
|
|
56
|
+
heartbeatInterval,
|
|
57
|
+
gcObserver,
|
|
58
|
+
eventLoopHistogram,
|
|
59
|
+
lastCpuUsage,
|
|
60
|
+
lastEventLoopUtilization
|
|
61
|
+
};
|
|
62
|
+
callIfFn(napi.jsSetEventloopHeartbeatTsMs, Date.now());
|
|
63
|
+
try {
|
|
64
|
+
collectAndPush();
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function stopProcessMetrics() {
|
|
69
|
+
if (!state) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
clearInterval(state.scrapeInterval);
|
|
73
|
+
clearInterval(state.heartbeatInterval);
|
|
74
|
+
state.gcObserver.disconnect();
|
|
75
|
+
state.eventLoopHistogram.disable();
|
|
76
|
+
state = void 0;
|
|
77
|
+
}
|
|
78
|
+
function collectAndPush() {
|
|
79
|
+
if (!state) return;
|
|
80
|
+
const hist = state.eventLoopHistogram;
|
|
81
|
+
callIfFn(napi.jsSetEventloopLagQuantile, "p50", hist.percentile(50) / NS_PER_SECOND);
|
|
82
|
+
callIfFn(napi.jsSetEventloopLagQuantile, "p90", hist.percentile(90) / NS_PER_SECOND);
|
|
83
|
+
callIfFn(napi.jsSetEventloopLagQuantile, "p99", hist.percentile(99) / NS_PER_SECOND);
|
|
84
|
+
callIfFn(napi.jsSetEventloopLagQuantile, "max", hist.max / NS_PER_SECOND);
|
|
85
|
+
hist.reset();
|
|
86
|
+
const nextElu = performance.eventLoopUtilization();
|
|
87
|
+
const eluDelta = performance.eventLoopUtilization(nextElu, state.lastEventLoopUtilization);
|
|
88
|
+
state.lastEventLoopUtilization = nextElu;
|
|
89
|
+
callIfFn(napi.jsSetEventloopUtilization, eluDelta.utilization);
|
|
90
|
+
const nextCpu = process.cpuUsage();
|
|
91
|
+
const userDeltaUs = nextCpu.user - state.lastCpuUsage.user;
|
|
92
|
+
const systemDeltaUs = nextCpu.system - state.lastCpuUsage.system;
|
|
93
|
+
state.lastCpuUsage = nextCpu;
|
|
94
|
+
if (userDeltaUs > 0) {
|
|
95
|
+
callIfFn(napi.jsAddProcessCpuSeconds, "user", userDeltaUs / US_PER_SECOND);
|
|
96
|
+
}
|
|
97
|
+
if (systemDeltaUs > 0) {
|
|
98
|
+
callIfFn(napi.jsAddProcessCpuSeconds, "system", systemDeltaUs / US_PER_SECOND);
|
|
99
|
+
}
|
|
100
|
+
const mem = process.memoryUsage();
|
|
101
|
+
callIfFn(napi.jsSetProcessResidentMemoryBytes, mem.rss);
|
|
102
|
+
callIfFn(napi.jsSetHeapBytes, "used", mem.heapUsed);
|
|
103
|
+
callIfFn(napi.jsSetHeapBytes, "total", mem.heapTotal);
|
|
104
|
+
const heapLimit = getHeapStatistics().heap_size_limit;
|
|
105
|
+
callIfFn(napi.jsSetHeapBytes, "limit", heapLimit);
|
|
106
|
+
const proc = process;
|
|
107
|
+
if (typeof proc._getActiveHandles === "function") {
|
|
108
|
+
callIfFn(napi.jsSetActiveHandles, proc._getActiveHandles().length);
|
|
109
|
+
}
|
|
110
|
+
if (typeof proc._getActiveRequests === "function") {
|
|
111
|
+
callIfFn(napi.jsSetActiveRequests, proc._getActiveRequests().length);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export {
|
|
115
|
+
startProcessMetrics,
|
|
116
|
+
stopProcessMetrics
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=process-metrics-NW754INA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/registry/process-metrics.ts"],"sourcesContent":["/**\n * Node.js runtime health metrics.\n *\n * Collects JS-internal data (event loop lag, GC, heap, libuv handles,\n * event loop utilization, CPU) using Node built-ins (`node:perf_hooks`,\n * `process`, `node:v8`, `PerformanceObserver`) and pushes them across NAPI\n * into Rust-side prometheus collectors registered with\n * `rivet_metrics::REGISTRY` so they appear on the existing `/metrics`\n * endpoint.\n *\n * All data collection happens here in TypeScript. The NAPI bridge is pure\n * type marshalling and the Rust side only registers + stores the metrics.\n */\nimport { monitorEventLoopDelay, performance, PerformanceObserver } from \"node:perf_hooks\";\nimport { getHeapStatistics } from \"node:v8\";\nimport * as napi from \"@rivetkit/rivetkit-napi\";\n\n// Some napi process-metrics symbols may be missing on older native binaries\n// (the auto-generated index.js destructures them as `undefined` if the\n// underlying `.node` was built before they were added). Guard each call so\n// the metrics collection runs as a no-op instead of throwing\n// `TypeError: napi.jsXxx is not a function` on every interval tick.\nfunction callIfFn<T extends unknown[]>(\n\tfn: ((...args: T) => void) | undefined,\n\t...args: T\n): void {\n\tif (typeof fn === \"function\") {\n\t\tfn(...args);\n\t}\n}\n\nconst SCRAPE_INTERVAL_MS = 5_000;\nconst HEARTBEAT_INTERVAL_MS = 100;\nconst EVENTLOOP_DELAY_RESOLUTION_MS = 20;\nconst NS_PER_SECOND = 1e9;\nconst US_PER_SECOND = 1e6;\n\n// V8 GC kind bitfield from Node's perf_hooks documentation. A `gc` performance\n// entry's `kind` field is one of these values.\nconst GC_KIND_NAMES: Record<number, string> = {\n\t1: \"minor\",\n\t2: \"major\",\n\t4: \"incremental\",\n\t8: \"weakcb\",\n};\n\ninterface ProcessMetricsState {\n\tscrapeInterval: NodeJS.Timeout;\n\theartbeatInterval: NodeJS.Timeout;\n\tgcObserver: PerformanceObserver;\n\teventLoopHistogram: ReturnType<typeof monitorEventLoopDelay>;\n\tlastCpuUsage: NodeJS.CpuUsage;\n\tlastEventLoopUtilization: ReturnType<typeof performance.eventLoopUtilization>;\n}\n\nlet state: ProcessMetricsState | undefined;\n\nexport function startProcessMetrics(): void {\n\tif (state) {\n\t\treturn;\n\t}\n\n\tconst eventLoopHistogram = monitorEventLoopDelay({\n\t\tresolution: EVENTLOOP_DELAY_RESOLUTION_MS,\n\t});\n\teventLoopHistogram.enable();\n\n\tconst gcObserver = new PerformanceObserver((list) => {\n\t\tfor (const entry of list.getEntries()) {\n\t\t\tconst kind =\n\t\t\t\t(entry as PerformanceEntry & { detail?: { kind?: number }; kind?: number }).detail\n\t\t\t\t\t?.kind ??\n\t\t\t\t(entry as PerformanceEntry & { kind?: number }).kind;\n\t\t\tif (typeof kind !== \"number\") continue;\n\t\t\tconst kindName = GC_KIND_NAMES[kind];\n\t\t\tif (!kindName) continue;\n\t\t\t// `entry.duration` is in milliseconds; convert to seconds.\n\t\t\tcallIfFn(napi.jsObserveGcDuration, kindName, entry.duration / 1000);\n\t\t}\n\t});\n\tgcObserver.observe({ entryTypes: [\"gc\"], buffered: false });\n\n\tconst lastCpuUsage = process.cpuUsage();\n\tconst lastEventLoopUtilization = performance.eventLoopUtilization();\n\n\tconst heartbeatInterval = setInterval(() => {\n\t\tcallIfFn(napi.jsSetEventloopHeartbeatTsMs, Date.now());\n\t}, HEARTBEAT_INTERVAL_MS);\n\theartbeatInterval.unref();\n\n\tconst scrapeInterval = setInterval(() => {\n\t\ttry {\n\t\t\tcollectAndPush();\n\t\t} catch {\n\t\t\t// Collection errors must never bring down the process; metrics\n\t\t\t// are best-effort.\n\t\t}\n\t}, SCRAPE_INTERVAL_MS);\n\tscrapeInterval.unref();\n\n\tstate = {\n\t\tscrapeInterval,\n\t\theartbeatInterval,\n\t\tgcObserver,\n\t\teventLoopHistogram,\n\t\tlastCpuUsage,\n\t\tlastEventLoopUtilization,\n\t};\n\n\t// Emit one snapshot immediately so freshly-scraped instances have data.\n\tcallIfFn(napi.jsSetEventloopHeartbeatTsMs, Date.now());\n\ttry {\n\t\tcollectAndPush();\n\t} catch {\n\t\t// As above; best-effort.\n\t}\n}\n\nexport function stopProcessMetrics(): void {\n\tif (!state) {\n\t\treturn;\n\t}\n\tclearInterval(state.scrapeInterval);\n\tclearInterval(state.heartbeatInterval);\n\tstate.gcObserver.disconnect();\n\tstate.eventLoopHistogram.disable();\n\tstate = undefined;\n}\n\nfunction collectAndPush(): void {\n\tif (!state) return;\n\n\t// Event loop delay quantiles. `monitorEventLoopDelay()` reports values in\n\t// nanoseconds; convert to seconds. Reset after reading so the next window\n\t// reflects only the new interval.\n\tconst hist = state.eventLoopHistogram;\n\tcallIfFn(napi.jsSetEventloopLagQuantile, \"p50\", hist.percentile(50) / NS_PER_SECOND);\n\tcallIfFn(napi.jsSetEventloopLagQuantile, \"p90\", hist.percentile(90) / NS_PER_SECOND);\n\tcallIfFn(napi.jsSetEventloopLagQuantile, \"p99\", hist.percentile(99) / NS_PER_SECOND);\n\tcallIfFn(napi.jsSetEventloopLagQuantile, \"max\", hist.max / NS_PER_SECOND);\n\thist.reset();\n\n\t// Event loop utilization delta over the scrape window.\n\tconst nextElu = performance.eventLoopUtilization();\n\tconst eluDelta = performance.eventLoopUtilization(nextElu, state.lastEventLoopUtilization);\n\tstate.lastEventLoopUtilization = nextElu;\n\tcallIfFn(napi.jsSetEventloopUtilization, eluDelta.utilization);\n\n\t// CPU usage delta. `process.cpuUsage()` returns microseconds.\n\tconst nextCpu = process.cpuUsage();\n\tconst userDeltaUs = nextCpu.user - state.lastCpuUsage.user;\n\tconst systemDeltaUs = nextCpu.system - state.lastCpuUsage.system;\n\tstate.lastCpuUsage = nextCpu;\n\tif (userDeltaUs > 0) {\n\t\tcallIfFn(napi.jsAddProcessCpuSeconds, \"user\", userDeltaUs / US_PER_SECOND);\n\t}\n\tif (systemDeltaUs > 0) {\n\t\tcallIfFn(napi.jsAddProcessCpuSeconds, \"system\", systemDeltaUs / US_PER_SECOND);\n\t}\n\n\t// Memory + heap.\n\tconst mem = process.memoryUsage();\n\tcallIfFn(napi.jsSetProcessResidentMemoryBytes, mem.rss);\n\tcallIfFn(napi.jsSetHeapBytes, \"used\", mem.heapUsed);\n\tcallIfFn(napi.jsSetHeapBytes, \"total\", mem.heapTotal);\n\tconst heapLimit = getHeapStatistics().heap_size_limit;\n\tcallIfFn(napi.jsSetHeapBytes, \"limit\", heapLimit);\n\n\t// libuv active handles + requests. These are unstable Node internals\n\t// guarded behind underscore-prefixed names; if a future Node release\n\t// removes them the try/catch above keeps the rest of the collection\n\t// alive.\n\tconst proc = process as unknown as {\n\t\t_getActiveHandles?: () => unknown[];\n\t\t_getActiveRequests?: () => unknown[];\n\t};\n\tif (typeof proc._getActiveHandles === \"function\") {\n\t\tcallIfFn(napi.jsSetActiveHandles, proc._getActiveHandles().length);\n\t}\n\tif (typeof proc._getActiveRequests === \"function\") {\n\t\tcallIfFn(napi.jsSetActiveRequests, proc._getActiveRequests().length);\n\t}\n}\n"],"mappings":";AAaA,SAAS,uBAAuB,aAAa,2BAA2B;AACxE,SAAS,yBAAyB;AAClC,YAAY,UAAU;AAOtB,SAAS,SACR,OACG,MACI;AACP,MAAI,OAAO,OAAO,YAAY;AAC7B,OAAG,GAAG,IAAI;AAAA,EACX;AACD;AAEA,IAAM,qBAAqB;AAC3B,IAAM,wBAAwB;AAC9B,IAA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Ac,0BAAqB,KAAK,mBAAmB,EAAE,MAAM;AAAA,EACpE;AACD;","names":[]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/registry/process-metrics.ts
|
|
2
|
+
var _perf_hooks = require('perf_hooks');
|
|
3
|
+
var _v8 = require('v8');
|
|
4
|
+
var _rivetkitnapi = require('@rivetkit/rivetkit-napi'); var napi = _interopRequireWildcard(_rivetkitnapi);
|
|
5
|
+
function callIfFn(fn, ...args) {
|
|
6
|
+
if (typeof fn === "function") {
|
|
7
|
+
fn(...args);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var SCRAPE_INTERVAL_MS = 5e3;
|
|
11
|
+
var HEARTBEAT_INTERVAL_MS = 100;
|
|
12
|
+
var EVENTLOOP_DELAY_RESOLUTION_MS = 20;
|
|
13
|
+
var NS_PER_SECOND = 1e9;
|
|
14
|
+
var US_PER_SECOND = 1e6;
|
|
15
|
+
var GC_KIND_NAMES = {
|
|
16
|
+
1: "minor",
|
|
17
|
+
2: "major",
|
|
18
|
+
4: "incremental",
|
|
19
|
+
8: "weakcb"
|
|
20
|
+
};
|
|
21
|
+
var state;
|
|
22
|
+
function startProcessMetrics() {
|
|
23
|
+
if (state) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const eventLoopHistogram = _perf_hooks.monitorEventLoopDelay.call(void 0, {
|
|
27
|
+
resolution: EVENTLOOP_DELAY_RESOLUTION_MS
|
|
28
|
+
});
|
|
29
|
+
eventLoopHistogram.enable();
|
|
30
|
+
const gcObserver = new (0, _perf_hooks.PerformanceObserver)((list) => {
|
|
31
|
+
var _a;
|
|
32
|
+
for (const entry of list.getEntries()) {
|
|
33
|
+
const kind = _nullishCoalesce(((_a = entry.detail) == null ? void 0 : _a.kind), () => ( entry.kind));
|
|
34
|
+
if (typeof kind !== "number") continue;
|
|
35
|
+
const kindName = GC_KIND_NAMES[kind];
|
|
36
|
+
if (!kindName) continue;
|
|
37
|
+
callIfFn(napi.jsObserveGcDuration, kindName, entry.duration / 1e3);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
gcObserver.observe({ entryTypes: ["gc"], buffered: false });
|
|
41
|
+
const lastCpuUsage = process.cpuUsage();
|
|
42
|
+
const lastEventLoopUtilization = _perf_hooks.performance.eventLoopUtilization();
|
|
43
|
+
const heartbeatInterval = setInterval(() => {
|
|
44
|
+
callIfFn(napi.jsSetEventloopHeartbeatTsMs, Date.now());
|
|
45
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
46
|
+
heartbeatInterval.unref();
|
|
47
|
+
const scrapeInterval = setInterval(() => {
|
|
48
|
+
try {
|
|
49
|
+
collectAndPush();
|
|
50
|
+
} catch (e) {
|
|
51
|
+
}
|
|
52
|
+
}, SCRAPE_INTERVAL_MS);
|
|
53
|
+
scrapeInterval.unref();
|
|
54
|
+
state = {
|
|
55
|
+
scrapeInterval,
|
|
56
|
+
heartbeatInterval,
|
|
57
|
+
gcObserver,
|
|
58
|
+
eventLoopHistogram,
|
|
59
|
+
lastCpuUsage,
|
|
60
|
+
lastEventLoopUtilization
|
|
61
|
+
};
|
|
62
|
+
callIfFn(napi.jsSetEventloopHeartbeatTsMs, Date.now());
|
|
63
|
+
try {
|
|
64
|
+
collectAndPush();
|
|
65
|
+
} catch (e2) {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function stopProcessMetrics() {
|
|
69
|
+
if (!state) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
clearInterval(state.scrapeInterval);
|
|
73
|
+
clearInterval(state.heartbeatInterval);
|
|
74
|
+
state.gcObserver.disconnect();
|
|
75
|
+
state.eventLoopHistogram.disable();
|
|
76
|
+
state = void 0;
|
|
77
|
+
}
|
|
78
|
+
function collectAndPush() {
|
|
79
|
+
if (!state) return;
|
|
80
|
+
const hist = state.eventLoopHistogram;
|
|
81
|
+
callIfFn(napi.jsSetEventloopLagQuantile, "p50", hist.percentile(50) / NS_PER_SECOND);
|
|
82
|
+
callIfFn(napi.jsSetEventloopLagQuantile, "p90", hist.percentile(90) / NS_PER_SECOND);
|
|
83
|
+
callIfFn(napi.jsSetEventloopLagQuantile, "p99", hist.percentile(99) / NS_PER_SECOND);
|
|
84
|
+
callIfFn(napi.jsSetEventloopLagQuantile, "max", hist.max / NS_PER_SECOND);
|
|
85
|
+
hist.reset();
|
|
86
|
+
const nextElu = _perf_hooks.performance.eventLoopUtilization();
|
|
87
|
+
const eluDelta = _perf_hooks.performance.eventLoopUtilization(nextElu, state.lastEventLoopUtilization);
|
|
88
|
+
state.lastEventLoopUtilization = nextElu;
|
|
89
|
+
callIfFn(napi.jsSetEventloopUtilization, eluDelta.utilization);
|
|
90
|
+
const nextCpu = process.cpuUsage();
|
|
91
|
+
const userDeltaUs = nextCpu.user - state.lastCpuUsage.user;
|
|
92
|
+
const systemDeltaUs = nextCpu.system - state.lastCpuUsage.system;
|
|
93
|
+
state.lastCpuUsage = nextCpu;
|
|
94
|
+
if (userDeltaUs > 0) {
|
|
95
|
+
callIfFn(napi.jsAddProcessCpuSeconds, "user", userDeltaUs / US_PER_SECOND);
|
|
96
|
+
}
|
|
97
|
+
if (systemDeltaUs > 0) {
|
|
98
|
+
callIfFn(napi.jsAddProcessCpuSeconds, "system", systemDeltaUs / US_PER_SECOND);
|
|
99
|
+
}
|
|
100
|
+
const mem = process.memoryUsage();
|
|
101
|
+
callIfFn(napi.jsSetProcessResidentMemoryBytes, mem.rss);
|
|
102
|
+
callIfFn(napi.jsSetHeapBytes, "used", mem.heapUsed);
|
|
103
|
+
callIfFn(napi.jsSetHeapBytes, "total", mem.heapTotal);
|
|
104
|
+
const heapLimit = _v8.getHeapStatistics.call(void 0, ).heap_size_limit;
|
|
105
|
+
callIfFn(napi.jsSetHeapBytes, "limit", heapLimit);
|
|
106
|
+
const proc = process;
|
|
107
|
+
if (typeof proc._getActiveHandles === "function") {
|
|
108
|
+
callIfFn(napi.jsSetActiveHandles, proc._getActiveHandles().length);
|
|
109
|
+
}
|
|
110
|
+
if (typeof proc._getActiveRequests === "function") {
|
|
111
|
+
callIfFn(napi.jsSetActiveRequests, proc._getActiveRequests().length);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
exports.startProcessMetrics = startProcessMetrics; exports.stopProcessMetrics = stopProcessMetrics;
|
|
118
|
+
//# sourceMappingURL=process-metrics-TYAGKCEJ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/process-metrics-TYAGKCEJ.cjs","../../src/registry/process-metrics.ts"],"names":[],"mappings":"AAAA;ACaA,wCAAwE;AACxE,wBAAkC;AAClC,0GAAsB;AAOtB,SAAS,QAAA,CACR,EAAA,EAAA,GACG,IAAA,EACI;AACP,EAAA,GAAA,CAAI,OAAO,GAAA,IAAO,UAAA,EAAY;AAC7B,IAAA,EAAA,CAAG,GAAG,IAAI,CAAA;AAAA,EACX;AACD;AAEA,IAAM,mBAAA,EAAqB,GAAA;AAC3B,IAAM,sBAAA,EAAwB,GAAA;AAC9B,IAAM,8BAAA,EAAgC,EAAA;AACtC,IAAM,cAAA,EAAgB,GAAA;AACtB,IAAM,cAAA,EAAgB,GAAA;AAItB,IAAM,cAAA,EAAwC;AAAA,EAC7C,CAAA,EAAG,OAAA;AAAA,EACH,CAAA,EAAG,OAAA;AAAA,EACH,CAAA,EAAG,aAAA;AAAA,EACH,CAAA,EAAG;AACJ,CAAA;AAWA,IAAI,KAAA;AAEG,SAAS,mBAAA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;AAGA,EAAA,MAAM,IAAA,EAAM,OAAA,CAAQ,WAAA,CAAY,CAAA;AAChC,EAAA,QAAA,CAAc,IAAA,CAAA,+BAAA,EAAiC,GAAA,CAAI,GAAG,CAAA;AACtD,EAAA,QAAA,CAAc,IAAA,CAAA,cAAA,EAAgB,MAAA,EAAQ,GAAA,CAAI,QAAQ,CAAA;AAClD,EAAA,QAAA,CAAc,IAAA,CAAA,cAAA,EAAgB,OAAA,EAAS,GAAA,CAAI,SAAS,CAAA;AACpD,EAAA,MAAM,UAAA,EAAY,mCAAA,CAAkB,CAAE,eAAA;AACtC,EAAA,QAAA,CAAc,IAAA,CAAA,cAAA,EAAgB,OAAA,EAAS,SAAS,CAAA;AAMhD,EAAA,MAAM,KAAA,EAAO,OAAA;AAIb,EAAA,GAAA,CAAI,OAAO,IAAA,CAAK,kBAAA,IAAsB,UAAA,EAAY;AACjD,IAAA,QAAA,CAAc,IAAA,CAAA,kBAAA,EAAoB,IAAA,CAAK,iBAAA,CAAkB,CAAA,CAAE,MAAM,CAAA;AAAA,EAClE;AACA,EAAA,GAAA,CAAI,OAAO,IAAA,CAAK,mBAAA,IAAuB,UAAA,EAAY;AAClD,IAAA,QAAA,CAAc,IAAA,CAAA,mBAAA,EAAqB,IAAA,CAAK,kBAAA,CAAmB,CAAA,CAAE,MAAM,CAAA;AAAA,EACpE;AACD;ADrEA;AACE;AACA;AACF,mGAAC","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/process-metrics-TYAGKCEJ.cjs","sourcesContent":[null,"/**\n * Node.js runtime health metrics.\n *\n * Collects JS-internal data (event loop lag, GC, heap, libuv handles,\n * event loop utilization, CPU) using Node built-ins (`node:perf_hooks`,\n * `process`, `node:v8`, `PerformanceObserver`) and pushes them across NAPI\n * into Rust-side prometheus collectors registered with\n * `rivet_metrics::REGISTRY` so they appear on the existing `/metrics`\n * endpoint.\n *\n * All data collection happens here in TypeScript. The NAPI bridge is pure\n * type marshalling and the Rust side only registers + stores the metrics.\n */\nimport { monitorEventLoopDelay, performance, PerformanceObserver } from \"node:perf_hooks\";\nimport { getHeapStatistics } from \"node:v8\";\nimport * as napi from \"@rivetkit/rivetkit-napi\";\n\n// Some napi process-metrics symbols may be missing on older native binaries\n// (the auto-generated index.js destructures them as `undefined` if the\n// underlying `.node` was built before they were added). Guard each call so\n// the metrics collection runs as a no-op instead of throwing\n// `TypeError: napi.jsXxx is not a function` on every interval tick.\nfunction callIfFn<T extends unknown[]>(\n\tfn: ((...args: T) => void) | undefined,\n\t...args: T\n): void {\n\tif (typeof fn === \"function\") {\n\t\tfn(...args);\n\t}\n}\n\nconst SCRAPE_INTERVAL_MS = 5_000;\nconst HEARTBEAT_INTERVAL_MS = 100;\nconst EVENTLOOP_DELAY_RESOLUTION_MS = 20;\nconst NS_PER_SECOND = 1e9;\nconst US_PER_SECOND = 1e6;\n\n// V8 GC kind bitfield from Node's perf_hooks documentation. A `gc` performance\n// entry's `kind` field is one of these values.\nconst GC_KIND_NAMES: Record<number, string> = {\n\t1: \"minor\",\n\t2: \"major\",\n\t4: \"incremental\",\n\t8: \"weakcb\",\n};\n\ninterface ProcessMetricsState {\n\tscrapeInterval: NodeJS.Timeout;\n\theartbeatInterval: NodeJS.Timeout;\n\tgcObserver: PerformanceObserver;\n\teventLoopHistogram: ReturnType<typeof monitorEventLoopDelay>;\n\tlastCpuUsage: NodeJS.CpuUsage;\n\tlastEventLoopUtilization: ReturnType<typeof performance.eventLoopUtilization>;\n}\n\nlet state: ProcessMetricsState | undefined;\n\nexport function startProcessMetrics(): void {\n\tif (state) {\n\t\treturn;\n\t}\n\n\tconst eventLoopHistogram = monitorEventLoopDelay({\n\t\tresolution: EVENTLOOP_DELAY_RESOLUTION_MS,\n\t});\n\teventLoopHistogram.enable();\n\n\tconst gcObserver = new PerformanceObserver((list) => {\n\t\tfor (const entry of list.getEntries()) {\n\t\t\tconst kind =\n\t\t\t\t(entry as PerformanceEntry & { detail?: { kind?: number }; kind?: number }).detail\n\t\t\t\t\t?.kind ??\n\t\t\t\t(entry as PerformanceEntry & { kind?: number }).kind;\n\t\t\tif (typeof kind !== \"number\") continue;\n\t\t\tconst kindName = GC_KIND_NAMES[kind];\n\t\t\tif (!kindName) continue;\n\t\t\t// `entry.duration` is in milliseconds; convert to seconds.\n\t\t\tcallIfFn(napi.jsObserveGcDuration, kindName, entry.duration / 1000);\n\t\t}\n\t});\n\tgcObserver.observe({ entryTypes: [\"gc\"], buffered: false });\n\n\tconst lastCpuUsage = process.cpuUsage();\n\tconst lastEventLoopUtilization = performance.eventLoopUtilization();\n\n\tconst heartbeatInterval = setInterval(() => {\n\t\tcallIfFn(napi.jsSetEventloopHeartbeatTsMs, Date.now());\n\t}, HEARTBEAT_INTERVAL_MS);\n\theartbeatInterval.unref();\n\n\tconst scrapeInterval = setInterval(() => {\n\t\ttry {\n\t\t\tcollectAndPush();\n\t\t} catch {\n\t\t\t// Collection errors must never bring down the process; metrics\n\t\t\t// are best-effort.\n\t\t}\n\t}, SCRAPE_INTERVAL_MS);\n\tscrapeInterval.unref();\n\n\tstate = {\n\t\tscrapeInterval,\n\t\theartbeatInterval,\n\t\tgcObserver,\n\t\teventLoopHistogram,\n\t\tlastCpuUsage,\n\t\tlastEventLoopUtilization,\n\t};\n\n\t// Emit one snapshot immediately so freshly-scraped instances have data.\n\tcallIfFn(napi.jsSetEventloopHeartbeatTsMs, Date.now());\n\ttry {\n\t\tcollectAndPush();\n\t} catch {\n\t\t// As above; best-effort.\n\t}\n}\n\nexport function stopProcessMetrics(): void {\n\tif (!state) {\n\t\treturn;\n\t}\n\tclearInterval(state.scrapeInterval);\n\tclearInterval(state.heartbeatInterval);\n\tstate.gcObserver.disconnect();\n\tstate.eventLoopHistogram.disable();\n\tstate = undefined;\n}\n\nfunction collectAndPush(): void {\n\tif (!state) return;\n\n\t// Event loop delay quantiles. `monitorEventLoopDelay()` reports values in\n\t// nanoseconds; convert to seconds. Reset after reading so the next window\n\t// reflects only the new interval.\n\tconst hist = state.eventLoopHistogram;\n\tcallIfFn(napi.jsSetEventloopLagQuantile, \"p50\", hist.percentile(50) / NS_PER_SECOND);\n\tcallIfFn(napi.jsSetEventloopLagQuantile, \"p90\", hist.percentile(90) / NS_PER_SECOND);\n\tcallIfFn(napi.jsSetEventloopLagQuantile, \"p99\", hist.percentile(99) / NS_PER_SECOND);\n\tcallIfFn(napi.jsSetEventloopLagQuantile, \"max\", hist.max / NS_PER_SECOND);\n\thist.reset();\n\n\t// Event loop utilization delta over the scrape window.\n\tconst nextElu = performance.eventLoopUtilization();\n\tconst eluDelta = performance.eventLoopUtilization(nextElu, state.lastEventLoopUtilization);\n\tstate.lastEventLoopUtilization = nextElu;\n\tcallIfFn(napi.jsSetEventloopUtilization, eluDelta.utilization);\n\n\t// CPU usage delta. `process.cpuUsage()` returns microseconds.\n\tconst nextCpu = process.cpuUsage();\n\tconst userDeltaUs = nextCpu.user - state.lastCpuUsage.user;\n\tconst systemDeltaUs = nextCpu.system - state.lastCpuUsage.system;\n\tstate.lastCpuUsage = nextCpu;\n\tif (userDeltaUs > 0) {\n\t\tcallIfFn(napi.jsAddProcessCpuSeconds, \"user\", userDeltaUs / US_PER_SECOND);\n\t}\n\tif (systemDeltaUs > 0) {\n\t\tcallIfFn(napi.jsAddProcessCpuSeconds, \"system\", systemDeltaUs / US_PER_SECOND);\n\t}\n\n\t// Memory + heap.\n\tconst mem = process.memoryUsage();\n\tcallIfFn(napi.jsSetProcessResidentMemoryBytes, mem.rss);\n\tcallIfFn(napi.jsSetHeapBytes, \"used\", mem.heapUsed);\n\tcallIfFn(napi.jsSetHeapBytes, \"total\", mem.heapTotal);\n\tconst heapLimit = getHeapStatistics().heap_size_limit;\n\tcallIfFn(napi.jsSetHeapBytes, \"limit\", heapLimit);\n\n\t// libuv active handles + requests. These are unstable Node internals\n\t// guarded behind underscore-prefixed names; if a future Node release\n\t// removes them the try/catch above keeps the rest of the collection\n\t// alive.\n\tconst proc = process as unknown as {\n\t\t_getActiveHandles?: () => unknown[];\n\t\t_getActiveRequests?: () => unknown[];\n\t};\n\tif (typeof proc._getActiveHandles === \"function\") {\n\t\tcallIfFn(napi.jsSetActiveHandles, proc._getActiveHandles().length);\n\t}\n\tif (typeof proc._getActiveRequests === \"function\") {\n\t\tcallIfFn(napi.jsSetActiveRequests, proc._getActiveRequests().length);\n\t}\n}\n"]}
|
package/dist/tsup/test/mod.cjs
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkG5HUSWP4cjs = require('../chunk-G5HUSWP4.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkZGPX6KAHcjs = require('../chunk-ZGPX6KAH.cjs');
|
|
8
8
|
require('../chunk-LD5YASJU.cjs');
|
|
9
|
-
require('../chunk-
|
|
9
|
+
require('../chunk-FEOG44WH.cjs');
|
|
10
10
|
require('../chunk-2NDZ7JCR.cjs');
|
|
11
|
-
require('../chunk-
|
|
12
|
-
require('../chunk-
|
|
13
|
-
require('../chunk-
|
|
11
|
+
require('../chunk-SJLPZEA3.cjs');
|
|
12
|
+
require('../chunk-X6HIFXNK.cjs');
|
|
13
|
+
require('../chunk-63WNTDRC.cjs');
|
|
14
14
|
|
|
15
15
|
// src/test/mod.ts
|
|
16
16
|
var _pretry = require('p-retry'); var _pretry2 = _interopRequireDefault(_pretry);
|
|
17
17
|
async function waitForRegistryReady(registry) {
|
|
18
|
-
const clientConfig =
|
|
18
|
+
const clientConfig = _chunkZGPX6KAHcjs.convertRegistryConfigToClientConfig.call(void 0,
|
|
19
19
|
registry.parseConfig()
|
|
20
20
|
);
|
|
21
21
|
await _pretry2.default.call(void 0, async () => {
|
|
22
|
-
await
|
|
22
|
+
await _chunkZGPX6KAHcjs.getMetadata.call(void 0, clientConfig);
|
|
23
23
|
}, {
|
|
24
24
|
retries: 20,
|
|
25
25
|
minTimeout: 50,
|
|
@@ -31,8 +31,8 @@ async function setupTest(c, registry) {
|
|
|
31
31
|
registry.config.noWelcome = true;
|
|
32
32
|
registry.start();
|
|
33
33
|
await waitForRegistryReady(registry);
|
|
34
|
-
const client =
|
|
35
|
-
...
|
|
34
|
+
const client = _chunkG5HUSWP4cjs.createClient.call(void 0, {
|
|
35
|
+
..._chunkZGPX6KAHcjs.convertRegistryConfigToClientConfig.call(void 0, registry.parseConfig()),
|
|
36
36
|
disableMetadataLookup: false
|
|
37
37
|
});
|
|
38
38
|
c.onTestFinished(async () => {
|
package/dist/tsup/test/mod.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TestContext } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { aq as Registry, V as Client } from '../config-DU_xj4qZ.cjs';
|
|
3
3
|
import 'zod/v4';
|
|
4
4
|
import '@rivetkit/virtual-websocket';
|
|
5
5
|
import '../config-CxjGYf4K.cjs';
|
|
@@ -9,9 +9,8 @@ import 'pino';
|
|
|
9
9
|
import '@standard-schema/spec';
|
|
10
10
|
import 'hono';
|
|
11
11
|
import '../utils.cjs';
|
|
12
|
-
import '../utils-
|
|
12
|
+
import '../utils-DVekpm4I.cjs';
|
|
13
13
|
import 'hono/utils/http-status';
|
|
14
|
-
import '../actor/errors.cjs';
|
|
15
14
|
|
|
16
15
|
interface SetupTestResult<A extends Registry<any>> {
|
|
17
16
|
client: Client<A>;
|
package/dist/tsup/test/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TestContext } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { aq as Registry, V as Client } from '../config-Ak1lv4gF.js';
|
|
3
3
|
import 'zod/v4';
|
|
4
4
|
import '@rivetkit/virtual-websocket';
|
|
5
5
|
import '../config-CxjGYf4K.js';
|
|
@@ -9,9 +9,8 @@ import 'pino';
|
|
|
9
9
|
import '@standard-schema/spec';
|
|
10
10
|
import 'hono';
|
|
11
11
|
import '../utils.js';
|
|
12
|
-
import '../utils-
|
|
12
|
+
import '../utils-DVekpm4I.js';
|
|
13
13
|
import 'hono/utils/http-status';
|
|
14
|
-
import '../actor/errors.js';
|
|
15
14
|
|
|
16
15
|
interface SetupTestResult<A extends Registry<any>> {
|
|
17
16
|
client: Client<A>;
|
package/dist/tsup/test/mod.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createClient
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-CMV6N5OX.js";
|
|
4
4
|
import {
|
|
5
5
|
convertRegistryConfigToClientConfig,
|
|
6
6
|
getMetadata
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-VJ4Y4WBT.js";
|
|
8
8
|
import "../chunk-3YY5S6TV.js";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-4LTY5TOO.js";
|
|
10
10
|
import "../chunk-PCBNKI2J.js";
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
11
|
+
import "../chunk-4DJMFOSU.js";
|
|
12
|
+
import "../chunk-HERL2VQ2.js";
|
|
13
|
+
import "../chunk-TMLOKTRB.js";
|
|
14
14
|
|
|
15
15
|
// src/test/mod.ts
|
|
16
16
|
import pRetry from "p-retry";
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Next } from 'hono';
|
|
2
|
+
import { ContentfulStatusCode } from 'hono/utils/http-status';
|
|
3
|
+
|
|
4
|
+
declare const INTERNAL_ERROR_CODE = "internal_error";
|
|
5
|
+
declare const INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
6
|
+
type InternalErrorMetadata = Record<string, never>;
|
|
7
|
+
declare const USER_ERROR_CODE = "user_error";
|
|
8
|
+
declare const BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
9
|
+
interface RivetErrorOptions extends ErrorOptions {
|
|
10
|
+
/** Error data can safely be serialized in a response to the client. */
|
|
11
|
+
public?: boolean;
|
|
12
|
+
/** Metadata associated with this error. */
|
|
13
|
+
metadata?: unknown;
|
|
14
|
+
/** Explicit HTTP status override for router responses. */
|
|
15
|
+
statusCode?: number;
|
|
16
|
+
/** Actor context associated with this error. */
|
|
17
|
+
actor?: ActorSpecifier;
|
|
18
|
+
}
|
|
19
|
+
/** Identifies the actor that was handling work when an error was produced. */
|
|
20
|
+
interface ActorSpecifier {
|
|
21
|
+
actorId: string;
|
|
22
|
+
generation: number;
|
|
23
|
+
key?: string;
|
|
24
|
+
}
|
|
25
|
+
interface RivetErrorLike {
|
|
26
|
+
__type?: "ActorError" | "RivetError";
|
|
27
|
+
group: string;
|
|
28
|
+
code: string;
|
|
29
|
+
message: string;
|
|
30
|
+
metadata?: unknown;
|
|
31
|
+
public?: boolean;
|
|
32
|
+
statusCode?: number;
|
|
33
|
+
actor?: ActorSpecifier;
|
|
34
|
+
}
|
|
35
|
+
interface BridgeRivetErrorPayload extends RivetErrorLike {
|
|
36
|
+
}
|
|
37
|
+
interface UserErrorOptions extends ErrorOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Machine readable code for this error. Useful for catching different types of
|
|
40
|
+
* errors in try-catch.
|
|
41
|
+
*/
|
|
42
|
+
code?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Additional metadata related to the error. Useful for understanding context
|
|
45
|
+
* about the error.
|
|
46
|
+
*/
|
|
47
|
+
metadata?: unknown;
|
|
48
|
+
}
|
|
49
|
+
declare function isRivetErrorLike(error: unknown): error is RivetError | DeconstructedError | RivetErrorLike;
|
|
50
|
+
declare class RivetError extends Error {
|
|
51
|
+
__type: "RivetError";
|
|
52
|
+
public: boolean;
|
|
53
|
+
metadata?: unknown;
|
|
54
|
+
statusCode: number;
|
|
55
|
+
actor?: ActorSpecifier;
|
|
56
|
+
readonly group: string;
|
|
57
|
+
readonly code: string;
|
|
58
|
+
static isRivetError(error: unknown): error is RivetError | DeconstructedError;
|
|
59
|
+
static isActorError(error: unknown): error is RivetError | DeconstructedError;
|
|
60
|
+
constructor(group: string, code: string, message: string, options?: RivetErrorOptions | unknown);
|
|
61
|
+
toString(): string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare class UserError extends RivetError {
|
|
65
|
+
constructor(message: string, options?: UserErrorOptions);
|
|
66
|
+
}
|
|
67
|
+
declare function toRivetError(error: unknown, fallback?: Partial<RivetErrorLike>): RivetError;
|
|
68
|
+
declare function encodeBridgeRivetError(error: RivetErrorLike): string;
|
|
69
|
+
declare function decodeBridgeRivetErrorPayload(value: string): BridgeRivetErrorPayload | undefined;
|
|
70
|
+
declare function decodeBridgeRivetError(value: string): RivetError | undefined;
|
|
71
|
+
declare function isRivetErrorCode(error: unknown, group: string, code: string): error is RivetError;
|
|
72
|
+
declare function internalError(message: string, options?: Partial<RivetErrorOptions> & {
|
|
73
|
+
group?: string;
|
|
74
|
+
code?: string;
|
|
75
|
+
}): RivetError;
|
|
76
|
+
declare function invalidEncoding(format?: string): RivetError;
|
|
77
|
+
declare function invalidRequest(error?: unknown): RivetError;
|
|
78
|
+
declare function actorNotFound(identifier?: string): RivetError;
|
|
79
|
+
declare function actorStopping(identifier?: string): RivetError;
|
|
80
|
+
interface ActorRestartingOptions {
|
|
81
|
+
phase?: "stopping" | "sleeping" | "waking" | "runner_shutdown";
|
|
82
|
+
retryAfterMs?: number;
|
|
83
|
+
}
|
|
84
|
+
declare function actorRestarting(opts?: ActorRestartingOptions): RivetError;
|
|
85
|
+
declare function forbiddenError(): RivetError;
|
|
86
|
+
declare function unsupportedFeature(feature: string): RivetError;
|
|
87
|
+
|
|
88
|
+
declare function assertUnreachable(x: never): never;
|
|
89
|
+
interface DeconstructedError {
|
|
90
|
+
__type: "ActorError";
|
|
91
|
+
statusCode: ContentfulStatusCode;
|
|
92
|
+
public: boolean;
|
|
93
|
+
group: string;
|
|
94
|
+
code: string;
|
|
95
|
+
message: string;
|
|
96
|
+
metadata?: unknown;
|
|
97
|
+
actor?: ActorSpecifier;
|
|
98
|
+
}
|
|
99
|
+
declare function stringifyError(error: unknown): string;
|
|
100
|
+
/** Generates a `Next` handler to pass to middleware in order to be able to call arbitrary middleware. */
|
|
101
|
+
declare function noopNext(): Next;
|
|
102
|
+
|
|
103
|
+
export { type ActorRestartingOptions as A, BRIDGE_RIVET_ERROR_PREFIX as B, INTERNAL_ERROR_CODE as I, RivetError as R, UserError as U, type UserErrorOptions as a, assertUnreachable as b, type ActorSpecifier as c, type BridgeRivetErrorPayload as d, INTERNAL_ERROR_DESCRIPTION as e, type InternalErrorMetadata as f, type RivetErrorLike as g, type RivetErrorOptions as h, USER_ERROR_CODE as i, actorNotFound as j, actorRestarting as k, actorStopping as l, decodeBridgeRivetError as m, noopNext as n, decodeBridgeRivetErrorPayload as o, encodeBridgeRivetError as p, forbiddenError as q, internalError as r, stringifyError as s, invalidEncoding as t, invalidRequest as u, isRivetErrorCode as v, isRivetErrorLike as w, toRivetError as x, unsupportedFeature as y };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Next } from 'hono';
|
|
2
|
+
import { ContentfulStatusCode } from 'hono/utils/http-status';
|
|
3
|
+
|
|
4
|
+
declare const INTERNAL_ERROR_CODE = "internal_error";
|
|
5
|
+
declare const INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
6
|
+
type InternalErrorMetadata = Record<string, never>;
|
|
7
|
+
declare const USER_ERROR_CODE = "user_error";
|
|
8
|
+
declare const BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
9
|
+
interface RivetErrorOptions extends ErrorOptions {
|
|
10
|
+
/** Error data can safely be serialized in a response to the client. */
|
|
11
|
+
public?: boolean;
|
|
12
|
+
/** Metadata associated with this error. */
|
|
13
|
+
metadata?: unknown;
|
|
14
|
+
/** Explicit HTTP status override for router responses. */
|
|
15
|
+
statusCode?: number;
|
|
16
|
+
/** Actor context associated with this error. */
|
|
17
|
+
actor?: ActorSpecifier;
|
|
18
|
+
}
|
|
19
|
+
/** Identifies the actor that was handling work when an error was produced. */
|
|
20
|
+
interface ActorSpecifier {
|
|
21
|
+
actorId: string;
|
|
22
|
+
generation: number;
|
|
23
|
+
key?: string;
|
|
24
|
+
}
|
|
25
|
+
interface RivetErrorLike {
|
|
26
|
+
__type?: "ActorError" | "RivetError";
|
|
27
|
+
group: string;
|
|
28
|
+
code: string;
|
|
29
|
+
message: string;
|
|
30
|
+
metadata?: unknown;
|
|
31
|
+
public?: boolean;
|
|
32
|
+
statusCode?: number;
|
|
33
|
+
actor?: ActorSpecifier;
|
|
34
|
+
}
|
|
35
|
+
interface BridgeRivetErrorPayload extends RivetErrorLike {
|
|
36
|
+
}
|
|
37
|
+
interface UserErrorOptions extends ErrorOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Machine readable code for this error. Useful for catching different types of
|
|
40
|
+
* errors in try-catch.
|
|
41
|
+
*/
|
|
42
|
+
code?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Additional metadata related to the error. Useful for understanding context
|
|
45
|
+
* about the error.
|
|
46
|
+
*/
|
|
47
|
+
metadata?: unknown;
|
|
48
|
+
}
|
|
49
|
+
declare function isRivetErrorLike(error: unknown): error is RivetError | DeconstructedError | RivetErrorLike;
|
|
50
|
+
declare class RivetError extends Error {
|
|
51
|
+
__type: "RivetError";
|
|
52
|
+
public: boolean;
|
|
53
|
+
metadata?: unknown;
|
|
54
|
+
statusCode: number;
|
|
55
|
+
actor?: ActorSpecifier;
|
|
56
|
+
readonly group: string;
|
|
57
|
+
readonly code: string;
|
|
58
|
+
static isRivetError(error: unknown): error is RivetError | DeconstructedError;
|
|
59
|
+
static isActorError(error: unknown): error is RivetError | DeconstructedError;
|
|
60
|
+
constructor(group: string, code: string, message: string, options?: RivetErrorOptions | unknown);
|
|
61
|
+
toString(): string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare class UserError extends RivetError {
|
|
65
|
+
constructor(message: string, options?: UserErrorOptions);
|
|
66
|
+
}
|
|
67
|
+
declare function toRivetError(error: unknown, fallback?: Partial<RivetErrorLike>): RivetError;
|
|
68
|
+
declare function encodeBridgeRivetError(error: RivetErrorLike): string;
|
|
69
|
+
declare function decodeBridgeRivetErrorPayload(value: string): BridgeRivetErrorPayload | undefined;
|
|
70
|
+
declare function decodeBridgeRivetError(value: string): RivetError | undefined;
|
|
71
|
+
declare function isRivetErrorCode(error: unknown, group: string, code: string): error is RivetError;
|
|
72
|
+
declare function internalError(message: string, options?: Partial<RivetErrorOptions> & {
|
|
73
|
+
group?: string;
|
|
74
|
+
code?: string;
|
|
75
|
+
}): RivetError;
|
|
76
|
+
declare function invalidEncoding(format?: string): RivetError;
|
|
77
|
+
declare function invalidRequest(error?: unknown): RivetError;
|
|
78
|
+
declare function actorNotFound(identifier?: string): RivetError;
|
|
79
|
+
declare function actorStopping(identifier?: string): RivetError;
|
|
80
|
+
interface ActorRestartingOptions {
|
|
81
|
+
phase?: "stopping" | "sleeping" | "waking" | "runner_shutdown";
|
|
82
|
+
retryAfterMs?: number;
|
|
83
|
+
}
|
|
84
|
+
declare function actorRestarting(opts?: ActorRestartingOptions): RivetError;
|
|
85
|
+
declare function forbiddenError(): RivetError;
|
|
86
|
+
declare function unsupportedFeature(feature: string): RivetError;
|
|
87
|
+
|
|
88
|
+
declare function assertUnreachable(x: never): never;
|
|
89
|
+
interface DeconstructedError {
|
|
90
|
+
__type: "ActorError";
|
|
91
|
+
statusCode: ContentfulStatusCode;
|
|
92
|
+
public: boolean;
|
|
93
|
+
group: string;
|
|
94
|
+
code: string;
|
|
95
|
+
message: string;
|
|
96
|
+
metadata?: unknown;
|
|
97
|
+
actor?: ActorSpecifier;
|
|
98
|
+
}
|
|
99
|
+
declare function stringifyError(error: unknown): string;
|
|
100
|
+
/** Generates a `Next` handler to pass to middleware in order to be able to call arbitrary middleware. */
|
|
101
|
+
declare function noopNext(): Next;
|
|
102
|
+
|
|
103
|
+
export { type ActorRestartingOptions as A, BRIDGE_RIVET_ERROR_PREFIX as B, INTERNAL_ERROR_CODE as I, RivetError as R, UserError as U, type UserErrorOptions as a, assertUnreachable as b, type ActorSpecifier as c, type BridgeRivetErrorPayload as d, INTERNAL_ERROR_DESCRIPTION as e, type InternalErrorMetadata as f, type RivetErrorLike as g, type RivetErrorOptions as h, USER_ERROR_CODE as i, actorNotFound as j, actorRestarting as k, actorStopping as l, decodeBridgeRivetError as m, noopNext as n, decodeBridgeRivetErrorPayload as o, encodeBridgeRivetError as p, forbiddenError as q, internalError as r, stringifyError as s, invalidEncoding as t, invalidRequest as u, isRivetErrorCode as v, isRivetErrorLike as w, toRivetError as x, unsupportedFeature as y };
|
package/dist/tsup/utils.cjs
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
var
|
|
21
|
-
require('./chunk-
|
|
20
|
+
var _chunkX6HIFXNKcjs = require('./chunk-X6HIFXNK.cjs');
|
|
21
|
+
require('./chunk-63WNTDRC.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -38,5 +38,5 @@ require('./chunk-V3QNBJ7N.cjs');
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
exports.EXTRA_ERROR_LOG =
|
|
41
|
+
exports.EXTRA_ERROR_LOG = _chunkX6HIFXNKcjs.EXTRA_ERROR_LOG; exports.SinglePromiseQueue = _chunkX6HIFXNKcjs.SinglePromiseQueue; exports.VERSION = _chunkX6HIFXNKcjs.VERSION; exports.arrayBuffersEqual = _chunkX6HIFXNKcjs.arrayBuffersEqual; exports.assertUnreachable = _chunkX6HIFXNKcjs.assertUnreachable; exports.bufferToArrayBuffer = _chunkX6HIFXNKcjs.bufferToArrayBuffer; exports.combineUrlPath = _chunkX6HIFXNKcjs.combineUrlPath; exports.dbg = _chunkX6HIFXNKcjs.dbg; exports.detectRuntime = _chunkX6HIFXNKcjs.detectRuntime; exports.getEnvUniversal = _chunkX6HIFXNKcjs.getEnvUniversal; exports.httpUserAgent = _chunkX6HIFXNKcjs.httpUserAgent; exports.interval = _chunkX6HIFXNKcjs.interval; exports.joinSignals = _chunkX6HIFXNKcjs.joinSignals; exports.promiseWithResolvers = _chunkX6HIFXNKcjs.promiseWithResolvers; exports.setLongTimeout = _chunkX6HIFXNKcjs.setLongTimeout; exports.sleep = _chunkX6HIFXNKcjs.sleep; exports.stringifyError = _chunkX6HIFXNKcjs.stringifyError; exports.toUint8Array = _chunkX6HIFXNKcjs.toUint8Array;
|
|
42
42
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/tsup/utils.d.cts
CHANGED
package/dist/tsup/utils.d.ts
CHANGED
package/dist/tsup/utils.js
CHANGED