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
| 1 | import type { ExecCommandError, ExecResult } from "@distilled.cloud/fly-io/sprites"; |
| 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 { Sprite } from "./Sprite.ts"; |
| 6 | |
| 7 | export interface ExecRequest { |
| 8 | /** Command and args. */ |
| 9 | cmd: string[]; |
| 10 | /** Explicit path to the executable. */ |
| 11 | path?: string; |
| 12 | /** Read stdin from {@link body}. */ |
| 13 | stdin?: boolean; |
| 14 | /** Environment variables as `KEY=VALUE`. */ |
| 15 | env?: string[]; |
| 16 | /** Working directory. */ |
| 17 | dir?: string; |
| 18 | /** Stdin bytes when {@link stdin} is true. */ |
| 19 | body?: Uint8Array | string; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Run a command on a {@link Sprite} via `POST /sprites/{name}/exec`. |
| 24 | * |
| 25 | * |
| 26 | * ### Exec a command |
| 27 | * Bind the client in init. Provide {@link ExecHttp}. The Sprite name |
| 28 | * is fixed by `Exec(box)`. Alchemy transports that name and the |
| 29 | * deployment's org token to the caller automatically. |
| 30 | * |
| 31 | * **Example:** List files |
| 32 | * ```typescript |
| 33 | * const exec = yield* Fly.Exec(Box); |
| 34 | * const result = yield* exec({ cmd: ["ls", "-la"] }); |
| 35 | * ``` |
| 36 | * |
| 37 | * @binding |
| 38 | * @product Sprite |
| 39 | */ |
| 40 | export interface Exec extends Binding.Service< |
| 41 | Exec, |
| 42 | "Fly.Exec", |
| 43 | ( |
| 44 | sprite: Sprite, |
| 45 | ) => Effect.Effect< |
| 46 | (request: ExecRequest) => Effect.Effect<ExecResult, ExecCommandError, RuntimeContext> |
| 47 | > |
| 48 | > {} |
| 49 | |
| 50 | export const Exec = Binding.Service<Exec>("Fly.Exec"); |