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, 06:00 UTC
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import { declareDurableObjectApplication } from "@alchemy.run/cloudflare/Containers/DurableObjectApplication"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import type { NativeAsyncObject } from "./async-worker.ts"; |
| 5 | |
| 6 | /** Public half of a key generated once for these tests; the private key was discarded. */ |
| 7 | export const TEST_SSH_PUBLIC_KEY = |
| 8 | "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHyBNPTu6UntBqHyD4LsYK16cRDTf2k+uD10WnuvHYoe alchemy-container-test"; |
| 9 | |
| 10 | export type ApplicationSettings = Pick< |
| 11 | Cloudflare.Containers.DurableObjectContainerProps, |
| 12 | "ssh" | "authorizedKeys" | "observability" |
| 13 | >; |
| 14 | |
| 15 | /** |
| 16 | * Two Containers backing one Durable Object class. Application-wide settings |
| 17 | * may be declared on either one; `tools` declares its own to probe conflicts. |
| 18 | */ |
| 19 | export const settingsStack = ( |
| 20 | settings: ApplicationSettings = {}, |
| 21 | tools: ApplicationSettings = {}, |
| 22 | ) => |
| 23 | Effect.gen(function* () { |
| 24 | const shell = Cloudflare.Container("SettingsShell", { |
| 25 | schedulingPolicy: "durable_object", |
| 26 | image: "alpine:3.21", |
| 27 | ...settings, |
| 28 | }); |
| 29 | const toolbox = Cloudflare.Container("SettingsTools", { |
| 30 | schedulingPolicy: "durable_object", |
| 31 | image: "alpine:3.20", |
| 32 | ...tools, |
| 33 | }); |
| 34 | const worker = yield* Cloudflare.Worker("SettingsWorker", { |
| 35 | main: `${import.meta.dirname}/async-worker.ts`, |
| 36 | env: { |
| 37 | SANDBOX: Cloudflare.DurableObject<NativeAsyncObject>("NativeAsyncObject", { |
| 38 | containers: [shell, toolbox], |
| 39 | }), |
| 40 | IMAGE_REVISION: "settings", |
| 41 | }, |
| 42 | }); |
| 43 | return { |
| 44 | worker, |
| 45 | application: yield* declareDurableObjectApplication(worker, "NativeAsyncObject"), |
| 46 | }; |
| 47 | }); |
| 48 | |
| 49 | /** A container application declared under one logical id with either scheduling policy. */ |
| 50 | export const policyStack = (policy: "default" | "durable_object") => |
| 51 | Effect.gen(function* () { |
| 52 | if (policy === "default") { |
| 53 | return yield* Cloudflare.Container("PolicySwitch", { image: "alpine:3.21" }).Application; |
| 54 | } |
| 55 | return yield* Cloudflare.Container("PolicySwitch", { |
| 56 | schedulingPolicy: "durable_object", |
| 57 | image: "alpine:3.21", |
| 58 | }).Application; |
| 59 | }); |