The best way to control Claude Code, Codex and more from any computer or phone

main
ts 64 lines 2.34 KB
Raw
1 import * as DistilledRegion from "@distilled.cloud/gcp/Region";
2 import * as Effect from "effect/Effect";
3 import type * as Layer from "effect/Layer";
4 import { GcpEnvironment } from "./Environment.ts";
5
6 export type { RegionalEndpointMode, RegionName } from "@distilled.cloud/gcp/Region";
7
8 /**
9 * Override the default GCP region — the region regional resources land in
10 * when created without an explicit `location` / `region`.
11 *
12 * The region normally comes with the credentials (the profile's
13 * `region`), else `us-central1`. Provide `GCP.Region(...)` on the
14 * providers layer to override that for a stack. There is no environment
15 * variable: Google's SDKs don't define one, and deployed GCP runtimes
16 * read their region from the metadata server. A resource that should live elsewhere takes
17 * an explicit `location`; a recorded location always wins, so changing
18 * the region never moves a deployed resource.
19 *
20 * ### Choosing a region
21 * **Example:** Deploy a stack to europe-west1
22 * ```typescript
23 * export default Alchemy.Stack(
24 * "App",
25 * {
26 * providers: GCP.providers().pipe(
27 * Layer.provideMerge(GCP.Region("europe-west1")),
28 * ),
29 * state: Alchemy.localState(),
30 * },
31 * program,
32 * );
33 * ```
34 */
35 export const Region = (region: DistilledRegion.RegionName): Layer.Layer<DistilledRegion.Region> =>
36 DistilledRegion.of(region);
37
38 /**
39 * Route requests to Google's regional endpoints
40 * (`{service}.{region}.rep.googleapis.com`):
41 *
42 * - `"required"` (default): only where the global endpoint rejects
43 * regional resources (Secret Manager, Parameter Manager).
44 * - `"prefer"`: every request for a regional resource whose service
45 * publishes a regional endpoint, so traffic terminates in-region.
46 * - `"never"`: always the global endpoint.
47 *
48 * ### Data residency
49 * **Example:** Keep every regional request in-region
50 * ```typescript
51 * GCP.providers().pipe(
52 * Layer.provideMerge(GCP.Region("europe-west1")),
53 * Layer.provideMerge(GCP.RegionalEndpoints("prefer")),
54 * );
55 * ```
56 */
57 export const RegionalEndpoints = (
58 mode: DistilledRegion.RegionalEndpointMode,
59 ): Layer.Layer<DistilledRegion.RegionalEndpoints> => DistilledRegion.regionalEndpoints(mode);
60
61 /** The effective default region in the current scope. */
62 export const currentRegion = Effect.suspend(() =>
63 GcpEnvironment.use((env) => Effect.map(env, ({ region }) => region)),
64 );