rivetkit 2.3.0-rc.7 → 2.3.0-rc.9
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 +8 -37
- package/dist/browser/client.js +34 -64
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +3 -4
- 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 +5 -7
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +5 -26
- package/dist/tsup/agent-os/index.d.ts +5 -26
- package/dist/tsup/agent-os/index.js +5 -7
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-55E7IR6D.cjs → chunk-4CGA6QJO.cjs} +4 -4
- package/dist/tsup/{chunk-55E7IR6D.cjs.map → chunk-4CGA6QJO.cjs.map} +1 -1
- package/dist/tsup/{chunk-G5HUSWP4.cjs → chunk-4WPEZBK4.cjs} +8 -8
- package/dist/tsup/{chunk-G5HUSWP4.cjs.map → chunk-4WPEZBK4.cjs.map} +1 -1
- package/dist/tsup/{chunk-2H4ISA4Y.cjs → chunk-CPA4Y3RG.cjs} +10 -10
- package/dist/tsup/chunk-CPA4Y3RG.cjs.map +1 -0
- package/dist/tsup/{chunk-VJ4Y4WBT.js → chunk-F3Q5BFQ6.js} +34 -10
- package/dist/tsup/chunk-F3Q5BFQ6.js.map +1 -0
- package/dist/tsup/{chunk-ZGPX6KAH.cjs → chunk-GVTOE34S.cjs} +193 -169
- package/dist/tsup/chunk-GVTOE34S.cjs.map +1 -0
- package/dist/tsup/{chunk-4DJMFOSU.js → chunk-H37XQU3I.js} +2 -2
- package/dist/tsup/{chunk-CMV6N5OX.js → chunk-H7P7WR2Y.js} +3 -3
- package/dist/tsup/{chunk-TMLOKTRB.js → chunk-KIWH5H3K.js} +3 -3
- package/dist/tsup/chunk-KIWH5H3K.js.map +1 -0
- package/dist/tsup/{chunk-52TPEKEC.js → chunk-KJTA3ATT.js} +2 -2
- package/dist/tsup/{chunk-SJLPZEA3.cjs → chunk-MALSPBAF.cjs} +3 -3
- package/dist/tsup/{chunk-SJLPZEA3.cjs.map → chunk-MALSPBAF.cjs.map} +1 -1
- package/dist/tsup/{chunk-VFIY6GWO.js → chunk-MMMEZM5J.js} +4 -4
- package/dist/tsup/chunk-MMMEZM5J.js.map +1 -0
- package/dist/tsup/{chunk-63WNTDRC.cjs → chunk-QAZLM4WT.cjs} +3 -3
- package/dist/tsup/{chunk-63WNTDRC.cjs.map → chunk-QAZLM4WT.cjs.map} +1 -1
- package/dist/tsup/{chunk-D5G75T7J.js → chunk-T6YVRM4K.js} +1 -3
- package/dist/tsup/chunk-T6YVRM4K.js.map +1 -0
- package/dist/tsup/{chunk-FEOG44WH.cjs → chunk-VJFRBJVQ.cjs} +9 -137
- package/dist/tsup/chunk-VJFRBJVQ.cjs.map +1 -0
- package/dist/tsup/{chunk-HERL2VQ2.js → chunk-VRCIXJRN.js} +5 -7
- package/dist/tsup/chunk-VRCIXJRN.js.map +1 -0
- package/dist/tsup/{chunk-4LTY5TOO.js → chunk-W7EYSYVI.js} +4 -132
- package/dist/tsup/chunk-W7EYSYVI.js.map +1 -0
- package/dist/tsup/{chunk-SRNOPUC6.cjs → chunk-WQ4HNA4W.cjs} +2 -4
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +1 -0
- package/dist/tsup/{chunk-X6HIFXNK.cjs → chunk-Y5NSCZA2.cjs} +12 -14
- package/dist/tsup/chunk-Y5NSCZA2.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-Ak1lv4gF.d.ts → config-0Ta55UV0.d.ts} +6 -27
- package/dist/tsup/{config-DU_xj4qZ.d.cts → config-Ca8dN4cS.d.cts} +6 -27
- package/dist/tsup/{context-DAAp4Lpg.d.ts → context-B_IWbWne.d.ts} +1 -1
- package/dist/tsup/{context-Dt_L55q8.d.cts → context-CUrQ9MHc.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 +355 -482
- 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 +276 -403
- package/dist/tsup/mod.js.map +1 -1
- 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 +16 -41
- 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 +10 -35
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +10 -11
- package/src/actor/config.ts +0 -3
- package/src/actor/errors.ts +2 -2
- package/src/agent-os/actor/session.ts +2 -2
- package/src/client/actor-conn.ts +34 -6
- package/src/client/actor-handle.ts +1 -2
- package/src/client/queue.ts +1 -2
- package/src/client/utils.ts +1 -0
- package/src/common/encoding.ts +5 -243
- package/src/common/inline-websocket-adapter.ts +12 -12
- package/src/common/log.ts +0 -1
- package/src/common/router.ts +2 -2
- package/src/common/utils.ts +148 -0
- package/src/drivers/engine/actor-driver.ts +11 -11
- package/src/engine-client/actor-websocket-client.ts +1 -2
- package/src/engine-client/mod.ts +2 -3
- package/src/registry/index.ts +109 -46
- package/src/registry/napi-runtime.ts +34 -11
- package/src/registry/native.ts +162 -205
- package/src/registry/runtime.ts +12 -5
- package/src/registry/wasm-runtime.ts +13 -2
- package/src/serde.ts +2 -2
- package/src/workflow/context.ts +5 -32
- package/src/workflow/inspector.ts +1 -2
- package/dist/tsup/chunk-2H4ISA4Y.cjs.map +0 -1
- package/dist/tsup/chunk-4LTY5TOO.js.map +0 -1
- package/dist/tsup/chunk-D5G75T7J.js.map +0 -1
- package/dist/tsup/chunk-FEOG44WH.cjs.map +0 -1
- package/dist/tsup/chunk-HERL2VQ2.js.map +0 -1
- package/dist/tsup/chunk-SRNOPUC6.cjs.map +0 -1
- package/dist/tsup/chunk-TMLOKTRB.js.map +0 -1
- package/dist/tsup/chunk-VFIY6GWO.js.map +0 -1
- package/dist/tsup/chunk-VJ4Y4WBT.js.map +0 -1
- package/dist/tsup/chunk-X6HIFXNK.cjs.map +0 -1
- package/dist/tsup/chunk-ZGPX6KAH.cjs.map +0 -1
- package/dist/tsup/process-metrics-NW754INA.js +0 -118
- package/dist/tsup/process-metrics-NW754INA.js.map +0 -1
- package/dist/tsup/process-metrics-TYAGKCEJ.cjs +0 -118
- package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +0 -1
- package/src/registry/process-metrics.ts +0 -183
- package/src/registry/write-through-proxy.ts +0 -40
- /package/dist/tsup/{chunk-4DJMFOSU.js.map → chunk-H37XQU3I.js.map} +0 -0
- /package/dist/tsup/{chunk-CMV6N5OX.js.map → chunk-H7P7WR2Y.js.map} +0 -0
- /package/dist/tsup/{chunk-52TPEKEC.js.map → chunk-KJTA3ATT.js.map} +0 -0
package/src/registry/index.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Hono } from "hono";
|
|
2
1
|
import { ENGINE_ENDPOINT } from "@/common/engine";
|
|
3
2
|
import { configureServerlessPool } from "@/serverless/configure";
|
|
4
|
-
import {
|
|
5
|
-
import { crossPlatformServe, loadRuntimeServeStatic } from "@/utils/serve";
|
|
3
|
+
import { VERSION } from "@/utils";
|
|
6
4
|
import {
|
|
7
5
|
type RegistryActors,
|
|
8
6
|
type RegistryConfig,
|
|
@@ -40,13 +38,15 @@ export interface ServerlessHandler {
|
|
|
40
38
|
fetch: FetchHandler;
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
export interface
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
export interface RegistryRoutes {
|
|
42
|
+
health(): Promise<Response>;
|
|
43
|
+
metadata(): Promise<Response>;
|
|
44
|
+
prometheusMetrics(request?: Request): Promise<Response>;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
export class Registry<A extends RegistryActors> {
|
|
49
48
|
#config: RegistryConfigInput<A>;
|
|
49
|
+
public readonly routes: RegistryRoutes;
|
|
50
50
|
|
|
51
51
|
get config(): RegistryConfigInput<A> {
|
|
52
52
|
return this.#config;
|
|
@@ -67,6 +67,12 @@ 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
|
+
};
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
#ensureServerlessPoolConfigured(config: RegistryConfig): Promise<void> | undefined {
|
|
@@ -298,36 +304,91 @@ export class Registry<A extends RegistryActors> {
|
|
|
298
304
|
}
|
|
299
305
|
|
|
300
306
|
/**
|
|
301
|
-
*
|
|
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
|
-
* ```
|
|
307
|
+
* Returns a health response suitable for mounting in a user-owned router.
|
|
314
308
|
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
309
|
+
async #healthRoute(): Promise<Response> {
|
|
310
|
+
const configured = await this.#activeConfiguredRegistry();
|
|
311
|
+
if (!configured) {
|
|
312
|
+
return jsonRouteResponse(503, {
|
|
313
|
+
status: "not_started",
|
|
314
|
+
runtime: "rivetkit",
|
|
315
|
+
version: VERSION,
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const { runtime, registry } = configured;
|
|
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
|
+
});
|
|
325
345
|
}
|
|
326
|
-
|
|
327
|
-
|
|
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.
|
|
364
|
+
*/
|
|
365
|
+
async #prometheusMetricsRoute(_request?: Request): Promise<Response> {
|
|
366
|
+
const configured = await this.#activeConfiguredRegistry();
|
|
367
|
+
if (!configured) {
|
|
368
|
+
return new Response("registry not started\n", {
|
|
369
|
+
status: 503,
|
|
370
|
+
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const { runtime, registry } = configured;
|
|
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
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const response = await runtime.registryMetrics(registry);
|
|
383
|
+
return new Response(new Uint8Array(response.body), {
|
|
384
|
+
status: response.status,
|
|
385
|
+
headers: response.headers,
|
|
386
|
+
});
|
|
328
387
|
}
|
|
329
388
|
|
|
330
|
-
|
|
389
|
+
async #activeConfiguredRegistry(): Promise<
|
|
390
|
+
Awaited<ReturnType<typeof buildConfiguredRegistry>> | undefined
|
|
391
|
+
> {
|
|
331
392
|
const candidates = [
|
|
332
393
|
this.#runtimeServerlessPromise,
|
|
333
394
|
this.#runtimeServeConfiguredPromise,
|
|
@@ -335,13 +396,8 @@ export class Registry<A extends RegistryActors> {
|
|
|
335
396
|
candidate !== undefined
|
|
336
397
|
);
|
|
337
398
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const diagnostics = await runtime.registryDiagnostics?.(registry);
|
|
341
|
-
if (diagnostics) return diagnostics;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return { mode: "not_started", envoyActiveActorCount: null };
|
|
399
|
+
if (candidates.length === 0) return undefined;
|
|
400
|
+
return await candidates[0]!;
|
|
345
401
|
}
|
|
346
402
|
|
|
347
403
|
/**
|
|
@@ -355,12 +411,12 @@ export class Registry<A extends RegistryActors> {
|
|
|
355
411
|
.then(async ({ runtime, registry, serveConfig }) => {
|
|
356
412
|
await runtime.serveRegistry(registry, serveConfig);
|
|
357
413
|
})
|
|
358
|
-
.catch((
|
|
414
|
+
.catch((err) => {
|
|
359
415
|
// Always-attached catch so the stored promise never leaves a
|
|
360
416
|
// rejection unhandled. Downstream awaits (e.g. #runShutdown's
|
|
361
417
|
// Promise.race) attach their own catches and still observe
|
|
362
418
|
// resolution via the race.
|
|
363
|
-
logger().warn({
|
|
419
|
+
logger().warn({ err }, "runtime registry serve errored");
|
|
364
420
|
});
|
|
365
421
|
// Install signal handlers once an envoy lifecycle has begun. Only
|
|
366
422
|
// Mode A ever reaches here. Mode B (handler(request)) intentionally
|
|
@@ -423,8 +479,8 @@ export class Registry<A extends RegistryActors> {
|
|
|
423
479
|
signal,
|
|
424
480
|
config,
|
|
425
481
|
configuredRegistryPromise,
|
|
426
|
-
).catch((
|
|
427
|
-
logger().warn({
|
|
482
|
+
).catch((err) => {
|
|
483
|
+
logger().warn({ err }, "shutdown error");
|
|
428
484
|
});
|
|
429
485
|
}
|
|
430
486
|
|
|
@@ -451,9 +507,9 @@ export class Registry<A extends RegistryActors> {
|
|
|
451
507
|
const { runtime, registry } =
|
|
452
508
|
await configuredRegistryPromise;
|
|
453
509
|
await runtime.shutdownRegistry(registry);
|
|
454
|
-
} catch (
|
|
510
|
+
} catch (err) {
|
|
455
511
|
logger().warn(
|
|
456
|
-
{
|
|
512
|
+
{ err },
|
|
457
513
|
"runtime registry shutdown errored (mode A)",
|
|
458
514
|
);
|
|
459
515
|
}
|
|
@@ -469,7 +525,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
469
525
|
await runtime.shutdownRegistry(registry);
|
|
470
526
|
} catch (err) {
|
|
471
527
|
logger().warn(
|
|
472
|
-
{
|
|
528
|
+
{ err },
|
|
473
529
|
"runtime registry shutdown errored (mode B)",
|
|
474
530
|
);
|
|
475
531
|
}
|
|
@@ -598,6 +654,13 @@ function isServerlessMetadataRequest(request: Request, basePath: string): boolea
|
|
|
598
654
|
return parsed.pathname === `${normalizedBase}/metadata`;
|
|
599
655
|
}
|
|
600
656
|
|
|
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
|
+
|
|
601
664
|
export function setup<A extends RegistryActors>(
|
|
602
665
|
input: RegistryConfigInput<A>,
|
|
603
666
|
): Registry<A> {
|
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
RuntimeQueueTryNextBatchOptions,
|
|
25
25
|
RuntimeQueueWaitOptions,
|
|
26
26
|
RuntimeRequestSaveOpts,
|
|
27
|
-
|
|
27
|
+
RuntimeRegistryRouteResponse,
|
|
28
28
|
RuntimeServeConfig,
|
|
29
29
|
RuntimeServerlessRequest,
|
|
30
30
|
RuntimeServerlessResponseHead,
|
|
@@ -202,16 +202,6 @@ 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
|
-
|
|
215
205
|
async registryActorStopThresholdMs(
|
|
216
206
|
registry: RegistryHandle,
|
|
217
207
|
): Promise<number | undefined> {
|
|
@@ -221,6 +211,39 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
221
211
|
);
|
|
222
212
|
}
|
|
223
213
|
|
|
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
|
+
|
|
224
247
|
async handleServerlessRequest(
|
|
225
248
|
registry: RegistryHandle,
|
|
226
249
|
req: RuntimeServerlessRequest,
|