-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalchemy.run.ts
More file actions
111 lines (96 loc) · 2.71 KB
/
alchemy.run.ts
File metadata and controls
111 lines (96 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import alchemy from "alchemy";
import {
SvelteKit,
Worker,
D1Database,
KVNamespace,
WorkerLoader,
Ai,
Self,
R2Bucket,
DurableObjectNamespace,
} from "alchemy/cloudflare";
import { CloudflareStateStore, FileSystemStateStore } from "alchemy/state";
const projectName = "lab";
const project = await alchemy(projectName, {
password: process.env.ALCHEMY_PASSWORD!,
stateStore: (scope) => scope.local
? new FileSystemStateStore(scope)
: new CloudflareStateStore(scope, {
scriptName: `${projectName}-app-state`,
apiToken: alchemy.secret(process.env.CLOUDFLARE_API_TOKEN || ""),
stateToken: alchemy.secret(process.env.ALCHEMY_STATE_TOKEN || ""),
forceUpdate: true
})
});
// KV namespace for traces + demo data
const KV = await KVNamespace(`${projectName}-kv`);
// D1 database for Better Auth
const DB = await D1Database(`${projectName}-db`, {
name: `${projectName}-db`,
migrationsDir: "migrations",
adopt: true,
});
// Engine D1 for guest read demos (isolate worker only)
const ENGINE_D1 = await D1Database(`${projectName}-engine-d1`, {
name: `${projectName}-engine-d1`,
migrationsDir: "worker/d1-migrations",
adopt: true,
});
const R2 = await R2Bucket(`${projectName}-r2`);
const LAB_DO = DurableObjectNamespace("lab-stub-do", {
className: "LabStubDurableObject",
sqlite: true,
});
// Petri Dish Durable Object for persistent experiment substrate
const PETRI_DO = DurableObjectNamespace("petri-dish", {
className: "PetriDish",
});
// Worker Loader for V8 isolate creation
const LOADER = WorkerLoader();
// Workers AI binding
const AI = Ai();
// Lab isolate engine worker
// SELF binding lets the worker call itself for spawn/child routes
export const WORKER = await Worker(`${projectName}-worker`, {
entrypoint: "./worker/index.ts",
adopt: true,
compatibilityDate: "2025-06-01",
compatibilityFlags: ["nodejs_compat"],
bindings: {
LOADER,
KV,
AI,
SELF: Self,
R2,
ENGINE_D1,
LAB_DO,
PETRI_DO,
},
url: false,
// Same port as SvelteKit dev proxy (`data.remote.ts`) and `@acoyfellow/lab` local dogfood (`LAB_URL`).
dev: {
port: 1337,
},
});
// SvelteKit app
export const APP = await SvelteKit(`${projectName}-app`, {
bindings: {
WORKER,
DB,
KV,
},
url: true,
adopt: true,
env: {
BETTER_AUTH_SECRET: (() => {
const secret = process.env.BETTER_AUTH_SECRET;
if (!secret) throw new Error("BETTER_AUTH_SECRET environment variable is required for deployment");
return secret;
})(),
BETTER_AUTH_URL: process.env.BETTER_AUTH_URL || "http://localhost:5173",
GH_CLIENT_ID: process.env.GH_CLIENT_ID || "",
GH_CLIENT_SECRET: process.env.GH_CLIENT_SECRET || "",
}
});
await project.finalize();