@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 48 lines 1.79 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import { inChatbotRegion } from "./internal.ts";
4
5 /**
6 * Shared scaffolding for AWS Chatbot HTTP bindings.
7 *
8 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
9 * thin `Layer.effect(Cap, makeChatbotAccountHttpBinding({ … }))` over the
10 * builder below. Everything except the operation and the IAM action list is
11 * boilerplate.
12 *
13 * Chatbot is offered in only four regions, so every operation runs through
14 * {@link inChatbotRegion} (ambient region when supported, else `us-east-2`).
15 *
16 * All Chatbot management operations bound here are account-scoped: the
17 * chat-identity and account-preference IAM actions do not support
18 * resource-level scoping, so the deploy-time half grants `actions` on `*`.
19 */
20 export const makeChatbotAccountHttpBinding = <I, A, E, R>(options: {
21 /** Fully-qualified binding tag, e.g. `AWS.Chatbot.GetAccountPreferences`. */
22 tag: string;
23 /** The distilled operation, invoked with the caller's request as-is. */
24 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
25 /** IAM actions granted on `*`. */
26 actions: readonly string[];
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`${options.tag}()`({
35 policyStatements: [
36 {
37 Effect: "Allow",
38 Action: [...options.actions],
39 Resource: ["*"],
40 },
41 ],
42 });
43 }
44 return Effect.fn(options.tag)(function* (request?: I) {
45 return yield* op((request ?? {}) as I).pipe(inChatbotRegion);
46 });
47 });
48 });