/**
 * src/models/openai.ts
 * OpenAI provider — gpt-4o, gpt-4o-mini, o1, o3-mini, etc.
 *
 * Reads OPENAI_API_KEY from env. Model selection per-call via the `model`
 * argument; default is gpt-4o-mini (best price/perf for SMB workloads). The
 * dashboard's Settings tab lets the owner pick a different default per tier
 * by setting the identity_fact `preference.model.brain` (or `.flash` /
 * `.reasoning`). The failover chain auto-includes this provider when the key
 * is set.
 */
import { config } from '../config.js';
import { callOpenAICompatible, ModelError, } from './provider.js';
const OPENAI_BASE_URL = 'https://api.openai.com/v1';
export const OPENAI_MODELS = {
    // Latest flagship (Dec 2025 release tier)
    'gpt-4o': { in: 2.50, out: 10.00, ctx: 128_000, supports_tools: true, supports_vision: true },
    'gpt-4o-mini': { in: 0.15, out: 0.60, ctx: 128_000, supports_tools: true, supports_vision: true },
    'gpt-4.1': { in: 2.00, out: 8.00, ctx: 200_000, supports_tools: true, supports_vision: true },
    // Reasoning tier
    'o1': { in: 15.00, out: 60.00, ctx: 200_000, supports_tools: false, supports_vision: false },
    'o1-mini': { in: 3.00, out: 12.00, ctx: 128_000, supports_tools: false, supports_vision: false },
    'o3-mini': { in: 1.10, out: 4.40, ctx: 200_000, supports_tools: true, supports_vision: false },
    'o3': { in: 30.00, out: 60.00, ctx: 200_000, supports_tools: true, supports_vision: false },
};
const DEFAULT_MODEL = 'gpt-4o-mini';
export class OpenAIProvider {
    name = 'openai';
    model = DEFAULT_MODEL;
    async chat(messages, options = {}) {
        const apiKey = config.OPENAI_API_KEY;
        if (!apiKey) {
            throw new ModelError('OpenAI API key not configured (set OPENAI_API_KEY)', 503, this.model);
        }
        return callOpenAICompatible(OPENAI_BASE_URL, apiKey, this.model, messages, {
            temperature: options.temperature ?? 0.7,
            maxTokens: options.maxTokens ?? 4096,
            topP: options.topP,
            stop: options.stop,
            tools: options.tools,
            toolChoice: options.toolChoice,
            timeoutMs: options.timeoutMs,
        });
    }
    setModel(model) {
        if (!(model in OPENAI_MODELS)) {
            throw new Error(`Unknown OpenAI model: ${model}. Available: ${Object.keys(OPENAI_MODELS).join(', ')}`);
        }
        this.model = model;
    }
}
export const openai = new OpenAIProvider();
//# sourceMappingURL=openai.js.map