export class ProviderRegistry {
    constructor() {
        Object.defineProperty(this, "providers", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: new Map()
        });
        Object.defineProperty(this, "modelDefinitions", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: new Map()
        });
        Object.defineProperty(this, "streamHandlers", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: new Map()
        });
        Object.defineProperty(this, "attachmentToolDefinitionsResolver", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: null
        });
    }
    registerProvider(provider) {
        const { kind } = provider.metadata;
        this.providers.set(kind, provider);
    }
    hasProvider(kind) {
        return this.providers.has(kind);
    }
    listProviders() {
        return Array.from(this.providers.values());
    }
    registerModelDefinition(definition) {
        if (!definition || !definition.id) {
            throw new Error('Attempted to register an invalid model definition. Ensure the provider plugin exports a definition with an id.');
        }
        this.modelDefinitions.set(definition.id, definition);
    }
    registerStreamHandler(kind, handler) {
        this.streamHandlers.set(kind, handler);
    }
    setAttachmentToolDefinitionsResolver(resolver) {
        this.attachmentToolDefinitionsResolver = resolver;
    }
    hasAttachmentToolDefinitionsResolver() {
        return this.attachmentToolDefinitionsResolver !== null;
    }
    getModelDefinition(kind) {
        return this.modelDefinitions.get(kind);
    }
    listModelDefinitions() {
        return Array.from(this.modelDefinitions.values());
    }
    getStreamHandler(kind) {
        return this.streamHandlers.get(kind);
    }
    getAttachmentToolDefinitions() {
        if (!this.attachmentToolDefinitionsResolver) {
            return [];
        }
        return [...this.attachmentToolDefinitionsResolver()];
    }
    getProvider(kind) {
        const provider = this.providers.get(kind);
        if (!provider) {
            throw new Error(`No chat provider registered for kind "${kind}"`);
        }
        return provider;
    }
    findProvider(kind) {
        return this.providers.get(kind);
    }
}
export const providerRegistry = new ProviderRegistry();
export const registerProvider = (provider) => {
    providerRegistry.registerProvider(provider);
};
export const hasProvider = (kind) => {
    return providerRegistry.hasProvider(kind);
};
export const listProviders = () => {
    return providerRegistry.listProviders();
};
export const getRegisteredProvider = (kind) => {
    return providerRegistry.getProvider(kind);
};
export const getOptionalRegisteredProvider = (kind) => {
    return providerRegistry.findProvider(kind);
};
export const registerModelDefinition = (definition) => {
    providerRegistry.registerModelDefinition(definition);
};
export const getRegisteredModelDefinition = (kind) => {
    return providerRegistry.getModelDefinition(kind);
};
export const listModelDefinitions = () => {
    return providerRegistry.listModelDefinitions();
};
export const registerStreamHandler = (kind, handler) => {
    providerRegistry.registerStreamHandler(kind, handler);
};
export const getRegisteredStreamHandler = (kind) => {
    return providerRegistry.getStreamHandler(kind);
};
export const setAttachmentToolDefinitionsResolver = (resolver) => {
    providerRegistry.setAttachmentToolDefinitionsResolver(resolver);
};
export const getAttachmentToolDefinitions = () => {
    return providerRegistry.getAttachmentToolDefinitions();
};
export const hasAttachmentToolDefinitionsResolver = () => {
    return providerRegistry.hasAttachmentToolDefinitionsResolver();
};
