@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, 04:45 UTC

main
ts 63 lines 2.04 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as GCPBindings from "../GCPBindings.ts";
3 import { grantFor, type BindingIam, type GcpHttpOp } from "../HttpBinding.ts";
4 import type { Model } from "./Model.ts";
5 import type { ModelsVersion } from "./ModelsVersion.ts";
6
7 /**
8 * Shared HTTP scaffolding for AI Platform (legacy ML Engine) bindings.
9 * NOT exported from index.ts.
10 */
11 export const makeModelHttpBinding = <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* (model: Model) {
20 if (!globalThis.__ALCHEMY_RUNTIME__) {
21 yield* bind`${options.tag}(${model})`({
22 iam: [grantFor(options.iam, model.name)],
23 });
24 }
25 const name = yield* model.name;
26 return Effect.fn(`${options.tag}(${model.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 * Versions have no IAM policy of their own; `iam.on` (`ml.model`) is
37 * granted on the version's parent model.
38 */
39 export const makeVersionHttpBinding = <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* (version: ModelsVersion) {
48 if (!globalThis.__ALCHEMY_RUNTIME__) {
49 yield* bind`${options.tag}(${version})`({
50 iam: [grantFor(options.iam, version.model)],
51 });
52 }
53 const name = yield* version.name;
54 return Effect.fn(`${options.tag}(${version.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 });