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, 03:37 UTC
| 1 | import * as Layer from "effect/Layer"; |
| 2 | import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; |
| 3 | import * as Schema from "effect/Schema"; |
| 4 | import * as Config from "effect/Config"; |
| 5 | import * as ConfigProvider from "effect/ConfigProvider"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as FileSystem from "effect/FileSystem"; |
| 8 | import * as Option from "effect/Option"; |
| 9 | import * as WriterRegistry from "./WriterRegistry.ts"; |
| 10 | |
| 11 | const encodeWriters = Schema.encodeEffect( |
| 12 | Schema.fromJsonString(Schema.Record(Schema.String, Schema.String)), |
| 13 | ); |
| 14 | |
| 15 | // An absent registry must fail deployment rather than revoke every existing writer. |
| 16 | export const WriterSecrets = ConfigProvider.layerAdd( |
| 17 | Effect.gen(function* () { |
| 18 | const configured = yield* Config.Redacted("DEVELOPER_KEYS").pipe(Config.option); |
| 19 | const readers = yield* Config.Redacted("READER_KEYS").pipe(Config.option); |
| 20 | const fs = yield* FileSystem.FileSystem; |
| 21 | const readerKeys = Option.isSome(readers) |
| 22 | ? {} |
| 23 | : { |
| 24 | READER_KEYS: yield* fs.readFileString( |
| 25 | `${yield* Config.String("HOME")}/.config/t3-task-cache/readers.json`, |
| 26 | ), |
| 27 | }; |
| 28 | if (Option.isSome(configured)) return ConfigProvider.fromUnknown(readerKeys); |
| 29 | return ConfigProvider.fromUnknown({ |
| 30 | ...readerKeys, |
| 31 | DEVELOPER_KEYS: yield* encodeWriters( |
| 32 | yield* WriterRegistry.WriterRegistry.pipe( |
| 33 | Effect.flatMap((registry) => registry.read()), |
| 34 | Effect.provide(WriterRegistry.layer.pipe(Layer.provide(NodeCrypto.layer))), |
| 35 | ), |
| 36 | ), |
| 37 | }); |
| 38 | }), |
| 39 | ); |