import { loadBuiltInModels, mergeCustomModels } from "./model-registry-builtins.js";
import { loadCustomModelsFromPaths } from "./model-registry-custom-loader.js";
const OPENAI_COMPATIBLE_APIS = new Set(["openai-completions", "openai-responses"]);
export function loadModelRegistryModels(authStorage, modelsJsonPaths) {
    const { models: customModels, overrides, modelOverrides, providerRequestConfigs, modelRequestHeaders, error, } = loadCustomModelsFromPaths(modelsJsonPaths);
    const builtInModels = loadBuiltInModels(overrides, modelOverrides);
    const builtInProviders = new Set(builtInModels.map((model) => model.provider));
    const customOpenAICompatibleProviders = new Set(customModels
        .filter((model) => !builtInProviders.has(model.provider) && OPENAI_COMPATIBLE_APIS.has(model.api))
        .map((model) => model.provider));
    let combined = mergeCustomModels(builtInModels, customModels);
    for (const oauthProvider of authStorage.getOAuthProviders()) {
        const cred = authStorage.get(oauthProvider.id);
        if (cred?.type === "oauth" && oauthProvider.modifyModels) {
            combined = oauthProvider.modifyModels(combined, cred);
        }
    }
    return {
        modelOverrides,
        models: combined,
        providerRequestConfigs,
        modelRequestHeaders,
        builtInProviders,
        customOpenAICompatibleProviders,
        loadError: error,
    };
}
//# sourceMappingURL=model-registry-loader.js.map