import {
  buildOpenApiDocument
} from "./chunk-FVLI5FNJ.js";

// src/handlers/openapi.ts
function originFromRequest(request) {
  const headers = request.headers;
  const proto = headers.get("x-forwarded-proto") ?? new URL(request.url).protocol.replace(":", "");
  const host = headers.get("x-forwarded-host") ?? headers.get("host") ?? new URL(request.url).host;
  return `${proto}://${host}`;
}
function inferPathPrefix(request) {
  const url = new URL(request.url);
  if (url.searchParams.get("all") === "true") return void 0;
  if (url.pathname.startsWith("/anthropic/v1/")) return "/anthropic/v1";
  if (url.pathname.startsWith("/agentstep/v1/")) return "/agentstep/v1";
  if (url.pathname.startsWith("/google/v1beta/")) return "/google/v1beta";
  return void 0;
}
async function handleGetOpenApiSpec(request) {
  const serverUrl = originFromRequest(request);
  const pathPrefix = inferPathPrefix(request);
  const doc = buildOpenApiDocument({ serverUrl, pathPrefix });
  return Response.json(doc);
}

export {
  handleGetOpenApiSpec
};
