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

main
ts 37 lines 1.34 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
5 /**
6 * Container that mounts a FUSE filesystem at boot and serves a file read
7 * through the mount (see `context/start.sh`).
8 */
9 class FuseContainer extends Cloudflare.Container<FuseContainer>()("FuseContainer", {
10 // Template string, not `path.join(import.meta.dirname, …)`: this module is
11 // bundled into the Worker and `import.meta.dirname` is undefined there.
12 context: `${import.meta.dirname}/context`,
13 observability: { logs: { enabled: true } },
14 }) {}
15
16 /** Durable Object that starts the {@link FuseContainer} and reads its page. */
17 export class FuseContainerObject extends Cloudflare.DurableObject<FuseContainerObject>()(
18 "FuseContainerObject",
19 Effect.gen(function* () {
20 const container = yield* FuseContainer;
21
22 return Effect.gen(function* () {
23 // Starting is idempotent: a no-op once the container is running.
24 const start = container.start();
25 const { fetch } = yield* container.getTcpPort(8080);
26
27 return {
28 read: () =>
29 Effect.gen(function* () {
30 yield* start;
31 const response = yield* fetch(HttpClientRequest.get("http://container/"));
32 return yield* response.text;
33 }),
34 };
35 });
36 }),
37 ) {}