export class UnknownProviderError extends Error {
    providerType;
    constructor(providerType) {
        super(`Unsupported provider type: ${providerType}`);
        this.name = 'UnknownProviderError';
        this.providerType = providerType;
    }
}
export class DuplicateProviderError extends Error {
    providerType;
    constructor(providerType) {
        super(`Provider type "${providerType}" is already registered. Pass { replace: true } to override an existing registration.`);
        this.name = 'DuplicateProviderError';
        this.providerType = providerType;
    }
}
// Module-private state. Only the exported functions below can read/mutate.
const providers = new Map();
const capabilities = new Map();
/**
 * Central registry for LLM providers.
 *
 * Provider packages (@namzu/bedrock, @namzu/openai, etc.) export a
 * `register<Vendor>()` function that calls `ProviderRegistry.register()`
 * with a vendor-specific type string, provider class, and capabilities.
 *
 * The core sdk pre-registers `MockLLMProvider` under type `'mock'`.
 *
 * @example
 * ```ts
 * import { ProviderRegistry } from '@namzu/sdk'
 * import { registerBedrock } from '@namzu/bedrock'
 *
 * registerBedrock()
 *
 * const { provider, capabilities } = ProviderRegistry.create({
 *   type: 'bedrock',
 *   region: 'us-east-1',
 * })
 * ```
 */
export class ProviderRegistry {
    static register(type, ctor, caps, options) {
        if (providers.has(type) && !options?.replace) {
            throw new DuplicateProviderError(type);
        }
        providers.set(type, ctor);
        capabilities.set(type, caps);
    }
    static create(config) {
        const provider = ProviderRegistry.createProvider(config);
        const caps = ProviderRegistry.getCapabilities(config.type);
        return { provider, capabilities: caps };
    }
    static createProvider(config) {
        const Ctor = providers.get(config.type);
        if (!Ctor) {
            throw new UnknownProviderError(config.type);
        }
        return new Ctor(config);
    }
    static getCapabilities(type) {
        const caps = capabilities.get(type);
        if (!caps) {
            throw new UnknownProviderError(type);
        }
        return caps;
    }
    static isSupported(type) {
        return providers.has(type);
    }
    static unregister(type) {
        capabilities.delete(type);
        return providers.delete(type);
    }
    static listTypes() {
        return Array.from(providers.keys());
    }
}
/**
 * @internal — not exported from the package barrel. Do not use in production code.
 * Available to in-tree tests via relative import (`./provider/registry.js`).
 * External consumers cannot reach this because `@namzu/sdk` only exports `.`.
 */
export function __resetProviderRegistryInternal() {
    providers.clear();
    capabilities.clear();
}
//# sourceMappingURL=registry.js.map