rivetkit 2.0.3 → 2.0.4
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/README.md +11 -0
- package/dist/schemas/actor-persist/v1.ts +21 -24
- package/dist/schemas/client-protocol/v1.ts +6 -0
- package/dist/tsup/actor/errors.cjs +10 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +17 -4
- package/dist/tsup/actor/errors.d.ts +17 -4
- package/dist/tsup/actor/errors.js +11 -3
- package/dist/tsup/{chunk-6PDXBYI5.js → chunk-3F2YSRJL.js} +8 -23
- package/dist/tsup/chunk-3F2YSRJL.js.map +1 -0
- package/dist/tsup/chunk-4CXBCT26.cjs +250 -0
- package/dist/tsup/chunk-4CXBCT26.cjs.map +1 -0
- package/dist/tsup/chunk-4R73YDN3.cjs +20 -0
- package/dist/tsup/chunk-4R73YDN3.cjs.map +1 -0
- package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-6LJT3QRL.cjs} +39 -25
- package/dist/tsup/chunk-6LJT3QRL.cjs.map +1 -0
- package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-GICQ3YCU.cjs} +143 -141
- package/dist/tsup/chunk-GICQ3YCU.cjs.map +1 -0
- package/dist/tsup/{chunk-FLMTTN27.js → chunk-H26RP6GD.js} +15 -8
- package/dist/tsup/chunk-H26RP6GD.js.map +1 -0
- package/dist/tsup/chunk-HI3HWJRC.js +20 -0
- package/dist/tsup/chunk-HI3HWJRC.js.map +1 -0
- package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-HLLF4B4Q.js} +116 -114
- package/dist/tsup/chunk-HLLF4B4Q.js.map +1 -0
- package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-IH6CKNDW.cjs} +12 -27
- package/dist/tsup/chunk-IH6CKNDW.cjs.map +1 -0
- package/dist/tsup/chunk-LV2S3OU3.js +250 -0
- package/dist/tsup/chunk-LV2S3OU3.js.map +1 -0
- package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LWNKVZG5.cjs} +20 -13
- package/dist/tsup/chunk-LWNKVZG5.cjs.map +1 -0
- package/dist/tsup/{chunk-INGJP237.js → chunk-NFU2BBT5.js} +102 -43
- package/dist/tsup/chunk-NFU2BBT5.js.map +1 -0
- package/dist/tsup/{chunk-3H7O2A7I.js → chunk-PQY7KKTL.js} +33 -19
- package/dist/tsup/chunk-PQY7KKTL.js.map +1 -0
- package/dist/tsup/{chunk-PO4VLDWA.js → chunk-QK72M5JB.js} +3 -5
- package/dist/tsup/chunk-QK72M5JB.js.map +1 -0
- package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-QNNXFOQV.cjs} +3 -5
- package/dist/tsup/chunk-QNNXFOQV.cjs.map +1 -0
- package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-SBHHJ6QS.cjs} +102 -43
- package/dist/tsup/chunk-SBHHJ6QS.cjs.map +1 -0
- package/dist/tsup/chunk-TQ62L3X7.js +325 -0
- package/dist/tsup/chunk-TQ62L3X7.js.map +1 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs +6293 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs.map +1 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs +325 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs.map +1 -0
- package/dist/tsup/chunk-XJQHKJ4P.js +6293 -0
- package/dist/tsup/chunk-XJQHKJ4P.js.map +1 -0
- package/dist/tsup/client/mod.cjs +10 -10
- package/dist/tsup/client/mod.d.cts +7 -13
- package/dist/tsup/client/mod.d.ts +7 -13
- package/dist/tsup/client/mod.js +9 -9
- package/dist/tsup/common/log.cjs +12 -4
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +23 -17
- package/dist/tsup/common/log.d.ts +23 -17
- package/dist/tsup/common/log.js +15 -7
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -4
- package/dist/tsup/{common-CpqORuCq.d.cts → common-CXCe7s6i.d.cts} +2 -2
- package/dist/tsup/{common-CpqORuCq.d.ts → common-CXCe7s6i.d.ts} +2 -2
- package/dist/tsup/{connection-BwUMoe6n.d.ts → connection-BI-6UIBJ.d.ts} +196 -226
- package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-Dyd4NLGW.d.cts} +196 -226
- package/dist/tsup/driver-helpers/mod.cjs +6 -9
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +5 -6
- package/dist/tsup/driver-helpers/mod.d.ts +5 -6
- package/dist/tsup/driver-helpers/mod.js +6 -9
- package/dist/tsup/driver-test-suite/mod.cjs +155 -1363
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +11 -5
- package/dist/tsup/driver-test-suite/mod.d.ts +11 -5
- package/dist/tsup/driver-test-suite/mod.js +876 -2084
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -8
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +3 -3
- package/dist/tsup/inspector/mod.d.ts +3 -3
- package/dist/tsup/inspector/mod.js +8 -10
- package/dist/tsup/mod.cjs +9 -15
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +47 -42
- package/dist/tsup/mod.d.ts +47 -42
- package/dist/tsup/mod.js +10 -16
- package/dist/tsup/{router-endpoints-DAbqVFx2.d.ts → router-endpoints-BTe_Rsdn.d.cts} +2 -3
- package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-CBSrKHmo.d.ts} +2 -3
- package/dist/tsup/test/mod.cjs +10 -14
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -5
- package/dist/tsup/test/mod.d.ts +4 -5
- package/dist/tsup/test/mod.js +9 -13
- package/dist/tsup/{utils-CT0cv4jd.d.ts → utils-fwx3o3K9.d.cts} +1 -0
- package/dist/tsup/{utils-CT0cv4jd.d.cts → utils-fwx3o3K9.d.ts} +1 -0
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/package.json +4 -4
- package/src/actor/action.ts +1 -5
- package/src/actor/config.ts +27 -295
- package/src/actor/connection.ts +9 -12
- package/src/actor/context.ts +1 -4
- package/src/actor/definition.ts +7 -11
- package/src/actor/errors.ts +97 -35
- package/src/actor/generic-conn-driver.ts +28 -16
- package/src/actor/instance.ts +177 -133
- package/src/actor/log.ts +4 -13
- package/src/actor/mod.ts +0 -5
- package/src/actor/protocol/old.ts +42 -26
- package/src/actor/protocol/serde.ts +1 -1
- package/src/actor/router-endpoints.ts +41 -38
- package/src/actor/router.ts +20 -18
- package/src/actor/unstable-react.ts +1 -1
- package/src/actor/utils.ts +6 -2
- package/src/client/actor-common.ts +1 -1
- package/src/client/actor-conn.ts +152 -91
- package/src/client/actor-handle.ts +85 -25
- package/src/client/actor-query.ts +65 -0
- package/src/client/client.ts +29 -98
- package/src/client/config.ts +44 -0
- package/src/client/errors.ts +1 -0
- package/src/client/log.ts +2 -4
- package/src/client/mod.ts +16 -12
- package/src/client/raw-utils.ts +82 -25
- package/src/client/utils.ts +5 -3
- package/src/common/fake-event-source.ts +10 -9
- package/src/common/inline-websocket-adapter2.ts +39 -30
- package/src/common/log.ts +176 -101
- package/src/common/logfmt.ts +21 -30
- package/src/common/router.ts +12 -19
- package/src/common/utils.ts +27 -13
- package/src/common/websocket.ts +0 -1
- package/src/driver-helpers/mod.ts +1 -1
- package/src/driver-test-suite/log.ts +1 -3
- package/src/driver-test-suite/mod.ts +86 -60
- package/src/driver-test-suite/tests/actor-handle.ts +33 -0
- package/src/driver-test-suite/tests/manager-driver.ts +5 -3
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
- package/src/driver-test-suite/tests/request-access.ts +112 -126
- package/src/driver-test-suite/utils.ts +13 -10
- package/src/drivers/default.ts +7 -4
- package/src/drivers/engine/actor-driver.ts +22 -13
- package/src/drivers/engine/config.ts +2 -10
- package/src/drivers/engine/kv.ts +1 -1
- package/src/drivers/engine/log.ts +1 -3
- package/src/drivers/engine/mod.ts +2 -3
- package/src/drivers/file-system/actor.ts +1 -1
- package/src/drivers/file-system/global-state.ts +33 -20
- package/src/drivers/file-system/log.ts +1 -3
- package/src/drivers/file-system/manager.ts +31 -8
- package/src/inspector/config.ts +9 -4
- package/src/inspector/log.ts +1 -1
- package/src/inspector/manager.ts +2 -2
- package/src/inspector/utils.ts +1 -1
- package/src/manager/driver.ts +10 -2
- package/src/manager/hono-websocket-adapter.ts +21 -12
- package/src/manager/log.ts +2 -4
- package/src/manager/mod.ts +1 -1
- package/src/manager/router.ts +277 -1657
- package/src/manager-api/routes/actors-create.ts +16 -0
- package/src/manager-api/routes/actors-delete.ts +4 -0
- package/src/manager-api/routes/actors-get-by-id.ts +7 -0
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
- package/src/manager-api/routes/actors-get.ts +7 -0
- package/src/manager-api/routes/common.ts +18 -0
- package/src/mod.ts +0 -2
- package/src/registry/config.ts +1 -1
- package/src/registry/log.ts +2 -4
- package/src/registry/mod.ts +57 -24
- package/src/registry/run-config.ts +31 -33
- package/src/registry/serve.ts +4 -5
- package/src/remote-manager-driver/actor-http-client.ts +72 -0
- package/src/remote-manager-driver/actor-websocket-client.ts +63 -0
- package/src/remote-manager-driver/api-endpoints.ts +79 -0
- package/src/remote-manager-driver/api-utils.ts +43 -0
- package/src/remote-manager-driver/log.ts +5 -0
- package/src/remote-manager-driver/mod.ts +274 -0
- package/src/{drivers/engine → remote-manager-driver}/ws-proxy.ts +24 -14
- package/src/serde.ts +8 -2
- package/src/test/log.ts +1 -3
- package/src/test/mod.ts +17 -16
- package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
- package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
- package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
- package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
- package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
- package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
- package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
- package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
- package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
- package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
- package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
- package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
- package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
- package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
- package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
- package/dist/tsup/chunk-INGJP237.js.map +0 -1
- package/dist/tsup/chunk-KJCJLKRM.js +0 -116
- package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
- package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
- package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
- package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
- package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
- package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
- package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
- package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
- package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
- package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
- package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
- package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
- package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
- package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
- package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
- package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
- package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
- package/dist/tsup/chunk-UVUPOS46.js +0 -230
- package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
- package/dist/tsup/chunk-VRRHBNJC.js +0 -189
- package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
- package/dist/tsup/chunk-XFSS33EQ.js +0 -202
- package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
- package/src/client/http-client-driver.ts +0 -326
- package/src/driver-test-suite/test-inline-client-driver.ts +0 -402
- package/src/driver-test-suite/tests/actor-auth.ts +0 -591
- package/src/drivers/engine/api-endpoints.ts +0 -128
- package/src/drivers/engine/api-utils.ts +0 -70
- package/src/drivers/engine/manager-driver.ts +0 -391
- package/src/inline-client-driver/log.ts +0 -7
- package/src/inline-client-driver/mod.ts +0 -385
- package/src/manager/auth.ts +0 -121
- /package/src/{drivers/engine → actor}/keys.test.ts +0 -0
- /package/src/{drivers/engine → actor}/keys.ts +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActorSchema } from "./common";
|
|
3
|
+
|
|
4
|
+
export const ActorsCreateRequestSchema = z.object({
|
|
5
|
+
name: z.string(),
|
|
6
|
+
runner_name_selector: z.string(),
|
|
7
|
+
crash_policy: z.string(),
|
|
8
|
+
key: z.string().nullable().optional(),
|
|
9
|
+
input: z.string().nullable().optional(),
|
|
10
|
+
});
|
|
11
|
+
export type ActorsCreateRequest = z.infer<typeof ActorsCreateRequestSchema>;
|
|
12
|
+
|
|
13
|
+
export const ActorsCreateResponseSchema = z.object({
|
|
14
|
+
actor: ActorSchema,
|
|
15
|
+
});
|
|
16
|
+
export type ActorsCreateResponse = z.infer<typeof ActorsCreateResponseSchema>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActorSchema, RivetIdSchema } from "./common";
|
|
3
|
+
|
|
4
|
+
export const ActorsGetOrCreateResponseSchema = z.object({
|
|
5
|
+
actor: ActorSchema,
|
|
6
|
+
created: z.boolean(),
|
|
7
|
+
});
|
|
8
|
+
export type ActorsGetOrCreateResponse = z.infer<
|
|
9
|
+
typeof ActorsGetOrCreateResponseSchema
|
|
10
|
+
>;
|
|
11
|
+
|
|
12
|
+
export const ActorsGetOrCreateByIdResponseSchema = z.object({
|
|
13
|
+
actor_id: RivetIdSchema,
|
|
14
|
+
created: z.boolean(),
|
|
15
|
+
});
|
|
16
|
+
export type ActorsGetOrCreateByIdResponse = z.infer<
|
|
17
|
+
typeof ActorsGetOrCreateByIdResponseSchema
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export const ActorsGetOrCreateByIdRequestSchema = z.object({
|
|
21
|
+
name: z.string(),
|
|
22
|
+
key: z.string(),
|
|
23
|
+
runner_name_selector: z.string(),
|
|
24
|
+
crash_policy: z.string(),
|
|
25
|
+
input: z.string().nullable().optional(),
|
|
26
|
+
});
|
|
27
|
+
export type ActorsGetOrCreateByIdRequest = z.infer<
|
|
28
|
+
typeof ActorsGetOrCreateByIdRequestSchema
|
|
29
|
+
>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const RivetIdSchema = z.string();
|
|
4
|
+
export type RivetId = z.infer<typeof RivetIdSchema>;
|
|
5
|
+
|
|
6
|
+
export const ActorSchema = z.object({
|
|
7
|
+
actor_id: RivetIdSchema,
|
|
8
|
+
name: z.string(),
|
|
9
|
+
key: z.string(),
|
|
10
|
+
namespace_id: RivetIdSchema,
|
|
11
|
+
runner_name_selector: z.string(),
|
|
12
|
+
create_ts: z.number(),
|
|
13
|
+
connectable_ts: z.number().nullable().optional(),
|
|
14
|
+
destroy_ts: z.number().nullable().optional(),
|
|
15
|
+
sleep_ts: z.number().nullable().optional(),
|
|
16
|
+
start_ts: z.number().nullable().optional(),
|
|
17
|
+
});
|
|
18
|
+
export type Actor = z.infer<typeof ActorSchema>;
|
package/src/mod.ts
CHANGED
|
@@ -3,7 +3,6 @@ export * from "@/actor/mod";
|
|
|
3
3
|
export {
|
|
4
4
|
type AnyClient,
|
|
5
5
|
type Client,
|
|
6
|
-
type ClientDriver,
|
|
7
6
|
createClientWithDriver,
|
|
8
7
|
} from "@/client/client";
|
|
9
8
|
export { InlineWebSocketAdapter2 } from "@/common/inline-websocket-adapter2";
|
|
@@ -13,7 +12,6 @@ export {
|
|
|
13
12
|
createFileSystemDriver,
|
|
14
13
|
createMemoryDriver,
|
|
15
14
|
} from "@/drivers/file-system/mod";
|
|
16
|
-
export { createInlineClientDriver } from "@/inline-client-driver/mod";
|
|
17
15
|
// Re-export important protocol types and utilities needed by drivers
|
|
18
16
|
export type { ActorQuery } from "@/manager/protocol/query";
|
|
19
17
|
export * from "@/registry/mod";
|
package/src/registry/config.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { ActorDefinition, AnyActorDefinition } from "@/actor/definition";
|
|
|
5
5
|
|
|
6
6
|
export const ActorsSchema = z.record(
|
|
7
7
|
z.string(),
|
|
8
|
-
z.custom<ActorDefinition<any, any, any, any, any, any, any
|
|
8
|
+
z.custom<ActorDefinition<any, any, any, any, any, any, any>>(),
|
|
9
9
|
);
|
|
10
10
|
export type RegistryActors = z.infer<typeof ActorsSchema>;
|
|
11
11
|
|
package/src/registry/log.ts
CHANGED
package/src/registry/mod.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Hono } from "hono";
|
|
2
|
-
import { createActorRouter } from "@/actor/router";
|
|
3
2
|
import { type Client, createClientWithDriver } from "@/client/client";
|
|
3
|
+
import { configureBaseLogger, configureDefaultLogger } from "@/common/log";
|
|
4
4
|
import { chooseDefaultDriver } from "@/drivers/default";
|
|
5
|
-
import { createInlineClientDriver } from "@/inline-client-driver/mod";
|
|
6
5
|
import { getInspectorUrl } from "@/inspector/utils";
|
|
7
6
|
import { createManagerRouter } from "@/manager/router";
|
|
7
|
+
import pkg from "../../package.json" with { type: "json" };
|
|
8
8
|
import {
|
|
9
9
|
type RegistryActors,
|
|
10
10
|
type RegistryConfig,
|
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
import { crossPlatformServe } from "./serve";
|
|
22
22
|
|
|
23
23
|
interface ServerOutput<A extends Registry<any>> {
|
|
24
|
+
config: RunConfig;
|
|
25
|
+
driver: DriverConfig;
|
|
24
26
|
client: Client<A>;
|
|
25
27
|
hono: Hono;
|
|
26
28
|
handler: (req: Request) => Promise<Response>;
|
|
@@ -44,9 +46,24 @@ export class Registry<A extends RegistryActors> {
|
|
|
44
46
|
public createServer(inputConfig?: RunConfigInput): ServerOutput<this> {
|
|
45
47
|
const config = RunConfigSchema.parse(inputConfig);
|
|
46
48
|
|
|
49
|
+
// Configure logger
|
|
50
|
+
if (config.logging?.baseLogger) {
|
|
51
|
+
// Use provided base logger
|
|
52
|
+
configureBaseLogger(config.logging.baseLogger);
|
|
53
|
+
} else {
|
|
54
|
+
// Configure default logger with log level from config
|
|
55
|
+
// getPinoLevel will handle env variable priority
|
|
56
|
+
configureDefaultLogger(config.logging?.level);
|
|
57
|
+
}
|
|
58
|
+
|
|
47
59
|
// Choose the driver based on configuration
|
|
48
60
|
const driver = chooseDefaultDriver(config);
|
|
49
61
|
|
|
62
|
+
// TODO: Find cleaner way of disabling by default
|
|
63
|
+
if (driver.name === "engine") {
|
|
64
|
+
config.inspector.enabled = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
50
67
|
// Configure getUpgradeWebSocket lazily so we can assign it in crossPlatformServe
|
|
51
68
|
let upgradeWebSocket: any;
|
|
52
69
|
if (!config.getUpgradeWebSocket) {
|
|
@@ -55,45 +72,56 @@ export class Registry<A extends RegistryActors> {
|
|
|
55
72
|
|
|
56
73
|
// Create router
|
|
57
74
|
const managerDriver = driver.manager(this.#config, config);
|
|
58
|
-
const clientDriver = createInlineClientDriver(managerDriver);
|
|
59
75
|
const { router: hono } = createManagerRouter(
|
|
60
76
|
this.#config,
|
|
61
77
|
config,
|
|
62
|
-
clientDriver,
|
|
63
78
|
managerDriver,
|
|
64
79
|
false,
|
|
65
80
|
);
|
|
66
81
|
|
|
67
82
|
// Create client
|
|
68
|
-
const client = createClientWithDriver<this>(
|
|
83
|
+
const client = createClientWithDriver<this>(managerDriver, config);
|
|
69
84
|
|
|
70
85
|
const driverLog = managerDriver.extraStartupLog?.() ?? {};
|
|
71
|
-
logger().info(
|
|
86
|
+
logger().info({
|
|
87
|
+
msg: "rivetkit ready",
|
|
72
88
|
driver: driver.name,
|
|
73
89
|
definitions: Object.keys(this.#config.use).length,
|
|
74
90
|
...driverLog,
|
|
75
91
|
});
|
|
76
|
-
if (config.inspector?.enabled) {
|
|
77
|
-
logger().info("inspector ready",
|
|
78
|
-
url: getInspectorUrl(config),
|
|
79
|
-
});
|
|
92
|
+
if (config.inspector?.enabled && managerDriver.inspector) {
|
|
93
|
+
logger().info({ msg: "inspector ready", url: getInspectorUrl(config) });
|
|
80
94
|
}
|
|
81
95
|
|
|
82
|
-
//
|
|
83
|
-
if (config.
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
)
|
|
93
|
-
|
|
96
|
+
// Print welcome information
|
|
97
|
+
if (!config.noWelcome) {
|
|
98
|
+
const displayInfo = managerDriver.displayInformation();
|
|
99
|
+
console.log();
|
|
100
|
+
console.log(` RivetKit ${pkg.version} (${displayInfo.name})`);
|
|
101
|
+
console.log(` - Endpoint: http://127.0.0.1:6420`);
|
|
102
|
+
for (const [k, v] of Object.entries(displayInfo.properties)) {
|
|
103
|
+
const padding = " ".repeat(Math.max(0, 13 - k.length));
|
|
104
|
+
console.log(` - ${k}:${padding}${v}`);
|
|
105
|
+
}
|
|
106
|
+
if (config.inspector?.enabled && managerDriver.inspector) {
|
|
107
|
+
console.log(` - Inspector: ${getInspectorUrl(config)}`);
|
|
108
|
+
}
|
|
109
|
+
console.log();
|
|
94
110
|
}
|
|
95
111
|
|
|
112
|
+
// Create runner
|
|
113
|
+
//
|
|
114
|
+
// Even though we do not use the return value, this is required to start the code that will handle incoming actors
|
|
115
|
+
const _actorDriver = driver.actor(
|
|
116
|
+
this.#config,
|
|
117
|
+
config,
|
|
118
|
+
managerDriver,
|
|
119
|
+
client,
|
|
120
|
+
);
|
|
121
|
+
|
|
96
122
|
return {
|
|
123
|
+
config,
|
|
124
|
+
driver,
|
|
97
125
|
client,
|
|
98
126
|
hono,
|
|
99
127
|
handler: async (req: Request) => await hono.fetch(req),
|
|
@@ -108,8 +136,13 @@ export class Registry<A extends RegistryActors> {
|
|
|
108
136
|
* Runs the registry as a standalone server.
|
|
109
137
|
*/
|
|
110
138
|
public async runServer(inputConfig?: RunConfigInput) {
|
|
111
|
-
const { serve } = this.createServer(inputConfig);
|
|
112
|
-
|
|
139
|
+
const { driver, serve } = this.createServer(inputConfig);
|
|
140
|
+
|
|
141
|
+
// TODO: FInd better way of doing this
|
|
142
|
+
// Don't run server by default
|
|
143
|
+
if (driver.name !== "engine") {
|
|
144
|
+
serve();
|
|
145
|
+
}
|
|
113
146
|
}
|
|
114
147
|
}
|
|
115
148
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { cors } from "hono/cors";
|
|
2
|
+
import type { Logger } from "pino";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import type { ActorDriverBuilder } from "@/actor/driver";
|
|
5
|
+
import { ClientConfigSchema } from "@/client/config";
|
|
6
|
+
import { LogLevelSchema } from "@/common/log";
|
|
4
7
|
import { InspectorConfigSchema } from "@/inspector/config";
|
|
5
8
|
import type { ManagerDriverBuilder } from "@/manager/driver";
|
|
6
|
-
import type { UpgradeWebSocket } from "@/utils";
|
|
7
9
|
|
|
8
10
|
type CorsOptions = NonNullable<Parameters<typeof cors>[0]>;
|
|
9
11
|
|
|
10
|
-
export type GetUpgradeWebSocket = () => UpgradeWebSocket;
|
|
11
|
-
|
|
12
12
|
export const DriverConfigSchema = z.object({
|
|
13
13
|
/** Machine-readable name to identify this driver by. */
|
|
14
14
|
name: z.string(),
|
|
@@ -19,36 +19,34 @@ export const DriverConfigSchema = z.object({
|
|
|
19
19
|
export type DriverConfig = z.infer<typeof DriverConfigSchema>;
|
|
20
20
|
|
|
21
21
|
/** Base config used for the actor config across all platforms. */
|
|
22
|
-
export const RunConfigSchema =
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
.default({});
|
|
22
|
+
export const RunConfigSchema = ClientConfigSchema.extend({
|
|
23
|
+
driver: DriverConfigSchema.optional(),
|
|
24
|
+
|
|
25
|
+
/** CORS configuration for the router. Uses Hono's CORS middleware options. */
|
|
26
|
+
cors: z.custom<CorsOptions>().optional(),
|
|
27
|
+
|
|
28
|
+
maxIncomingMessageSize: z.number().optional().default(65_536),
|
|
29
|
+
|
|
30
|
+
inspector: InspectorConfigSchema,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Base path for the router. This is used to prefix all routes.
|
|
34
|
+
* For example, if the base path is `/api`, then the route `/actors` will be
|
|
35
|
+
* available at `/api/actors`.
|
|
36
|
+
*/
|
|
37
|
+
basePath: z.string().optional().default("/"),
|
|
38
|
+
|
|
39
|
+
/** Disable welcome message. */
|
|
40
|
+
noWelcome: z.boolean().optional().default(false),
|
|
41
|
+
|
|
42
|
+
logging: z
|
|
43
|
+
.object({
|
|
44
|
+
baseLogger: z.custom<Logger>().optional(),
|
|
45
|
+
level: LogLevelSchema.optional(),
|
|
46
|
+
})
|
|
47
|
+
.optional()
|
|
48
|
+
.default({}),
|
|
49
|
+
}).default({});
|
|
52
50
|
|
|
53
51
|
export type RunConfig = z.infer<typeof RunConfigSchema>;
|
|
54
52
|
export type RunConfigInput = z.input<typeof RunConfigSchema>;
|
package/src/registry/serve.ts
CHANGED
|
@@ -21,7 +21,8 @@ export async function crossPlatformServe(
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// Mount registry
|
|
24
|
-
app.route("/registry", rivetKitRouter);
|
|
24
|
+
// app.route("/registry", rivetKitRouter);
|
|
25
|
+
app.route("/", rivetKitRouter);
|
|
25
26
|
|
|
26
27
|
// Import @hono/node-ws
|
|
27
28
|
let createNodeWebSocket: any;
|
|
@@ -41,11 +42,9 @@ export async function crossPlatformServe(
|
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
// Start server
|
|
44
|
-
const port =
|
|
45
|
-
getEnvUniversal("PORT") ?? getEnvUniversal("PORT_HTTP") ?? "8080",
|
|
46
|
-
);
|
|
45
|
+
const port = 6420;
|
|
47
46
|
const server = serve({ fetch: app.fetch, port }, () =>
|
|
48
|
-
logger().info("server listening",
|
|
47
|
+
logger().info({ msg: "server listening", port }),
|
|
49
48
|
);
|
|
50
49
|
injectWebSocket(server);
|
|
51
50
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ClientConfig } from "@/client/config";
|
|
2
|
+
import { getEndpoint } from "./api-utils";
|
|
3
|
+
|
|
4
|
+
export async function sendHttpRequestToActor(
|
|
5
|
+
runConfig: ClientConfig,
|
|
6
|
+
actorId: string,
|
|
7
|
+
actorRequest: Request,
|
|
8
|
+
): Promise<Response> {
|
|
9
|
+
// Route through guard port
|
|
10
|
+
const url = new URL(actorRequest.url);
|
|
11
|
+
const endpoint = getEndpoint(runConfig);
|
|
12
|
+
const guardUrl = `${endpoint}${url.pathname}${url.search}`;
|
|
13
|
+
|
|
14
|
+
// Handle body properly based on method and presence
|
|
15
|
+
let bodyToSend: ArrayBuffer | null = null;
|
|
16
|
+
const guardHeaders = buildGuardHeadersForHttp(actorRequest, actorId);
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
actorRequest.body &&
|
|
20
|
+
actorRequest.method !== "GET" &&
|
|
21
|
+
actorRequest.method !== "HEAD"
|
|
22
|
+
) {
|
|
23
|
+
if (actorRequest.bodyUsed) {
|
|
24
|
+
throw new Error("Request body has already been consumed");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// TODO: This buffers the entire request in memory every time. We
|
|
28
|
+
// need to properly implement streaming bodies.
|
|
29
|
+
// Clone and read the body to ensure it can be sent
|
|
30
|
+
const clonedRequest = actorRequest.clone();
|
|
31
|
+
bodyToSend = await clonedRequest.arrayBuffer();
|
|
32
|
+
|
|
33
|
+
// If this is a streaming request, we need to convert the headers
|
|
34
|
+
// for the basic array buffer
|
|
35
|
+
guardHeaders.delete("transfer-encoding");
|
|
36
|
+
guardHeaders.set(
|
|
37
|
+
"content-length",
|
|
38
|
+
String((bodyToSend as ArrayBuffer).byteLength),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const guardRequest = new Request(guardUrl, {
|
|
43
|
+
method: actorRequest.method,
|
|
44
|
+
headers: guardHeaders,
|
|
45
|
+
body: bodyToSend,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return mutableResponse(await fetch(guardRequest));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function mutableResponse(fetchRes: Response): Response {
|
|
52
|
+
// We cannot return the raw response from `fetch` since the response type is not mutable.
|
|
53
|
+
//
|
|
54
|
+
// In order for middleware to be able to mutate the response, we need to build a new Response object that is mutable.
|
|
55
|
+
return new Response(fetchRes.body, fetchRes);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function buildGuardHeadersForHttp(
|
|
59
|
+
actorRequest: Request,
|
|
60
|
+
actorId: string,
|
|
61
|
+
): Headers {
|
|
62
|
+
const headers = new Headers();
|
|
63
|
+
// Copy all headers from the original request
|
|
64
|
+
for (const [key, value] of actorRequest.headers.entries()) {
|
|
65
|
+
headers.set(key, value);
|
|
66
|
+
}
|
|
67
|
+
// Add guard-specific headers
|
|
68
|
+
headers.set("x-rivet-target", "actor");
|
|
69
|
+
headers.set("x-rivet-actor", actorId);
|
|
70
|
+
headers.set("x-rivet-port", "main");
|
|
71
|
+
return headers;
|
|
72
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HEADER_AUTH_DATA,
|
|
3
|
+
HEADER_CONN_PARAMS,
|
|
4
|
+
HEADER_ENCODING,
|
|
5
|
+
} from "@/actor/router-endpoints";
|
|
6
|
+
import type { ClientConfig } from "@/client/config";
|
|
7
|
+
import { importWebSocket } from "@/common/websocket";
|
|
8
|
+
import type { Encoding, UniversalWebSocket } from "@/mod";
|
|
9
|
+
import { getEndpoint } from "./api-utils";
|
|
10
|
+
import { logger } from "./log";
|
|
11
|
+
|
|
12
|
+
export async function openWebSocketToActor(
|
|
13
|
+
runConfig: ClientConfig,
|
|
14
|
+
path: string,
|
|
15
|
+
actorId: string,
|
|
16
|
+
encoding: Encoding,
|
|
17
|
+
params: unknown,
|
|
18
|
+
): Promise<UniversalWebSocket> {
|
|
19
|
+
const WebSocket = await importWebSocket();
|
|
20
|
+
|
|
21
|
+
// WebSocket connections go through guard
|
|
22
|
+
const endpoint = getEndpoint(runConfig);
|
|
23
|
+
const guardUrl = `${endpoint}${path}`;
|
|
24
|
+
|
|
25
|
+
logger().debug({
|
|
26
|
+
msg: "opening websocket to actor via guard",
|
|
27
|
+
actorId,
|
|
28
|
+
path,
|
|
29
|
+
guardUrl,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Create WebSocket connection
|
|
33
|
+
const ws = new WebSocket(guardUrl, {
|
|
34
|
+
headers: buildGuardHeadersForWebSocket(actorId, encoding, params),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Set binary type to arraybuffer for proper encoding support
|
|
38
|
+
ws.binaryType = "arraybuffer";
|
|
39
|
+
|
|
40
|
+
logger().debug({ msg: "websocket connection opened", actorId });
|
|
41
|
+
|
|
42
|
+
return ws as UniversalWebSocket;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function buildGuardHeadersForWebSocket(
|
|
46
|
+
actorId: string,
|
|
47
|
+
encoding: Encoding,
|
|
48
|
+
params?: unknown,
|
|
49
|
+
authData?: unknown,
|
|
50
|
+
): Record<string, string> {
|
|
51
|
+
const headers: Record<string, string> = {};
|
|
52
|
+
headers["x-rivet-target"] = "actor";
|
|
53
|
+
headers["x-rivet-actor"] = actorId;
|
|
54
|
+
headers["x-rivet-port"] = "main";
|
|
55
|
+
headers[HEADER_ENCODING] = encoding;
|
|
56
|
+
if (params) {
|
|
57
|
+
headers[HEADER_CONN_PARAMS] = JSON.stringify(params);
|
|
58
|
+
}
|
|
59
|
+
if (authData) {
|
|
60
|
+
headers[HEADER_AUTH_DATA] = JSON.stringify(authData);
|
|
61
|
+
}
|
|
62
|
+
return headers;
|
|
63
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { serializeActorKey } from "@/actor/keys";
|
|
2
|
+
import type { ClientConfig } from "@/client/client";
|
|
3
|
+
import type {
|
|
4
|
+
ActorsCreateRequest,
|
|
5
|
+
ActorsCreateResponse,
|
|
6
|
+
} from "@/manager-api/routes/actors-create";
|
|
7
|
+
import type { ActorsDeleteResponse } from "@/manager-api/routes/actors-delete";
|
|
8
|
+
import type { ActorsGetResponse } from "@/manager-api/routes/actors-get";
|
|
9
|
+
import type { ActorsGetByIdResponse } from "@/manager-api/routes/actors-get-by-id";
|
|
10
|
+
import type {
|
|
11
|
+
ActorsGetOrCreateByIdRequest,
|
|
12
|
+
ActorsGetOrCreateByIdResponse,
|
|
13
|
+
} from "@/manager-api/routes/actors-get-or-create-by-id";
|
|
14
|
+
import type { RivetId } from "@/manager-api/routes/common";
|
|
15
|
+
import { apiCall } from "./api-utils";
|
|
16
|
+
|
|
17
|
+
// MARK: Get actor
|
|
18
|
+
export async function getActor(
|
|
19
|
+
config: ClientConfig,
|
|
20
|
+
actorId: RivetId,
|
|
21
|
+
): Promise<ActorsGetResponse> {
|
|
22
|
+
return apiCall<never, ActorsGetResponse>(
|
|
23
|
+
config,
|
|
24
|
+
"GET",
|
|
25
|
+
`/actors/${encodeURIComponent(actorId)}`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// MARK: Get actor by id
|
|
30
|
+
export async function getActorById(
|
|
31
|
+
config: ClientConfig,
|
|
32
|
+
name: string,
|
|
33
|
+
key: string[],
|
|
34
|
+
): Promise<ActorsGetByIdResponse> {
|
|
35
|
+
const serializedKey = serializeActorKey(key);
|
|
36
|
+
return apiCall<never, ActorsGetByIdResponse>(
|
|
37
|
+
config,
|
|
38
|
+
"GET",
|
|
39
|
+
`/actors/by-id?name=${encodeURIComponent(name)}&key=${encodeURIComponent(serializedKey)}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// MARK: Get or create actor by id
|
|
44
|
+
export async function getOrCreateActorById(
|
|
45
|
+
config: ClientConfig,
|
|
46
|
+
request: ActorsGetOrCreateByIdRequest,
|
|
47
|
+
): Promise<ActorsGetOrCreateByIdResponse> {
|
|
48
|
+
return apiCall<ActorsGetOrCreateByIdRequest, ActorsGetOrCreateByIdResponse>(
|
|
49
|
+
config,
|
|
50
|
+
"PUT",
|
|
51
|
+
`/actors/by-id`,
|
|
52
|
+
request,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// MARK: Create actor
|
|
57
|
+
export async function createActor(
|
|
58
|
+
config: ClientConfig,
|
|
59
|
+
request: ActorsCreateRequest,
|
|
60
|
+
): Promise<ActorsCreateResponse> {
|
|
61
|
+
return apiCall<ActorsCreateRequest, ActorsCreateResponse>(
|
|
62
|
+
config,
|
|
63
|
+
"POST",
|
|
64
|
+
`/actors`,
|
|
65
|
+
request,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// MARK: Destroy actor
|
|
70
|
+
export async function destroyActor(
|
|
71
|
+
config: ClientConfig,
|
|
72
|
+
actorId: RivetId,
|
|
73
|
+
): Promise<ActorsDeleteResponse> {
|
|
74
|
+
return apiCall<never, ActorsDeleteResponse>(
|
|
75
|
+
config,
|
|
76
|
+
"DELETE",
|
|
77
|
+
`/actors/${encodeURIComponent(actorId)}`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ClientConfig } from "@/client/config";
|
|
2
|
+
import { sendHttpRequest } from "@/client/utils";
|
|
3
|
+
import { logger } from "./log";
|
|
4
|
+
|
|
5
|
+
// Error class for Engine API errors
|
|
6
|
+
export class EngineApiError extends Error {
|
|
7
|
+
constructor(
|
|
8
|
+
public readonly group: string,
|
|
9
|
+
public readonly code: string,
|
|
10
|
+
message?: string,
|
|
11
|
+
) {
|
|
12
|
+
super(message || `Engine API error: ${group}/${code}`);
|
|
13
|
+
this.name = "EngineApiError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getEndpoint(config: ClientConfig) {
|
|
18
|
+
return config.endpoint ?? "http://127.0.0.1:6420";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Helper function for making API calls
|
|
22
|
+
export async function apiCall<TInput = unknown, TOutput = unknown>(
|
|
23
|
+
config: ClientConfig,
|
|
24
|
+
method: "GET" | "POST" | "PUT" | "DELETE",
|
|
25
|
+
path: string,
|
|
26
|
+
body?: TInput,
|
|
27
|
+
): Promise<TOutput> {
|
|
28
|
+
const endpoint = getEndpoint(config);
|
|
29
|
+
const url = `${endpoint}${path}${path.includes("?") ? "&" : "?"}namespace=${encodeURIComponent(config.namespace)}`;
|
|
30
|
+
|
|
31
|
+
logger().debug({ msg: "making api call", method, url });
|
|
32
|
+
|
|
33
|
+
return await sendHttpRequest<TInput, TOutput>({
|
|
34
|
+
method,
|
|
35
|
+
url,
|
|
36
|
+
headers: {},
|
|
37
|
+
body,
|
|
38
|
+
encoding: "json",
|
|
39
|
+
skipParseResponse: false,
|
|
40
|
+
requestVersionedDataHandler: undefined,
|
|
41
|
+
responseVersionedDataHandler: undefined,
|
|
42
|
+
});
|
|
43
|
+
}
|