"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MODELS = exports.DEFAULT_CONTEXT_SIZE = exports.CONTEXT_SIZES = void 0;
exports.contextSizeToWindow = contextSizeToWindow;
exports.findModelById = findModelById;
exports.versionsForAlias = versionsForAlias;
exports.defaultForAlias = defaultForAlias;
exports.resolveModel = resolveModel;
exports.allowedEffortLevels = allowedEffortLevels;
exports.recommendedEffort = recommendedEffort;
exports.coerceEffort = coerceEffort;
exports.toProviderModels = toProviderModels;
exports.splitLegacyModel = splitLegacyModel;
exports.resolveProviderId = resolveProviderId;
exports.CONTEXT_SIZES = {
    "200k": { label: "200K", disableEnv: true, window: 200_000 },
    "1m": { label: "1M", disableEnv: false, window: 1_000_000 },
};
exports.DEFAULT_CONTEXT_SIZE = "200k";
function contextSizeToWindow(size) {
    return exports.CONTEXT_SIZES[size].window;
}
exports.MODELS = [
    {
        alias: "haiku",
        version: "4.5",
        modelId: "claude-haiku-4-5-20251001",
        displayName: "Haiku 4.5",
        description: "Fastest",
        contextSizes: ["200k"],
        contextWindow: 200_000,
        isDefault: true,
    },
    {
        alias: "sonnet",
        version: "4.6",
        modelId: "claude-sonnet-4-6",
        displayName: "Sonnet 4.6",
        description: "Balanced",
        contextSizes: ["200k", "1m"],
        contextWindow: 200_000,
        isDefault: true,
    },
    {
        alias: "opus",
        version: "4.6",
        modelId: "claude-opus-4-6",
        displayName: "Opus 4.6",
        description: "Previous generation",
        contextSizes: ["200k", "1m"],
        contextWindow: 200_000,
    },
    {
        alias: "opus",
        version: "4.7",
        modelId: "claude-opus-4-7",
        displayName: "Opus 4.7",
        description: "Previous generation",
        contextSizes: ["200k", "1m"],
        contextWindow: 200_000,
        supportsXhigh: true,
    },
    {
        alias: "opus",
        version: "4.8",
        modelId: "claude-opus-4-8",
        displayName: "Opus 4.8",
        description: "Most capable",
        contextSizes: ["200k", "1m"],
        contextWindow: 200_000,
        isDefault: true,
        supportsXhigh: true,
    },
];
function findModelById(modelId) {
    if (!modelId)
        return undefined;
    return exports.MODELS.find((m) => m.modelId === modelId);
}
function versionsForAlias(alias) {
    return exports.MODELS.filter((m) => m.alias === alias);
}
function defaultForAlias(alias) {
    return exports.MODELS.find((m) => m.alias === alias && m.isDefault) ?? versionsForAlias(alias)[0];
}
function resolveModel(model) {
    if (!model)
        return null;
    const base = model.replace(/\[.*\]$/, "");
    if (base === "opus" || base === "sonnet" || base === "haiku") {
        return defaultForAlias(base) ?? null;
    }
    return findModelById(base) ?? null;
}
function allowedEffortLevels(entry) {
    if (!entry || entry.alias === "haiku")
        return [];
    const levels = ["low", "medium", "high"];
    if (entry.supportsXhigh)
        levels.push("xhigh");
    levels.push("max");
    return levels;
}
function recommendedEffort(entry) {
    if (!entry || entry.alias === "haiku")
        return null;
    if (entry.supportsXhigh)
        return "xhigh";
    if (entry.alias === "sonnet")
        return "medium";
    return "high";
}
function coerceEffort(level, entry) {
    const allowed = allowedEffortLevels(entry);
    if (allowed.length === 0)
        return null;
    if (allowed.includes(level))
        return level;
    return recommendedEffort(entry) ?? allowed[allowed.length - 1] ?? null;
}
function toProviderModels() {
    return exports.MODELS.map((m) => ({
        modelId: m.modelId,
        displayName: m.displayName,
        effortLevels: allowedEffortLevels(m),
        contextSizes: m.contextSizes,
        defaultEffort: recommendedEffort(m) ?? undefined,
    }));
}
function splitLegacyModel(stored) {
    if (!stored)
        return { model: undefined, contextSize: exports.DEFAULT_CONTEXT_SIZE };
    const hasOneM = /\[1m\]$/i.test(stored);
    const stripped = stored.replace(/\[.*\]$/, "");
    return {
        model: stripped || undefined,
        contextSize: hasOneM ? "1m" : "200k",
    };
}
function resolveProviderId(currentModel, providers) {
    if (!providers)
        return "anthropic";
    const stripped = currentModel.replace(/\[.*\]$/, "");
    const provider = providers.find((p) => p.models.some((m) => m.modelId === stripped || `${p.id}:${m.modelId}` === stripped));
    return provider?.id ?? "anthropic";
}
