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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { RivetIdSchema } from "./common";
|
|
3
|
+
|
|
4
|
+
export const ActorSchema = z.object({
|
|
5
|
+
actor_id: RivetIdSchema,
|
|
6
|
+
name: z.string(),
|
|
7
|
+
key: z.string(),
|
|
8
|
+
namespace_id: RivetIdSchema,
|
|
9
|
+
runner_name_selector: z.string(),
|
|
10
|
+
create_ts: z.number(),
|
|
11
|
+
connectable_ts: z.number().nullable().optional(),
|
|
12
|
+
destroy_ts: z.number().nullable().optional(),
|
|
13
|
+
sleep_ts: z.number().nullable().optional(),
|
|
14
|
+
start_ts: z.number().nullable().optional(),
|
|
15
|
+
});
|
|
16
|
+
export type Actor = z.infer<typeof ActorSchema>;
|
|
17
|
+
|
|
18
|
+
// MARK: GET /actors
|
|
19
|
+
export const ActorsListResponseSchema = z.object({
|
|
20
|
+
actors: z.array(ActorSchema),
|
|
21
|
+
});
|
|
22
|
+
export type ActorsListResponse = z.infer<typeof ActorsListResponseSchema>;
|
|
23
|
+
|
|
24
|
+
// MARK: POST /actors
|
|
25
|
+
export const ActorsCreateRequestSchema = z.object({
|
|
26
|
+
name: z.string(),
|
|
27
|
+
runner_name_selector: z.string(),
|
|
28
|
+
crash_policy: z.string(),
|
|
29
|
+
key: z.string().nullable().optional(),
|
|
30
|
+
input: z.string().nullable().optional(),
|
|
31
|
+
});
|
|
32
|
+
export type ActorsCreateRequest = z.infer<typeof ActorsCreateRequestSchema>;
|
|
33
|
+
|
|
34
|
+
export const ActorsCreateResponseSchema = z.object({
|
|
35
|
+
actor: ActorSchema,
|
|
36
|
+
});
|
|
37
|
+
export type ActorsCreateResponse = z.infer<typeof ActorsCreateResponseSchema>;
|
|
38
|
+
|
|
39
|
+
// MARK: PUT /actors
|
|
40
|
+
export const ActorsGetOrCreateRequestSchema = z.object({
|
|
41
|
+
name: z.string(),
|
|
42
|
+
key: z.string(),
|
|
43
|
+
runner_name_selector: z.string(),
|
|
44
|
+
crash_policy: z.string(),
|
|
45
|
+
input: z.string().nullable().optional(),
|
|
46
|
+
});
|
|
47
|
+
export type ActorsGetOrCreateRequest = z.infer<
|
|
48
|
+
typeof ActorsGetOrCreateRequestSchema
|
|
49
|
+
>;
|
|
50
|
+
|
|
51
|
+
export const ActorsGetOrCreateResponseSchema = z.object({
|
|
52
|
+
actor: ActorSchema,
|
|
53
|
+
created: z.boolean(),
|
|
54
|
+
});
|
|
55
|
+
export type ActorsGetOrCreateResponse = z.infer<
|
|
56
|
+
typeof ActorsGetOrCreateResponseSchema
|
|
57
|
+
>;
|
|
58
|
+
|
|
59
|
+
// MARK: DELETE /actors/{}
|
|
60
|
+
export const ActorsDeleteResponseSchema = z.object({});
|
|
61
|
+
export type ActorsDeleteResponse = z.infer<typeof ActorsDeleteResponseSchema>;
|
package/src/mod.ts
CHANGED
package/src/registry/mod.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type { Hono } from "hono";
|
|
2
1
|
import { type Client, createClientWithDriver } from "@/client/client";
|
|
3
2
|
import { configureBaseLogger, configureDefaultLogger } from "@/common/log";
|
|
3
|
+
import type { ActorDriver } from "@/driver-helpers/mod";
|
|
4
4
|
import { chooseDefaultDriver } from "@/drivers/default";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
configureInspectorAccessToken,
|
|
7
|
+
getInspectorUrl,
|
|
8
|
+
isInspectorEnabled,
|
|
9
|
+
} from "@/inspector/utils";
|
|
6
10
|
import { createManagerRouter } from "@/manager/router";
|
|
7
11
|
import pkg from "../../package.json" with { type: "json" };
|
|
8
12
|
import {
|
|
@@ -59,11 +63,11 @@ export class Registry<A extends RegistryActors> {
|
|
|
59
63
|
|
|
60
64
|
// TODO: Find cleaner way of disabling by default
|
|
61
65
|
if (driver.name === "engine") {
|
|
62
|
-
config.inspector.enabled = false;
|
|
66
|
+
config.inspector.enabled = { manager: false, actor: true };
|
|
63
67
|
config.disableServer = true;
|
|
64
68
|
}
|
|
65
69
|
if (driver.name === "cloudflare-workers") {
|
|
66
|
-
config.inspector.enabled = false;
|
|
70
|
+
config.inspector.enabled = { manager: false, actor: true };
|
|
67
71
|
config.disableServer = true;
|
|
68
72
|
config.disableActorDriver = true;
|
|
69
73
|
config.noWelcome = true;
|
|
@@ -77,13 +81,110 @@ export class Registry<A extends RegistryActors> {
|
|
|
77
81
|
|
|
78
82
|
// Create router
|
|
79
83
|
const managerDriver = driver.manager(this.#config, config);
|
|
84
|
+
configureInspectorAccessToken(config, managerDriver);
|
|
85
|
+
|
|
86
|
+
// Create client
|
|
87
|
+
const client = createClientWithDriver<this>(managerDriver, config);
|
|
88
|
+
|
|
89
|
+
const driverLog = managerDriver.extraStartupLog?.() ?? {};
|
|
90
|
+
logger().info({
|
|
91
|
+
msg: "rivetkit ready",
|
|
92
|
+
driver: driver.name,
|
|
93
|
+
definitions: Object.keys(this.#config.use).length,
|
|
94
|
+
...driverLog,
|
|
95
|
+
});
|
|
96
|
+
if (isInspectorEnabled(config, "manager") && managerDriver.inspector) {
|
|
97
|
+
logger().info({ msg: "inspector ready", url: getInspectorUrl(config) });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Print welcome information
|
|
101
|
+
if (!config.noWelcome) {
|
|
102
|
+
const displayInfo = managerDriver.displayInformation();
|
|
103
|
+
console.log();
|
|
104
|
+
console.log(` RivetKit ${pkg.version} (${displayInfo.name})`);
|
|
105
|
+
console.log(` - Endpoint: http://127.0.0.1:6420`);
|
|
106
|
+
for (const [k, v] of Object.entries(displayInfo.properties)) {
|
|
107
|
+
const padding = " ".repeat(Math.max(0, 13 - k.length));
|
|
108
|
+
console.log(` - ${k}:${padding}${v}`);
|
|
109
|
+
}
|
|
110
|
+
if (isInspectorEnabled(config, "manager") && managerDriver.inspector) {
|
|
111
|
+
console.log(` - Inspector: ${getInspectorUrl(config)}`);
|
|
112
|
+
}
|
|
113
|
+
console.log();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// HACK: We need to find a better way to let the driver itself decide when to start the actor driver
|
|
117
|
+
// Create runner
|
|
118
|
+
//
|
|
119
|
+
// Even though we do not use the return value, this is required to start the code that will handle incoming actors
|
|
120
|
+
if (!config.disableActorDriver) {
|
|
121
|
+
const _actorDriver = driver.actor(
|
|
122
|
+
this.#config,
|
|
123
|
+
config,
|
|
124
|
+
managerDriver,
|
|
125
|
+
client,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
80
129
|
const { router: hono } = createManagerRouter(
|
|
81
130
|
this.#config,
|
|
82
131
|
config,
|
|
83
132
|
managerDriver,
|
|
84
|
-
|
|
133
|
+
undefined,
|
|
85
134
|
);
|
|
86
135
|
|
|
136
|
+
// Start server
|
|
137
|
+
if (!config.disableServer) {
|
|
138
|
+
(async () => {
|
|
139
|
+
const out = await crossPlatformServe(hono, undefined);
|
|
140
|
+
upgradeWebSocket = out.upgradeWebSocket;
|
|
141
|
+
})();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
client,
|
|
146
|
+
fetch: hono.fetch.bind(hono),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public startServerless(inputConfig?: RunConfigInput): ServerOutput<this> {
|
|
151
|
+
const config = RunConfigSchema.parse(inputConfig);
|
|
152
|
+
|
|
153
|
+
// Configure logger
|
|
154
|
+
if (config.logging?.baseLogger) {
|
|
155
|
+
// Use provided base logger
|
|
156
|
+
configureBaseLogger(config.logging.baseLogger);
|
|
157
|
+
} else {
|
|
158
|
+
// Configure default logger with log level from config
|
|
159
|
+
// getPinoLevel will handle env variable priority
|
|
160
|
+
configureDefaultLogger(config.logging?.level);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Choose the driver based on configuration
|
|
164
|
+
const driver = chooseDefaultDriver(config);
|
|
165
|
+
|
|
166
|
+
// TODO: Find cleaner way of disabling by default
|
|
167
|
+
if (driver.name === "engine") {
|
|
168
|
+
config.inspector.enabled = false;
|
|
169
|
+
config.disableServer = true;
|
|
170
|
+
config.disableActorDriver = true;
|
|
171
|
+
}
|
|
172
|
+
if (driver.name === "cloudflare-workers") {
|
|
173
|
+
config.inspector.enabled = false;
|
|
174
|
+
config.disableServer = true;
|
|
175
|
+
config.disableActorDriver = true;
|
|
176
|
+
config.noWelcome = true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Configure getUpgradeWebSocket lazily so we can assign it in crossPlatformServe
|
|
180
|
+
let upgradeWebSocket: any;
|
|
181
|
+
if (!config.getUpgradeWebSocket) {
|
|
182
|
+
config.getUpgradeWebSocket = () => upgradeWebSocket!;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Create router
|
|
186
|
+
const managerDriver = driver.manager(this.#config, config);
|
|
187
|
+
|
|
87
188
|
// Create client
|
|
88
189
|
const client = createClientWithDriver<this>(managerDriver, config);
|
|
89
190
|
|
|
@@ -114,19 +215,26 @@ export class Registry<A extends RegistryActors> {
|
|
|
114
215
|
console.log();
|
|
115
216
|
}
|
|
116
217
|
|
|
218
|
+
let serverlessActorDriverBuilder: (() => ActorDriver) | undefined = () => {
|
|
219
|
+
return driver.actor(this.#config, config, managerDriver, client);
|
|
220
|
+
};
|
|
221
|
+
|
|
117
222
|
// HACK: We need to find a better way to let the driver itself decide when to start the actor driver
|
|
118
223
|
// Create runner
|
|
119
224
|
//
|
|
120
225
|
// Even though we do not use the return value, this is required to start the code that will handle incoming actors
|
|
121
226
|
if (!config.disableActorDriver) {
|
|
122
|
-
const _actorDriver =
|
|
123
|
-
|
|
124
|
-
config,
|
|
125
|
-
managerDriver,
|
|
126
|
-
client,
|
|
127
|
-
);
|
|
227
|
+
const _actorDriver = serverlessActorDriverBuilder();
|
|
228
|
+
serverlessActorDriverBuilder = undefined;
|
|
128
229
|
}
|
|
129
230
|
|
|
231
|
+
const { router: hono } = createManagerRouter(
|
|
232
|
+
this.#config,
|
|
233
|
+
config,
|
|
234
|
+
managerDriver,
|
|
235
|
+
serverlessActorDriverBuilder,
|
|
236
|
+
);
|
|
237
|
+
|
|
130
238
|
// Start server
|
|
131
239
|
if (!config.disableServer) {
|
|
132
240
|
(async () => {
|
|
@@ -149,5 +257,11 @@ export function setup<A extends RegistryActors>(
|
|
|
149
257
|
return new Registry(config);
|
|
150
258
|
}
|
|
151
259
|
|
|
152
|
-
export type {
|
|
260
|
+
export type {
|
|
261
|
+
RegistryConfig,
|
|
262
|
+
RegistryActors,
|
|
263
|
+
RunConfig,
|
|
264
|
+
RunConfigInput,
|
|
265
|
+
DriverConfig,
|
|
266
|
+
};
|
|
153
267
|
export { RegistryConfigSchema };
|
package/src/registry/serve.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
-
import { getEnvUniversal } from "@/utils";
|
|
3
2
|
import { logger } from "./log";
|
|
4
3
|
|
|
5
4
|
export async function crossPlatformServe(
|
|
@@ -11,7 +10,10 @@ export async function crossPlatformServe(
|
|
|
11
10
|
// Import @hono/node-server
|
|
12
11
|
let serve: any;
|
|
13
12
|
try {
|
|
14
|
-
const dep = await import(
|
|
13
|
+
const dep = await import(
|
|
14
|
+
/* webpackIgnore: true */
|
|
15
|
+
"@hono/node-server"
|
|
16
|
+
);
|
|
15
17
|
serve = dep.serve;
|
|
16
18
|
} catch (err) {
|
|
17
19
|
logger().error(
|
|
@@ -27,7 +29,10 @@ export async function crossPlatformServe(
|
|
|
27
29
|
// Import @hono/node-ws
|
|
28
30
|
let createNodeWebSocket: any;
|
|
29
31
|
try {
|
|
30
|
-
const dep = await import(
|
|
32
|
+
const dep = await import(
|
|
33
|
+
/* webpackIgnore: true */
|
|
34
|
+
"@hono/node-ws"
|
|
35
|
+
);
|
|
31
36
|
createNodeWebSocket = dep.createNodeWebSocket;
|
|
32
37
|
} catch (err) {
|
|
33
38
|
logger().error(
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { ClientConfig } from "@/client/config";
|
|
2
|
+
import {
|
|
3
|
+
HEADER_RIVET_ACTOR,
|
|
4
|
+
HEADER_RIVET_TARGET,
|
|
5
|
+
HEADER_RIVET_TOKEN,
|
|
6
|
+
} from "@/common/actor-router-consts";
|
|
2
7
|
import { combineUrlPath } from "@/utils";
|
|
3
8
|
import { getEndpoint } from "./api-utils";
|
|
4
9
|
|
|
@@ -14,30 +19,29 @@ export async function sendHttpRequestToActor(
|
|
|
14
19
|
|
|
15
20
|
// Handle body properly based on method and presence
|
|
16
21
|
let bodyToSend: ArrayBuffer | null = null;
|
|
17
|
-
const guardHeaders = buildGuardHeadersForHttp(
|
|
22
|
+
const guardHeaders = buildGuardHeadersForHttp(
|
|
23
|
+
runConfig,
|
|
24
|
+
actorRequest,
|
|
25
|
+
actorId,
|
|
26
|
+
);
|
|
18
27
|
|
|
19
|
-
if (
|
|
20
|
-
actorRequest.body &&
|
|
21
|
-
actorRequest.method !== "GET" &&
|
|
22
|
-
actorRequest.method !== "HEAD"
|
|
23
|
-
) {
|
|
28
|
+
if (actorRequest.method !== "GET" && actorRequest.method !== "HEAD") {
|
|
24
29
|
if (actorRequest.bodyUsed) {
|
|
25
30
|
throw new Error("Request body has already been consumed");
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
// TODO: This buffers the entire request in memory every time. We
|
|
29
34
|
// need to properly implement streaming bodies.
|
|
30
|
-
|
|
31
|
-
const clonedRequest = actorRequest.clone();
|
|
32
|
-
bodyToSend = await clonedRequest.arrayBuffer();
|
|
35
|
+
const reqBody = await actorRequest.arrayBuffer();
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
if (reqBody.byteLength !== 0) {
|
|
38
|
+
bodyToSend = reqBody;
|
|
39
|
+
|
|
40
|
+
// If this is a streaming request, we need to convert the headers
|
|
41
|
+
// for the basic array buffer
|
|
42
|
+
guardHeaders.delete("transfer-encoding");
|
|
43
|
+
guardHeaders.set("content-length", String(bodyToSend.byteLength));
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
const guardRequest = new Request(guardUrl, {
|
|
@@ -58,6 +62,7 @@ function mutableResponse(fetchRes: Response): Response {
|
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
function buildGuardHeadersForHttp(
|
|
65
|
+
runConfig: ClientConfig,
|
|
61
66
|
actorRequest: Request,
|
|
62
67
|
actorId: string,
|
|
63
68
|
): Headers {
|
|
@@ -66,9 +71,15 @@ function buildGuardHeadersForHttp(
|
|
|
66
71
|
for (const [key, value] of actorRequest.headers.entries()) {
|
|
67
72
|
headers.set(key, value);
|
|
68
73
|
}
|
|
74
|
+
// Add extra headers from config
|
|
75
|
+
for (const [key, value] of Object.entries(runConfig.headers)) {
|
|
76
|
+
headers.set(key, value);
|
|
77
|
+
}
|
|
69
78
|
// Add guard-specific headers
|
|
70
|
-
headers.set(
|
|
71
|
-
headers.set(
|
|
72
|
-
|
|
79
|
+
headers.set(HEADER_RIVET_TARGET, "actor");
|
|
80
|
+
headers.set(HEADER_RIVET_ACTOR, actorId);
|
|
81
|
+
if (runConfig.token) {
|
|
82
|
+
headers.set(HEADER_RIVET_TOKEN, runConfig.token);
|
|
83
|
+
}
|
|
73
84
|
return headers;
|
|
74
85
|
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import type { ClientConfig } from "@/client/config";
|
|
1
2
|
import {
|
|
2
|
-
HEADER_AUTH_DATA,
|
|
3
3
|
HEADER_CONN_PARAMS,
|
|
4
4
|
HEADER_ENCODING,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
WS_PROTOCOL_ACTOR,
|
|
6
|
+
WS_PROTOCOL_CONN_ID,
|
|
7
|
+
WS_PROTOCOL_CONN_PARAMS,
|
|
8
|
+
WS_PROTOCOL_CONN_TOKEN,
|
|
9
|
+
WS_PROTOCOL_ENCODING,
|
|
10
|
+
WS_PROTOCOL_STANDARD as WS_PROTOCOL_RIVETKIT,
|
|
11
|
+
WS_PROTOCOL_TARGET,
|
|
12
|
+
WS_PROTOCOL_TOKEN,
|
|
13
|
+
} from "@/common/actor-router-consts";
|
|
7
14
|
import { importWebSocket } from "@/common/websocket";
|
|
8
15
|
import type { Encoding, UniversalWebSocket } from "@/mod";
|
|
9
16
|
import { combineUrlPath } from "@/utils";
|
|
@@ -16,6 +23,8 @@ export async function openWebSocketToActor(
|
|
|
16
23
|
actorId: string,
|
|
17
24
|
encoding: Encoding,
|
|
18
25
|
params: unknown,
|
|
26
|
+
connId?: string,
|
|
27
|
+
connToken?: string,
|
|
19
28
|
): Promise<UniversalWebSocket> {
|
|
20
29
|
const WebSocket = await importWebSocket();
|
|
21
30
|
|
|
@@ -31,9 +40,17 @@ export async function openWebSocketToActor(
|
|
|
31
40
|
});
|
|
32
41
|
|
|
33
42
|
// Create WebSocket connection
|
|
34
|
-
const ws = new WebSocket(
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
const ws = new WebSocket(
|
|
44
|
+
guardUrl,
|
|
45
|
+
buildWebSocketProtocols(
|
|
46
|
+
runConfig,
|
|
47
|
+
actorId,
|
|
48
|
+
encoding,
|
|
49
|
+
params,
|
|
50
|
+
connId,
|
|
51
|
+
connToken,
|
|
52
|
+
),
|
|
53
|
+
);
|
|
37
54
|
|
|
38
55
|
// Set binary type to arraybuffer for proper encoding support
|
|
39
56
|
ws.binaryType = "arraybuffer";
|
|
@@ -43,22 +60,32 @@ export async function openWebSocketToActor(
|
|
|
43
60
|
return ws as UniversalWebSocket;
|
|
44
61
|
}
|
|
45
62
|
|
|
46
|
-
export function
|
|
63
|
+
export function buildWebSocketProtocols(
|
|
64
|
+
runConfig: ClientConfig,
|
|
47
65
|
actorId: string,
|
|
48
66
|
encoding: Encoding,
|
|
49
67
|
params?: unknown,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
connId?: string,
|
|
69
|
+
connToken?: string,
|
|
70
|
+
): string[] {
|
|
71
|
+
const protocols: string[] = [];
|
|
72
|
+
protocols.push(WS_PROTOCOL_RIVETKIT);
|
|
73
|
+
protocols.push(`${WS_PROTOCOL_TARGET}actor`);
|
|
74
|
+
protocols.push(`${WS_PROTOCOL_ACTOR}${actorId}`);
|
|
75
|
+
protocols.push(`${WS_PROTOCOL_ENCODING}${encoding}`);
|
|
76
|
+
if (runConfig.token) {
|
|
77
|
+
protocols.push(`${WS_PROTOCOL_TOKEN}${runConfig.token}`);
|
|
78
|
+
}
|
|
57
79
|
if (params) {
|
|
58
|
-
|
|
80
|
+
protocols.push(
|
|
81
|
+
`${WS_PROTOCOL_CONN_PARAMS}${encodeURIComponent(JSON.stringify(params))}`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (connId) {
|
|
85
|
+
protocols.push(`${WS_PROTOCOL_CONN_ID}${connId}`);
|
|
59
86
|
}
|
|
60
|
-
if (
|
|
61
|
-
|
|
87
|
+
if (connToken) {
|
|
88
|
+
protocols.push(`${WS_PROTOCOL_CONN_TOKEN}${connToken}`);
|
|
62
89
|
}
|
|
63
|
-
return
|
|
90
|
+
return protocols;
|
|
64
91
|
}
|
|
@@ -3,52 +3,50 @@ import type { ClientConfig } from "@/client/client";
|
|
|
3
3
|
import type {
|
|
4
4
|
ActorsCreateRequest,
|
|
5
5
|
ActorsCreateResponse,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ActorsGetOrCreateByIdResponse,
|
|
13
|
-
} from "@/manager-api/routes/actors-get-or-create-by-id";
|
|
14
|
-
import type { RivetId } from "@/manager-api/routes/common";
|
|
6
|
+
ActorsDeleteResponse,
|
|
7
|
+
ActorsGetOrCreateRequest,
|
|
8
|
+
ActorsGetOrCreateResponse,
|
|
9
|
+
ActorsListResponse,
|
|
10
|
+
} from "@/manager-api/actors";
|
|
11
|
+
import type { RivetId } from "@/manager-api/common";
|
|
15
12
|
import { apiCall } from "./api-utils";
|
|
16
13
|
|
|
17
14
|
// MARK: Get actor
|
|
18
15
|
export async function getActor(
|
|
19
16
|
config: ClientConfig,
|
|
17
|
+
name: string,
|
|
20
18
|
actorId: RivetId,
|
|
21
|
-
): Promise<
|
|
22
|
-
return apiCall<never,
|
|
19
|
+
): Promise<ActorsListResponse> {
|
|
20
|
+
return apiCall<never, ActorsListResponse>(
|
|
23
21
|
config,
|
|
24
22
|
"GET",
|
|
25
|
-
`/actors
|
|
23
|
+
`/actors?name=${name}&actor_ids=${encodeURIComponent(actorId)}`,
|
|
26
24
|
);
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
// MARK: Get actor by id
|
|
30
|
-
export async function
|
|
28
|
+
export async function getActorByKey(
|
|
31
29
|
config: ClientConfig,
|
|
32
30
|
name: string,
|
|
33
31
|
key: string[],
|
|
34
|
-
): Promise<
|
|
32
|
+
): Promise<ActorsListResponse> {
|
|
35
33
|
const serializedKey = serializeActorKey(key);
|
|
36
|
-
return apiCall<never,
|
|
34
|
+
return apiCall<never, ActorsListResponse>(
|
|
37
35
|
config,
|
|
38
36
|
"GET",
|
|
39
|
-
`/actors
|
|
37
|
+
`/actors?name=${encodeURIComponent(name)}&key=${encodeURIComponent(serializedKey)}`,
|
|
40
38
|
);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
// MARK: Get or create actor by id
|
|
44
|
-
export async function
|
|
42
|
+
export async function getOrCreateActor(
|
|
45
43
|
config: ClientConfig,
|
|
46
|
-
request:
|
|
47
|
-
): Promise<
|
|
48
|
-
return apiCall<
|
|
44
|
+
request: ActorsGetOrCreateRequest,
|
|
45
|
+
): Promise<ActorsGetOrCreateResponse> {
|
|
46
|
+
return apiCall<ActorsGetOrCreateRequest, ActorsGetOrCreateResponse>(
|
|
49
47
|
config,
|
|
50
48
|
"PUT",
|
|
51
|
-
`/actors
|
|
49
|
+
`/actors`,
|
|
52
50
|
request,
|
|
53
51
|
);
|
|
54
52
|
}
|
|
@@ -33,10 +33,19 @@ export async function apiCall<TInput = unknown, TOutput = unknown>(
|
|
|
33
33
|
|
|
34
34
|
logger().debug({ msg: "making api call", method, url });
|
|
35
35
|
|
|
36
|
+
const headers: Record<string, string> = {
|
|
37
|
+
...config.headers,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Add Authorization header if token is provided
|
|
41
|
+
if (config.token) {
|
|
42
|
+
headers.Authorization = `Bearer ${config.token}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
return await sendHttpRequest<TInput, TOutput>({
|
|
37
46
|
method,
|
|
38
47
|
url,
|
|
39
|
-
headers
|
|
48
|
+
headers,
|
|
40
49
|
body,
|
|
41
50
|
encoding: "json",
|
|
42
51
|
skipParseResponse: false,
|