/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { loadExtensionByName, loadExtensionConfig, } from '../../config/extension.js';
import { DebugLogger } from '@vybestack/llxprt-code-core';
const debugLogger = DebugLogger.getLogger('llxprt:extensions:utils');
/**
 * Loads an extension and its config by name.
 * Logs error and returns nulls if extension not found or config invalid.
 *
 * @param name - Extension name to load
 * @returns Object with extension and extensionConfig, or nulls if not found
 */
export async function getExtensionAndConfig(name) {
    const extension = loadExtensionByName(name, process.cwd());
    if (!extension) {
        debugLogger.error(`Extension "${name}" not found.`);
        return { extension: null, extensionConfig: null };
    }
    let extensionConfig;
    try {
        extensionConfig = await loadExtensionConfig({
            extensionDir: extension.path,
            workspaceDir: process.cwd(),
        });
    }
    catch (error) {
        debugLogger.error(`Could not load configuration for extension "${name}".`, error);
        return { extension: null, extensionConfig: null };
    }
    if (!extensionConfig) {
        debugLogger.error(`Could not load configuration for extension "${name}".`);
        return { extension: null, extensionConfig: null };
    }
    return { extension, extensionConfig };
}
//# sourceMappingURL=utils.js.map