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, 06:00 UTC
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import * as Neon from "@alchemy.run/neon"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as FetchHttpClient from "effect/http/FetchHttpClient"; |
| 5 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 6 | import * as Layer from "effect/Layer"; |
| 7 | import * as Redacted from "effect/Redacted"; |
| 8 | import { backendAuth, backendBranch, backendDataApi, backendGateway } from "./backend-resources.ts"; |
| 9 | |
| 10 | const bindings = Layer.mergeAll( |
| 11 | Neon.ConnectAuthHttp, |
| 12 | Neon.QueryDataApiHttp, |
| 13 | Neon.QueryAIGatewayHttp, |
| 14 | ).pipe(Layer.provide(FetchHttpClient.layer)); |
| 15 | |
| 16 | export default class BackendHttpWorker extends Cloudflare.Worker<BackendHttpWorker>()( |
| 17 | "BackendHttpWorker", |
| 18 | { |
| 19 | main: import.meta.url, |
| 20 | }, |
| 21 | Effect.gen(function* () { |
| 22 | const auth = yield* Neon.ConnectAuth(backendAuth); |
| 23 | const data = yield* Neon.QueryDataApi(backendDataApi); |
| 24 | const ai = yield* Neon.QueryAIGateway(backendGateway); |
| 25 | const shared = yield* Neon.QueryAIGateway( |
| 26 | Effect.gen(function* () { |
| 27 | return yield* Neon.AIGateway("SharedGateway", { |
| 28 | branch: yield* backendBranch, |
| 29 | }); |
| 30 | }), |
| 31 | ); |
| 32 | return { |
| 33 | fetch: Effect.gen(function* () { |
| 34 | return yield* HttpServerResponse.json({ |
| 35 | authUrl: yield* auth.baseUrl, |
| 36 | jwksUrl: yield* auth.jwksUrl, |
| 37 | dataUrl: yield* data.baseUrl, |
| 38 | aiUrl: yield* ai.baseUrl, |
| 39 | hasToken: Redacted.value(yield* ai.token).length > 0, |
| 40 | sharedToken: Redacted.value(yield* ai.token) === Redacted.value(yield* shared.token), |
| 41 | }); |
| 42 | }), |
| 43 | }; |
| 44 | }).pipe(Effect.provide(bindings)), |
| 45 | ) {} |