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

main
ts 43 lines 1.64 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 * as Layer from "effect/Layer";
6 import * as EffectStream from "effect/Stream";
7 import { PageView, PageViews } from "./pipelines-stream.ts";
8
9 /**
10 * Worker sending through the stream's HTTP ingest endpoint with a scoped
11 * `Pipelines Send` token (`WriteStreamHttp` / `StreamSinkHttp`).
12 */
13 export default class PipelinesHttpWorker extends Cloudflare.Worker<PipelinesHttpWorker>()(
14 "PipelinesHttpWorker",
15 { main: import.meta.url },
16 Effect.gen(function* () {
17 const views = yield* Cloudflare.Basin.WriteStream(PageViews);
18 const sink = yield* Cloudflare.Basin.StreamSink(PageViews);
19
20 return {
21 fetch: Effect.gen(function* () {
22 const request = yield* HttpServerRequest;
23 const url = new URL(request.originalUrl, "http://x");
24 if (url.pathname === "/send") {
25 yield* views
26 .send([new PageView({ url: "/http", at: new Date(), tags: [] })])
27 .pipe(Effect.orDie);
28 yield* EffectStream.range(1, 20).pipe(
29 EffectStream.map((i) => new PageView({ url: `/http/${i}`, at: new Date(), tags: [] })),
30 EffectStream.run(sink),
31 Effect.orDie,
32 );
33 return yield* HttpServerResponse.json({ sent: 21 });
34 }
35 return yield* HttpServerResponse.json({ ok: true });
36 }),
37 };
38 }).pipe(
39 Effect.provide(
40 Layer.mergeAll(Cloudflare.Basin.WriteStreamHttp, Cloudflare.Basin.StreamSinkHttp),
41 ),
42 ),
43 ) {}