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

main
ts 54 lines 1.88 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared HTTP scaffolding for the CloudWatch Observability Admin runtime
6 * bindings.
7 *
8 * Every account-level Observability Admin read (`ListResourceTelemetry`,
9 * `GetTelemetryEvaluationStatus`, ...) targets account configuration rather
10 * than a discrete ARN, so each binding grants its action on
11 * `Resource: ["*"]`. The only variation between bindings is the distilled
12 * operation and the IAM action.
13 *
14 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
15 * a `Layer.effect(Cap, makeObservabilityAdminHttpBinding({ … }))`.
16 */
17 export const makeObservabilityAdminHttpBinding = <I, A, E, R>(options: {
18 /**
19 * Short capability name used in the binding sid and runtime span, e.g.
20 * `"ListResourceTelemetry"`.
21 */
22 capability: string;
23 /**
24 * IAM actions granted on `Resource: ["*"]` (account-level configuration
25 * reads have no resource ARN to scope to).
26 */
27 iamActions: readonly string[];
28 /**
29 * The distilled operation implementing the capability.
30 */
31 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
32 }) =>
33 Effect.gen(function* () {
34 const bind = yield* AWSBindings.Bind;
35 const op = yield* AWSBindings.withCredentials(options.operation);
36
37 return Effect.fn(function* () {
38 if (!globalThis.__ALCHEMY_RUNTIME__) {
39 yield* bind`AWS.ObservabilityAdmin.${options.capability}()`({
40 policyStatements: [
41 {
42 Effect: "Allow",
43 Action: [...options.iamActions],
44 // Account-level configuration reads have no resource ARN.
45 Resource: ["*"],
46 },
47 ],
48 });
49 }
50 return Effect.fn(`AWS.ObservabilityAdmin.${options.capability}`)(function* (request?: I) {
51 return yield* op(request ?? ({} as I));
52 });
53 });
54 });