The best way to control Claude Code, Codex and more from any computer or phone

main
ts 47 lines 1.77 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Git from "@alchemy.run/git";
3 /** The application's HTTP routes: our API and Git, with shared authentication. */
4 import * as Http from "alchemy/Http";
5 import * as Effect from "effect/Effect";
6 import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
7 import * as Layer from "effect/Layer";
8 import { AppApi, MeLive } from "./api.ts";
9 import { GitHubLive } from "./github.ts";
10 import { Authentication } from "./middleware.ts";
11 import { ProtocolLive } from "./protocol.ts";
12 import { RefsLive, PullsLive } from "./ref-writes.ts";
13
14 /** Packs, clone bundles, and spilled pushes. */
15 export const GitObjects = Cloudflare.R2.Bucket("GitObjects", {
16 // `bun test` sets NODE_ENV=test: the integration test tears the stack
17 // down with repositories still in the bucket.
18 forceDestroy: process.env.NODE_ENV === "test",
19 });
20
21 const PublicRoutes = HttpApiBuilder.layer(AppApi).pipe(
22 Layer.provide(
23 Layer.mergeAll(
24 MeLive,
25 ProtocolLive,
26 RefsLive,
27 PullsLive,
28 GitHubLive,
29 HttpApiBuilder.group(AppApi, "repos", (h) =>
30 Effect.map(Git.Handlers, (defaults) => h.handleAll(defaults.repos)),
31 ),
32 HttpApiBuilder.group(AppApi, "objects", (h) =>
33 Effect.map(Git.Handlers, (defaults) => h.handleAll(defaults.objects)),
34 ),
35 ),
36 ),
37 Layer.provide(Authentication.layer),
38 );
39
40 export const HttpLive = Layer.mergeAll(PublicRoutes, Git.InternalApiLive).pipe(
41 Layer.provide(Git.ApiHandlersLive),
42 Layer.provide(Git.ReposDurableObject),
43 Layer.provide(Git.RegistryDurableObject), // owner/name → repo
44 Layer.provide(Git.HasherInline), // push verification in this Worker
45 Layer.provide(Git.BlobStoreR2(GitObjects)), // packs, bundles, large pushes
46 Layer.provide(Http.Platform),
47 );