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

main
ts 52 lines 1.73 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 { CustomClass } from "./CustomClass.ts";
5 import type { PhraseSet } from "./PhraseSet.ts";
6
7 const makeNamedHttpBinding = <
8 Resource extends CustomClass | PhraseSet,
9 I,
10 A,
11 E,
12 Req = void,
13 >(options: {
14 tag: string;
15 iam: BindingIam;
16 operation: GcpHttpOp<I, A, E>;
17 toInput: (name: string, request: Req | undefined) => I;
18 }) =>
19 Effect.gen(function* () {
20 const bind = yield* GCPBindings.Bind;
21 const run = yield* GCPBindings.withCredentials(options.operation);
22 return Effect.fn(function* (resource: Resource) {
23 if (!globalThis.__ALCHEMY_RUNTIME__) {
24 yield* bind`${options.tag}(${resource})`({
25 iam: [grantFor(options.iam, resource.name)],
26 });
27 }
28 const name = yield* resource.name;
29 return Effect.fn(`${options.tag}(${resource.LogicalId})`)(function* (request?: Req) {
30 const resourceName = yield* name;
31 return yield* run(options.toInput(resourceName, request));
32 });
33 });
34 });
35
36 /**
37 * Shared HTTP scaffolding for Speech-to-Text bindings.
38 * NOT exported from index.ts.
39 */
40 export const makeCustomClassHttpBinding = <I, A, E, Req = void>(options: {
41 tag: string;
42 iam: BindingIam;
43 operation: GcpHttpOp<I, A, E>;
44 toInput: (name: string, request: Req | undefined) => I;
45 }) => makeNamedHttpBinding<CustomClass, I, A, E, Req>(options);
46
47 export const makePhraseSetHttpBinding = <I, A, E, Req = void>(options: {
48 tag: string;
49 iam: BindingIam;
50 operation: GcpHttpOp<I, A, E>;
51 toInput: (name: string, request: Req | undefined) => I;
52 }) => makeNamedHttpBinding<PhraseSet, I, A, E, Req>(options);