import { BaseProvider } from "../BaseProvider.js";
import { DEFAULT_OPENAI_BASE_URL } from "../../constants.js";
import { Capabilities } from "./Capabilities.js";
import { OpenAIChat } from "./Chat.js";
import { OpenAIStreaming } from "./Streaming.js";
import { OpenAIModels } from "./Models.js";
import { OpenAIImage } from "./Image.js";
import { OpenAITranscription } from "./Transcription.js";
import { OpenAIModeration } from "./Moderation.js";
import { OpenAIEmbedding } from "./Embedding.js";
export class OpenAIProvider extends BaseProvider {
    options;
    baseUrl;
    chatHandler;
    streamingHandler;
    modelsHandler;
    imageHandler;
    transcriptionHandler;
    moderationHandler;
    embeddingHandler;
    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) => Capabilities.supportsDeveloperRole(model),
        supportsPrediction: (model) => Capabilities.supportsPrediction(model),
        getContextWindow: (model) => Capabilities.getContextWindow(model) || null
    };
    constructor(options) {
        super();
        this.options = options;
        this.baseUrl = options.baseUrl ?? DEFAULT_OPENAI_BASE_URL;
        this.chatHandler = new OpenAIChat(this, options.apiKey);
        this.streamingHandler = new OpenAIStreaming(this, options.apiKey);
        this.modelsHandler = new OpenAIModels(this.baseUrl, options.apiKey);
        this.imageHandler = new OpenAIImage(this.baseUrl, options.apiKey);
        this.transcriptionHandler = new OpenAITranscription(this.baseUrl, options.apiKey);
        this.moderationHandler = new OpenAIModeration(this.baseUrl, options.apiKey);
        this.embeddingHandler = new OpenAIEmbedding(this.baseUrl, options.apiKey);
    }
    apiBase() {
        return this.baseUrl;
    }
    headers() {
        return {
            Authorization: `Bearer ${this.options.apiKey}`,
            "Content-Type": "application/json"
        };
    }
    providerName() {
        return "OpenAI";
    }
    defaultModel(feature) {
        switch (feature) {
            case "embedding":
                return "text-embedding-3-small";
            case "transcription":
                return "whisper-1";
            case "moderation":
                return "omni-moderation-latest";
            case "image":
                return "dall-e-3";
            default:
                return "gpt-4o";
        }
    }
    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);
    }
    async transcribe(request) {
        return this.transcriptionHandler.execute(request);
    }
    async moderate(request) {
        return this.moderationHandler.execute(request);
    }
    async embed(request) {
        return this.embeddingHandler.execute(request);
    }
}
