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

main
ts 118 lines 3.91 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as GCPBindings from "../GCPBindings.ts";
3 import { type BindingIam, type GcpHttpOp, grantFor } from "../HttpBinding.ts";
4 import type { WorkstationCluster } from "./WorkstationCluster.ts";
5 import type { WorkstationClustersWorkstationConfig } from "./WorkstationClustersWorkstationConfig.ts";
6 import type { WorkstationClustersWorkstationConfigsWorkstation } from "./WorkstationClustersWorkstationConfigsWorkstation.ts";
7
8 /**
9 * Shared HTTP scaffolding for Cloud Workstations bindings.
10 * NOT exported from index.ts.
11 */
12 export const makeClusterHttpBinding = <I extends { name?: string }, A, E>(options: {
13 tag: string;
14 iam: BindingIam;
15 operation: GcpHttpOp<I, A, E>;
16 }) =>
17 Effect.gen(function* () {
18 const bind = yield* GCPBindings.Bind;
19 const run = yield* GCPBindings.withCredentials(options.operation);
20 return Effect.fn(function* (cluster: WorkstationCluster) {
21 if (!globalThis.__ALCHEMY_RUNTIME__) {
22 yield* bind`${options.tag}(${cluster})`({
23 iam: [grantFor(options.iam, cluster.name)],
24 });
25 }
26 const name = yield* cluster.name;
27 return Effect.fn(`${options.tag}(${cluster.LogicalId})`)(function* (
28 request?: Omit<I, "name">,
29 ) {
30 return yield* run({
31 ...(request as I),
32 name: yield* name,
33 } as I);
34 });
35 });
36 });
37
38 export const makeConfigHttpBinding = <I extends { name?: string }, A, E>(options: {
39 tag: string;
40 iam: BindingIam;
41 operation: GcpHttpOp<I, A, E>;
42 }) =>
43 Effect.gen(function* () {
44 const bind = yield* GCPBindings.Bind;
45 const run = yield* GCPBindings.withCredentials(options.operation);
46 return Effect.fn(function* (config: WorkstationClustersWorkstationConfig) {
47 if (!globalThis.__ALCHEMY_RUNTIME__) {
48 yield* bind`${options.tag}(${config})`({
49 iam: [grantFor(options.iam, config.name)],
50 });
51 }
52 const name = yield* config.name;
53 return Effect.fn(`${options.tag}(${config.LogicalId})`)(function* (
54 request?: Omit<I, "name">,
55 ) {
56 return yield* run({
57 ...(request as I),
58 name: yield* name,
59 } as I);
60 });
61 });
62 });
63
64 export const makeWorkstationHttpBinding = <I extends { name?: string }, A, E>(options: {
65 tag: string;
66 iam: BindingIam;
67 operation: GcpHttpOp<I, A, E>;
68 }) =>
69 Effect.gen(function* () {
70 const bind = yield* GCPBindings.Bind;
71 const run = yield* GCPBindings.withCredentials(options.operation);
72 return Effect.fn(function* (workstation: WorkstationClustersWorkstationConfigsWorkstation) {
73 if (!globalThis.__ALCHEMY_RUNTIME__) {
74 yield* bind`${options.tag}(${workstation})`({
75 iam: [grantFor(options.iam, workstation.name)],
76 });
77 }
78 const name = yield* workstation.name;
79 return Effect.fn(`${options.tag}(${workstation.LogicalId})`)(function* (
80 request?: Omit<I, "name">,
81 ) {
82 return yield* run({
83 ...(request as I),
84 name: yield* name,
85 } as I);
86 });
87 });
88 });
89
90 export const makeGenerateAccessTokenHttpBinding = <
91 I extends { workstation?: string },
92 A,
93 E,
94 >(options: {
95 tag: string;
96 iam: BindingIam;
97 operation: GcpHttpOp<I, A, E>;
98 }) =>
99 Effect.gen(function* () {
100 const bind = yield* GCPBindings.Bind;
101 const run = yield* GCPBindings.withCredentials(options.operation);
102 return Effect.fn(function* (workstation: WorkstationClustersWorkstationConfigsWorkstation) {
103 if (!globalThis.__ALCHEMY_RUNTIME__) {
104 yield* bind`${options.tag}(${workstation})`({
105 iam: [grantFor(options.iam, workstation.name)],
106 });
107 }
108 const name = yield* workstation.name;
109 return Effect.fn(`${options.tag}(${workstation.LogicalId})`)(function* (
110 request?: Omit<I, "workstation">,
111 ) {
112 return yield* run({
113 ...(request as I),
114 workstation: yield* name,
115 } as I);
116 });
117 });
118 });