/* * catalogHelpers.ts * Zyquo Cloud Web * * Author: Simon-Pierre Boucher * Mail: contact@spboucher.ai * * Catalog conveniences shared by the store and UI: re-exports of the ported * catalog queries plus cost/estimation helpers. */ import { pricingCost, type AIModel, type TokenUsage } from '../types' export { CATALOG, cheapestModel, defaultModel, findModel, modelsFor, rankModel } from '../providers/catalog' /** Estimated USD cost of a usage record for a model (0 when unpriced). */ export function pricedCost(model: AIModel, usage: TokenUsage): number { if (!model.pricing) return 0 return pricingCost(model.pricing, usage.inputTokens, usage.outputTokens) } /** Rough token estimate for context-window accounting (≈4 chars/token). */ export function estimateTokens(text: string): number { return Math.ceil(text.length / 4) } /** "$1.25 / $10" per-MTok badge, or "—" when unpriced. */ export function priceBadge(model: AIModel): string { if (!model.pricing) return '—' const fmt = (v: number) => (v >= 1 ? `$${v.toFixed(2).replace(/\.?0+$/, '')}` : `$${v}`) return `${fmt(model.pricing.inputPerMTok)} / ${fmt(model.pricing.outputPerMTok)}` } /** "$0.0042" style cost display. */ export function costLabel(cost: number): string { if (cost <= 0) return '' return `~$${cost.toFixed(4)}` }