The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { ConfigError } from "@distilled.cloud/core/errors"; |
| 2 | import type { Config } from "@distilled.cloud/hetzner"; |
| 3 | import { Credentials } from "@distilled.cloud/hetzner"; |
| 4 | import * as Context from "effect/Context"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Layer from "effect/Layer"; |
| 7 | |
| 8 | /** |
| 9 | * Fully-resolved Hetzner Cloud environment for a stack. |
| 10 | * |
| 11 | * A Hetzner Cloud token is issued per project — the token IS the project |
| 12 | * scope, so this service only carries `{ token, apiBaseUrl }`. Resolve |
| 13 | * it inside lifecycle operations with `HetznerEnvironment.current`. |
| 14 | */ |
| 15 | export type HetznerEnvironmentShape = Config; |
| 16 | |
| 17 | export class HetznerEnvironment extends Context.Service< |
| 18 | HetznerEnvironment, |
| 19 | Effect.Effect<HetznerEnvironmentShape, ConfigError> |
| 20 | >()("Hetzner::Environment") { |
| 21 | static current = HetznerEnvironment.use((env) => env); |
| 22 | readonly kind = "Environment" as const; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Build a `HetznerEnvironment` layer from the distilled `Credentials` |
| 27 | * service. Provide this after `Credentials.fromAuthProvider()`. |
| 28 | */ |
| 29 | export const fromCredentials = () => Layer.effect(HetznerEnvironment, Credentials); |