@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 33 lines 1.27 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 { produceRoute, SourceQueue } from "./queue-sink-shared.ts";
6
7 /**
8 * Producer-only Worker that drains clicks into the shared source queue
9 * through `QueueSinkHttp` (bulk-push HTTP API with a scoped token). The
10 * `QueueSinkWorker` consumers carry them the rest of the way. Live-only:
11 * the HTTP layer mints a real account API token.
12 */
13 export default class QueueSinkHttpWorker extends Cloudflare.Worker<QueueSinkHttpWorker>()(
14 "QueueSinkHttpWorker",
15 {
16 main: import.meta.url,
17 },
18 Effect.gen(function* () {
19 const source = yield* SourceQueue;
20 const clicks = yield* Cloudflare.Queues.QueueSink(source);
21
22 return {
23 fetch: Effect.gen(function* () {
24 const request = yield* HttpServerRequest;
25 const url = new URL(request.url, "http://x");
26 if (request.method === "POST" && url.pathname === "/produce") {
27 return yield* produceRoute(clicks, url);
28 }
29 return HttpServerResponse.text("Not Found", { status: 404 });
30 }),
31 };
32 }).pipe(Effect.provide(Cloudflare.Queues.QueueSinkHttp)),
33 ) {}