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, 04:45 UTC
| 1 | /** Smart HTTP uses the same API middleware and request services as JSON endpoints. */ |
| 2 | import * as Git from "@alchemy.run/git"; |
| 3 | import * as GitHttp from "@alchemy.run/git/Http"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"; |
| 6 | import { AppApi } from "./api.ts"; |
| 7 | import { checkRefChanges } from "./branch-policy.ts"; |
| 8 | |
| 9 | export const ProtocolLive = HttpApiBuilder.group(AppApi, "protocol", (h) => |
| 10 | Effect.gen(function* () { |
| 11 | const git = yield* Git.Engine; |
| 12 | const defaults = yield* Git.Handlers; |
| 13 | return h |
| 14 | .handleRaw("infoRefs", defaults.protocol.infoRefs) |
| 15 | .handleRaw("uploadPack", defaults.protocol.uploadPack) |
| 16 | .handleRaw("receivePack", ({ params, request }) => |
| 17 | Effect.scoped( |
| 18 | Effect.gen(function* () { |
| 19 | const repo = yield* git.repositories |
| 20 | .get(params) |
| 21 | .pipe(Effect.catchTag("StoreError", Effect.die)); |
| 22 | const push = yield* GitHttp.ReceivePack.decode(request); |
| 23 | if (push._tag === "Probe") return GitHttp.ReceivePack.probeResponse(); |
| 24 | return yield* Effect.gen(function* () { |
| 25 | yield* checkRefChanges(repo, push.updates); |
| 26 | const prepared = yield* git.preparePush(repo, push.input); |
| 27 | // Additional application validation can read prepared.readObject(oid) here. |
| 28 | return GitHttp.ReceivePack.response(push, yield* git.commitPush(prepared)); |
| 29 | }).pipe( |
| 30 | Effect.catchTag("PushDenied", (error) => |
| 31 | Effect.succeed(GitHttp.ReceivePack.reject(push, error.reason)), |
| 32 | ), |
| 33 | ); |
| 34 | }), |
| 35 | ).pipe( |
| 36 | Effect.catchTag("StoreError", (error) => |
| 37 | Effect.succeed(GitHttp.ReceivePack.failure(error.reason)), |
| 38 | ), |
| 39 | Effect.catchTag(["WireProtocolError", "PackIngestError"], (error) => |
| 40 | Effect.succeed(GitHttp.ReceivePack.failure(error.reason)), |
| 41 | ), |
| 42 | ), |
| 43 | ); |
| 44 | }), |
| 45 | ); |