The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as transcribe from "@distilled.cloud/aws/transcribe"; |
| 2 | import * as Output from "alchemy/Output"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as AWSBindings from "../AWSBindings.ts"; |
| 6 | import type { Role } from "../IAM/Role.ts"; |
| 7 | import { CreateLanguageModel, type CreateLanguageModelRequest } from "./CreateLanguageModel.ts"; |
| 8 | |
| 9 | // Bespoke (not makeTranscribeRoleHttpBinding): CreateLanguageModel nests the |
| 10 | // data-access role inside `InputDataConfig.DataAccessRoleArn` rather than as |
| 11 | // a top-level request field. |
| 12 | export const CreateLanguageModelHttp = Layer.effect( |
| 13 | CreateLanguageModel, |
| 14 | Effect.gen(function* () { |
| 15 | const bind = yield* AWSBindings.Bind; |
| 16 | const createLanguageModel = yield* AWSBindings.withCredentials(transcribe.createLanguageModel); |
| 17 | |
| 18 | return Effect.fn(function* <Rl extends Role>(dataAccessRole: Rl) { |
| 19 | const RoleArn = yield* dataAccessRole.roleArn; |
| 20 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 21 | yield* bind`AWS.Transcribe.CreateLanguageModel(${dataAccessRole})`({ |
| 22 | policyStatements: [ |
| 23 | { |
| 24 | Effect: "Allow", |
| 25 | Action: ["transcribe:CreateLanguageModel"], |
| 26 | Resource: ["*"], |
| 27 | }, |
| 28 | // CRITICAL: without iam:PassRole on the data-access role, |
| 29 | // CreateLanguageModel fails only at runtime with an |
| 30 | // AccessDenied. |
| 31 | { |
| 32 | Effect: "Allow", |
| 33 | Action: ["iam:PassRole"], |
| 34 | Resource: [Output.interpolate`${dataAccessRole.roleArn}`], |
| 35 | Condition: { |
| 36 | StringEquals: { |
| 37 | "iam:PassedToService": "transcribe.amazonaws.com", |
| 38 | }, |
| 39 | }, |
| 40 | }, |
| 41 | ], |
| 42 | }); |
| 43 | } |
| 44 | return Effect.fn(`AWS.Transcribe.CreateLanguageModel(${dataAccessRole.LogicalId})`)( |
| 45 | function* (request: CreateLanguageModelRequest) { |
| 46 | return yield* createLanguageModel({ |
| 47 | ...request, |
| 48 | InputDataConfig: { |
| 49 | ...request.InputDataConfig, |
| 50 | DataAccessRoleArn: request.InputDataConfig.DataAccessRoleArn ?? (yield* RoleArn), |
| 51 | }, |
| 52 | }); |
| 53 | }, |
| 54 | ); |
| 55 | }); |
| 56 | }), |
| 57 | ); |