import { Ca as resolveProviderAuthAliasMap, Oa as loadPluginManifestRegistry } from "./env-Dlz8aQHP.js";

//#region src/secrets/provider-env-vars.ts
const CORE_PROVIDER_AUTH_ENV_VAR_CANDIDATES = {
	openai: ["OPENAI_API_KEY"],
	anthropic: ["ANTHROPIC_API_KEY"],
	google: ["GEMINI_API_KEY"],
	chutes: ["CHUTES_API_KEY", "CHUTES_OAUTH_TOKEN"],
	minimax: ["MINIMAX_API_KEY"],
	"minimax-cn": ["MINIMAX_API_KEY"],
	moonshot: ["MOONSHOT_API_KEY"],
	"kimi-coding": ["KIMI_API_KEY", "KIMICODE_API_KEY"],
	synthetic: ["SYNTHETIC_API_KEY"],
	venice: ["VENICE_API_KEY"],
	zai: ["ZAI_API_KEY", "Z_AI_API_KEY"],
	xiaomi: ["XIAOMI_API_KEY"],
	openrouter: ["OPENROUTER_API_KEY"],
	"cloudflare-ai-gateway": ["CLOUDFLARE_AI_GATEWAY_API_KEY"],
	litellm: ["LITELLM_API_KEY"],
	"vercel-ai-gateway": ["AI_GATEWAY_API_KEY"],
	opencode: ["OPENCODE_API_KEY", "OPENCODE_ZEN_API_KEY"],
	together: ["TOGETHER_API_KEY"],
	huggingface: ["HUGGINGFACE_HUB_TOKEN", "HF_TOKEN"],
	qianfan: ["QIANFAN_API_KEY"],
	xai: ["XAI_API_KEY"],
	mistral: ["MISTRAL_API_KEY"],
	volcengine: ["VOLCANO_ENGINE_API_KEY"],
	"volcengine-coding": ["VOLCANO_ENGINE_API_KEY"],
	"volcengine-plan": ["VOLCANO_ENGINE_API_KEY"],
	byteplus: ["BYTEPLUS_API_KEY"],
	"byteplus-coding": ["BYTEPLUS_API_KEY"],
	"byteplus-plan": ["BYTEPLUS_API_KEY"]
};
function appendUniqueEnvVarCandidates(target, providerId, keys) {
	const normalizedProviderId = providerId.trim();
	if (!normalizedProviderId || keys.length === 0) return;
	const bucket = target[normalizedProviderId] ??= [];
	const seen = new Set(bucket);
	for (const key of keys) {
		const normalizedKey = key.trim();
		if (!normalizedKey || seen.has(normalizedKey)) continue;
		seen.add(normalizedKey);
		bucket.push(normalizedKey);
	}
}
function resolveProviderEnvVarCandidates(params) {
	const candidates = Object.create(null);
	for (const [providerId, keys] of Object.entries(CORE_PROVIDER_AUTH_ENV_VAR_CANDIDATES)) appendUniqueEnvVarCandidates(candidates, providerId, keys);
	const registry = loadPluginManifestRegistry({
		config: params?.config,
		workspaceDir: params?.workspaceDir,
		env: params?.env
	});
	for (const plugin of registry.plugins) {
		if (!plugin.providerAuthEnvVars) continue;
		for (const [providerId, keys] of Object.entries(plugin.providerAuthEnvVars).toSorted(([left], [right]) => left.localeCompare(right))) appendUniqueEnvVarCandidates(candidates, providerId, keys);
	}
	const aliases = resolveProviderAuthAliasMap(params);
	for (const [alias, target] of Object.entries(aliases).toSorted(([left], [right]) => left.localeCompare(right))) {
		const keys = candidates[target];
		if (keys) appendUniqueEnvVarCandidates(candidates, alias, keys);
	}
	return candidates;
}
function resolveProviderEnvVars(params) {
	return resolveProviderEnvVarCandidates(params);
}
const PROVIDER_ENV_VARS = { ...resolveProviderEnvVars() };
function listKnownProviderAuthEnvVarNames(params) {
	return [...new Set(Object.values(resolveProviderEnvVars(params)).flatMap((keys) => keys))];
}
function listKnownSecretEnvVarNames(params) {
	return listKnownProviderAuthEnvVarNames(params);
}

//#endregion
export { listKnownSecretEnvVarNames as n, PROVIDER_ENV_VARS as t };