@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 34 lines 1.5 KB
Raw
1 import * as Effect from "effect/Effect";
2 import type * as HttpClient from "effect/http/HttpClient";
3 import { CloudflareEnvironment } from "../CloudflareEnvironment.ts";
4 import type { Credentials } from "../Credentials.ts";
5 import type { TunnelAuth } from "./TunnelBinding.ts";
6
7 /**
8 * Shared scaffolding for the `*Local` tunnel services.
9 *
10 * Instead of minting a scoped {@link AccountApiToken} (the `*Binding` path), it
11 * captures the ambient current-credentials context available during stack-eval
12 * and builds a {@link TunnelAuth} that provides those credentials directly to
13 * the cfd_tunnel HTTP ops. It then delegates to the same client builders the
14 * `*Binding` variant uses.
15 *
16 * NOT exported from `index.ts` — this is internal scaffolding shared by the
17 * three access-level Local layers.
18 */
19 export const makeLocalTunnelClient = <Client>(makeClient: (auth: TunnelAuth) => Client) =>
20 Effect.gen(function* () {
21 // Account + credentials are ambient during stack-eval (the stack's
22 // providers layer). Capture the full context so cfd_tunnel HTTP ops can run
23 // with the current credentials — no `host.bind`, no minted token.
24 const { accountId } = yield* yield* CloudflareEnvironment;
25 const context = yield* Effect.context<Credentials | HttpClient.HttpClient>();
26
27 return Effect.fn(function* () {
28 const auth: TunnelAuth = {
29 authorize: (eff) => eff.pipe(Effect.provideContext(context)),
30 accountId: Effect.succeed(accountId),
31 };
32 return makeClient(auth);
33 });
34 });