rivetkit 2.0.9 → 2.0.10
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/tsup/{chunk-APHV6WXU.js → chunk-346X2XU4.js} +2 -2
- package/dist/tsup/{chunk-DLPIL3VC.js → chunk-7E5K3375.js} +2 -2
- package/dist/tsup/{chunk-SOC4HWCG.cjs → chunk-CA3X5M6H.cjs} +92 -39
- package/dist/tsup/{chunk-VVCL5DXN.js.map → chunk-CA3X5M6H.cjs.map} +1 -1
- package/dist/tsup/{chunk-2MJYYF2Q.cjs → chunk-DVPXSB4B.cjs} +12 -12
- package/dist/tsup/{chunk-2MJYYF2Q.cjs.map → chunk-DVPXSB4B.cjs.map} +1 -1
- package/dist/tsup/{chunk-U2IXX6DY.cjs → chunk-GIFHYL7A.cjs} +5 -6
- package/dist/tsup/chunk-GIFHYL7A.cjs.map +1 -0
- package/dist/tsup/{chunk-KHZ2QSQ4.js → chunk-H7E2UU23.js} +32 -10
- package/dist/tsup/chunk-H7E2UU23.js.map +1 -0
- package/dist/tsup/{chunk-E63WU5PL.js → chunk-HI55LHM3.js} +5 -6
- package/dist/tsup/chunk-HI55LHM3.js.map +1 -0
- package/dist/tsup/{chunk-SDXTJDDR.cjs → chunk-I3FB346I.cjs} +58 -14
- package/dist/tsup/chunk-I3FB346I.cjs.map +1 -0
- package/dist/tsup/{chunk-WBSPHV5V.js → chunk-KGDZYQYE.js} +2 -2
- package/dist/tsup/{chunk-A44TWAS5.cjs → chunk-KH5WFDUK.cjs} +6 -6
- package/dist/tsup/{chunk-A44TWAS5.cjs.map → chunk-KH5WFDUK.cjs.map} +1 -1
- package/dist/tsup/{chunk-YR2VY4XS.js → chunk-KL4V2ULR.js} +5 -4
- package/dist/tsup/chunk-KL4V2ULR.js.map +1 -0
- package/dist/tsup/{chunk-R7OP5N25.js → chunk-MLQIYKAZ.js} +53 -9
- package/dist/tsup/chunk-MLQIYKAZ.js.map +1 -0
- package/dist/tsup/{chunk-F2YZNUPU.js → chunk-N3A5GYJU.js} +3 -3
- package/dist/tsup/{chunk-4YV6RDZL.cjs → chunk-PDFL7FBL.cjs} +698 -358
- package/dist/tsup/chunk-PDFL7FBL.cjs.map +1 -0
- package/dist/tsup/{chunk-DZZQG7VH.cjs → chunk-PPLR53PP.cjs} +3 -3
- package/dist/tsup/{chunk-DZZQG7VH.cjs.map → chunk-PPLR53PP.cjs.map} +1 -1
- package/dist/tsup/{chunk-7OMMIAWP.cjs → chunk-PSCDCEXM.cjs} +17 -12
- package/dist/tsup/chunk-PSCDCEXM.cjs.map +1 -0
- package/dist/tsup/{chunk-VVCL5DXN.js → chunk-QRFXXTLG.js} +96 -43
- package/dist/tsup/chunk-QRFXXTLG.js.map +1 -0
- package/dist/tsup/{chunk-WRSWUDFA.js → chunk-R2S45MO6.js} +14 -9
- package/dist/tsup/chunk-R2S45MO6.js.map +1 -0
- package/dist/tsup/{chunk-QGRYH6TU.cjs → chunk-SIWYIRXP.cjs} +7 -6
- package/dist/tsup/chunk-SIWYIRXP.cjs.map +1 -0
- package/dist/tsup/{chunk-FZP2IBIX.js → chunk-VJRXZPTT.js} +579 -239
- package/dist/tsup/chunk-VJRXZPTT.js.map +1 -0
- package/dist/tsup/{chunk-4PSLOAXR.cjs → chunk-VZMXAZKC.cjs} +226 -204
- package/dist/tsup/chunk-VZMXAZKC.cjs.map +1 -0
- package/dist/tsup/{chunk-DL7TPF63.cjs → chunk-YKVTF7MP.cjs} +7 -7
- package/dist/tsup/{chunk-DL7TPF63.cjs.map → chunk-YKVTF7MP.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{conn-CEh3WKbA.d.cts → conn-Cc9WHuN4.d.cts} +196 -191
- package/dist/tsup/{conn-Bt8rkUzm.d.ts → conn-DfPG71FA.d.ts} +196 -191
- package/dist/tsup/driver-helpers/mod.cjs +5 -5
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +1 -1
- package/dist/tsup/driver-helpers/mod.d.ts +1 -1
- package/dist/tsup/driver-helpers/mod.js +6 -6
- package/dist/tsup/driver-test-suite/mod.cjs +116 -102
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +3 -2
- package/dist/tsup/driver-test-suite/mod.d.ts +3 -2
- package/dist/tsup/driver-test-suite/mod.js +61 -47
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.d.cts +6 -6
- package/dist/tsup/inspector/mod.d.ts +6 -6
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/mod.cjs +10 -10
- package/dist/tsup/mod.d.cts +8 -39
- package/dist/tsup/mod.d.ts +8 -39
- package/dist/tsup/mod.js +9 -9
- package/dist/tsup/test/mod.cjs +11 -11
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +10 -10
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.d.cts +2 -1
- package/dist/tsup/utils.d.ts +2 -1
- package/dist/tsup/utils.js +1 -1
- package/package.json +4 -5
- package/src/actor/driver.ts +2 -2
- package/src/actor/protocol/serde.ts +75 -3
- package/src/actor/router-endpoints.ts +6 -6
- package/src/actor/router.ts +2 -2
- package/src/client/actor-conn.ts +24 -3
- package/src/client/config.ts +18 -25
- package/src/driver-helpers/mod.ts +4 -1
- package/src/driver-test-suite/mod.ts +65 -43
- package/src/driver-test-suite/utils.ts +4 -1
- package/src/drivers/default.ts +11 -9
- package/src/drivers/engine/actor-driver.ts +40 -39
- package/src/drivers/engine/config.ts +9 -22
- package/src/drivers/engine/mod.ts +9 -8
- package/src/drivers/file-system/global-state.ts +4 -4
- package/src/engine-process/log.ts +5 -0
- package/src/engine-process/mod.ts +316 -0
- package/src/inspector/utils.ts +6 -4
- package/src/manager/driver.ts +2 -2
- package/src/manager/gateway.ts +29 -11
- package/src/manager/router-schema.ts +20 -0
- package/src/manager/router.ts +105 -23
- package/src/registry/mod.ts +145 -119
- package/src/registry/run-config.ts +116 -47
- package/src/registry/serve.ts +3 -1
- package/src/serde.ts +3 -3
- package/src/test/config.ts +2 -2
- package/src/test/mod.ts +6 -3
- package/src/utils.ts +2 -0
- package/dist/tsup/chunk-4PSLOAXR.cjs.map +0 -1
- package/dist/tsup/chunk-4YV6RDZL.cjs.map +0 -1
- package/dist/tsup/chunk-7OMMIAWP.cjs.map +0 -1
- package/dist/tsup/chunk-E63WU5PL.js.map +0 -1
- package/dist/tsup/chunk-FZP2IBIX.js.map +0 -1
- package/dist/tsup/chunk-KHZ2QSQ4.js.map +0 -1
- package/dist/tsup/chunk-QGRYH6TU.cjs.map +0 -1
- package/dist/tsup/chunk-R7OP5N25.js.map +0 -1
- package/dist/tsup/chunk-SDXTJDDR.cjs.map +0 -1
- package/dist/tsup/chunk-SOC4HWCG.cjs.map +0 -1
- package/dist/tsup/chunk-U2IXX6DY.cjs.map +0 -1
- package/dist/tsup/chunk-WRSWUDFA.js.map +0 -1
- package/dist/tsup/chunk-YR2VY4XS.js.map +0 -1
- /package/dist/tsup/{chunk-APHV6WXU.js.map → chunk-346X2XU4.js.map} +0 -0
- /package/dist/tsup/{chunk-DLPIL3VC.js.map → chunk-7E5K3375.js.map} +0 -0
- /package/dist/tsup/{chunk-WBSPHV5V.js.map → chunk-KGDZYQYE.js.map} +0 -0
- /package/dist/tsup/{chunk-F2YZNUPU.js.map → chunk-N3A5GYJU.js.map} +0 -0
|
@@ -26,7 +26,7 @@ import type { UpgradeWebSocketArgs } from "@/common/inline-websocket-adapter2";
|
|
|
26
26
|
import { deconstructError, stringifyError } from "@/common/utils";
|
|
27
27
|
import type { UniversalWebSocket } from "@/common/websocket-interface";
|
|
28
28
|
import { HonoWebSocketAdapter } from "@/manager/hono-websocket-adapter";
|
|
29
|
-
import type {
|
|
29
|
+
import type { RunnerConfig } from "@/registry/run-config";
|
|
30
30
|
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
31
31
|
import {
|
|
32
32
|
HTTP_ACTION_REQUEST_VERSIONED,
|
|
@@ -106,7 +106,7 @@ export interface WebSocketOpts {
|
|
|
106
106
|
*/
|
|
107
107
|
export async function handleWebSocketConnect(
|
|
108
108
|
req: Request | undefined,
|
|
109
|
-
runConfig:
|
|
109
|
+
runConfig: RunnerConfig,
|
|
110
110
|
actorDriver: ActorDriver,
|
|
111
111
|
actorId: string,
|
|
112
112
|
encoding: Encoding,
|
|
@@ -325,7 +325,7 @@ export async function handleWebSocketConnect(
|
|
|
325
325
|
*/
|
|
326
326
|
export async function handleSseConnect(
|
|
327
327
|
c: HonoContext,
|
|
328
|
-
_runConfig:
|
|
328
|
+
_runConfig: RunnerConfig,
|
|
329
329
|
actorDriver: ActorDriver,
|
|
330
330
|
actorId: string,
|
|
331
331
|
) {
|
|
@@ -437,7 +437,7 @@ export async function handleSseConnect(
|
|
|
437
437
|
*/
|
|
438
438
|
export async function handleAction(
|
|
439
439
|
c: HonoContext,
|
|
440
|
-
_runConfig:
|
|
440
|
+
_runConfig: RunnerConfig,
|
|
441
441
|
actorDriver: ActorDriver,
|
|
442
442
|
actionName: string,
|
|
443
443
|
actorId: string,
|
|
@@ -505,7 +505,7 @@ export async function handleAction(
|
|
|
505
505
|
*/
|
|
506
506
|
export async function handleConnectionMessage(
|
|
507
507
|
c: HonoContext,
|
|
508
|
-
_runConfig:
|
|
508
|
+
_runConfig: RunnerConfig,
|
|
509
509
|
actorDriver: ActorDriver,
|
|
510
510
|
connId: string,
|
|
511
511
|
connToken: string,
|
|
@@ -542,7 +542,7 @@ export async function handleConnectionMessage(
|
|
|
542
542
|
|
|
543
543
|
export async function handleConnectionClose(
|
|
544
544
|
c: HonoContext,
|
|
545
|
-
_runConfig:
|
|
545
|
+
_runConfig: RunnerConfig,
|
|
546
546
|
actorDriver: ActorDriver,
|
|
547
547
|
connId: string,
|
|
548
548
|
connToken: string,
|
package/src/actor/router.ts
CHANGED
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
createActorInspectorRouter,
|
|
42
42
|
} from "@/inspector/actor";
|
|
43
43
|
import { isInspectorEnabled, secureInspector } from "@/inspector/utils";
|
|
44
|
-
import type {
|
|
44
|
+
import type { RunnerConfig } from "@/registry/run-config";
|
|
45
45
|
import { ConnDriverKind } from "./conn-drivers";
|
|
46
46
|
import type { ActorDriver } from "./driver";
|
|
47
47
|
import { InternalError } from "./errors";
|
|
@@ -67,7 +67,7 @@ export type ActorRouter = Hono<{ Bindings: ActorRouterBindings }>;
|
|
|
67
67
|
* Creates a router that runs on the partitioned instance.
|
|
68
68
|
*/
|
|
69
69
|
export function createActorRouter(
|
|
70
|
-
runConfig:
|
|
70
|
+
runConfig: RunnerConfig,
|
|
71
71
|
actorDriver: ActorDriver,
|
|
72
72
|
isTest: boolean,
|
|
73
73
|
): ActorRouter {
|
package/src/client/actor-conn.ts
CHANGED
|
@@ -315,13 +315,34 @@ enc
|
|
|
315
315
|
});
|
|
316
316
|
});
|
|
317
317
|
ws.addEventListener("message", async (ev) => {
|
|
318
|
-
|
|
318
|
+
try {
|
|
319
|
+
await this.#handleOnMessage(ev.data);
|
|
320
|
+
} catch (err) {
|
|
321
|
+
logger().error({
|
|
322
|
+
msg: "error in websocket message handler",
|
|
323
|
+
error: stringifyError(err),
|
|
324
|
+
});
|
|
325
|
+
}
|
|
319
326
|
});
|
|
320
327
|
ws.addEventListener("close", (ev) => {
|
|
321
|
-
|
|
328
|
+
try {
|
|
329
|
+
this.#handleOnClose(ev);
|
|
330
|
+
} catch (err) {
|
|
331
|
+
logger().error({
|
|
332
|
+
msg: "error in websocket close handler",
|
|
333
|
+
error: stringifyError(err),
|
|
334
|
+
});
|
|
335
|
+
}
|
|
322
336
|
});
|
|
323
337
|
ws.addEventListener("error", (_ev) => {
|
|
324
|
-
|
|
338
|
+
try {
|
|
339
|
+
this.#handleOnError();
|
|
340
|
+
} catch (err) {
|
|
341
|
+
logger().error({
|
|
342
|
+
msg: "error in websocket error handler",
|
|
343
|
+
error: stringifyError(err),
|
|
344
|
+
});
|
|
345
|
+
}
|
|
325
346
|
});
|
|
326
347
|
}
|
|
327
348
|
|
package/src/client/config.ts
CHANGED
|
@@ -1,38 +1,32 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
2
|
import { TransportSchema } from "@/actor/protocol/old";
|
|
3
3
|
import { EncodingSchema } from "@/actor/protocol/serde";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export type GetUpgradeWebSocket = () => UpgradeWebSocket;
|
|
4
|
+
import { type GetUpgradeWebSocket, getEnvUniversal } from "@/utils";
|
|
7
5
|
|
|
8
6
|
export const ClientConfigSchema = z.object({
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
/** Endpoint to connect to for Rivet Engine or RivetKit manager API. */
|
|
8
|
+
endpoint: z
|
|
9
|
+
.string()
|
|
10
|
+
.optional()
|
|
11
|
+
.transform(
|
|
12
|
+
(x) =>
|
|
13
|
+
x ??
|
|
14
|
+
getEnvUniversal("RIVET_ENGINE") ??
|
|
15
|
+
getEnvUniversal("RIVET_ENDPOINT"),
|
|
16
|
+
),
|
|
17
|
+
|
|
18
|
+
/** Token to use to authenticate with the API. */
|
|
17
19
|
token: z
|
|
18
20
|
.string()
|
|
19
21
|
.optional()
|
|
20
22
|
.transform((x) => x ?? getEnvUniversal("RIVET_TOKEN")),
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
headers: z.record(z.string()).optional().default({}),
|
|
25
|
-
|
|
26
|
-
/** Endpoint to connect to the Rivet engine. Can be configured via RIVET_ENGINE env var. */
|
|
27
|
-
endpoint: z
|
|
28
|
-
.string()
|
|
29
|
-
.nullable()
|
|
30
|
-
.default(() => getEnvUniversal("RIVET_ENGINE") ?? null),
|
|
31
|
-
|
|
24
|
+
/** Namespace to connect to. */
|
|
32
25
|
namespace: z
|
|
33
26
|
.string()
|
|
34
27
|
.default(() => getEnvUniversal("RIVET_NAMESPACE") ?? "default"),
|
|
35
28
|
|
|
29
|
+
/** Name of the runner. This is used to group together runners in to different pools. */
|
|
36
30
|
runnerName: z
|
|
37
31
|
.string()
|
|
38
32
|
.default(() => getEnvUniversal("RIVET_RUNNER") ?? "rivetkit"),
|
|
@@ -41,10 +35,9 @@ export const ClientConfigSchema = z.object({
|
|
|
41
35
|
|
|
42
36
|
transport: TransportSchema.default("websocket"),
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
//
|
|
47
|
-
// created or must be imported async using `await import(...)`
|
|
38
|
+
headers: z.record(z.string()).optional().default({}),
|
|
39
|
+
|
|
40
|
+
// See RunConfig.getUpgradeWebSocket
|
|
48
41
|
getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
|
|
49
42
|
});
|
|
50
43
|
|
|
@@ -32,5 +32,8 @@ export type {
|
|
|
32
32
|
ManagerDisplayInformation,
|
|
33
33
|
ManagerDriver,
|
|
34
34
|
} from "@/manager/driver";
|
|
35
|
-
export {
|
|
35
|
+
export {
|
|
36
|
+
DriverConfigSchema,
|
|
37
|
+
RunnerConfigSchema as RunConfigSchema,
|
|
38
|
+
} from "@/registry/run-config";
|
|
36
39
|
export { serializeEmptyPersistData } from "./utils";
|
|
@@ -3,11 +3,16 @@ import { createNodeWebSocket, type NodeWebSocket } from "@hono/node-ws";
|
|
|
3
3
|
import { bundleRequire } from "bundle-require";
|
|
4
4
|
import invariant from "invariant";
|
|
5
5
|
import { describe } from "vitest";
|
|
6
|
-
import type { Transport } from "@/client/mod";
|
|
6
|
+
import type { Encoding, Transport } from "@/client/mod";
|
|
7
7
|
import { configureInspectorAccessToken } from "@/inspector/utils";
|
|
8
8
|
import { createManagerRouter } from "@/manager/router";
|
|
9
|
-
import
|
|
10
|
-
|
|
9
|
+
import {
|
|
10
|
+
createClientWithDriver,
|
|
11
|
+
type DriverConfig,
|
|
12
|
+
type Registry,
|
|
13
|
+
type RunConfig,
|
|
14
|
+
} from "@/mod";
|
|
15
|
+
import { RunnerConfigSchema } from "@/registry/run-config";
|
|
11
16
|
import { getPort } from "@/test/mod";
|
|
12
17
|
import { logger } from "./log";
|
|
13
18
|
import { runActionFeaturesTests } from "./tests/action-features";
|
|
@@ -55,6 +60,8 @@ export interface DriverTestConfig {
|
|
|
55
60
|
|
|
56
61
|
transport?: Transport;
|
|
57
62
|
|
|
63
|
+
encoding?: Encoding;
|
|
64
|
+
|
|
58
65
|
clientType: ClientType;
|
|
59
66
|
|
|
60
67
|
cleanup?: () => Promise<void>;
|
|
@@ -78,68 +85,81 @@ export interface DriverDeployOutput {
|
|
|
78
85
|
|
|
79
86
|
/** Runs all Vitest tests against the provided drivers. */
|
|
80
87
|
export function runDriverTests(
|
|
81
|
-
driverTestConfigPartial: Omit<
|
|
88
|
+
driverTestConfigPartial: Omit<
|
|
89
|
+
DriverTestConfig,
|
|
90
|
+
"clientType" | "transport" | "encoding"
|
|
91
|
+
>,
|
|
82
92
|
) {
|
|
83
93
|
const clientTypes: ClientType[] = driverTestConfigPartial.skip?.inline
|
|
84
94
|
? ["http"]
|
|
85
95
|
: ["http", "inline"];
|
|
86
96
|
for (const clientType of clientTypes) {
|
|
87
|
-
const driverTestConfig: DriverTestConfig = {
|
|
88
|
-
...driverTestConfigPartial,
|
|
89
|
-
clientType,
|
|
90
|
-
};
|
|
91
|
-
|
|
92
97
|
describe(`client type (${clientType})`, () => {
|
|
93
|
-
|
|
94
|
-
runManagerDriverTests(driverTestConfig);
|
|
98
|
+
const encodings: Encoding[] = ["bare", "cbor", "json"];
|
|
95
99
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
transport,
|
|
104
|
-
});
|
|
100
|
+
for (const encoding of encodings) {
|
|
101
|
+
describe(`encoding (${encoding})`, () => {
|
|
102
|
+
const driverTestConfig: DriverTestConfig = {
|
|
103
|
+
...driverTestConfigPartial,
|
|
104
|
+
clientType,
|
|
105
|
+
encoding,
|
|
106
|
+
};
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
runActorDriverTests(driverTestConfig);
|
|
109
|
+
runManagerDriverTests(driverTestConfig);
|
|
107
110
|
|
|
108
|
-
|
|
111
|
+
const transports: Transport[] = driverTestConfig.skip?.sse
|
|
112
|
+
? ["websocket"]
|
|
113
|
+
: ["websocket", "sse"];
|
|
114
|
+
for (const transport of transports) {
|
|
115
|
+
describe(`transport (${transport})`, () => {
|
|
116
|
+
runActorConnTests({
|
|
117
|
+
...driverTestConfig,
|
|
118
|
+
transport,
|
|
119
|
+
});
|
|
109
120
|
|
|
110
|
-
|
|
121
|
+
runActorConnStateTests({ ...driverTestConfig, transport });
|
|
111
122
|
|
|
112
|
-
|
|
113
|
-
});
|
|
114
|
-
}
|
|
123
|
+
runActorReconnectTests({ ...driverTestConfig, transport });
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
runRequestAccessTests({ ...driverTestConfig, transport });
|
|
117
126
|
|
|
118
|
-
|
|
127
|
+
runActorDriverTestsWithTransport({
|
|
128
|
+
...driverTestConfig,
|
|
129
|
+
transport,
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
119
133
|
|
|
120
|
-
|
|
134
|
+
runActorHandleTests(driverTestConfig);
|
|
121
135
|
|
|
122
|
-
|
|
136
|
+
runActionFeaturesTests(driverTestConfig);
|
|
123
137
|
|
|
124
|
-
|
|
138
|
+
runActorVarsTests(driverTestConfig);
|
|
125
139
|
|
|
126
|
-
|
|
140
|
+
runActorMetadataTests(driverTestConfig);
|
|
127
141
|
|
|
128
|
-
|
|
142
|
+
runActorOnStateChangeTests(driverTestConfig);
|
|
129
143
|
|
|
130
|
-
|
|
144
|
+
runActorErrorHandlingTests(driverTestConfig);
|
|
131
145
|
|
|
132
|
-
|
|
146
|
+
runActorInlineClientTests(driverTestConfig);
|
|
133
147
|
|
|
134
|
-
|
|
148
|
+
runRawHttpTests(driverTestConfig);
|
|
135
149
|
|
|
136
|
-
|
|
137
|
-
// runRawHttpDirectRegistryTests(driverTestConfig);
|
|
150
|
+
runRawHttpRequestPropertiesTests(driverTestConfig);
|
|
138
151
|
|
|
139
|
-
|
|
140
|
-
// runRawWebSocketDirectRegistryTests(driverTestConfig);
|
|
152
|
+
runRawWebSocketTests(driverTestConfig);
|
|
141
153
|
|
|
142
|
-
|
|
154
|
+
// TODO: re-expose this once we can have actor queries on the gateway
|
|
155
|
+
// runRawHttpDirectRegistryTests(driverTestConfig);
|
|
156
|
+
|
|
157
|
+
// TODO: re-expose this once we can have actor queries on the gateway
|
|
158
|
+
// runRawWebSocketDirectRegistryTests(driverTestConfig);
|
|
159
|
+
|
|
160
|
+
runActorInspectorTests(driverTestConfig);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
143
163
|
});
|
|
144
164
|
}
|
|
145
165
|
}
|
|
@@ -199,7 +219,7 @@ export async function createTestRuntime(
|
|
|
199
219
|
// Build driver config
|
|
200
220
|
// biome-ignore lint/style/useConst: Assigned later
|
|
201
221
|
let upgradeWebSocket: any;
|
|
202
|
-
const config: RunConfig =
|
|
222
|
+
const config: RunConfig = RunnerConfigSchema.parse({
|
|
203
223
|
driver,
|
|
204
224
|
getUpgradeWebSocket: () => upgradeWebSocket!,
|
|
205
225
|
inspector: {
|
|
@@ -210,12 +230,14 @@ export async function createTestRuntime(
|
|
|
210
230
|
|
|
211
231
|
// Create router
|
|
212
232
|
const managerDriver = driver.manager(registry.config, config);
|
|
233
|
+
const client = createClientWithDriver(managerDriver);
|
|
213
234
|
configureInspectorAccessToken(config, managerDriver);
|
|
214
235
|
const { router } = createManagerRouter(
|
|
215
236
|
registry.config,
|
|
216
237
|
config,
|
|
217
238
|
managerDriver,
|
|
218
|
-
|
|
239
|
+
driver,
|
|
240
|
+
client,
|
|
219
241
|
);
|
|
220
242
|
|
|
221
243
|
// Inject WebSocket
|
|
@@ -36,17 +36,20 @@ export async function setupDriverTest(
|
|
|
36
36
|
namespace,
|
|
37
37
|
runnerName,
|
|
38
38
|
transport: driverTestConfig.transport,
|
|
39
|
+
encoding: driverTestConfig.encoding,
|
|
39
40
|
});
|
|
40
41
|
} else if (driverTestConfig.clientType === "inline") {
|
|
41
42
|
// Use inline client from driver
|
|
42
43
|
const transport = driverTestConfig.transport ?? "websocket";
|
|
44
|
+
const encoding = driverTestConfig.encoding ?? "bare";
|
|
43
45
|
const managerDriver = createTestInlineClientDriver(
|
|
44
46
|
endpoint,
|
|
45
|
-
|
|
47
|
+
encoding,
|
|
46
48
|
transport,
|
|
47
49
|
);
|
|
48
50
|
const runConfig = RunConfigSchema.parse({
|
|
49
51
|
transport: transport,
|
|
52
|
+
encoding: encoding,
|
|
50
53
|
});
|
|
51
54
|
client = createClientWithDriver(managerDriver, runConfig);
|
|
52
55
|
} else {
|
package/src/drivers/default.ts
CHANGED
|
@@ -2,15 +2,21 @@ import { UserError } from "@/actor/errors";
|
|
|
2
2
|
import { loggerWithoutContext } from "@/actor/log";
|
|
3
3
|
import { createEngineDriver } from "@/drivers/engine/mod";
|
|
4
4
|
import { createFileSystemOrMemoryDriver } from "@/drivers/file-system/mod";
|
|
5
|
-
import type { DriverConfig,
|
|
5
|
+
import type { DriverConfig, RunnerConfig } from "@/registry/run-config";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Chooses the appropriate driver based on the run configuration.
|
|
9
9
|
*/
|
|
10
|
-
export function chooseDefaultDriver(runConfig:
|
|
10
|
+
export function chooseDefaultDriver(runConfig: RunnerConfig): DriverConfig {
|
|
11
11
|
if (runConfig.endpoint && runConfig.driver) {
|
|
12
12
|
throw new UserError(
|
|
13
|
-
"Cannot specify both '
|
|
13
|
+
"Cannot specify both 'endpoint' and 'driver' in configuration",
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (runConfig.runnerKind === "serverless" && !runConfig.endpoint) {
|
|
18
|
+
throw new UserError(
|
|
19
|
+
"Cannot use 'serverless' runnerKind without the 'endpoint' config set.",
|
|
14
20
|
);
|
|
15
21
|
}
|
|
16
22
|
|
|
@@ -18,16 +24,12 @@ export function chooseDefaultDriver(runConfig: RunConfig): DriverConfig {
|
|
|
18
24
|
return runConfig.driver;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
if (runConfig.endpoint) {
|
|
27
|
+
if (runConfig.endpoint || runConfig.token) {
|
|
22
28
|
loggerWithoutContext().debug({
|
|
23
29
|
msg: "using rivet engine driver",
|
|
24
30
|
endpoint: runConfig.endpoint,
|
|
25
31
|
});
|
|
26
|
-
|
|
27
|
-
return createEngineDriver({
|
|
28
|
-
endpoint: runConfig.endpoint,
|
|
29
|
-
token: runConfig.token,
|
|
30
|
-
});
|
|
32
|
+
return createEngineDriver();
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
loggerWithoutContext().debug({ msg: "using default file system driver" });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
RunnerConfig as EngineRunnerConfig,
|
|
2
3
|
ActorConfig as RunnerActorConfig,
|
|
3
|
-
RunnerConfig,
|
|
4
4
|
} from "@rivetkit/engine-runner";
|
|
5
5
|
import { Runner } from "@rivetkit/engine-runner";
|
|
6
6
|
import * as cbor from "cbor-x";
|
|
@@ -34,13 +34,13 @@ import {
|
|
|
34
34
|
serializeEmptyPersistData,
|
|
35
35
|
} from "@/driver-helpers/mod";
|
|
36
36
|
import type { RegistryConfig } from "@/registry/config";
|
|
37
|
-
import type {
|
|
37
|
+
import type { RunnerConfig } from "@/registry/run-config";
|
|
38
|
+
import { getEndpoint } from "@/remote-manager-driver/api-utils";
|
|
38
39
|
import {
|
|
39
40
|
type LongTimeoutHandle,
|
|
40
41
|
promiseWithResolvers,
|
|
41
42
|
setLongTimeout,
|
|
42
43
|
} from "@/utils";
|
|
43
|
-
import type { Config } from "./config";
|
|
44
44
|
import { KEYS } from "./kv";
|
|
45
45
|
import { logger } from "./log";
|
|
46
46
|
|
|
@@ -54,10 +54,9 @@ export type DriverContext = {};
|
|
|
54
54
|
|
|
55
55
|
export class EngineActorDriver implements ActorDriver {
|
|
56
56
|
#registryConfig: RegistryConfig;
|
|
57
|
-
#runConfig:
|
|
57
|
+
#runConfig: RunnerConfig;
|
|
58
58
|
#managerDriver: ManagerDriver;
|
|
59
59
|
#inlineClient: Client<any>;
|
|
60
|
-
#config: Config;
|
|
61
60
|
#runner: Runner;
|
|
62
61
|
#actors: Map<string, ActorHandler> = new Map();
|
|
63
62
|
#actorRouter: ActorRouter;
|
|
@@ -69,16 +68,22 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
69
68
|
|
|
70
69
|
constructor(
|
|
71
70
|
registryConfig: RegistryConfig,
|
|
72
|
-
runConfig:
|
|
71
|
+
runConfig: RunnerConfig,
|
|
73
72
|
managerDriver: ManagerDriver,
|
|
74
73
|
inlineClient: Client<any>,
|
|
75
|
-
config: Config,
|
|
76
74
|
) {
|
|
77
75
|
this.#registryConfig = registryConfig;
|
|
78
76
|
this.#runConfig = runConfig;
|
|
79
77
|
this.#managerDriver = managerDriver;
|
|
80
78
|
this.#inlineClient = inlineClient;
|
|
81
|
-
|
|
79
|
+
|
|
80
|
+
// HACK: Override inspector token (which are likely to be
|
|
81
|
+
// removed later on) with token from x-rivet-token header
|
|
82
|
+
const token = runConfig.token ?? runConfig.token;
|
|
83
|
+
if (token && runConfig.inspector && runConfig.inspector.enabled) {
|
|
84
|
+
runConfig.inspector.token = () => token;
|
|
85
|
+
}
|
|
86
|
+
|
|
82
87
|
this.#actorRouter = createActorRouter(
|
|
83
88
|
runConfig,
|
|
84
89
|
this,
|
|
@@ -87,15 +92,14 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
87
92
|
|
|
88
93
|
// Create runner configuration
|
|
89
94
|
let hasDisconnected = false;
|
|
90
|
-
const
|
|
95
|
+
const engineRunnerConfig: EngineRunnerConfig = {
|
|
91
96
|
version: this.#version,
|
|
92
|
-
endpoint:
|
|
93
|
-
token
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
runnerKey: config.runnerKey,
|
|
97
|
+
endpoint: getEndpoint(runConfig),
|
|
98
|
+
token,
|
|
99
|
+
namespace: runConfig.namespace ?? runConfig.namespace,
|
|
100
|
+
totalSlots: runConfig.totalSlots ?? runConfig.totalSlots,
|
|
101
|
+
runnerName: runConfig.runnerName ?? runConfig.runnerName,
|
|
102
|
+
runnerKey: runConfig.runnerKey,
|
|
99
103
|
metadata: {
|
|
100
104
|
inspectorToken: this.#runConfig.inspector.token(),
|
|
101
105
|
},
|
|
@@ -109,14 +113,14 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
109
113
|
if (hasDisconnected) {
|
|
110
114
|
logger().info({
|
|
111
115
|
msg: "runner reconnected",
|
|
112
|
-
namespace: this.#
|
|
113
|
-
runnerName: this.#
|
|
116
|
+
namespace: this.#runConfig.namespace,
|
|
117
|
+
runnerName: this.#runConfig.runnerName,
|
|
114
118
|
});
|
|
115
119
|
} else {
|
|
116
120
|
logger().debug({
|
|
117
121
|
msg: "runner connected",
|
|
118
|
-
namespace: this.#
|
|
119
|
-
runnerName: this.#
|
|
122
|
+
namespace: this.#runConfig.namespace,
|
|
123
|
+
runnerName: this.#runConfig.runnerName,
|
|
120
124
|
});
|
|
121
125
|
}
|
|
122
126
|
|
|
@@ -125,8 +129,8 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
125
129
|
onDisconnected: () => {
|
|
126
130
|
logger().warn({
|
|
127
131
|
msg: "runner disconnected",
|
|
128
|
-
namespace: this.#
|
|
129
|
-
runnerName: this.#
|
|
132
|
+
namespace: this.#runConfig.namespace,
|
|
133
|
+
runnerName: this.#runConfig.runnerName,
|
|
130
134
|
});
|
|
131
135
|
hasDisconnected = true;
|
|
132
136
|
},
|
|
@@ -141,13 +145,13 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
141
145
|
};
|
|
142
146
|
|
|
143
147
|
// Create and start runner
|
|
144
|
-
this.#runner = new Runner(
|
|
148
|
+
this.#runner = new Runner(engineRunnerConfig);
|
|
145
149
|
this.#runner.start();
|
|
146
150
|
logger().debug({
|
|
147
151
|
msg: "engine runner started",
|
|
148
|
-
endpoint:
|
|
149
|
-
namespace:
|
|
150
|
-
runnerName:
|
|
152
|
+
endpoint: runConfig.endpoint,
|
|
153
|
+
namespace: runConfig.namespace,
|
|
154
|
+
runnerName: runConfig.runnerName,
|
|
151
155
|
});
|
|
152
156
|
}
|
|
153
157
|
|
|
@@ -228,20 +232,20 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
228
232
|
async #runnerOnActorStart(
|
|
229
233
|
actorId: string,
|
|
230
234
|
generation: number,
|
|
231
|
-
|
|
235
|
+
runConfig: RunnerActorConfig,
|
|
232
236
|
): Promise<void> {
|
|
233
237
|
logger().debug({
|
|
234
238
|
msg: "runner actor starting",
|
|
235
239
|
actorId,
|
|
236
|
-
name:
|
|
237
|
-
key:
|
|
240
|
+
name: runConfig.name,
|
|
241
|
+
key: runConfig.key,
|
|
238
242
|
generation,
|
|
239
243
|
});
|
|
240
244
|
|
|
241
245
|
// Deserialize input
|
|
242
246
|
let input: any;
|
|
243
|
-
if (
|
|
244
|
-
input = cbor.decode(
|
|
247
|
+
if (runConfig.input) {
|
|
248
|
+
input = cbor.decode(runConfig.input);
|
|
245
249
|
}
|
|
246
250
|
|
|
247
251
|
// Get or create handler
|
|
@@ -254,15 +258,12 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
254
258
|
this.#actors.set(actorId, handler);
|
|
255
259
|
}
|
|
256
260
|
|
|
257
|
-
const name =
|
|
258
|
-
invariant(
|
|
259
|
-
const key = deserializeActorKey(
|
|
261
|
+
const name = runConfig.name as string;
|
|
262
|
+
invariant(runConfig.key, "actor should have a key");
|
|
263
|
+
const key = deserializeActorKey(runConfig.key);
|
|
260
264
|
|
|
261
265
|
// Create actor instance
|
|
262
|
-
const definition = lookupInRegistry(
|
|
263
|
-
this.#registryConfig,
|
|
264
|
-
config.name as string, // TODO: Remove cast
|
|
265
|
-
);
|
|
266
|
+
const definition = lookupInRegistry(this.#registryConfig, runConfig.name);
|
|
266
267
|
handler.actor = definition.instantiate();
|
|
267
268
|
|
|
268
269
|
// Start actor
|
|
@@ -413,7 +414,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
413
414
|
// Runner id should be set if the runner started
|
|
414
415
|
const payload = this.#runner.getServerlessInitPacket();
|
|
415
416
|
invariant(payload, "runnerId not set");
|
|
416
|
-
stream.writeSSE({ data: payload });
|
|
417
|
+
await stream.writeSSE({ data: payload });
|
|
417
418
|
|
|
418
419
|
return this.#runnerStopped.promise;
|
|
419
420
|
});
|
|
@@ -1,35 +1,22 @@
|
|
|
1
|
-
import type { Hono } from "hono";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { ClientConfigSchema } from "@/client/config";
|
|
3
3
|
import { getEnvUniversal } from "@/utils";
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const EngingConfigSchema = z
|
|
6
6
|
.object({
|
|
7
|
-
|
|
8
|
-
endpoint: z
|
|
9
|
-
.string()
|
|
10
|
-
.default(
|
|
11
|
-
() => getEnvUniversal("RIVET_ENGINE") ?? "http://localhost:6420",
|
|
12
|
-
),
|
|
13
|
-
token: z
|
|
14
|
-
.string()
|
|
15
|
-
.optional()
|
|
16
|
-
.transform((val) => val ?? getEnvUniversal("RIVET_TOKEN")),
|
|
17
|
-
pegboardEndpoint: z.string().optional(),
|
|
18
|
-
namespace: z
|
|
19
|
-
.string()
|
|
20
|
-
.default(() => getEnvUniversal("RIVET_NAMESPACE") ?? "default"),
|
|
21
|
-
runnerName: z
|
|
22
|
-
.string()
|
|
23
|
-
.default(() => getEnvUniversal("RIVET_RUNNER") ?? "rivetkit"),
|
|
24
|
-
// TODO: Automatically attempt to determine key by common env vars (e.g. k8s pod name)
|
|
7
|
+
/** Unique key for this runner. Runners connecting a given key will replace any other runner connected with the same key. */
|
|
25
8
|
runnerKey: z
|
|
26
9
|
.string()
|
|
27
10
|
.default(
|
|
28
11
|
() => getEnvUniversal("RIVET_RUNNER_KEY") ?? crypto.randomUUID(),
|
|
29
12
|
),
|
|
13
|
+
|
|
14
|
+
/** How many actors this runner can run. */
|
|
30
15
|
totalSlots: z.number().default(100_000),
|
|
31
16
|
})
|
|
17
|
+
// We include the client config since this includes the common properties like endpoint, namespace, etc.
|
|
18
|
+
.merge(ClientConfigSchema)
|
|
32
19
|
.default({});
|
|
33
20
|
|
|
34
|
-
export type
|
|
35
|
-
export type
|
|
21
|
+
export type EngineConfig = z.infer<typeof EngingConfigSchema>;
|
|
22
|
+
export type EngineConfigInput = z.input<typeof EngingConfigSchema>;
|