import { Type } from "typebox";
import { Compile } from "typebox/compile";
const PercentileCutoffsSchema = Type.Object({
    p50: Type.Optional(Type.Number()),
    p75: Type.Optional(Type.Number()),
    p90: Type.Optional(Type.Number()),
    p99: Type.Optional(Type.Number()),
});
const OpenRouterRoutingSchema = Type.Object({
    allow_fallbacks: Type.Optional(Type.Boolean()),
    require_parameters: Type.Optional(Type.Boolean()),
    data_collection: Type.Optional(Type.Union([Type.Literal("deny"), Type.Literal("allow")])),
    zdr: Type.Optional(Type.Boolean()),
    enforce_distillable_text: Type.Optional(Type.Boolean()),
    order: Type.Optional(Type.Array(Type.String())),
    only: Type.Optional(Type.Array(Type.String())),
    ignore: Type.Optional(Type.Array(Type.String())),
    quantizations: Type.Optional(Type.Array(Type.String())),
    sort: Type.Optional(Type.Union([
        Type.String(),
        Type.Object({
            by: Type.Optional(Type.String()),
            partition: Type.Optional(Type.Union([Type.String(), Type.Null()])),
        }),
    ])),
    max_price: Type.Optional(Type.Object({
        prompt: Type.Optional(Type.Union([Type.Number(), Type.String()])),
        completion: Type.Optional(Type.Union([Type.Number(), Type.String()])),
        image: Type.Optional(Type.Union([Type.Number(), Type.String()])),
        audio: Type.Optional(Type.Union([Type.Number(), Type.String()])),
        request: Type.Optional(Type.Union([Type.Number(), Type.String()])),
    })),
    preferred_min_throughput: Type.Optional(Type.Union([Type.Number(), PercentileCutoffsSchema])),
    preferred_max_latency: Type.Optional(Type.Union([Type.Number(), PercentileCutoffsSchema])),
});
const VercelGatewayRoutingSchema = Type.Object({
    only: Type.Optional(Type.Array(Type.String())),
    order: Type.Optional(Type.Array(Type.String())),
});
const ThinkingLevelMapValueSchema = Type.Union([Type.String(), Type.Null()]);
const ThinkingLevelMapSchema = Type.Object({
    off: Type.Optional(ThinkingLevelMapValueSchema),
    minimal: Type.Optional(ThinkingLevelMapValueSchema),
    low: Type.Optional(ThinkingLevelMapValueSchema),
    medium: Type.Optional(ThinkingLevelMapValueSchema),
    high: Type.Optional(ThinkingLevelMapValueSchema),
    xhigh: Type.Optional(ThinkingLevelMapValueSchema),
    max: Type.Optional(ThinkingLevelMapValueSchema),
});
const ContextWindowOptionsSchema = Type.Array(Type.Number());
const ChatTemplateKwargScalarSchema = Type.Union([Type.String(), Type.Number(), Type.Boolean(), Type.Null()]);
const ChatTemplateKwargVariableSchema = Type.Object({
    $var: Type.Union([Type.Literal("thinking.enabled"), Type.Literal("thinking.effort")]),
    omitWhenOff: Type.Optional(Type.Boolean()),
});
const ChatTemplateKwargSchema = Type.Union([ChatTemplateKwargScalarSchema, ChatTemplateKwargVariableSchema]);
const ModelCostRatesSchema = Type.Object({
    input: Type.Number(),
    output: Type.Number(),
    cacheRead: Type.Number(),
    cacheWrite: Type.Number(),
});
const ModelCostTierSchema = Type.Intersect([
    ModelCostRatesSchema,
    Type.Object({ inputTokensAbove: Type.Number() }),
]);
const ModelCostSchema = Type.Intersect([
    ModelCostRatesSchema,
    Type.Object({ tiers: Type.Optional(Type.Array(ModelCostTierSchema)) }),
]);
const ModelCostOverrideSchema = Type.Object({
    input: Type.Optional(Type.Number()),
    output: Type.Optional(Type.Number()),
    cacheRead: Type.Optional(Type.Number()),
    cacheWrite: Type.Optional(Type.Number()),
    tiers: Type.Optional(Type.Array(ModelCostTierSchema)),
});
const OpenAICompletionsCompatSchema = Type.Object({
    supportsStore: Type.Optional(Type.Boolean()),
    supportsDeveloperRole: Type.Optional(Type.Boolean()),
    supportsReasoningEffort: Type.Optional(Type.Boolean()),
    supportsUsageInStreaming: Type.Optional(Type.Boolean()),
    maxTokensField: Type.Optional(Type.Union([Type.Literal("max_completion_tokens"), Type.Literal("max_tokens")])),
    requiresToolResultName: Type.Optional(Type.Boolean()),
    requiresAssistantAfterToolResult: Type.Optional(Type.Boolean()),
    requiresThinkingAsText: Type.Optional(Type.Boolean()),
    requiresReasoningContentOnAssistantMessages: Type.Optional(Type.Boolean()),
    thinkingFormat: Type.Optional(Type.Union([
        Type.Literal("openai"),
        Type.Literal("openrouter"),
        Type.Literal("together"),
        Type.Literal("deepseek"),
        Type.Literal("zai"),
        Type.Literal("qwen"),
        Type.Literal("chat-template"),
        Type.Literal("qwen-chat-template"),
        Type.Literal("string-thinking"),
        Type.Literal("ant-ling"),
    ])),
    chatTemplateKwargs: Type.Optional(Type.Record(Type.String(), ChatTemplateKwargSchema)),
    cacheControlFormat: Type.Optional(Type.Literal("anthropic")),
    openRouterRouting: Type.Optional(OpenRouterRoutingSchema),
    vercelGatewayRouting: Type.Optional(VercelGatewayRoutingSchema),
    supportsStrictMode: Type.Optional(Type.Boolean()),
    supportsLongCacheRetention: Type.Optional(Type.Boolean()),
});
const OpenAIResponsesCompatSchema = Type.Object({
    sendSessionIdHeader: Type.Optional(Type.Boolean()),
    supportsDeveloperRole: Type.Optional(Type.Boolean()),
    supportsLongCacheRetention: Type.Optional(Type.Boolean()),
});
const AnthropicMessagesCompatSchema = Type.Object({
    supportsEagerToolInputStreaming: Type.Optional(Type.Boolean()),
    supportsLongCacheRetention: Type.Optional(Type.Boolean()),
    sendSessionAffinityHeaders: Type.Optional(Type.Boolean()),
    supportsCacheControlOnTools: Type.Optional(Type.Boolean()),
    forceAdaptiveThinking: Type.Optional(Type.Boolean()),
});
const ProviderCompatSchema = Type.Union([
    OpenAICompletionsCompatSchema,
    OpenAIResponsesCompatSchema,
    AnthropicMessagesCompatSchema,
]);
const ModelDefinitionSchema = Type.Object({
    id: Type.String({ minLength: 1 }),
    name: Type.Optional(Type.String({ minLength: 1 })),
    api: Type.Optional(Type.String({ minLength: 1 })),
    baseUrl: Type.Optional(Type.String({ minLength: 1 })),
    reasoning: Type.Optional(Type.Boolean()),
    thinkingLevelMap: Type.Optional(ThinkingLevelMapSchema),
    input: Type.Optional(Type.Array(Type.Union([Type.Literal("text"), Type.Literal("image")]))),
    cost: Type.Optional(ModelCostSchema),
    contextWindow: Type.Optional(Type.Number()),
    contextWindowOptions: Type.Optional(ContextWindowOptionsSchema),
    maxTokens: Type.Optional(Type.Number()),
    headers: Type.Optional(Type.Record(Type.String(), Type.String())),
    compat: Type.Optional(ProviderCompatSchema),
});
const ModelOverrideSchema = Type.Object({
    name: Type.Optional(Type.String({ minLength: 1 })),
    reasoning: Type.Optional(Type.Boolean()),
    thinkingLevelMap: Type.Optional(ThinkingLevelMapSchema),
    input: Type.Optional(Type.Array(Type.Union([Type.Literal("text"), Type.Literal("image")]))),
    cost: Type.Optional(ModelCostOverrideSchema),
    contextWindow: Type.Optional(Type.Number()),
    contextWindowOptions: Type.Optional(ContextWindowOptionsSchema),
    maxTokens: Type.Optional(Type.Number()),
    headers: Type.Optional(Type.Record(Type.String(), Type.String())),
    compat: Type.Optional(ProviderCompatSchema),
});
const ProviderConfigSchema = Type.Object({
    name: Type.Optional(Type.String({ minLength: 1 })),
    baseUrl: Type.Optional(Type.String({ minLength: 1 })),
    apiKey: Type.Optional(Type.String({ minLength: 1 })),
    api: Type.Optional(Type.String({ minLength: 1 })),
    headers: Type.Optional(Type.Record(Type.String(), Type.String())),
    compat: Type.Optional(ProviderCompatSchema),
    authHeader: Type.Optional(Type.Boolean()),
    models: Type.Optional(Type.Array(ModelDefinitionSchema)),
    modelOverrides: Type.Optional(Type.Record(Type.String(), ModelOverrideSchema)),
});
const ModelsConfigSchema = Type.Object({
    providers: Type.Record(Type.String(), ProviderConfigSchema),
});
export const validateModelsConfig = Compile(ModelsConfigSchema);
export function formatValidationPath(error) {
    if (error.keyword === "required") {
        const requiredProperties = error.params.requiredProperties;
        const requiredProperty = requiredProperties?.[0];
        if (requiredProperty) {
            const basePath = error.instancePath.replace(/^\//, "").replace(/\//g, ".");
            return basePath ? `${basePath}.${requiredProperty}` : requiredProperty;
        }
    }
    const path = error.instancePath.replace(/^\//, "").replace(/\//g, ".");
    return path || "root";
}
export function stripJsonComments(input) {
    return input
        .replace(/"(?:\\.|[^"\\])*"|\/\/[^\n]*/g, (m) => (m[0] === '"' ? m : ""))
        .replace(/"(?:\\.|[^"\\])*"|,(\s*[}\]])/g, (m, tail) => tail ?? (m[0] === '"' ? m : ""));
}
//# sourceMappingURL=model-registry-schemas.js.map