The best way to control Claude Code, Codex and more from any computer or phone

main
ts 43 lines 1.5 KB
Raw
1 import { fileURLToPath } from "node:url";
2 import * as Cloudflare from "@alchemy.run/cloudflare";
3 import { adopt } from "alchemy/AdoptPolicy";
4 import * as Effect from "effect/Effect";
5
6 const workerMain = fileURLToPath(new URL("./worker.ts", import.meta.url));
7
8 export const applications = (maxInstances = 2, name?: string) =>
9 Effect.gen(function* () {
10 const owned = yield* Cloudflare.Container("CachedIdentity", {
11 name,
12 image: "mendhak/http-https-echo:41",
13 maxInstances,
14 }).Application;
15 const other = yield* Cloudflare.Container("OtherIdentity", {
16 image: "mendhak/http-https-echo:41",
17 maxInstances: 3,
18 }).Application;
19 return { owned, other };
20 });
21
22 /**
23 * An application and a Worker that reference each other, so the application
24 * is precreated. The Worker's name keeps the application's props unresolved.
25 */
26 export const cyclicApplication = (name: string, scoped?: boolean) =>
27 Effect.gen(function* () {
28 const worker = yield* Cloudflare.Worker("CyclicWorker", {
29 main: workerMain,
30 workersDev: false,
31 });
32 const declaration = Cloudflare.Container("CyclicDifferent", {
33 name,
34 image: "mendhak/http-https-echo:41",
35 maxInstances: 1,
36 env: { WORKER_NAME: worker.workerName },
37 }).Application;
38 const app = yield* scoped === undefined ? declaration : declaration.pipe(adopt(scoped));
39 yield* worker.bind`APP_NAME`({
40 bindings: [{ type: "plain_text", name: "APP_NAME", text: app.applicationName }],
41 });
42 return app;
43 });