import { o as resolveAgentEffectiveModelPrimary } from "./agent-scope-93WG1XkL.js";
import { n as resolveDefaultAgentWorkspaceDir } from "./workspace-default-BmR9Qrdu.js";
import { c as resolveDefaultAgentId, o as resolveAgentWorkspaceDir } from "./agent-scope-config-DIAx4Oyb.js";
import { r as DEFAULT_PROVIDER } from "./defaults-mDjiWzE5.js";
import "./workspace-DTN6Y6b8.js";
import { t as loadModelCatalogForBrowse } from "./model-catalog-browse-BOIh07bn.js";
import { t as resolveVisibleModelCatalog } from "./model-catalog-visibility-C43GlHJs.js";
//#region src/gateway/server-methods/models-list-result.ts
let loggedSlowModelsListCatalog = false;
function resolveModelsListView(params) {
	return typeof params.view === "string" ? params.view : "default";
}
function omitRuntimeModelParams(entry) {
	const { params: _params, ...rest } = entry;
	return rest;
}
function omitRuntimeModelParamsFromCatalog(catalog) {
	return catalog.map(omitRuntimeModelParams);
}
async function buildModelsListResult(params) {
	const cfg = params.context.getRuntimeConfig();
	const agentId = params.agentId ?? resolveDefaultAgentId(cfg);
	const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId) ?? resolveDefaultAgentWorkspaceDir();
	const view = resolveModelsListView(params.params);
	const catalog = await loadModelCatalogForBrowse({
		cfg,
		view,
		loadCatalog: params.context.loadGatewayModelCatalog,
		onTimeout: (timeoutMs) => {
			if (loggedSlowModelsListCatalog) return;
			loggedSlowModelsListCatalog = true;
			params.context.logGateway.debug(`models.list continuing without model catalog after ${timeoutMs}ms`);
		}
	});
	if (view === "all") return { models: omitRuntimeModelParamsFromCatalog(catalog) };
	return { models: omitRuntimeModelParamsFromCatalog(await resolveVisibleModelCatalog({
		cfg,
		catalog,
		defaultProvider: DEFAULT_PROVIDER,
		defaultModel: resolveAgentEffectiveModelPrimary(cfg, agentId),
		agentId,
		workspaceDir,
		view,
		runtimeAuthDiscovery: false
	})) };
}
//#endregion
export { buildModelsListResult as t };
