import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js";
import { c as isRecord } from "./record-coerce-DItp3I4t.js";
import { _ as sortUniqueStrings } from "./string-normalization-e_fvmxMf.js";
import { n as discoverOpenClawPlugins } from "./discovery-DUKpMd1M.js";
import { i as parseModelCatalogRef } from "./model-catalog-refs-BdjEHOKQ.js";
import { t as createSubsystemLogger } from "./subsystem-CT-8ly4J.js";
import { i as getGatewayPluginMetadataSnapshot } from "./current-plugin-metadata-state-C9do4nKP.js";
import { n as loadPluginManifestRegistryCore } from "./manifest-registry-7OpYeIgh.js";
import { n as getCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot-DUwUqs5q.js";
import { n as isManifestPluginAvailableForControlPlane, o as loadManifestContractSnapshot, r as isManifestPluginOwnerAllowedByControlPlanePolicy, t as hasManifestContractValue } from "./manifest-contract-eligibility-B5yM4KNC.js";
import { a as resolveConfiguredTalkRealtimeProviderId, o as resolveConfiguredTalkSpeechProviderId } from "./talk-kxni9fig.js";
import { i as getPluginRuntimeGatewayRequestScope } from "./gateway-request-scope-Bj2ffrHm.js";
import { r as normalizeCapabilityProviderId } from "./provider-registry-shared-CYfJZ_PT.js";
import { t as withBundledPluginEnablementCompat } from "./bundled-compat-BSKjnqIT.js";
import { a as resolveRuntimePluginRegistry, c as loadOpenClawPluginsWithInternalOverrides } from "./loader-DLF0KUIe.js";
import { a as registryContainsRuntimePluginIds, n as getLoadedRuntimePluginRegistry } from "./active-runtime-registry-DZ1QGfzv.js";
import { i as getPluginRuntimeLoadContext, t as buildPluginRuntimeLoadOptions } from "./load-context-DNurcC7X.js";
//#region src/tts/voice-models.ts
function normalizeLowercaseString(value) {
	return normalizeOptionalString(value)?.toLowerCase();
}
function normalizeTimeoutMs(value) {
	return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : void 0;
}
function parseVoiceModelRef(value) {
	const parsed = typeof value === "string" ? parseModelCatalogRef(value) : null;
	return parsed ? {
		provider: parsed.provider,
		model: parsed.modelId
	} : void 0;
}
function sameProvider(left, right) {
	const normalizedLeft = normalizeLowercaseString(left);
	return Boolean(normalizedLeft && normalizedLeft === normalizeLowercaseString(right));
}
/** Match provider ids case-insensitively across canonical id and aliases. */
function providerMatchesId(provider, providerId) {
	return sameProvider(provider.id, providerId) || (provider.aliases ?? []).some((alias) => sameProvider(alias, providerId));
}
/** Find the provider metadata for a configured provider id or alias. */
function findVoiceModelProvider(params) {
	return params.providers.find((provider) => providerMatchesId(provider, params.providerId));
}
/** Return true when a provider advertises the requested model. */
function voiceProviderSupportsModel(provider, model) {
	if (!provider) return false;
	const normalizedModel = normalizeOptionalString(model);
	return [provider.defaultModel, ...provider.models ?? []].some((candidate) => normalizeOptionalString(candidate) === normalizedModel);
}
/** Parse primary/fallback voice model refs from config. */
function resolveVoiceModelRefs(config) {
	const voiceModel = config;
	if (typeof voiceModel === "string") {
		const parsed = parseVoiceModelRef(voiceModel);
		return parsed ? [parsed] : [];
	}
	if (typeof voiceModel !== "object" || voiceModel === null || Array.isArray(voiceModel)) return [];
	const timeoutMs = normalizeTimeoutMs(voiceModel.timeoutMs);
	const refs = [];
	const addRef = (value) => {
		const parsed = parseVoiceModelRef(value);
		if (parsed) refs.push({
			...parsed,
			...timeoutMs === void 0 ? {} : { timeoutMs }
		});
	};
	addRef(voiceModel.primary);
	if (Array.isArray(voiceModel.fallbacks)) for (const fallback of voiceModel.fallbacks) addRef(fallback);
	return refs;
}
/** Resolve configured voice model refs that are supported by known providers. */
function resolveSupportedVoiceModelRefs(params) {
	return resolveVoiceModelRefs(params.config).flatMap((ref) => {
		const provider = findVoiceModelProvider({
			providers: params.providers,
			providerId: ref.provider
		});
		if (!provider || params.providerId && !providerMatchesId(provider, params.providerId)) return [];
		return voiceProviderSupportsModel(provider, ref.model) ? [{
			...ref,
			provider: provider.id
		}] : [];
	});
}
/** Build ordered provider candidates from primary provider plus voice-model fallbacks. */
function resolveVoiceProviderCandidates(params) {
	const primary = findVoiceModelProvider({
		providers: params.providers,
		providerId: params.primaryProvider
	})?.id ?? params.primaryProvider;
	const candidates = [];
	const seenProviders = /* @__PURE__ */ new Set();
	const addCandidate = (candidate) => {
		candidates.push(candidate);
		seenProviders.add(candidate.provider);
	};
	const refs = resolveSupportedVoiceModelRefs({
		config: params.voiceModelConfig,
		providers: params.providers
	});
	const primaryRefs = refs.filter((ref) => ref.provider === primary);
	for (const voiceModel of primaryRefs) addCandidate({
		provider: primary,
		voiceModel
	});
	if (primaryRefs.length === 0) addCandidate({ provider: primary });
	for (const voiceModel of refs) if (voiceModel.provider !== primary) addCandidate({
		provider: voiceModel.provider,
		voiceModel
	});
	for (const provider of params.providers) if (!seenProviders.has(provider.id)) addCandidate({ provider: provider.id });
	return candidates;
}
/** Resolve only the primary provider candidate for direct synthesis paths. */
function resolvePrimaryVoiceProviderCandidate(params) {
	const provider = findVoiceModelProvider({
		providers: params.providers,
		providerId: params.primaryProvider
	})?.id ?? params.primaryProvider;
	const voiceModel = resolveSupportedVoiceModelRefs({
		config: params.voiceModelConfig,
		providers: params.providers,
		providerId: provider
	})[0];
	return voiceModel ? {
		provider,
		voiceModel
	} : { provider };
}
/** Read provider config by configured id, canonical id, or alias. */
function getVoiceProviderConfig(params) {
	const candidates = [
		normalizeOptionalString(params.configuredProviderId),
		params.provider.id,
		...params.provider.aliases ?? []
	].filter((key) => Boolean(key));
	const configuredKeys = Object.keys(params.providerConfigs);
	for (const candidate of candidates) {
		if (Object.hasOwn(params.providerConfigs, candidate)) return params.providerConfigs[candidate] ?? {};
		const normalizedCandidate = normalizeLowercaseString(candidate);
		const matchingKey = configuredKeys.find((key) => normalizeLowercaseString(key) === normalizedCandidate);
		if (matchingKey) return params.providerConfigs[matchingKey] ?? {};
	}
	return {};
}
//#endregion
//#region src/plugins/bundled-capability-runtime.ts
/** Loads capability providers through the canonical scoped plugin loader. */
const log = createSubsystemLogger("plugins");
function createCapabilityRegistrationRuntime(config) {
	return { config: {
		current: () => config,
		mutateConfigFile: async () => {
			throw new Error("Capability discovery cannot mutate plugin configuration.");
		},
		replaceConfigFile: async () => {
			throw new Error("Capability discovery cannot replace plugin configuration.");
		}
	} };
}
function loadBundledCapabilityRuntimeRegistry(params) {
	const { pluginIds: requestedPluginIds, ...loadOptions } = params;
	const env = params.env ?? process.env;
	const config = params.config?.plugins?.enabled === false ? params.config : withBundledPluginEnablementCompat({
		config: params.config,
		pluginIds: params.pluginIds
	}) ?? {};
	const snapshot = !params.discovery && !params.installRecords ? getGatewayPluginMetadataSnapshot() : void 0;
	const preparedRegistry = params.manifestRegistry ?? (snapshot ? snapshot.bundledManifestRegistry ?? {
		plugins: [],
		diagnostics: []
	} : void 0);
	const discovery = preparedRegistry ? void 0 : params.discovery ?? discoverOpenClawPlugins({
		env,
		workspaceDir: params.workspaceDir,
		installRecords: params.installRecords
	});
	const pluginIds = new Set(params.pluginIds);
	const manifestRegistry = preparedRegistry ?? loadPluginManifestRegistryCore({
		config,
		env,
		workspaceDir: params.workspaceDir,
		installRecords: params.installRecords,
		candidates: discovery?.candidates,
		diagnostics: discovery?.diagnostics
	});
	const scopedManifestRegistry = {
		plugins: manifestRegistry.plugins.filter((plugin) => plugin.origin === "bundled" && pluginIds.has(plugin.id)),
		diagnostics: manifestRegistry.diagnostics
	};
	return loadOpenClawPluginsWithInternalOverrides({
		...loadOptions,
		config,
		env,
		onlyPluginIds: [...requestedPluginIds],
		cache: false,
		activate: false,
		channelPluginLoadIntent: "full",
		manifestRegistry: scopedManifestRegistry,
		logger: {
			info: (message) => log.info(message),
			warn: (message) => log.warn(message),
			error: (message) => log.error(message),
			debug: (message) => log.debug(message)
		}
	}, {
		runtime: createCapabilityRegistrationRuntime(config),
		moduleLoader: {
			installNativeSdkResolver: false,
			loaderFilename: import.meta.url
		}
	});
}
//#endregion
//#region src/plugins/capability-provider-runtime.ts
function shouldMergeManifestProvidersWhenActive(key) {
	return key === "imageGenerationProviders" || key === "videoGenerationProviders" || key === "musicGenerationProviders";
}
function shouldSkipCapabilityResolution(params) {
	return params.cfg?.plugins?.enabled === false && params.key !== "speechProviders";
}
/** Loads the manifest snapshot used to resolve capability-provider ownership. */
function loadCapabilityManifestSnapshot(params) {
	if (params.pluginMetadataSnapshot) return params.pluginMetadataSnapshot;
	return loadManifestContractSnapshot({
		config: params.cfg,
		...params.workspaceDir ? { workspaceDir: params.workspaceDir } : {}
	});
}
function resolveCapabilityPluginIds(params) {
	const snapshot = loadCapabilityManifestSnapshot(params);
	const availableContractPlugins = snapshot.plugins.filter((plugin) => hasManifestContractValue({
		plugin,
		contract: params.key,
		value: params.providerId
	}) && isManifestPluginAvailableForControlPlane({
		snapshot,
		plugin,
		config: params.cfg,
		allowRestrictiveAllowlistBypass: params.key === "speechProviders" && params.cfg?.plugins?.enabled === false
	}));
	return {
		runtimePluginIds: sortUniqueStrings(availableContractPlugins.map((plugin) => plugin.id)),
		bundledCompatPluginIds: sortUniqueStrings(availableContractPlugins.filter((plugin) => plugin.origin === "bundled").map((plugin) => plugin.id))
	};
}
function createCapabilityProviderLoadOptions(params) {
	const pluginIds = params.resolution.bundledCompatPluginIds;
	const config = withBundledPluginEnablementCompat({
		config: params.cfg,
		pluginIds
	});
	const overrides = {
		...config === void 0 ? {} : { config },
		onlyPluginIds: params.resolution.runtimePluginIds,
		activate: false
	};
	return params.loadContext ? buildPluginRuntimeLoadOptions(params.loadContext, overrides) : overrides;
}
function resolveCapabilityLoadContext(registry, cfg) {
	const context = getPluginRuntimeLoadContext(registry);
	if (!context?.metadataSnapshot || context.env !== process.env) return;
	return getCurrentPluginMetadataSnapshot({
		config: cfg,
		workspaceDir: context.workspaceDir,
		...cfg === void 0 ? { requireDefaultDiscoveryContext: true } : {}
	}) === context.metadataSnapshot ? context : void 0;
}
function findProviderById(entries, providerId) {
	const normalizedProviderId = normalizeCapabilityProviderId(providerId);
	if (!normalizedProviderId) return;
	for (const entry of entries) {
		const provider = entry.provider;
		if (!isRecord(provider)) continue;
		if (typeof provider.id === "string" && normalizeCapabilityProviderId(provider.id) === normalizedProviderId) return entry.provider;
	}
	for (const entry of entries) {
		const provider = entry.provider;
		if (!isRecord(provider)) continue;
		if ((Array.isArray(provider.aliases) ? provider.aliases : []).some((alias) => typeof alias === "string" && normalizeCapabilityProviderId(alias) === normalizedProviderId)) return entry.provider;
	}
}
function mergeCapabilityProviderEntries(left, right) {
	const merged = /* @__PURE__ */ new Map();
	const unnamed = [];
	const addEntries = (entries) => {
		for (const entry of entries) {
			const provider = entry.provider;
			if (!provider.id) {
				unnamed.push(entry);
				continue;
			}
			if (!merged.has(provider.id)) merged.set(provider.id, entry);
		}
	};
	addEntries(left);
	addEntries(right);
	return [...merged.values(), ...unnamed];
}
function addObjectKeys(target, value) {
	if (typeof value !== "object" || value === null || Array.isArray(value)) return;
	for (const key of Object.keys(value)) {
		const normalized = key.trim().toLowerCase();
		if (normalized) target.add(normalized);
	}
}
function addStringValue(target, value) {
	if (typeof value !== "string") return;
	const normalized = value.trim().toLowerCase();
	if (normalized) target.add(normalized);
}
function addModelConfigProviderIds(target, value) {
	for (const ref of resolveVoiceModelRefs(value)) addStringValue(target, ref.provider);
}
function collectRequestedSpeechProviderIds(cfg, options) {
	const requested = /* @__PURE__ */ new Set();
	const tts = typeof cfg?.tts === "object" && cfg.tts !== null ? cfg.tts : void 0;
	addStringValue(requested, tts?.provider);
	addObjectKeys(requested, tts?.providers);
	addStringValue(requested, cfg && resolveConfiguredTalkSpeechProviderId(cfg));
	if (options.includeVoiceModel) addModelConfigProviderIds(requested, cfg?.agents?.defaults?.voiceModel);
	addObjectKeys(requested, cfg?.models?.providers);
	return requested;
}
function collectRequestedVoiceModelProviderIds(cfg) {
	const requested = /* @__PURE__ */ new Set();
	addModelConfigProviderIds(requested, cfg?.agents?.defaults?.voiceModel);
	return requested;
}
function addMediaModelProviders(target, value) {
	if (!Array.isArray(value)) return;
	for (const entry of value) if (typeof entry === "object" && entry !== null) addStringValue(target, entry.provider);
}
function collectRequestedMediaUnderstandingProviderIds(cfg) {
	const requested = /* @__PURE__ */ new Set();
	const media = cfg?.tools?.media;
	addMediaModelProviders(requested, media?.models);
	return requested;
}
function collectRequestedCapabilityProviderIds(params) {
	switch (params.key) {
		case "speechProviders": return collectRequestedSpeechProviderIds(params.cfg, { includeVoiceModel: params.includeVoiceModel ?? false });
		case "realtimeTranscriptionProviders": return params.includeVoiceModel ? collectRequestedVoiceModelProviderIds(params.cfg) : void 0;
		case "realtimeVoiceProviders": {
			const requested = params.includeVoiceModel ? collectRequestedVoiceModelProviderIds(params.cfg) : /* @__PURE__ */ new Set();
			addStringValue(requested, resolveConfiguredTalkRealtimeProviderId(params.cfg ?? {}));
			return requested.size > 0 ? requested : void 0;
		}
		case "mediaUnderstandingProviders": return collectRequestedMediaUnderstandingProviderIds(params.cfg);
		default: return;
	}
}
function nonEmptyRequestedProviders(requested) {
	return requested && requested.size > 0 ? requested : void 0;
}
function shouldScopeCapabilityLoadToRequestedProviders(key) {
	return key === "speechProviders" || key === "realtimeTranscriptionProviders" || key === "realtimeVoiceProviders";
}
function removeActiveProviderIds(requested, entries) {
	for (const entry of entries) {
		const provider = entry.provider;
		if (typeof provider.id === "string") requested.delete(provider.id.toLowerCase());
		if (Array.isArray(provider.aliases)) {
			for (const alias of provider.aliases) if (typeof alias === "string") requested.delete(alias.toLowerCase());
		}
	}
}
function filterLoadedProvidersForRequestedConfig(params) {
	if (params.key !== "speechProviders" && params.key !== "realtimeTranscriptionProviders" && params.key !== "realtimeVoiceProviders" && params.key !== "mediaUnderstandingProviders") return [];
	if (params.requested.size === 0) return [];
	return params.entries.filter((entry) => {
		const provider = entry.provider;
		if (typeof provider.id === "string" && params.requested.has(provider.id.toLowerCase())) return true;
		if (Array.isArray(provider.aliases)) return provider.aliases.some((alias) => typeof alias === "string" && params.requested.has(alias.toLowerCase()));
		return false;
	});
}
function resolveRequestedCapabilityPluginIds(params) {
	if (!params.requested || params.requested.size === 0) return;
	const runtimePluginIds = /* @__PURE__ */ new Set();
	const bundledCompatPluginIds = /* @__PURE__ */ new Set();
	for (const providerId of params.requested) {
		const resolution = resolveCapabilityPluginIds({
			key: params.key,
			cfg: params.cfg,
			providerId,
			pluginMetadataSnapshot: params.pluginMetadataSnapshot
		});
		for (const pluginId of resolution.runtimePluginIds) runtimePluginIds.add(pluginId);
		for (const pluginId of resolution.bundledCompatPluginIds) bundledCompatPluginIds.add(pluginId);
	}
	return runtimePluginIds.size > 0 ? {
		runtimePluginIds: sortUniqueStrings(runtimePluginIds),
		bundledCompatPluginIds: sortUniqueStrings(bundledCompatPluginIds)
	} : void 0;
}
function filterPolicyAllowedCapabilityProviders(params) {
	if (!params.cfg?.plugins) return params.entries;
	const origins = new Map((params.registry?.plugins ?? []).map((plugin) => [plugin.id, plugin.origin]));
	return params.entries.filter((entry) => {
		const origin = origins.get(entry.pluginId) ?? (params.bundledPluginIds?.has(entry.pluginId) ? "bundled" : "global");
		return isManifestPluginOwnerAllowedByControlPlanePolicy({
			plugin: {
				id: entry.pluginId,
				origin
			},
			config: params.cfg,
			allowRestrictiveAllowlistBypass: params.key === "speechProviders" && params.cfg?.plugins?.enabled === false
		});
	});
}
function loadCapabilityProviderEntries(params) {
	const allowedPluginIds = new Set(params.loadOptions.onlyPluginIds);
	const filterAllowedEntries = (registry) => (registry?.[params.key] ?? []).filter((entry) => allowedPluginIds.has(entry.pluginId));
	const scopedRegistry = getPluginRuntimeGatewayRequestScope()?.pluginRegistry;
	const entries = filterAllowedEntries((scopedRegistry ? registryContainsRuntimePluginIds(scopedRegistry, params.loadOptions.onlyPluginIds) ? scopedRegistry : void 0 : getLoadedRuntimePluginRegistry({
		env: params.loadOptions.env,
		loadOptions: params.loadOptions,
		workspaceDir: params.loadOptions.workspaceDir,
		requiredPluginIds: params.loadOptions.onlyPluginIds
	})) ?? resolveRuntimePluginRegistry(params.loadOptions));
	const missingRequested = params.requested && params.requested.size > 0 ? new Set(params.requested) : void 0;
	if (missingRequested) removeActiveProviderIds(missingRequested, entries);
	if (entries.length > 0 && (!missingRequested || missingRequested.size === 0)) return entries;
	if (params.bundledCompatPluginIds.length === 0) return entries;
	const captured = filterAllowedEntries(loadBundledCapabilityRuntimeRegistry({
		...params.loadOptions,
		pluginIds: params.bundledCompatPluginIds
	}));
	return entries.length > 0 ? mergeCapabilityProviderEntries(entries, captured) : captured;
}
function resolvePluginCapabilityProvider(params) {
	if (shouldSkipCapabilityResolution(params)) return;
	const activeRegistry = getPluginRuntimeGatewayRequestScope()?.pluginRegistry ?? getLoadedRuntimePluginRegistry();
	const activeProvider = findProviderById(filterPolicyAllowedCapabilityProviders({
		entries: activeRegistry?.[params.key] ?? [],
		registry: activeRegistry,
		cfg: params.cfg,
		key: params.key
	}), params.providerId);
	if (activeProvider) return activeProvider;
	const loadContext = resolveCapabilityLoadContext(activeRegistry, params.cfg);
	const pluginMetadataSnapshot = loadCapabilityManifestSnapshot({
		cfg: params.cfg,
		pluginMetadataSnapshot: loadContext?.metadataSnapshot
	});
	let pluginIds = resolveCapabilityPluginIds({
		key: params.key,
		cfg: params.cfg,
		providerId: params.providerId,
		pluginMetadataSnapshot
	});
	if (pluginIds.runtimePluginIds.length === 0) {
		pluginIds = resolveCapabilityPluginIds({
			key: params.key,
			cfg: params.cfg,
			pluginMetadataSnapshot
		});
		if (pluginIds.runtimePluginIds.length === 0) return;
	}
	const loadOptions = createCapabilityProviderLoadOptions({
		cfg: params.cfg,
		resolution: pluginIds,
		loadContext
	});
	return findProviderById(loadCapabilityProviderEntries({
		key: params.key,
		bundledCompatPluginIds: pluginIds.bundledCompatPluginIds,
		loadOptions,
		requested: /* @__PURE__ */ new Set([params.providerId.toLowerCase()])
	}), params.providerId);
}
function resolvePluginCapabilityProviders(params) {
	if (shouldSkipCapabilityResolution(params)) return [];
	const activeRegistry = getPluginRuntimeGatewayRequestScope()?.pluginRegistry ?? getLoadedRuntimePluginRegistry();
	const activeProviders = filterPolicyAllowedCapabilityProviders({
		entries: activeRegistry?.[params.key] ?? [],
		registry: activeRegistry,
		cfg: params.cfg,
		key: params.key
	});
	const missingRequestedProviders = activeProviders.length > 0 ? nonEmptyRequestedProviders(collectRequestedCapabilityProviderIds({
		key: params.key,
		cfg: params.cfg,
		includeVoiceModel: true
	})) : void 0;
	if (activeProviders.length > 0) {
		if (!missingRequestedProviders && !shouldMergeManifestProvidersWhenActive(params.key)) return activeProviders.map((entry) => entry.provider);
		if (missingRequestedProviders) {
			removeActiveProviderIds(missingRequestedProviders, activeProviders);
			if (missingRequestedProviders.size === 0) return activeProviders.map((entry) => entry.provider);
		}
	}
	const requestedProviders = missingRequestedProviders ?? (activeProviders.length === 0 ? nonEmptyRequestedProviders(collectRequestedCapabilityProviderIds({
		key: params.key,
		cfg: params.cfg
	})) : void 0);
	const requestedProviderLoadScope = requestedProviders && shouldScopeCapabilityLoadToRequestedProviders(params.key) ? requestedProviders : void 0;
	const loadContext = resolveCapabilityLoadContext(activeRegistry, params.cfg);
	const pluginMetadataSnapshot = loadCapabilityManifestSnapshot({
		cfg: params.cfg,
		pluginMetadataSnapshot: loadContext?.metadataSnapshot
	});
	const requestedPluginIds = resolveRequestedCapabilityPluginIds({
		key: params.key,
		cfg: params.cfg,
		requested: requestedProviderLoadScope,
		pluginMetadataSnapshot
	});
	const requestedProviderFilter = requestedProviders && (!shouldScopeCapabilityLoadToRequestedProviders(params.key) || requestedPluginIds) ? requestedProviders : void 0;
	const pluginIds = requestedPluginIds ?? resolveCapabilityPluginIds({
		key: params.key,
		cfg: params.cfg,
		pluginMetadataSnapshot
	});
	const loadOptions = createCapabilityProviderLoadOptions({
		cfg: params.cfg,
		resolution: pluginIds,
		loadContext
	});
	const loadedProviders = loadCapabilityProviderEntries({
		key: params.key,
		bundledCompatPluginIds: pluginIds.bundledCompatPluginIds,
		loadOptions,
		requested: requestedProviderFilter
	});
	const requestedLoadedProviders = requestedProviderFilter ? filterLoadedProvidersForRequestedConfig({
		key: params.key,
		requested: requestedProviderFilter,
		entries: loadedProviders
	}) : loadedProviders;
	return mergeCapabilityProviderEntries(activeProviders, activeProviders.length > 0 && missingRequestedProviders ? filterLoadedProvidersForRequestedConfig({
		key: params.key,
		requested: missingRequestedProviders,
		entries: requestedLoadedProviders
	}) : requestedLoadedProviders).map((entry) => entry.provider);
}
function prepareMediaCapabilityProviders(params) {
	const providers = (key) => {
		if (shouldSkipCapabilityResolution({
			key,
			cfg: params.cfg
		})) return [];
		const resolution = resolveCapabilityPluginIds({
			key,
			cfg: params.cfg,
			pluginMetadataSnapshot: params.pluginMetadataSnapshot
		});
		const requiredPluginIds = resolution.runtimePluginIds;
		if (requiredPluginIds.length === 0 && params.pluginMetadataSnapshot.plugins.some((plugin) => hasManifestContractValue({
			plugin,
			contract: key
		}))) return Object.freeze([]);
		if (!params.registry || !registryContainsRuntimePluginIds(params.registry, requiredPluginIds)) return;
		const eligiblePluginIds = new Set(requiredPluginIds);
		const availableEntries = filterPolicyAllowedCapabilityProviders({
			entries: params.registry[key],
			registry: params.registry,
			cfg: params.cfg,
			key,
			bundledPluginIds: new Set(resolution.bundledCompatPluginIds)
		});
		if (availableEntries.some((entry) => !eligiblePluginIds.has(entry.pluginId))) return;
		return Object.freeze(availableEntries.map((entry) => entry.provider));
	};
	return Object.freeze({
		mediaUnderstandingProviders: providers("mediaUnderstandingProviders"),
		imageGenerationProviders: providers("imageGenerationProviders"),
		videoGenerationProviders: providers("videoGenerationProviders"),
		musicGenerationProviders: providers("musicGenerationProviders")
	});
}
//#endregion
export { getVoiceProviderConfig as a, resolveSupportedVoiceModelRefs as c, voiceProviderSupportsModel as d, resolvePluginCapabilityProviders as i, resolveVoiceModelRefs as l, prepareMediaCapabilityProviders as n, providerMatchesId as o, resolvePluginCapabilityProvider as r, resolvePrimaryVoiceProviderCandidate as s, loadCapabilityManifestSnapshot as t, resolveVoiceProviderCandidates as u };
