import { j as json } from './exports-D1quPX8S.js';
import { a3 as fetchProviderModels, aZ as resolveStackDir } from './src-CidJbygh.js';
import './utils-BSRjJDrZ.js';
import './chunk-CLZ62Ad-.js';
import 'node:module';
import './provider-constants-DPrj3yBX.js';
import './dist-DOFcG0Zp.js';
import 'node:fs';
import 'node:path';
import 'buffer';
import 'fs';
import 'path';
import 'node:child_process';
import 'node:url';
import 'node:crypto';
import 'events';
import 'node:events';
import 'node:stream';
import 'node:string_decoder';
import 'assert';
import 'zlib';
import 'node:assert';
import 'node:fs/promises';
import 'node:os';

//#region src/routes/api/setup/models/[provider]/+server.ts
var POST = async ({ params, request }) => {
	const provider = decodeURIComponent(params.provider);
	let body = {};
	try {
		body = await request.json();
	} catch {
		return json({
			ok: false,
			error: "invalid_json",
			message: "Request body must be valid JSON"
		}, { status: 400 });
	}
	const apiKey = typeof body.apiKey === "string" ? body.apiKey : "";
	const baseUrl = typeof body.baseUrl === "string" ? body.baseUrl : "";
	try {
		const result = await fetchProviderModels(provider, apiKey, baseUrl, resolveStackDir());
		if (result.status !== "ok") return json({
			ok: false,
			...result
		}, { status: 502 });
		return json({
			ok: true,
			...result
		});
	} catch (err) {
		return json({
			ok: false,
			error: "model_fetch_failed",
			message: String(err)
		}, { status: 500 });
	}
};

export { POST };
//# sourceMappingURL=_server.ts-Dl9rmY33.js.map
