@rivetkit/cloudflare-workers 2.0.33 → 2.0.34-rc.2
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/mod.cjs +81 -66
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +8 -62
- package/dist/mod.d.ts +8 -62
- package/dist/mod.js +82 -67
- package/dist/mod.js.map +1 -1
- package/package.json +2 -2
- package/src/actor-driver.ts +3 -9
- package/src/actor-handler-do.ts +24 -25
- package/src/config.ts +15 -12
- package/src/handler.ts +34 -20
- package/src/manager-driver.ts +28 -11
package/dist/mod.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Client, Registry,
|
|
1
|
+
import { Client, Registry, ActorKey } from 'rivetkit';
|
|
2
2
|
export { Client } from 'rivetkit';
|
|
3
3
|
import { DurableObject } from 'cloudflare:workers';
|
|
4
|
-
import
|
|
4
|
+
import { GetUpgradeWebSocket } from 'rivetkit/utils';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
7
7
|
interface DriverContext {
|
|
@@ -9,64 +9,9 @@ interface DriverContext {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
declare const ConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
12
|
-
maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
13
|
-
maxOutgoingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
14
|
-
inspector: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
15
|
-
enabled: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
|
|
16
|
-
actor: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
17
|
-
manager: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
18
|
-
}, z.core.$strip>]>>>;
|
|
19
|
-
token: z.ZodDefault<z.ZodOptional<z.ZodCustom<() => string, () => string>>>;
|
|
20
|
-
defaultEndpoint: z.ZodOptional<z.ZodString>;
|
|
21
|
-
}, z.core.$strip>>>;
|
|
22
|
-
disableDefaultServer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
23
|
-
defaultServerPort: z.ZodDefault<z.ZodNumber>;
|
|
24
|
-
runEngine: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
25
|
-
runEngineVersion: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
26
|
-
overrideServerAddress: z.ZodOptional<z.ZodString>;
|
|
27
|
-
disableActorDriver: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
28
|
-
runnerKind: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
29
|
-
serverless: "serverless";
|
|
30
|
-
normal: "normal";
|
|
31
|
-
}>>>;
|
|
32
|
-
basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
33
|
-
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
34
|
-
logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
35
|
-
baseLogger: z.ZodOptional<z.ZodCustom<rivetkit_log.Logger, rivetkit_log.Logger>>;
|
|
36
|
-
level: z.ZodOptional<z.ZodEnum<{
|
|
37
|
-
error: "error";
|
|
38
|
-
trace: "trace";
|
|
39
|
-
fatal: "fatal";
|
|
40
|
-
warn: "warn";
|
|
41
|
-
info: "info";
|
|
42
|
-
debug: "debug";
|
|
43
|
-
silent: "silent";
|
|
44
|
-
}>>;
|
|
45
|
-
}, z.core.$strip>>>;
|
|
46
|
-
autoConfigureServerless: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
47
|
-
url: z.ZodOptional<z.ZodString>;
|
|
48
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
49
|
-
maxRunners: z.ZodOptional<z.ZodNumber>;
|
|
50
|
-
minRunners: z.ZodOptional<z.ZodNumber>;
|
|
51
|
-
requestLifespan: z.ZodOptional<z.ZodNumber>;
|
|
52
|
-
runnersMargin: z.ZodOptional<z.ZodNumber>;
|
|
53
|
-
slotsPerRunner: z.ZodOptional<z.ZodNumber>;
|
|
54
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
55
|
-
}, z.core.$strip>]>>;
|
|
56
|
-
runnerKey: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
57
|
-
totalSlots: z.ZodDefault<z.ZodNumber>;
|
|
58
|
-
endpoint: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
59
|
-
token: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
60
|
-
namespace: z.ZodDefault<z.ZodString>;
|
|
61
|
-
runnerName: z.ZodDefault<z.ZodString>;
|
|
62
|
-
encoding: z.ZodDefault<z.ZodEnum<{
|
|
63
|
-
json: "json";
|
|
64
|
-
cbor: "cbor";
|
|
65
|
-
bare: "bare";
|
|
66
|
-
}>>;
|
|
67
|
-
headers: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
68
|
-
disableMetadataLookup: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
69
12
|
managerPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
13
|
+
runnerKey: z.ZodOptional<z.ZodString>;
|
|
14
|
+
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
70
15
|
fetch: z.ZodOptional<z.ZodCustom<ExportedHandlerFetchHandler<{
|
|
71
16
|
RIVET: Client<any>;
|
|
72
17
|
}, unknown>, ExportedHandlerFetchHandler<{
|
|
@@ -98,14 +43,14 @@ interface HandlerOutput {
|
|
|
98
43
|
*
|
|
99
44
|
* If you want to expose a public manager API, either:
|
|
100
45
|
*
|
|
101
|
-
* - Use `createHandler` to expose the Rivet API on `/rivet`
|
|
46
|
+
* - Use `createHandler` to expose the Rivet API on `/api/rivet`
|
|
102
47
|
* - Forward Rivet API requests to `InlineOutput::fetch`
|
|
103
48
|
*/
|
|
104
49
|
declare function createInlineClient<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): InlineOutput<R>;
|
|
105
50
|
/**
|
|
106
51
|
* Creates a handler to be exported from a Cloudflare Worker.
|
|
107
52
|
*
|
|
108
|
-
* This will automatically expose the Rivet manager API on `/rivet`.
|
|
53
|
+
* This will automatically expose the Rivet manager API on `/api/rivet`.
|
|
109
54
|
*
|
|
110
55
|
* This includes a `fetch` handler and `ActorHandler` Durable Object.
|
|
111
56
|
*/
|
|
@@ -119,6 +64,7 @@ interface ActorHandlerInterface extends DurableObject {
|
|
|
119
64
|
key: ActorKey;
|
|
120
65
|
destroying: boolean;
|
|
121
66
|
} | undefined>;
|
|
67
|
+
managerKvGet(key: Uint8Array): Promise<Uint8Array | null>;
|
|
122
68
|
}
|
|
123
69
|
interface ActorInitRequest {
|
|
124
70
|
name: string;
|
|
@@ -137,6 +83,6 @@ type ActorInitResponse = {
|
|
|
137
83
|
};
|
|
138
84
|
};
|
|
139
85
|
type DurableObjectConstructor = new (...args: ConstructorParameters<typeof DurableObject<Bindings>>) => DurableObject<Bindings>;
|
|
140
|
-
declare function createActorDurableObject(registry: Registry<any>,
|
|
86
|
+
declare function createActorDurableObject(registry: Registry<any>, getUpgradeWebSocket: GetUpgradeWebSocket): DurableObjectConstructor;
|
|
141
87
|
|
|
142
88
|
export { type Bindings, type InputConfig as Config, type DriverContext, type HandlerOutput, type InlineOutput, createActorDurableObject, createHandler, createInlineClient };
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Client, Registry,
|
|
1
|
+
import { Client, Registry, ActorKey } from 'rivetkit';
|
|
2
2
|
export { Client } from 'rivetkit';
|
|
3
3
|
import { DurableObject } from 'cloudflare:workers';
|
|
4
|
-
import
|
|
4
|
+
import { GetUpgradeWebSocket } from 'rivetkit/utils';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
7
7
|
interface DriverContext {
|
|
@@ -9,64 +9,9 @@ interface DriverContext {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
declare const ConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
12
|
-
maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
13
|
-
maxOutgoingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
14
|
-
inspector: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
15
|
-
enabled: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
|
|
16
|
-
actor: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
17
|
-
manager: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
18
|
-
}, z.core.$strip>]>>>;
|
|
19
|
-
token: z.ZodDefault<z.ZodOptional<z.ZodCustom<() => string, () => string>>>;
|
|
20
|
-
defaultEndpoint: z.ZodOptional<z.ZodString>;
|
|
21
|
-
}, z.core.$strip>>>;
|
|
22
|
-
disableDefaultServer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
23
|
-
defaultServerPort: z.ZodDefault<z.ZodNumber>;
|
|
24
|
-
runEngine: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
25
|
-
runEngineVersion: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
26
|
-
overrideServerAddress: z.ZodOptional<z.ZodString>;
|
|
27
|
-
disableActorDriver: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
28
|
-
runnerKind: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
29
|
-
serverless: "serverless";
|
|
30
|
-
normal: "normal";
|
|
31
|
-
}>>>;
|
|
32
|
-
basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
33
|
-
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
34
|
-
logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
35
|
-
baseLogger: z.ZodOptional<z.ZodCustom<rivetkit_log.Logger, rivetkit_log.Logger>>;
|
|
36
|
-
level: z.ZodOptional<z.ZodEnum<{
|
|
37
|
-
error: "error";
|
|
38
|
-
trace: "trace";
|
|
39
|
-
fatal: "fatal";
|
|
40
|
-
warn: "warn";
|
|
41
|
-
info: "info";
|
|
42
|
-
debug: "debug";
|
|
43
|
-
silent: "silent";
|
|
44
|
-
}>>;
|
|
45
|
-
}, z.core.$strip>>>;
|
|
46
|
-
autoConfigureServerless: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
47
|
-
url: z.ZodOptional<z.ZodString>;
|
|
48
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
49
|
-
maxRunners: z.ZodOptional<z.ZodNumber>;
|
|
50
|
-
minRunners: z.ZodOptional<z.ZodNumber>;
|
|
51
|
-
requestLifespan: z.ZodOptional<z.ZodNumber>;
|
|
52
|
-
runnersMargin: z.ZodOptional<z.ZodNumber>;
|
|
53
|
-
slotsPerRunner: z.ZodOptional<z.ZodNumber>;
|
|
54
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
55
|
-
}, z.core.$strip>]>>;
|
|
56
|
-
runnerKey: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
57
|
-
totalSlots: z.ZodDefault<z.ZodNumber>;
|
|
58
|
-
endpoint: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
59
|
-
token: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
60
|
-
namespace: z.ZodDefault<z.ZodString>;
|
|
61
|
-
runnerName: z.ZodDefault<z.ZodString>;
|
|
62
|
-
encoding: z.ZodDefault<z.ZodEnum<{
|
|
63
|
-
json: "json";
|
|
64
|
-
cbor: "cbor";
|
|
65
|
-
bare: "bare";
|
|
66
|
-
}>>;
|
|
67
|
-
headers: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
68
|
-
disableMetadataLookup: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
69
12
|
managerPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
13
|
+
runnerKey: z.ZodOptional<z.ZodString>;
|
|
14
|
+
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
70
15
|
fetch: z.ZodOptional<z.ZodCustom<ExportedHandlerFetchHandler<{
|
|
71
16
|
RIVET: Client<any>;
|
|
72
17
|
}, unknown>, ExportedHandlerFetchHandler<{
|
|
@@ -98,14 +43,14 @@ interface HandlerOutput {
|
|
|
98
43
|
*
|
|
99
44
|
* If you want to expose a public manager API, either:
|
|
100
45
|
*
|
|
101
|
-
* - Use `createHandler` to expose the Rivet API on `/rivet`
|
|
46
|
+
* - Use `createHandler` to expose the Rivet API on `/api/rivet`
|
|
102
47
|
* - Forward Rivet API requests to `InlineOutput::fetch`
|
|
103
48
|
*/
|
|
104
49
|
declare function createInlineClient<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): InlineOutput<R>;
|
|
105
50
|
/**
|
|
106
51
|
* Creates a handler to be exported from a Cloudflare Worker.
|
|
107
52
|
*
|
|
108
|
-
* This will automatically expose the Rivet manager API on `/rivet`.
|
|
53
|
+
* This will automatically expose the Rivet manager API on `/api/rivet`.
|
|
109
54
|
*
|
|
110
55
|
* This includes a `fetch` handler and `ActorHandler` Durable Object.
|
|
111
56
|
*/
|
|
@@ -119,6 +64,7 @@ interface ActorHandlerInterface extends DurableObject {
|
|
|
119
64
|
key: ActorKey;
|
|
120
65
|
destroying: boolean;
|
|
121
66
|
} | undefined>;
|
|
67
|
+
managerKvGet(key: Uint8Array): Promise<Uint8Array | null>;
|
|
122
68
|
}
|
|
123
69
|
interface ActorInitRequest {
|
|
124
70
|
name: string;
|
|
@@ -137,6 +83,6 @@ type ActorInitResponse = {
|
|
|
137
83
|
};
|
|
138
84
|
};
|
|
139
85
|
type DurableObjectConstructor = new (...args: ConstructorParameters<typeof DurableObject<Bindings>>) => DurableObject<Bindings>;
|
|
140
|
-
declare function createActorDurableObject(registry: Registry<any>,
|
|
86
|
+
declare function createActorDurableObject(registry: Registry<any>, getUpgradeWebSocket: GetUpgradeWebSocket): DurableObjectConstructor;
|
|
141
87
|
|
|
142
88
|
export { type Bindings, type InputConfig as Config, type DriverContext, type HandlerOutput, type InlineOutput, createActorDurableObject, createHandler, createInlineClient };
|
package/dist/mod.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/actor-handler-do.ts
|
|
2
2
|
import { DurableObject, env as env2 } from "cloudflare:workers";
|
|
3
3
|
import invariant2 from "invariant";
|
|
4
|
-
import { createActorRouter, createClientWithDriver } from "rivetkit";
|
|
4
|
+
import { createActorRouter, createClientWithDriver as createClientWithDriver2 } from "rivetkit";
|
|
5
5
|
import { getInitialActorKvState } from "rivetkit/driver-helpers";
|
|
6
6
|
|
|
7
7
|
// src/actor-driver.ts
|
|
@@ -9,23 +9,6 @@ import invariant from "invariant";
|
|
|
9
9
|
import { lookupInRegistry } from "rivetkit";
|
|
10
10
|
import { promiseWithResolvers } from "rivetkit/utils";
|
|
11
11
|
|
|
12
|
-
// src/actor-id.ts
|
|
13
|
-
function buildActorId(doId, generation) {
|
|
14
|
-
return `${doId}:${generation}`;
|
|
15
|
-
}
|
|
16
|
-
function parseActorId(actorId) {
|
|
17
|
-
const parts = actorId.split(":");
|
|
18
|
-
if (parts.length !== 2) {
|
|
19
|
-
throw new Error(`Invalid actor ID format: ${actorId}`);
|
|
20
|
-
}
|
|
21
|
-
const [doId, generationStr] = parts;
|
|
22
|
-
const generation = parseInt(generationStr, 10);
|
|
23
|
-
if (Number.isNaN(generation)) {
|
|
24
|
-
throw new Error(`Invalid generation number in actor ID: ${actorId}`);
|
|
25
|
-
}
|
|
26
|
-
return [doId, generation];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
12
|
// src/actor-kv.ts
|
|
30
13
|
function kvGet(sql, key) {
|
|
31
14
|
const cursor = sql.exec(
|
|
@@ -89,13 +72,18 @@ var GLOBAL_KV_KEYS = {
|
|
|
89
72
|
|
|
90
73
|
// src/handler.ts
|
|
91
74
|
import { env } from "cloudflare:workers";
|
|
75
|
+
import { createClientWithDriver } from "rivetkit";
|
|
76
|
+
import { buildManagerRouter } from "rivetkit/driver-helpers";
|
|
92
77
|
|
|
93
78
|
// src/config.ts
|
|
94
|
-
import { RunConfigSchema } from "rivetkit/driver-helpers";
|
|
95
79
|
import { z } from "zod";
|
|
96
|
-
var ConfigSchemaBase =
|
|
80
|
+
var ConfigSchemaBase = z.object({
|
|
97
81
|
/** Path that the Rivet manager API will be mounted. */
|
|
98
|
-
managerPath: z.string().optional().default("/rivet"),
|
|
82
|
+
managerPath: z.string().optional().default("/api/rivet"),
|
|
83
|
+
/** Runner key for authentication. */
|
|
84
|
+
runnerKey: z.string().optional(),
|
|
85
|
+
/** Disable the welcome message. */
|
|
86
|
+
noWelcome: z.boolean().optional().default(false),
|
|
99
87
|
fetch: z.custom().optional()
|
|
100
88
|
});
|
|
101
89
|
var ConfigSchema = ConfigSchemaBase.default(
|
|
@@ -104,7 +92,6 @@ var ConfigSchema = ConfigSchemaBase.default(
|
|
|
104
92
|
|
|
105
93
|
// src/manager-driver.ts
|
|
106
94
|
import {
|
|
107
|
-
generateRandomString,
|
|
108
95
|
WS_PROTOCOL_ACTOR,
|
|
109
96
|
WS_PROTOCOL_CONN_PARAMS,
|
|
110
97
|
WS_PROTOCOL_ENCODING,
|
|
@@ -118,6 +105,23 @@ import {
|
|
|
118
105
|
} from "rivetkit/errors";
|
|
119
106
|
import { assertUnreachable } from "rivetkit/utils";
|
|
120
107
|
|
|
108
|
+
// src/actor-id.ts
|
|
109
|
+
function buildActorId(doId, generation) {
|
|
110
|
+
return `${doId}:${generation}`;
|
|
111
|
+
}
|
|
112
|
+
function parseActorId(actorId) {
|
|
113
|
+
const parts = actorId.split(":");
|
|
114
|
+
if (parts.length !== 2) {
|
|
115
|
+
throw new Error(`Invalid actor ID format: ${actorId}`);
|
|
116
|
+
}
|
|
117
|
+
const [doId, generationStr] = parts;
|
|
118
|
+
const generation = parseInt(generationStr, 10);
|
|
119
|
+
if (Number.isNaN(generation)) {
|
|
120
|
+
throw new Error(`Invalid generation number in actor ID: ${actorId}`);
|
|
121
|
+
}
|
|
122
|
+
return [doId, generation];
|
|
123
|
+
}
|
|
124
|
+
|
|
121
125
|
// src/log.ts
|
|
122
126
|
import { getLogger } from "rivetkit/log";
|
|
123
127
|
function logger() {
|
|
@@ -229,6 +233,7 @@ Response: ${await response.text()}`
|
|
|
229
233
|
return webSocket;
|
|
230
234
|
}
|
|
231
235
|
async proxyRequest(c, actorRequest, actorId) {
|
|
236
|
+
const env3 = getCloudflareAmbientEnv();
|
|
232
237
|
const [doId] = parseActorId(actorId);
|
|
233
238
|
logger().debug({
|
|
234
239
|
msg: "forwarding request to durable object",
|
|
@@ -237,8 +242,8 @@ Response: ${await response.text()}`
|
|
|
237
242
|
method: actorRequest.method,
|
|
238
243
|
url: actorRequest.url
|
|
239
244
|
});
|
|
240
|
-
const id =
|
|
241
|
-
const stub =
|
|
245
|
+
const id = env3.ACTOR_DO.idFromString(doId);
|
|
246
|
+
const stub = env3.ACTOR_DO.get(id);
|
|
242
247
|
return await stub.fetch(actorRequest);
|
|
243
248
|
}
|
|
244
249
|
async proxyWebSocket(c, path, actorId, encoding, params) {
|
|
@@ -283,13 +288,15 @@ Response: ${await response.text()}`
|
|
|
283
288
|
"sec-websocket-protocol",
|
|
284
289
|
protocols.join(", ")
|
|
285
290
|
);
|
|
291
|
+
const env3 = getCloudflareAmbientEnv();
|
|
286
292
|
const [doId] = parseActorId(actorId);
|
|
287
|
-
const id =
|
|
288
|
-
const stub =
|
|
293
|
+
const id = env3.ACTOR_DO.idFromString(doId);
|
|
294
|
+
const stub = env3.ACTOR_DO.get(id);
|
|
289
295
|
return await stub.fetch(actorRequest);
|
|
290
296
|
}
|
|
291
297
|
async getForId({
|
|
292
298
|
c,
|
|
299
|
+
name,
|
|
293
300
|
actorId
|
|
294
301
|
}) {
|
|
295
302
|
const env3 = getCloudflareAmbientEnv();
|
|
@@ -434,12 +441,20 @@ Response: ${await response.text()}`
|
|
|
434
441
|
}
|
|
435
442
|
displayInformation() {
|
|
436
443
|
return {
|
|
437
|
-
|
|
438
|
-
|
|
444
|
+
properties: {
|
|
445
|
+
Driver: "Cloudflare Workers"
|
|
446
|
+
}
|
|
439
447
|
};
|
|
440
448
|
}
|
|
441
|
-
|
|
442
|
-
|
|
449
|
+
setGetUpgradeWebSocket() {
|
|
450
|
+
}
|
|
451
|
+
async kvGet(actorId, key) {
|
|
452
|
+
const env3 = getCloudflareAmbientEnv();
|
|
453
|
+
const [doId] = parseActorId(actorId);
|
|
454
|
+
const id = env3.ACTOR_DO.idFromString(doId);
|
|
455
|
+
const stub = env3.ACTOR_DO.get(id);
|
|
456
|
+
const value = await stub.managerKvGet(key);
|
|
457
|
+
return value !== null ? new TextDecoder().decode(value) : null;
|
|
443
458
|
}
|
|
444
459
|
};
|
|
445
460
|
|
|
@@ -515,19 +530,25 @@ function getCloudflareAmbientEnv() {
|
|
|
515
530
|
function createInlineClient(registry, inputConfig) {
|
|
516
531
|
inputConfig = { ...inputConfig, runnerKey: "" };
|
|
517
532
|
const config = ConfigSchema.parse(inputConfig);
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
getUpgradeWebSocket: () => upgradeWebSocket
|
|
533
|
+
const ActorHandler = createActorDurableObject(
|
|
534
|
+
registry,
|
|
535
|
+
() => upgradeWebSocket
|
|
536
|
+
);
|
|
537
|
+
registry.config.noWelcome = true;
|
|
538
|
+
registry.config.inspector = {
|
|
539
|
+
enabled: false,
|
|
540
|
+
token: () => ""
|
|
527
541
|
};
|
|
528
|
-
|
|
529
|
-
const
|
|
530
|
-
|
|
542
|
+
registry.config.managerBasePath = "/";
|
|
543
|
+
const parsedConfig = registry.parseConfig();
|
|
544
|
+
const managerDriver = new CloudflareActorsManagerDriver();
|
|
545
|
+
const { router } = buildManagerRouter(
|
|
546
|
+
parsedConfig,
|
|
547
|
+
managerDriver,
|
|
548
|
+
() => upgradeWebSocket
|
|
549
|
+
);
|
|
550
|
+
const client = createClientWithDriver(managerDriver);
|
|
551
|
+
return { client, fetch: router.fetch.bind(router), config, ActorHandler };
|
|
531
552
|
}
|
|
532
553
|
function createHandler(registry, inputConfig) {
|
|
533
554
|
const { client, fetch, config, ActorHandler } = createInlineClient(
|
|
@@ -550,7 +571,7 @@ function createHandler(registry, inputConfig) {
|
|
|
550
571
|
return config.fetch(request, env3, ctx);
|
|
551
572
|
} else {
|
|
552
573
|
return new Response(
|
|
553
|
-
"This is a RivetKit server.\n\nLearn more at https://
|
|
574
|
+
"This is a RivetKit server.\n\nLearn more at https://rivet.dev\n",
|
|
554
575
|
{ status: 200 }
|
|
555
576
|
);
|
|
556
577
|
}
|
|
@@ -608,13 +629,11 @@ var ActorGlobalState = class {
|
|
|
608
629
|
};
|
|
609
630
|
var CloudflareActorsActorDriver = class {
|
|
610
631
|
#registryConfig;
|
|
611
|
-
#runConfig;
|
|
612
632
|
#managerDriver;
|
|
613
633
|
#inlineClient;
|
|
614
634
|
#globalState;
|
|
615
|
-
constructor(registryConfig,
|
|
635
|
+
constructor(registryConfig, managerDriver, inlineClient, globalState) {
|
|
616
636
|
this.#registryConfig = registryConfig;
|
|
617
|
-
this.#runConfig = runConfig;
|
|
618
637
|
this.#managerDriver = managerDriver;
|
|
619
638
|
this.#inlineClient = inlineClient;
|
|
620
639
|
this.#globalState = globalState;
|
|
@@ -746,10 +765,9 @@ var CloudflareActorsActorDriver = class {
|
|
|
746
765
|
}
|
|
747
766
|
};
|
|
748
767
|
function createCloudflareActorsActorDriverBuilder(globalState) {
|
|
749
|
-
return (
|
|
768
|
+
return (config, managerDriver, inlineClient) => {
|
|
750
769
|
return new CloudflareActorsActorDriver(
|
|
751
|
-
|
|
752
|
-
runConfig,
|
|
770
|
+
config,
|
|
753
771
|
managerDriver,
|
|
754
772
|
inlineClient,
|
|
755
773
|
globalState
|
|
@@ -758,9 +776,9 @@ function createCloudflareActorsActorDriverBuilder(globalState) {
|
|
|
758
776
|
}
|
|
759
777
|
|
|
760
778
|
// src/actor-handler-do.ts
|
|
761
|
-
function createActorDurableObject(registry,
|
|
779
|
+
function createActorDurableObject(registry, getUpgradeWebSocket) {
|
|
762
780
|
const globalState = new CloudflareDurableObjectGlobalState();
|
|
763
|
-
const
|
|
781
|
+
const parsedConfig = registry.parseConfig();
|
|
764
782
|
return class ActorHandler extends DurableObject {
|
|
765
783
|
/**
|
|
766
784
|
* This holds a strong reference to ActorGlobalState.
|
|
@@ -794,7 +812,7 @@ function createActorDurableObject(registry, rootRunConfig) {
|
|
|
794
812
|
}
|
|
795
813
|
}
|
|
796
814
|
async #loadActor() {
|
|
797
|
-
var _a;
|
|
815
|
+
var _a, _b;
|
|
798
816
|
invariant2(this.#state, "State should be initialized");
|
|
799
817
|
if (!this.#state.initialized) {
|
|
800
818
|
const cursor = this.ctx.storage.sql.exec(
|
|
@@ -835,26 +853,19 @@ function createActorDurableObject(registry, rootRunConfig) {
|
|
|
835
853
|
if (!this.#state.initialized) throw new Error("Not initialized");
|
|
836
854
|
const actorId = this.ctx.id.toString();
|
|
837
855
|
globalState.setDOState(actorId, { ctx: this.ctx, env: env2 });
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
const
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
);
|
|
844
|
-
const inlineClient = createClientWithDriver(
|
|
845
|
-
managerDriver,
|
|
846
|
-
runConfig
|
|
847
|
-
);
|
|
848
|
-
const actorDriver = runConfig.driver.actor(
|
|
849
|
-
registry.config,
|
|
850
|
-
runConfig,
|
|
856
|
+
const managerDriver = new CloudflareActorsManagerDriver();
|
|
857
|
+
const inlineClient = createClientWithDriver2(managerDriver);
|
|
858
|
+
const actorDriverBuilder = createCloudflareActorsActorDriverBuilder(globalState);
|
|
859
|
+
const actorDriver = actorDriverBuilder(
|
|
860
|
+
parsedConfig,
|
|
851
861
|
managerDriver,
|
|
852
862
|
inlineClient
|
|
853
863
|
);
|
|
854
864
|
const actorRouter = createActorRouter(
|
|
855
|
-
|
|
865
|
+
parsedConfig,
|
|
856
866
|
actorDriver,
|
|
857
|
-
|
|
867
|
+
getUpgradeWebSocket,
|
|
868
|
+
((_b = registry.config.test) == null ? void 0 : _b.enabled) ?? false
|
|
858
869
|
);
|
|
859
870
|
this.#state.actor = {
|
|
860
871
|
actorRouter,
|
|
@@ -907,6 +918,10 @@ function createActorDurableObject(registry, rootRunConfig) {
|
|
|
907
918
|
});
|
|
908
919
|
return void 0;
|
|
909
920
|
}
|
|
921
|
+
/** RPC called by ManagerDriver.kvGet to read from KV. */
|
|
922
|
+
async managerKvGet(key) {
|
|
923
|
+
return kvGet(this.ctx.storage.sql, key);
|
|
924
|
+
}
|
|
910
925
|
/** RPC called by the manager to create a DO. Can optionally allow existing actors. */
|
|
911
926
|
async create(req) {
|
|
912
927
|
const checkCursor = this.ctx.storage.sql.exec(
|