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.
Files changed (122) hide show
  1. package/dist/browser/client.d.ts +37 -8
  2. package/dist/browser/client.js +64 -34
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +4 -3
  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 +7 -5
  9. package/dist/tsup/agent-os/index.cjs.map +1 -1
  10. package/dist/tsup/agent-os/index.d.cts +26 -5
  11. package/dist/tsup/agent-os/index.d.ts +26 -5
  12. package/dist/tsup/agent-os/index.js +7 -5
  13. package/dist/tsup/agent-os/index.js.map +1 -1
  14. package/dist/tsup/{chunk-2G64KSZQ.cjs → chunk-2H4ISA4Y.cjs} +10 -10
  15. package/dist/tsup/chunk-2H4ISA4Y.cjs.map +1 -0
  16. package/dist/tsup/{chunk-ZI5QJMKO.js → chunk-4DJMFOSU.js} +2 -2
  17. package/dist/tsup/{chunk-RTC2AZGB.js → chunk-4LTY5TOO.js} +132 -4
  18. package/dist/tsup/chunk-4LTY5TOO.js.map +1 -0
  19. package/dist/tsup/{chunk-DEO7MMWQ.js → chunk-52TPEKEC.js} +2 -2
  20. package/dist/tsup/{chunk-HTR4YLNT.cjs → chunk-55E7IR6D.cjs} +4 -4
  21. package/dist/tsup/{chunk-HTR4YLNT.cjs.map → chunk-55E7IR6D.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-63WNTDRC.cjs} +3 -3
  23. package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-63WNTDRC.cjs.map} +1 -1
  24. package/dist/tsup/{chunk-EMO6E3PJ.js → chunk-CMV6N5OX.js} +3 -3
  25. package/dist/tsup/{chunk-T6YVRM4K.js → chunk-D5G75T7J.js} +3 -1
  26. package/dist/tsup/chunk-D5G75T7J.js.map +1 -0
  27. package/dist/tsup/{chunk-LIXXFXVR.cjs → chunk-FEOG44WH.cjs} +137 -9
  28. package/dist/tsup/chunk-FEOG44WH.cjs.map +1 -0
  29. package/dist/tsup/{chunk-M5C7YNI5.cjs → chunk-G5HUSWP4.cjs} +8 -8
  30. package/dist/tsup/{chunk-M5C7YNI5.cjs.map → chunk-G5HUSWP4.cjs.map} +1 -1
  31. package/dist/tsup/{chunk-6S25NVAP.js → chunk-HERL2VQ2.js} +7 -5
  32. package/dist/tsup/chunk-HERL2VQ2.js.map +1 -0
  33. package/dist/tsup/{chunk-JALSAX7Z.cjs → chunk-SJLPZEA3.cjs} +3 -3
  34. package/dist/tsup/{chunk-JALSAX7Z.cjs.map → chunk-SJLPZEA3.cjs.map} +1 -1
  35. package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-SRNOPUC6.cjs} +4 -2
  36. package/dist/tsup/chunk-SRNOPUC6.cjs.map +1 -0
  37. package/dist/tsup/{chunk-KIWH5H3K.js → chunk-TMLOKTRB.js} +3 -3
  38. package/dist/tsup/chunk-TMLOKTRB.js.map +1 -0
  39. package/dist/tsup/{chunk-CAF6JDJE.js → chunk-VFIY6GWO.js} +4 -4
  40. package/dist/tsup/chunk-VFIY6GWO.js.map +1 -0
  41. package/dist/tsup/{chunk-FLODVLYW.js → chunk-VJ4Y4WBT.js} +10 -34
  42. package/dist/tsup/chunk-VJ4Y4WBT.js.map +1 -0
  43. package/dist/tsup/{chunk-K5BA2LEO.cjs → chunk-X6HIFXNK.cjs} +14 -12
  44. package/dist/tsup/chunk-X6HIFXNK.cjs.map +1 -0
  45. package/dist/tsup/{chunk-ENK7C66G.cjs → chunk-ZGPX6KAH.cjs} +169 -193
  46. package/dist/tsup/chunk-ZGPX6KAH.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-0Ta55UV0.d.ts → config-Ak1lv4gF.d.ts} +27 -6
  56. package/dist/tsup/{config-Ca8dN4cS.d.cts → config-DU_xj4qZ.d.cts} +27 -6
  57. package/dist/tsup/{context-B_IWbWne.d.ts → context-DAAp4Lpg.d.ts} +1 -1
  58. package/dist/tsup/{context-CUrQ9MHc.d.cts → context-Dt_L55q8.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 +470 -316
  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 +391 -237
  66. package/dist/tsup/mod.js.map +1 -1
  67. package/dist/tsup/process-metrics-NW754INA.js +118 -0
  68. package/dist/tsup/process-metrics-NW754INA.js.map +1 -0
  69. package/dist/tsup/process-metrics-TYAGKCEJ.cjs +118 -0
  70. package/dist/tsup/process-metrics-TYAGKCEJ.cjs.map +1 -0
  71. package/dist/tsup/test/mod.cjs +10 -10
  72. package/dist/tsup/test/mod.d.cts +1 -1
  73. package/dist/tsup/test/mod.d.ts +1 -1
  74. package/dist/tsup/test/mod.js +6 -6
  75. package/dist/tsup/utils.cjs +3 -3
  76. package/dist/tsup/utils.js +2 -2
  77. package/dist/tsup/workflow/mod.cjs +41 -16
  78. package/dist/tsup/workflow/mod.cjs.map +1 -1
  79. package/dist/tsup/workflow/mod.d.cts +3 -3
  80. package/dist/tsup/workflow/mod.d.ts +3 -3
  81. package/dist/tsup/workflow/mod.js +35 -10
  82. package/dist/tsup/workflow/mod.js.map +1 -1
  83. package/package.json +11 -10
  84. package/src/actor/config.ts +3 -0
  85. package/src/actor/errors.ts +2 -2
  86. package/src/agent-os/actor/session.ts +2 -2
  87. package/src/client/actor-conn.ts +6 -34
  88. package/src/client/actor-handle.ts +2 -1
  89. package/src/client/queue.ts +2 -1
  90. package/src/client/utils.ts +0 -1
  91. package/src/common/encoding.ts +243 -5
  92. package/src/common/inline-websocket-adapter.ts +12 -12
  93. package/src/common/log.ts +1 -0
  94. package/src/common/router.ts +2 -2
  95. package/src/common/utils.ts +0 -148
  96. package/src/drivers/engine/actor-driver.ts +11 -11
  97. package/src/engine-client/actor-websocket-client.ts +2 -1
  98. package/src/engine-client/mod.ts +3 -2
  99. package/src/registry/index.ts +46 -109
  100. package/src/registry/napi-runtime.ts +11 -34
  101. package/src/registry/native.ts +193 -104
  102. package/src/registry/process-metrics.ts +183 -0
  103. package/src/registry/runtime.ts +5 -12
  104. package/src/registry/wasm-runtime.ts +2 -13
  105. package/src/registry/write-through-proxy.ts +40 -0
  106. package/src/serde.ts +2 -2
  107. package/src/workflow/context.ts +32 -5
  108. package/src/workflow/inspector.ts +2 -1
  109. package/dist/tsup/chunk-2G64KSZQ.cjs.map +0 -1
  110. package/dist/tsup/chunk-6S25NVAP.js.map +0 -1
  111. package/dist/tsup/chunk-CAF6JDJE.js.map +0 -1
  112. package/dist/tsup/chunk-ENK7C66G.cjs.map +0 -1
  113. package/dist/tsup/chunk-FLODVLYW.js.map +0 -1
  114. package/dist/tsup/chunk-K5BA2LEO.cjs.map +0 -1
  115. package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
  116. package/dist/tsup/chunk-LIXXFXVR.cjs.map +0 -1
  117. package/dist/tsup/chunk-RTC2AZGB.js.map +0 -1
  118. package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
  119. package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
  120. /package/dist/tsup/{chunk-ZI5QJMKO.js.map → chunk-4DJMFOSU.js.map} +0 -0
  121. /package/dist/tsup/{chunk-DEO7MMWQ.js.map → chunk-52TPEKEC.js.map} +0 -0
  122. /package/dist/tsup/{chunk-EMO6E3PJ.js.map → chunk-CMV6N5OX.js.map} +0 -0
@@ -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 RegistryRoutes {
42
- health(): Promise<Response>;
43
- metadata(): Promise<Response>;
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
- * Returns a health response suitable for mounting in a user-owned router.
308
- */
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
- });
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 #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
- });
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
- const response = await runtime.registryMetrics(registry);
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 #activeConfiguredRegistry(): Promise<
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
- if (candidates.length === 0) return undefined;
400
- return await candidates[0]!;
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((err) => {
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({ err }, "runtime registry serve errored");
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((err) => {
483
- logger().warn({ err }, "shutdown error");
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 (err) {
454
+ } catch (error) {
511
455
  logger().warn(
512
- { err },
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
- RuntimeRegistryRouteResponse,
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,