import { AuthError, authenticateRequest } from "@/lib/auth/server";
import { CatalogError, listGateModels } from "@/lib/chat/catalog";
const noStoreHeaders = { "Cache-Control": "no-store" };
export async function GET(request: Request): Promise<Response> {
try {
await authenticateRequest(request);
const authorization = request.headers.get("Authorization");
if (!authorization) throw new AuthError();
const models = await listGateModels(authorization, request.signal);
return Response.json({ models }, { headers: noStoreHeaders });
} catch (error) {
const status =
error instanceof AuthError ||
(error instanceof CatalogError && error.reason === "unauthorized")
? 401
: 503;
return Response.json(
{ error: status === 401 ? "Unauthorized" : "Каталог моделей временно недоступен" },
{ status, headers: noStoreHeaders },
);
}
}