export const DEFAULT_THINKING_LEVELS = ["medium", "high", "xhigh", "max"];
const PROVIDER_LEVELS = {
    kimi: ["medium", "high", "xhigh", "max"],
    mimo: ["medium", "high", "xhigh", "max"],
    deepseek: ["off", "high", "xhigh", "max"],
    qwen: ["off", "medium", "high", "max"],
    openrouter: ["minimal", "low", "medium", "high", "xhigh", "max"],
    codex: ["minimal", "low", "medium", "high", "xhigh"],
};
const MODEL_LEVELS = [
    { pattern: /kimi|mimo/i, levels: PROVIDER_LEVELS.kimi },
    { pattern: /deepseek/i, levels: PROVIDER_LEVELS.deepseek },
    { pattern: /qwen/i, levels: PROVIDER_LEVELS.qwen },
    { pattern: /claude|sonnet|opus|haiku|gpt|openrouter/i, levels: PROVIDER_LEVELS.openrouter },
    { pattern: /codex/i, levels: PROVIDER_LEVELS.codex },
];
export function thinkingLevelsFor(provider, model) {
    const modelText = model ?? "";
    for (const entry of MODEL_LEVELS) {
        if (entry.pattern.test(modelText))
            return entry.levels;
    }
    const key = provider?.trim().toLowerCase() ?? "";
    return PROVIDER_LEVELS[key] ?? DEFAULT_THINKING_LEVELS;
}
export function normalizeThinkingLevel(value) {
    const normalized = value?.trim().toLowerCase();
    if (!normalized)
        return undefined;
    if (normalized === "med" || normalized === "normal" || normalized === "mid")
        return "medium";
    if (normalized === "hi")
        return "high";
    if (normalized === "lo")
        return "low";
    if (normalized === "min")
        return "minimal";
    if (normalized === "extra" || normalized === "x-high" || normalized === "x_high" || normalized === "xhi")
        return "xhigh";
    if (normalized === "maximum" || normalized === "full")
        return "max";
    if (["off", "minimal", "low", "medium", "high", "xhigh", "max"].includes(normalized)) {
        return normalized;
    }
    return undefined;
}
export function nextThinkingLevel(current, provider, model) {
    const levels = thinkingLevelsFor(provider, model);
    const normalized = normalizeThinkingLevel(current);
    const index = normalized ? levels.indexOf(normalized) : -1;
    return levels[(index + 1) % levels.length] ?? "medium";
}
export function normalizeThinkingVariant(value) {
    const normalized = value?.trim().toLowerCase();
    if (!normalized)
        return undefined;
    const level = normalizeThinkingLevel(normalized);
    if (level)
        return level;
    if (normalized.length > 80)
        return undefined;
    return /^[a-z0-9][a-z0-9._:-]*$/.test(normalized) ? normalized : undefined;
}
export function formatThinkingModelVariant(model, variant) {
    const base = model?.trim() || "auto";
    return `${base}:${variant}`;
}
