rivetkit 2.0.24-rc.1 → 2.0.25-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 +6 -0
- package/dist/schemas/actor-persist/v2.ts +9 -3
- package/dist/schemas/actor-persist/v3.ts +280 -0
- package/dist/schemas/client-protocol/v1.ts +6 -0
- package/dist/schemas/client-protocol/v2.ts +438 -0
- package/dist/schemas/file-system-driver/v1.ts +6 -0
- package/dist/schemas/file-system-driver/v2.ts +142 -0
- package/dist/tsup/actor/errors.cjs +2 -4
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +7 -10
- package/dist/tsup/actor/errors.d.ts +7 -10
- package/dist/tsup/actor/errors.js +9 -11
- package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.cts → actor-router-consts-DzI2szci.d.cts} +5 -9
- package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.ts → actor-router-consts-DzI2szci.d.ts} +5 -9
- package/dist/tsup/{chunk-ZTH3KYFH.cjs → chunk-3FG5OJ3G.cjs} +3 -3
- package/dist/tsup/{chunk-ZTH3KYFH.cjs.map → chunk-3FG5OJ3G.cjs.map} +1 -1
- package/dist/tsup/{chunk-BLK27ES3.js → chunk-6JN6W6G3.js} +44 -56
- package/dist/tsup/chunk-6JN6W6G3.js.map +1 -0
- package/dist/tsup/chunk-7IBNNGQ2.js +514 -0
- package/dist/tsup/chunk-7IBNNGQ2.js.map +1 -0
- package/dist/tsup/{chunk-36JJ4IQB.cjs → chunk-AZATXPR4.cjs} +4 -8
- package/dist/tsup/chunk-AZATXPR4.cjs.map +1 -0
- package/dist/tsup/chunk-B7MENRD5.cjs +5694 -0
- package/dist/tsup/chunk-B7MENRD5.cjs.map +1 -0
- package/dist/tsup/{chunk-BOMZS2TJ.js → chunk-BBVFDEYD.js} +9 -9
- package/dist/tsup/chunk-BBVFDEYD.js.map +1 -0
- package/dist/tsup/{chunk-KSRXX3Z4.cjs → chunk-D6762AOA.cjs} +20 -25
- package/dist/tsup/chunk-D6762AOA.cjs.map +1 -0
- package/dist/tsup/{chunk-2JYPS5YM.cjs → chunk-E63WZNMR.cjs} +6 -6
- package/dist/tsup/chunk-E63WZNMR.cjs.map +1 -0
- package/dist/tsup/{chunk-YBG6R7LX.js → chunk-EDGN4OC7.js} +3 -7
- package/dist/tsup/chunk-EDGN4OC7.js.map +1 -0
- package/dist/tsup/{chunk-BYMKMOBS.js → chunk-FLOQ3UWM.js} +1844 -1681
- package/dist/tsup/chunk-FLOQ3UWM.js.map +1 -0
- package/dist/tsup/{chunk-7L65NNWP.cjs → chunk-H7GV5DIW.cjs} +187 -185
- package/dist/tsup/chunk-H7GV5DIW.cjs.map +1 -0
- package/dist/tsup/{chunk-227FEWMB.js → chunk-HZYZ7JSF.js} +3322 -2251
- package/dist/tsup/chunk-HZYZ7JSF.js.map +1 -0
- package/dist/tsup/{chunk-FX7TWFQR.js → chunk-IDJK7ILQ.js} +2 -6
- package/dist/tsup/chunk-IDJK7ILQ.js.map +1 -0
- package/dist/tsup/{chunk-VHGY7PU5.cjs → chunk-ILFXA4AL.cjs} +1900 -1737
- package/dist/tsup/chunk-ILFXA4AL.cjs.map +1 -0
- package/dist/tsup/chunk-MV6M3FDL.cjs +514 -0
- package/dist/tsup/chunk-MV6M3FDL.cjs.map +1 -0
- package/dist/tsup/{chunk-PLUN2NQT.js → chunk-NWBKMCWC.js} +189 -187
- package/dist/tsup/chunk-NWBKMCWC.js.map +1 -0
- package/dist/tsup/{chunk-CD33GT6Z.js → chunk-QIHBDXTO.js} +2 -2
- package/dist/tsup/{chunk-G64QUEDJ.js → chunk-W6RDS6NW.js} +23 -28
- package/dist/tsup/chunk-W6RDS6NW.js.map +1 -0
- package/dist/tsup/{chunk-INNFK746.cjs → chunk-WQU4M4ZC.cjs} +10 -14
- package/dist/tsup/chunk-WQU4M4ZC.cjs.map +1 -0
- package/dist/tsup/{chunk-SHVX2QUR.cjs → chunk-XKZA47XS.cjs} +17 -17
- package/dist/tsup/chunk-XKZA47XS.cjs.map +1 -0
- package/dist/tsup/{chunk-HHFKKVLR.cjs → chunk-YHWIOWVA.cjs} +45 -57
- package/dist/tsup/chunk-YHWIOWVA.cjs.map +1 -0
- package/dist/tsup/{chunk-YBHYXIP6.js → chunk-YVL6IRUM.js} +3 -3
- package/dist/tsup/chunk-YVL6IRUM.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +5 -7
- package/dist/tsup/client/mod.d.ts +5 -7
- 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-B3Vhbgnd.d.ts → config-BRDYDraU.d.cts} +1119 -1047
- package/dist/tsup/{conn-DJWL3nGx.d.cts → config-Bo-blHpJ.d.ts} +1119 -1047
- package/dist/tsup/driver-helpers/mod.cjs +5 -13
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +11 -9
- package/dist/tsup/driver-helpers/mod.d.ts +11 -9
- package/dist/tsup/driver-helpers/mod.js +14 -22
- package/dist/tsup/driver-test-suite/mod.cjs +474 -303
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +6 -9
- package/dist/tsup/driver-test-suite/mod.d.ts +6 -9
- package/dist/tsup/driver-test-suite/mod.js +1085 -914
- 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 +5 -7
- package/dist/tsup/inspector/mod.d.ts +5 -7
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/mod.cjs +10 -16
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +23 -25
- package/dist/tsup/mod.d.ts +23 -25
- package/dist/tsup/mod.js +17 -23
- package/dist/tsup/test/mod.cjs +11 -11
- package/dist/tsup/test/mod.d.cts +4 -6
- package/dist/tsup/test/mod.d.ts +4 -6
- package/dist/tsup/test/mod.js +10 -10
- package/dist/tsup/utils.cjs +3 -5
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +1 -2
- package/dist/tsup/utils.d.ts +1 -2
- package/dist/tsup/utils.js +2 -4
- package/package.json +13 -6
- package/src/actor/config.ts +56 -44
- package/src/actor/conn/driver.ts +61 -0
- package/src/actor/conn/drivers/http.ts +17 -0
- package/src/actor/conn/drivers/raw-request.ts +24 -0
- package/src/actor/conn/drivers/raw-websocket.ts +65 -0
- package/src/actor/conn/drivers/websocket.ts +129 -0
- package/src/actor/conn/mod.ts +232 -0
- package/src/actor/conn/persisted.ts +81 -0
- package/src/actor/conn/state-manager.ts +196 -0
- package/src/actor/contexts/action.ts +23 -0
- package/src/actor/{context.ts → contexts/actor.ts} +19 -8
- package/src/actor/contexts/conn-init.ts +31 -0
- package/src/actor/contexts/conn.ts +48 -0
- package/src/actor/contexts/create-conn-state.ts +13 -0
- package/src/actor/contexts/on-before-connect.ts +13 -0
- package/src/actor/contexts/on-connect.ts +22 -0
- package/src/actor/contexts/request.ts +48 -0
- package/src/actor/contexts/websocket.ts +48 -0
- package/src/actor/definition.ts +3 -3
- package/src/actor/driver.ts +36 -5
- package/src/actor/errors.ts +19 -24
- package/src/actor/instance/connection-manager.ts +465 -0
- package/src/actor/instance/event-manager.ts +292 -0
- package/src/actor/instance/kv.ts +15 -0
- package/src/actor/instance/mod.ts +1107 -0
- package/src/actor/instance/persisted.ts +67 -0
- package/src/actor/instance/schedule-manager.ts +349 -0
- package/src/actor/instance/state-manager.ts +502 -0
- package/src/actor/mod.ts +13 -16
- package/src/actor/protocol/old.ts +131 -43
- package/src/actor/protocol/serde.ts +19 -4
- package/src/actor/router-endpoints.ts +61 -586
- package/src/actor/router-websocket-endpoints.ts +408 -0
- package/src/actor/router.ts +63 -197
- package/src/actor/schedule.ts +1 -1
- package/src/client/actor-conn.ts +183 -249
- package/src/client/actor-handle.ts +29 -6
- package/src/client/client.ts +0 -4
- package/src/client/config.ts +1 -4
- package/src/client/mod.ts +0 -1
- package/src/client/raw-utils.ts +3 -3
- package/src/client/utils.ts +85 -39
- package/src/common/actor-router-consts.ts +5 -12
- package/src/common/{inline-websocket-adapter2.ts → inline-websocket-adapter.ts} +26 -48
- package/src/common/log.ts +1 -1
- package/src/common/router.ts +28 -17
- package/src/common/utils.ts +2 -0
- package/src/driver-helpers/mod.ts +7 -10
- package/src/driver-helpers/utils.ts +18 -9
- package/src/driver-test-suite/mod.ts +26 -50
- package/src/driver-test-suite/test-inline-client-driver.ts +27 -51
- package/src/driver-test-suite/tests/actor-conn-hibernation.ts +150 -0
- package/src/driver-test-suite/tests/actor-conn-state.ts +1 -4
- package/src/driver-test-suite/tests/actor-conn.ts +5 -9
- package/src/driver-test-suite/tests/actor-destroy.ts +294 -0
- package/src/driver-test-suite/tests/actor-driver.ts +0 -7
- package/src/driver-test-suite/tests/actor-handle.ts +12 -12
- package/src/driver-test-suite/tests/actor-metadata.ts +1 -1
- package/src/driver-test-suite/tests/manager-driver.ts +1 -1
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +8 -8
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +6 -5
- package/src/driver-test-suite/tests/raw-http.ts +5 -5
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +7 -7
- package/src/driver-test-suite/tests/request-access.ts +4 -4
- package/src/driver-test-suite/utils.ts +6 -10
- package/src/drivers/engine/actor-driver.ts +614 -424
- package/src/drivers/engine/mod.ts +0 -1
- package/src/drivers/file-system/actor.ts +24 -12
- package/src/drivers/file-system/global-state.ts +427 -37
- package/src/drivers/file-system/manager.ts +71 -83
- package/src/drivers/file-system/mod.ts +3 -0
- package/src/drivers/file-system/utils.ts +18 -8
- package/src/engine-process/mod.ts +38 -38
- package/src/inspector/utils.ts +7 -5
- package/src/manager/driver.ts +11 -4
- package/src/manager/gateway.ts +4 -29
- package/src/manager/protocol/mod.ts +0 -2
- package/src/manager/protocol/query.ts +0 -4
- package/src/manager/router.ts +67 -64
- package/src/manager-api/actors.ts +13 -0
- package/src/mod.ts +1 -3
- package/src/registry/mod.ts +20 -20
- package/src/registry/serve.ts +9 -14
- package/src/remote-manager-driver/actor-websocket-client.ts +1 -16
- package/src/remote-manager-driver/api-endpoints.ts +13 -1
- package/src/remote-manager-driver/api-utils.ts +8 -0
- package/src/remote-manager-driver/metadata.ts +58 -0
- package/src/remote-manager-driver/mod.ts +47 -62
- package/src/remote-manager-driver/ws-proxy.ts +1 -1
- package/src/schemas/actor-persist/mod.ts +1 -1
- package/src/schemas/actor-persist/versioned.ts +56 -31
- package/src/schemas/client-protocol/mod.ts +1 -1
- package/src/schemas/client-protocol/versioned.ts +41 -21
- package/src/schemas/client-protocol-zod/mod.ts +103 -0
- package/src/schemas/file-system-driver/mod.ts +1 -1
- package/src/schemas/file-system-driver/versioned.ts +42 -19
- package/src/serde.ts +33 -11
- package/src/test/mod.ts +7 -3
- package/src/utils/node.ts +173 -0
- package/src/utils.ts +0 -4
- package/dist/tsup/chunk-227FEWMB.js.map +0 -1
- package/dist/tsup/chunk-2JYPS5YM.cjs.map +0 -1
- package/dist/tsup/chunk-36JJ4IQB.cjs.map +0 -1
- package/dist/tsup/chunk-7L65NNWP.cjs.map +0 -1
- package/dist/tsup/chunk-BLK27ES3.js.map +0 -1
- package/dist/tsup/chunk-BOMZS2TJ.js.map +0 -1
- package/dist/tsup/chunk-BYMKMOBS.js.map +0 -1
- package/dist/tsup/chunk-FX7TWFQR.js.map +0 -1
- package/dist/tsup/chunk-G64QUEDJ.js.map +0 -1
- package/dist/tsup/chunk-HHFKKVLR.cjs.map +0 -1
- package/dist/tsup/chunk-INNFK746.cjs.map +0 -1
- package/dist/tsup/chunk-KSRXX3Z4.cjs.map +0 -1
- package/dist/tsup/chunk-O44LFKSB.cjs +0 -4623
- package/dist/tsup/chunk-O44LFKSB.cjs.map +0 -1
- package/dist/tsup/chunk-PLUN2NQT.js.map +0 -1
- package/dist/tsup/chunk-S4UJG7ZE.js +0 -1119
- package/dist/tsup/chunk-S4UJG7ZE.js.map +0 -1
- package/dist/tsup/chunk-SHVX2QUR.cjs.map +0 -1
- package/dist/tsup/chunk-VFB23BYZ.cjs +0 -1119
- package/dist/tsup/chunk-VFB23BYZ.cjs.map +0 -1
- package/dist/tsup/chunk-VHGY7PU5.cjs.map +0 -1
- package/dist/tsup/chunk-YBG6R7LX.js.map +0 -1
- package/dist/tsup/chunk-YBHYXIP6.js.map +0 -1
- package/src/actor/action.ts +0 -178
- package/src/actor/conn-drivers.ts +0 -216
- package/src/actor/conn-socket.ts +0 -8
- package/src/actor/conn.ts +0 -272
- package/src/actor/instance.ts +0 -2336
- package/src/actor/persisted.ts +0 -49
- package/src/actor/unstable-react.ts +0 -110
- package/src/driver-test-suite/tests/actor-reconnect.ts +0 -170
- package/src/drivers/engine/kv.ts +0 -3
- package/src/manager/hono-websocket-adapter.ts +0 -393
- /package/dist/tsup/{chunk-CD33GT6Z.js.map → chunk-QIHBDXTO.js.map} +0 -0
|
@@ -3,9 +3,7 @@ import { EncodingSchema } from "@/actor/protocol/serde";
|
|
|
3
3
|
import {
|
|
4
4
|
HEADER_ACTOR_ID,
|
|
5
5
|
HEADER_ACTOR_QUERY,
|
|
6
|
-
HEADER_CONN_ID,
|
|
7
6
|
HEADER_CONN_PARAMS,
|
|
8
|
-
HEADER_CONN_TOKEN,
|
|
9
7
|
HEADER_ENCODING,
|
|
10
8
|
} from "@/common/actor-router-consts";
|
|
11
9
|
|
|
@@ -69,9 +67,7 @@ export const ConnectWebSocketRequestSchema = z.object({
|
|
|
69
67
|
|
|
70
68
|
export const ConnMessageRequestSchema = z.object({
|
|
71
69
|
actorId: z.string().describe(HEADER_ACTOR_ID),
|
|
72
|
-
connId: z.string().describe(HEADER_CONN_ID),
|
|
73
70
|
encoding: EncodingSchema.describe(HEADER_ENCODING),
|
|
74
|
-
connToken: z.string().describe(HEADER_CONN_TOKEN),
|
|
75
71
|
});
|
|
76
72
|
|
|
77
73
|
export const ResolveRequestSchema = z.object({
|
package/src/manager/router.ts
CHANGED
|
@@ -7,20 +7,16 @@ import {
|
|
|
7
7
|
type Next,
|
|
8
8
|
} from "hono";
|
|
9
9
|
import { createMiddleware } from "hono/factory";
|
|
10
|
-
import { streamSSE } from "hono/streaming";
|
|
11
10
|
import invariant from "invariant";
|
|
12
11
|
import { z } from "zod";
|
|
13
12
|
import { ActorNotFound, InvalidRequest, Unsupported } from "@/actor/errors";
|
|
14
13
|
import { serializeActorKey } from "@/actor/keys";
|
|
15
|
-
import type { Client, Encoding
|
|
14
|
+
import type { Client, Encoding } from "@/client/mod";
|
|
16
15
|
import {
|
|
17
16
|
WS_PROTOCOL_ACTOR,
|
|
18
|
-
WS_PROTOCOL_CONN_ID,
|
|
19
17
|
WS_PROTOCOL_CONN_PARAMS,
|
|
20
|
-
WS_PROTOCOL_CONN_TOKEN,
|
|
21
18
|
WS_PROTOCOL_ENCODING,
|
|
22
|
-
|
|
23
|
-
WS_PROTOCOL_TRANSPORT,
|
|
19
|
+
WS_TEST_PROTOCOL_PATH,
|
|
24
20
|
} from "@/common/actor-router-consts";
|
|
25
21
|
import { cors } from "@/common/cors";
|
|
26
22
|
import {
|
|
@@ -50,12 +46,14 @@ import {
|
|
|
50
46
|
ActorsGetOrCreateRequestSchema,
|
|
51
47
|
type ActorsGetOrCreateResponse,
|
|
52
48
|
ActorsGetOrCreateResponseSchema,
|
|
49
|
+
type ActorsListNamesResponse,
|
|
50
|
+
ActorsListNamesResponseSchema,
|
|
53
51
|
type ActorsListResponse,
|
|
54
52
|
ActorsListResponseSchema,
|
|
55
53
|
type Actor as ApiActor,
|
|
56
54
|
} from "@/manager-api/actors";
|
|
57
55
|
import type { AnyClient } from "@/mod";
|
|
58
|
-
import type
|
|
56
|
+
import { buildActorNames, type RegistryConfig } from "@/registry/config";
|
|
59
57
|
import type { DriverConfig, RunnerConfig } from "@/registry/run-config";
|
|
60
58
|
import type { ActorOutput, ManagerDriver } from "./driver";
|
|
61
59
|
import { actorGateway, createTestWebSocketProxy } from "./gateway";
|
|
@@ -81,6 +79,17 @@ function buildOpenApiResponses<T>(schema: T) {
|
|
|
81
79
|
};
|
|
82
80
|
}
|
|
83
81
|
|
|
82
|
+
function buildOpenApiRequestBody<T>(schema: T) {
|
|
83
|
+
return {
|
|
84
|
+
required: true,
|
|
85
|
+
content: {
|
|
86
|
+
"application/json": {
|
|
87
|
+
schema,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
84
93
|
export function createManagerRouter(
|
|
85
94
|
registryConfig: RegistryConfig,
|
|
86
95
|
runConfig: RunnerConfig,
|
|
@@ -222,6 +231,7 @@ function addManagerRoutes(
|
|
|
222
231
|
managerDriver: ManagerDriver,
|
|
223
232
|
router: OpenAPIHono,
|
|
224
233
|
) {
|
|
234
|
+
// TODO(kacper): Remove this in favor of standard manager API
|
|
225
235
|
// Inspector
|
|
226
236
|
if (isInspectorEnabled(runConfig, "manager")) {
|
|
227
237
|
if (!managerDriver.inspector) {
|
|
@@ -290,17 +300,7 @@ function addManagerRoutes(
|
|
|
290
300
|
if (key && !name) {
|
|
291
301
|
return c.json(
|
|
292
302
|
{
|
|
293
|
-
error: "
|
|
294
|
-
},
|
|
295
|
-
400,
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Validate: must provide either actor_ids or (name + key)
|
|
300
|
-
if (!actorIdsParsed && !key) {
|
|
301
|
-
return c.json(
|
|
302
|
-
{
|
|
303
|
-
error: "Must provide either 'actor_ids' or both 'name' and 'key'.",
|
|
303
|
+
error: "Name is required when key is provided.",
|
|
304
304
|
},
|
|
305
305
|
400,
|
|
306
306
|
);
|
|
@@ -352,16 +352,33 @@ function addManagerRoutes(
|
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
|
-
} else if (key) {
|
|
356
|
-
// At this point, name is guaranteed to be defined due to validation above
|
|
355
|
+
} else if (key && name) {
|
|
357
356
|
const actorOutput = await managerDriver.getWithKey({
|
|
358
357
|
c,
|
|
359
|
-
name
|
|
358
|
+
name,
|
|
360
359
|
key: [key], // Convert string to ActorKey array
|
|
361
360
|
});
|
|
362
361
|
if (actorOutput) {
|
|
363
362
|
actors.push(actorOutput);
|
|
364
363
|
}
|
|
364
|
+
} else {
|
|
365
|
+
if (!name) {
|
|
366
|
+
return c.json(
|
|
367
|
+
{
|
|
368
|
+
error: "Name is required when not using actor_ids.",
|
|
369
|
+
},
|
|
370
|
+
400,
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// List all actors with the given name
|
|
375
|
+
const actorOutputs = await managerDriver.listActors({
|
|
376
|
+
c,
|
|
377
|
+
name,
|
|
378
|
+
key,
|
|
379
|
+
includeDestroyed: false,
|
|
380
|
+
});
|
|
381
|
+
actors.push(...actorOutputs);
|
|
365
382
|
}
|
|
366
383
|
|
|
367
384
|
return c.json<ActorsListResponse>({
|
|
@@ -372,19 +389,34 @@ function addManagerRoutes(
|
|
|
372
389
|
});
|
|
373
390
|
}
|
|
374
391
|
|
|
392
|
+
// GET /actors/names
|
|
393
|
+
{
|
|
394
|
+
const route = createRoute({
|
|
395
|
+
method: "get",
|
|
396
|
+
path: "/actors/names",
|
|
397
|
+
request: {
|
|
398
|
+
query: z.object({
|
|
399
|
+
namespace: z.string(),
|
|
400
|
+
}),
|
|
401
|
+
},
|
|
402
|
+
responses: buildOpenApiResponses(ActorsListNamesResponseSchema),
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
router.openapi(route, async (c) => {
|
|
406
|
+
const names = buildActorNames(registryConfig);
|
|
407
|
+
return c.json<ActorsListNamesResponse>({
|
|
408
|
+
names,
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
375
413
|
// PUT /actors
|
|
376
414
|
{
|
|
377
415
|
const route = createRoute({
|
|
378
416
|
method: "put",
|
|
379
417
|
path: "/actors",
|
|
380
418
|
request: {
|
|
381
|
-
body:
|
|
382
|
-
content: {
|
|
383
|
-
"application/json": {
|
|
384
|
-
schema: ActorsGetOrCreateRequestSchema,
|
|
385
|
-
},
|
|
386
|
-
},
|
|
387
|
-
},
|
|
419
|
+
body: buildOpenApiRequestBody(ActorsGetOrCreateRequestSchema),
|
|
388
420
|
},
|
|
389
421
|
responses: buildOpenApiResponses(ActorsGetOrCreateResponseSchema),
|
|
390
422
|
});
|
|
@@ -430,13 +462,7 @@ function addManagerRoutes(
|
|
|
430
462
|
method: "post",
|
|
431
463
|
path: "/actors",
|
|
432
464
|
request: {
|
|
433
|
-
body:
|
|
434
|
-
content: {
|
|
435
|
-
"application/json": {
|
|
436
|
-
schema: ActorsCreateRequestSchema,
|
|
437
|
-
},
|
|
438
|
-
},
|
|
439
|
-
},
|
|
465
|
+
body: buildOpenApiRequestBody(ActorsCreateRequestSchema),
|
|
440
466
|
},
|
|
441
467
|
responses: buildOpenApiResponses(ActorsCreateResponseSchema),
|
|
442
468
|
});
|
|
@@ -492,19 +518,12 @@ function addManagerRoutes(
|
|
|
492
518
|
router.post(".test/inline-driver/call", async (c) => {
|
|
493
519
|
// TODO: use openapi instead
|
|
494
520
|
const buffer = await c.req.arrayBuffer();
|
|
495
|
-
const {
|
|
496
|
-
|
|
497
|
-
transport,
|
|
498
|
-
method,
|
|
499
|
-
args,
|
|
500
|
-
}: TestInlineDriverCallRequest = cbor.decode(
|
|
501
|
-
new Uint8Array(buffer),
|
|
502
|
-
);
|
|
521
|
+
const { encoding, method, args }: TestInlineDriverCallRequest =
|
|
522
|
+
cbor.decode(new Uint8Array(buffer));
|
|
503
523
|
|
|
504
524
|
logger().debug({
|
|
505
525
|
msg: "received inline request",
|
|
506
526
|
encoding,
|
|
507
|
-
transport,
|
|
508
527
|
method,
|
|
509
528
|
args,
|
|
510
529
|
});
|
|
@@ -541,38 +560,25 @@ function addManagerRoutes(
|
|
|
541
560
|
// Parse protocols to extract connection info
|
|
542
561
|
let actorId = "";
|
|
543
562
|
let encoding: Encoding = "bare";
|
|
544
|
-
let transport: Transport = "websocket";
|
|
545
563
|
let path = "";
|
|
546
564
|
let params: unknown;
|
|
547
|
-
let connId: string | undefined;
|
|
548
|
-
let connToken: string | undefined;
|
|
549
565
|
|
|
550
566
|
for (const protocol of protocols) {
|
|
551
567
|
if (protocol.startsWith(WS_PROTOCOL_ACTOR)) {
|
|
552
|
-
actorId = protocol.substring(WS_PROTOCOL_ACTOR.length);
|
|
568
|
+
actorId = decodeURIComponent(protocol.substring(WS_PROTOCOL_ACTOR.length));
|
|
553
569
|
} else if (protocol.startsWith(WS_PROTOCOL_ENCODING)) {
|
|
554
570
|
encoding = protocol.substring(
|
|
555
571
|
WS_PROTOCOL_ENCODING.length,
|
|
556
572
|
) as Encoding;
|
|
557
|
-
} else if (protocol.startsWith(
|
|
558
|
-
transport = protocol.substring(
|
|
559
|
-
WS_PROTOCOL_TRANSPORT.length,
|
|
560
|
-
) as Transport;
|
|
561
|
-
} else if (protocol.startsWith(WS_PROTOCOL_PATH)) {
|
|
573
|
+
} else if (protocol.startsWith(WS_TEST_PROTOCOL_PATH)) {
|
|
562
574
|
path = decodeURIComponent(
|
|
563
|
-
protocol.substring(
|
|
575
|
+
protocol.substring(WS_TEST_PROTOCOL_PATH.length),
|
|
564
576
|
);
|
|
565
577
|
} else if (protocol.startsWith(WS_PROTOCOL_CONN_PARAMS)) {
|
|
566
578
|
const paramsRaw = decodeURIComponent(
|
|
567
579
|
protocol.substring(WS_PROTOCOL_CONN_PARAMS.length),
|
|
568
580
|
);
|
|
569
581
|
params = JSON.parse(paramsRaw);
|
|
570
|
-
} else if (protocol.startsWith(WS_PROTOCOL_CONN_ID)) {
|
|
571
|
-
connId = protocol.substring(WS_PROTOCOL_CONN_ID.length);
|
|
572
|
-
} else if (protocol.startsWith(WS_PROTOCOL_CONN_TOKEN)) {
|
|
573
|
-
connToken = protocol.substring(
|
|
574
|
-
WS_PROTOCOL_CONN_TOKEN.length,
|
|
575
|
-
);
|
|
576
582
|
}
|
|
577
583
|
}
|
|
578
584
|
|
|
@@ -581,7 +587,6 @@ function addManagerRoutes(
|
|
|
581
587
|
actorId,
|
|
582
588
|
params,
|
|
583
589
|
encodingKind: encoding,
|
|
584
|
-
transport,
|
|
585
590
|
path: path,
|
|
586
591
|
});
|
|
587
592
|
|
|
@@ -591,8 +596,6 @@ function addManagerRoutes(
|
|
|
591
596
|
actorId,
|
|
592
597
|
encoding,
|
|
593
598
|
params,
|
|
594
|
-
connId,
|
|
595
|
-
connToken,
|
|
596
599
|
);
|
|
597
600
|
|
|
598
601
|
return await createTestWebSocketProxy(clientWsPromise);
|
|
@@ -725,7 +728,7 @@ function createApiActor(
|
|
|
725
728
|
key: serializeActorKey(actor.key),
|
|
726
729
|
namespace_id: "default", // Assert default namespace
|
|
727
730
|
runner_name_selector: runnerName,
|
|
728
|
-
create_ts: Date.now(),
|
|
731
|
+
create_ts: actor.createTs ?? Date.now(),
|
|
729
732
|
connectable_ts: null,
|
|
730
733
|
destroy_ts: null,
|
|
731
734
|
sleep_ts: null,
|
|
@@ -15,6 +15,11 @@ export const ActorSchema = z.object({
|
|
|
15
15
|
});
|
|
16
16
|
export type Actor = z.infer<typeof ActorSchema>;
|
|
17
17
|
|
|
18
|
+
export const ActorNameSchema = z.object({
|
|
19
|
+
metadata: z.record(z.string(), z.unknown()),
|
|
20
|
+
});
|
|
21
|
+
export type ActorName = z.infer<typeof ActorNameSchema>;
|
|
22
|
+
|
|
18
23
|
// MARK: GET /actors
|
|
19
24
|
export const ActorsListResponseSchema = z.object({
|
|
20
25
|
actors: z.array(ActorSchema),
|
|
@@ -61,3 +66,11 @@ export type ActorsGetOrCreateResponse = z.infer<
|
|
|
61
66
|
// MARK: DELETE /actors/{}
|
|
62
67
|
export const ActorsDeleteResponseSchema = z.object({});
|
|
63
68
|
export type ActorsDeleteResponse = z.infer<typeof ActorsDeleteResponseSchema>;
|
|
69
|
+
|
|
70
|
+
// MARK: GET /actors/names
|
|
71
|
+
export const ActorsListNamesResponseSchema = z.object({
|
|
72
|
+
names: z.record(z.string(), ActorNameSchema),
|
|
73
|
+
});
|
|
74
|
+
export type ActorsListNamesResponse = z.infer<
|
|
75
|
+
typeof ActorsListNamesResponseSchema
|
|
76
|
+
>;
|
package/src/mod.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
export { generateConnId, generateConnToken } from "@/actor/conn";
|
|
2
1
|
export * from "@/actor/mod";
|
|
3
2
|
export {
|
|
4
3
|
type AnyClient,
|
|
5
4
|
type Client,
|
|
6
5
|
createClientWithDriver,
|
|
7
6
|
} from "@/client/client";
|
|
8
|
-
export {
|
|
7
|
+
export { InlineWebSocketAdapter } from "@/common/inline-websocket-adapter";
|
|
9
8
|
export { noopNext } from "@/common/utils";
|
|
10
9
|
export { createEngineDriver } from "@/drivers/engine/mod";
|
|
11
10
|
export {
|
|
12
11
|
createFileSystemDriver,
|
|
13
12
|
createMemoryDriver,
|
|
14
13
|
} from "@/drivers/file-system/mod";
|
|
15
|
-
// Re-export important protocol types and utilities needed by drivers
|
|
16
14
|
export type { ActorQuery } from "@/manager/protocol/query";
|
|
17
15
|
export * from "@/registry/mod";
|
|
18
16
|
export { toUint8Array } from "@/utils";
|
package/src/registry/mod.ts
CHANGED
|
@@ -72,7 +72,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// Promise for any async operations we need to wait to complete
|
|
75
|
-
const readyPromises = [];
|
|
75
|
+
const readyPromises: Promise<unknown>[] = [];
|
|
76
76
|
|
|
77
77
|
// Disable health check if using serverless
|
|
78
78
|
//
|
|
@@ -80,7 +80,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
80
80
|
// a serverless runner request, so we do not know what to health check
|
|
81
81
|
if (config.runnerKind === "serverless") {
|
|
82
82
|
logger().debug("disabling health check since using serverless");
|
|
83
|
-
config.
|
|
83
|
+
config.disableMetadataLookup = true;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// Auto-configure serverless runner if not in prod
|
|
@@ -209,6 +209,23 @@ export class Registry<A extends RegistryActors> {
|
|
|
209
209
|
console.log();
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
const { router: hono } = createManagerRouter(
|
|
213
|
+
this.#config,
|
|
214
|
+
config,
|
|
215
|
+
managerDriver,
|
|
216
|
+
driver,
|
|
217
|
+
client,
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
// Start server
|
|
221
|
+
if (!config.disableDefaultServer) {
|
|
222
|
+
const serverPromise = (async () => {
|
|
223
|
+
const out = await crossPlatformServe(config, hono);
|
|
224
|
+
upgradeWebSocket = out.upgradeWebSocket;
|
|
225
|
+
})();
|
|
226
|
+
readyPromises.push(serverPromise);
|
|
227
|
+
}
|
|
228
|
+
|
|
212
229
|
// HACK: We need to find a better way to let the driver itself decide when to start the actor driver
|
|
213
230
|
// Create runner
|
|
214
231
|
//
|
|
@@ -230,22 +247,6 @@ export class Registry<A extends RegistryActors> {
|
|
|
230
247
|
});
|
|
231
248
|
}
|
|
232
249
|
|
|
233
|
-
const { router: hono } = createManagerRouter(
|
|
234
|
-
this.#config,
|
|
235
|
-
config,
|
|
236
|
-
managerDriver,
|
|
237
|
-
driver,
|
|
238
|
-
client,
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
// Start server
|
|
242
|
-
if (!config.disableDefaultServer) {
|
|
243
|
-
(async () => {
|
|
244
|
-
const out = await crossPlatformServe(config, hono, undefined);
|
|
245
|
-
upgradeWebSocket = out.upgradeWebSocket;
|
|
246
|
-
})();
|
|
247
|
-
}
|
|
248
|
-
|
|
249
250
|
return {
|
|
250
251
|
client,
|
|
251
252
|
fetch: hono.fetch.bind(hono),
|
|
@@ -287,10 +288,9 @@ async function configureServerlessRunner(config: RunnerConfig): Promise<void> {
|
|
|
287
288
|
namespace: config.namespace,
|
|
288
289
|
runnerName: config.runnerName,
|
|
289
290
|
encoding: config.encoding,
|
|
290
|
-
transport: config.transport,
|
|
291
291
|
headers: config.headers,
|
|
292
292
|
getUpgradeWebSocket: config.getUpgradeWebSocket,
|
|
293
|
-
|
|
293
|
+
disableMetadataLookup: true, // We don't need health check for this operation
|
|
294
294
|
};
|
|
295
295
|
|
|
296
296
|
// Fetch all datacenters
|
package/src/registry/serve.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { Hono } from "hono";
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
2
|
import { logger } from "./log";
|
|
3
3
|
import type { RunnerConfig } from "./run-config";
|
|
4
4
|
|
|
5
5
|
export async function crossPlatformServe(
|
|
6
6
|
runConfig: RunnerConfig,
|
|
7
|
-
|
|
8
|
-
userRouter: Hono | undefined,
|
|
7
|
+
app: Hono<any>,
|
|
9
8
|
) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// Import @hono/node-server
|
|
9
|
+
// Import @hono/node-server using string variable to prevent static analysis
|
|
10
|
+
const nodeServerModule = "@hono/node-server";
|
|
13
11
|
let serve: any;
|
|
14
12
|
try {
|
|
15
13
|
const dep = await import(
|
|
16
14
|
/* webpackIgnore: true */
|
|
17
|
-
|
|
15
|
+
nodeServerModule
|
|
18
16
|
);
|
|
19
17
|
serve = dep.serve;
|
|
20
18
|
} catch (err) {
|
|
@@ -24,16 +22,13 @@ export async function crossPlatformServe(
|
|
|
24
22
|
process.exit(1);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
app.route("/", rivetKitRouter);
|
|
30
|
-
|
|
31
|
-
// Import @hono/node-ws
|
|
25
|
+
// Import @hono/node-ws using string variable to prevent static analysis
|
|
26
|
+
const nodeWsModule = "@hono/node-ws";
|
|
32
27
|
let createNodeWebSocket: any;
|
|
33
28
|
try {
|
|
34
29
|
const dep = await import(
|
|
35
30
|
/* webpackIgnore: true */
|
|
36
|
-
|
|
31
|
+
nodeWsModule
|
|
37
32
|
);
|
|
38
33
|
createNodeWebSocket = dep.createNodeWebSocket;
|
|
39
34
|
} catch (err) {
|
|
@@ -45,7 +40,7 @@ export async function crossPlatformServe(
|
|
|
45
40
|
|
|
46
41
|
// Inject WS
|
|
47
42
|
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({
|
|
48
|
-
app,
|
|
43
|
+
app: app,
|
|
49
44
|
});
|
|
50
45
|
|
|
51
46
|
// Start server
|
|
@@ -2,9 +2,7 @@ import type { ClientConfig } from "@/client/config";
|
|
|
2
2
|
import {
|
|
3
3
|
HEADER_CONN_PARAMS,
|
|
4
4
|
HEADER_ENCODING,
|
|
5
|
-
WS_PROTOCOL_CONN_ID,
|
|
6
5
|
WS_PROTOCOL_CONN_PARAMS,
|
|
7
|
-
WS_PROTOCOL_CONN_TOKEN,
|
|
8
6
|
WS_PROTOCOL_ENCODING,
|
|
9
7
|
WS_PROTOCOL_STANDARD as WS_PROTOCOL_RIVETKIT,
|
|
10
8
|
WS_PROTOCOL_TOKEN,
|
|
@@ -21,8 +19,6 @@ export async function openWebSocketToActor(
|
|
|
21
19
|
actorId: string,
|
|
22
20
|
encoding: Encoding,
|
|
23
21
|
params: unknown,
|
|
24
|
-
connId?: string,
|
|
25
|
-
connToken?: string,
|
|
26
22
|
): Promise<UniversalWebSocket> {
|
|
27
23
|
const WebSocket = await importWebSocket();
|
|
28
24
|
|
|
@@ -40,7 +36,7 @@ export async function openWebSocketToActor(
|
|
|
40
36
|
// Create WebSocket connection
|
|
41
37
|
const ws = new WebSocket(
|
|
42
38
|
guardUrl,
|
|
43
|
-
buildWebSocketProtocols(runConfig, encoding, params
|
|
39
|
+
buildWebSocketProtocols(runConfig, encoding, params),
|
|
44
40
|
);
|
|
45
41
|
|
|
46
42
|
// Set binary type to arraybuffer for proper encoding support
|
|
@@ -55,25 +51,14 @@ export function buildWebSocketProtocols(
|
|
|
55
51
|
runConfig: ClientConfig,
|
|
56
52
|
encoding: Encoding,
|
|
57
53
|
params?: unknown,
|
|
58
|
-
connId?: string,
|
|
59
|
-
connToken?: string,
|
|
60
54
|
): string[] {
|
|
61
55
|
const protocols: string[] = [];
|
|
62
56
|
protocols.push(WS_PROTOCOL_RIVETKIT);
|
|
63
57
|
protocols.push(`${WS_PROTOCOL_ENCODING}${encoding}`);
|
|
64
|
-
if (runConfig.token) {
|
|
65
|
-
protocols.push(`${WS_PROTOCOL_TOKEN}${runConfig.token}`);
|
|
66
|
-
}
|
|
67
58
|
if (params) {
|
|
68
59
|
protocols.push(
|
|
69
60
|
`${WS_PROTOCOL_CONN_PARAMS}${encodeURIComponent(JSON.stringify(params))}`,
|
|
70
61
|
);
|
|
71
62
|
}
|
|
72
|
-
if (connId) {
|
|
73
|
-
protocols.push(`${WS_PROTOCOL_CONN_ID}${connId}`);
|
|
74
|
-
}
|
|
75
|
-
if (connToken) {
|
|
76
|
-
protocols.push(`${WS_PROTOCOL_CONN_TOKEN}${connToken}`);
|
|
77
|
-
}
|
|
78
63
|
return protocols;
|
|
79
64
|
}
|
|
@@ -25,7 +25,7 @@ export async function getActor(
|
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
// MARK: Get actor by
|
|
28
|
+
// MARK: Get actor by key
|
|
29
29
|
export async function getActorByKey(
|
|
30
30
|
config: ClientConfig,
|
|
31
31
|
name: string,
|
|
@@ -39,6 +39,18 @@ export async function getActorByKey(
|
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// MARK: List actors by name
|
|
43
|
+
export async function listActorsByName(
|
|
44
|
+
config: ClientConfig,
|
|
45
|
+
name: string,
|
|
46
|
+
): Promise<ActorsListResponse> {
|
|
47
|
+
return apiCall<never, ActorsListResponse>(
|
|
48
|
+
config,
|
|
49
|
+
"GET",
|
|
50
|
+
`/actors?name=${encodeURIComponent(name)}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
// MARK: Get or create actor by id
|
|
43
55
|
export async function getOrCreateActor(
|
|
44
56
|
config: ClientConfig,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import type { ClientConfig } from "@/client/config";
|
|
2
3
|
import { sendHttpRequest } from "@/client/utils";
|
|
3
4
|
import { combineUrlPath } from "@/utils";
|
|
@@ -51,5 +52,12 @@ export async function apiCall<TInput = unknown, TOutput = unknown>(
|
|
|
51
52
|
skipParseResponse: false,
|
|
52
53
|
requestVersionedDataHandler: undefined,
|
|
53
54
|
responseVersionedDataHandler: undefined,
|
|
55
|
+
requestZodSchema: z.any() as z.ZodType<TInput>,
|
|
56
|
+
responseZodSchema: z.any() as z.ZodType<TOutput>,
|
|
57
|
+
// Identity conversions (passthrough for generic API calls)
|
|
58
|
+
requestToJson: (value) => value,
|
|
59
|
+
requestToBare: (value) => value,
|
|
60
|
+
responseFromJson: (value) => value,
|
|
61
|
+
responseFromBare: (value) => value,
|
|
54
62
|
});
|
|
55
63
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import pRetry from "p-retry";
|
|
2
|
+
import type { ClientConfig } from "@/client/client";
|
|
3
|
+
import type { MetadataResponse } from "@/common/router";
|
|
4
|
+
import { stringifyError } from "@/common/utils";
|
|
5
|
+
import { getMetadata } from "./api-endpoints";
|
|
6
|
+
import { getEndpoint } from "./api-utils";
|
|
7
|
+
import { logger } from "./log";
|
|
8
|
+
|
|
9
|
+
// Global cache to store metadata check promises for each endpoint
|
|
10
|
+
const metadataLookupCache = new Map<string, Promise<MetadataResponse>>();
|
|
11
|
+
|
|
12
|
+
export async function lookupMetadataCached(
|
|
13
|
+
config: ClientConfig,
|
|
14
|
+
): Promise<MetadataResponse> {
|
|
15
|
+
const endpoint = getEndpoint(config);
|
|
16
|
+
|
|
17
|
+
// Check if metadata lookup is already in progress or completed for this endpoint
|
|
18
|
+
const existingPromise = metadataLookupCache.get(endpoint);
|
|
19
|
+
if (existingPromise) {
|
|
20
|
+
return existingPromise;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Create and store the promise immediately to prevent racing requests
|
|
24
|
+
const metadataLookupPromise = pRetry(
|
|
25
|
+
async () => {
|
|
26
|
+
logger().debug({
|
|
27
|
+
msg: "fetching metadata",
|
|
28
|
+
endpoint,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const metadataData = await getMetadata(config);
|
|
32
|
+
|
|
33
|
+
logger().debug({
|
|
34
|
+
msg: "received metadata",
|
|
35
|
+
endpoint,
|
|
36
|
+
clientEndpoint: metadataData.clientEndpoint,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return metadataData;
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
forever: true,
|
|
43
|
+
minTimeout: 500,
|
|
44
|
+
maxTimeout: 15_000,
|
|
45
|
+
onFailedAttempt: (error) => {
|
|
46
|
+
logger().warn({
|
|
47
|
+
msg: "failed to fetch metadata, retrying",
|
|
48
|
+
endpoint,
|
|
49
|
+
attempt: error.attemptNumber,
|
|
50
|
+
error: stringifyError(error),
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
metadataLookupCache.set(endpoint, metadataLookupPromise);
|
|
57
|
+
return metadataLookupPromise;
|
|
58
|
+
}
|