@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 07:15 UTC

main
ts 30 lines 1.3 KB
Raw
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 { artifactsRoutes } from "./routes.ts";
6 import { Repos } from "./shared.ts";
7
8 /**
9 * Effect-native Worker fixture for the Artifacts namespace binding. Yielding
10 * `Cloudflare.Artifacts.ReadWriteNamespace(Repos)` during Init registers the native
11 * `{ type: "artifacts" }` binding and returns the Effect-native
12 * {@link ReadWriteNamespaceClient}. Routes are shared with the async worker via
13 * `routes.ts`.
14 */
15 export default class ArtifactsEffectWorker extends Cloudflare.Worker<ArtifactsEffectWorker>()(
16 "ArtifactsEffectWorker",
17 { main: import.meta.url },
18 Effect.gen(function* () {
19 const repos = yield* Repos;
20 const client = yield* Cloudflare.Artifacts.ReadWriteNamespace(repos);
21 return {
22 fetch: Effect.gen(function* () {
23 const request = yield* HttpServerRequest;
24 const url = new URL(request.url, "http://x");
25 const handled = yield* artifactsRoutes(client, url);
26 return handled ?? HttpServerResponse.text("Not Found", { status: 404 });
27 }),
28 };
29 }).pipe(Effect.provide(Cloudflare.Artifacts.ReadWriteNamespaceBinding)),
30 ) {}