The best way to control Claude Code, Codex and more from any computer or phone

main
ts 53 lines 1.8 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import * as Effect from "effect/Effect";
3 import * as HttpServerResponse from "effect/http/HttpServerResponse";
4 import * as Layer from "effect/Layer";
5 import * as Stream from "effect/Stream";
6 import path from "pathe";
7 import { SourceAndResultQueues, SourceAndResultQueuesLive } from "./event-source-handler.ts";
8
9 const main = path.resolve(import.meta.dirname, "inline-event-source-handler.ts");
10
11 // The inline (non-class) form of `event-source-handler.ts`: the event source
12 // needs the `Function` host, which the implementation must be able to require.
13 export default AWS.Lambda.Function(
14 "InlineQueueEventSourceFunction",
15 { main, functionUrl: true },
16 Effect.gen(function* () {
17 const { source, result } = yield* SourceAndResultQueues;
18 const sink = yield* AWS.SQS.QueueSink(result);
19
20 yield* AWS.SQS.consumeQueueMessages(
21 source,
22 { batchSize: 10 },
23 Effect.fn(function* (event) {
24 yield* Stream.fromIterable(event.Records).pipe(
25 Stream.map((record) => ({ MessageBody: record.body })),
26 Stream.run(sink),
27 );
28 }),
29 );
30
31 const sourceQueueUrl = yield* source.queueUrl;
32 const sourceQueueArn = yield* source.queueArn;
33 const resultQueueUrl = yield* result.queueUrl;
34
35 return {
36 fetch: Effect.gen(function* () {
37 return yield* HttpServerResponse.json({
38 ok: true,
39 sourceQueueUrl: yield* sourceQueueUrl,
40 sourceQueueArn: yield* sourceQueueArn,
41 resultQueueUrl: yield* resultQueueUrl,
42 });
43 }).pipe(Effect.orDie),
44 };
45 }).pipe(
46 Effect.provide(
47 Layer.provideMerge(
48 Layer.mergeAll(AWS.Lambda.QueueEventSource, AWS.SQS.QueueSinkHttp),
49 Layer.mergeAll(AWS.SQS.SendMessageBatchHttp, SourceAndResultQueuesLive),
50 ),
51 ),
52 ),
53 );