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

main
ts 50 lines 1.81 KB
Raw
1 import * as autoscaling from "@distilled.cloud/aws/auto-scaling";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as AWSBindings from "../AWSBindings.ts";
5 import type { AutoScalingGroup } from "./AutoScalingGroup.ts";
6 import { Standby, type EnterStandbyRequest, type ExitStandbyRequest } from "./Standby.ts";
7
8 // Bespoke (not the shared scaffold): a multi-operation client over
9 // `enterStandby` + `exitStandby` behind one IAM grant.
10 export const StandbyHttp = Layer.effect(
11 Standby,
12 Effect.gen(function* () {
13 const bind = yield* AWSBindings.Bind;
14 const enter = yield* AWSBindings.withCredentials(autoscaling.enterStandby);
15 const exit = yield* AWSBindings.withCredentials(autoscaling.exitStandby);
16
17 return Effect.fn(function* (group: AutoScalingGroup) {
18 const AutoScalingGroupName = yield* group.autoScalingGroupName;
19 if (!globalThis.__ALCHEMY_RUNTIME__) {
20 yield* bind`AWS.AutoScaling.Standby(${group})`({
21 policyStatements: [
22 {
23 Effect: "Allow",
24 Action: ["autoscaling:EnterStandby", "autoscaling:ExitStandby"],
25 Resource: [group.autoScalingGroupArn],
26 },
27 ],
28 });
29 }
30 return {
31 enter: Effect.fn(`AWS.AutoScaling.EnterStandby(${group.LogicalId})`)(function* (
32 request: EnterStandbyRequest,
33 ) {
34 return yield* enter({
35 ...request,
36 AutoScalingGroupName: yield* AutoScalingGroupName,
37 });
38 }),
39 exit: Effect.fn(`AWS.AutoScaling.ExitStandby(${group.LogicalId})`)(function* (
40 request: ExitStandbyRequest,
41 ) {
42 return yield* exit({
43 ...request,
44 AutoScalingGroupName: yield* AutoScalingGroupName,
45 });
46 }),
47 };
48 });
49 }),
50 );