The best way to control Claude Code, Codex and more from any computer or phone

main
ts 50 lines 1.8 KB
Raw
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 InvokeCallee from "./invoke-callee.ts";
7
8 /**
9 * Public Effect-native Cloud Run Service that calls the private
10 * {@link InvokeCallee} through `GCP.Run.InvokeService`.
11 */
12 export default class InvokeCaller extends GCP.Function<InvokeCaller>()(
13 "InvokeCaller",
14 {
15 main: import.meta.url,
16 location: "us-central1",
17 invokerIamDisabled: true,
18 },
19 Effect.gen(function* () {
20 const callee = yield* GCP.Run.InvokeService(InvokeCallee);
21 return {
22 fetch: Effect.gen(function* () {
23 const request = yield* HttpServerRequest;
24 const path = new URL(request.originalUrl, "http://localhost").pathname;
25 if (path === "/rpc") {
26 const sum = yield* callee.add(2, 3);
27 const countdown = yield* callee.countdown(3).pipe(Stream.runCollect);
28 const viaClient = yield* callee.httpClient.get("/hello");
29 return yield* HttpServerResponse.json({
30 sum,
31 countdown: [...countdown],
32 viaClient: yield* viaClient.json,
33 });
34 }
35 const response =
36 path === "/post"
37 ? yield* callee.fetch("/echo", {
38 method: "POST",
39 headers: { "content-type": "text/plain" },
40 body: "ping",
41 })
42 : yield* callee.fetch("/hello");
43 return yield* HttpServerResponse.json({
44 status: response.status,
45 body: response.status === 200 ? yield* response.json : undefined,
46 });
47 }).pipe(Effect.orDie),
48 };
49 }).pipe(Effect.provide(GCP.Run.InvokeServiceHttp)),
50 ) {}