/**
 * src/models/kimi.ts
 * Moonshot Kimi provider — moonshot-v1, kimi-k2 (1T trillion-param MoE).
 *
 * Why Kimi: top-tier Chinese-trained model with strong multilingual handling
 * and exceptional 128k+ context windows. Useful for Saudi customers with
 * Mandarin-business ties (Chinese trading partners) and for very long
 * document processing.
 *
 * API is OpenAI-compatible. Reads MOONSHOT_API_KEY from env.
 */
import { config } from '../config.js';
import { callOpenAICompatible, ModelError, } from './provider.js';
const KIMI_BASE_URL = 'https://api.moonshot.ai/v1';
export const KIMI_MODELS = {
    // Standard Moonshot models (8k / 32k / 128k context)
    'moonshot-v1-8k': { in: 0.13, out: 0.13, ctx: 8_192, supports_tools: true, supports_vision: false },
    'moonshot-v1-32k': { in: 0.27, out: 0.27, ctx: 32_768, supports_tools: true, supports_vision: false },
    'moonshot-v1-128k': { in: 0.53, out: 0.53, ctx: 131_072, supports_tools: true, supports_vision: false },
    // K2 — the trillion-parameter MoE (Kimi 2)
    'kimi-k2-0711-preview': { in: 0.40, out: 1.20, ctx: 131_072, supports_tools: true, supports_vision: false },
    // K2 turbo — faster, cheaper variant
    'kimi-k2-turbo-preview': { in: 0.30, out: 0.90, ctx: 131_072, supports_tools: true, supports_vision: false },
};
const DEFAULT_MODEL = 'moonshot-v1-32k';
export class KimiProvider {
    name = 'kimi';
    model = DEFAULT_MODEL;
    async chat(messages, options = {}) {
        const apiKey = config.MOONSHOT_API_KEY;
        if (!apiKey) {
            throw new ModelError('Kimi (Moonshot) API key not configured (set MOONSHOT_API_KEY)', 503, this.model);
        }
        return callOpenAICompatible(KIMI_BASE_URL, apiKey, this.model, messages, {
            temperature: options.temperature ?? 0.6,
            maxTokens: options.maxTokens ?? 4096,
            topP: options.topP,
            stop: options.stop,
            tools: options.tools,
            toolChoice: options.toolChoice,
            timeoutMs: options.timeoutMs,
        });
    }
    setModel(model) {
        if (!(model in KIMI_MODELS)) {
            throw new Error(`Unknown Kimi model: ${model}. Available: ${Object.keys(KIMI_MODELS).join(', ')}`);
        }
        this.model = model;
    }
}
export const kimi = new KimiProvider();
//# sourceMappingURL=kimi.js.map