import { BaseProvider } from "../BaseProvider.js";
import { DEFAULT_MISTRAL_BASE_URL } from "../../constants.js";
import { MistralChat } from "./Chat.js";
import { MistralModels } from "./Models.js";
import { MistralStreaming } from "./Streaming.js";
import { MistralEmbedding } from "./Embedding.js";
import { MistralCapabilities } from "./Capabilities.js";
import { MistralTranscription } from "./Transcription.js";
import { MistralModeration } from "./Moderation.js";
export class MistralProvider extends BaseProvider {
    options;
    baseUrl;
    chatHandler;
    streamingHandler;
    modelsHandler;
    embeddingHandler;
    transcriptionHandler;
    moderationHandler;
    capabilities = {
        supportsVision: (model) => MistralCapabilities.supportsVision(model),
        supportsTools: (model) => MistralCapabilities.supportsTools(model),
        supportsStructuredOutput: (model) => MistralCapabilities.supportsStructuredOutput(model),
        supportsEmbeddings: (model) => MistralCapabilities.supportsEmbeddings(model),
        supportsImageGeneration: (model) => MistralCapabilities.supportsImageGeneration(model),
        supportsTranscription: (model) => MistralCapabilities.supportsTranscription(model),
        supportsModeration: (model) => MistralCapabilities.supportsModeration(model),
        supportsReasoning: (model) => MistralCapabilities.supportsReasoning(model),
        supportsDeveloperRole: (_model) => false,
        getContextWindow: (model) => MistralCapabilities.getContextWindow(model)
    };
    constructor(options) {
        super();
        this.options = options;
        this.baseUrl = options.baseUrl ?? DEFAULT_MISTRAL_BASE_URL;
        this.chatHandler = new MistralChat(this.baseUrl, options.apiKey);
        this.streamingHandler = new MistralStreaming(this.baseUrl, options.apiKey);
        this.modelsHandler = new MistralModels(this.baseUrl, options.apiKey);
        this.embeddingHandler = new MistralEmbedding(this.baseUrl, options.apiKey);
        this.transcriptionHandler = new MistralTranscription(this.baseUrl, options.apiKey);
        this.moderationHandler = new MistralModeration(this.baseUrl, options.apiKey);
    }
    apiBase() {
        return this.baseUrl;
    }
    headers() {
        return {
            Authorization: `Bearer ${this.options.apiKey}`,
            "Content-Type": "application/json",
            Accept: "application/json"
        };
    }
    providerName() {
        return "Mistral";
    }
    defaultModel(feature) {
        if (feature === "embedding" || feature === "embeddings")
            return "mistral-embed";
        if (feature === "transcription")
            return "voxtral-mini-latest";
        if (feature === "moderation")
            return "mistral-moderation-latest";
        return "mistral-large-latest";
    }
    async chat(request) {
        return this.chatHandler.execute(request);
    }
    async *stream(request) {
        yield* this.streamingHandler.execute(request);
    }
    async listModels() {
        return this.modelsHandler.execute();
    }
    async embed(request) {
        return this.embeddingHandler.execute(request);
    }
    async transcribe(request) {
        return this.transcriptionHandler.execute(request);
    }
    async moderate(request) {
        return this.moderationHandler.execute(request);
    }
}
