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 Alchemy from "alchemy"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Path from "effect/Path"; |
| 5 | import type { AttachmentContainerObject } from "./worker.ts"; |
| 6 | |
| 7 | export const stackName = "ContainerAttachmentStack"; |
| 8 | |
| 9 | export const namedStackName = "ContainerNamedAttachmentStack"; |
| 10 | |
| 11 | export const attachmentStack = (attached = true, name?: string) => |
| 12 | Alchemy.Stack( |
| 13 | name === undefined ? stackName : namedStackName, |
| 14 | { providers: Cloudflare.providers(), state: Cloudflare.state() }, |
| 15 | Effect.gen(function* () { |
| 16 | const path = yield* Path.Path; |
| 17 | const container = Cloudflare.Container<AttachmentContainerObject>("AttachmentContainer", { |
| 18 | className: "AttachmentContainerObject", |
| 19 | image: "mendhak/http-https-echo:41", |
| 20 | maxInstances: 2, |
| 21 | name, |
| 22 | }); |
| 23 | const other = Cloudflare.Container<AttachmentContainerObject>("OtherAttachmentContainer", { |
| 24 | className: "AttachmentContainerObject", |
| 25 | image: "mendhak/http-https-echo:41", |
| 26 | maxInstances: 2, |
| 27 | }); |
| 28 | const worker = yield* Cloudflare.Worker("AttachmentWorker", { |
| 29 | main: path.join(import.meta.dirname, attached ? "worker.ts" : "detached-worker.ts"), |
| 30 | env: attached ? { ECHO: container } : {}, |
| 31 | }); |
| 32 | const otherWorker = yield* Cloudflare.Worker("OtherAttachmentWorker", { |
| 33 | main: path.join(import.meta.dirname, "worker.ts"), |
| 34 | env: { ECHO: other }, |
| 35 | }); |
| 36 | const app = yield* container.Application; |
| 37 | const otherApp = yield* other.Application; |
| 38 | return { |
| 39 | worker, |
| 40 | app, |
| 41 | otherWorker, |
| 42 | otherApp, |
| 43 | url: worker.url.as<string>(), |
| 44 | }; |
| 45 | }), |
| 46 | ); |
| 47 | |
| 48 | export default attachmentStack(); |