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
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import * as Cause from "effect/Cause"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as HttpClientRequest from "effect/http/HttpClientRequest"; |
| 5 | import { HttpServerRequest } from "effect/http/HttpServerRequest"; |
| 6 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 7 | import * as Stream from "effect/Stream"; |
| 8 | import Worker from "./container-worker.ts"; |
| 9 | |
| 10 | /** |
| 11 | * Cloud Run Service that binds the `Worker` sidecar and calls it over |
| 12 | * `localhost`. Deployed from {@link ../Service.test.ts}. |
| 13 | */ |
| 14 | export default class BoundContainerService extends GCP.Run.Service<BoundContainerService>()( |
| 15 | "BoundContainerService", |
| 16 | { |
| 17 | main: import.meta.url, |
| 18 | location: "us-central1", |
| 19 | invokerIamDisabled: true, |
| 20 | startupProbe: { httpGet: { path: "/health" }, periodSeconds: 2, failureThreshold: 30 }, |
| 21 | }, |
| 22 | Effect.gen(function* () { |
| 23 | const worker = yield* GCP.Run.bindContainer(Worker); |
| 24 | |
| 25 | return { |
| 26 | fetch: Effect.gen(function* () { |
| 27 | const request = yield* HttpServerRequest; |
| 28 | if (request.url.startsWith("/health")) return HttpServerResponse.text("ok"); |
| 29 | const greeting = yield* worker.greet("sam"); |
| 30 | const counts = yield* worker.count().pipe(Stream.runCollect); |
| 31 | const published = yield* worker.publish("from a sidecar"); |
| 32 | const staticStatus = yield* worker.staticStatus(); |
| 33 | const health = yield* worker.fetch(HttpClientRequest.get("/health")); |
| 34 | return yield* HttpServerResponse.json({ |
| 35 | greeting, |
| 36 | counts: [...counts], |
| 37 | published, |
| 38 | staticStatus, |
| 39 | health: yield* health.text, |
| 40 | }); |
| 41 | }).pipe( |
| 42 | // Surface the failing call in the response so a test failure shows it. |
| 43 | Effect.catchCause((cause) => |
| 44 | Effect.succeed(HttpServerResponse.text(Cause.pretty(cause), { status: 500 })), |
| 45 | ), |
| 46 | ), |
| 47 | }; |
| 48 | }), |
| 49 | ) {} |