@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 43 lines 1.58 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import * as HttpClientRequest from "effect/http/HttpClientRequest";
4 import * as Schedule from "effect/Schedule";
5 import { RemoteContainer } from "./remote-container.ts";
6
7 /**
8 * Durable Object backing one remote (non-effectful) container instance.
9 * `boot()` blocks until the container's HTTP server answers on its TCP port.
10 * NOTE: the authoritative cold-start clock runs in the Worker AROUND the whole
11 * DO call, so it also covers Durable Object construction.
12 */
13 export class RemoteObject extends Cloudflare.DurableObject<RemoteObject>()(
14 "BenchRemoteObject",
15 Effect.gen(function* () {
16 const container = yield* RemoteContainer;
17
18 return Effect.gen(function* () {
19 const port = yield* container.getTcpPort(8080);
20
21 return {
22 boot: () =>
23 Effect.gen(function* () {
24 const start = yield* Effect.sync(() => Date.now());
25 yield* container.start({ enableInternet: true });
26 yield* port.fetch(HttpClientRequest.get("http://container/")).pipe(
27 Effect.flatMap((r) => r.text),
28 Effect.retry({
29 schedule: Schedule.min([
30 Schedule.exponential("1 second"),
31 Schedule.spaced("5 seconds"),
32 ]),
33 times: 40,
34 }),
35 );
36 const readyMs = (yield* Effect.sync(() => Date.now())) - start;
37 return { readyMs };
38 }),
39 shutdown: () => container.destroy().pipe(Effect.ignore),
40 };
41 });
42 }),
43 ) {}