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

main
ts 48 lines 1.61 KB
Raw
1 import type { AppSecret, GetSecretError } from "@distilled.cloud/fly-io/machines";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import type * as Effect from "effect/Effect";
5 import type { Secret } from "./Secret.ts";
6
7 /**
8 * Fetch one Fly.io App secret. The App and name are fixed by
9 * `GetSecret(secret)`. Calls take no `app_name`.
10 *
11 *
12 * ### Read a secret
13 * Bind the client in init. Call it from `fetch` or an Action body.
14 * Provide {@link GetSecretHttp}. Alchemy transports the bound App name,
15 * secret name, and deployment's org token automatically. There is no
16 * need to configure `FLY_SECRET_*` environment variables.
17 *
18 * Fly only returns plaintext from a Machine in the same App. From a
19 * deploy-time Action you get metadata (name, digest, timestamps).
20 *
21 * **Example:** GetSecret
22 * ```typescript
23 * export default class Api extends Fly.Service<Api>()(
24 * "Api",
25 * { app: Site, main: import.meta.url, port: 3000 },
26 * Effect.gen(function* () {
27 * const get = yield* Fly.GetSecret(ApiToken);
28 *
29 * return {
30 * fetch: Effect.gen(function* () {
31 * const got = yield* get().pipe(Effect.orDie);
32 * return HttpServerResponse.json({ name: got.name });
33 * }),
34 * };
35 * }).pipe(Effect.provide(Fly.GetSecretHttp)),
36 * ) {}
37 * ```
38 *
39 * @binding
40 * @product Secret
41 */
42 export interface GetSecret extends Binding.Service<
43 GetSecret,
44 "Fly.GetSecret",
45 (secret: Secret) => Effect.Effect<() => Effect.Effect<AppSecret, GetSecretError, RuntimeContext>>
46 > {}
47
48 export const GetSecret = Binding.Service<GetSecret>("Fly.GetSecret");