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 | /** |
| 2 | * The Git host with its pack hasher on AWS Lambda (DESIGN §22.11): the |
| 3 | * same building-block assembly as `stack.ts`, with `HasherLambda` in place |
| 4 | * of the in-process hasher. Needs BOTH provider sets — the Worker binds |
| 5 | * `InvokeFunction` cross-cloud (an IAM identity is minted for it). |
| 6 | */ |
| 7 | import * as AWS from "@alchemy.run/aws"; |
| 8 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 9 | import { |
| 10 | BlobStoreR2, |
| 11 | GIT_WORKER_OPTIONS, |
| 12 | ApiHandlersLive, |
| 13 | ReposDurableObject, |
| 14 | RegistryDurableObject, |
| 15 | } from "@alchemy.run/git"; |
| 16 | import { HasherFunction, HasherLambda } from "@alchemy.run/git/Hasher"; |
| 17 | import * as Alchemy from "alchemy"; |
| 18 | import * as Effect from "effect/Effect"; |
| 19 | import * as HttpRouter from "effect/http/HttpRouter"; |
| 20 | import * as Layer from "effect/Layer"; |
| 21 | import { TestRoutes } from "./http.ts"; |
| 22 | import { TEST_SECRET, TestApi, TestAuthLive } from "./stack.ts"; |
| 23 | export { TEST_SECRET }; |
| 24 | |
| 25 | const GitObjects = Cloudflare.R2.Bucket("GitLambdaObjects", { |
| 26 | forceDestroy: true, |
| 27 | }); |
| 28 | |
| 29 | const GitLive = TestRoutes.pipe( |
| 30 | Layer.provide(ApiHandlersLive), |
| 31 | Layer.provide(ReposDurableObject), |
| 32 | Layer.provide(RegistryDurableObject), |
| 33 | Layer.provide(HasherLambda(HasherFunction)), |
| 34 | Layer.provide(AWS.Lambda.InvokeFunctionHttp), |
| 35 | Layer.provide(BlobStoreR2(GitObjects)), |
| 36 | ); |
| 37 | |
| 38 | export default class LambdaGitHost extends Cloudflare.Worker<LambdaGitHost>()( |
| 39 | "GitLambdaWorker", |
| 40 | { |
| 41 | main: import.meta.url, |
| 42 | ...GIT_WORKER_OPTIONS, |
| 43 | observability: { enabled: true }, |
| 44 | }, |
| 45 | Effect.gen(function* () { |
| 46 | const fetch = yield* HttpRouter.toHttpEffect(GitLive); |
| 47 | return { fetch }; |
| 48 | }).pipe(Effect.provide(Cloudflare.R2.ReadWriteBucketBinding)), |
| 49 | ) {} |
| 50 | |
| 51 | export const makeLambdaTestStack = (name: string) => |
| 52 | Alchemy.Stack( |
| 53 | name, |
| 54 | { |
| 55 | providers: Layer.mergeAll(AWS.providers(), Cloudflare.providers()), |
| 56 | state: Cloudflare.state(), |
| 57 | }, |
| 58 | Effect.gen(function* () { |
| 59 | const host = yield* LambdaGitHost; |
| 60 | return { url: host.url.as<string>() }; |
| 61 | }), |
| 62 | ); |