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
| 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 Layer from "effect/Layer"; |
| 5 | import { HttpOrders, produceRoutes } from "./k2-shared.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Produces to a K2 stream through its HTTP input with a scoped `K2 Produce` |
| 9 | * token (`WriteStreamHttp` / `StreamSinkHttp`). Live-only: the HTTP layers |
| 10 | * mint a real account API token. |
| 11 | */ |
| 12 | export default class K2HttpWorker extends Cloudflare.Worker<K2HttpWorker>()( |
| 13 | "K2HttpWorker", |
| 14 | { |
| 15 | main: import.meta.url, |
| 16 | }, |
| 17 | Effect.gen(function* () { |
| 18 | const orders = yield* HttpOrders; |
| 19 | const typed = yield* Cloudflare.K2.WriteStream(orders); |
| 20 | const sink = yield* Cloudflare.K2.StreamSink(orders); |
| 21 | |
| 22 | return { |
| 23 | fetch: Effect.gen(function* () { |
| 24 | const request = yield* HttpServerRequest; |
| 25 | return yield* produceRoutes(new URL(request.url, "http://x"), { typed, sink }); |
| 26 | }), |
| 27 | }; |
| 28 | }).pipe( |
| 29 | Effect.provide(Layer.mergeAll(Cloudflare.K2.WriteStreamHttp, Cloudflare.K2.StreamSinkHttp)), |
| 30 | ), |
| 31 | ) {} |