@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 63 lines 2.02 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 { Node } from "./Node.ts";
5 import type { QueuedResource } from "./QueuedResource.ts";
6
7 /**
8 * Shared HTTP scaffolding for Cloud TPU node bindings.
9 * NOT exported from index.ts.
10 */
11 export const makeTpuNodeHttpBinding = <I extends { name?: string }, A, E>(options: {
12 tag: string;
13 iam: BindingIam;
14 operation: GcpHttpOp<I, A, E>;
15 }) =>
16 Effect.gen(function* () {
17 const bind = yield* GCPBindings.Bind;
18 const run = yield* GCPBindings.withCredentials(options.operation);
19 return Effect.fn(function* (node: Node) {
20 if (!globalThis.__ALCHEMY_RUNTIME__) {
21 yield* bind`${options.tag}(${node})`({
22 iam: [grantFor(options.iam, node.name)],
23 });
24 }
25 const name = yield* node.name;
26 return Effect.fn(`${options.tag}(${node.LogicalId})`)(function* (request?: Omit<I, "name">) {
27 return yield* run({
28 ...(request as I),
29 name: yield* name,
30 } as I);
31 });
32 });
33 });
34
35 /**
36 * Shared HTTP scaffolding for Cloud TPU queued resource bindings.
37 * NOT exported from index.ts.
38 */
39 export const makeTpuQueuedResourceHttpBinding = <I extends { name?: string }, A, E>(options: {
40 tag: string;
41 iam: BindingIam;
42 operation: GcpHttpOp<I, A, E>;
43 }) =>
44 Effect.gen(function* () {
45 const bind = yield* GCPBindings.Bind;
46 const run = yield* GCPBindings.withCredentials(options.operation);
47 return Effect.fn(function* (resource: QueuedResource) {
48 if (!globalThis.__ALCHEMY_RUNTIME__) {
49 yield* bind`${options.tag}(${resource})`({
50 iam: [grantFor(options.iam, resource.name)],
51 });
52 }
53 const name = yield* resource.name;
54 return Effect.fn(`${options.tag}(${resource.LogicalId})`)(function* (
55 request?: Omit<I, "name">,
56 ) {
57 return yield* run({
58 ...(request as I),
59 name: yield* name,
60 } as I);
61 });
62 });
63 });