UNPKG

@copilotkit/runtime

Version:

<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />

33 lines (31 loc) 1.15 kB
require("reflect-metadata"); //#region src/v2/runtime/handlers/handle-debug-events.ts function handleDebugEvents({ runtime, request }) { if (process.env.NODE_ENV === "production") return new Response("Not Found", { status: 404 }); if (!runtime.debugEventBus) return new Response("Debug event bus not available", { status: 503 }); const bus = runtime.debugEventBus; const encoder = new TextEncoder(); const stream = new TransformStream(); const writer = stream.writable.getWriter(); writer.write(encoder.encode(": connected\n\n")).catch(() => {}); const unsubscribe = bus.subscribe((envelope) => { if (request.signal.aborted) return; const line = `data: ${JSON.stringify(envelope)}\n\n`; writer.write(encoder.encode(line)).catch(() => {}); }); request.signal.addEventListener("abort", () => { unsubscribe(); writer.close().catch(() => {}); }); return new Response(stream.readable, { status: 200, headers: { "Content-Type": "text/event-stream", "Cache-Control": "no-cache", Connection: "keep-alive" } }); } //#endregion exports.handleDebugEvents = handleDebugEvents; //# sourceMappingURL=handle-debug-events.cjs.map