Repository navigation
Expand file tree
/
Copy pathalchemy.run.ts
More file actions
73 lines (66 loc) · 2.76 KB
/
Copy pathalchemy.run.ts
File metadata and controls
73 lines (66 loc) · 2.76 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
import * as Alchemy from "alchemy";
import { adopt } from "alchemy/AdoptPolicy";
import * as Cloudflare from "alchemy/Cloudflare";
import { Config, Effect, Layer } from "effect";
// Deploys run against the account-wide Cloudflare state store so CI runs
// share one state history; ALCHEMY_LOCAL_STATE=true keeps dry runs and local
// experiments out of it. Alchemy's `state` option requires an infallible
// Layer (`Layer<State, never, StackServices>`), so a malformed flag cannot
// stay typed past this boundary: it fails closed as a defect that names the
// flag and the accepted values instead of silently picking a state store.
const state = Layer.unwrap(
Effect.gen(function* () {
const useLocalState = yield* Config.Boolean("ALCHEMY_LOCAL_STATE").pipe(
Config.withDefault(false),
);
return useLocalState ? Alchemy.localState() : Cloudflare.state();
}).pipe(
Effect.mapError(
(error) =>
new Error(
`ALCHEMY_LOCAL_STATE must be a boolean (true/false); refusing to guess a state store: ${String(error)}`,
),
),
Effect.orDie,
),
);
const docsAssets = {
base: "/agent/",
notFoundHandling: "404-page",
} satisfies Omit<Cloudflare.Workers.AssetsProps, "directory">;
const stack = Effect.gen(function* () {
yield* Cloudflare.Website.StaticSite("Docs", {
name: "effect-agent-docs",
command: "vp run docs:build",
outdir: "docs/dist",
domain: {
name: "effect-agent.com",
aliases: ["www.effect-agent.com"],
zoneName: "effect-agent.com",
},
routes: [{ pattern: "yielded.dev/agent*", zoneName: "yielded.dev" }],
workersDev: false,
dev: { command: "vp run docs:dev" },
// Astro emits directory indexes and 404.html. HTML handling keeps the
// /agent prefix. The Worker runs first so it can 301 the legacy hosts,
// permanently redirect the site root onto /agent/, and serve the
// not-found document with status 404.
main: "./docs/worker.ts",
assets: {
...docsAssets,
runWorkerFirst: true,
},
// The dist and cache directories are gitignored, so hashing docs/**
// rebuilds exactly when a source page or the site config changes;
// package.json is included because it owns the docs:build script.
memo: { include: ["docs/**", "package.json"], lockfile: true },
});
// Adopted so this stack does not create or delete the zone. The dynamic
// redirect entrypoint is gone: regex_replace is not entitled here, and a
// zone rule would run before the Worker. The Worker issues the legacy 301.
yield* Cloudflare.Zone.Zone("LegacyDocsZone", {
name: "effect-agent.com",
}).pipe(adopt());
return { url: "https://yielded.dev/agent/" };
});
export default Alchemy.Stack("effect-agent", { providers: Cloudflare.providers(), state }, stack);