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

main
ts 27 lines 1.02 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 { RELOAD_CONTAINER_PORT, ReloadContainer } from "./container.ts";
5
6 /** Durable Object fronting {@link ReloadContainer}; proxies `path` into it. */
7 export class ReloadContainerObject extends Cloudflare.DurableObject<ReloadContainerObject>()(
8 "ReloadContainerObject",
9 Effect.gen(function* () {
10 const container = yield* ReloadContainer;
11
12 return Effect.gen(function* () {
13 // Starting is idempotent: a no-op once the container is running.
14 const start = container.start({ enableInternet: false });
15 const { fetch } = yield* container.getTcpPort(RELOAD_CONTAINER_PORT);
16
17 return {
18 read: (path: string) =>
19 Effect.gen(function* () {
20 yield* start;
21 const response = yield* fetch(HttpClientRequest.get(`http://container${path}`));
22 return yield* response.text;
23 }),
24 };
25 });
26 }),
27 ) {}