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 Effect from "effect/Effect"; |
| 3 | import { HttpServerRequest } from "effect/http/HttpServerRequest"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | import * as Stream from "effect/Stream"; |
| 6 | import { Tweets } from "./bound-resources.ts"; |
| 7 | import { Static } from "./sidecars.ts"; |
| 8 | |
| 9 | /** |
| 10 | * Effect-native sidecar with RPC methods. It binds the `Static` sidecar |
| 11 | * and publishes to Pub/Sub as the service's account. Bound from |
| 12 | * {@link ./service-bound-container.ts}. |
| 13 | */ |
| 14 | export default class Worker extends GCP.Run.Container<Worker>()( |
| 15 | "Worker", |
| 16 | { |
| 17 | main: import.meta.url, |
| 18 | port: 3000, |
| 19 | startupProbe: { httpGet: { path: "/health" }, periodSeconds: 2, failureThreshold: 30 }, |
| 20 | }, |
| 21 | Effect.gen(function* () { |
| 22 | const tweets = yield* Tweets; |
| 23 | const publish = yield* GCP.PubSub.Publish(tweets); |
| 24 | const web = yield* GCP.Run.bindPort(Static, 80); |
| 25 | |
| 26 | return { |
| 27 | greet: (name: string) => Effect.succeed(`hello ${name}`), |
| 28 | count: () => Stream.make(1, 2, 3), |
| 29 | publish: (text: string) => |
| 30 | publish({ body: { messages: [{ data: btoa(text) }] } }).pipe( |
| 31 | Effect.map(({ messageIds }) => messageIds?.length ?? 0), |
| 32 | Effect.orDie, |
| 33 | ), |
| 34 | staticStatus: () => |
| 35 | web.client.get("/").pipe( |
| 36 | Effect.map((response) => response.status), |
| 37 | Effect.orDie, |
| 38 | ), |
| 39 | fetch: Effect.gen(function* () { |
| 40 | const request = yield* HttpServerRequest; |
| 41 | if (request.url.startsWith("/health")) return HttpServerResponse.text("worker ok"); |
| 42 | return HttpServerResponse.text("not found", { status: 404 }); |
| 43 | }), |
| 44 | }; |
| 45 | }).pipe(Effect.provide(GCP.PubSub.PublishHttp)), |
| 46 | ) {} |