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 AWS from "@alchemy.run/aws"; |
| 2 | import { R2 } from "@alchemy.run/cloudflare"; |
| 3 | import * as Fly from "@alchemy.run/fly"; |
| 4 | import * as Storage from "@alchemy.run/gcp/Storage"; |
| 5 | import * as Hetzner from "@alchemy.run/hetzner"; |
| 6 | import * as Neon from "@alchemy.run/neon"; |
| 7 | import * as Railway from "@alchemy.run/railway"; |
| 8 | import type * as Alchemy from "alchemy"; |
| 9 | import * as FileSystem from "effect/FileSystem"; |
| 10 | |
| 11 | const GCP = { Storage }; |
| 12 | import * as Context from "effect/Context"; |
| 13 | import * as Effect from "effect/Effect"; |
| 14 | import * as Layer from "effect/Layer"; |
| 15 | |
| 16 | export class Files extends Context.Service< |
| 17 | Files, |
| 18 | { upload(name: string, body: string): Effect.Effect<void, never, Alchemy.RuntimeContext> } |
| 19 | >()("Files") {} |
| 20 | |
| 21 | // #region show |
| 22 | export const FilesR2 = Layer.effect( |
| 23 | Files, |
| 24 | Effect.gen(function* () { |
| 25 | const bucket = yield* R2.ReadWriteBucket(yield* R2.Bucket("Files")); |
| 26 | return { |
| 27 | upload: (name, body) => |
| 28 | bucket |
| 29 | .put(name, body) /*hide*/ |
| 30 | .pipe(Effect.asVoid, Effect.orDie) /*end*/, |
| 31 | }; |
| 32 | }), |
| 33 | ).pipe(Layer.provide(R2.ReadWriteBucketBinding)); |
| 34 | |
| 35 | export const FilesS3 = Layer.effect( |
| 36 | Files, |
| 37 | Effect.gen(function* () { |
| 38 | const putObject = yield* AWS.S3.PutObject(yield* AWS.S3.Bucket("Files")); |
| 39 | return { |
| 40 | upload: (name, body) => |
| 41 | putObject({ Key: name, Body: body }) /*hide*/ |
| 42 | .pipe(Effect.asVoid, Effect.orDie) /*end*/, |
| 43 | }; |
| 44 | }), |
| 45 | ).pipe(Layer.provide(AWS.S3.PutObjectHttp)); |
| 46 | |
| 47 | export const FilesGCS = Layer.effect( |
| 48 | Files, |
| 49 | Effect.gen(function* () { |
| 50 | const bucket = yield* GCP.Storage.WriteBucket(yield* GCP.Storage.Bucket("Files", {})); |
| 51 | return { |
| 52 | upload: (name, body) => |
| 53 | bucket |
| 54 | .put(name, body) /*hide*/ |
| 55 | .pipe(Effect.asVoid, Effect.orDie) /*end*/, |
| 56 | }; |
| 57 | }), |
| 58 | ).pipe(Layer.provide(GCP.Storage.WriteBucketHttp)); |
| 59 | // #endregion show |
| 60 | |
| 61 | // More stores, for the host roll (not on the Files slide). |
| 62 | export const FilesTigris = Layer.effect( |
| 63 | Files, |
| 64 | Effect.gen(function* () { |
| 65 | const putObject = yield* Fly.PutObject(yield* Fly.Bucket("Files", {})); |
| 66 | return { |
| 67 | upload: (name, body) => |
| 68 | putObject({ Key: name, Body: body }) /*hide*/ |
| 69 | .pipe(Effect.asVoid, Effect.orDie) /*end*/, |
| 70 | }; |
| 71 | }), |
| 72 | ).pipe(Layer.provide(Fly.PutObjectHttp)); |
| 73 | |
| 74 | export const FilesRailway = Layer.effect( |
| 75 | Files, |
| 76 | Effect.gen(function* () { |
| 77 | const putObject = yield* Railway.PutObject( |
| 78 | yield* Railway.Bucket("Files", { project: yield* Railway.Project("Chat", {}) }), |
| 79 | ); |
| 80 | return { |
| 81 | upload: (name, body) => |
| 82 | putObject({ Key: name, Body: body }) /*hide*/ |
| 83 | .pipe(Effect.asVoid, Effect.orDie) /*end*/, |
| 84 | }; |
| 85 | }), |
| 86 | ).pipe(Layer.provide(Railway.PutObjectHttp)); |
| 87 | |
| 88 | export const FilesNeon = Layer.effect( |
| 89 | Files, |
| 90 | Effect.gen(function* () { |
| 91 | const bucket = yield* Neon.WriteBucket( |
| 92 | yield* Neon.Bucket("Files", { |
| 93 | branch: yield* Neon.Branch("Main", { project: yield* Neon.Project("Db") }), |
| 94 | }), |
| 95 | ); |
| 96 | return { |
| 97 | upload: (name, body) => |
| 98 | bucket |
| 99 | .put(name, body) /*hide*/ |
| 100 | .pipe(Effect.asVoid, Effect.orDie) /*end*/, |
| 101 | }; |
| 102 | }), |
| 103 | ).pipe(Layer.provide(Neon.WriteBucketHttp)); |
| 104 | |
| 105 | export const FilesVolume = Layer.effect( |
| 106 | Files, |
| 107 | Effect.gen(function* () { |
| 108 | const volume = yield* Hetzner.Volume("Files", { size: 10, format: "ext4", location: "nbg1" }); |
| 109 | const mount = yield* Hetzner.MountVolume(volume, { path: "/files" }); |
| 110 | const fs = yield* FileSystem.FileSystem; |
| 111 | return { |
| 112 | upload: (name, body) => |
| 113 | fs |
| 114 | .writeFileString(`${mount.path}/${name}`, body) /*hide*/ |
| 115 | .pipe(Effect.orDie) /*end*/, |
| 116 | }; |
| 117 | }), |
| 118 | ).pipe(Layer.provide(Hetzner.MountVolumeLive)); |