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, 04:45 UTC
| 1 | import * as Output from "alchemy/Output"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as GCPBindings from "../GCPBindings.ts"; |
| 4 | import { type BindingIam, type GcpHttpOp, grantFor } from "../HttpBinding.ts"; |
| 5 | import type { Instance } from "./Instance.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Shared HTTP scaffolding for Compute Engine instance bindings. |
| 9 | * NOT exported from index.ts. |
| 10 | */ |
| 11 | export const makeInstanceHttpBinding = < |
| 12 | I extends { instance?: string; zone?: string; project?: string }, |
| 13 | A, |
| 14 | E, |
| 15 | >(options: { |
| 16 | tag: string; |
| 17 | iam: BindingIam; |
| 18 | operation: GcpHttpOp<I, A, E>; |
| 19 | }) => |
| 20 | Effect.gen(function* () { |
| 21 | const bind = yield* GCPBindings.Bind; |
| 22 | const run = yield* GCPBindings.withCredentials(options.operation); |
| 23 | return Effect.fn(function* (instance: Instance) { |
| 24 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 25 | yield* bind`${options.tag}(${instance})`({ |
| 26 | iam: [ |
| 27 | grantFor( |
| 28 | options.iam, |
| 29 | Output.interpolate`projects/${instance.project}/zones/${instance.zone}/instances/${instance.instanceName}`, |
| 30 | ), |
| 31 | ], |
| 32 | }); |
| 33 | } |
| 34 | const instanceName = yield* instance.instanceName; |
| 35 | const zone = yield* instance.zone; |
| 36 | const project = yield* instance.project; |
| 37 | return Effect.fn(`${options.tag}(${instance.LogicalId})`)(function* ( |
| 38 | request?: Omit<I, "instance" | "zone" | "project">, |
| 39 | ) { |
| 40 | return yield* run({ |
| 41 | ...(request as I), |
| 42 | instance: yield* instanceName, |
| 43 | zone: yield* zone, |
| 44 | project: yield* project, |
| 45 | } as I); |
| 46 | }); |
| 47 | }); |
| 48 | }); |