@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, 04:45 UTC

main
ts 47 lines 1.38 KB
Raw
1 import * as sprites from "@distilled.cloud/fly-io/sprites";
2 import * as Effect from "effect/Effect";
3 import * as FetchHttpClient from "effect/http/FetchHttpClient";
4 import * as Layer from "effect/Layer";
5 import { CredentialsFromAmbientOrEnv } from "./Credentials.ts";
6 import { Exec, type ExecRequest } from "./Exec.ts";
7 import { makeHttpSpriteBinding } from "./SpriteHttp.ts";
8
9 /**
10 * HTTP implementation of {@link Exec}. Provide it on the
11 * {@link Sprite}, {@link Service}, or Action Effect.
12 *
13 *
14 * ### Provide the layer
15 * **Example:** On a Sprite
16 * ```typescript
17 * Effect.gen(function* () {
18 * const exec = yield* Fly.Exec(Box);
19 * // ...
20 * }).pipe(Effect.provide(Fly.ExecHttp))
21 * ```
22 *
23 * @layer
24 * @product Sprite
25 * @provides Fly.Exec
26 */
27 export const ExecHttp = Layer.effect(
28 Exec,
29 Effect.suspend(() =>
30 makeHttpSpriteBinding({
31 makeClient: (auth, spriteName) =>
32 Effect.fn("Fly.Exec")(function* (request: ExecRequest) {
33 return yield* auth.authorize(
34 sprites.execCommand({
35 name: yield* spriteName,
36 cmd: request.cmd,
37 path: request.path,
38 stdin: request.stdin,
39 env: request.env,
40 dir: request.dir,
41 body: request.body,
42 }),
43 );
44 }),
45 }),
46 ),
47 ).pipe(Layer.provide(FetchHttpClient.layer), Layer.provide(CredentialsFromAmbientOrEnv));