import { r as normalizeProviderId } from "./provider-id-DMd-TDFp.js";
import { f as resolveAmbientAgentCredentialsForDiscovery, m as resolveUsableAgentCredentialModes } from "./prepared-model-runtime.plugin-generation-B8ea1sCV.js";
import { r as prepareFullCatalogFacts } from "./prepared-model-runtime.full-catalog-CWJ7TZJh.js";
import { r as prepareImplicitProviderStaticCatalog } from "./models-config-BC3wDBI6.js";
import { a as listPreparedSyntheticAuthProviderRefs, i as prepareWorkspaceBuildGroup, n as prepareAgentCatalogSource, o as resolvePreparedSyntheticAuth } from "./prepared-model-runtime.facts-CofECT8p.js";
//#region src/agents/prepared-model-runtime.scoped-catalog.ts
async function prepareScopedReadOnlyModelCatalogWithMode(input, providerDiscoveryProviderIds, catalogMode) {
	const { agentFacts, pluginGeneration } = await prepareWorkspaceBuildGroup([input.readOnly ? input : {
		...input,
		readOnly: true
	}], catalogMode, { providerDiscoveryProviderIds });
	const agentFactsForInput = agentFacts[0];
	if (!agentFactsForInput) throw new Error("scoped prepared model catalog facts are missing");
	return (await prepareFullCatalogFacts(agentFactsForInput, pluginGeneration, catalogMode, await prepareAgentCatalogSource(agentFactsForInput, pluginGeneration, catalogMode, false, catalogMode === "live" ? { providerDiscoveryProviderIds } : {}))).modelCatalog;
}
/** Resolves provider-scoped, secret-free auth modes without live model discovery. */
async function prepareScopedReadOnlyModelAuthModes(input, providerDiscoveryProviderIds, pluginMetadataSnapshot) {
	const providerIds = [...new Set(providerDiscoveryProviderIds.map(normalizeProviderId).filter(Boolean))];
	const providers = (await prepareImplicitProviderStaticCatalog({
		config: input.config,
		env: input.env,
		pluginMetadataSnapshot,
		providerDiscoveryProviderIds: providerIds,
		staticCatalogProviderIds: providerIds,
		...input.workspaceDir ? { workspaceDir: input.workspaceDir } : {}
	})).providers ?? [];
	const modes = resolveUsableAgentCredentialModes(resolveAmbientAgentCredentialsForDiscovery({
		config: input.config,
		env: input.env,
		authoritativeSyntheticAuthProviderRefs: pluginMetadataSnapshot.owners.cliBackends.keys(),
		syntheticAuthProviderRefs: listPreparedSyntheticAuthProviderRefs(providers),
		resolveSyntheticAuth: (provider) => resolvePreparedSyntheticAuth({
			config: input.config,
			provider,
			providers
		}),
		...input.workspaceDir ? { workspaceDir: input.workspaceDir } : {}
	}));
	const scoped = {};
	for (const provider of providerIds) if (modes[provider]) scoped[provider] = modes[provider];
	return scoped;
}
/** Builds a request-scoped read-only catalog without executing live provider discovery. */
function prepareScopedReadOnlyModelCatalog(input, providerDiscoveryProviderIds) {
	return prepareScopedReadOnlyModelCatalogWithMode(input, providerDiscoveryProviderIds, "static");
}
/** Builds a request-scoped read-only catalog with live discovery for selected providers. */
function prepareScopedReadOnlyLiveModelCatalog(input, providerDiscoveryProviderIds) {
	return prepareScopedReadOnlyModelCatalogWithMode(input, providerDiscoveryProviderIds, "live");
}
//#endregion
export { prepareScopedReadOnlyModelAuthModes as n, prepareScopedReadOnlyModelCatalog as r, prepareScopedReadOnlyLiveModelCatalog as t };
