import { mcpOfficialAdapter } from './mcp-official.js';
import { claudeMarketplaceAdapter } from './claude-marketplace.js';
import { smitheryAdapter } from './smithery.js';
import { skillsShAdapter } from './skills-sh.js';
import { githubUrlAdapter } from './github-url.js';
import { manualAdapter } from './manual.js';
import { RegistryError } from './types.js';
const adapters = [
    mcpOfficialAdapter,
    claudeMarketplaceAdapter,
    smitheryAdapter,
    skillsShAdapter,
    githubUrlAdapter,
    manualAdapter
];
export function listRegistrySources() {
    return adapters.map((adapter) => adapter.descriptor);
}
export function getRegistryAdapter(id) {
    const adapter = adapters.find((a) => a.descriptor.id === id);
    if (!adapter)
        throw new RegistryError(`Unknown registry source: ${id}`, 404);
    return adapter;
}
export async function searchAcrossRegistries(query, options = {}) {
    const sources = options.sources ?? adapters.map((a) => a.descriptor.id);
    const limit = options.limit ?? 100;
    const results = [];
    await Promise.all(sources.map(async (id) => {
        const adapter = adapters.find((a) => a.descriptor.id === id);
        if (!adapter)
            return;
        if (options.kind && !adapter.descriptor.kinds.includes(options.kind))
            return;
        try {
            const entries = await adapter.search(query, limit);
            for (const entry of entries) {
                if (!options.kind || entry.kind === options.kind)
                    results.push(entry);
            }
        }
        catch {
            // ignore individual registry failures so the others still produce results
        }
    }));
    return results.slice(0, limit);
}
export async function resolveInstallFromRegistry(source, entry) {
    const adapter = getRegistryAdapter(source);
    return adapter.resolveInstall(entry);
}
export { RegistryError };
//# sourceMappingURL=index.js.map