@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 93 lines 3.54 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import type { Endpoint } from "./Endpoint.ts";
4 import type { FeatureGroup } from "./FeatureGroup.ts";
5
6 /**
7 * Shared scaffolding for Amazon SageMaker HTTP bindings.
8 *
9 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
10 * a `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the two builders
11 * below. Everything except the operation, the IAM action list, and the
12 * request shaping is boilerplate.
13 */
14
15 /**
16 * Build the impl Effect for a SageMaker Feature Store data-plane operation
17 * scoped to a {@link FeatureGroup}: the deploy-time half grants `actions` on
18 * the bound feature group's ARN, and the runtime half injects the feature
19 * group's name into every request via `prepare`.
20 */
21 export const makeFeatureGroupHttpBinding = <Req, I, A, E, R>(options: {
22 /** Fully-qualified binding tag, e.g. `AWS.SageMaker.GetRecord`. */
23 tag: string;
24 /** The distilled operation. */
25 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
26 /** IAM actions granted on the feature group ARN. */
27 actions: readonly string[];
28 /** Shape the caller's request into the wire request (injecting the name). */
29 prepare: (request: Req, featureGroupName: string) => I;
30 }) =>
31 Effect.gen(function* () {
32 const bind = yield* AWSBindings.Bind;
33 const op = yield* AWSBindings.withCredentials(options.operation);
34
35 return Effect.fn(function* (featureGroup: FeatureGroup) {
36 const FeatureGroupName = yield* featureGroup.featureGroupName;
37 if (!globalThis.__ALCHEMY_RUNTIME__) {
38 yield* bind`${options.tag}(${featureGroup})`({
39 policyStatements: [
40 {
41 Effect: "Allow",
42 Action: [...options.actions],
43 Resource: [featureGroup.featureGroupArn],
44 },
45 ],
46 });
47 }
48 return Effect.fn(`${options.tag}(${featureGroup.LogicalId})`)(function* (request: Req) {
49 const featureGroupName = yield* FeatureGroupName;
50 return yield* op(options.prepare(request, featureGroupName));
51 });
52 });
53 });
54
55 /**
56 * Build the impl Effect for a SageMaker control-plane operation scoped to an
57 * {@link Endpoint}: the deploy-time half grants `actions` on the bound
58 * endpoint's ARN, and the runtime half injects the endpoint's name into
59 * every request.
60 */
61 export const makeEndpointHttpBinding = <I extends { EndpointName?: string }, A, E, R>(options: {
62 /** Fully-qualified binding tag, e.g. `AWS.SageMaker.DescribeEndpoint`. */
63 tag: string;
64 /** The distilled operation. */
65 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
66 /** IAM actions granted on the endpoint ARN. */
67 actions: readonly string[];
68 }) =>
69 Effect.gen(function* () {
70 const bind = yield* AWSBindings.Bind;
71 const op = yield* AWSBindings.withCredentials(options.operation);
72
73 return Effect.fn(function* (endpoint: Endpoint) {
74 const EndpointName = yield* endpoint.endpointName;
75 if (!globalThis.__ALCHEMY_RUNTIME__) {
76 yield* bind`${options.tag}(${endpoint})`({
77 policyStatements: [
78 {
79 Effect: "Allow",
80 Action: [...options.actions],
81 Resource: [endpoint.endpointArn],
82 },
83 ],
84 });
85 }
86 return Effect.fn(`${options.tag}(${endpoint.LogicalId})`)(function* (
87 request?: Omit<I, "EndpointName">,
88 ) {
89 const endpointName = yield* EndpointName;
90 return yield* op({ ...request, EndpointName: endpointName } as I);
91 });
92 });
93 });