rivetkit 2.3.0-rc.8 → 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.
Files changed (122) hide show
  1. package/dist/browser/client.d.ts +8 -37
  2. package/dist/browser/client.js +34 -64
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +3 -4
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/actor/errors.cjs +2 -2
  7. package/dist/tsup/actor/errors.js +1 -1
  8. package/dist/tsup/agent-os/index.cjs +5 -7
  9. package/dist/tsup/agent-os/index.cjs.map +1 -1
  10. package/dist/tsup/agent-os/index.d.cts +5 -26
  11. package/dist/tsup/agent-os/index.d.ts +5 -26
  12. package/dist/tsup/agent-os/index.js +5 -7
  13. package/dist/tsup/agent-os/index.js.map +1 -1
  14. package/dist/tsup/{chunk-OT7FF6GB.cjs → chunk-4CGA6QJO.cjs} +4 -4
  15. package/dist/tsup/{chunk-OT7FF6GB.cjs.map → chunk-4CGA6QJO.cjs.map} +1 -1
  16. package/dist/tsup/{chunk-4BPKKZJO.cjs → chunk-4WPEZBK4.cjs} +8 -8
  17. package/dist/tsup/{chunk-4BPKKZJO.cjs.map → chunk-4WPEZBK4.cjs.map} +1 -1
  18. package/dist/tsup/{chunk-AWTPTUQ7.cjs → chunk-CPA4Y3RG.cjs} +10 -10
  19. package/dist/tsup/chunk-CPA4Y3RG.cjs.map +1 -0
  20. package/dist/tsup/{chunk-EMFKMVJR.js → chunk-F3Q5BFQ6.js} +34 -10
  21. package/dist/tsup/chunk-F3Q5BFQ6.js.map +1 -0
  22. package/dist/tsup/{chunk-7HLFSAJP.cjs → chunk-GVTOE34S.cjs} +193 -169
  23. package/dist/tsup/chunk-GVTOE34S.cjs.map +1 -0
  24. package/dist/tsup/{chunk-D3T3ZBSY.js → chunk-H37XQU3I.js} +2 -2
  25. package/dist/tsup/{chunk-4JU3IPG2.js → chunk-H7P7WR2Y.js} +3 -3
  26. package/dist/tsup/{chunk-TMLOKTRB.js → chunk-KIWH5H3K.js} +3 -3
  27. package/dist/tsup/chunk-KIWH5H3K.js.map +1 -0
  28. package/dist/tsup/{chunk-VUGENVIK.js → chunk-KJTA3ATT.js} +2 -2
  29. package/dist/tsup/{chunk-6TQSSJ4F.cjs → chunk-MALSPBAF.cjs} +3 -3
  30. package/dist/tsup/{chunk-6TQSSJ4F.cjs.map → chunk-MALSPBAF.cjs.map} +1 -1
  31. package/dist/tsup/{chunk-UZXQEGVJ.js → chunk-MMMEZM5J.js} +4 -4
  32. package/dist/tsup/chunk-MMMEZM5J.js.map +1 -0
  33. package/dist/tsup/{chunk-63WNTDRC.cjs → chunk-QAZLM4WT.cjs} +3 -3
  34. package/dist/tsup/{chunk-63WNTDRC.cjs.map → chunk-QAZLM4WT.cjs.map} +1 -1
  35. package/dist/tsup/{chunk-D5G75T7J.js → chunk-T6YVRM4K.js} +1 -3
  36. package/dist/tsup/chunk-T6YVRM4K.js.map +1 -0
  37. package/dist/tsup/{chunk-HGW6PBWR.cjs → chunk-VJFRBJVQ.cjs} +9 -137
  38. package/dist/tsup/chunk-VJFRBJVQ.cjs.map +1 -0
  39. package/dist/tsup/{chunk-GBG63SUG.js → chunk-VRCIXJRN.js} +5 -7
  40. package/dist/tsup/chunk-VRCIXJRN.js.map +1 -0
  41. package/dist/tsup/{chunk-KY3CERZR.js → chunk-W7EYSYVI.js} +4 -132
  42. package/dist/tsup/chunk-W7EYSYVI.js.map +1 -0
  43. package/dist/tsup/{chunk-SRNOPUC6.cjs → chunk-WQ4HNA4W.cjs} +2 -4
  44. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +1 -0
  45. package/dist/tsup/{chunk-BATTOVHF.cjs → chunk-Y5NSCZA2.cjs} +12 -14
  46. package/dist/tsup/chunk-Y5NSCZA2.cjs.map +1 -0
  47. package/dist/tsup/client/mod.cjs +7 -7
  48. package/dist/tsup/client/mod.d.cts +2 -2
  49. package/dist/tsup/client/mod.d.ts +2 -2
  50. package/dist/tsup/client/mod.js +6 -6
  51. package/dist/tsup/common/log.cjs +3 -3
  52. package/dist/tsup/common/log.js +2 -2
  53. package/dist/tsup/common/websocket.cjs +4 -4
  54. package/dist/tsup/common/websocket.js +3 -3
  55. package/dist/tsup/{config-Ak1lv4gF.d.ts → config-0Ta55UV0.d.ts} +6 -27
  56. package/dist/tsup/{config-DU_xj4qZ.d.cts → config-Ca8dN4cS.d.cts} +6 -27
  57. package/dist/tsup/{context-DAAp4Lpg.d.ts → context-B_IWbWne.d.ts} +1 -1
  58. package/dist/tsup/{context-Dt_L55q8.d.cts → context-CUrQ9MHc.d.cts} +1 -1
  59. package/dist/tsup/inspector/mod.cjs +6 -6
  60. package/dist/tsup/inspector/mod.js +5 -5
  61. package/dist/tsup/mod.cjs +355 -482
  62. package/dist/tsup/mod.cjs.map +1 -1
  63. package/dist/tsup/mod.d.cts +3 -3
  64. package/dist/tsup/mod.d.ts +3 -3
  65. package/dist/tsup/mod.js +276 -403
  66. package/dist/tsup/mod.js.map +1 -1
  67. package/dist/tsup/test/mod.cjs +10 -10
  68. package/dist/tsup/test/mod.d.cts +1 -1
  69. package/dist/tsup/test/mod.d.ts +1 -1
  70. package/dist/tsup/test/mod.js +6 -6
  71. package/dist/tsup/utils.cjs +3 -3
  72. package/dist/tsup/utils.js +2 -2
  73. package/dist/tsup/workflow/mod.cjs +16 -41
  74. package/dist/tsup/workflow/mod.cjs.map +1 -1
  75. package/dist/tsup/workflow/mod.d.cts +3 -3
  76. package/dist/tsup/workflow/mod.d.ts +3 -3
  77. package/dist/tsup/workflow/mod.js +10 -35
  78. package/dist/tsup/workflow/mod.js.map +1 -1
  79. package/package.json +10 -11
  80. package/src/actor/config.ts +0 -3
  81. package/src/actor/errors.ts +2 -2
  82. package/src/agent-os/actor/session.ts +2 -2
  83. package/src/client/actor-conn.ts +34 -6
  84. package/src/client/actor-handle.ts +1 -2
  85. package/src/client/queue.ts +1 -2
  86. package/src/client/utils.ts +1 -0
  87. package/src/common/encoding.ts +5 -243
  88. package/src/common/inline-websocket-adapter.ts +12 -12
  89. package/src/common/log.ts +0 -1
  90. package/src/common/router.ts +2 -2
  91. package/src/common/utils.ts +148 -0
  92. package/src/drivers/engine/actor-driver.ts +11 -11
  93. package/src/engine-client/actor-websocket-client.ts +1 -2
  94. package/src/engine-client/mod.ts +2 -3
  95. package/src/registry/index.ts +109 -46
  96. package/src/registry/napi-runtime.ts +34 -11
  97. package/src/registry/native.ts +162 -205
  98. package/src/registry/runtime.ts +12 -5
  99. package/src/registry/wasm-runtime.ts +13 -2
  100. package/src/serde.ts +2 -2
  101. package/src/workflow/context.ts +5 -32
  102. package/src/workflow/inspector.ts +1 -2
  103. package/dist/tsup/chunk-7HLFSAJP.cjs.map +0 -1
  104. package/dist/tsup/chunk-AWTPTUQ7.cjs.map +0 -1
  105. package/dist/tsup/chunk-BATTOVHF.cjs.map +0 -1
  106. package/dist/tsup/chunk-D5G75T7J.js.map +0 -1
  107. package/dist/tsup/chunk-EMFKMVJR.js.map +0 -1
  108. package/dist/tsup/chunk-GBG63SUG.js.map +0 -1
  109. package/dist/tsup/chunk-HGW6PBWR.cjs.map +0 -1
  110. package/dist/tsup/chunk-KY3CERZR.js.map +0 -1
  111. package/dist/tsup/chunk-SRNOPUC6.cjs.map +0 -1
  112. package/dist/tsup/chunk-TMLOKTRB.js.map +0 -1
  113. package/dist/tsup/chunk-UZXQEGVJ.js.map +0 -1
  114. package/dist/tsup/process-metrics-NW754INA.js +0 -118
  115. package/dist/tsup/process-metrics-NW754INA.js.map +0 -1
  116. package/dist/tsup/process-metrics-TYAGKCEJ.cjs +0 -118
  117. package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +0 -1
  118. package/src/registry/process-metrics.ts +0 -183
  119. package/src/registry/write-through-proxy.ts +0 -40
  120. /package/dist/tsup/{chunk-D3T3ZBSY.js.map → chunk-H37XQU3I.js.map} +0 -0
  121. /package/dist/tsup/{chunk-4JU3IPG2.js.map → chunk-H7P7WR2Y.js.map} +0 -0
  122. /package/dist/tsup/{chunk-VUGENVIK.js.map → chunk-KJTA3ATT.js.map} +0 -0
@@ -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 { detectRuntime, VERSION } from "@/utils";
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 RegistryDiagnostics {
44
- mode: string;
45
- envoyActiveActorCount?: number | null;
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
- * 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
- * ```
307
+ * Returns a health response suitable for mounting in a user-owned router.
314
308
  */
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 }));
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
- app.all("*", (c) => this.handler(c.req.raw));
327
- await crossPlatformServe(config, port, app, runtime);
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
- public async diagnostics(): Promise<RegistryDiagnostics> {
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
- 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 };
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((error) => {
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({ error }, "runtime registry serve errored");
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((error) => {
427
- logger().warn({ error }, "shutdown error");
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 (error) {
510
+ } catch (err) {
455
511
  logger().warn(
456
- { error },
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
- { error: err },
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
- RuntimeRegistryDiagnostics,
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,