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

main
ts 43 lines 1.4 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import * as HttpClientRequest from "effect/http/HttpClientRequest";
4 import { PlanetscaleHostRole } from "./db.ts";
5
6 class PlanetscaleHostContainer extends Cloudflare.Container<PlanetscaleHostContainer>()(
7 "PlanetscaleHostContainer",
8 Effect.gen(function* () {
9 const role = yield* PlanetscaleHostRole;
10 return {
11 context: `${import.meta.dirname}/../sqlreach/context`,
12 env: {
13 DATABASE_URL: role.connectionUrlPooled,
14 },
15 observability: { logs: { enabled: true } },
16 };
17 }),
18 ) {}
19
20 export class PlanetscaleHostContainerObject extends Cloudflare.DurableObject<PlanetscaleHostContainerObject>()(
21 "PlanetscaleHostContainerObject",
22 Effect.gen(function* () {
23 const container = yield* PlanetscaleHostContainer;
24
25 return Effect.gen(function* () {
26 // Starting is idempotent: a no-op once the container is running.
27 const start = container.start({ enableInternet: true });
28 const { fetch } = yield* container.getTcpPort(8080);
29
30 const get = (path: string) =>
31 Effect.gen(function* () {
32 yield* start;
33 const response = yield* fetch(HttpClientRequest.get(`http://container${path}`));
34 return yield* response.text;
35 });
36
37 return {
38 getEnv: () => get("/env"),
39 getProbe: () => get("/probe"),
40 };
41 });
42 }),
43 ) {}