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 Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | import type { PolicyStatement } from "../IAM/Policy.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared HTTP scaffolding for the Comprehend Medical runtime bindings. |
| 7 | * |
| 8 | * Comprehend Medical is a pure pay-per-call service: none of its actions |
| 9 | * support resource-level IAM, so every binding is account-level and grants |
| 10 | * its action(s) on `Resource: ["*"]`. The only variation between bindings is |
| 11 | * the distilled operation, the IAM action, and whether the operation passes |
| 12 | * a data-access role to the service (the `Start*Job` operations, which |
| 13 | * additionally need `iam:PassRole` scoped to |
| 14 | * `comprehendmedical.amazonaws.com`). |
| 15 | * |
| 16 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is |
| 17 | * a `Layer.effect(Cap, makeComprehendMedicalHttpBinding({ … }))`. |
| 18 | */ |
| 19 | export const makeComprehendMedicalHttpBinding = <I, A, E, R>(options: { |
| 20 | /** |
| 21 | * Short capability name used in the binding sid and runtime span, e.g. |
| 22 | * `"DetectEntitiesV2"`. |
| 23 | */ |
| 24 | capability: string; |
| 25 | /** |
| 26 | * IAM actions granted on `Resource: ["*"]` (Comprehend Medical has no |
| 27 | * resource-level IAM). |
| 28 | */ |
| 29 | iamActions: readonly string[]; |
| 30 | /** |
| 31 | * The distilled operation implementing the capability. |
| 32 | */ |
| 33 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 34 | /** |
| 35 | * Grant `iam:PassRole` (conditioned to `comprehendmedical.amazonaws.com`) |
| 36 | * so the function can hand the service the `DataAccessRoleArn` a batch job |
| 37 | * assumes to read/write S3. Set on the `Start*Job` bindings. |
| 38 | */ |
| 39 | passRole?: boolean; |
| 40 | }) => |
| 41 | Effect.gen(function* () { |
| 42 | const bind = yield* AWSBindings.Bind; |
| 43 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 44 | |
| 45 | return Effect.fn(function* () { |
| 46 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 47 | const policyStatements: PolicyStatement[] = [ |
| 48 | { |
| 49 | Effect: "Allow", |
| 50 | Action: [...options.iamActions], |
| 51 | // Comprehend Medical actions have no resource-level IAM. |
| 52 | Resource: ["*"], |
| 53 | }, |
| 54 | ]; |
| 55 | if (options.passRole) { |
| 56 | policyStatements.push({ |
| 57 | Effect: "Allow", |
| 58 | Action: ["iam:PassRole"], |
| 59 | Resource: ["*"], |
| 60 | Condition: { |
| 61 | StringEquals: { |
| 62 | "iam:PassedToService": "comprehendmedical.amazonaws.com", |
| 63 | }, |
| 64 | }, |
| 65 | }); |
| 66 | } |
| 67 | yield* bind`AWS.ComprehendMedical.${options.capability}()`({ |
| 68 | policyStatements, |
| 69 | }); |
| 70 | } |
| 71 | return Effect.fn(`AWS.ComprehendMedical.${options.capability}`)(function* (request: I) { |
| 72 | return yield* op(request); |
| 73 | }); |
| 74 | }); |
| 75 | }); |