rivetkit 2.0.5 → 2.0.7-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.
- package/dist/schemas/actor-persist/v1.ts +0 -6
- package/dist/tsup/actor-router-consts-B3Lu87yJ.d.cts +28 -0
- package/dist/tsup/actor-router-consts-B3Lu87yJ.d.ts +28 -0
- package/dist/tsup/{chunk-5YTI25C3.cjs → chunk-3MBP4WNC.cjs} +7 -7
- package/dist/tsup/{chunk-5YTI25C3.cjs.map → chunk-3MBP4WNC.cjs.map} +1 -1
- package/dist/tsup/chunk-3Y45CIF4.cjs +3726 -0
- package/dist/tsup/chunk-3Y45CIF4.cjs.map +1 -0
- package/dist/tsup/chunk-4GP7BZSR.js +102 -0
- package/dist/tsup/chunk-4GP7BZSR.js.map +1 -0
- package/dist/tsup/chunk-5ZOHIKWG.cjs +4071 -0
- package/dist/tsup/chunk-5ZOHIKWG.cjs.map +1 -0
- package/dist/tsup/{chunk-WADSS5X4.cjs → chunk-6EUWRXLT.cjs} +21 -7
- package/dist/tsup/chunk-6EUWRXLT.cjs.map +1 -0
- package/dist/tsup/{chunk-D7NWUCRK.cjs → chunk-6OVKCDSH.cjs} +6 -6
- package/dist/tsup/{chunk-D7NWUCRK.cjs.map → chunk-6OVKCDSH.cjs.map} +1 -1
- package/dist/tsup/{chunk-I5VTWPHW.js → chunk-7N56ZUC7.js} +3 -3
- package/dist/tsup/{chunk-LZIBTLEY.cjs → chunk-B3TLRM4Q.cjs} +13 -25
- package/dist/tsup/chunk-B3TLRM4Q.cjs.map +1 -0
- package/dist/tsup/chunk-BW5DPM6Z.js +4071 -0
- package/dist/tsup/chunk-BW5DPM6Z.js.map +1 -0
- package/dist/tsup/chunk-DFS77KAA.cjs +1046 -0
- package/dist/tsup/chunk-DFS77KAA.cjs.map +1 -0
- package/dist/tsup/{chunk-PG3K2LI7.js → chunk-E4UVJKSV.js} +2 -2
- package/dist/tsup/chunk-G4ABMAQY.cjs +102 -0
- package/dist/tsup/chunk-G4ABMAQY.cjs.map +1 -0
- package/dist/tsup/{chunk-CKA54YQN.js → chunk-GZVBFXBI.js} +3 -15
- package/dist/tsup/chunk-GZVBFXBI.js.map +1 -0
- package/dist/tsup/chunk-HPT3I7UU.js +3726 -0
- package/dist/tsup/chunk-HPT3I7UU.js.map +1 -0
- package/dist/tsup/chunk-JD54PXWP.js +1046 -0
- package/dist/tsup/chunk-JD54PXWP.js.map +1 -0
- package/dist/tsup/{chunk-PHSQJ6QI.cjs → chunk-K4ENQCC4.cjs} +3 -3
- package/dist/tsup/{chunk-PHSQJ6QI.cjs.map → chunk-K4ENQCC4.cjs.map} +1 -1
- package/dist/tsup/{chunk-WNGOBAA7.js → chunk-PUSQNDJG.js} +2 -2
- package/dist/tsup/{chunk-CFFKMUYH.js → chunk-RVP5RUSC.js} +20 -6
- package/dist/tsup/chunk-RVP5RUSC.js.map +1 -0
- package/dist/tsup/chunk-SAZCNSVY.cjs +259 -0
- package/dist/tsup/chunk-SAZCNSVY.cjs.map +1 -0
- package/dist/tsup/{chunk-YW6Y6VNE.js → chunk-SBKRVQS2.js} +9 -5
- package/dist/tsup/chunk-SBKRVQS2.js.map +1 -0
- package/dist/tsup/{chunk-FGFT4FVX.cjs → chunk-TZGUSEIJ.cjs} +14 -10
- package/dist/tsup/chunk-TZGUSEIJ.cjs.map +1 -0
- package/dist/tsup/chunk-YQ4XQYPM.js +259 -0
- package/dist/tsup/chunk-YQ4XQYPM.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +7 -8
- package/dist/tsup/client/mod.d.ts +7 -8
- 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/{connection-BvE-Oq7t.d.ts → conn-DCSQgIlw.d.ts} +1605 -1353
- package/dist/tsup/{connection-DTzmWwU5.d.cts → conn-DdzHTm2E.d.cts} +1605 -1353
- package/dist/tsup/driver-helpers/mod.cjs +31 -5
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +7 -8
- package/dist/tsup/driver-helpers/mod.d.ts +7 -8
- package/dist/tsup/driver-helpers/mod.js +33 -7
- package/dist/tsup/driver-test-suite/mod.cjs +319 -216
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +7 -7
- package/dist/tsup/driver-test-suite/mod.d.ts +7 -7
- package/dist/tsup/driver-test-suite/mod.js +588 -485
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +17 -5
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +34 -7
- package/dist/tsup/inspector/mod.d.ts +34 -7
- package/dist/tsup/inspector/mod.js +20 -8
- package/dist/tsup/mod.cjs +10 -17
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +56 -9
- package/dist/tsup/mod.d.ts +56 -9
- package/dist/tsup/mod.js +17 -24
- package/dist/tsup/test/mod.cjs +11 -9
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +6 -7
- package/dist/tsup/test/mod.d.ts +6 -7
- package/dist/tsup/test/mod.js +10 -8
- package/dist/tsup/utils.cjs +4 -2
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +11 -1
- package/dist/tsup/utils.d.ts +11 -1
- package/dist/tsup/utils.js +3 -1
- package/package.json +8 -4
- package/src/actor/action.ts +1 -1
- package/src/actor/config.ts +1 -1
- package/src/actor/conn-drivers.ts +205 -0
- package/src/actor/conn-socket.ts +6 -0
- package/src/actor/{connection.ts → conn.ts} +78 -84
- package/src/actor/context.ts +1 -1
- package/src/actor/driver.ts +4 -43
- package/src/actor/instance.ts +162 -86
- package/src/actor/mod.ts +6 -14
- package/src/actor/persisted.ts +2 -5
- package/src/actor/protocol/old.ts +1 -1
- package/src/actor/router-endpoints.ts +147 -138
- package/src/actor/router.ts +89 -52
- package/src/actor/utils.ts +5 -1
- package/src/client/actor-conn.ts +163 -31
- package/src/client/actor-handle.ts +0 -1
- package/src/client/client.ts +2 -2
- package/src/client/config.ts +7 -0
- package/src/client/raw-utils.ts +1 -1
- package/src/client/utils.ts +1 -1
- package/src/common/actor-router-consts.ts +59 -0
- package/src/common/router.ts +2 -1
- package/src/common/versioned-data.ts +5 -5
- package/src/driver-helpers/mod.ts +15 -2
- package/src/driver-test-suite/mod.ts +11 -2
- package/src/driver-test-suite/test-inline-client-driver.ts +40 -22
- package/src/driver-test-suite/tests/actor-conn-state.ts +66 -22
- package/src/driver-test-suite/tests/actor-conn.ts +65 -126
- package/src/driver-test-suite/tests/actor-reconnect.ts +160 -0
- package/src/driver-test-suite/tests/actor-sleep.ts +0 -1
- package/src/driver-test-suite/tests/raw-websocket.ts +0 -35
- package/src/driver-test-suite/utils.ts +8 -3
- package/src/drivers/default.ts +8 -7
- package/src/drivers/engine/actor-driver.ts +67 -44
- package/src/drivers/engine/config.ts +4 -0
- package/src/drivers/file-system/actor.ts +0 -6
- package/src/drivers/file-system/global-state.ts +3 -14
- package/src/drivers/file-system/manager.ts +12 -8
- package/src/inspector/actor.ts +4 -3
- package/src/inspector/config.ts +10 -1
- package/src/inspector/mod.ts +1 -0
- package/src/inspector/utils.ts +23 -4
- package/src/manager/driver.ts +12 -2
- package/src/manager/gateway.ts +407 -0
- package/src/manager/protocol/query.ts +1 -1
- package/src/manager/router.ts +269 -468
- package/src/manager-api/actors.ts +61 -0
- package/src/manager-api/common.ts +4 -0
- package/src/mod.ts +1 -1
- package/src/registry/mod.ts +126 -12
- package/src/registry/serve.ts +8 -3
- package/src/remote-manager-driver/actor-http-client.ts +30 -19
- package/src/remote-manager-driver/actor-websocket-client.ts +45 -18
- package/src/remote-manager-driver/api-endpoints.ts +19 -21
- package/src/remote-manager-driver/api-utils.ts +10 -1
- package/src/remote-manager-driver/mod.ts +53 -53
- package/src/remote-manager-driver/ws-proxy.ts +2 -9
- package/src/test/mod.ts +6 -2
- package/src/utils.ts +21 -2
- package/dist/tsup/chunk-2MD57QF4.js +0 -1794
- package/dist/tsup/chunk-2MD57QF4.js.map +0 -1
- package/dist/tsup/chunk-B2QGJGZQ.js +0 -338
- package/dist/tsup/chunk-B2QGJGZQ.js.map +0 -1
- package/dist/tsup/chunk-CFFKMUYH.js.map +0 -1
- package/dist/tsup/chunk-CKA54YQN.js.map +0 -1
- package/dist/tsup/chunk-FGFT4FVX.cjs.map +0 -1
- package/dist/tsup/chunk-IRMBWX36.cjs +0 -1794
- package/dist/tsup/chunk-IRMBWX36.cjs.map +0 -1
- package/dist/tsup/chunk-L7QRXNWP.js +0 -6562
- package/dist/tsup/chunk-L7QRXNWP.js.map +0 -1
- package/dist/tsup/chunk-LZIBTLEY.cjs.map +0 -1
- package/dist/tsup/chunk-MRZS2J4X.cjs +0 -6562
- package/dist/tsup/chunk-MRZS2J4X.cjs.map +0 -1
- package/dist/tsup/chunk-RM2SVURR.cjs +0 -338
- package/dist/tsup/chunk-RM2SVURR.cjs.map +0 -1
- package/dist/tsup/chunk-WADSS5X4.cjs.map +0 -1
- package/dist/tsup/chunk-YW6Y6VNE.js.map +0 -1
- package/dist/tsup/common-CXCe7s6i.d.cts +0 -218
- package/dist/tsup/common-CXCe7s6i.d.ts +0 -218
- package/dist/tsup/router-endpoints-CctffZNL.d.cts +0 -65
- package/dist/tsup/router-endpoints-DFm1BglJ.d.ts +0 -65
- package/src/actor/generic-conn-driver.ts +0 -246
- package/src/common/fake-event-source.ts +0 -267
- package/src/manager-api/routes/actors-create.ts +0 -16
- package/src/manager-api/routes/actors-delete.ts +0 -4
- package/src/manager-api/routes/actors-get-by-id.ts +0 -7
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +0 -29
- package/src/manager-api/routes/actors-get.ts +0 -7
- package/src/manager-api/routes/common.ts +0 -18
- /package/dist/tsup/{chunk-I5VTWPHW.js.map → chunk-7N56ZUC7.js.map} +0 -0
- /package/dist/tsup/{chunk-PG3K2LI7.js.map → chunk-E4UVJKSV.js.map} +0 -0
- /package/dist/tsup/{chunk-WNGOBAA7.js.map → chunk-PUSQNDJG.js.map} +0 -0
|
@@ -4,46 +4,45 @@ import type {
|
|
|
4
4
|
} from "@rivetkit/engine-runner";
|
|
5
5
|
import { Runner } from "@rivetkit/engine-runner";
|
|
6
6
|
import * as cbor from "cbor-x";
|
|
7
|
+
import type { Context as HonoContext } from "hono";
|
|
8
|
+
import { streamSSE } from "hono/streaming";
|
|
7
9
|
import { WSContext } from "hono/ws";
|
|
8
10
|
import invariant from "invariant";
|
|
11
|
+
import { lookupInRegistry } from "@/actor/definition";
|
|
9
12
|
import { deserializeActorKey } from "@/actor/keys";
|
|
10
13
|
import { EncodingSchema } from "@/actor/protocol/serde";
|
|
14
|
+
import { type ActorRouter, createActorRouter } from "@/actor/router";
|
|
15
|
+
import {
|
|
16
|
+
handleRawWebSocketHandler,
|
|
17
|
+
handleWebSocketConnect,
|
|
18
|
+
} from "@/actor/router-endpoints";
|
|
11
19
|
import type { Client } from "@/client/client";
|
|
20
|
+
import {
|
|
21
|
+
PATH_CONNECT_WEBSOCKET,
|
|
22
|
+
PATH_RAW_WEBSOCKET_PREFIX,
|
|
23
|
+
WS_PROTOCOL_CONN_PARAMS,
|
|
24
|
+
WS_PROTOCOL_ENCODING,
|
|
25
|
+
WS_PROTOCOL_TOKEN,
|
|
26
|
+
} from "@/common/actor-router-consts";
|
|
27
|
+
import type { UpgradeWebSocketArgs } from "@/common/inline-websocket-adapter2";
|
|
12
28
|
import { getLogger } from "@/common/log";
|
|
29
|
+
import type { UniversalWebSocket } from "@/common/websocket-interface";
|
|
13
30
|
import {
|
|
14
31
|
type ActorDriver,
|
|
15
32
|
type AnyActorInstance,
|
|
16
|
-
HEADER_AUTH_DATA,
|
|
17
|
-
HEADER_CONN_PARAMS,
|
|
18
|
-
HEADER_ENCODING,
|
|
19
33
|
type ManagerDriver,
|
|
20
34
|
serializeEmptyPersistData,
|
|
21
35
|
} from "@/driver-helpers/mod";
|
|
22
|
-
import type {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
RunConfig,
|
|
26
|
-
UniversalWebSocket,
|
|
27
|
-
UpgradeWebSocketArgs,
|
|
28
|
-
} from "@/mod";
|
|
29
|
-
import {
|
|
30
|
-
createActorRouter,
|
|
31
|
-
createGenericConnDrivers,
|
|
32
|
-
GenericConnGlobalState,
|
|
33
|
-
handleRawWebSocketHandler,
|
|
34
|
-
handleWebSocketConnect,
|
|
35
|
-
lookupInRegistry,
|
|
36
|
-
PATH_CONNECT_WEBSOCKET,
|
|
37
|
-
PATH_RAW_WEBSOCKET_PREFIX,
|
|
38
|
-
} from "@/mod";
|
|
36
|
+
import type { RegistryConfig } from "@/registry/config";
|
|
37
|
+
import type { RunConfig } from "@/registry/run-config";
|
|
38
|
+
import { promiseWithResolvers } from "@/utils";
|
|
39
39
|
import type { Config } from "./config";
|
|
40
40
|
import { KEYS } from "./kv";
|
|
41
41
|
import { logger } from "./log";
|
|
42
42
|
|
|
43
43
|
interface ActorHandler {
|
|
44
44
|
actor?: AnyActorInstance;
|
|
45
|
-
actorStartPromise?:
|
|
46
|
-
genericConnGlobalState: GenericConnGlobalState;
|
|
45
|
+
actorStartPromise?: ReturnType<typeof promiseWithResolvers<void>>;
|
|
47
46
|
persistedData?: Uint8Array;
|
|
48
47
|
}
|
|
49
48
|
|
|
@@ -60,6 +59,9 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
60
59
|
#actorRouter: ActorRouter;
|
|
61
60
|
#version: number = 1; // Version for the runner protocol
|
|
62
61
|
|
|
62
|
+
#runnerStarted: PromiseWithResolvers<undefined> = Promise.withResolvers();
|
|
63
|
+
#runnerStopped: PromiseWithResolvers<undefined> = Promise.withResolvers();
|
|
64
|
+
|
|
63
65
|
constructor(
|
|
64
66
|
registryConfig: RegistryConfig,
|
|
65
67
|
runConfig: RunConfig,
|
|
@@ -79,6 +81,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
79
81
|
const runnerConfig: RunnerConfig = {
|
|
80
82
|
version: this.#version,
|
|
81
83
|
endpoint: config.endpoint,
|
|
84
|
+
token: config.token,
|
|
82
85
|
pegboardEndpoint: config.pegboardEndpoint,
|
|
83
86
|
namespace: config.namespace,
|
|
84
87
|
totalSlots: config.totalSlots,
|
|
@@ -107,6 +110,8 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
107
110
|
runnerName: this.#config.runnerName,
|
|
108
111
|
});
|
|
109
112
|
}
|
|
113
|
+
|
|
114
|
+
this.#runnerStarted.resolve(undefined);
|
|
110
115
|
},
|
|
111
116
|
onDisconnected: () => {
|
|
112
117
|
logger().warn({
|
|
@@ -116,7 +121,9 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
116
121
|
});
|
|
117
122
|
hasDisconnected = true;
|
|
118
123
|
},
|
|
119
|
-
onShutdown: () => {
|
|
124
|
+
onShutdown: () => {
|
|
125
|
+
this.#runnerStopped.resolve(undefined);
|
|
126
|
+
},
|
|
120
127
|
fetch: this.#runnerFetch.bind(this),
|
|
121
128
|
websocket: this.#runnerWebSocket.bind(this),
|
|
122
129
|
onActorStart: this.#runnerOnActorStart.bind(this),
|
|
@@ -150,14 +157,6 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
150
157
|
return handler.actor;
|
|
151
158
|
}
|
|
152
159
|
|
|
153
|
-
getGenericConnGlobalState(actorId: string): GenericConnGlobalState {
|
|
154
|
-
const handler = this.#actors.get(actorId);
|
|
155
|
-
if (!handler) {
|
|
156
|
-
throw new Error(`Actor ${actorId} not loaded`);
|
|
157
|
-
}
|
|
158
|
-
return handler.genericConnGlobalState;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
160
|
getContext(actorId: string): DriverContext {
|
|
162
161
|
return {};
|
|
163
162
|
}
|
|
@@ -220,8 +219,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
220
219
|
let handler = this.#actors.get(actorId);
|
|
221
220
|
if (!handler) {
|
|
222
221
|
handler = {
|
|
223
|
-
|
|
224
|
-
actorStartPromise: Promise.withResolvers(),
|
|
222
|
+
actorStartPromise: promiseWithResolvers(),
|
|
225
223
|
persistedData: serializeEmptyPersistData(input),
|
|
226
224
|
};
|
|
227
225
|
this.#actors.set(actorId, handler);
|
|
@@ -239,11 +237,7 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
239
237
|
handler.actor = definition.instantiate();
|
|
240
238
|
|
|
241
239
|
// Start actor
|
|
242
|
-
const connDrivers = createGenericConnDrivers(
|
|
243
|
-
handler.genericConnGlobalState,
|
|
244
|
-
);
|
|
245
240
|
await handler.actor.start(
|
|
246
|
-
connDrivers,
|
|
247
241
|
this,
|
|
248
242
|
this.#inlineClient,
|
|
249
243
|
actorId,
|
|
@@ -292,14 +286,29 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
292
286
|
|
|
293
287
|
const url = new URL(request.url);
|
|
294
288
|
|
|
295
|
-
// Parse
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
289
|
+
// Parse configuration from Sec-WebSocket-Protocol header
|
|
290
|
+
const protocols = request.headers.get("sec-websocket-protocol");
|
|
291
|
+
if (protocols === null)
|
|
292
|
+
throw new Error(`Missing sec-websocket-protocol header`);
|
|
293
|
+
|
|
294
|
+
let encodingRaw: string | undefined;
|
|
295
|
+
let connParamsRaw: string | undefined;
|
|
296
|
+
|
|
297
|
+
if (protocols) {
|
|
298
|
+
const protocolList = protocols.split(",").map((p) => p.trim());
|
|
299
|
+
for (const protocol of protocolList) {
|
|
300
|
+
if (protocol.startsWith(WS_PROTOCOL_ENCODING)) {
|
|
301
|
+
encodingRaw = protocol.substring(WS_PROTOCOL_ENCODING.length);
|
|
302
|
+
} else if (protocol.startsWith(WS_PROTOCOL_CONN_PARAMS)) {
|
|
303
|
+
connParamsRaw = decodeURIComponent(
|
|
304
|
+
protocol.substring(WS_PROTOCOL_CONN_PARAMS.length),
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
299
309
|
|
|
300
310
|
const encoding = EncodingSchema.parse(encodingRaw);
|
|
301
311
|
const connParams = connParamsRaw ? JSON.parse(connParamsRaw) : undefined;
|
|
302
|
-
const authData = authDataRaw ? JSON.parse(authDataRaw) : undefined;
|
|
303
312
|
|
|
304
313
|
// Fetch WS handler
|
|
305
314
|
//
|
|
@@ -313,7 +322,9 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
313
322
|
actorId,
|
|
314
323
|
encoding,
|
|
315
324
|
connParams,
|
|
316
|
-
|
|
325
|
+
// Extract connId and connToken from protocols if needed
|
|
326
|
+
undefined,
|
|
327
|
+
undefined,
|
|
317
328
|
);
|
|
318
329
|
} else if (url.pathname.startsWith(PATH_RAW_WEBSOCKET_PREFIX)) {
|
|
319
330
|
wsHandlerPromise = handleRawWebSocketHandler(
|
|
@@ -321,7 +332,6 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
321
332
|
url.pathname + url.search,
|
|
322
333
|
this,
|
|
323
334
|
actorId,
|
|
324
|
-
authData,
|
|
325
335
|
);
|
|
326
336
|
} else {
|
|
327
337
|
throw new Error(`Unreachable path: ${url.pathname}`);
|
|
@@ -366,4 +376,17 @@ export class EngineActorDriver implements ActorDriver {
|
|
|
366
376
|
logger().info({ msg: "stopping engine actor driver" });
|
|
367
377
|
await this.#runner.shutdown(immediate);
|
|
368
378
|
}
|
|
379
|
+
|
|
380
|
+
async serverlessHandleStart(c: HonoContext): Promise<Response> {
|
|
381
|
+
await this.#runnerStarted.promise;
|
|
382
|
+
|
|
383
|
+
return streamSSE(c, async (stream) => {
|
|
384
|
+
// Runner id should be set if the runner started
|
|
385
|
+
const runnerId = this.#runner.runnerId;
|
|
386
|
+
invariant(runnerId, "runnerId not set");
|
|
387
|
+
stream.writeSSE({ data: runnerId });
|
|
388
|
+
|
|
389
|
+
return this.#runnerStopped.promise;
|
|
390
|
+
});
|
|
391
|
+
}
|
|
369
392
|
}
|
|
@@ -10,6 +10,10 @@ export const ConfigSchema = z
|
|
|
10
10
|
.default(
|
|
11
11
|
() => getEnvUniversal("RIVET_ENGINE") ?? "http://localhost:6420",
|
|
12
12
|
),
|
|
13
|
+
token: z
|
|
14
|
+
.string()
|
|
15
|
+
.optional()
|
|
16
|
+
.transform((val) => val ?? getEnvUniversal("RIVET_TOKEN")),
|
|
13
17
|
pegboardEndpoint: z.string().optional(),
|
|
14
18
|
namespace: z
|
|
15
19
|
.string()
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { GenericConnGlobalState } from "@/actor/generic-conn-driver";
|
|
2
|
-
import { loggerWithoutContext } from "@/actor/log";
|
|
3
1
|
import type { AnyClient } from "@/client/client";
|
|
4
2
|
import type {
|
|
5
3
|
ActorDriver,
|
|
@@ -46,10 +44,6 @@ export class FileSystemActorDriver implements ActorDriver {
|
|
|
46
44
|
);
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
getGenericConnGlobalState(actorId: string): GenericConnGlobalState {
|
|
50
|
-
return this.#state.getActorOrError(actorId).genericConnGlobalState;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
47
|
/**
|
|
54
48
|
* Get the current storage directory path
|
|
55
49
|
*/
|
|
@@ -5,10 +5,6 @@ import * as path from "node:path";
|
|
|
5
5
|
import invariant from "invariant";
|
|
6
6
|
import { lookupInRegistry } from "@/actor/definition";
|
|
7
7
|
import { ActorAlreadyExists } from "@/actor/errors";
|
|
8
|
-
import {
|
|
9
|
-
createGenericConnDrivers,
|
|
10
|
-
GenericConnGlobalState,
|
|
11
|
-
} from "@/actor/generic-conn-driver";
|
|
12
8
|
import type { AnyActorInstance } from "@/actor/instance";
|
|
13
9
|
import type { ActorKey } from "@/actor/mod";
|
|
14
10
|
import { generateRandomString } from "@/actor/utils";
|
|
@@ -27,7 +23,7 @@ import {
|
|
|
27
23
|
import {
|
|
28
24
|
bufferToArrayBuffer,
|
|
29
25
|
type LongTimeoutHandle,
|
|
30
|
-
|
|
26
|
+
promiseWithResolvers,
|
|
31
27
|
setLongTimeout,
|
|
32
28
|
stringifyError,
|
|
33
29
|
} from "@/utils";
|
|
@@ -49,9 +45,7 @@ interface ActorEntry {
|
|
|
49
45
|
|
|
50
46
|
actor?: AnyActorInstance;
|
|
51
47
|
/** Promise for starting the actor. */
|
|
52
|
-
startPromise?:
|
|
53
|
-
|
|
54
|
-
genericConnGlobalState: GenericConnGlobalState;
|
|
48
|
+
startPromise?: ReturnType<typeof promiseWithResolvers<void>>;
|
|
55
49
|
|
|
56
50
|
alarmTimeout?: LongTimeoutHandle;
|
|
57
51
|
/** The timestamp currently scheduled for this actor's alarm (ms since epoch). */
|
|
@@ -188,7 +182,6 @@ export class FileSystemGlobalState {
|
|
|
188
182
|
|
|
189
183
|
entry = {
|
|
190
184
|
id: actorId,
|
|
191
|
-
genericConnGlobalState: new GenericConnGlobalState(),
|
|
192
185
|
removed: false,
|
|
193
186
|
};
|
|
194
187
|
this.#actors.set(actorId, entry);
|
|
@@ -469,7 +462,7 @@ export class FileSystemGlobalState {
|
|
|
469
462
|
}
|
|
470
463
|
|
|
471
464
|
// Create start promise
|
|
472
|
-
entry.startPromise =
|
|
465
|
+
entry.startPromise = promiseWithResolvers();
|
|
473
466
|
|
|
474
467
|
try {
|
|
475
468
|
// Create actor
|
|
@@ -477,11 +470,7 @@ export class FileSystemGlobalState {
|
|
|
477
470
|
entry.actor = definition.instantiate();
|
|
478
471
|
|
|
479
472
|
// Start actor
|
|
480
|
-
const connDrivers = createGenericConnDrivers(
|
|
481
|
-
entry.genericConnGlobalState,
|
|
482
|
-
);
|
|
483
473
|
await entry.actor.start(
|
|
484
|
-
connDrivers,
|
|
485
474
|
actorDriver,
|
|
486
475
|
inlineClient,
|
|
487
476
|
actorId,
|
|
@@ -57,10 +57,6 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
57
57
|
this.#driverConfig = driverConfig;
|
|
58
58
|
|
|
59
59
|
if (runConfig.inspector.enabled) {
|
|
60
|
-
if (!this.#runConfig.inspector.token()) {
|
|
61
|
-
this.#runConfig.inspector.token = () =>
|
|
62
|
-
this.#state.getOrCreateInspectorAccessToken();
|
|
63
|
-
}
|
|
64
60
|
const startedAt = new Date().toISOString();
|
|
65
61
|
function transformActor(actorState: schema.ActorState): Actor {
|
|
66
62
|
return {
|
|
@@ -141,6 +137,8 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
141
137
|
actorId: string,
|
|
142
138
|
encoding: Encoding,
|
|
143
139
|
params: unknown,
|
|
140
|
+
connId?: string,
|
|
141
|
+
connToken?: string,
|
|
144
142
|
): Promise<UniversalWebSocket> {
|
|
145
143
|
// Handle raw WebSocket paths
|
|
146
144
|
const pathOnly = path.split("?")[0];
|
|
@@ -154,7 +152,8 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
154
152
|
actorId,
|
|
155
153
|
encoding,
|
|
156
154
|
params,
|
|
157
|
-
|
|
155
|
+
connId,
|
|
156
|
+
connToken,
|
|
158
157
|
);
|
|
159
158
|
return new InlineWebSocketAdapter2(wsHandler);
|
|
160
159
|
} else if (
|
|
@@ -168,7 +167,6 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
168
167
|
path,
|
|
169
168
|
this.#actorDriver,
|
|
170
169
|
actorId,
|
|
171
|
-
undefined,
|
|
172
170
|
);
|
|
173
171
|
return new InlineWebSocketAdapter2(wsHandler);
|
|
174
172
|
} else {
|
|
@@ -192,6 +190,8 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
192
190
|
actorId: string,
|
|
193
191
|
encoding: Encoding,
|
|
194
192
|
connParams: unknown,
|
|
193
|
+
connId?: string,
|
|
194
|
+
connToken?: string,
|
|
195
195
|
): Promise<Response> {
|
|
196
196
|
const upgradeWebSocket = this.#runConfig.getUpgradeWebSocket?.();
|
|
197
197
|
invariant(upgradeWebSocket, "missing getUpgradeWebSocket");
|
|
@@ -208,7 +208,8 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
208
208
|
actorId,
|
|
209
209
|
encoding,
|
|
210
210
|
connParams,
|
|
211
|
-
|
|
211
|
+
connId,
|
|
212
|
+
connToken,
|
|
212
213
|
);
|
|
213
214
|
return upgradeWebSocket(() => wsHandler)(c, noopNext());
|
|
214
215
|
} else if (
|
|
@@ -222,7 +223,6 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
222
223
|
path,
|
|
223
224
|
this.#actorDriver,
|
|
224
225
|
actorId,
|
|
225
|
-
undefined,
|
|
226
226
|
);
|
|
227
227
|
return upgradeWebSocket(() => wsHandler)(c, noopNext());
|
|
228
228
|
} else {
|
|
@@ -321,4 +321,8 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
321
321
|
data: this.#state.storagePath,
|
|
322
322
|
};
|
|
323
323
|
}
|
|
324
|
+
|
|
325
|
+
getOrCreateInspectorAccessToken() {
|
|
326
|
+
return this.#state.getOrCreateInspectorAccessToken();
|
|
327
|
+
}
|
|
324
328
|
}
|
package/src/inspector/actor.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
AnyDatabaseProvider,
|
|
9
9
|
InferDatabaseClient,
|
|
10
10
|
} from "@/actor/database";
|
|
11
|
+
import { promiseWithResolvers } from "@/utils";
|
|
11
12
|
import {
|
|
12
13
|
ColumnsSchema,
|
|
13
14
|
type Connection,
|
|
@@ -99,7 +100,7 @@ export function createActorInspectorRouter() {
|
|
|
99
100
|
});
|
|
100
101
|
});
|
|
101
102
|
|
|
102
|
-
const { promise } =
|
|
103
|
+
const { promise } = promiseWithResolvers<void>();
|
|
103
104
|
|
|
104
105
|
return promise;
|
|
105
106
|
},
|
|
@@ -128,7 +129,7 @@ export function createActorInspectorRouter() {
|
|
|
128
129
|
});
|
|
129
130
|
});
|
|
130
131
|
|
|
131
|
-
const { promise } =
|
|
132
|
+
const { promise } = promiseWithResolvers<void>();
|
|
132
133
|
|
|
133
134
|
return promise;
|
|
134
135
|
},
|
|
@@ -159,7 +160,7 @@ export function createActorInspectorRouter() {
|
|
|
159
160
|
});
|
|
160
161
|
});
|
|
161
162
|
|
|
162
|
-
const { promise } =
|
|
163
|
+
const { promise } = promiseWithResolvers<void>();
|
|
163
164
|
|
|
164
165
|
return promise;
|
|
165
166
|
},
|
package/src/inspector/config.ts
CHANGED
|
@@ -56,7 +56,16 @@ const defaultCors: CorsOptions = {
|
|
|
56
56
|
|
|
57
57
|
export const InspectorConfigSchema = z
|
|
58
58
|
.object({
|
|
59
|
-
enabled: z
|
|
59
|
+
enabled: z
|
|
60
|
+
.boolean()
|
|
61
|
+
.or(
|
|
62
|
+
z.object({
|
|
63
|
+
actor: z.boolean().optional().default(true),
|
|
64
|
+
manager: z.boolean().optional().default(true),
|
|
65
|
+
}),
|
|
66
|
+
)
|
|
67
|
+
.optional()
|
|
68
|
+
.default(defaultEnabled),
|
|
60
69
|
/** CORS configuration for the router. Uses Hono's CORS middleware options. */
|
|
61
70
|
cors: z
|
|
62
71
|
.custom<CorsOptions>()
|
package/src/inspector/mod.ts
CHANGED
package/src/inspector/utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import { createMiddleware } from "hono/factory";
|
|
3
|
+
import type { ManagerDriver } from "@/driver-helpers/mod";
|
|
3
4
|
import type { RunConfig } from "@/mod";
|
|
4
5
|
import type { RunConfigInput } from "@/registry/run-config";
|
|
5
6
|
import { inspectorLogger } from "./log";
|
|
@@ -28,10 +29,6 @@ export function compareSecrets(providedSecret: string, validSecret: string) {
|
|
|
28
29
|
|
|
29
30
|
export const secureInspector = (runConfig: RunConfig) =>
|
|
30
31
|
createMiddleware(async (c, next) => {
|
|
31
|
-
if (!runConfig.inspector.enabled) {
|
|
32
|
-
return c.text("Inspector is not enabled", 503);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
32
|
const userToken = c.req.header("Authorization")?.replace("Bearer ", "");
|
|
36
33
|
if (!userToken) {
|
|
37
34
|
return c.text("Unauthorized", 401);
|
|
@@ -74,3 +71,25 @@ export function getInspectorUrl(runConfig: RunConfigInput | undefined) {
|
|
|
74
71
|
|
|
75
72
|
return url.href;
|
|
76
73
|
}
|
|
74
|
+
|
|
75
|
+
export const isInspectorEnabled = (
|
|
76
|
+
runConfig: RunConfig,
|
|
77
|
+
context: "actor" | "manager",
|
|
78
|
+
) => {
|
|
79
|
+
if (typeof runConfig.inspector?.enabled === "boolean") {
|
|
80
|
+
return runConfig.inspector.enabled;
|
|
81
|
+
} else if (typeof runConfig.inspector?.enabled === "object") {
|
|
82
|
+
return runConfig.inspector.enabled[context];
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const configureInspectorAccessToken = (
|
|
88
|
+
runConfig: RunConfig,
|
|
89
|
+
managerDriver: ManagerDriver,
|
|
90
|
+
) => {
|
|
91
|
+
if (!runConfig.inspector?.token()) {
|
|
92
|
+
const token = managerDriver.getOrCreateInspectorAccessToken();
|
|
93
|
+
runConfig.inspector.token = () => token;
|
|
94
|
+
}
|
|
95
|
+
};
|
package/src/manager/driver.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Env, Hono, Context as HonoContext } from "hono";
|
|
2
2
|
import type { ActorKey, Encoding, UniversalWebSocket } from "@/actor/mod";
|
|
3
3
|
import type { ManagerInspector } from "@/inspector/manager";
|
|
4
|
-
import type { RunConfig } from "@/mod";
|
|
5
4
|
import type { RegistryConfig } from "@/registry/config";
|
|
5
|
+
import type { RunConfig } from "@/registry/run-config";
|
|
6
6
|
|
|
7
7
|
export type ManagerDriverBuilder = (
|
|
8
8
|
registryConfig: RegistryConfig,
|
|
@@ -21,6 +21,8 @@ export interface ManagerDriver {
|
|
|
21
21
|
actorId: string,
|
|
22
22
|
encoding: Encoding,
|
|
23
23
|
params: unknown,
|
|
24
|
+
connId?: string,
|
|
25
|
+
connToken?: string,
|
|
24
26
|
): Promise<UniversalWebSocket>;
|
|
25
27
|
proxyRequest(
|
|
26
28
|
c: HonoContext,
|
|
@@ -33,7 +35,8 @@ export interface ManagerDriver {
|
|
|
33
35
|
actorId: string,
|
|
34
36
|
encoding: Encoding,
|
|
35
37
|
params: unknown,
|
|
36
|
-
|
|
38
|
+
connId?: string,
|
|
39
|
+
connToken?: string,
|
|
37
40
|
): Promise<Response>;
|
|
38
41
|
|
|
39
42
|
displayInformation(): ManagerDisplayInformation;
|
|
@@ -46,6 +49,13 @@ export interface ManagerDriver {
|
|
|
46
49
|
* @internal
|
|
47
50
|
*/
|
|
48
51
|
readonly inspector?: ManagerInspector;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get or create the inspector access token.
|
|
55
|
+
* @internal
|
|
56
|
+
* @returns creates or returns existing inspector access token
|
|
57
|
+
*/
|
|
58
|
+
getOrCreateInspectorAccessToken: () => string;
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
export interface ManagerDisplayInformation {
|