import { __esmMin } from "../../_virtual/_rolldown/runtime.js";
import { createLogger } from "../utils/logger/index.js";
import { init_logger } from "../utils/logger.js";
//#region src/providers/plugin-registry.ts
function getProviderRegistry() {
	if (!globalRegistry) globalRegistry = new ProviderPluginRegistry();
	return globalRegistry;
}
function setProviderRegistry(registry) {
	globalRegistry = registry;
}
var log, ProviderPluginRegistry, globalRegistry;
var init_plugin_registry = __esmMin((() => {
	init_logger();
	log = createLogger("Provider:Registry");
	ProviderPluginRegistry = class {
		providers = /* @__PURE__ */ new Map();
		/**
		* Register a new provider
		*/
		register(provider) {
			if (this.providers.has(provider.id)) log.warn(`Provider "${provider.id}" already registered, overwriting`);
			if (!provider.id) throw new Error("Provider must have an id");
			if (!provider.name) throw new Error("Provider must have a name");
			if (!provider.createStream || typeof provider.createStream !== "function") throw new Error("Provider must implement createStream method");
			this.providers.set(provider.id, provider);
			log.info(`Registered provider: ${provider.name} (${provider.id})`);
		}
		/**
		* Get a provider by ID
		*/
		get(id) {
			return this.providers.get(id);
		}
		/**
		* List all registered providers
		*/
		listAll() {
			return Array.from(this.providers.values());
		}
		/**
		* Get models for a specific provider
		*/
		getModels(providerId) {
			return this.providers.get(providerId)?.models || [];
		}
		/**
		* Check if a provider is registered
		*/
		has(id) {
			return this.providers.has(id);
		}
		/**
		* Unregister a provider
		*/
		unregister(id) {
			const deleted = this.providers.delete(id);
			if (deleted) log.info(`Unregistered provider: ${id}`);
			return deleted;
		}
		/**
		* Get all available model IDs across all providers
		*/
		getAllModelIds() {
			const modelIds = [];
			for (const provider of this.providers.values()) for (const model of provider.models) modelIds.push(`${provider.id}:${model.id}`);
			return modelIds;
		}
		/**
		* Find a model across all providers
		*/
		findModel(modelId) {
			if (modelId.includes(":")) {
				const [providerId, actualModelId] = modelId.split(":");
				const provider = this.providers.get(providerId);
				if (provider) {
					const model = provider.models.find((m) => m.id === actualModelId);
					if (model) return {
						provider,
						model
					};
				}
			}
			for (const provider of this.providers.values()) {
				const model = provider.models.find((m) => m.id === modelId);
				if (model) return {
					provider,
					model
				};
			}
		}
		/**
		* Get provider by model ID
		*/
		getProviderForModel(modelId) {
			return this.findModel(modelId)?.provider;
		}
	};
	globalRegistry = null;
}));
//#endregion
init_plugin_registry();
export { ProviderPluginRegistry, getProviderRegistry, init_plugin_registry, setProviderRegistry };

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