import { c as normalizeOptionalString } from "./string-coerce-mnp54Vah.js";
import "./string-coerce-runtime-CmKEt2-v.js";
import { u as applyProviderConfigWithModelCatalogPreset } from "./provider-onboard-CouSiPmK.js";
import { d as resolveZaiBaseUrl, l as buildZaiCatalogModels, o as ZAI_DEFAULT_MODEL_ID, r as ZAI_CODING_DEFAULT_MODEL_ID } from "./model-definitions-CPkYEVYc.js";
//#region extensions/zai/onboard.ts
const ZAI_DEFAULT_MODEL_REF = `zai/${ZAI_DEFAULT_MODEL_ID}`;
function resolveZaiPresetBaseUrl(cfg, endpoint) {
	const existingProvider = cfg.models?.providers?.zai;
	const existingBaseUrl = normalizeOptionalString(existingProvider?.baseUrl) ?? "";
	return endpoint ? resolveZaiBaseUrl(endpoint) : existingBaseUrl || resolveZaiBaseUrl();
}
function resolveZaiModelId(params) {
	const explicitModelId = normalizeOptionalString(params?.modelId);
	if (explicitModelId) return explicitModelId;
	const baseUrl = normalizeOptionalString(params?.baseUrl)?.replace(/\/+$/, "");
	return params?.endpoint?.startsWith("coding-") || baseUrl === "https://api.z.ai/api/coding/paas/v4" || baseUrl === "https://open.bigmodel.cn/api/coding/paas/v4" ? ZAI_CODING_DEFAULT_MODEL_ID : ZAI_DEFAULT_MODEL_ID;
}
function applyZaiPreset(cfg, params, primaryModelRef) {
	const baseUrl = resolveZaiPresetBaseUrl(cfg, params?.endpoint);
	const modelRef = `zai/${resolveZaiModelId({
		...params,
		baseUrl
	})}`;
	return applyProviderConfigWithModelCatalogPreset(cfg, {
		providerId: "zai",
		api: "openai-completions",
		baseUrl,
		catalogModels: buildZaiCatalogModels(),
		aliases: [{
			modelRef,
			alias: "GLM"
		}],
		primaryModelRef
	});
}
function applyZaiProviderConfig(cfg, params) {
	return applyZaiPreset(cfg, params);
}
function applyZaiConfig(cfg, params) {
	const baseUrl = resolveZaiPresetBaseUrl(cfg, params?.endpoint);
	const modelId = resolveZaiModelId({
		...params,
		baseUrl
	});
	return applyZaiPreset(cfg, params, modelId === "glm-5.1" ? ZAI_DEFAULT_MODEL_REF : `zai/${modelId}`);
}
//#endregion
export { resolveZaiModelId as i, applyZaiConfig as n, applyZaiProviderConfig as r, ZAI_DEFAULT_MODEL_REF as t };
