import { SHORTCUT_MODEL_ID } from '../model-ids.js';
/** Provider tag the registry uses to gate auth and model lookup. */
export const ShortcutXLAgentProviderId = {
    Shortcut: 'shortcut'
};
/** Stable id for each model the ShortcutXL runtime knows how to stream. */
export const ShortcutXLAgentModelId = {
    ClaudeOpus47: SHORTCUT_MODEL_ID.ClaudeOpus47,
    ClaudeOpus48: SHORTCUT_MODEL_ID.ClaudeOpus48,
    ClaudeSonnet46: SHORTCUT_MODEL_ID.ClaudeSonnet46,
    Gpt55: SHORTCUT_MODEL_ID.Gpt55,
    /**
     * Opaque alias for the free fallback model. Selected by host degraded mode,
     * never user-selectable. The proxy validates eligibility and resolves the
     * real upstream model server-side.
     */
    FreeModel: SHORTCUT_MODEL_ID.FreeModel
};
const DEFAULT_SHORTCUTXL_AGENT_MODEL_ID = ShortcutXLAgentModelId.ClaudeOpus48;
function formatGatewayModelName(modelId) {
    return modelId
        .split('-')
        .filter(Boolean)
        .map((part) => (part.length === 0 ? part : `${part[0].toUpperCase()}${part.slice(1)}`))
        .join(' ');
}
function createGatewayModel(modelId, baseUrl) {
    return {
        id: modelId,
        name: formatGatewayModelName(modelId),
        api: 'shortcut-llm',
        provider: ShortcutXLAgentProviderId.Shortcut,
        baseUrl,
        reasoning: true,
        input: ['text', 'image'],
        cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
        contextWindow: 200000,
        maxTokens: 64000
    };
}
/** Build the canonical list of ShortcutXL-served models with the configured base URL. */
function createShortcutXLAgentModels(options = {}) {
    const baseUrl = options.baseUrl ?? '';
    const shortcutModels = [
        {
            id: ShortcutXLAgentModelId.ClaudeOpus47,
            name: 'Claude Opus 4.7',
            api: 'shortcut-llm',
            provider: ShortcutXLAgentProviderId.Shortcut,
            baseUrl,
            reasoning: true,
            input: ['text', 'image'],
            cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
            contextWindow: 1_000_000,
            maxTokens: 128000
        },
        {
            id: ShortcutXLAgentModelId.ClaudeOpus48,
            name: 'Claude Opus 4.8',
            api: 'shortcut-llm',
            provider: ShortcutXLAgentProviderId.Shortcut,
            baseUrl,
            reasoning: true,
            input: ['text', 'image'],
            cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
            contextWindow: 1_000_000,
            maxTokens: 128000
        },
        {
            id: ShortcutXLAgentModelId.ClaudeSonnet46,
            name: 'Claude Sonnet 4.6',
            api: 'shortcut-llm',
            provider: ShortcutXLAgentProviderId.Shortcut,
            baseUrl,
            reasoning: true,
            input: ['text', 'image'],
            cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
            contextWindow: 200000,
            maxTokens: 64000
        },
        {
            id: ShortcutXLAgentModelId.Gpt55,
            name: 'GPT-5.5',
            api: 'shortcut-llm',
            provider: ShortcutXLAgentProviderId.Shortcut,
            baseUrl,
            reasoning: true,
            input: ['text', 'image'],
            cost: { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 5 },
            contextWindow: 1_000_000,
            maxTokens: 128000
        },
        {
            // Free-tier vLLM fallback. Internal-only — see ModelId.FreeModel docstring.
            // Not surfaced via getAvailable(); only resolvable via find() once
            // CreditGate has selected it.
            id: ShortcutXLAgentModelId.FreeModel,
            name: 'Free Model',
            api: 'shortcut-llm',
            provider: ShortcutXLAgentProviderId.Shortcut,
            baseUrl,
            reasoning: false,
            input: ['text'],
            // Cost is for observability only; webhook attribution happens server-
            // side after vLLM dispatch.
            cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
            contextWindow: 128000,
            maxTokens: 32000
        }
    ];
    const existingModelIds = new Set(shortcutModels.map((model) => model.id));
    const gatewayModels = [
        ...new Set((options.gatewayModelIds ?? []).map((modelId) => modelId.trim()).filter(Boolean))
    ]
        .filter((modelId) => !existingModelIds.has(modelId))
        .map((modelId) => createGatewayModel(modelId, baseUrl));
    return [...shortcutModels, ...gatewayModels];
}
/** Look up a model by id from the catalog, returning the product default when id is omitted. */
function resolveShortcutXLAgentModel(modelId, options = {}) {
    const models = createShortcutXLAgentModels(options);
    return models.find((model) => model.id === (modelId ?? DEFAULT_SHORTCUTXL_AGENT_MODEL_ID));
}
/** Predicate: is this an internal-only model that should never appear in UI selectors? */
function isInternalModel(modelId) {
    return modelId === ShortcutXLAgentModelId.FreeModel;
}
/** Build a `AgentModelRegistry` over the ShortcutXL model catalog. */
export function createShortcutXLAgentModelRegistry(options = {}) {
    const getAccessToken = options.getAccessToken ?? (async () => undefined);
    return {
        find(provider, modelId) {
            // `find` resolves ALL registered models, including internal ones —
            // CreditGate calls this to obtain the FreeModel reference for swapping
            // mid-run. UI surfaces use `getAll`/`getAvailable` instead.
            if (provider !== ShortcutXLAgentProviderId.Shortcut) {
                return undefined;
            }
            return resolveShortcutXLAgentModel(modelId, options);
        },
        getAll() {
            return createShortcutXLAgentModels(options).filter((m) => !isInternalModel(m.id));
        },
        async getApiKey(model) {
            if (model.provider !== ShortcutXLAgentProviderId.Shortcut) {
                return undefined;
            }
            return getAccessToken();
        },
        async getApiKeyForProvider(provider) {
            if (provider !== ShortcutXLAgentProviderId.Shortcut) {
                return undefined;
            }
            return getAccessToken();
        },
        getAvailable() {
            return createShortcutXLAgentModels(options).filter((m) => !isInternalModel(m.id));
        },
        getError() {
            return undefined;
        },
        isUsingOAuth(model) {
            return model.provider === ShortcutXLAgentProviderId.Shortcut;
        },
        refresh() { }
    };
}
/** Resolve a single model by id, or fall back to the catalog default. */
export function createShortcutXLAgentModel(modelId, options = {}) {
    return resolveShortcutXLAgentModel(modelId, options);
}
//# sourceMappingURL=model-registry.js.map