The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { Credentials, fromApiToken } from "@distilled.cloud/cloudflare/Credentials"; |
| 2 | import type { RuntimeContext } from "alchemy/RuntimeContext"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as FetchHttpClient from "effect/http/FetchHttpClient"; |
| 5 | import type { HttpClient } from "effect/http/HttpClient"; |
| 6 | import * as Layer from "effect/Layer"; |
| 7 | import * as Redacted from "effect/Redacted"; |
| 8 | |
| 9 | /** |
| 10 | * Resolve credentials from a bound token's value and provide them (plus the |
| 11 | * fetch-based HTTP client) to a raw SDK operation. |
| 12 | */ |
| 13 | export const authorizeWith = |
| 14 | (token: { value: Effect.Effect<Redacted.Redacted<string>> }) => |
| 15 | <A, E>(eff: Effect.Effect<A, E, Credentials | HttpClient>): Effect.Effect<A, E, RuntimeContext> => |
| 16 | token.value.pipe( |
| 17 | Effect.flatMap((value) => |
| 18 | eff.pipe( |
| 19 | Effect.provide( |
| 20 | fromApiToken({ apiToken: value }).pipe(Layer.provideMerge(FetchHttpClient.layer)), |
| 21 | ), |
| 22 | ), |
| 23 | ), |
| 24 | ); |