The best way to control Claude Code, Codex and more from any computer or phone
| 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 | * Local-dev twin of `object.ts` with its own logical ids so |
| 7 | * `LocalContainer.test.ts` never shares a container application, Durable |
| 8 | * Object namespace, or worker with the live `Container.test.ts` deployment |
| 9 | * when the two files run concurrently. |
| 10 | */ |
| 11 | export class LocalRemoteContainer extends Cloudflare.Container<LocalRemoteContainer>()( |
| 12 | "LocalRemoteContainer", |
| 13 | { |
| 14 | image: "mendhak/http-https-echo:latest", |
| 15 | observability: { logs: { enabled: true } }, |
| 16 | }, |
| 17 | ) {} |
| 18 | |
| 19 | /** |
| 20 | * Durable Object that binds and starts the {@link LocalRemoteContainer} and |
| 21 | * proxies an HTTP request to the echo server running on port 8080 inside it. |
| 22 | */ |
| 23 | export class LocalRemoteContainerObject extends Cloudflare.DurableObject<LocalRemoteContainerObject>()( |
| 24 | "LocalRemoteContainerObject", |
| 25 | Effect.gen(function* () { |
| 26 | const container = yield* LocalRemoteContainer; |
| 27 | |
| 28 | return Effect.gen(function* () { |
| 29 | // Starting is idempotent: a no-op once the container is running. |
| 30 | const start = container.start({ enableInternet: true }); |
| 31 | const { fetch } = yield* container.getTcpPort(8080); |
| 32 | |
| 33 | return { |
| 34 | hello: () => |
| 35 | Effect.gen(function* () { |
| 36 | yield* start; |
| 37 | const response = yield* fetch(HttpClientRequest.get("http://container/")); |
| 38 | return yield* response.text; |
| 39 | }), |
| 40 | }; |
| 41 | }); |
| 42 | }), |
| 43 | ) {} |