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 sqs from "@distilled.cloud/aws/sqs"; |
| 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 { Queue } from "./Queue.ts"; |
| 7 | import { StartMessageMoveTask, type StartMessageMoveTaskRequest } from "./StartMessageMoveTask.ts"; |
| 8 | |
| 9 | // Bespoke (not the shared scaffold): redrive spans TWO queues. The source |
| 10 | // (DLQ) needs the start/receive/delete/get-attributes actions, and the |
| 11 | // destination needs send/get-attributes — on `*` when no explicit |
| 12 | // destination is given, because "redrive to original source queues" targets |
| 13 | // queues unknowable at deploy time. |
| 14 | export const StartMessageMoveTaskHttp = Layer.effect( |
| 15 | StartMessageMoveTask, |
| 16 | Effect.gen(function* () { |
| 17 | const bind = yield* AWSBindings.Bind; |
| 18 | const startMessageMoveTask = yield* AWSBindings.withCredentials(sqs.startMessageMoveTask); |
| 19 | |
| 20 | return Effect.fn(function* (source: Queue, options?: { destination?: Queue }) { |
| 21 | const SourceArn = yield* source.queueArn; |
| 22 | const destination = options?.destination; |
| 23 | const DestinationArn = destination ? yield* destination.queueArn : undefined; |
| 24 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 25 | yield* bind`AWS.SQS.StartMessageMoveTask(${source})`({ |
| 26 | policyStatements: [ |
| 27 | { |
| 28 | Effect: "Allow", |
| 29 | Action: [ |
| 30 | "sqs:StartMessageMoveTask", |
| 31 | "sqs:ReceiveMessage", |
| 32 | "sqs:DeleteMessage", |
| 33 | "sqs:GetQueueAttributes", |
| 34 | ], |
| 35 | Resource: [Output.interpolate`${source.queueArn}`], |
| 36 | }, |
| 37 | { |
| 38 | Effect: "Allow", |
| 39 | Action: ["sqs:SendMessage", "sqs:GetQueueAttributes"], |
| 40 | Resource: [destination ? Output.interpolate`${destination.queueArn}` : "*"], |
| 41 | }, |
| 42 | ], |
| 43 | }); |
| 44 | } |
| 45 | return Effect.fn(`AWS.SQS.StartMessageMoveTask(${source.LogicalId})`)(function* ( |
| 46 | request?: StartMessageMoveTaskRequest, |
| 47 | ) { |
| 48 | return yield* startMessageMoveTask({ |
| 49 | ...request, |
| 50 | SourceArn: yield* SourceArn, |
| 51 | ...(DestinationArn !== undefined ? { DestinationArn: yield* DestinationArn } : {}), |
| 52 | }); |
| 53 | }); |
| 54 | }); |
| 55 | }), |
| 56 | ); |