/** * Built-in free-tier coding models in priority order, as `provider/model-id`. * Each entry answered a ~14K-token prompt with a correct tool call on a free account. * Catalog prices are not consulted: free tiers are account plans, not zero-priced models. */ export const BUILT_IN_MODELS: readonly string[] = [ "kilo/kilo-auto/free", "kilo/stealth/glyph-cluster", "kilo/recursive/flint-v1.0:free", "kilo/reflection/beam-free", "openrouter/openrouter/free", "mistral/ministral-14b-2512", "mistral/ministral-8b-2512", "nvidia/nvidia/nemotron-3.5-super-vl-120b-a12b", "nvidia/nvidia/nemotron-3-ultra-550b-a55b", ]; /** `*` matches any run of characters; everything else is literal. */ export function matches(pattern: string, key: string): boolean { const parts = pattern.split("*"); if (parts.length === 1) return pattern === key; const first = parts[0] ?? ""; const last = parts.at(-1) ?? ""; if (!key.startsWith(first) || key.length < first.length + last.length) return false; let index = first.length; for (const part of parts.slice(1, -1)) { const found = key.indexOf(part, index); if (found === -1) return false; index = found + part.length; } return key.endsWith(last) && key.length - last.length >= index; } /** Comma-separated in env; a JSON string array in settings files. */ export function parseModelPatterns( raw: unknown, source: string, ): string[] | undefined { const values = source === "env" || source === "flag" ? typeof raw === "string" ? raw.split(",") : undefined : Array.isArray(raw) && raw.every((item) => typeof item === "string") ? raw : undefined; if (!values) return undefined; const patterns = values.map((value) => value.trim()).filter(Boolean); const invalid = patterns.find((pattern) => !pattern.includes("/")); if (invalid) throw new Error(`expected provider/model patterns, got "${invalid}"`); return patterns; } const PERMANENT = /\b(?:401|403|404|410)\b|not found|\bgone\b|end of life|no longer available|reported as leaked|timed? ?out/i; /** Failures that will recur on the same model for the rest of the session. */ export function isPermanentFailure(errorMessage: string | undefined): boolean { return PERMANENT.test((errorMessage ?? "").slice(0, 400)); }