@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, 06:00 UTC

main
ts 21 lines 966 Bytes
Raw
1 import { FunctionTriggerEnvelope } from "@alchemy.run/neon/FunctionTriggerEvent";
2 import * as Schema from "effect/Schema";
3
4 const events = new Map<string, FunctionTriggerEnvelope>();
5 export default {
6 async fetch(request: Request) {
7 if (new URL(request.url).pathname === "/events") return Response.json([...events.values()]);
8 if (request.method !== "POST") return new Response(null, { status: 405 });
9 const invocation = request.headers.get("x-neon-trigger-invocation-id");
10 if (!invocation) return new Response(null, { status: 403 });
11 let event: FunctionTriggerEnvelope;
12 try {
13 event = Schema.decodeUnknownSync(FunctionTriggerEnvelope)(await request.json());
14 } catch {
15 return new Response(null, { status: 400 });
16 }
17 if (event.invocation_id !== invocation) return new Response(null, { status: 400 });
18 if (!events.has(invocation)) events.set(invocation, event);
19 return new Response(null, { status: 204 });
20 },
21 };