import { i as normalizeProviderId } from "./provider-id-Dq06Bcx6.js";
import { D as listRegisteredEmbeddingProviders, E as getRegisteredEmbeddingProvider } from "./registry-DLXHHZd2.js";
import { n as resolvePluginCapabilityProvider, r as resolvePluginCapabilityProviders } from "./capability-provider-runtime-3FgFASr_.js";
//#region src/plugins/embedding-provider-runtime-shared.ts
function resolveConfiguredProviderConfig(providerId, cfg) {
	const providers = cfg?.models?.providers;
	if (!providers) return;
	const normalized = normalizeProviderId(providerId);
	return providers[providerId] ?? Object.entries(providers).find(([candidateId]) => normalizeProviderId(candidateId) === normalized)?.[1];
}
function readConfiguredProviderApiId(params) {
	const providerConfig = resolveConfiguredProviderConfig(params.providerId, params.cfg);
	if (!providerConfig) return;
	const normalized = normalizeProviderId(params.providerId);
	const api = providerConfig.api?.trim();
	const resolvedProviderId = api ? params.resolveApiProviderId?.(normalizeProviderId(api)) ?? normalizeProviderId(api) : params.resolveMissingApiProviderId?.(providerConfig);
	return resolvedProviderId && resolvedProviderId !== normalized ? resolvedProviderId : void 0;
}
function resolveRuntimeEmbeddingProviderLookupIds(params) {
	const ids = [params.id];
	const configuredProviderId = params.resolveConfiguredProviderId(params.id, params.cfg);
	if (configuredProviderId && !ids.some((candidate) => normalizeProviderId(candidate) === configuredProviderId)) ids.push(configuredProviderId);
	return ids;
}
function listRuntimeEmbeddingProviderAdapters(params) {
	const merged = new Map(params.registered.map((adapter) => [adapter.id, adapter]));
	const capabilityAdapters = resolvePluginCapabilityProviders({
		key: params.key,
		cfg: params.cfg
	});
	for (const adapter of capabilityAdapters) if (!merged.has(adapter.id)) merged.set(adapter.id, adapter);
	return [...merged.values()];
}
function getRuntimeEmbeddingProviderAdapter(params) {
	for (const candidateId of params.lookupIds) {
		const registered = params.getRegisteredProvider(candidateId);
		if (registered) return registered.adapter;
	}
	for (const candidateId of params.lookupIds) {
		const provider = resolvePluginCapabilityProvider({
			key: params.key,
			providerId: candidateId,
			cfg: params.cfg
		});
		if (provider) return provider;
	}
}
//#endregion
//#region src/plugins/embedding-provider-runtime.ts
const OPENAI_COMPATIBLE_EMBEDDING_PROVIDER_ID = "openai-compatible";
const OPENAI_COMPATIBLE_MODEL_APIS = new Set(["openai-completions", "openai-responses"]);
function listRegisteredEmbeddingProviderAdapters() {
	return listRegisteredEmbeddingProviders().map((entry) => entry.adapter);
}
function listEmbeddingProviders(cfg) {
	return listRuntimeEmbeddingProviderAdapters({
		key: "embeddingProviders",
		cfg,
		registered: listRegisteredEmbeddingProviderAdapters()
	});
}
function resolveConfiguredEmbeddingProviderId(providerId, cfg) {
	return readConfiguredProviderApiId({
		providerId,
		cfg,
		resolveApiProviderId: (normalizedApiId) => OPENAI_COMPATIBLE_MODEL_APIS.has(normalizedApiId) ? OPENAI_COMPATIBLE_EMBEDDING_PROVIDER_ID : normalizedApiId,
		resolveMissingApiProviderId: (providerConfig) => providerConfig.baseUrl?.trim() ? OPENAI_COMPATIBLE_EMBEDDING_PROVIDER_ID : void 0
	});
}
function resolveEmbeddingProviderLookupIds(id, cfg) {
	return resolveRuntimeEmbeddingProviderLookupIds({
		id,
		cfg,
		resolveConfiguredProviderId: resolveConfiguredEmbeddingProviderId
	});
}
function getEmbeddingProvider(id, cfg) {
	return getRuntimeEmbeddingProviderAdapter({
		key: "embeddingProviders",
		cfg,
		lookupIds: resolveEmbeddingProviderLookupIds(id, cfg),
		getRegisteredProvider: getRegisteredEmbeddingProvider
	});
}
//#endregion
export { readConfiguredProviderApiId as a, listRuntimeEmbeddingProviderAdapters as i, listEmbeddingProviders as n, resolveRuntimeEmbeddingProviderLookupIds as o, getRuntimeEmbeddingProviderAdapter as r, getEmbeddingProvider as t };
