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

main
ts 38 lines 1.25 KB
Raw
1 import { ConfigError } from "@distilled.cloud/core/errors";
2 import { Credentials, toConfig } from "@distilled.cloud/railway";
3 import { lazyCredentials } from "alchemy/Auth/Resolve";
4 import * as Layer from "effect/Layer";
5 import { RAILWAY_AUTH_PROVIDER_NAME, type RailwayResolvedCredentials } from "./AuthProvider.ts";
6
7 export {
8 Credentials,
9 CredentialsFromEnv,
10 CredentialsFromToken,
11 DEFAULT_API_BASE_URL,
12 type Config as CredentialsConfig,
13 type TokenKind,
14 } from "@distilled.cloud/railway";
15
16 /**
17 * Build a `Credentials` layer that resolves Railway credentials via the
18 * current Alchemy profile, or directly from environment variables in CI.
19 *
20 * Maps onto `@distilled.cloud/railway`'s
21 * `{ token, tokenKind: "account", apiBaseUrl }` shape. Alchemy itself only
22 * reads `RAILWAY_API_TOKEN` (account Bearer). Distilled's own
23 * `CredentialsFromEnv` also accepts `RAILWAY_TOKEN` / `RAILWAY_PROJECT_TOKEN`
24 * as fallbacks.
25 */
26 export const fromAuthProvider = () =>
27 Layer.effect(
28 Credentials,
29 lazyCredentials<RailwayResolvedCredentials, ConfigError>()(
30 RAILWAY_AUTH_PROVIDER_NAME,
31 (creds) =>
32 toConfig({
33 token: creds.token,
34 tokenKind: creds.tokenKind,
35 apiBaseUrl: creds.apiBaseUrl,
36 }),
37 ),
38 );