@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 51 lines 1.51 KB
Raw
1 import * as machines from "@distilled.cloud/fly-io/machines";
2 import * as Effect from "effect/Effect";
3 import * as Schedule from "effect/Schedule";
4
5 export const nginx = {
6 region: "iad",
7 image: "nginx:alpine",
8 guest: { cpus: 1, memoryMb: 256 },
9 };
10
11 /** Plain HTTP on port 80: Fly issues no TLS certificate for `.flycast`. */
12 export const httpService = {
13 protocol: "tcp",
14 internalPort: 80,
15 ports: [{ port: 80, handlers: ["http"] }],
16 autostart: true,
17 autostop: "off" as const,
18 };
19
20 /** Fetch `url` from inside a Machine until the body contains `expected`. */
21 export const fetchFrom = (
22 caller: { appName: string; machineId: string },
23 url: string,
24 expected = "Welcome to nginx",
25 ) =>
26 machines
27 .execMachine({
28 app_name: caller.appName,
29 machine_id: caller.machineId,
30 command: ["sh", "-c", `wget -qO- -T 5 ${url} || true`],
31 timeout: 15,
32 })
33 .pipe(
34 Effect.repeat({
35 schedule: Schedule.spaced("3 seconds"),
36 times: 20,
37 until: (result) => result.stdout?.includes(expected) === true,
38 }),
39 Effect.map((result) => result.stdout ?? ""),
40 );
41
42 /** Fetch `url` once from inside a Machine; returns the body or wget's error. */
43 export const fetchOnce = (caller: { appName: string; machineId: string }, url: string) =>
44 machines
45 .execMachine({
46 app_name: caller.appName,
47 machine_id: caller.machineId,
48 command: ["sh", "-c", `wget -qO- -T 5 ${url} 2>&1 || true`],
49 timeout: 15,
50 })
51 .pipe(Effect.map((result) => result.stdout ?? ""));