import fs from 'node:fs/promises';
import { g as getLatencyRecording } from './latency-recordings-CqioXMQl.js';
import 'node:crypto';
import 'node:path';

function sourceIdFromUrl(url) {
  const raw = url.searchParams.get("source");
  if (!raw) return null;
  const trimmed = raw.trim();
  return trimmed || null;
}
const GET = async ({ params, url }) => {
  try {
    const conversationId = params.conversationId ?? "";
    if (!conversationId) {
      return new Response("Conversation id is required", { status: 400 });
    }
    const recording = await getLatencyRecording(conversationId, sourceIdFromUrl(url));
    if (!recording) {
      return new Response("Not found", { status: 404 });
    }
    const bytes = await fs.readFile(recording.audioPath);
    return new Response(new Uint8Array(bytes), {
      status: 200,
      headers: {
        "cache-control": "no-store",
        "content-length": String(bytes.byteLength),
        "content-type": recording.mimeType || "audio/wav"
      }
    });
  } catch (error) {
    console.error("Failed to load latency recording audio:", error);
    return new Response("Failed to load audio", { status: 500 });
  }
};

export { GET };
//# sourceMappingURL=_server.ts-CbcaMe9z.js.map
