The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
| 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 { IsolatedContainer } from "./container.ts"; |
| 5 | |
| 6 | /** Durable Object backing one {@link IsolatedContainer} instance. */ |
| 7 | export class IsolatedObject extends Cloudflare.DurableObject<IsolatedObject>()( |
| 8 | "IsolatedProjectObject", |
| 9 | Effect.gen(function* () { |
| 10 | const container = yield* IsolatedContainer; |
| 11 | |
| 12 | return Effect.gen(function* () { |
| 13 | // Starting is idempotent: a no-op once the container is running. |
| 14 | const start = container.start({ enableInternet: true }); |
| 15 | return { |
| 16 | // RPC into the container (starts it + proves it's up). |
| 17 | ping: () => start.pipe(Effect.andThen(container.ping())), |
| 18 | // HTTP over the container's TCP port. |
| 19 | hello: () => |
| 20 | Effect.gen(function* () { |
| 21 | yield* start; |
| 22 | const { fetch } = yield* container.getTcpPort(3000); |
| 23 | const response = yield* fetch(HttpClientRequest.get("http://container/")); |
| 24 | return yield* response.text; |
| 25 | }).pipe(Effect.orDie), |
| 26 | }; |
| 27 | }); |
| 28 | }), |
| 29 | ) {} |