rivetkit 0.0.0-sqlite-profiling-compat.4a9a623 → 0.0.0-sqlite-sync-3-0-0-release.14341d0
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 +1317 -765
- package/dist/browser/client.js +1433 -692
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2042 -228
- 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 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +3 -2367
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -2277
- package/dist/tsup/agent-os/index.d.ts +1 -2277
- package/dist/tsup/agent-os/index.js +3 -2367
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-AGDY6TKH.js → chunk-2EQ2WCO7.js} +1054 -364
- package/dist/tsup/chunk-2EQ2WCO7.js.map +1 -0
- package/dist/tsup/{chunk-7QKCGUTJ.cjs → chunk-4H2LT2WB.cjs} +444 -29
- package/dist/tsup/chunk-4H2LT2WB.cjs.map +1 -0
- package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
- package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
- package/dist/tsup/{chunk-QAVN4QNO.cjs → chunk-6WYQ3NJI.cjs} +7 -7
- package/dist/tsup/chunk-6WYQ3NJI.cjs.map +1 -0
- package/dist/tsup/{chunk-75UE45DE.js → chunk-6ZJX3KXW.js} +436 -21
- package/dist/tsup/chunk-6ZJX3KXW.js.map +1 -0
- package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-RIT7N3TX.js → chunk-AIGW2SKA.js} +50 -3
- package/dist/tsup/chunk-AIGW2SKA.js.map +1 -0
- package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
- package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
- package/dist/tsup/{chunk-2CICCOBL.cjs → chunk-HU4F7H3F.cjs} +52 -5
- package/dist/tsup/chunk-HU4F7H3F.cjs.map +1 -0
- package/dist/tsup/{chunk-4PX3ZKJR.js → chunk-JNJEWQZL.js} +3 -3
- package/dist/tsup/chunk-JNJEWQZL.js.map +1 -0
- package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
- package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
- package/dist/tsup/{chunk-NHUTYWKU.cjs → chunk-NE5CUQRN.cjs} +1173 -483
- package/dist/tsup/chunk-NE5CUQRN.cjs.map +1 -0
- package/dist/tsup/{chunk-IICIOTML.js → chunk-OX5MX7TO.js} +2 -2
- package/dist/tsup/{chunk-ND567FR5.cjs → chunk-PSIBTOAR.cjs} +3 -3
- package/dist/tsup/chunk-PSIBTOAR.cjs.map +1 -0
- package/dist/tsup/chunk-PW6FYEIV.cjs +14 -0
- package/dist/tsup/chunk-PW6FYEIV.cjs.map +1 -0
- package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-RTWH3AX3.cjs} +18 -10
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/chunk-SLICBKAU.js +14 -0
- package/dist/tsup/chunk-SLICBKAU.js.map +1 -0
- package/dist/tsup/{chunk-XFYEVYHG.js → chunk-WCVYMFWJ.js} +16 -9
- package/dist/tsup/chunk-WCVYMFWJ.js.map +1 -0
- package/dist/tsup/chunk-WX3JS4XU.cjs +243 -0
- package/dist/tsup/chunk-WX3JS4XU.cjs.map +1 -0
- package/dist/tsup/chunk-X32L7FDD.js +243 -0
- package/dist/tsup/chunk-X32L7FDD.js.map +1 -0
- package/dist/tsup/{chunk-2WMYYG4R.cjs → chunk-XAY2HIZN.cjs} +18 -11
- package/dist/tsup/chunk-XAY2HIZN.cjs.map +1 -0
- package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
- package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +32 -6
- package/dist/tsup/client/mod.d.ts +32 -6
- package/dist/tsup/client/mod.js +7 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-BR1Nn0QQ.d.ts → config-B4erdavw.d.ts} +571 -65
- package/dist/tsup/{config-B0LNDrLY.d.ts → config-BfG1qpYz.d.cts} +80 -14
- package/dist/tsup/{config-B0LNDrLY.d.cts → config-BfG1qpYz.d.ts} +80 -14
- package/dist/tsup/{config-tCvkwzyN.d.cts → config-DK144OAw.d.cts} +571 -65
- package/dist/tsup/{context-oc9zhA3x.d.ts → context-Cvnf3BRe.d.cts} +3 -2
- package/dist/tsup/{context-D4WDwf9m.d.cts → context-Oxi6YWcG.d.ts} +3 -2
- package/dist/tsup/db/drizzle.cjs +127 -67
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -4
- package/dist/tsup/db/drizzle.d.ts +8 -4
- package/dist/tsup/db/drizzle.js +127 -67
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +6 -126
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +8 -4
- package/dist/tsup/db/mod.d.ts +8 -4
- package/dist/tsup/db/mod.js +5 -125
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.cjs.map +1 -1
- package/dist/tsup/dynamic/mod.d.cts +6 -4
- package/dist/tsup/dynamic/mod.d.ts +6 -4
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +26 -136
- package/dist/tsup/inspector/mod.d.ts +26 -136
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector/workflow.cjs +21 -0
- package/dist/tsup/inspector/workflow.cjs.map +1 -0
- package/dist/tsup/inspector/workflow.d.cts +144 -0
- package/dist/tsup/inspector/workflow.d.ts +144 -0
- package/dist/tsup/inspector/workflow.js +21 -0
- package/dist/tsup/inspector/workflow.js.map +1 -0
- package/dist/tsup/inspector-tab/mod.cjs +2 -13
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
- package/dist/tsup/inspector-tab/mod.d.cts +9 -17
- package/dist/tsup/inspector-tab/mod.d.ts +9 -17
- package/dist/tsup/inspector-tab/mod.js +1 -12
- package/dist/tsup/inspector-tab/mod.js.map +1 -1
- package/dist/tsup/mod.cjs +2728 -611
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +9 -7
- package/dist/tsup/mod.d.ts +9 -7
- package/dist/tsup/mod.js +2645 -528
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +19 -17
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +6 -4
- package/dist/tsup/test/mod.d.ts +6 -4
- package/dist/tsup/test/mod.js +18 -16
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/{utils-CqDnC_PS.d.cts → utils-3rsE0JvI.d.cts} +25 -2
- package/dist/tsup/{utils-CqDnC_PS.d.ts → utils-3rsE0JvI.d.ts} +25 -2
- package/dist/tsup/utils-C1O-SklO.d.ts +162 -0
- package/dist/tsup/utils-C6b0aYUM.d.cts +162 -0
- package/dist/tsup/utils.cjs +7 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +4 -147
- package/dist/tsup/utils.d.ts +4 -147
- package/dist/tsup/utils.js +6 -2
- package/dist/tsup/workflow/mod.cjs +260 -200
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +8 -6
- package/dist/tsup/workflow/mod.d.ts +8 -6
- package/dist/tsup/workflow/mod.js +249 -189
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +34 -14
- package/src/actor/actions.ts +155 -0
- package/src/actor/config.ts +403 -43
- package/src/actor/definition.ts +26 -7
- package/src/actor/errors.ts +87 -5
- package/src/actor/keys.ts +86 -0
- package/src/actor/mod.ts +15 -1
- package/src/actor/tracing.ts +28 -0
- package/src/agent-os/index.ts +5 -65
- package/src/client/actor-common.ts +8 -15
- package/src/client/actor-conn.ts +178 -25
- package/src/client/actor-handle.ts +180 -42
- package/src/client/actor-query.ts +8 -1
- package/src/client/auth.ts +37 -0
- package/src/client/client.ts +89 -21
- package/src/client/config.ts +27 -2
- package/src/client/errors.ts +2 -1
- package/src/client/lifecycle-errors.ts +29 -1
- package/src/client/mod.ts +9 -0
- package/src/client/outbound-telemetry.ts +66 -0
- package/src/client/query.ts +2 -0
- package/src/client/queue.ts +3 -0
- package/src/client/raw-utils.ts +37 -8
- package/src/client/resolve-gateway-target.ts +2 -0
- package/src/client/retry-budget.ts +78 -0
- package/src/client/token-provider.ts +93 -0
- package/src/client/utils.ts +16 -2
- package/src/common/actor-router-consts.ts +5 -0
- package/src/common/actor-telemetry-context.ts +19 -0
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/bare/transport/v1.ts +36 -0
- package/src/common/database/config.ts +108 -15
- package/src/common/database/mod.ts +247 -76
- package/src/common/database/native-database.ts +433 -23
- package/src/common/database/shared.ts +24 -0
- package/src/common/encoding.ts +31 -21
- package/src/common/fetch-like.ts +63 -0
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +14 -8
- package/src/common/otel-context.ts +99 -0
- package/src/common/router.ts +1 -1
- package/src/common/utils.ts +7 -19
- package/src/db/drizzle.ts +182 -80
- package/src/db/mod.ts +2 -0
- package/src/dynamic/isolate-runtime.ts +0 -2
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-http-client.ts +29 -20
- package/src/engine-client/actor-websocket-client.ts +6 -3
- package/src/engine-client/api-endpoints.ts +72 -14
- package/src/engine-client/driver.ts +8 -15
- package/src/engine-client/mod.ts +248 -112
- package/src/inspector/client.browser.ts +134 -16
- package/src/inspector/mod.ts +1 -1
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +1 -15
- package/src/registry/config/envoy.ts +2 -18
- package/src/registry/config/index.ts +54 -61
- package/src/registry/index.ts +324 -21
- package/src/registry/napi-runtime.ts +583 -39
- package/src/registry/native-http.ts +225 -0
- package/src/registry/native.ts +1365 -414
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.ts +372 -7
- package/src/registry/wasm-runtime.ts +490 -21
- package/src/registry/write-through-proxy.ts +101 -0
- package/src/test/mod.ts +1 -19
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/env-vars.ts +15 -6
- package/src/utils/node.ts +44 -28
- package/src/utils.ts +3 -0
- package/src/workflow/context.ts +9 -27
- package/src/workflow/driver.ts +253 -116
- package/src/workflow/inspector.ts +23 -24
- package/src/workflow/mod.ts +50 -72
- package/dist/tsup/chunk-2CICCOBL.cjs.map +0 -1
- package/dist/tsup/chunk-2WMYYG4R.cjs.map +0 -1
- package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
- package/dist/tsup/chunk-4PX3ZKJR.js.map +0 -1
- package/dist/tsup/chunk-75UE45DE.js.map +0 -1
- package/dist/tsup/chunk-7QKCGUTJ.cjs.map +0 -1
- package/dist/tsup/chunk-AGDY6TKH.js.map +0 -1
- package/dist/tsup/chunk-HXUEHHJF.js.map +0 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
- package/dist/tsup/chunk-ND567FR5.cjs.map +0 -1
- package/dist/tsup/chunk-NHUTYWKU.cjs.map +0 -1
- package/dist/tsup/chunk-QAVN4QNO.cjs.map +0 -1
- package/dist/tsup/chunk-RIT7N3TX.js.map +0 -1
- package/dist/tsup/chunk-RV5MAFDT.cjs +0 -382
- package/dist/tsup/chunk-RV5MAFDT.cjs.map +0 -1
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
- package/dist/tsup/chunk-XFYEVYHG.js.map +0 -1
- package/dist/tsup/chunk-XHGDS3DZ.js +0 -382
- package/dist/tsup/chunk-XHGDS3DZ.js.map +0 -1
- package/dist/tsup/chunk-XIX5DOZN.js.map +0 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +0 -1
- package/dist/tsup/chunk-ZZ3WBRPD.js.map +0 -1
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2484
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/agent-os/actor/cron.ts +0 -84
- package/src/agent-os/actor/db.ts +0 -54
- package/src/agent-os/actor/filesystem.ts +0 -131
- package/src/agent-os/actor/index.ts +0 -285
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -190
- package/src/agent-os/actor/process.ts +0 -177
- package/src/agent-os/actor/session.ts +0 -518
- package/src/agent-os/actor/shell.ts +0 -60
- package/src/agent-os/config.ts +0 -79
- package/src/agent-os/fs/database-vfs.ts +0 -624
- package/src/agent-os/types.ts +0 -148
- package/src/client/test.ts +0 -44
- package/src/common/database/mod.test.ts +0 -137
- package/src/common/database/native-database.test.ts +0 -211
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/drivers/engine/actor-driver.ts +0 -2473
- package/src/registry/process-metrics.ts +0 -250
- package/src/registry/runtime.test.ts +0 -50
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils.test.ts +0 -34
- /package/dist/tsup/{chunk-IICIOTML.js.map → chunk-OX5MX7TO.js.map} +0 -0
package/src/registry/index.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { isLocalEngineEndpoint } from "@/common/engine";
|
|
2
|
+
import { isResponseLike } from "@/common/fetch-like";
|
|
3
|
+
import { configureBaseLogger } from "@/common/log";
|
|
2
4
|
import { configureServerlessPool } from "@/serverless/configure";
|
|
3
5
|
import { VERSION } from "@/utils";
|
|
4
6
|
import {
|
|
7
|
+
getNodeEnv,
|
|
8
|
+
getRivetEnvoyVersion,
|
|
5
9
|
getRivetkitPublicDir,
|
|
6
10
|
getRivetkitRuntimeMode,
|
|
7
11
|
parsePortEnv,
|
|
@@ -14,10 +18,30 @@ import {
|
|
|
14
18
|
} from "./config";
|
|
15
19
|
import { logger } from "./log";
|
|
16
20
|
import { buildConfiguredRegistry } from "./native";
|
|
17
|
-
import
|
|
21
|
+
import { convertNativeHttpResponse } from "./native-http";
|
|
22
|
+
import type {
|
|
23
|
+
CoreRuntime,
|
|
24
|
+
RuntimeApplicationFetch,
|
|
25
|
+
RuntimeHttpResponseBodyStream,
|
|
26
|
+
RuntimeServerlessResponseHead,
|
|
27
|
+
} from "./runtime";
|
|
18
28
|
|
|
19
29
|
type ShutdownSignal = "SIGINT" | "SIGTERM";
|
|
20
30
|
|
|
31
|
+
const REGISTRY_READY_TIMEOUT_MS = 30_000;
|
|
32
|
+
// A managed Engine restart can wait for the old process to release storage and
|
|
33
|
+
// for its worker lease to expire before the replacement can register.
|
|
34
|
+
const LOCAL_ENGINE_READY_TIMEOUT_MS = 60_000;
|
|
35
|
+
// Core gives local actors three seconds to drain and acknowledge their stopped
|
|
36
|
+
// reports. Leave time to close the node connection after that, while staying
|
|
37
|
+
// below the five-second force-kill ceiling used by tsx watch.
|
|
38
|
+
const LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS = 4_000;
|
|
39
|
+
|
|
40
|
+
// Serverless is disabled for v3; keep the implementation for a later release.
|
|
41
|
+
function rejectServerless(): void {
|
|
42
|
+
throw new Error("serverless is disabled in this version");
|
|
43
|
+
}
|
|
44
|
+
|
|
21
45
|
function signalExitCode(signal: ShutdownSignal): number {
|
|
22
46
|
switch (signal) {
|
|
23
47
|
case "SIGINT":
|
|
@@ -34,6 +58,65 @@ function finishShutdownSignal(signal: ShutdownSignal): void {
|
|
|
34
58
|
process.kill(process.pid, signal);
|
|
35
59
|
}
|
|
36
60
|
|
|
61
|
+
function createApplicationFetch(
|
|
62
|
+
application: RegistryApplication,
|
|
63
|
+
runtime: CoreRuntime,
|
|
64
|
+
): RuntimeApplicationFetch {
|
|
65
|
+
return async (
|
|
66
|
+
request,
|
|
67
|
+
responseBodyStream?: RuntimeHttpResponseBodyStream,
|
|
68
|
+
) => {
|
|
69
|
+
const method = request.method.toUpperCase();
|
|
70
|
+
const body =
|
|
71
|
+
method === "GET" || method === "HEAD" || request.body.length === 0
|
|
72
|
+
? undefined
|
|
73
|
+
: Uint8Array.from(request.body).buffer;
|
|
74
|
+
const abortController = new AbortController();
|
|
75
|
+
if (request.cancelToken) {
|
|
76
|
+
if (runtime.cancellationTokenAborted(request.cancelToken)) {
|
|
77
|
+
abortController.abort();
|
|
78
|
+
} else {
|
|
79
|
+
runtime.onCancellationTokenCancelled(request.cancelToken, () =>
|
|
80
|
+
abortController.abort(),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const response = await application.fetch(
|
|
85
|
+
new Request(request.url, {
|
|
86
|
+
method,
|
|
87
|
+
headers: request.headers,
|
|
88
|
+
body,
|
|
89
|
+
signal: abortController.signal,
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
if (!isResponseLike(response)) {
|
|
93
|
+
throw new TypeError(
|
|
94
|
+
"registry.listen() application fetch must return a Response",
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
const conversion = await convertNativeHttpResponse(
|
|
98
|
+
response,
|
|
99
|
+
responseBodyStream,
|
|
100
|
+
);
|
|
101
|
+
if (conversion.bodyCompletion) {
|
|
102
|
+
void conversion.bodyCompletion.catch((error) => {
|
|
103
|
+
logger().error({
|
|
104
|
+
msg: "application response stream failed",
|
|
105
|
+
error,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
status: conversion.response.status ?? response.status,
|
|
111
|
+
headers:
|
|
112
|
+
conversion.response.headers ??
|
|
113
|
+
Object.fromEntries(response.headers.entries()),
|
|
114
|
+
body: conversion.response.body,
|
|
115
|
+
stream: conversion.response.stream,
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
37
120
|
export type FetchHandler = (
|
|
38
121
|
request: Request,
|
|
39
122
|
...args: any
|
|
@@ -43,6 +126,17 @@ export interface ServerlessHandler {
|
|
|
43
126
|
fetch: FetchHandler;
|
|
44
127
|
}
|
|
45
128
|
|
|
129
|
+
export interface RegistryApplication {
|
|
130
|
+
fetch: FetchHandler;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface RegistryListenOptions {
|
|
134
|
+
port?: number;
|
|
135
|
+
host?: string;
|
|
136
|
+
publicDir?: string;
|
|
137
|
+
application?: RegistryApplication;
|
|
138
|
+
}
|
|
139
|
+
|
|
46
140
|
export interface RegistryRoutes {
|
|
47
141
|
health(): Promise<Response>;
|
|
48
142
|
metadata(): Promise<Response>;
|
|
@@ -72,8 +166,11 @@ export class Registry<A extends RegistryActors> {
|
|
|
72
166
|
}
|
|
73
167
|
|
|
74
168
|
#runtimeServePromise?: Promise<void>;
|
|
169
|
+
#runtimeServeLifecyclePromise?: Promise<void>;
|
|
170
|
+
#runtimeReadyPromise?: Promise<void>;
|
|
75
171
|
#runtimeServeConfiguredPromise?: ReturnType<typeof buildConfiguredRegistry>;
|
|
76
172
|
#runtimeServerlessPromise?: ReturnType<typeof buildConfiguredRegistry>;
|
|
173
|
+
#applicationListenerPromise?: Promise<void>;
|
|
77
174
|
#configureServerlessPoolPromise?: Promise<void>;
|
|
78
175
|
#welcomePrinted = false;
|
|
79
176
|
#shutdownInstalled = false;
|
|
@@ -82,6 +179,9 @@ export class Registry<A extends RegistryActors> {
|
|
|
82
179
|
|
|
83
180
|
constructor(config: RegistryConfigInput<A>, deps?: Partial<RegistryDeps>) {
|
|
84
181
|
this.#config = config;
|
|
182
|
+
if (config.logging?.baseLogger) {
|
|
183
|
+
configureBaseLogger(config.logging.baseLogger);
|
|
184
|
+
}
|
|
85
185
|
this.#buildConfiguredRegistry =
|
|
86
186
|
deps?.buildConfiguredRegistry ?? buildConfiguredRegistry;
|
|
87
187
|
this.routes = {
|
|
@@ -102,6 +202,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
102
202
|
config: RegistryConfig,
|
|
103
203
|
): Promise<void> | undefined {
|
|
104
204
|
if (!config.configurePool) return undefined;
|
|
205
|
+
rejectServerless();
|
|
105
206
|
|
|
106
207
|
if (!this.#configureServerlessPoolPromise) {
|
|
107
208
|
this.#configureServerlessPoolPromise = configureServerlessPool(
|
|
@@ -127,6 +228,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
127
228
|
* ```
|
|
128
229
|
*/
|
|
129
230
|
public async handler(request: Request): Promise<Response> {
|
|
231
|
+
rejectServerless();
|
|
130
232
|
const config = this.parseConfig();
|
|
131
233
|
this.#printWelcome(config, "serverless");
|
|
132
234
|
|
|
@@ -325,6 +427,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
325
427
|
* ```
|
|
326
428
|
*/
|
|
327
429
|
public serve(): ServerlessHandler {
|
|
430
|
+
rejectServerless();
|
|
328
431
|
return {
|
|
329
432
|
fetch: (request) => this.handler(request),
|
|
330
433
|
};
|
|
@@ -340,22 +443,72 @@ export class Registry<A extends RegistryActors> {
|
|
|
340
443
|
* @param opts.host Address to bind. Defaults to `0.0.0.0`.
|
|
341
444
|
* @param opts.publicDir If set, serves static files from this directory
|
|
342
445
|
* as a fallback below the framework routes.
|
|
446
|
+
* @param opts.application If set, handles requests that do not match a
|
|
447
|
+
* framework route.
|
|
343
448
|
*
|
|
344
449
|
* @example
|
|
345
450
|
* ```ts
|
|
346
451
|
* await registry.listen();
|
|
347
|
-
* await registry.listen({
|
|
452
|
+
* await registry.listen({ application: app });
|
|
348
453
|
* ```
|
|
349
454
|
*/
|
|
350
|
-
public async listen(
|
|
351
|
-
opts
|
|
352
|
-
|
|
455
|
+
public async listen(opts: RegistryListenOptions = {}): Promise<void> {
|
|
456
|
+
if (!opts.application) {
|
|
457
|
+
rejectServerless();
|
|
458
|
+
}
|
|
353
459
|
const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3000;
|
|
354
460
|
const publicDir = opts.publicDir ?? getRivetkitPublicDir();
|
|
355
461
|
const config = this.parseConfig();
|
|
356
462
|
|
|
463
|
+
if (opts.application && getRivetkitRuntimeMode() !== "serverless") {
|
|
464
|
+
if (config.runtime === "wasm") {
|
|
465
|
+
throw new Error(
|
|
466
|
+
"registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly",
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
this.#installSignalHandlers(config);
|
|
470
|
+
this.#printWelcome(config, "serverful", {
|
|
471
|
+
port,
|
|
472
|
+
host: opts.host,
|
|
473
|
+
publicDir,
|
|
474
|
+
});
|
|
475
|
+
this.#startEnvoy(config, true);
|
|
476
|
+
const readyPromise = this.startAndWait();
|
|
477
|
+
const configuredRegistryPromise =
|
|
478
|
+
this.#runtimeServeConfiguredPromise;
|
|
479
|
+
if (!configuredRegistryPromise) {
|
|
480
|
+
throw new Error("registry envoy startup did not initialize");
|
|
481
|
+
}
|
|
482
|
+
const { runtime, registry, serveConfig } =
|
|
483
|
+
await configuredRegistryPromise;
|
|
484
|
+
const application = createApplicationFetch(
|
|
485
|
+
opts.application,
|
|
486
|
+
runtime,
|
|
487
|
+
);
|
|
488
|
+
await readyPromise;
|
|
489
|
+
const listenerPromise = runtime.serveApplicationListener(
|
|
490
|
+
registry,
|
|
491
|
+
{
|
|
492
|
+
port,
|
|
493
|
+
host: opts.host,
|
|
494
|
+
publicDir,
|
|
495
|
+
application,
|
|
496
|
+
},
|
|
497
|
+
serveConfig,
|
|
498
|
+
);
|
|
499
|
+
this.#applicationListenerPromise = listenerPromise;
|
|
500
|
+
const serveLifecyclePromise = this.#runtimeServeLifecyclePromise;
|
|
501
|
+
if (!serveLifecyclePromise) {
|
|
502
|
+
throw new Error(
|
|
503
|
+
"registry envoy serve lifecycle did not initialize",
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
await Promise.all([listenerPromise, serveLifecyclePromise]);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
|
|
357
510
|
// Cache on both promise fields so the shutdown drain sees Mode A and B.
|
|
358
|
-
const configuredRegistryPromise = buildConfiguredRegistry(config);
|
|
511
|
+
const configuredRegistryPromise = this.#buildConfiguredRegistry(config);
|
|
359
512
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
360
513
|
this.#runtimeServerlessPromise = configuredRegistryPromise;
|
|
361
514
|
this.#installSignalHandlers(config);
|
|
@@ -371,9 +524,17 @@ export class Registry<A extends RegistryActors> {
|
|
|
371
524
|
|
|
372
525
|
const { runtime, registry, serveConfig } =
|
|
373
526
|
await configuredRegistryPromise;
|
|
527
|
+
const application = opts.application
|
|
528
|
+
? createApplicationFetch(opts.application, runtime)
|
|
529
|
+
: undefined;
|
|
374
530
|
await runtime.serveListener(
|
|
375
531
|
registry,
|
|
376
|
-
{
|
|
532
|
+
{
|
|
533
|
+
port,
|
|
534
|
+
host: opts.host,
|
|
535
|
+
publicDir,
|
|
536
|
+
application,
|
|
537
|
+
},
|
|
377
538
|
serveConfig,
|
|
378
539
|
);
|
|
379
540
|
}
|
|
@@ -411,6 +572,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
411
572
|
* Returns serverless metadata suitable for mounting in a user-owned router.
|
|
412
573
|
*/
|
|
413
574
|
async #metadataRoute(): Promise<Response> {
|
|
575
|
+
rejectServerless();
|
|
414
576
|
const configured = await this.#activeConfiguredRegistry();
|
|
415
577
|
if (!configured) {
|
|
416
578
|
return new Response("registry not started\n", {
|
|
@@ -483,19 +645,53 @@ export class Registry<A extends RegistryActors> {
|
|
|
483
645
|
*/
|
|
484
646
|
#startEnvoy(config: RegistryConfig, printWelcome: boolean) {
|
|
485
647
|
if (!this.#runtimeServePromise) {
|
|
648
|
+
const configuredEnvoyVersion = this.#config.node?.version;
|
|
649
|
+
const envoyVersionSource =
|
|
650
|
+
configuredEnvoyVersion !== undefined
|
|
651
|
+
? "config"
|
|
652
|
+
: getRivetEnvoyVersion() !== undefined
|
|
653
|
+
? "environment"
|
|
654
|
+
: "default";
|
|
655
|
+
|
|
656
|
+
logger().info({
|
|
657
|
+
msg: "starting rivetkit envoy",
|
|
658
|
+
rivetkitVersion: VERSION,
|
|
659
|
+
envoyVersion: config.node.version,
|
|
660
|
+
envoyVersionSource,
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
if (
|
|
664
|
+
envoyVersionSource === "default" &&
|
|
665
|
+
getNodeEnv() === "production"
|
|
666
|
+
) {
|
|
667
|
+
logger().error({
|
|
668
|
+
msg: "node version defaulted because neither config.node.version nor RIVET_NODE_VERSION is set; actors will not drain automatically across deploys. See https://rivet.dev/docs/actors/versions",
|
|
669
|
+
envoyVersion: config.node.version,
|
|
670
|
+
envoyVersionSource,
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
|
|
486
674
|
const configuredRegistryPromise =
|
|
487
675
|
this.#buildConfiguredRegistry(config);
|
|
488
676
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
489
|
-
this.#
|
|
490
|
-
|
|
677
|
+
this.#runtimeServeLifecyclePromise = configuredRegistryPromise.then(
|
|
678
|
+
async ({ runtime, registry, serveConfig }) => {
|
|
491
679
|
await runtime.serveRegistry(registry, serveConfig);
|
|
492
|
-
}
|
|
493
|
-
|
|
680
|
+
},
|
|
681
|
+
);
|
|
682
|
+
this.#runtimeServePromise =
|
|
683
|
+
this.#runtimeServeLifecyclePromise.catch((error) => {
|
|
494
684
|
// Always-attached catch so the stored promise never leaves a
|
|
495
685
|
// rejection unhandled. Downstream awaits (e.g. #runShutdown's
|
|
496
686
|
// Promise.race) attach their own catches and still observe
|
|
497
687
|
// resolution via the race.
|
|
498
|
-
logger().
|
|
688
|
+
logger().error({ error }, "runtime registry serve errored");
|
|
689
|
+
if (
|
|
690
|
+
typeof process !== "undefined" &&
|
|
691
|
+
typeof process.exit === "function"
|
|
692
|
+
) {
|
|
693
|
+
process.exit(1);
|
|
694
|
+
}
|
|
499
695
|
});
|
|
500
696
|
// Install signal handlers once an envoy lifecycle has begun. Only
|
|
501
697
|
// Mode A ever reaches here. Mode B (handler(request)) intentionally
|
|
@@ -543,7 +739,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
543
739
|
finishShutdownSignal(signal);
|
|
544
740
|
return;
|
|
545
741
|
}
|
|
546
|
-
this.#shutdownInFlight = this.#drain(config)
|
|
742
|
+
this.#shutdownInFlight = this.#drain(config, true)
|
|
547
743
|
.catch((err) => {
|
|
548
744
|
logger().warn({ err }, "shutdown error");
|
|
549
745
|
})
|
|
@@ -586,17 +782,28 @@ export class Registry<A extends RegistryActors> {
|
|
|
586
782
|
return this.#shutdownInFlight;
|
|
587
783
|
}
|
|
588
784
|
|
|
589
|
-
async #drain(config: RegistryConfig): Promise<void> {
|
|
785
|
+
async #drain(config: RegistryConfig, signalDriven = false): Promise<void> {
|
|
590
786
|
const modeAPromise = this.#runtimeServeConfiguredPromise;
|
|
591
787
|
const modeBPromise = this.#runtimeServerlessPromise;
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
788
|
+
const runtimes = new Set<CoreRuntime>();
|
|
789
|
+
|
|
790
|
+
const localDevSignal =
|
|
791
|
+
signalDriven &&
|
|
792
|
+
getNodeEnv() !== "production" &&
|
|
793
|
+
config.engineSpawn &&
|
|
794
|
+
config.endpoint !== undefined &&
|
|
795
|
+
isLocalEngineEndpoint(config.endpoint);
|
|
796
|
+
let gracePeriodMs = config.shutdown?.gracePeriodMs;
|
|
797
|
+
if (gracePeriodMs === undefined) {
|
|
798
|
+
gracePeriodMs = localDevSignal
|
|
799
|
+
? LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS
|
|
800
|
+
: ((await this.#actorStopThresholdMs(
|
|
801
|
+
modeAPromise ?? modeBPromise,
|
|
802
|
+
)) ?? 30 * 60 * 1000);
|
|
803
|
+
}
|
|
597
804
|
// Race the entire drain sequence (both modes + serve promise) against
|
|
598
|
-
// a single grace ceiling.
|
|
599
|
-
//
|
|
805
|
+
// a single grace ceiling. Local dev signal shutdowns allow the watcher
|
|
806
|
+
// to restart promptly; other shutdowns use the engine's actor stop threshold.
|
|
600
807
|
const drain = async () => {
|
|
601
808
|
// Shut down every live `CoreRegistry` we know about. Mode A
|
|
602
809
|
// (`start()`) and Mode B (`handler()`) each build a separate
|
|
@@ -608,6 +815,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
608
815
|
(async () => {
|
|
609
816
|
try {
|
|
610
817
|
const { runtime, registry } = await modeAPromise;
|
|
818
|
+
runtimes.add(runtime);
|
|
611
819
|
await runtime.shutdownRegistry(registry);
|
|
612
820
|
} catch (err) {
|
|
613
821
|
logger().warn(
|
|
@@ -623,6 +831,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
623
831
|
(async () => {
|
|
624
832
|
try {
|
|
625
833
|
const { runtime, registry } = await modeBPromise;
|
|
834
|
+
runtimes.add(runtime);
|
|
626
835
|
await runtime.shutdownRegistry(registry);
|
|
627
836
|
} catch (err) {
|
|
628
837
|
logger().warn(
|
|
@@ -642,6 +851,9 @@ export class Registry<A extends RegistryActors> {
|
|
|
642
851
|
// already logged any serve-side error.
|
|
643
852
|
await runtimeServePromise.catch(() => undefined);
|
|
644
853
|
}
|
|
854
|
+
if (this.#applicationListenerPromise !== undefined) {
|
|
855
|
+
await this.#applicationListenerPromise.catch(() => undefined);
|
|
856
|
+
}
|
|
645
857
|
};
|
|
646
858
|
await Promise.race([
|
|
647
859
|
drain(),
|
|
@@ -649,6 +861,9 @@ export class Registry<A extends RegistryActors> {
|
|
|
649
861
|
setTimeout(resolve, gracePeriodMs).unref?.(),
|
|
650
862
|
),
|
|
651
863
|
]);
|
|
864
|
+
await Promise.all(
|
|
865
|
+
[...runtimes].map((runtime) => runtime.shutdownTelemetry?.()),
|
|
866
|
+
);
|
|
652
867
|
}
|
|
653
868
|
|
|
654
869
|
async #actorStopThresholdMs(
|
|
@@ -690,6 +905,94 @@ export class Registry<A extends RegistryActors> {
|
|
|
690
905
|
this.#startEnvoy(this.parseConfig(), true);
|
|
691
906
|
}
|
|
692
907
|
|
|
908
|
+
/**
|
|
909
|
+
* Starts the serverful registry if needed and waits until its envoy has
|
|
910
|
+
* registered with the Engine. Repeated and concurrent calls share one
|
|
911
|
+
* startup lifecycle and readiness promise.
|
|
912
|
+
*
|
|
913
|
+
* Unlike {@link start}, this reports startup failures and does not resolve
|
|
914
|
+
* merely because an HTTP health endpoint is listening.
|
|
915
|
+
*/
|
|
916
|
+
public startAndWait(): Promise<void> {
|
|
917
|
+
if (this.#shutdownInFlight !== null) {
|
|
918
|
+
return Promise.reject(
|
|
919
|
+
new Error(
|
|
920
|
+
"registry.startAndWait() cannot run after shutdown has begun",
|
|
921
|
+
),
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
|
|
925
|
+
try {
|
|
926
|
+
if (getRivetkitRuntimeMode() === "serverless") {
|
|
927
|
+
return Promise.reject(
|
|
928
|
+
new Error(
|
|
929
|
+
"registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request",
|
|
930
|
+
),
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
} catch (error) {
|
|
934
|
+
return Promise.reject(error);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
const config = this.parseConfig();
|
|
938
|
+
if (config.runtime === "wasm") {
|
|
939
|
+
return Promise.reject(
|
|
940
|
+
new Error(
|
|
941
|
+
"registry.startAndWait() requires the native runtime; WebAssembly registries do not host an envoy",
|
|
942
|
+
),
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
this.#startEnvoy(config, true);
|
|
946
|
+
const configuredRegistryPromise = this.#runtimeServeConfiguredPromise;
|
|
947
|
+
const serveLifecyclePromise = this.#runtimeServeLifecyclePromise;
|
|
948
|
+
if (!configuredRegistryPromise || !serveLifecyclePromise) {
|
|
949
|
+
throw new Error("registry envoy startup did not initialize");
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
const readyTimeoutMs =
|
|
953
|
+
config.engineSpawn &&
|
|
954
|
+
config.endpoint !== undefined &&
|
|
955
|
+
isLocalEngineEndpoint(config.endpoint)
|
|
956
|
+
? LOCAL_ENGINE_READY_TIMEOUT_MS
|
|
957
|
+
: REGISTRY_READY_TIMEOUT_MS;
|
|
958
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
959
|
+
const timeoutPromise = new Promise<never>((_resolve, reject) => {
|
|
960
|
+
timeout = setTimeout(
|
|
961
|
+
() =>
|
|
962
|
+
reject(
|
|
963
|
+
new Error(
|
|
964
|
+
`RivetKit registry did not register with the Engine within ${readyTimeoutMs}ms`,
|
|
965
|
+
),
|
|
966
|
+
),
|
|
967
|
+
readyTimeoutMs,
|
|
968
|
+
);
|
|
969
|
+
timeout.unref?.();
|
|
970
|
+
});
|
|
971
|
+
const readinessPromise = (async () => {
|
|
972
|
+
const { runtime, registry } = await configuredRegistryPromise;
|
|
973
|
+
const stoppedBeforeReady = serveLifecyclePromise.then(() => {
|
|
974
|
+
throw new Error(
|
|
975
|
+
"RivetKit registry stopped before becoming ready",
|
|
976
|
+
);
|
|
977
|
+
});
|
|
978
|
+
await Promise.race([
|
|
979
|
+
runtime.waitRegistryReady(registry),
|
|
980
|
+
stoppedBeforeReady,
|
|
981
|
+
]);
|
|
982
|
+
})();
|
|
983
|
+
this.#runtimeReadyPromise = Promise.race([
|
|
984
|
+
readinessPromise,
|
|
985
|
+
timeoutPromise,
|
|
986
|
+
]).finally(() => {
|
|
987
|
+
if (timeout !== undefined) clearTimeout(timeout);
|
|
988
|
+
});
|
|
989
|
+
// The native registry is consumed once serve begins. Retrying the same
|
|
990
|
+
// instance after failure could duplicate partially-created resources, so
|
|
991
|
+
// retain the rejected promise and return the same failure to later calls.
|
|
992
|
+
this.#runtimeReadyPromise.catch(() => {});
|
|
993
|
+
return this.#runtimeReadyPromise;
|
|
994
|
+
}
|
|
995
|
+
|
|
693
996
|
/**
|
|
694
997
|
* Starts the actor envoy for standalone server deployments.
|
|
695
998
|
*
|