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 Redacted from "effect/Redacted"; |
| 4 | import { BuildInputs } from "./inputs.ts"; |
| 5 | |
| 6 | /** Built from `context/Dockerfile` with a build arg and a BuildKit secret. */ |
| 7 | export class BuildSecretsImage extends Cloudflare.Container<BuildSecretsImage>()( |
| 8 | "BuildSecretsImage", |
| 9 | Effect.map(BuildInputs, ({ greeting, token }) => ({ |
| 10 | schedulingPolicy: "durable_object" as const, |
| 11 | // A template string, not `path.join(import.meta.dirname, …)`: this module |
| 12 | // is bundled into the Worker, where `import.meta.dirname` is undefined. |
| 13 | context: `${import.meta.dirname}/context`, |
| 14 | build: { |
| 15 | args: { GREETING: greeting }, |
| 16 | secrets: { token: Redacted.make(token) }, |
| 17 | }, |
| 18 | })), |
| 19 | ) {} |
| 20 | |
| 21 | /** Starts {@link BuildSecretsImage} and reads the file its build wrote. */ |
| 22 | export class BuildSecretsObject extends Cloudflare.DurableObject<BuildSecretsObject>()( |
| 23 | "BuildSecretsObject", |
| 24 | Effect.gen(function* () { |
| 25 | const container = yield* BuildSecretsImage; |
| 26 | return Effect.succeed({ |
| 27 | build: Effect.fn(function* () { |
| 28 | if (!(yield* container.running)) { |
| 29 | yield* container.start({ entrypoint: ["sleep", "infinity"], enableInternet: false }); |
| 30 | } |
| 31 | const output = yield* Effect.scoped( |
| 32 | Effect.flatMap(container.exec(["cat", "/build.txt"]), (child) => child.output()), |
| 33 | ); |
| 34 | return new TextDecoder().decode(output.stdout).trim(); |
| 35 | }), |
| 36 | }); |
| 37 | }), |
| 38 | ) {} |