rivetkit 2.3.0-rc.6 → 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 +37 -8
- package/dist/browser/client.js +64 -34
- 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 +2 -2
- package/dist/tsup/actor/errors.js +1 -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 +26 -5
- package/dist/tsup/agent-os/index.d.ts +26 -5
- package/dist/tsup/agent-os/index.js +7 -5
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-2G64KSZQ.cjs → chunk-2H4ISA4Y.cjs} +10 -10
- package/dist/tsup/chunk-2H4ISA4Y.cjs.map +1 -0
- package/dist/tsup/{chunk-ZI5QJMKO.js → chunk-4DJMFOSU.js} +2 -2
- package/dist/tsup/{chunk-RTC2AZGB.js → chunk-4LTY5TOO.js} +132 -4
- package/dist/tsup/chunk-4LTY5TOO.js.map +1 -0
- package/dist/tsup/{chunk-DEO7MMWQ.js → chunk-52TPEKEC.js} +2 -2
- package/dist/tsup/{chunk-HTR4YLNT.cjs → chunk-55E7IR6D.cjs} +4 -4
- package/dist/tsup/{chunk-HTR4YLNT.cjs.map → chunk-55E7IR6D.cjs.map} +1 -1
- package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-63WNTDRC.cjs} +3 -3
- package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-63WNTDRC.cjs.map} +1 -1
- package/dist/tsup/{chunk-EMO6E3PJ.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-LIXXFXVR.cjs → chunk-FEOG44WH.cjs} +137 -9
- package/dist/tsup/chunk-FEOG44WH.cjs.map +1 -0
- package/dist/tsup/{chunk-M5C7YNI5.cjs → chunk-G5HUSWP4.cjs} +8 -8
- package/dist/tsup/{chunk-M5C7YNI5.cjs.map → chunk-G5HUSWP4.cjs.map} +1 -1
- package/dist/tsup/{chunk-6S25NVAP.js → chunk-HERL2VQ2.js} +7 -5
- package/dist/tsup/chunk-HERL2VQ2.js.map +1 -0
- package/dist/tsup/{chunk-JALSAX7Z.cjs → chunk-SJLPZEA3.cjs} +3 -3
- package/dist/tsup/{chunk-JALSAX7Z.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-KIWH5H3K.js → chunk-TMLOKTRB.js} +3 -3
- package/dist/tsup/chunk-TMLOKTRB.js.map +1 -0
- package/dist/tsup/{chunk-CAF6JDJE.js → chunk-VFIY6GWO.js} +4 -4
- package/dist/tsup/chunk-VFIY6GWO.js.map +1 -0
- package/dist/tsup/{chunk-FLODVLYW.js → chunk-VJ4Y4WBT.js} +10 -34
- package/dist/tsup/chunk-VJ4Y4WBT.js.map +1 -0
- package/dist/tsup/{chunk-K5BA2LEO.cjs → chunk-X6HIFXNK.cjs} +14 -12
- package/dist/tsup/chunk-X6HIFXNK.cjs.map +1 -0
- package/dist/tsup/{chunk-ENK7C66G.cjs → chunk-ZGPX6KAH.cjs} +169 -193
- package/dist/tsup/chunk-ZGPX6KAH.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +7 -7
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- 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-0Ta55UV0.d.ts → config-Ak1lv4gF.d.ts} +27 -6
- package/dist/tsup/{config-Ca8dN4cS.d.cts → config-DU_xj4qZ.d.cts} +27 -6
- package/dist/tsup/{context-B_IWbWne.d.ts → context-DAAp4Lpg.d.ts} +1 -1
- package/dist/tsup/{context-CUrQ9MHc.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 +470 -316
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +3 -3
- package/dist/tsup/mod.d.ts +3 -3
- package/dist/tsup/mod.js +391 -237
- 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 +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +6 -6
- package/dist/tsup/utils.cjs +3 -3
- 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 +3 -3
- package/dist/tsup/workflow/mod.d.ts +3 -3
- 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 +2 -2
- package/src/agent-os/actor/session.ts +2 -2
- package/src/client/actor-conn.ts +6 -34
- package/src/client/actor-handle.ts +2 -1
- package/src/client/queue.ts +2 -1
- package/src/client/utils.ts +0 -1
- 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 +2 -2
- package/src/common/utils.ts +0 -148
- package/src/drivers/engine/actor-driver.ts +11 -11
- package/src/engine-client/actor-websocket-client.ts +2 -1
- package/src/engine-client/mod.ts +3 -2
- package/src/registry/index.ts +46 -109
- package/src/registry/napi-runtime.ts +11 -34
- package/src/registry/native.ts +193 -104
- package/src/registry/process-metrics.ts +183 -0
- package/src/registry/runtime.ts +5 -12
- package/src/registry/wasm-runtime.ts +2 -13
- 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-2G64KSZQ.cjs.map +0 -1
- package/dist/tsup/chunk-6S25NVAP.js.map +0 -1
- package/dist/tsup/chunk-CAF6JDJE.js.map +0 -1
- package/dist/tsup/chunk-ENK7C66G.cjs.map +0 -1
- package/dist/tsup/chunk-FLODVLYW.js.map +0 -1
- package/dist/tsup/chunk-K5BA2LEO.cjs.map +0 -1
- package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
- package/dist/tsup/chunk-LIXXFXVR.cjs.map +0 -1
- package/dist/tsup/chunk-RTC2AZGB.js.map +0 -1
- package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
- /package/dist/tsup/{chunk-ZI5QJMKO.js.map → chunk-4DJMFOSU.js.map} +0 -0
- /package/dist/tsup/{chunk-DEO7MMWQ.js.map → chunk-52TPEKEC.js.map} +0 -0
- /package/dist/tsup/{chunk-EMO6E3PJ.js.map → chunk-CMV6N5OX.js.map} +0 -0
package/src/registry/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
1
2
|
import { ENGINE_ENDPOINT } from "@/common/engine";
|
|
2
3
|
import { configureServerlessPool } from "@/serverless/configure";
|
|
3
|
-
import { VERSION } from "@/utils";
|
|
4
|
+
import { detectRuntime, VERSION } from "@/utils";
|
|
5
|
+
import { crossPlatformServe, loadRuntimeServeStatic } from "@/utils/serve";
|
|
4
6
|
import {
|
|
5
7
|
type RegistryActors,
|
|
6
8
|
type RegistryConfig,
|
|
@@ -38,15 +40,13 @@ export interface ServerlessHandler {
|
|
|
38
40
|
fetch: FetchHandler;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
export interface
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
prometheusMetrics(request?: Request): Promise<Response>;
|
|
43
|
+
export interface RegistryDiagnostics {
|
|
44
|
+
mode: string;
|
|
45
|
+
envoyActiveActorCount?: number | null;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export class Registry<A extends RegistryActors> {
|
|
48
49
|
#config: RegistryConfigInput<A>;
|
|
49
|
-
public readonly routes: RegistryRoutes;
|
|
50
50
|
|
|
51
51
|
get config(): RegistryConfigInput<A> {
|
|
52
52
|
return this.#config;
|
|
@@ -67,12 +67,6 @@ export class Registry<A extends RegistryActors> {
|
|
|
67
67
|
|
|
68
68
|
constructor(config: RegistryConfigInput<A>) {
|
|
69
69
|
this.#config = config;
|
|
70
|
-
this.routes = {
|
|
71
|
-
health: () => this.#healthRoute(),
|
|
72
|
-
metadata: () => this.#metadataRoute(),
|
|
73
|
-
prometheusMetrics: (request?: Request) =>
|
|
74
|
-
this.#prometheusMetricsRoute(request),
|
|
75
|
-
};
|
|
76
70
|
}
|
|
77
71
|
|
|
78
72
|
#ensureServerlessPoolConfigured(config: RegistryConfig): Promise<void> | undefined {
|
|
@@ -304,91 +298,36 @@ export class Registry<A extends RegistryActors> {
|
|
|
304
298
|
}
|
|
305
299
|
|
|
306
300
|
/**
|
|
307
|
-
*
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (!runtime.registryHealth) {
|
|
321
|
-
return jsonRouteResponse(501, {
|
|
322
|
-
status: "unsupported",
|
|
323
|
-
runtime: "rivetkit",
|
|
324
|
-
version: VERSION,
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const response = await runtime.registryHealth(registry);
|
|
329
|
-
return new Response(new Uint8Array(response.body), {
|
|
330
|
-
status: response.status,
|
|
331
|
-
headers: response.headers,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Returns serverless metadata suitable for mounting in a user-owned router.
|
|
337
|
-
*/
|
|
338
|
-
async #metadataRoute(): Promise<Response> {
|
|
339
|
-
const configured = await this.#activeConfiguredRegistry();
|
|
340
|
-
if (!configured) {
|
|
341
|
-
return new Response("registry not started\n", {
|
|
342
|
-
status: 503,
|
|
343
|
-
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const { runtime, registry } = configured;
|
|
348
|
-
if (!runtime.registryMetadata) {
|
|
349
|
-
return new Response("metadata is not supported by this runtime\n", {
|
|
350
|
-
status: 501,
|
|
351
|
-
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
const response = await runtime.registryMetadata(registry);
|
|
356
|
-
return new Response(new Uint8Array(response.body), {
|
|
357
|
-
status: response.status,
|
|
358
|
-
headers: response.headers,
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Returns a Prometheus metrics response suitable for mounting in a user-owned router.
|
|
301
|
+
* Starts an HTTP server that dispatches every request through the
|
|
302
|
+
* serverless handler. Uses `crossPlatformServe` to pick the right
|
|
303
|
+
* runtime (Node, Bun, Deno).
|
|
304
|
+
*
|
|
305
|
+
* @param opts.port Port to listen on. Defaults to 3000.
|
|
306
|
+
* @param opts.publicDir If set, serves static files from this directory
|
|
307
|
+
* before falling through to the registry handler.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* await registry.listen();
|
|
312
|
+
* await registry.listen({ port: 8080, publicDir: "./public" });
|
|
313
|
+
* ```
|
|
364
314
|
*/
|
|
365
|
-
async
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if (!runtime.registryMetrics) {
|
|
376
|
-
return new Response("metrics are not supported by this runtime\n", {
|
|
377
|
-
status: 501,
|
|
378
|
-
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
379
|
-
});
|
|
315
|
+
public async listen(
|
|
316
|
+
opts: { port?: number; publicDir?: string } = {},
|
|
317
|
+
): Promise<void> {
|
|
318
|
+
const port = opts.port ?? 3000;
|
|
319
|
+
const config = this.parseConfig();
|
|
320
|
+
const runtime = detectRuntime();
|
|
321
|
+
const app = new Hono();
|
|
322
|
+
if (opts.publicDir) {
|
|
323
|
+
const serveStatic = await loadRuntimeServeStatic(runtime);
|
|
324
|
+
app.use("*", serveStatic({ root: opts.publicDir }));
|
|
380
325
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return new Response(new Uint8Array(response.body), {
|
|
384
|
-
status: response.status,
|
|
385
|
-
headers: response.headers,
|
|
386
|
-
});
|
|
326
|
+
app.all("*", (c) => this.handler(c.req.raw));
|
|
327
|
+
await crossPlatformServe(config, port, app, runtime);
|
|
387
328
|
}
|
|
388
329
|
|
|
389
|
-
async
|
|
390
|
-
Awaited<ReturnType<typeof buildConfiguredRegistry>> | undefined
|
|
391
|
-
> {
|
|
330
|
+
public async diagnostics(): Promise<RegistryDiagnostics> {
|
|
392
331
|
const candidates = [
|
|
393
332
|
this.#runtimeServerlessPromise,
|
|
394
333
|
this.#runtimeServeConfiguredPromise,
|
|
@@ -396,8 +335,13 @@ export class Registry<A extends RegistryActors> {
|
|
|
396
335
|
candidate !== undefined
|
|
397
336
|
);
|
|
398
337
|
|
|
399
|
-
|
|
400
|
-
|
|
338
|
+
for (const candidate of candidates) {
|
|
339
|
+
const { runtime, registry } = await candidate;
|
|
340
|
+
const diagnostics = await runtime.registryDiagnostics?.(registry);
|
|
341
|
+
if (diagnostics) return diagnostics;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return { mode: "not_started", envoyActiveActorCount: null };
|
|
401
345
|
}
|
|
402
346
|
|
|
403
347
|
/**
|
|
@@ -411,12 +355,12 @@ export class Registry<A extends RegistryActors> {
|
|
|
411
355
|
.then(async ({ runtime, registry, serveConfig }) => {
|
|
412
356
|
await runtime.serveRegistry(registry, serveConfig);
|
|
413
357
|
})
|
|
414
|
-
.catch((
|
|
358
|
+
.catch((error) => {
|
|
415
359
|
// Always-attached catch so the stored promise never leaves a
|
|
416
360
|
// rejection unhandled. Downstream awaits (e.g. #runShutdown's
|
|
417
361
|
// Promise.race) attach their own catches and still observe
|
|
418
362
|
// resolution via the race.
|
|
419
|
-
logger().warn({
|
|
363
|
+
logger().warn({ error }, "runtime registry serve errored");
|
|
420
364
|
});
|
|
421
365
|
// Install signal handlers once an envoy lifecycle has begun. Only
|
|
422
366
|
// Mode A ever reaches here. Mode B (handler(request)) intentionally
|
|
@@ -479,8 +423,8 @@ export class Registry<A extends RegistryActors> {
|
|
|
479
423
|
signal,
|
|
480
424
|
config,
|
|
481
425
|
configuredRegistryPromise,
|
|
482
|
-
).catch((
|
|
483
|
-
logger().warn({
|
|
426
|
+
).catch((error) => {
|
|
427
|
+
logger().warn({ error }, "shutdown error");
|
|
484
428
|
});
|
|
485
429
|
}
|
|
486
430
|
|
|
@@ -507,9 +451,9 @@ export class Registry<A extends RegistryActors> {
|
|
|
507
451
|
const { runtime, registry } =
|
|
508
452
|
await configuredRegistryPromise;
|
|
509
453
|
await runtime.shutdownRegistry(registry);
|
|
510
|
-
} catch (
|
|
454
|
+
} catch (error) {
|
|
511
455
|
logger().warn(
|
|
512
|
-
{
|
|
456
|
+
{ error },
|
|
513
457
|
"runtime registry shutdown errored (mode A)",
|
|
514
458
|
);
|
|
515
459
|
}
|
|
@@ -525,7 +469,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
525
469
|
await runtime.shutdownRegistry(registry);
|
|
526
470
|
} catch (err) {
|
|
527
471
|
logger().warn(
|
|
528
|
-
{ err },
|
|
472
|
+
{ error: err },
|
|
529
473
|
"runtime registry shutdown errored (mode B)",
|
|
530
474
|
);
|
|
531
475
|
}
|
|
@@ -654,13 +598,6 @@ function isServerlessMetadataRequest(request: Request, basePath: string): boolea
|
|
|
654
598
|
return parsed.pathname === `${normalizedBase}/metadata`;
|
|
655
599
|
}
|
|
656
600
|
|
|
657
|
-
function jsonRouteResponse(status: number, body: unknown): Response {
|
|
658
|
-
return new Response(JSON.stringify(body), {
|
|
659
|
-
status,
|
|
660
|
-
headers: { "content-type": "application/json" },
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
|
|
664
601
|
export function setup<A extends RegistryActors>(
|
|
665
602
|
input: RegistryConfigInput<A>,
|
|
666
603
|
): Registry<A> {
|
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
RuntimeQueueTryNextBatchOptions,
|
|
25
25
|
RuntimeQueueWaitOptions,
|
|
26
26
|
RuntimeRequestSaveOpts,
|
|
27
|
-
|
|
27
|
+
RuntimeRegistryDiagnostics,
|
|
28
28
|
RuntimeServeConfig,
|
|
29
29
|
RuntimeServerlessRequest,
|
|
30
30
|
RuntimeServerlessResponseHead,
|
|
@@ -202,6 +202,16 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
202
202
|
await asNativeRegistry(registry).shutdown();
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
async registryDiagnostics(
|
|
206
|
+
registry: RegistryHandle,
|
|
207
|
+
): Promise<RuntimeRegistryDiagnostics> {
|
|
208
|
+
const diagnostics = await asNativeRegistry(registry).diagnostics();
|
|
209
|
+
return {
|
|
210
|
+
mode: diagnostics.mode,
|
|
211
|
+
envoyActiveActorCount: diagnostics.envoyActiveActorCount,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
205
215
|
async registryActorStopThresholdMs(
|
|
206
216
|
registry: RegistryHandle,
|
|
207
217
|
): Promise<number | undefined> {
|
|
@@ -211,39 +221,6 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
211
221
|
);
|
|
212
222
|
}
|
|
213
223
|
|
|
214
|
-
async registryHealth(
|
|
215
|
-
registry: RegistryHandle,
|
|
216
|
-
): Promise<RuntimeRegistryRouteResponse> {
|
|
217
|
-
const response = await asNativeRegistry(registry).health();
|
|
218
|
-
return {
|
|
219
|
-
status: response.status,
|
|
220
|
-
headers: response.headers,
|
|
221
|
-
body: response.body,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async registryMetadata(
|
|
226
|
-
registry: RegistryHandle,
|
|
227
|
-
): Promise<RuntimeRegistryRouteResponse> {
|
|
228
|
-
const response = asNativeRegistry(registry).metadata();
|
|
229
|
-
return {
|
|
230
|
-
status: response.status,
|
|
231
|
-
headers: response.headers,
|
|
232
|
-
body: response.body,
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
async registryMetrics(
|
|
237
|
-
registry: RegistryHandle,
|
|
238
|
-
): Promise<RuntimeRegistryRouteResponse> {
|
|
239
|
-
const response = asNativeRegistry(registry).metrics();
|
|
240
|
-
return {
|
|
241
|
-
status: response.status,
|
|
242
|
-
headers: response.headers,
|
|
243
|
-
body: response.body,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
224
|
async handleServerlessRequest(
|
|
248
225
|
registry: RegistryHandle,
|
|
249
226
|
req: RuntimeServerlessRequest,
|