import { m as normalizeProviderModelIdWithPolicies, r as getCurrentPluginMetadataSnapshot, u as collectManifestModelIdNormalizationPolicies } from "./current-plugin-metadata-snapshot-CNb-bmep.js";
import { a as resolvePluginMetadataSnapshot } from "./plugin-metadata-snapshot-30GVjW7k.js";
//#region src/plugins/runtime-workspace-state.ts
const PLUGIN_REGISTRY_STATE = Symbol.for("nodmix.pluginRegistryState");
function getActivePluginRegistryWorkspaceDirFromState() {
	return globalThis[PLUGIN_REGISTRY_STATE]?.workspaceDir ?? void 0;
}
//#endregion
//#region src/plugins/manifest-model-id-normalization.ts
let cachedPolicies;
function resolveMetadataSnapshotForPolicies(params = {}) {
	const env = params.env ?? process.env;
	const workspaceDir = params.workspaceDir ?? getActivePluginRegistryWorkspaceDirFromState();
	if (params.config === void 0) {
		const currentSnapshot = getCurrentPluginMetadataSnapshot({
			env,
			workspaceDir,
			allowWorkspaceScopedSnapshot: true,
			requireDefaultDiscoveryContext: true
		});
		if (currentSnapshot) return {
			plugins: currentSnapshot.plugins,
			configFingerprint: currentSnapshot.configFingerprint,
			cacheable: true
		};
	}
	const snapshot = resolvePluginMetadataSnapshot({
		config: params.config ?? {},
		env,
		workspaceDir,
		allowWorkspaceScopedCurrent: true
	});
	return {
		plugins: snapshot.plugins,
		configFingerprint: snapshot.configFingerprint,
		cacheable: false
	};
}
function loadManifestModelIdNormalizationPolicies(params = {}) {
	if (params.plugins) return collectManifestModelIdNormalizationPolicies(params.plugins);
	const { plugins, configFingerprint, cacheable } = resolveMetadataSnapshotForPolicies(params);
	if (cacheable && configFingerprint && cachedPolicies?.configFingerprint === configFingerprint) return cachedPolicies.policies;
	const policies = collectManifestModelIdNormalizationPolicies(plugins);
	if (cacheable && configFingerprint) cachedPolicies = {
		configFingerprint,
		policies
	};
	return policies;
}
function normalizeProviderModelIdWithManifest(params) {
	return normalizeProviderModelIdWithPolicies({
		provider: params.provider,
		policies: loadManifestModelIdNormalizationPolicies(params),
		context: { modelId: params.context.modelId }
	});
}
//#endregion
export { normalizeProviderModelIdWithManifest as t };
