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 { HttpServerRequest } from "effect/http/HttpServerRequest"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | import { artifactsReadRoutes } from "./read-routes.ts"; |
| 6 | import { Repos } from "./shared.ts"; |
| 7 | |
| 8 | /** |
| 9 | * Read-only Worker fixture: `Cloudflare.Artifacts.ReadNamespace(Repos)` hands |
| 10 | * out repos as `ReadRepoClient`, which the routes in `read-routes.ts` drive |
| 11 | * through metadata, history and Git object reads. |
| 12 | */ |
| 13 | export default class ArtifactsReadWorker extends Cloudflare.Worker<ArtifactsReadWorker>()( |
| 14 | "ArtifactsReadWorker", |
| 15 | { main: import.meta.url }, |
| 16 | Effect.gen(function* () { |
| 17 | const repos = yield* Repos; |
| 18 | const client = yield* Cloudflare.Artifacts.ReadNamespace(repos); |
| 19 | return { |
| 20 | fetch: Effect.gen(function* () { |
| 21 | const request = yield* HttpServerRequest; |
| 22 | const url = new URL(request.url, "http://x"); |
| 23 | const handled = yield* artifactsReadRoutes(client, url); |
| 24 | return handled ?? HttpServerResponse.text("Not Found", { status: 404 }); |
| 25 | }), |
| 26 | }; |
| 27 | }).pipe(Effect.provide(Cloudflare.Artifacts.ReadNamespaceBinding)), |
| 28 | ) {} |