rivetkit 2.3.10 → 2.3.11-rc.1

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 (86) hide show
  1. package/dist/browser/client.d.ts +24 -6
  2. package/dist/browser/client.js +18 -4
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +1 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/agent-os/index.cjs +1 -1
  7. package/dist/tsup/agent-os/index.cjs.map +1 -1
  8. package/dist/tsup/agent-os/index.d.cts +24 -6
  9. package/dist/tsup/agent-os/index.d.ts +24 -6
  10. package/dist/tsup/agent-os/index.js +1 -1
  11. package/dist/tsup/agent-os/index.js.map +1 -1
  12. package/dist/tsup/{chunk-PCJSDS7N.cjs → chunk-57ZE43T5.cjs} +3 -3
  13. package/dist/tsup/{chunk-PCJSDS7N.cjs.map → chunk-57ZE43T5.cjs.map} +1 -1
  14. package/dist/tsup/{chunk-Q5H37KNQ.js → chunk-5FVMFSBH.js} +2 -2
  15. package/dist/tsup/{chunk-E6IEX6AP.js → chunk-5ZS22TOP.js} +3 -3
  16. package/dist/tsup/{chunk-XSPAARQ5.js → chunk-6ZPMYIZ6.js} +2 -2
  17. package/dist/tsup/{chunk-X7XY6NCU.js → chunk-ET2F6BXK.js} +6 -3
  18. package/dist/tsup/chunk-ET2F6BXK.js.map +1 -0
  19. package/dist/tsup/{chunk-INXPYXN6.cjs → chunk-JAQHV6LB.cjs} +7 -7
  20. package/dist/tsup/{chunk-INXPYXN6.cjs.map → chunk-JAQHV6LB.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-G6XA2OSW.cjs → chunk-K4DNAIWT.cjs} +4 -4
  22. package/dist/tsup/{chunk-G6XA2OSW.cjs.map → chunk-K4DNAIWT.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-6UHZLL6S.js → chunk-L4DYLD7P.js} +3 -3
  24. package/dist/tsup/{chunk-DPM73GAL.js → chunk-MMPE77KO.js} +20 -5
  25. package/dist/tsup/chunk-MMPE77KO.js.map +1 -0
  26. package/dist/tsup/{chunk-Z2ESFE5Z.cjs → chunk-TWNMQDZK.cjs} +6 -3
  27. package/dist/tsup/chunk-TWNMQDZK.cjs.map +1 -0
  28. package/dist/tsup/{chunk-LCWHS6K7.cjs → chunk-W2YEXCCJ.cjs} +156 -141
  29. package/dist/tsup/chunk-W2YEXCCJ.cjs.map +1 -0
  30. package/dist/tsup/{chunk-U2A3Y7OK.cjs → chunk-XEOPXHN2.cjs} +9 -9
  31. package/dist/tsup/{chunk-U2A3Y7OK.cjs.map → chunk-XEOPXHN2.cjs.map} +1 -1
  32. package/dist/tsup/client/mod.cjs +5 -5
  33. package/dist/tsup/client/mod.d.cts +2 -2
  34. package/dist/tsup/client/mod.d.ts +2 -2
  35. package/dist/tsup/client/mod.js +4 -4
  36. package/dist/tsup/common/log.cjs +2 -2
  37. package/dist/tsup/common/log.js +1 -1
  38. package/dist/tsup/common/websocket.cjs +3 -3
  39. package/dist/tsup/common/websocket.js +2 -2
  40. package/dist/tsup/{config-BRpVbJCD.d.ts → config-BKAMOHez.d.ts} +25 -7
  41. package/dist/tsup/{config-BobvQpex.d.cts → config-Caocy3Z9.d.cts} +25 -7
  42. package/dist/tsup/{context-Cj-DFyiy.d.ts → context-AfCExwbr.d.ts} +1 -1
  43. package/dist/tsup/{context-YEBNJrws.d.cts → context-D1_m5x1D.d.cts} +1 -1
  44. package/dist/tsup/db/drizzle.cjs +2 -2
  45. package/dist/tsup/db/drizzle.js +1 -1
  46. package/dist/tsup/db/mod.cjs +2 -2
  47. package/dist/tsup/db/mod.js +1 -1
  48. package/dist/tsup/dynamic/mod.d.cts +1 -1
  49. package/dist/tsup/dynamic/mod.d.ts +1 -1
  50. package/dist/tsup/inspector/mod.cjs +4 -4
  51. package/dist/tsup/inspector/mod.js +3 -3
  52. package/dist/tsup/inspector-tab/mod.d.cts +2 -2
  53. package/dist/tsup/inspector-tab/mod.d.ts +2 -2
  54. package/dist/tsup/mod.cjs +187 -72
  55. package/dist/tsup/mod.cjs.map +1 -1
  56. package/dist/tsup/mod.d.cts +3 -3
  57. package/dist/tsup/mod.d.ts +3 -3
  58. package/dist/tsup/mod.js +129 -14
  59. package/dist/tsup/mod.js.map +1 -1
  60. package/dist/tsup/test/mod.cjs +6 -6
  61. package/dist/tsup/test/mod.d.cts +1 -1
  62. package/dist/tsup/test/mod.d.ts +1 -1
  63. package/dist/tsup/test/mod.js +4 -4
  64. package/dist/tsup/utils.cjs +2 -2
  65. package/dist/tsup/utils.js +1 -1
  66. package/dist/tsup/workflow/mod.cjs +6 -6
  67. package/dist/tsup/workflow/mod.d.cts +3 -3
  68. package/dist/tsup/workflow/mod.d.ts +3 -3
  69. package/dist/tsup/workflow/mod.js +3 -3
  70. package/package.json +8 -8
  71. package/src/client/raw-utils.ts +3 -2
  72. package/src/common/encoding.ts +4 -1
  73. package/src/common/fetch-like.ts +49 -0
  74. package/src/registry/index.ts +117 -12
  75. package/src/registry/napi-runtime.ts +47 -0
  76. package/src/registry/native.ts +3 -2
  77. package/src/registry/runtime.ts +21 -0
  78. package/src/registry/wasm-runtime.ts +11 -0
  79. package/dist/tsup/chunk-DPM73GAL.js.map +0 -1
  80. package/dist/tsup/chunk-LCWHS6K7.cjs.map +0 -1
  81. package/dist/tsup/chunk-X7XY6NCU.js.map +0 -1
  82. package/dist/tsup/chunk-Z2ESFE5Z.cjs.map +0 -1
  83. /package/dist/tsup/{chunk-Q5H37KNQ.js.map → chunk-5FVMFSBH.js.map} +0 -0
  84. /package/dist/tsup/{chunk-E6IEX6AP.js.map → chunk-5ZS22TOP.js.map} +0 -0
  85. /package/dist/tsup/{chunk-XSPAARQ5.js.map → chunk-6ZPMYIZ6.js.map} +0 -0
  86. /package/dist/tsup/{chunk-6UHZLL6S.js.map → chunk-L4DYLD7P.js.map} +0 -0
