//#region src/agent/image/generation/provider-registry.ts
/**
* Provider ids that must never be registered (defensive — guards against
* accidentally shadowing well-known internal namespaces / prototype keys).
*/
const UNSAFE_PROVIDER_IDS = new Set([
	"__proto__",
	"constructor",
	"prototype"
]);
const registry = /* @__PURE__ */ new Map();
const aliasIndex = /* @__PURE__ */ new Map();
function normalizeId(id) {
	return id.trim().toLowerCase();
}
function isExtensionDisabled(cfg, providerId) {
	if (!cfg) return false;
	const extensions = cfg?.extensions;
	if (!extensions || typeof extensions !== "object") return false;
	const entry = extensions[providerId];
	if (!entry || typeof entry !== "object") return false;
	return entry.enabled === false;
}
function registerImageGenerationProvider(provider) {
	if (!provider.id?.trim()) throw new Error("Image generation provider id is required");
	const id = normalizeId(provider.id);
	if (UNSAFE_PROVIDER_IDS.has(id)) throw new Error(`Image generation provider id is reserved: ${provider.id}`);
	for (const [alias, target] of [...aliasIndex.entries()]) if (target === id) aliasIndex.delete(alias);
	registry.set(id, provider);
	for (const aliasRaw of provider.aliases ?? []) {
		if (typeof aliasRaw !== "string") continue;
		const alias = normalizeId(aliasRaw);
		if (!alias || alias === id) continue;
		if (UNSAFE_PROVIDER_IDS.has(alias)) continue;
		if (registry.has(alias)) continue;
		aliasIndex.set(alias, id);
	}
}
/**
* Resolve a provider by id or alias.
*
* `cfg` is honoured to skip providers disabled via `cfg.extensions[<id>].enabled = false`.
*/
function getImageGenerationProvider(providerId, cfg) {
	if (typeof providerId !== "string") return void 0;
	const id = normalizeId(providerId);
	if (!id) return void 0;
	const direct = registry.get(id);
	if (direct) return isExtensionDisabled(cfg, direct.id) ? void 0 : direct;
	const aliasTarget = aliasIndex.get(id);
	if (!aliasTarget) return void 0;
	const aliased = registry.get(aliasTarget);
	if (!aliased) return void 0;
	return isExtensionDisabled(cfg, aliased.id) ? void 0 : aliased;
}
function listImageGenerationProviders(cfg) {
	const out = [];
	for (const provider of registry.values()) {
		if (isExtensionDisabled(cfg, provider.id)) continue;
		out.push(provider);
	}
	return out;
}
function listImageGenerationProvidersSummary(cfg) {
	return listImageGenerationProviders(cfg).map((provider) => ({
		id: provider.id,
		...provider.label ? { label: provider.label } : {},
		...provider.defaultModel ? { defaultModel: provider.defaultModel } : {},
		models: provider.models ?? (provider.defaultModel ? [provider.defaultModel] : []),
		...provider.aliases?.length ? { aliases: [...provider.aliases] } : {},
		...provider.capabilities ? { capabilities: provider.capabilities } : {},
		...provider.ui ? { ui: provider.ui } : {}
	}));
}
function clearImageGenerationRegistryForTests() {
	registry.clear();
	aliasIndex.clear();
}
//#endregion
export { clearImageGenerationRegistryForTests, getImageGenerationProvider, listImageGenerationProviders, listImageGenerationProvidersSummary, registerImageGenerationProvider };

//# sourceMappingURL=provider-registry.js.map