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 | |
| 4 | /** |
| 5 | * Shared HTTP scaffolding for the Polly runtime bindings. |
| 6 | * |
| 7 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 8 | * thin `Layer.effect(Cap, makePollyHttpBinding({ … }))` over the builder |
| 9 | * below. Everything except the operation and the IAM action is boilerplate. |
| 10 | * |
| 11 | * Per the `polly` service authorization reference, only the lexicon |
| 12 | * management actions (`GetLexicon`, `PutLexicon`, `DeleteLexicon`) support |
| 13 | * resource-level IAM (the `lexicon` resource type); the synthesis, task, |
| 14 | * and describe actions authorize on `Resource: ["*"]`, so the account-level |
| 15 | * builder grants on `*`. |
| 16 | */ |
| 17 | export const makePollyHttpBinding = <I extends object, A, E, R>(options: { |
| 18 | /** |
| 19 | * Short capability name used in the binding sid and runtime span, e.g. |
| 20 | * `"SynthesizeSpeech"`. |
| 21 | */ |
| 22 | capability: string; |
| 23 | /** IAM actions granted on `Resource: ["*"]`. */ |
| 24 | iamActions: readonly string[]; |
| 25 | /** The distilled operation implementing the capability. */ |
| 26 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 27 | }) => |
| 28 | Effect.gen(function* () { |
| 29 | const bind = yield* AWSBindings.Bind; |
| 30 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 31 | |
| 32 | return Effect.fn(function* () { |
| 33 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 34 | yield* bind`AWS.Polly.${options.capability}()`({ |
| 35 | policyStatements: [ |
| 36 | { |
| 37 | Effect: "Allow", |
| 38 | Action: [...options.iamActions], |
| 39 | Resource: ["*"], |
| 40 | }, |
| 41 | ], |
| 42 | }); |
| 43 | } |
| 44 | return Effect.fn(`AWS.Polly.${options.capability}`)(function* (request?: I) { |
| 45 | return yield* op((request ?? {}) as I); |
| 46 | }); |
| 47 | }); |
| 48 | }); |