import { d as getRequestId, r as requireAdmin, g as getOpenCodeClient, e as errorResponse, k as jsonResponse } from './helpers-kzwksNq1.js';
import { b as asRecord } from './coercion-TNFJisCC.js';
import './src-CidJbygh.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';
import './endpoints-UdQGgKsR.js';
import './state-fxN45gBp.js';

//#region src/lib/opencode/provider-models.ts
function sanitizeOpenCodeModels(models, fallbackProviderId) {
	if (!models || typeof models !== "object") return [];
	return Object.values(models).map((value) => asRecord(value)).filter((model) => typeof model?.id === "string").map((model) => {
		const id = model.id;
		return {
			id,
			name: typeof model.name === "string" ? model.name : id,
			family: typeof model.family === "string" ? model.family : "",
			providerID: typeof model.providerID === "string" ? model.providerID : fallbackProviderId,
			status: typeof model.status === "string" ? model.status : "active",
			capabilities: asRecord(model.capabilities) ?? {}
		};
	});
}
//#endregion
//#region src/routes/admin/opencode/providers/[id]/models/+server.ts
var GET = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const providerId = event.params.id;
	const result = await getOpenCodeClient().proxy("/provider");
	if (!result.ok) return errorResponse(result.status, result.code, result.message, {}, requestId);
	const provider = result.data.all?.find((p) => p.id === providerId);
	if (!provider) return errorResponse(404, "not_found", `Provider "${providerId}" not found`, {}, requestId);
	if (!provider.models) return jsonResponse(200, { models: [] }, requestId);
	return jsonResponse(200, { models: sanitizeOpenCodeModels(provider.models, providerId) }, requestId);
};

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