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 { Endpoint } from "@distilled.cloud/aws"; |
| 2 | import * as Region from "@distilled.cloud/aws/Region"; |
| 3 | import * as sfn from "@distilled.cloud/aws/sfn"; |
| 4 | import type { SourceError } from "effect/ConfigProvider"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Layer from "effect/Layer"; |
| 7 | import { makeStateMachineArnHttpBinding } from "./BindingHttp.ts"; |
| 8 | import { StartSyncExecution } from "./StartSyncExecution.ts"; |
| 9 | |
| 10 | /** |
| 11 | * `StartSyncExecution` must target the `sync-states.{region}` endpoint |
| 12 | * (the Smithy `hostPrefix: "sync-"` endpoint trait) — the regular |
| 13 | * `states.{region}` endpoint rejects it. distilled applies the host |
| 14 | * prefix itself; the explicit Endpoint here additionally pins the |
| 15 | * correct host for runtimes bundled against a distilled build that |
| 16 | * predates host-prefix support. |
| 17 | */ |
| 18 | const startSyncExecutionOnSyncEndpoint = Effect.gen(function* () { |
| 19 | const regionEffect = yield* Region.Region; |
| 20 | // No region: no pin; the call itself then fails with MissingRegion. |
| 21 | const syncStatesEndpoint: Effect.Effect<string | undefined, SourceError> = regionEffect.pipe( |
| 22 | Effect.map((region): string | undefined => `https://sync-states.${region}.amazonaws.com`), |
| 23 | Effect.catchTag("Alchemy::AWS::MissingRegion", () => Effect.undefined), |
| 24 | ); |
| 25 | const op = yield* sfn.startSyncExecution; |
| 26 | // The endpoint must be pinned per call, not around the yield: the |
| 27 | // yield-time snapshot is only a fallback — the calling fiber's ambient |
| 28 | // `Endpoint` (e.g. the runtime's `Endpoint.fromEnv`) wins over it. |
| 29 | return (input: sfn.StartSyncExecutionInput) => |
| 30 | op(input).pipe(Effect.provideService(Endpoint.Endpoint, syncStatesEndpoint)); |
| 31 | }); |
| 32 | |
| 33 | export const StartSyncExecutionHttp = Layer.effect( |
| 34 | StartSyncExecution, |
| 35 | makeStateMachineArnHttpBinding({ |
| 36 | tag: "AWS.StepFunctions.StartSyncExecution", |
| 37 | operation: startSyncExecutionOnSyncEndpoint, |
| 38 | actions: ["states:StartSyncExecution"], |
| 39 | }), |
| 40 | ); |