@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 39 lines 1.45 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import * as HttpServerResponse from "effect/http/HttpServerResponse";
4 import * as Stream from "effect/Stream";
5
6 /** Queues and helpers shared by the QueueSink fixtures. */
7
8 /** Produced by `POST /produce` into the source queue. */
9 export interface Click {
10 run: string;
11 index: number;
12 padding?: string;
13 }
14
15 /** The transformed message the source consumer sinks into the result queue. */
16 export interface EnrichedClick extends Click {
17 doubled: number;
18 }
19
20 export const SourceQueue = Cloudflare.Queues.Queue("QueueSinkSource");
21 export const ResultQueue = Cloudflare.Queues.Queue("QueueSinkResult");
22
23 /**
24 * `POST /produce?run=K&count=N[&padding=B]`: drain N clicks into `sink` as a
25 * single stream chunk, so the sink must split it into batches.
26 */
27 export const produceRoute = (sink: Cloudflare.Queues.QueueSinkClient, url: URL) =>
28 Effect.gen(function* () {
29 const run = url.searchParams.get("run") ?? "default";
30 const count = Number(url.searchParams.get("count") ?? "1");
31 const padding = Number(url.searchParams.get("padding") ?? "0");
32 const events = Array.from({ length: count }, (_, index): Click => ({
33 run,
34 index,
35 ...(padding > 0 ? { padding: "x".repeat(padding) } : {}),
36 }));
37 yield* Stream.fromIterable(events).pipe(Stream.run(sink), Effect.orDie);
38 return yield* HttpServerResponse.json({ produced: count }, { status: 202 });
39 });