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 | /** Standard Effect HTTP group registration with an application user handler. */ |
| 2 | import { GitApi, GroupsLive, InternalApiLive, Handlers } from "@alchemy.run/git"; |
| 3 | import * as Http from "alchemy/Http"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"; |
| 6 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 7 | import * as Layer from "effect/Layer"; |
| 8 | import * as Option from "effect/Option"; |
| 9 | import { TestCaller, TestAuthLive } from "./test-auth.ts"; |
| 10 | |
| 11 | export const GitHubLive = HttpApiBuilder.group(GitApi, "github", (h) => |
| 12 | Effect.map(Handlers, (git) => |
| 13 | h.handleAll({ |
| 14 | ...git.github, |
| 15 | user: () => |
| 16 | Effect.gen(function* () { |
| 17 | const caller = yield* Effect.serviceOption(TestCaller); |
| 18 | const user = Option.isSome(caller) ? caller.value.user : null; |
| 19 | return user === null |
| 20 | ? HttpServerResponse.jsonUnsafe({ message: "Requires authentication" }, { status: 401 }) |
| 21 | : HttpServerResponse.jsonUnsafe({ |
| 22 | login: user.name, |
| 23 | id: 1, |
| 24 | type: "User", |
| 25 | }); |
| 26 | }), |
| 27 | }), |
| 28 | ), |
| 29 | ); |
| 30 | |
| 31 | /** The test application's router: public Git routes plus the internal hash route. */ |
| 32 | export const TestRoutes = Layer.mergeAll( |
| 33 | HttpApiBuilder.layer(GitApi).pipe( |
| 34 | Layer.provide(Layer.mergeAll(GroupsLive, GitHubLive)), |
| 35 | Layer.provide(TestAuthLive), |
| 36 | ), |
| 37 | InternalApiLive, |
| 38 | ).pipe(Layer.provide(Http.Platform)); |