import {
  getModels
} from "./chunk-6AIKJWPI.js";
import {
  jsonOk,
  routeWrap
} from "./chunk-KKJ5D3II.js";
import {
  notFound
} from "./chunk-EZYKRG4W.js";

// src/handlers/models.ts
function handleListModels(request) {
  return routeWrap(request, async ({ request: req }) => {
    const url = new URL(req.url);
    const engine = url.searchParams.get("engine") ?? void 0;
    const provider = url.searchParams.get("provider") ?? void 0;
    const q = url.searchParams.get("q") ?? void 0;
    const models = await getModels({ engine, provider, q });
    return jsonOk({ data: models });
  });
}
function handleGetModel(request, modelId) {
  return routeWrap(request, async () => {
    const models = await getModels({});
    const model = models.find((m) => m.id === modelId);
    if (!model) throw notFound(`model not found: ${modelId}`);
    return jsonOk(model);
  });
}

export {
  handleListModels,
  handleGetModel
};
