@rivetkit/cloudflare-workers 2.0.3 → 2.0.4-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/README.md +3 -3
- package/dist/mod.cjs +790 -363
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +70 -161
- package/dist/mod.d.ts +70 -161
- package/dist/mod.js +803 -376
- package/dist/mod.js.map +1 -1
- package/package.json +9 -5
- package/src/actor-driver.ts +223 -72
- package/src/actor-handler-do.ts +339 -109
- package/src/actor-id.ts +38 -0
- package/src/actor-kv.ts +71 -0
- package/src/config.ts +22 -10
- package/src/global-kv.ts +6 -0
- package/src/handler.ts +103 -52
- package/src/log.ts +1 -3
- package/src/manager-driver.ts +236 -132
- package/src/mod.ts +9 -1
- package/src/websocket.ts +17 -6
package/dist/mod.d.ts
CHANGED
|
@@ -1,179 +1,88 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { Hono } from 'hono';
|
|
4
|
-
import * as rivetkit_utils from 'rivetkit/utils';
|
|
5
|
-
import * as rivetkit_driver_helpers from 'rivetkit/driver-helpers';
|
|
6
|
-
import * as rivetkit from 'rivetkit';
|
|
7
|
-
import { ActorKey, Registry } from 'rivetkit';
|
|
8
|
-
import { z } from 'zod';
|
|
9
|
-
import { Client } from 'rivetkit/client';
|
|
1
|
+
import { Client, Registry, ActorKey } from 'rivetkit';
|
|
2
|
+
export { Client } from 'rivetkit';
|
|
10
3
|
import { DurableObject } from 'cloudflare:workers';
|
|
4
|
+
import { GetUpgradeWebSocket } from 'rivetkit/utils';
|
|
5
|
+
import { z } from 'zod/v4';
|
|
11
6
|
|
|
12
7
|
interface DriverContext {
|
|
13
8
|
state: DurableObjectState;
|
|
14
9
|
}
|
|
15
10
|
|
|
16
|
-
declare const ConfigSchema: z.ZodDefault<z.ZodObject<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
actor: (registryConfig: rivetkit.RegistryConfig, runConfig: rivetkit.RunConfig, managerDriver: rivetkit_driver_helpers.ManagerDriver, inlineClient: rivetkit.AnyClient) => rivetkit_driver_helpers.ActorDriver;
|
|
27
|
-
name: string;
|
|
28
|
-
manager: (registryConfig: rivetkit.RegistryConfig, runConfig: rivetkit.RunConfig) => rivetkit_driver_helpers.ManagerDriver;
|
|
29
|
-
}>>;
|
|
30
|
-
engine: z.ZodOptional<z.ZodString>;
|
|
31
|
-
getUpgradeWebSocket: z.ZodOptional<z.ZodType<() => rivetkit_utils.UpgradeWebSocket, z.ZodTypeDef, () => rivetkit_utils.UpgradeWebSocket>>;
|
|
32
|
-
role: z.ZodDefault<z.ZodOptional<z.ZodEnum<["all", "server", "runner"]>>>;
|
|
33
|
-
cors: z.ZodOptional<z.ZodType<{
|
|
34
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
35
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
36
|
-
allowHeaders?: string[];
|
|
37
|
-
maxAge?: number;
|
|
38
|
-
credentials?: boolean;
|
|
39
|
-
exposeHeaders?: string[];
|
|
40
|
-
}, z.ZodTypeDef, {
|
|
41
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
42
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
43
|
-
allowHeaders?: string[];
|
|
44
|
-
maxAge?: number;
|
|
45
|
-
credentials?: boolean;
|
|
46
|
-
exposeHeaders?: string[];
|
|
47
|
-
}>>;
|
|
48
|
-
maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
49
|
-
inspector: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
50
|
-
enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
51
|
-
cors: z.ZodDefault<z.ZodOptional<z.ZodType<{
|
|
52
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
53
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
54
|
-
allowHeaders?: string[];
|
|
55
|
-
maxAge?: number;
|
|
56
|
-
credentials?: boolean;
|
|
57
|
-
exposeHeaders?: string[];
|
|
58
|
-
}, z.ZodTypeDef, {
|
|
59
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
60
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
61
|
-
allowHeaders?: string[];
|
|
62
|
-
maxAge?: number;
|
|
63
|
-
credentials?: boolean;
|
|
64
|
-
exposeHeaders?: string[];
|
|
65
|
-
}>>>;
|
|
66
|
-
token: z.ZodDefault<z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodString>>>;
|
|
67
|
-
defaultEndpoint: z.ZodOptional<z.ZodString>;
|
|
68
|
-
}, "strip", z.ZodTypeAny, {
|
|
69
|
-
enabled: boolean;
|
|
70
|
-
cors: {
|
|
71
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
72
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
73
|
-
allowHeaders?: string[];
|
|
74
|
-
maxAge?: number;
|
|
75
|
-
credentials?: boolean;
|
|
76
|
-
exposeHeaders?: string[];
|
|
77
|
-
};
|
|
78
|
-
token: (...args: unknown[]) => string;
|
|
79
|
-
defaultEndpoint?: string | undefined;
|
|
80
|
-
}, {
|
|
81
|
-
enabled?: boolean | undefined;
|
|
82
|
-
cors?: {
|
|
83
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
84
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
85
|
-
allowHeaders?: string[];
|
|
86
|
-
maxAge?: number;
|
|
87
|
-
credentials?: boolean;
|
|
88
|
-
exposeHeaders?: string[];
|
|
89
|
-
} | undefined;
|
|
90
|
-
token?: ((...args: unknown[]) => string) | undefined;
|
|
91
|
-
defaultEndpoint?: string | undefined;
|
|
92
|
-
}>>>;
|
|
93
|
-
basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
94
|
-
}, "driver" | "getUpgradeWebSocket"> & {
|
|
95
|
-
app: z.ZodOptional<z.ZodType<Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">, z.ZodTypeDef, Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">>>;
|
|
96
|
-
}, "strip", z.ZodTypeAny, {
|
|
97
|
-
role: "all" | "server" | "runner";
|
|
98
|
-
maxIncomingMessageSize: number;
|
|
99
|
-
inspector: {
|
|
100
|
-
enabled: boolean;
|
|
101
|
-
cors: {
|
|
102
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
103
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
104
|
-
allowHeaders?: string[];
|
|
105
|
-
maxAge?: number;
|
|
106
|
-
credentials?: boolean;
|
|
107
|
-
exposeHeaders?: string[];
|
|
108
|
-
};
|
|
109
|
-
token: (...args: unknown[]) => string;
|
|
110
|
-
defaultEndpoint?: string | undefined;
|
|
111
|
-
};
|
|
112
|
-
basePath: string;
|
|
113
|
-
engine?: string | undefined;
|
|
114
|
-
cors?: {
|
|
115
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
116
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
117
|
-
allowHeaders?: string[];
|
|
118
|
-
maxAge?: number;
|
|
119
|
-
credentials?: boolean;
|
|
120
|
-
exposeHeaders?: string[];
|
|
121
|
-
} | undefined;
|
|
122
|
-
app?: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/"> | undefined;
|
|
123
|
-
}, {
|
|
124
|
-
engine?: string | undefined;
|
|
125
|
-
role?: "all" | "server" | "runner" | undefined;
|
|
126
|
-
cors?: {
|
|
127
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
128
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
129
|
-
allowHeaders?: string[];
|
|
130
|
-
maxAge?: number;
|
|
131
|
-
credentials?: boolean;
|
|
132
|
-
exposeHeaders?: string[];
|
|
133
|
-
} | undefined;
|
|
134
|
-
maxIncomingMessageSize?: number | undefined;
|
|
135
|
-
inspector?: {
|
|
136
|
-
enabled?: boolean | undefined;
|
|
137
|
-
cors?: {
|
|
138
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
139
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
140
|
-
allowHeaders?: string[];
|
|
141
|
-
maxAge?: number;
|
|
142
|
-
credentials?: boolean;
|
|
143
|
-
exposeHeaders?: string[];
|
|
144
|
-
} | undefined;
|
|
145
|
-
token?: ((...args: unknown[]) => string) | undefined;
|
|
146
|
-
defaultEndpoint?: string | undefined;
|
|
147
|
-
} | undefined;
|
|
148
|
-
basePath?: string | undefined;
|
|
149
|
-
app?: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/"> | undefined;
|
|
150
|
-
}>>;
|
|
11
|
+
declare const ConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
12
|
+
managerPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
13
|
+
runnerKey: z.ZodOptional<z.ZodString>;
|
|
14
|
+
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
15
|
+
fetch: z.ZodOptional<z.ZodCustom<ExportedHandlerFetchHandler<{
|
|
16
|
+
RIVET: Client<any>;
|
|
17
|
+
}, unknown>, ExportedHandlerFetchHandler<{
|
|
18
|
+
RIVET: Client<any>;
|
|
19
|
+
}, unknown>>>;
|
|
20
|
+
}, z.core.$strip>>;
|
|
151
21
|
type InputConfig = z.input<typeof ConfigSchema>;
|
|
152
|
-
|
|
153
|
-
interface ActorHandlerInterface extends DurableObject {
|
|
154
|
-
initialize(req: ActorInitRequest): Promise<void>;
|
|
155
|
-
}
|
|
156
|
-
interface ActorInitRequest {
|
|
157
|
-
name: string;
|
|
158
|
-
key: ActorKey;
|
|
159
|
-
input?: unknown;
|
|
160
|
-
}
|
|
161
|
-
type DurableObjectConstructor = new (...args: ConstructorParameters<typeof DurableObject<Bindings>>) => DurableObject<Bindings>;
|
|
22
|
+
type Config = z.infer<typeof ConfigSchema>;
|
|
162
23
|
|
|
163
24
|
/** Cloudflare Workers env */
|
|
164
25
|
interface Bindings {
|
|
165
26
|
ACTOR_KV: KVNamespace;
|
|
166
27
|
ACTOR_DO: DurableObjectNamespace<ActorHandlerInterface>;
|
|
167
28
|
}
|
|
168
|
-
interface
|
|
29
|
+
interface InlineOutput<A extends Registry<any>> {
|
|
30
|
+
/** Client to communicate with the actors. */
|
|
31
|
+
client: Client<A>;
|
|
32
|
+
/** Fetch handler to manually route requests to the Rivet manager API. */
|
|
33
|
+
fetch: (request: Request, ...args: any) => Response | Promise<Response>;
|
|
34
|
+
config: Config;
|
|
35
|
+
ActorHandler: DurableObjectConstructor;
|
|
36
|
+
}
|
|
37
|
+
interface HandlerOutput {
|
|
169
38
|
handler: ExportedHandler<Bindings>;
|
|
170
39
|
ActorHandler: DurableObjectConstructor;
|
|
171
40
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Creates an inline client for accessing Rivet Actors privately without a public manager API.
|
|
43
|
+
*
|
|
44
|
+
* If you want to expose a public manager API, either:
|
|
45
|
+
*
|
|
46
|
+
* - Use `createHandler` to expose the Rivet API on `/api/rivet`
|
|
47
|
+
* - Forward Rivet API requests to `InlineOutput::fetch`
|
|
48
|
+
*/
|
|
49
|
+
declare function createInlineClient<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): InlineOutput<R>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a handler to be exported from a Cloudflare Worker.
|
|
52
|
+
*
|
|
53
|
+
* This will automatically expose the Rivet manager API on `/api/rivet`.
|
|
54
|
+
*
|
|
55
|
+
* This includes a `fetch` handler and `ActorHandler` Durable Object.
|
|
56
|
+
*/
|
|
57
|
+
declare function createHandler<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): HandlerOutput;
|
|
58
|
+
|
|
59
|
+
interface ActorHandlerInterface extends DurableObject {
|
|
60
|
+
create(req: ActorInitRequest): Promise<ActorInitResponse>;
|
|
61
|
+
getMetadata(): Promise<{
|
|
62
|
+
actorId: string;
|
|
63
|
+
name: string;
|
|
64
|
+
key: ActorKey;
|
|
65
|
+
destroying: boolean;
|
|
66
|
+
} | undefined>;
|
|
67
|
+
managerKvGet(key: Uint8Array): Promise<Uint8Array | null>;
|
|
175
68
|
}
|
|
176
|
-
|
|
177
|
-
|
|
69
|
+
interface ActorInitRequest {
|
|
70
|
+
name: string;
|
|
71
|
+
key: ActorKey;
|
|
72
|
+
input?: unknown;
|
|
73
|
+
allowExisting: boolean;
|
|
74
|
+
}
|
|
75
|
+
type ActorInitResponse = {
|
|
76
|
+
success: {
|
|
77
|
+
actorId: string;
|
|
78
|
+
created: boolean;
|
|
79
|
+
};
|
|
80
|
+
} | {
|
|
81
|
+
error: {
|
|
82
|
+
actorAlreadyExists: true;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
type DurableObjectConstructor = new (...args: ConstructorParameters<typeof DurableObject<Bindings>>) => DurableObject<Bindings>;
|
|
86
|
+
declare function createActorDurableObject(registry: Registry<any>, getUpgradeWebSocket: GetUpgradeWebSocket): DurableObjectConstructor;
|
|
178
87
|
|
|
179
|
-
export { type Bindings, type InputConfig as Config, type DriverContext,
|
|
88
|
+
export { type Bindings, type InputConfig as Config, type DriverContext, type HandlerOutput, type InlineOutput, createActorDurableObject, createHandler, createInlineClient };
|