import { Emitter } from '../../../../base/common/event.js';
import { toDisposable } from '../../../../base/common/lifecycle.js';
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
const ILanguageModelsService = ( createDecorator('ILanguageModelsService'));
class LanguageModelsService {
    constructor() {
        this._providers = ( new Map());
        this._onDidChangeProviders = ( new Emitter());
        this.onDidChangeLanguageModels = this._onDidChangeProviders.event;
    }
    dispose() {
        this._onDidChangeProviders.dispose();
        this._providers.clear();
    }
    getLanguageModelIds() {
        return Array.from(( this._providers.keys()));
    }
    lookupLanguageModel(identifier) {
        return this._providers.get(identifier)?.metadata;
    }
    registerLanguageModelChat(identifier, provider) {
        if (( this._providers.has(identifier))) {
            throw new Error(`Chat response provider with identifier ${identifier} is already registered.`);
        }
        this._providers.set(identifier, provider);
        this._onDidChangeProviders.fire({ added: [provider.metadata] });
        return toDisposable(() => {
            if (this._providers.delete(identifier)) {
                this._onDidChangeProviders.fire({ removed: [identifier] });
            }
        });
    }
    makeLanguageModelChatRequest(identifier, from, messages, options, progress, token) {
        const provider = this._providers.get(identifier);
        if (!provider) {
            throw new Error(`Chat response provider with identifier ${identifier} is not registered.`);
        }
        return provider.provideChatResponse(messages, from, options, progress, token);
    }
}
export { ILanguageModelsService, LanguageModelsService };
