Files
smartmenu-collina/messages
Jorem Juárez ceac688fa8 Add cost dashboard to the master panel (tokens + storage, USD/MXN)
Superadmin view in /admin showing operating cost with per-restaurant breakdown.

Models (migration 0012):
- TokenUsage(restaurantId?, model, feature, inputTokens, outputTokens, createdAt)
- ModelPrice(model, inputPricePerMTok, outputPricePerMTok, updatedAt) — seeded
  Haiku 4.5 1/5, Sonnet 4.6 3/15, Opus 4.8 5/25 (USD per million)
- PriceUpdateLog(model, old/new input+output, source, createdAt)
- ExchangeRate(date, rate) — daily USD→MXN cache
- AppConfig(key,value) — seeded costPerGb=0

B1 Instrumentation: recordUsage() (fire-and-forget) logs every Anthropic call with
its model/feature/restaurant and the response usage tokens — wired into the
consultor (ai-consult), translation, and menu import. restaurantId null = Collina
operational.

B2 Price update: 'Update prices from Anthropic' button → fetches the public pricing
page, Haiku extracts prices FROM THE PAGE TEXT ONLY (omits any not found), updates
ModelPrice and writes a PriceUpdateLog (old→new). If the fetch is blocked, the UI
offers a manual paste box processed the same way. These calls log as
feature 'precios-update', restaurantId null.

B3 Exchange: getUsdMxn() caches once/day via Frankfurter (no key); on failure falls
back to the last stored rate, then a constant — never /bin/zsh; shows the rate's date.

B4 Storage: measures GB per restaurant from /data/uploads/{slug}; configurable
costPerGb (editable) projects a storage cost.

B5 Dashboard (CostsDashboard): month total in USD + MXN, per-restaurant token cost
(USD/MXN) + GB + projected storage cost, average per active restaurant, a separate
'Operativo Collina' line for restaurantId-null calls, and context (exchange rate +
date, last price update). i18n es/en at parity.

Verified (build passes; migration 0012 applies; seeds present): a usage row records
model/tokens/restaurant; dashboard shows USD + MXN with the day's rate (Frankfurter
live 17.21, cached); token cost math correct (/bin/zsh.04 for 20k/4k Haiku); storage GB +
projected cost with cost/GB=0.10; operational calls isolated; price endpoint guarded
(401) and graceful without key (502); PriceUpdateLog records old→new.
2026-06-18 07:27:46 -06:00
..