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
| 1 | import * as Output from "alchemy/Output"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as AWSBindings from "../AWSBindings.ts"; |
| 4 | import type { Farm } from "./Farm.ts"; |
| 5 | import type { Queue } from "./Queue.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Shared scaffolding for AWS Deadline Cloud HTTP bindings. |
| 9 | * |
| 10 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is |
| 11 | * a `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the builders |
| 12 | * below. Everything except the operation, the IAM action list, and the |
| 13 | * injected identifiers is boilerplate. |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Build the impl Effect for a queue-scoped job operation. The runtime half |
| 18 | * injects the bound {@link Queue}'s `farmId` and `queueId` into every |
| 19 | * request; the deploy-time half grants `actions` on the queue's ARN and on |
| 20 | * its jobs (`{queueArn}/job/*`), since Deadline authorizes job-level actions |
| 21 | * (GetJob, UpdateJob, ListSteps, …) against the job resource. |
| 22 | */ |
| 23 | export const makeDeadlineQueueHttpBinding = < |
| 24 | I extends { farmId: string; queueId: string }, |
| 25 | A, |
| 26 | E, |
| 27 | R, |
| 28 | >(options: { |
| 29 | /** Fully-qualified binding tag, e.g. `AWS.Deadline.CreateJob`. */ |
| 30 | tag: string; |
| 31 | /** The distilled operation; `farmId`/`queueId` are injected. */ |
| 32 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 33 | /** IAM actions granted on the queue ARN and its jobs. */ |
| 34 | actions: readonly string[]; |
| 35 | }) => |
| 36 | Effect.gen(function* () { |
| 37 | const bind = yield* AWSBindings.Bind; |
| 38 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 39 | |
| 40 | return Effect.fn(function* (queue: Queue) { |
| 41 | const FarmId = yield* queue.farmId; |
| 42 | const QueueId = yield* queue.queueId; |
| 43 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 44 | yield* bind`${options.tag}(${queue})`({ |
| 45 | policyStatements: [ |
| 46 | { |
| 47 | Effect: "Allow", |
| 48 | Action: [...options.actions], |
| 49 | Resource: [queue.queueArn, queue.queueArn.pipe(Output.map((arn) => `${arn}/job/*`))], |
| 50 | }, |
| 51 | ], |
| 52 | }); |
| 53 | } |
| 54 | return Effect.fn(`${options.tag}(${queue.LogicalId})`)(function* ( |
| 55 | request?: Omit<I, "farmId" | "queueId">, |
| 56 | ) { |
| 57 | return yield* op({ |
| 58 | ...request, |
| 59 | farmId: yield* FarmId, |
| 60 | queueId: yield* QueueId, |
| 61 | } as I); |
| 62 | }); |
| 63 | }); |
| 64 | }); |
| 65 | |
| 66 | /** |
| 67 | * Build the impl Effect for a queue-scoped search operation |
| 68 | * (`SearchJobs`/`SearchSteps`/`SearchTasks` take a `queueIds` array rather |
| 69 | * than a single `queueId`). The runtime half injects the bound |
| 70 | * {@link Queue}'s `farmId` and `queueIds: [queueId]`; the deploy-time half |
| 71 | * grants `actions` on the queue's ARN and its jobs. |
| 72 | */ |
| 73 | export const makeDeadlineQueueSearchHttpBinding = < |
| 74 | I extends { farmId: string; queueIds: string[] }, |
| 75 | A, |
| 76 | E, |
| 77 | R, |
| 78 | >(options: { |
| 79 | /** Fully-qualified binding tag, e.g. `AWS.Deadline.SearchJobs`. */ |
| 80 | tag: string; |
| 81 | /** The distilled operation; `farmId`/`queueIds` are injected. */ |
| 82 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 83 | /** IAM actions granted on the queue ARN and its jobs. */ |
| 84 | actions: readonly string[]; |
| 85 | }) => |
| 86 | Effect.gen(function* () { |
| 87 | const bind = yield* AWSBindings.Bind; |
| 88 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 89 | |
| 90 | return Effect.fn(function* (queue: Queue) { |
| 91 | const FarmId = yield* queue.farmId; |
| 92 | const QueueId = yield* queue.queueId; |
| 93 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 94 | yield* bind`${options.tag}(${queue})`({ |
| 95 | policyStatements: [ |
| 96 | { |
| 97 | Effect: "Allow", |
| 98 | Action: [...options.actions], |
| 99 | Resource: [queue.queueArn, queue.queueArn.pipe(Output.map((arn) => `${arn}/job/*`))], |
| 100 | }, |
| 101 | ], |
| 102 | }); |
| 103 | } |
| 104 | return Effect.fn(`${options.tag}(${queue.LogicalId})`)(function* ( |
| 105 | request?: Omit<I, "farmId" | "queueIds">, |
| 106 | ) { |
| 107 | return yield* op({ |
| 108 | ...request, |
| 109 | farmId: yield* FarmId, |
| 110 | queueIds: [yield* QueueId], |
| 111 | } as I); |
| 112 | }); |
| 113 | }); |
| 114 | }); |
| 115 | |
| 116 | /** |
| 117 | * Build the impl Effect for a farm-scoped operation (usage statistics |
| 118 | * aggregations). The runtime half injects the bound {@link Farm}'s `farmId`; |
| 119 | * the deploy-time half grants `actions` on the farm's ARN and everything |
| 120 | * under it (queues/fleets referenced by the aggregation's `resourceIds`). |
| 121 | */ |
| 122 | export const makeDeadlineFarmHttpBinding = <I extends { farmId: string }, A, E, R>(options: { |
| 123 | /** Fully-qualified binding tag, e.g. `AWS.Deadline.GetSessionsStatisticsAggregation`. */ |
| 124 | tag: string; |
| 125 | /** The distilled operation; `farmId` is injected. */ |
| 126 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 127 | /** IAM actions granted on the farm ARN and its sub-resources. */ |
| 128 | actions: readonly string[]; |
| 129 | }) => |
| 130 | Effect.gen(function* () { |
| 131 | const bind = yield* AWSBindings.Bind; |
| 132 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 133 | |
| 134 | return Effect.fn(function* (farm: Farm) { |
| 135 | const FarmId = yield* farm.farmId; |
| 136 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 137 | yield* bind`${options.tag}(${farm})`({ |
| 138 | policyStatements: [ |
| 139 | { |
| 140 | Effect: "Allow", |
| 141 | Action: [...options.actions], |
| 142 | Resource: [farm.farmArn, farm.farmArn.pipe(Output.map((arn) => `${arn}/*`))], |
| 143 | }, |
| 144 | ], |
| 145 | }); |
| 146 | } |
| 147 | return Effect.fn(`${options.tag}(${farm.LogicalId})`)(function* ( |
| 148 | request?: Omit<I, "farmId">, |
| 149 | ) { |
| 150 | return yield* op({ ...request, farmId: yield* FarmId } as I); |
| 151 | }); |
| 152 | }); |
| 153 | }); |