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

main
ts 60 lines 1.94 KB
Raw
1 import type * as runtime from "@cloudflare/workers-types";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import * as Data from "effect/Data";
5 import * as Effect from "effect/Effect";
6 import * as Redacted from "effect/Redacted";
7 import type { Secret } from "./Secret.ts";
8
9 /**
10 * Bind a {@link Secret} to a Worker and obtain the Effect-native secret
11 * client. The client is itself an `Effect` that resolves to the secret's
12 * current value.
13 *
14 * `ReadSecret` is a single identifier that is simultaneously the binding's
15 * Context tag, its type, and the callable —
16 * `yield* Cloudflare.SecretsStore.ReadSecret(ApiKey)`.
17 *
18 * **Example:** Reading a secret at runtime
19 * ```typescript
20 * const apiKey = yield* Cloudflare.SecretsStore.ReadSecret(ApiKey);
21 * const value = yield* apiKey;
22 * ```
23 *
24 * @binding
25 * @product Secrets Store
26 * @category Storage & Databases
27 */
28 export interface ReadSecret extends Binding.Service<
29 ReadSecret,
30 "Cloudflare.SecretsStore.ReadSecret",
31 (secret: Secret) => Effect.Effect<ReadSecretClient>
32 > {}
33
34 export const ReadSecret = Binding.Service<ReadSecret>("Cloudflare.SecretsStore.ReadSecret");
35
36 export class SecretError extends Data.TaggedError("SecretError")<{
37 message: string;
38 cause: Error;
39 }> {}
40
41 /**
42 * A bound secret. The client itself is an `Effect` that resolves to the
43 * secret's current value, so you can `yield* apiKey` directly. Use `.get()`
44 * for the same thing as a callable, or `.raw` for the underlying
45 * `SecretsStoreSecret` binding.
46 */
47 export interface ReadSecretClient extends Effect.Effect<
48 Redacted.Redacted<string>,
49 SecretError,
50 RuntimeContext
51 > {
52 /**
53 * Effect that resolves to the raw Cloudflare `SecretsStoreSecret` binding.
54 */
55 raw: Effect.Effect<runtime.SecretsStoreSecret, never, RuntimeContext>;
56 /**
57 * Read the current value of the secret.
58 */
59 get(): Effect.Effect<Redacted.Redacted<string>, SecretError, RuntimeContext>;
60 }