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

main
ts 47 lines 1.73 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import { HttpServerRequest } from "effect/http/HttpServerRequest";
4 import * as HttpServerResponse from "effect/http/HttpServerResponse";
5 import { isolatedProject } from "../../../../IsolatedProject.ts";
6
7 /**
8 * The isolated consumer project this container is bundled from (see
9 * `test/IsolatedProject.ts`): `main` lives outside the repository, so the
10 * bundle `cwd` resolves none of alchemy's dependencies and the container
11 * bootstrap's own imports (`@effect/platform-bun`, `alchemy/*`, …) must be
12 * anchored by the bundler.
13 */
14 export const project = isolatedProject("cloudflare-container", import.meta.filename, [
15 "@alchemy.run/cloudflare",
16 ]);
17
18 /**
19 * Minimal effectful `Cloudflare.Container` served from an isolated project.
20 * `ping` (RPC) and `/hello` (HTTP over the container's port 3000) answering
21 * prove the generated bootstrap booted — with its imports left external bun
22 * dies at module load and the Durable Object's requests never get a reply.
23 */
24 export class IsolatedContainer extends Cloudflare.Container<
25 IsolatedContainer,
26 { ping: () => Effect.Effect<string> }
27 >()("IsolatedProjectContainer") {}
28
29 export default IsolatedContainer.make(
30 {
31 main: project.main,
32 image: "oven/bun:latest",
33 },
34 Effect.gen(function* () {
35 return {
36 ping: () => Effect.succeed("pong"),
37 fetch: Effect.gen(function* () {
38 const request = yield* HttpServerRequest;
39 const url = new URL(request.url, "http://container");
40 if (url.pathname === "/health") {
41 return yield* HttpServerResponse.json({ ok: true });
42 }
43 return HttpServerResponse.text("hello from isolated project");
44 }),
45 };
46 }),
47 );