rivetkit 2.3.10 → 2.3.11-rc.2
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 +24 -6
- package/dist/browser/client.js +20 -5
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +1 -1
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +24 -6
- package/dist/tsup/agent-os/index.d.ts +24 -6
- package/dist/tsup/agent-os/index.js +1 -1
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-LCWHS6K7.cjs → chunk-3NPCXMJS.cjs} +158 -142
- package/dist/tsup/chunk-3NPCXMJS.cjs.map +1 -0
- package/dist/tsup/{chunk-Z2ESFE5Z.cjs → chunk-5SHK4JM5.cjs} +6 -3
- package/dist/tsup/chunk-5SHK4JM5.cjs.map +1 -0
- package/dist/tsup/{chunk-E6IEX6AP.js → chunk-75K5VACB.js} +3 -3
- package/dist/tsup/{chunk-G6XA2OSW.cjs → chunk-7TVKYMD3.cjs} +4 -4
- package/dist/tsup/{chunk-G6XA2OSW.cjs.map → chunk-7TVKYMD3.cjs.map} +1 -1
- package/dist/tsup/{chunk-U2A3Y7OK.cjs → chunk-J4RT6EFK.cjs} +9 -9
- package/dist/tsup/{chunk-U2A3Y7OK.cjs.map → chunk-J4RT6EFK.cjs.map} +1 -1
- package/dist/tsup/{chunk-6UHZLL6S.js → chunk-KHSNHG4G.js} +3 -3
- package/dist/tsup/{chunk-INXPYXN6.cjs → chunk-LPGJPAVY.cjs} +7 -7
- package/dist/tsup/{chunk-INXPYXN6.cjs.map → chunk-LPGJPAVY.cjs.map} +1 -1
- package/dist/tsup/{chunk-XSPAARQ5.js → chunk-NLAW2MIM.js} +2 -2
- package/dist/tsup/{chunk-PCJSDS7N.cjs → chunk-NRRWLN6D.cjs} +3 -3
- package/dist/tsup/{chunk-PCJSDS7N.cjs.map → chunk-NRRWLN6D.cjs.map} +1 -1
- package/dist/tsup/{chunk-Q5H37KNQ.js → chunk-RVJQMOAA.js} +2 -2
- package/dist/tsup/{chunk-DPM73GAL.js → chunk-XR2KF2ZA.js} +22 -6
- package/dist/tsup/chunk-XR2KF2ZA.js.map +1 -0
- package/dist/tsup/{chunk-X7XY6NCU.js → chunk-XWIXH7JF.js} +6 -3
- package/dist/tsup/chunk-XWIXH7JF.js.map +1 -0
- package/dist/tsup/client/mod.cjs +5 -5
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +4 -4
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-BRpVbJCD.d.ts → config-BKAMOHez.d.ts} +25 -7
- package/dist/tsup/{config-BobvQpex.d.cts → config-Caocy3Z9.d.cts} +25 -7
- package/dist/tsup/{context-Cj-DFyiy.d.ts → context-AfCExwbr.d.ts} +1 -1
- package/dist/tsup/{context-YEBNJrws.d.cts → context-D1_m5x1D.d.cts} +1 -1
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +2 -2
- package/dist/tsup/db/mod.js +1 -1
- package/dist/tsup/dynamic/mod.d.cts +1 -1
- package/dist/tsup/dynamic/mod.d.ts +1 -1
- package/dist/tsup/inspector/mod.cjs +4 -4
- package/dist/tsup/inspector/mod.js +3 -3
- package/dist/tsup/inspector-tab/mod.d.cts +2 -2
- package/dist/tsup/inspector-tab/mod.d.ts +2 -2
- package/dist/tsup/mod.cjs +187 -72
- 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 +129 -14
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +6 -6
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +4 -4
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +6 -6
- package/dist/tsup/workflow/mod.d.cts +3 -3
- package/dist/tsup/workflow/mod.d.ts +3 -3
- package/dist/tsup/workflow/mod.js +3 -3
- package/package.json +8 -8
- package/src/client/actor-conn.ts +1 -1
- package/src/client/raw-utils.ts +3 -2
- package/src/common/encoding.ts +4 -1
- package/src/common/fetch-like.ts +49 -0
- package/src/registry/index.ts +117 -12
- package/src/registry/napi-runtime.ts +47 -0
- package/src/registry/native.ts +3 -2
- package/src/registry/runtime.ts +21 -0
- package/src/registry/wasm-runtime.ts +11 -0
- package/dist/tsup/chunk-DPM73GAL.js.map +0 -1
- package/dist/tsup/chunk-LCWHS6K7.cjs.map +0 -1
- package/dist/tsup/chunk-X7XY6NCU.js.map +0 -1
- package/dist/tsup/chunk-Z2ESFE5Z.cjs.map +0 -1
- /package/dist/tsup/{chunk-E6IEX6AP.js.map → chunk-75K5VACB.js.map} +0 -0
- /package/dist/tsup/{chunk-6UHZLL6S.js.map → chunk-KHSNHG4G.js.map} +0 -0
- /package/dist/tsup/{chunk-XSPAARQ5.js.map → chunk-NLAW2MIM.js.map} +0 -0
- /package/dist/tsup/{chunk-Q5H37KNQ.js.map → chunk-RVJQMOAA.js.map} +0 -0
package/dist/tsup/test/mod.cjs
CHANGED
|
@@ -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
|
|
3
|
+
var _chunkLPGJPAVYcjs = require('../chunk-LPGJPAVY.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk3NPCXMJScjs = require('../chunk-3NPCXMJS.cjs');
|
|
7
7
|
require('../chunk-MYWZCDML.cjs');
|
|
8
8
|
require('../chunk-UEULFXUI.cjs');
|
|
9
|
-
require('../chunk-
|
|
10
|
-
require('../chunk-
|
|
9
|
+
require('../chunk-NRRWLN6D.cjs');
|
|
10
|
+
require('../chunk-5SHK4JM5.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 =
|
|
40
|
-
...
|
|
39
|
+
const client = _chunkLPGJPAVYcjs.createClient.call(void 0, {
|
|
40
|
+
..._chunk3NPCXMJScjs.convertRegistryConfigToClientConfig.call(void 0, registry.parseConfig()),
|
|
41
41
|
disableMetadataLookup: false
|
|
42
42
|
});
|
|
43
43
|
c.onTestFinished(async () => {
|
package/dist/tsup/test/mod.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TestContext } from 'vitest';
|
|
2
|
-
import { aC as Registry, a2 as Client } from '../config-
|
|
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';
|
package/dist/tsup/test/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TestContext } from 'vitest';
|
|
2
|
-
import { aC as Registry, a2 as Client } from '../config-
|
|
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';
|
package/dist/tsup/test/mod.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createClient
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-KHSNHG4G.js";
|
|
4
4
|
import {
|
|
5
5
|
convertRegistryConfigToClientConfig
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-XR2KF2ZA.js";
|
|
7
7
|
import "../chunk-JI6GZ2C2.js";
|
|
8
8
|
import "../chunk-7AFZMFPQ.js";
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-RVJQMOAA.js";
|
|
10
|
+
import "../chunk-XWIXH7JF.js";
|
|
11
11
|
import "../chunk-ZZ3WBRPD.js";
|
|
12
12
|
|
|
13
13
|
// src/test/ready.ts
|
package/dist/tsup/utils.cjs
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var _chunk5SHK4JM5cjs = require('./chunk-5SHK4JM5.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 =
|
|
45
|
+
exports.EXTRA_ERROR_LOG = _chunk5SHK4JM5cjs.EXTRA_ERROR_LOG; exports.SinglePromiseQueue = _chunk5SHK4JM5cjs.SinglePromiseQueue; exports.VERSION = _chunk5SHK4JM5cjs.VERSION; exports.arrayBuffersEqual = _chunk5SHK4JM5cjs.arrayBuffersEqual; exports.assertUnreachable = _chunk5SHK4JM5cjs.assertUnreachable; exports.bufferToArrayBuffer = _chunk5SHK4JM5cjs.bufferToArrayBuffer; exports.combineUrlPath = _chunk5SHK4JM5cjs.combineUrlPath; exports.dbg = _chunk5SHK4JM5cjs.dbg; exports.detectRuntime = _chunk5SHK4JM5cjs.detectRuntime; exports.getEnvUniversal = _chunk5SHK4JM5cjs.getEnvUniversal; exports.httpUserAgent = _chunk5SHK4JM5cjs.httpUserAgent; exports.interval = _chunk5SHK4JM5cjs.interval; exports.joinSignals = _chunk5SHK4JM5cjs.joinSignals; exports.jsonParseCompat = _chunk5SHK4JM5cjs.jsonParseCompat; exports.jsonStringifyCompat = _chunk5SHK4JM5cjs.jsonStringifyCompat; exports.promiseWithResolvers = _chunk5SHK4JM5cjs.promiseWithResolvers; exports.setLongTimeout = _chunk5SHK4JM5cjs.setLongTimeout; exports.sleep = _chunk5SHK4JM5cjs.sleep; exports.stringifyError = _chunk5SHK4JM5cjs.stringifyError; exports.toUint8Array = _chunk5SHK4JM5cjs.toUint8Array;
|
|
46
46
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/tsup/utils.js
CHANGED
|
@@ -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
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkJ4RT6EFKcjs = require('../chunk-J4RT6EFK.cjs');
|
|
4
|
+
require('../chunk-7TVKYMD3.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
|
|
15
|
+
var _chunk5SHK4JM5cjs = require('../chunk-5SHK4JM5.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 =
|
|
719
|
+
workflowInspector = _chunkJ4RT6EFKcjs.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:
|
|
787
|
+
error: _chunk5SHK4JM5cjs.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:
|
|
793
|
+
error: _chunk5SHK4JM5cjs.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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-75K5VACB.js";
|
|
4
|
+
import "../chunk-NLAW2MIM.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-
|
|
15
|
+
} from "../chunk-XWIXH7JF.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.
|
|
3
|
+
"version": "2.3.11-rc.2",
|
|
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.
|
|
205
|
-
"@rivetkit/engine-envoy-protocol": "2.3.
|
|
204
|
+
"@rivetkit/engine-cli": "2.3.11-rc.2",
|
|
205
|
+
"@rivetkit/engine-envoy-protocol": "2.3.11-rc.2",
|
|
206
206
|
"@rivetkit/on-change": "6.0.1",
|
|
207
|
-
"@rivetkit/rivetkit-napi": "2.3.
|
|
208
|
-
"@rivetkit/rivetkit-wasm": "2.3.
|
|
209
|
-
"@rivetkit/traces": "2.3.
|
|
210
|
-
"@rivetkit/virtual-websocket": "2.3.
|
|
211
|
-
"@rivetkit/workflow-engine": "2.3.
|
|
207
|
+
"@rivetkit/rivetkit-napi": "2.3.11-rc.2",
|
|
208
|
+
"@rivetkit/rivetkit-wasm": "2.3.11-rc.2",
|
|
209
|
+
"@rivetkit/traces": "2.3.11-rc.2",
|
|
210
|
+
"@rivetkit/virtual-websocket": "2.3.11-rc.2",
|
|
211
|
+
"@rivetkit/workflow-engine": "2.3.11-rc.2",
|
|
212
212
|
"cbor-x": "^1.6.0",
|
|
213
213
|
"drizzle-orm": "^0.44.2",
|
|
214
214
|
"hono": "^4.7.0",
|
package/src/client/actor-conn.ts
CHANGED
package/src/client/raw-utils.ts
CHANGED
|
@@ -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
|
|
32
|
+
} else if (isUrlLike(input)) {
|
|
32
33
|
path = input.pathname + input.search;
|
|
33
|
-
} else if (input
|
|
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;
|
package/src/common/encoding.ts
CHANGED
|
@@ -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 [
|
|
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
|
+
}
|
package/src/registry/index.ts
CHANGED
|
@@ -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 {
|
|
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({
|
|
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
|
-
{
|
|
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 =
|
|
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(
|
|
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(
|
|
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
|
|
package/src/registry/native.ts
CHANGED
|
@@ -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:
|
|
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
|
|
4721
|
+
if (!isResponseLike(response)) {
|
|
4721
4722
|
throw new Error(
|
|
4722
4723
|
"onRequest handler must return a Response",
|
|
4723
4724
|
);
|
package/src/registry/runtime.ts
CHANGED
|
@@ -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>;
|