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

main
ts 50 lines 1.89 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared HTTP scaffolding for the Service Quotas runtime bindings.
6 *
7 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
8 * thin `Layer.effect(Cap, makeServiceQuotasHttpBinding({ … }))` over the
9 * builder below. Everything except the operation and the IAM action is
10 * boilerplate.
11 *
12 * Service Quotas is a control-plane query service: none of its actions
13 * support resource-level IAM in a way a deploy-time binding could scope
14 * (quota codes are supplied at runtime), so every grant is on
15 * `Resource: ["*"]` and every binding is account-level (takes no resource).
16 */
17 export const makeServiceQuotasHttpBinding = <I extends object, A, E, R>(options: {
18 /**
19 * Short capability name used in the binding sid and runtime span, e.g.
20 * `"GetServiceQuota"`.
21 */
22 capability: string;
23 /** IAM actions granted on `Resource: ["*"]`. */
24 iamActions: readonly string[];
25 /** The distilled operation implementing the capability. */
26 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
27 }) =>
28 Effect.gen(function* () {
29 const bind = yield* AWSBindings.Bind;
30 const op = yield* AWSBindings.withCredentials(options.operation);
31
32 return Effect.fn(function* () {
33 if (!globalThis.__ALCHEMY_RUNTIME__) {
34 yield* bind`AWS.ServiceQuotas.${options.capability}()`({
35 policyStatements: [
36 {
37 Effect: "Allow",
38 Action: [...options.iamActions],
39 // Service Quotas actions have no deploy-time scopeable
40 // resource — quota ARNs are only known at runtime.
41 Resource: ["*"],
42 },
43 ],
44 });
45 }
46 return Effect.fn(`AWS.ServiceQuotas.${options.capability}`)(function* (request?: I) {
47 return yield* op((request ?? {}) as I);
48 });
49 });
50 });