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

main
ts 82 lines 3.16 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import * as Effect from "effect/Effect";
3 import { serveProbes } from "../../bindingHost.ts";
4
5 /** Cluster → config → workstation, on the project's `default` network. */
6 export const Dev = Effect.gen(function* () {
7 const cluster = yield* GCP.Workstations.WorkstationCluster("Dev", {
8 location: "us-central1",
9 network: "default",
10 subnetwork: "default",
11 labels: { env: "test" },
12 });
13 const config = yield* GCP.Workstations.WorkstationClustersWorkstationConfig("Code", {
14 workstationCluster: cluster.name,
15 host: {
16 gceInstance: {
17 machineType: "e2-standard-2",
18 poolSize: 0,
19 bootDiskSizeGb: 30,
20 },
21 },
22 labels: { env: "test" },
23 });
24 const workstation = yield* GCP.Workstations.WorkstationClustersWorkstationConfigsWorkstation(
25 "Mine",
26 { workstationConfig: config.name, labels: { env: "test" } },
27 );
28 return { cluster, config, workstation };
29 });
30
31 /**
32 * Effect-native Cloud Run service exercising every Cloud Workstations
33 * binding as its own runtime service account. Deployed from
34 * {@link ../Bindings.test.ts}.
35 */
36 export default class WorkstationsBindingsHost extends GCP.Function<WorkstationsBindingsHost>()(
37 "WorkstationsBindingsHost",
38 { main: import.meta.url, invokerIamDisabled: true },
39 Effect.gen(function* () {
40 const { cluster, config, workstation } = yield* Dev;
41 const getCluster = yield* GCP.Workstations.GetWorkstationCluster(cluster);
42 const getConfig = yield* GCP.Workstations.GetWorkstationConfig(config);
43 const getWorkstation = yield* GCP.Workstations.GetWorkstation(workstation);
44 const generateAccessToken = yield* GCP.Workstations.GenerateAccessToken(workstation);
45 const start = yield* GCP.Workstations.StartWorkstation(workstation);
46 const stop = yield* GCP.Workstations.StopWorkstation(workstation);
47
48 return {
49 fetch: serveProbes({
50 getWorkstationCluster: getCluster().pipe(
51 Effect.map((live) => ({ name: live.name, network: live.network })),
52 ),
53 getWorkstationConfig: getConfig().pipe(
54 Effect.map((live) => ({
55 name: live.name,
56 machineType: live.host?.gceInstance?.machineType,
57 })),
58 ),
59 getWorkstation: getWorkstation().pipe(
60 Effect.map((live) => ({ name: live.name, state: live.state })),
61 ),
62 generateAccessToken: generateAccessToken({
63 body: { ttl: "600s" },
64 }).pipe(
65 Effect.map((token) => ({
66 hasToken: (token.accessToken ?? "").length > 0,
67 expireTime: token.expireTime,
68 })),
69 ),
70 startWorkstation: start().pipe(Effect.map((operation) => ({ name: operation.name }))),
71 stopWorkstation: stop().pipe(Effect.map((operation) => ({ name: operation.name }))),
72 }),
73 };
74 }).pipe(
75 Effect.provide(GCP.Workstations.GetWorkstationClusterHttp),
76 Effect.provide(GCP.Workstations.GetWorkstationConfigHttp),
77 Effect.provide(GCP.Workstations.GetWorkstationHttp),
78 Effect.provide(GCP.Workstations.GenerateAccessTokenHttp),
79 Effect.provide(GCP.Workstations.StartWorkstationHttp),
80 Effect.provide(GCP.Workstations.StopWorkstationHttp),
81 ),
82 ) {}