@@ -1,13 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
2
 
3
- var _chunkINXPYXN6cjs = require('../chunk-INXPYXN6.cjs');
3
+ var _chunkJAQHV6LBcjs = require('../chunk-JAQHV6LB.cjs');
4
4
 
5
5
 
6
- var _chunkLCWHS6K7cjs = require('../chunk-LCWHS6K7.cjs');
6
+ var _chunkW2YEXCCJcjs = require('../chunk-W2YEXCCJ.cjs');
7
7
  require('../chunk-MYWZCDML.cjs');
8
8
  require('../chunk-UEULFXUI.cjs');
9
- require('../chunk-PCJSDS7N.cjs');
10
- require('../chunk-Z2ESFE5Z.cjs');
9
+ require('../chunk-57ZE43T5.cjs');
10
+ require('../chunk-TWNMQDZK.cjs');
11
11
  require('../chunk-4FC7TVS6.cjs');
12
12
 
13
13
  // src/test/ready.ts
@@ -36,8 +36,8 @@ async function setupTest(c, registry) {
36
36
  registry.config.noWelcome = true;
37
37
  registry.start();
38
38
  await waitForRegistryReady(registry);
39
- const client = _chunkINXPYXN6cjs.createClient.call(void 0, {
40
- ..._chunkLCWHS6K7cjs.convertRegistryConfigToClientConfig.call(void 0, registry.parseConfig()),
39
+ const client = _chunkJAQHV6LBcjs.createClient.call(void 0, {
40
+ ..._chunkW2YEXCCJcjs.convertRegistryConfigToClientConfig.call(void 0, registry.parseConfig()),
41
41
  disableMetadataLookup: false
42
42
  });
43
43
  c.onTestFinished(async () => {
@@ -1,5 +1,5 @@
1
1
  import { TestContext } from 'vitest';
2
- import { aC as Registry, a2 as Client } from '../config-BobvQpex.cjs';
2
+ import { aC as Registry, a2 as Client } from '../config-Caocy3Z9.cjs';
3
3
  import 'zod/v4';
4
4
  import '../config-BxOimoGX.cjs';
5
5
  import '@rivetkit/rivetkit-wasm';
@@ -1,5 +1,5 @@
1
1
  import { TestContext } from 'vitest';
2
- import { aC as Registry, a2 as Client } from '../config-BRpVbJCD.js';
2
+ import { aC as Registry, a2 as Client } from '../config-BKAMOHez.js';
3
3
  import 'zod/v4';
4
4
  import '../config-BxOimoGX.js';
5
5
  import '@rivetkit/rivetkit-wasm';
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  createClient
3
- } from "../chunk-6UHZLL6S.js";
3
+ } from "../chunk-L4DYLD7P.js";
4
4
  import {
5
5
  convertRegistryConfigToClientConfig
6
- } from "../chunk-DPM73GAL.js";
6
+ } from "../chunk-MMPE77KO.js";
7
7
  import "../chunk-JI6GZ2C2.js";
8
8
  import "../chunk-7AFZMFPQ.js";
9
- import "../chunk-Q5H37KNQ.js";
10
- import "../chunk-X7XY6NCU.js";
9
+ import "../chunk-5FVMFSBH.js";
10
+ import "../chunk-ET2F6BXK.js";
11
11
  import "../chunk-ZZ3WBRPD.js";
12
12
 
13
13
  // src/test/ready.ts
@@ -19,7 +19,7 @@
19
19
 
20
20
 
21
21
 
22
- var _chunkZ2ESFE5Zcjs = require('./chunk-Z2ESFE5Z.cjs');
22
+ var _chunkTWNMQDZKcjs = require('./chunk-TWNMQDZK.cjs');
23
23
  require('./chunk-4FC7TVS6.cjs');
24
24
 
25
25
 
@@ -42,5 +42,5 @@ require('./chunk-4FC7TVS6.cjs');
42
42
 
43
43
 
44
44
 
45
- exports.EXTRA_ERROR_LOG = _chunkZ2ESFE5Zcjs.EXTRA_ERROR_LOG; exports.SinglePromiseQueue = _chunkZ2ESFE5Zcjs.SinglePromiseQueue; exports.VERSION = _chunkZ2ESFE5Zcjs.VERSION; exports.arrayBuffersEqual = _chunkZ2ESFE5Zcjs.arrayBuffersEqual; exports.assertUnreachable = _chunkZ2ESFE5Zcjs.assertUnreachable; exports.bufferToArrayBuffer = _chunkZ2ESFE5Zcjs.bufferToArrayBuffer; exports.combineUrlPath = _chunkZ2ESFE5Zcjs.combineUrlPath; exports.dbg = _chunkZ2ESFE5Zcjs.dbg; exports.detectRuntime = _chunkZ2ESFE5Zcjs.detectRuntime; exports.getEnvUniversal = _chunkZ2ESFE5Zcjs.getEnvUniversal; exports.httpUserAgent = _chunkZ2ESFE5Zcjs.httpUserAgent; exports.interval = _chunkZ2ESFE5Zcjs.interval; exports.joinSignals = _chunkZ2ESFE5Zcjs.joinSignals; exports.jsonParseCompat = _chunkZ2ESFE5Zcjs.jsonParseCompat; exports.jsonStringifyCompat = _chunkZ2ESFE5Zcjs.jsonStringifyCompat; exports.promiseWithResolvers = _chunkZ2ESFE5Zcjs.promiseWithResolvers; exports.setLongTimeout = _chunkZ2ESFE5Zcjs.setLongTimeout; exports.sleep = _chunkZ2ESFE5Zcjs.sleep; exports.stringifyError = _chunkZ2ESFE5Zcjs.stringifyError; exports.toUint8Array = _chunkZ2ESFE5Zcjs.toUint8Array;
45
+ exports.EXTRA_ERROR_LOG = _chunkTWNMQDZKcjs.EXTRA_ERROR_LOG; exports.SinglePromiseQueue = _chunkTWNMQDZKcjs.SinglePromiseQueue; exports.VERSION = _chunkTWNMQDZKcjs.VERSION; exports.arrayBuffersEqual = _chunkTWNMQDZKcjs.arrayBuffersEqual; exports.assertUnreachable = _chunkTWNMQDZKcjs.assertUnreachable; exports.bufferToArrayBuffer = _chunkTWNMQDZKcjs.bufferToArrayBuffer; exports.combineUrlPath = _chunkTWNMQDZKcjs.combineUrlPath; exports.dbg = _chunkTWNMQDZKcjs.dbg; exports.detectRuntime = _chunkTWNMQDZKcjs.detectRuntime; exports.getEnvUniversal = _chunkTWNMQDZKcjs.getEnvUniversal; exports.httpUserAgent = _chunkTWNMQDZKcjs.httpUserAgent; exports.interval = _chunkTWNMQDZKcjs.interval; exports.joinSignals = _chunkTWNMQDZKcjs.joinSignals; exports.jsonParseCompat = _chunkTWNMQDZKcjs.jsonParseCompat; exports.jsonStringifyCompat = _chunkTWNMQDZKcjs.jsonStringifyCompat; exports.promiseWithResolvers = _chunkTWNMQDZKcjs.promiseWithResolvers; exports.setLongTimeout = _chunkTWNMQDZKcjs.setLongTimeout; exports.sleep = _chunkTWNMQDZKcjs.sleep; exports.stringifyError = _chunkTWNMQDZKcjs.stringifyError; exports.toUint8Array = _chunkTWNMQDZKcjs.toUint8Array;
46
46
  //# sourceMappingURL=utils.cjs.map
@@ -19,7 +19,7 @@ import {
19
19
  sleep,
20
20
  stringifyError,
21
21
  toUint8Array
22
- } from "./chunk-X7XY6NCU.js";
22
+ } from "./chunk-ET2F6BXK.js";
23
23
  import "./chunk-ZZ3WBRPD.js";
24
24
  export {
25
25
  EXTRA_ERROR_LOG,
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2;
2
2
 
3
- var _chunkU2A3Y7OKcjs = require('../chunk-U2A3Y7OK.cjs');
4
- require('../chunk-G6XA2OSW.cjs');
3
+ var _chunkXEOPXHN2cjs = require('../chunk-XEOPXHN2.cjs');
4
+ require('../chunk-K4DNAIWT.cjs');
5
5
 
6
6
 
7
7
 
@@ -12,7 +12,7 @@ var _chunkHNHLBM3Ycjs = require('../chunk-HNHLBM3Y.cjs');
12
12
  var _chunkMYWZCDMLcjs = require('../chunk-MYWZCDML.cjs');
13
13
 
14
14
 
15
- var _chunkZ2ESFE5Zcjs = require('../chunk-Z2ESFE5Z.cjs');
15
+ var _chunkTWNMQDZKcjs = require('../chunk-TWNMQDZK.cjs');
16
16
 
17
17
 
18
18
 
@@ -716,7 +716,7 @@ function workflow(fn, options = {}) {
716
716
  function getWorkflowInspector(actorId) {
717
717
  let workflowInspector = workflowInspectors.get(actorId);
718
718
  if (!workflowInspector) {
719
- workflowInspector = _chunkU2A3Y7OKcjs.createWorkflowInspectorAdapter.call(void 0, );
719
+ workflowInspector = _chunkXEOPXHN2cjs.createWorkflowInspectorAdapter.call(void 0, );
720
720
  workflowInspectors.set(actorId, workflowInspector);
721
721
  }
722
722
  return workflowInspector;
@@ -784,13 +784,13 @@ function workflow(fn, options = {}) {
784
784
  if (shouldRethrowWorkflowError(error)) {
785
785
  runCtx.log.error({
786
786
  msg: "workflow run failed",
787
- error: _chunkZ2ESFE5Zcjs.stringifyError.call(void 0, error)
787
+ error: _chunkTWNMQDZKcjs.stringifyError.call(void 0, error)
788
788
  });
789
789
  throw error;
790
790
  }
791
791
  runCtx.log.warn({
792
792
  msg: "workflow failed and will sleep until woken",
793
- error: _chunkZ2ESFE5Zcjs.stringifyError.call(void 0, error)
793
+ error: _chunkTWNMQDZKcjs.stringifyError.call(void 0, error)
794
794
  });
795
795
  } finally {
796
796
  runCtx.abortSignal.removeEventListener("abort", onAbort);
@@ -1,9 +1,9 @@
1
1
  import { WorkflowErrorEvent } from '@rivetkit/workflow-engine';
2
2
  export { Loop, TryBlockCatchKind, TryBlockConfig, TryBlockFailure, TryBlockResult, TryStepCatchKind, TryStepConfig, TryStepFailure, TryStepResult, WorkflowError, WorkflowErrorEvent } from '@rivetkit/workflow-engine';
3
- import { E as EventSchemaConfig, Q as QueueSchemaConfig, h as RunContext } from '../config-BobvQpex.cjs';
3
+ import { E as EventSchemaConfig, Q as QueueSchemaConfig, h as RunContext } from '../config-Caocy3Z9.cjs';
4
4
  import { A as AnyDatabaseProvider } from '../config-BxOimoGX.cjs';
5
- import { d as WorkflowContext } from '../context-YEBNJrws.cjs';
6
- export { e as WorkflowBranchConfig, W as WorkflowBranchContextOf, a as WorkflowContextOf, f as WorkflowLoopConfig, b as WorkflowLoopContextOf, g as WorkflowStepConfig, h as WorkflowStepContext, c as WorkflowStepContextOf, i as WorkflowTryConfig, j as WorkflowTryStepConfig } from '../context-YEBNJrws.cjs';
5
+ import { d as WorkflowContext } from '../context-D1_m5x1D.cjs';
6
+ export { e as WorkflowBranchConfig, W as WorkflowBranchContextOf, a as WorkflowContextOf, f as WorkflowLoopConfig, b as WorkflowLoopContextOf, g as WorkflowStepConfig, h as WorkflowStepContext, c as WorkflowStepContextOf, i as WorkflowTryConfig, j as WorkflowTryStepConfig } from '../context-D1_m5x1D.cjs';
7
7
  import 'zod/v4';
8
8
  import '@rivetkit/rivetkit-wasm';
9
9
  import 'zod';
@@ -1,9 +1,9 @@
1
1
  import { WorkflowErrorEvent } from '@rivetkit/workflow-engine';
2
2
  export { Loop, TryBlockCatchKind, TryBlockConfig, TryBlockFailure, TryBlockResult, TryStepCatchKind, TryStepConfig, TryStepFailure, TryStepResult, WorkflowError, WorkflowErrorEvent } from '@rivetkit/workflow-engine';
3
- import { E as EventSchemaConfig, Q as QueueSchemaConfig, h as RunContext } from '../config-BRpVbJCD.js';
3
+ import { E as EventSchemaConfig, Q as QueueSchemaConfig, h as RunContext } from '../config-BKAMOHez.js';
4
4
  import { A as AnyDatabaseProvider } from '../config-BxOimoGX.js';
5
- import { d as WorkflowContext } from '../context-Cj-DFyiy.js';
6
- export { e as WorkflowBranchConfig, W as WorkflowBranchContextOf, a as WorkflowContextOf, f as WorkflowLoopConfig, b as WorkflowLoopContextOf, g as WorkflowStepConfig, h as WorkflowStepContext, c as WorkflowStepContextOf, i as WorkflowTryConfig, j as WorkflowTryStepConfig } from '../context-Cj-DFyiy.js';
5
+ import { d as WorkflowContext } from '../context-AfCExwbr.js';
6
+ export { e as WorkflowBranchConfig, W as WorkflowBranchContextOf, a as WorkflowContextOf, f as WorkflowLoopConfig, b as WorkflowLoopContextOf, g as WorkflowStepConfig, h as WorkflowStepContext, c as WorkflowStepContextOf, i as WorkflowTryConfig, j as WorkflowTryStepConfig } from '../context-AfCExwbr.js';
7
7
  import 'zod/v4';
8
8
  import '@rivetkit/rivetkit-wasm';
9
9
  import 'zod';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createWorkflowInspectorAdapter
3
- } from "../chunk-E6IEX6AP.js";
4
- import "../chunk-XSPAARQ5.js";
3
+ } from "../chunk-5ZS22TOP.js";
4
+ import "../chunk-6ZPMYIZ6.js";
5
5
  import {
6
6
  ACTOR_CONTEXT_INTERNAL_SYMBOL,
7
7
  RUN_FUNCTION_CONFIG_SYMBOL
@@ -12,7 +12,7 @@ import {
12
12
  } from "../chunk-JI6GZ2C2.js";
13
13
  import {
14
14
  stringifyError
15
- } from "../chunk-X7XY6NCU.js";
15
+ } from "../chunk-ET2F6BXK.js";
16
16
  import {
17
17
  RivetError,
18
18
  isActorAbortedError
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rivetkit",
3
- "version": "2.3.10",
3
+ "version": "2.3.11-rc.1",
4
4
  "description": "Lightweight libraries for building stateful actors on edge platforms",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -201,14 +201,14 @@
201
201
  "@hono/zod-openapi": "^1.1.5",
202
202
  "@rivet-dev/agent-os-core": "^0.1.1",
203
203
  "@rivetkit/bare-ts": "^0.6.2",
204
- "@rivetkit/engine-cli": "2.3.10",
205
- "@rivetkit/engine-envoy-protocol": "2.3.10",
204
+ "@rivetkit/engine-cli": "2.3.11-rc.1",
205
+ "@rivetkit/engine-envoy-protocol": "2.3.11-rc.1",
206
206
  "@rivetkit/on-change": "6.0.1",
207
- "@rivetkit/rivetkit-napi": "2.3.10",
208
- "@rivetkit/rivetkit-wasm": "2.3.10",
209
- "@rivetkit/traces": "2.3.10",
210
- "@rivetkit/virtual-websocket": "2.3.10",
211
- "@rivetkit/workflow-engine": "2.3.10",
207
+ "@rivetkit/rivetkit-napi": "2.3.11-rc.1",
208
+ "@rivetkit/rivetkit-wasm": "2.3.11-rc.1",
209
+ "@rivetkit/traces": "2.3.11-rc.1",
210
+ "@rivetkit/virtual-websocket": "2.3.11-rc.1",
211
+ "@rivetkit/workflow-engine": "2.3.11-rc.1",
212
212
  "cbor-x": "^1.6.0",
213
213
  "drizzle-orm": "^0.44.2",
214
214
  "hono": "^4.7.0",
@@ -3,6 +3,7 @@ import {
3
3
  PATH_WEBSOCKET_PREFIX,
4
4
  } from "@/common/actor-router-consts";
5
5
  import { deconstructError } from "@/common/utils";
6
+ import { isRequestLike, isUrlLike } from "@/common/fetch-like";
6
7
  import type {
7
8
  EngineControlClient,
8
9
  GatewayRequestOptions,
@@ -28,9 +29,9 @@ export async function rawHttpFetch(
28
29
 
29
30
  if (typeof input === "string") {
30
31
  path = input;
31
- } else if (input instanceof URL) {
32
+ } else if (isUrlLike(input)) {
32
33
  path = input.pathname + input.search;
33
- } else if (input instanceof Request) {
34
+ } else if (isRequestLike(input)) {
34
35
  // Extract path from Request URL
35
36
  const url = new URL(input.url);
36
37
  path = url.pathname + url.search;
@@ -484,7 +484,10 @@ export function jsonStringifyCompat(
484
484
  return [JSON_COMPAT_BIGINT, value.toString()];
485
485
  }
486
486
  if (value instanceof ArrayBuffer) {
487
- return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(value)];
487
+ return [
488
+ JSON_COMPAT_ARRAY_BUFFER,
489
+ base64EncodeArrayBuffer(value),
490
+ ];
488
491
  }
489
492
  if (value instanceof Uint8Array) {
490
493
  return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
@@ -0,0 +1,49 @@
1
+ type HeadersLike = {
2
+ entries(): IterableIterator<[string, string]>;
3
+ };
4
+
5
+ export type RequestLike = Request & {
6
+ readonly headers: HeadersLike & Request["headers"];
7
+ };
8
+
9
+ export type ResponseLike = Response & {
10
+ readonly headers: HeadersLike & Response["headers"];
11
+ };
12
+
13
+ export function isUrlLike(value: unknown): value is URL {
14
+ return (
15
+ typeof value === "object" &&
16
+ value !== null &&
17
+ typeof (value as URL).href === "string" &&
18
+ typeof (value as URL).pathname === "string" &&
19
+ typeof (value as URL).search === "string"
20
+ );
21
+ }
22
+
23
+ export function isRequestLike(value: unknown): value is RequestLike {
24
+ return (
25
+ typeof value === "object" &&
26
+ value !== null &&
27
+ typeof (value as Request).url === "string" &&
28
+ typeof (value as Request).method === "string" &&
29
+ isHeadersLike((value as Request).headers)
30
+ );
31
+ }
32
+
33
+ export function isResponseLike(value: unknown): value is ResponseLike {
34
+ return (
35
+ typeof value === "object" &&
36
+ value !== null &&
37
+ typeof (value as Response).status === "number" &&
38
+ isHeadersLike((value as Response).headers) &&
39
+ typeof (value as Response).arrayBuffer === "function"
40
+ );
41
+ }
42
+
43
+ function isHeadersLike(value: unknown): value is HeadersLike {
44
+ return (
45
+ typeof value === "object" &&
46
+ value !== null &&
47
+ typeof (value as HeadersLike).entries === "function"
48
+ );
49
+ }
@@ -1,4 +1,5 @@
1
1
  import { isLocalEngineEndpoint } from "@/common/engine";
2
+ import { isResponseLike } from "@/common/fetch-like";
2
3
  import { configureBaseLogger } from "@/common/log";
3
4
  import { configureServerlessPool } from "@/serverless/configure";
4
5
  import { VERSION } from "@/utils";
@@ -15,7 +16,10 @@ import {
15
16
  } from "./config";
16
17
  import { logger } from "./log";
17
18
  import { buildConfiguredRegistry } from "./native";
18
- import type { RuntimeServerlessResponseHead } from "./runtime";
19
+ import type {
20
+ RuntimeApplicationFetch,
21
+ RuntimeServerlessResponseHead,
22
+ } from "./runtime";
19
23
 
20
24
  type ShutdownSignal = "SIGINT" | "SIGTERM";
21
25
 
@@ -37,6 +41,35 @@ function finishShutdownSignal(signal: ShutdownSignal): void {
37
41
  process.kill(process.pid, signal);
38
42
  }
39
43
 
44
+ function createApplicationFetch(
45
+ application: RegistryApplication,
46
+ ): RuntimeApplicationFetch {
47
+ return async (request) => {
48
+ const method = request.method.toUpperCase();
49
+ const body =
50
+ method === "GET" || method === "HEAD" || request.body.length === 0
51
+ ? undefined
52
+ : Uint8Array.from(request.body).buffer;
53
+ const response = await application.fetch(
54
+ new Request(request.url, {
55
+ method,
56
+ headers: request.headers,
57
+ body,
58
+ }),
59
+ );
60
+ if (!isResponseLike(response)) {
61
+ throw new TypeError(
62
+ "registry.listen() application fetch must return a Response",
63
+ );
64
+ }
65
+ return {
66
+ status: response.status,
67
+ headers: Object.fromEntries(response.headers.entries()),
68
+ body: new Uint8Array(await response.arrayBuffer()),
69
+ };
70
+ };
71
+ }
72
+
40
73
  export type FetchHandler = (
41
74
  request: Request,
42
75
  ...args: any
@@ -46,6 +79,17 @@ export interface ServerlessHandler {
46
79
  fetch: FetchHandler;
47
80
  }
48
81
 
82
+ export interface RegistryApplication {
83
+ fetch: FetchHandler;
84
+ }
85
+
86
+ export interface RegistryListenOptions {
87
+ port?: number;
88
+ host?: string;
89
+ publicDir?: string;
90
+ application?: RegistryApplication;
91
+ }
92
+
49
93
  export interface RegistryRoutes {
50
94
  health(): Promise<Response>;
51
95
  metadata(): Promise<Response>;
@@ -79,6 +123,7 @@ export class Registry<A extends RegistryActors> {
79
123
  #runtimeReadyPromise?: Promise<void>;
80
124
  #runtimeServeConfiguredPromise?: ReturnType<typeof buildConfiguredRegistry>;
81
125
  #runtimeServerlessPromise?: ReturnType<typeof buildConfiguredRegistry>;
126
+ #applicationListenerPromise?: Promise<void>;
82
127
  #configureServerlessPoolPromise?: Promise<void>;
83
128
  #welcomePrinted = false;
84
129
  #shutdownInstalled = false;
@@ -348,19 +393,68 @@ export class Registry<A extends RegistryActors> {
348
393
  * @param opts.host Address to bind. Defaults to `0.0.0.0`.
349
394
  * @param opts.publicDir If set, serves static files from this directory
350
395
  * as a fallback below the framework routes.
396
+ * @param opts.application If set, handles requests that do not match a
397
+ * framework route.
351
398
  *
352
399
  * @example
353
400
  * ```ts
354
401
  * await registry.listen();
355
- * await registry.listen({ port: 8080, publicDir: "./public" });
402
+ * await registry.listen({ application: app });
356
403
  * ```
357
404
  */
358
- public async listen(
359
- opts: { port?: number; host?: string; publicDir?: string } = {},
360
- ): Promise<void> {
405
+ public async listen(opts: RegistryListenOptions = {}): Promise<void> {
361
406
  const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3000;
362
407
  const publicDir = opts.publicDir ?? getRivetkitPublicDir();
363
408
  const config = this.parseConfig();
409
+ const application = opts.application
410
+ ? createApplicationFetch(opts.application)
411
+ : undefined;
412
+
413
+ if (application && getRivetkitRuntimeMode() !== "serverless") {
414
+ if (config.runtime === "wasm") {
415
+ throw new Error(
416
+ "registry.listen() requires the native runtime; use an application-owned HTTP server with WebAssembly",
417
+ );
418
+ }
419
+ this.#installSignalHandlers(config);
420
+ this.#printWelcome(config, "serverful", {
421
+ port,
422
+ host: opts.host,
423
+ publicDir,
424
+ });
425
+ this.#startEnvoy(config, true);
426
+ const readyPromise = this.startAndWait();
427
+ const configuredRegistryPromise =
428
+ this.#runtimeServeConfiguredPromise;
429
+ if (!configuredRegistryPromise) {
430
+ throw new Error("registry envoy startup did not initialize");
431
+ }
432
+ const { runtime, registry, serveConfig } =
433
+ await configuredRegistryPromise;
434
+ const listenerPromise = runtime.serveApplicationListener(
435
+ registry,
436
+ {
437
+ port,
438
+ host: opts.host,
439
+ publicDir,
440
+ application,
441
+ },
442
+ serveConfig,
443
+ );
444
+ this.#applicationListenerPromise = listenerPromise;
445
+ const serveLifecyclePromise = this.#runtimeServeLifecyclePromise;
446
+ if (!serveLifecyclePromise) {
447
+ throw new Error(
448
+ "registry envoy serve lifecycle did not initialize",
449
+ );
450
+ }
451
+ await Promise.all([
452
+ readyPromise,
453
+ listenerPromise,
454
+ serveLifecyclePromise,
455
+ ]);
456
+ return;
457
+ }
364
458
 
365
459
  // Cache on both promise fields so the shutdown drain sees Mode A and B.
366
460
  const configuredRegistryPromise = buildConfiguredRegistry(config);
@@ -381,7 +475,12 @@ export class Registry<A extends RegistryActors> {
381
475
  await configuredRegistryPromise;
382
476
  await runtime.serveListener(
383
477
  registry,
384
- { port, host: opts.host, publicDir },
478
+ {
479
+ port,
480
+ host: opts.host,
481
+ publicDir,
482
+ application,
483
+ },
385
484
  serveConfig,
386
485
  );
387
486
  }
@@ -499,15 +598,14 @@ export class Registry<A extends RegistryActors> {
499
598
  await runtime.serveRegistry(registry, serveConfig);
500
599
  },
501
600
  );
502
- this.#runtimeServePromise = this.#runtimeServeLifecyclePromise.catch(
503
- (error) => {
601
+ this.#runtimeServePromise =
602
+ this.#runtimeServeLifecyclePromise.catch((error) => {
504
603
  // Always-attached catch so the stored promise never leaves a
505
604
  // rejection unhandled. Downstream awaits (e.g. #runShutdown's
506
605
  // Promise.race) attach their own catches and still observe
507
606
  // resolution via the race.
508
607
  logger().warn({ error }, "runtime registry serve errored");
509
- },
510
- );
608
+ });
511
609
  // Install signal handlers once an envoy lifecycle has begun. Only
512
610
  // Mode A ever reaches here. Mode B (handler(request)) intentionally
513
611
  // does not install handlers because it runs on Workers/Vercel/Deno
@@ -653,6 +751,9 @@ export class Registry<A extends RegistryActors> {
653
751
  // already logged any serve-side error.
654
752
  await runtimeServePromise.catch(() => undefined);
655
753
  }
754
+ if (this.#applicationListenerPromise !== undefined) {
755
+ await this.#applicationListenerPromise.catch(() => undefined);
756
+ }
656
757
  };
657
758
  await Promise.race([
658
759
  drain(),
@@ -712,7 +813,9 @@ export class Registry<A extends RegistryActors> {
712
813
  public startAndWait(): Promise<void> {
713
814
  if (this.#shutdownInFlight !== null) {
714
815
  return Promise.reject(
715
- new Error("registry.startAndWait() cannot run after shutdown has begun"),
816
+ new Error(
817
+ "registry.startAndWait() cannot run after shutdown has begun",
818
+ ),
716
819
  );
717
820
  }
718
821
  if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
@@ -755,7 +858,9 @@ export class Registry<A extends RegistryActors> {
755
858
  const readinessPromise = (async () => {
756
859
  const { runtime, registry } = await configuredRegistryPromise;
757
860
  const stoppedBeforeReady = serveLifecyclePromise.then(() => {
758
- throw new Error("RivetKit registry stopped before becoming ready");
861
+ throw new Error(
862
+ "RivetKit registry stopped before becoming ready",
863
+ );
759
864
  });
760
865
  await Promise.race([
761
866
  runtime.waitRegistryReady(registry),
@@ -14,6 +14,8 @@ import type {
14
14
  CoreRuntime,
15
15
  RegistryHandle,
16
16
  RuntimeActorConfig,
17
+ RuntimeApplicationFetch,
18
+ RuntimeApplicationListenerConfig,
17
19
  RuntimeBytes,
18
20
  RuntimeCronFire,
19
21
  RuntimeCronJobInfo,
@@ -135,6 +137,31 @@ function toNapiBuffer(value: RuntimeBytes): Buffer {
135
137
  return Buffer.from(value);
136
138
  }
137
139
 
140
+ function toNapiApplication(application: RuntimeApplicationFetch) {
141
+ return async (
142
+ error: unknown,
143
+ request?: {
144
+ method: string;
145
+ url: string;
146
+ headers: Record<string, string>;
147
+ body: Buffer;
148
+ },
149
+ ) => {
150
+ if (error) throw error;
151
+ if (!request) {
152
+ throw new Error("application fetch callback received no request");
153
+ }
154
+ const response = await application({
155
+ ...request,
156
+ body: new Uint8Array(request.body),
157
+ });
158
+ return {
159
+ ...response,
160
+ body: toNapiBuffer(response.body),
161
+ };
162
+ };
163
+ }
164
+
138
165
  function toNapiHttpRequest(
139
166
  request?: RuntimeHttpRequest | undefined | null,
140
167
  ): Parameters<NativeActorContext["connectConn"]>[1] {
@@ -296,6 +323,9 @@ export class NapiCoreRuntime implements CoreRuntime {
296
323
  listener: RuntimeListenerConfig,
297
324
  config: RuntimeServeConfig,
298
325
  ): Promise<void> {
326
+ const application = listener.application
327
+ ? toNapiApplication(listener.application)
328
+ : undefined;
299
329
  await asNativeRegistry(registry).serveListener(
300
330
  {
301
331
  port: listener.port,
@@ -303,6 +333,23 @@ export class NapiCoreRuntime implements CoreRuntime {
303
333
  publicDir: listener.publicDir,
304
334
  },
305
335
  config,
336
+ application,
337
+ );
338
+ }
339
+
340
+ async serveApplicationListener(
341
+ registry: RegistryHandle,
342
+ listener: RuntimeApplicationListenerConfig,
343
+ config: RuntimeServeConfig,
344
+ ): Promise<void> {
345
+ await asNativeRegistry(registry).serveApplicationListener(
346
+ {
347
+ port: listener.port,
348
+ host: listener.host,
349
+ publicDir: listener.publicDir,
350
+ },
351
+ toNapiApplication(listener.application),
352
+ config,
306
353
  );
307
354
  }
308
355
 
@@ -47,6 +47,7 @@ import { HEADER_CONN_PARAMS } from "@/common/actor-router-consts";
47
47
  import type { AnyDatabaseProvider } from "@/common/database/config";
48
48
  import { wrapJsNativeDatabase } from "@/common/database/native-database";
49
49
  import { assertJsonCompatValue, type JsonCompatValue } from "@/common/encoding";
50
+ import { isResponseLike, type ResponseLike } from "@/common/fetch-like";
50
51
  import { decodeWorkflowHistoryTransport } from "@/common/inspector-transport";
51
52
  import { deconstructError, stringifyError } from "@/common/utils";
52
53
  import type {
@@ -1183,7 +1184,7 @@ function buildRequest(init: {
1183
1184
  }
1184
1185
 
1185
1186
  async function toRuntimeHttpResponse(
1186
- response: Response,
1187
+ response: ResponseLike,
1187
1188
  ): Promise<RuntimeHttpResponse> {
1188
1189
  const headers = Object.fromEntries(response.headers.entries());
1189
1190
  const body = new Uint8Array(await response.arrayBuffer());
@@ -4717,7 +4718,7 @@ export function buildNativeFactory(
4717
4718
  requestCtx,
4718
4719
  jsRequest,
4719
4720
  );
4720
- if (!(response instanceof Response)) {
4721
+ if (!isResponseLike(response)) {
4721
4722
  throw new Error(
4722
4723
  "onRequest handler must return a Response",
4723
4724
  );
@@ -346,6 +346,7 @@ export interface RuntimeListenerConfig {
346
346
  port: number;
347
347
  host?: string;
348
348
  publicDir?: string;
349
+ application?: RuntimeApplicationFetch;
349
350
  }
350
351
 
351
352
  export interface RuntimeServerlessRequest {
@@ -355,6 +356,21 @@ export interface RuntimeServerlessRequest {
355
356
  body: RuntimeBytes;
356
357
  }
357
358
 
359
+ export interface RuntimeApplicationResponse {
360
+ status: number;
361
+ headers: Record<string, string>;
362
+ body: RuntimeBytes;
363
+ }
364
+
365
+ export type RuntimeApplicationFetch = (
366
+ request: RuntimeServerlessRequest,
367
+ ) => Promise<RuntimeApplicationResponse>;
368
+
369
+ export interface RuntimeApplicationListenerConfig
370
+ extends RuntimeListenerConfig {
371
+ application: RuntimeApplicationFetch;
372
+ }
373
+
358
374
  export interface RuntimeServerlessResponseHead {
359
375
  status: number;
360
376
  headers: Record<string, string>;
@@ -429,6 +445,11 @@ export interface CoreRuntime {
429
445
  listener: RuntimeListenerConfig,
430
446
  config: RuntimeServeConfig,
431
447
  ): Promise<void>;
448
+ serveApplicationListener(
449
+ registry: RegistryHandle,
450
+ listener: RuntimeApplicationListenerConfig,
451
+ config: RuntimeServeConfig,
452
+ ): Promise<void>;
432
453
  registryHealth?(
433
454
  registry: RegistryHandle,
434
455
  ): Promise<RuntimeRegistryRouteResponse>;