import { BaseProvider } from "../BaseProvider.js";
import { DEFAULT_XAI_BASE_URL } from "../../constants.js";
import { XAIChat } from "./Chat.js";
import { XAIModels } from "./Models.js";
import { XAIStreaming } from "./Streaming.js";
import { Capabilities } from "./Capabilities.js";
import { XAIImage } from "./Image.js";
export class XAIProvider extends BaseProvider {
    options;
    baseUrl;
    chatHandler;
    streamingHandler;
    modelsHandler;
    imageHandler;
    capabilities = {
        supportsVision: (model) => Capabilities.supportsVision(model),
        supportsTools: (model) => Capabilities.supportsTools(model),
        supportsStructuredOutput: (model) => Capabilities.supportsStructuredOutput(model),
        supportsEmbeddings: (model) => Capabilities.supportsEmbeddings(model),
        supportsImageGeneration: (model) => Capabilities.supportsImageGeneration(model),
        supportsTranscription: (model) => Capabilities.supportsTranscription(model),
        supportsModeration: (model) => Capabilities.supportsModeration(model),
        supportsReasoning: (model) => Capabilities.supportsReasoning(model),
        supportsDeveloperRole: (_model) => false,
        getContextWindow: (model) => Capabilities.getContextWindow(model)
    };
    constructor(options) {
        super();
        this.options = options;
        this.baseUrl = options.baseUrl ?? DEFAULT_XAI_BASE_URL;
        this.chatHandler = new XAIChat(this.baseUrl, options.apiKey);
        this.streamingHandler = new XAIStreaming(this.baseUrl, options.apiKey);
        this.modelsHandler = new XAIModels(this.baseUrl, options.apiKey);
        this.imageHandler = new XAIImage(this.baseUrl, options.apiKey);
    }
    get id() {
        return "xai";
    }
    apiBase() {
        return this.baseUrl;
    }
    headers() {
        return {
            Authorization: `Bearer ${this.options.apiKey}`,
            "Content-Type": "application/json"
        };
    }
    providerName() {
        return "xAI";
    }
    defaultModel(_feature) {
        return "grok-2";
    }
    async chat(request) {
        return this.chatHandler.execute(request);
    }
    async *stream(request) {
        yield* this.streamingHandler.execute(request);
    }
    async listModels() {
        return this.modelsHandler.execute();
    }
    async paint(request) {
        return this.imageHandler.execute(request);
    }
}
