@vultro/runtime-cf 0.0.0-stage → 0.0.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/README.md CHANGED
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # @vultro/runtime-cf
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@vultro/core` 的 **Cloudflare Workers / Durable Objects 适配层**。
4
+
5
+ ## 职责
6
+
7
+ 把平台无关的内核装配到 Cloudflare 上:
8
+
9
+ - `createRuntime()`:返回 `VultroDO` / `VultroSyncDO` / Worker 三件套;
10
+ - `defineWorker()`:更高层的组合入口(一次返回 DO + RPC entrypoint + Worker);
11
+ - `defineConfig()`(`@vultro/runtime-cf/config`):恒等函数,仅提供 `VultroConfig`
12
+ 类型;真正的默认值 / 运行时预设 / 路径归一化由 `resolveVultroConfig()`
13
+ 完成(参考 Nitro 的 `defineConfig` + `loadOptions` 设计);Cloudflare 分支
14
+ 注入绑定并生成不依赖 `src/index.ts` 模板的 Worker 入口;
15
+ - `createRuntimeWorker()`:Worker 路由(HTTP API 转发、WebSocket 按 shard 转发);
16
+ - `createSyncCoordinatorDO()`:`global-auto` 拓扑的 shard 协调器;
17
+ - `isolated.ts`:isolated UDF 执行(UDF 跑在独立 Worker,经 RPC 访问数据服务)。
18
+
19
+ ## 为什么不放在 core
20
+
21
+ `packages/core` 不允许出现任何 `cloudflare:*` 导入或 Durable Object 专属类型,
22
+ 这样 Bun 运行时才能复用同一份内核。Cloudflare 的 `WebSocketPair`、DO alarm、
23
+ `DurableObjectNamespace` 等只在本包里出现。
24
+
25
+ ## 同步逻辑在哪
26
+
27
+ **不在这里。** 订阅 / 广播 / 认证协议全部在 `@vultro/core` 的 `SyncEngine` 里,
28
+ 本包的 `VultroSyncDO` 只是把 `WebSocketPair` 握手和 DO alarm 接到引擎上。
29
+ 这样 CF 与 Bun 的协议行为天然一致。
@@ -0,0 +1,14 @@
1
+ /**
2
+ * ============================================================================
3
+ * @vultro/runtime-cf/config
4
+ * ============================================================================
5
+ *
6
+ * `vultro.config.ts` 的 `defineConfig` 与 resolver 现在放在
7
+ * `@vultro/core/config`:它是纯数据 / 路径归一化逻辑,不依赖任何 Cloudflare
8
+ * 运行时能力。放在 core 后,`@vultro/vite-plugin` 不需要为了读取配置而
9
+ * 依赖整个 Cloudflare 适配层。
10
+ *
11
+ * 这个入口保留给应用代码(`apps/play/vultro.config.ts` 等)使用,
12
+ * 避免破坏已有的 `import { defineConfig } from "@vultro/runtime-cf/config"`。
13
+ */
14
+ export * from "@vultro/core/config";
package/dist/config.js ADDED
@@ -0,0 +1 @@
1
+ export * from "@vultro/core/config";
@@ -0,0 +1,119 @@
1
+ /**
2
+ * ============================================================================
3
+ * defineWorker 组合 API
4
+ * ============================================================================
5
+ *
6
+ * 一次返回 Worker 需要的 Durable Object 类、RPC entrypoints、默认导出
7
+ * worker、运行时清单以及 Wrangler 绑定检查。
8
+ *
9
+ * 命名上没有沿用 `@concavejs/runtime-cf` 的 `defineConcave`——本项目不依赖
10
+ * 它,公开 API 不应该借用别人的品牌名。
11
+ *
12
+ * ```ts
13
+ * import { WorkerEntrypoint } from "cloudflare:workers";
14
+ * import { defineWorker } from "@vultro/runtime-cf";
15
+ *
16
+ * const composition = defineWorker({
17
+ * schema,
18
+ * modules: { messages },
19
+ * workerEntrypointBase: WorkerEntrypoint,
20
+ * });
21
+ *
22
+ * export const {
23
+ * RuntimeDO, SyncDO,
24
+ * UdfExecutorRpc, DataService, SyncTransportRpc,
25
+ * } = worker;
26
+ * export default composition.worker;
27
+ * ```
28
+ */
29
+ import { createRuntime } from "./durable-objects.js";
30
+ import { createDataServiceRpc, createSyncTransportRpc, createUdfExecutorRpc, type RpcEntrypointBase } from "./rpc.js";
31
+ import { createSyncCoordinatorDO } from "./sync-coordinator.js";
32
+ import { createIsolatedUdfExecutor } from "./isolated.js";
33
+ type RuntimeOptions = Parameters<typeof createRuntime>[0];
34
+ export interface DefineWorkerOptions extends RuntimeOptions {
35
+ /** 生产环境传 `WorkerEntrypoint`;测试环境可省略。 */
36
+ workerEntrypointBase?: RpcEntrypointBase;
37
+ /** 自定义 DO binding 名称。 */
38
+ bindings?: {
39
+ runtimeDO?: string;
40
+ syncDO?: string;
41
+ };
42
+ /** 是否在 wrangler() 中声明 RPC service entrypoints。默认 true。 */
43
+ rpc?: boolean;
44
+ /** UDF 执行策略;isolated 需要 UDF_WORKER / DATA_SERVICE。 */
45
+ execution?: "inline" | "isolated";
46
+ }
47
+ export interface RequiredBinding {
48
+ binding: string;
49
+ type: "durable_object" | "d1" | "r2" | "vectorize" | "service" | "kv";
50
+ wranglerSection: string;
51
+ className?: string;
52
+ }
53
+ export interface WranglerFragment {
54
+ compatibility_flags: string[];
55
+ durable_objects: {
56
+ bindings: Array<{
57
+ name: string;
58
+ class_name: string;
59
+ }>;
60
+ };
61
+ migrations: Array<{
62
+ tag: string;
63
+ new_sqlite_classes: string[];
64
+ }>;
65
+ d1_databases?: Array<{
66
+ binding: string;
67
+ database_name: string;
68
+ database_id: string;
69
+ }>;
70
+ r2_buckets?: Array<{
71
+ binding: string;
72
+ bucket_name: string;
73
+ }>;
74
+ vectorize?: Array<{
75
+ binding: string;
76
+ index_name: string;
77
+ }>;
78
+ services?: Array<{
79
+ binding: string;
80
+ service: string;
81
+ entrypoint: string;
82
+ }>;
83
+ kv_namespaces?: Array<{
84
+ binding: string;
85
+ id: string;
86
+ }>;
87
+ }
88
+ export interface WorkerComposition {
89
+ RuntimeDO: ReturnType<typeof createRuntime>["VultroDO"];
90
+ SyncDO: ReturnType<typeof createRuntime>["VultroSyncDO"];
91
+ SyncCoordinatorDO: ReturnType<typeof createSyncCoordinatorDO>;
92
+ UdfExecutorRpc: ReturnType<typeof createUdfExecutorRpc> | ReturnType<typeof createIsolatedUdfExecutor>;
93
+ DataService: ReturnType<typeof createDataServiceRpc>;
94
+ SyncTransportRpc: ReturnType<typeof createSyncTransportRpc>;
95
+ worker: ReturnType<typeof createRuntime>["worker"];
96
+ runtime: {
97
+ version: 1;
98
+ execution: {
99
+ strategy: "inline" | "isolated";
100
+ };
101
+ storage: {
102
+ docstore: string;
103
+ blobstore: string | false;
104
+ search: "local";
105
+ vecstore: string | false;
106
+ reads: "primary";
107
+ };
108
+ sync: {
109
+ topology: string;
110
+ shards: number;
111
+ };
112
+ };
113
+ requiredBindings: RequiredBinding[];
114
+ wrangler(): WranglerFragment;
115
+ checkWrangler(config: unknown): string[];
116
+ }
117
+ /** 组合一个完整的 Vultro Worker。 */
118
+ export declare function defineWorker(options: DefineWorkerOptions): WorkerComposition;
119
+ export {};
package/dist/define.js ADDED
@@ -0,0 +1,218 @@
1
+ import { createRuntime } from "./durable-objects.js";
2
+ import { createDataServiceRpc, createSyncTransportRpc, createUdfExecutorRpc } from "./rpc.js";
3
+ import { createSyncCoordinatorDO } from "./sync-coordinator.js";
4
+ import { createIsolatedUdfExecutor } from "./isolated.js";
5
+ import { readSchema } from "@vultro/core";
6
+ // src/define.ts
7
+ /**
8
+ * ============================================================================
9
+ * defineWorker 组合 API
10
+ * ============================================================================
11
+ *
12
+ * 一次返回 Worker 需要的 Durable Object 类、RPC entrypoints、默认导出
13
+ * worker、运行时清单以及 Wrangler 绑定检查。
14
+ *
15
+ * 命名上没有沿用 `@concavejs/runtime-cf` 的 `defineConcave`——本项目不依赖
16
+ * 它,公开 API 不应该借用别人的品牌名。
17
+ *
18
+ * ```ts
19
+ * import { WorkerEntrypoint } from "cloudflare:workers";
20
+ * import { defineWorker } from "@vultro/runtime-cf";
21
+ *
22
+ * const composition = defineWorker({
23
+ * schema,
24
+ * modules: { messages },
25
+ * workerEntrypointBase: WorkerEntrypoint,
26
+ * });
27
+ *
28
+ * export const {
29
+ * RuntimeDO, SyncDO,
30
+ * UdfExecutorRpc, DataService, SyncTransportRpc,
31
+ * } = worker;
32
+ * export default composition.worker;
33
+ * ```
34
+ */
35
+ function requiredBindings(options) {
36
+ const doBinding = options.bindings?.runtimeDO ?? "VULTRO_DO";
37
+ const syncBinding = options.bindings?.syncDO ?? "VULTRO_SYNC_DO";
38
+ const bindings = [{
39
+ binding: doBinding,
40
+ type: "durable_object",
41
+ wranglerSection: "durable_objects.bindings",
42
+ className: "VultroDO"
43
+ }, {
44
+ binding: syncBinding,
45
+ type: "durable_object",
46
+ wranglerSection: "durable_objects.bindings",
47
+ className: "VultroSyncDO"
48
+ }];
49
+ const docstore = options.docstore ?? "sqlite";
50
+ if (docstore === "d1" || docstore === "sharded") {
51
+ const count = options.d1ShardCount ?? 0;
52
+ if (docstore === "sharded" && count > 0) for (let index = 0; index < count; index++) bindings.push({
53
+ binding: `VULTRO_D1_${index}`,
54
+ type: "d1",
55
+ wranglerSection: "d1_databases"
56
+ });
57
+ else bindings.push({
58
+ binding: "VULTRO_D1",
59
+ type: "d1",
60
+ wranglerSection: "d1_databases"
61
+ });
62
+ }
63
+ if (options.r2) bindings.push({
64
+ binding: "VULTRO_R2",
65
+ type: "r2",
66
+ wranglerSection: "r2_buckets"
67
+ });
68
+ if (options.vectorize) bindings.push({
69
+ binding: "VULTRO_VECTORIZE",
70
+ type: "vectorize",
71
+ wranglerSection: "vectorize"
72
+ });
73
+ if ((options.sync?.topology ?? "single") === "global-auto") bindings.push({
74
+ binding: "VULTRO_SYNC_COORDINATOR",
75
+ type: "durable_object",
76
+ wranglerSection: "durable_objects.bindings",
77
+ className: "VultroSyncCoordinatorDO"
78
+ }, {
79
+ binding: "VULTRO_SYNC_SHARD_MAP",
80
+ type: "kv",
81
+ wranglerSection: "kv_namespaces"
82
+ });
83
+ if (options.rpc !== false || options.execution === "isolated") {
84
+ const existing = new Set(bindings.map((binding) => binding.binding));
85
+ for (const [binding, entrypoint] of [
86
+ ["UDF_WORKER", "UdfExecutorRpc"],
87
+ ["DATA_SERVICE", "DataService"],
88
+ ["SYNC_TRANSPORT", "SyncTransportRpc"]
89
+ ]) {
90
+ if (existing.has(binding)) continue;
91
+ bindings.push({
92
+ binding,
93
+ type: "service",
94
+ wranglerSection: "services"
95
+ });
96
+ }
97
+ }
98
+ return bindings;
99
+ }
100
+ function wranglerFragment(bindings) {
101
+ const fragment = {
102
+ compatibility_flags: ["nodejs_compat"],
103
+ durable_objects: { bindings: [] },
104
+ migrations: [{
105
+ tag: "v1",
106
+ new_sqlite_classes: [
107
+ "VultroDO",
108
+ "VultroSyncDO",
109
+ ...bindings.some((binding) => binding.className === "VultroSyncCoordinatorDO") ? ["VultroSyncCoordinatorDO"] : []
110
+ ]
111
+ }]
112
+ };
113
+ for (const binding of bindings) if (binding.type === "durable_object") fragment.durable_objects.bindings.push({
114
+ name: binding.binding,
115
+ class_name: binding.className ?? "VultroDO"
116
+ });
117
+ else if (binding.type === "d1") {
118
+ fragment.d1_databases ??= [];
119
+ fragment.d1_databases.push({
120
+ binding: binding.binding,
121
+ database_name: `${binding.binding.toLowerCase()}-db`,
122
+ database_id: "replace-with-database-id"
123
+ });
124
+ } else if (binding.type === "r2") {
125
+ fragment.r2_buckets ??= [];
126
+ fragment.r2_buckets.push({
127
+ binding: binding.binding,
128
+ bucket_name: "replace-with-bucket-name"
129
+ });
130
+ } else if (binding.type === "vectorize") {
131
+ fragment.vectorize ??= [];
132
+ fragment.vectorize.push({
133
+ binding: binding.binding,
134
+ index_name: "replace-with-index-name"
135
+ });
136
+ } else if (binding.type === "service") {
137
+ fragment.services ??= [];
138
+ fragment.services.push({
139
+ binding: binding.binding,
140
+ service: "your-worker",
141
+ entrypoint: binding.binding === "UDF_WORKER" ? "UdfExecutorRpc" : binding.binding === "DATA_SERVICE" ? "DataService" : binding.binding === "SYNC_TRANSPORT" ? "SyncTransportRpc" : "default"
142
+ });
143
+ } else if (binding.type === "kv") {
144
+ fragment.kv_namespaces ??= [];
145
+ fragment.kv_namespaces.push({
146
+ binding: binding.binding,
147
+ id: "replace-with-kv-namespace-id"
148
+ });
149
+ }
150
+ return fragment;
151
+ }
152
+ function bindingNames(config, path) {
153
+ let value = config;
154
+ for (const part of path.split(".")) {
155
+ if (!value || typeof value !== "object") return /* @__PURE__ */ new Set();
156
+ value = value[part];
157
+ }
158
+ if (!Array.isArray(value) && value && typeof value === "object") value = value.bindings;
159
+ if (!Array.isArray(value)) return /* @__PURE__ */ new Set();
160
+ return new Set(value.map((entry) => entry && typeof entry === "object" ? entry.binding ?? entry.name : void 0).filter((name) => typeof name === "string"));
161
+ }
162
+ /** 组合一个完整的 Vultro Worker。 */
163
+ function defineWorker(options) {
164
+ const composition = createRuntime(options);
165
+ const rpcOptions = {
166
+ workerEntrypointBase: options.workerEntrypointBase,
167
+ bindings: options.bindings
168
+ };
169
+ const SyncCoordinatorDO = createSyncCoordinatorDO({
170
+ instance: "global",
171
+ regions: options.sync?.regions,
172
+ shardsPerRegion: options.sync?.shardsPerRegion,
173
+ targetConnectionsPerShard: options.sync?.targetConnectionsPerShard
174
+ });
175
+ const normalizedSchema = options.schema && typeof options.schema === "object" && "tables" in options.schema && options.schema.tables instanceof Map ? options.schema : readSchema(options.schema);
176
+ const UdfExecutorRpc = options.execution === "isolated" ? createIsolatedUdfExecutor({
177
+ schema: normalizedSchema,
178
+ modules: options.modules,
179
+ workerEntrypointBase: options.workerEntrypointBase
180
+ }) : createUdfExecutorRpc(rpcOptions);
181
+ const DataService = createDataServiceRpc(rpcOptions);
182
+ const SyncTransportRpc = createSyncTransportRpc(rpcOptions);
183
+ const bindings = requiredBindings(options);
184
+ const docstore = options.docstore ?? "sqlite";
185
+ const syncShards = options.sync?.shards ?? 1;
186
+ return {
187
+ RuntimeDO: composition.VultroDO,
188
+ SyncDO: composition.VultroSyncDO,
189
+ SyncCoordinatorDO,
190
+ UdfExecutorRpc,
191
+ DataService,
192
+ SyncTransportRpc,
193
+ worker: composition.worker,
194
+ runtime: {
195
+ version: 1,
196
+ execution: { strategy: options.execution ?? "inline" },
197
+ storage: {
198
+ docstore,
199
+ blobstore: options.blobs?.kind ?? (options.r2 ? "r2" : false),
200
+ search: "local",
201
+ vecstore: options.vectorize ? "vectorize" : "local",
202
+ reads: "primary"
203
+ },
204
+ sync: {
205
+ topology: options.sync?.topology ?? (syncShards > 1 ? "global-manual" : "single"),
206
+ shards: syncShards
207
+ }
208
+ },
209
+ requiredBindings: bindings,
210
+ wrangler: () => wranglerFragment(bindings),
211
+ checkWrangler: (config) => {
212
+ const messages = [];
213
+ for (const binding of bindings) if (!bindingNames(config, binding.wranglerSection).has(binding.binding)) messages.push(`Missing ${binding.type} binding "${binding.binding}" (${binding.wranglerSection})`);
214
+ return messages;
215
+ }
216
+ };
217
+ }
218
+ export { defineWorker };
@@ -0,0 +1,175 @@
1
+ import { createRuntimeWorker } from "./worker.js";
2
+ import type { DurableObjectStateLike, RuntimeEnv } from "./platform.js";
3
+ import { type VectorizeIndexLike } from "@vultro/core";
4
+ import { type ComponentDefinitionInput } from "@vultro/core";
5
+ import "@vultro/docstore-sqlite/runtime";
6
+ import type { PostgresClientLike } from "@vultro/core";
7
+ import type { MysqlClientLike } from "@vultro/core";
8
+ import { type SyncRegionHint } from "@vultro/core";
9
+ import type { BlobStore, StorageFactory } from "@vultro/core/storage";
10
+ import type { DocStoreBackend } from "@vultro/core/docstore";
11
+ import type { R2StorageOptions } from "@vultro/storage-r2";
12
+ import { type D1DatabaseLike } from "@vultro/core";
13
+ /**
14
+ * ============================================================================
15
+ * Cloudflare Durable Object 实现
16
+ * ============================================================================
17
+ *
18
+ * 整体结构(与 Concave 的 Cloudflare 部署拓扑一致):
19
+ *
20
+ * 浏览器 / Convex 客户端
21
+ * │
22
+ * ├── /api/query|mutation|action ──► VultroDO(事务 + 存储)
23
+ * │
24
+ * └── /api/<version>/sync (WS) ────► VultroSyncDO(订阅 + 广播)
25
+ * │
26
+ * └── 内部 query 调用 VultroDO
27
+ *
28
+ * VultroDO:
29
+ * - 真正的“事务器”,所有写入都经过它串行提交;
30
+ * - 持有 DocumentStore 与函数运行时;
31
+ * - 提交后通过 `onCommit` 通知 VultroSyncDO。
32
+ *
33
+ * VultroSyncDO:
34
+ * - 管理 WebSocket 连接、每个连接的 query 集合与同步版本;
35
+ * - 收到提交通知后重新执行订阅 query,向客户端推送 Transition;
36
+ * - 客户端通过 WebSocket 发起的 mutation/action 也由它转发给 VultroDO。
37
+ */
38
+ interface VultroDOOptions {
39
+ schema?: unknown;
40
+ modules: Record<string, unknown>;
41
+ /**
42
+ * deployment 的公开地址,用于存储 URL / 上传 URL。
43
+ * 未配置时读取 `VULTRO_DEPLOYMENT_URL`,再退化为相对路径。
44
+ */
45
+ deploymentUrl?: string;
46
+ /**
47
+ * 给 Worker 的所有路由加统一前缀,例如 `"/v"`。
48
+ *
49
+ * 只在 **Worker 的 handler 层**剥离前缀再转发,内核(HTTP API、同步
50
+ * 协议、`/_storage/*`)看到的仍然是原来的路径——所以 Convex 客户端的
51
+ * 请求格式、上传 / 下载 URL、系统 UDF 都不需要任何改动。
52
+ *
53
+ * 用途:同一域名下挂多个 deployment / 与其他服务共用一个 Worker。
54
+ *
55
+ * 配了之后 `ctx.storage.getUrl()` / `generateUploadUrl()` 返回的地址会
56
+ * 自动带上前缀,应用不需要手动拼接。
57
+ */
58
+ prefix?: string;
59
+ /** 挂载的 Convex components(显式传入 schema + modules)。 */
60
+ components?: Record<string, ComponentDefinitionInput>;
61
+ /**
62
+ * 文件存储工厂;通常由配置里的 `storage: r2Storage()` 生成入口注入。
63
+ * 省略时默认 DO SQLite / D1 + R2。
64
+ */
65
+ storage?: StorageFactory;
66
+ /**
67
+ * 文件字节后端(任意 `BlobStore`,例如 S3)。
68
+ *
69
+ * 与 `r2` 二选一,优先使用 `blobs`。Cloudflare 上通常直接用 R2;
70
+ * 需要把文件写到外部 S3 时传这个。
71
+ */
72
+ blobs?: BlobStore;
73
+ /** R2 文件内容后端;未配置时读取 `VULTRO_R2` 绑定。 */
74
+ r2?: R2StorageOptions;
75
+ /** D1 deployment 持久化;未配置时读取 `VULTRO_D1` 绑定。 */
76
+ d1?: {
77
+ database: D1DatabaseLike;
78
+ key?: string;
79
+ };
80
+ /** sharded docstore 的 D1 数据库列表;也可通过 VULTRO_D1_SHARD_COUNT 推导。 */
81
+ d1Shards?: D1DatabaseLike[];
82
+ /** sharded docstore 的 shard 数量;绑定名为 VULTRO_D1_0..N-1。 */
83
+ d1ShardCount?: number;
84
+ /** Postgres 文档存储 client(由应用 / 自定义入口注入)。 */
85
+ postgres?: {
86
+ client?: PostgresClientLike;
87
+ createClient?: (env: RuntimeEnv) => PostgresClientLike;
88
+ };
89
+ /** MySQL 文档存储 client(由应用 / 自定义入口注入)。 */
90
+ mysql?: {
91
+ client?: MysqlClientLike;
92
+ createClient?: (env: RuntimeEnv) => MysqlClientLike;
93
+ };
94
+ /**
95
+ * 文档存储后端:`sqlite`(默认)或 `d1`。
96
+ *
97
+ * `d1` 模式把文档直接保存在 D1(内存读缓存 + 异步批量写),不再写穿
98
+ * deployment 快照;scheduler / storage 仍使用 DO SQLite。
99
+ */
100
+ docstore?: "sqlite" | "d1" | "sharded" | "postgres" | "mysql";
101
+ /** 文档存储后端包选择器;提供后优先于 `docstore` / `storeFactory`。 */
102
+ docStore?: DocStoreBackend;
103
+ /** SyncDO 分片 / 区域亲和配置。 */
104
+ sync?: {
105
+ shards?: number;
106
+ regions?: SyncRegionHint[];
107
+ /** `single` / `global-auto`;global-auto 需要 Coordinator + shard-map KV。 */
108
+ topology?: "single" | "global-auto";
109
+ shardsPerRegion?: number;
110
+ targetConnectionsPerShard?: number;
111
+ countryMap?: Record<string, string>;
112
+ regionMap?: Record<string, string>;
113
+ defaultRegion?: string;
114
+ useColoAsRegion?: boolean;
115
+ };
116
+ /** 外部 Cloudflare Vectorize;未配置时读取 VULTRO_VECTORIZE 绑定。 */
117
+ vectorize?: {
118
+ index: VectorizeIndexLike;
119
+ namespace?: string;
120
+ };
121
+ /** 自定义域名验证 / 绑定的 Cloudflare 配置;默认读取 VULTRO_CLOUDFLARE_*。 */
122
+ cloudflare?: {
123
+ apiToken?: string;
124
+ accountId?: string;
125
+ zoneId?: string;
126
+ workerName?: string;
127
+ databaseId?: string;
128
+ aiGatewayId?: string;
129
+ apiBase?: string;
130
+ };
131
+ /** 云团队 / 账单端点;默认读取 VULTRO_CLOUD_*。 */
132
+ cloudAccount?: {
133
+ teamName?: string;
134
+ projectName?: string;
135
+ billingUrl?: string;
136
+ apiToken?: string;
137
+ };
138
+ /** JWT 校验配置;未配置时 ctx.auth.getUserIdentity() 返回 null。 */
139
+ auth?: {
140
+ jwksUri?: string;
141
+ domain?: string;
142
+ issuer?: string;
143
+ audience?: string | string[];
144
+ };
145
+ }
146
+ /**
147
+ * createRuntime 返回的 Durable Object 构造函数契约。
148
+ *
149
+ * 匿名 class 的私有字段不能出现在 `.d.ts` 中(TS4094);对外只需要
150
+ * `fetch`,因此用显式接口描述构造签名与公开方法。
151
+ */
152
+ export interface VultroDurableObjectClass {
153
+ new (state: DurableObjectStateLike, env: RuntimeEnv): {
154
+ fetch(request: Request): Promise<Response>;
155
+ };
156
+ }
157
+ /** createRuntime 的返回结构:两个 DO 类与默认 Worker handler。 */
158
+ export interface VultroRuntime {
159
+ VultroDO: VultroDurableObjectClass;
160
+ VultroSyncDO: VultroDurableObjectClass;
161
+ worker: ReturnType<typeof createRuntimeWorker>;
162
+ }
163
+ /**
164
+ * 创建一个完整的 Cloudflare 运行时组合。
165
+ *
166
+ * 返回值可以直接用于 Worker 入口:
167
+ *
168
+ * ```ts
169
+ * const runtime = createRuntime({ schema, modules: { messages } });
170
+ * export const { VultroDO, VultroSyncDO } = runtime;
171
+ * export default runtime.worker;
172
+ * ```
173
+ */
174
+ export declare function createRuntime(options: VultroDOOptions): VultroRuntime;
175
+ export {};