@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 76 lines 2.83 KB
Raw
1 import * as Lambda from "@alchemy.run/aws/Lambda";
2 import * as Transfer from "@alchemy.run/aws/Transfer";
3 import * as Duration from "effect/Duration";
4 import * as Effect from "effect/Effect";
5 import { HttpServerRequest } from "effect/http/HttpServerRequest";
6 import * as HttpServerResponse from "effect/http/HttpServerResponse";
7 import * as Layer from "effect/Layer";
8 import * as Stream from "effect/Stream";
9 import path from "pathe";
10
11 const main = path.resolve(import.meta.dirname, "workflow-handler.ts");
12
13 /**
14 * Minimal ungated fixture: exercises the account-level
15 * `SendWorkflowStepState` binding and the `consumeFileTransferEvents`
16 * EventBridge event source without provisioning a (slow, hourly-billed)
17 * Transfer server.
18 */
19 export class TransferWorkflowTestFunction extends Lambda.Function<Lambda.Function>()(
20 "TransferWorkflowTestFunction",
21 ) {}
22
23 export default TransferWorkflowTestFunction.make(
24 {
25 main,
26 functionUrl: true,
27 timeout: Duration.seconds(30),
28 },
29 Effect.gen(function* () {
30 // Event source: subscribe the host to Transfer Family file-transfer
31 // events. The deploy proves the EventBridge rule + invoke permission
32 // wiring; Transfer publishes to the default bus automatically.
33 yield* Transfer.consumeFileTransferEvents(
34 { kinds: ["file-upload-completed", "file-upload-failed"] },
35 (events) =>
36 Stream.runForEach(events, (event) =>
37 Effect.log(`transfer ${event["detail-type"]}: ${event.detail.username}`),
38 ),
39 );
40
41 const sendWorkflowStepState = yield* Transfer.SendWorkflowStepState();
42
43 return {
44 fetch: Effect.gen(function* () {
45 const request = yield* HttpServerRequest;
46 const url = new URL(request.originalUrl);
47 const pathname = url.pathname;
48
49 if (request.method === "GET" && pathname === "/bindings") {
50 return yield* HttpServerResponse.json({
51 bound: ["sendWorkflowStepState"],
52 });
53 }
54
55 // Report a step state against a nonexistent workflow: proves the
56 // grant + call round-trips and the rejection is a typed tag.
57 if (request.method === "POST" && pathname === "/workflow-step") {
58 const sent = yield* sendWorkflowStepState({
59 WorkflowId: "w-1234567890abcdef0",
60 ExecutionId: "00000000-0000-0000-0000-000000000000",
61 Token: "MA==",
62 Status: "SUCCESS",
63 }).pipe(Effect.result);
64 return yield* HttpServerResponse.json(
65 sent._tag === "Success" ? { ok: true } : { ok: false, tag: sent.failure._tag },
66 );
67 }
68
69 return yield* HttpServerResponse.json(
70 { error: "Not found", method: request.method, pathname },
71 { status: 404 },
72 );
73 }).pipe(Effect.orDie),
74 };
75 }).pipe(Effect.provide(Layer.mergeAll(Lambda.EventSource, Transfer.SendWorkflowStepStateHttp))),
76 );