Files
magpie/internal/settingsapi
yetone 5211fd3ba2 usage: a currency "By provider" shows each provider's costs in what it sells in
onkashiko on X: DeepSeek, Kimi (China), Zhipu and other domestic vendors
price in yuan, the rest in dollars, and one currency for every cost made
the Usage page read wrong for half of them.

Settings > Usage > Currency gains a third choice, By provider. With it,
a figure of one provider's calls (a model's, an account's, a key's row,
a request, a routing try, a quota card's whole) shows in the currency
that provider sells in, and every sum across providers (the total,
agents, sessions, charts, the tray, Bark's daily, the day page) in the
currency a "Totals in" row picks, a row shown only while By provider is
chosen. GUI, TUI and CLI agree. Costs stay stored in dollars; only the
display converts, at the live rate (internal/fx).

Which providers sell in yuan (provider.PricesInYuan): a .cn host; a
preset at its own site that is a yuan preset (deepseek, zhipu,
volcengine, tencent-cloud, bailian, siliconflow…), ends in -cn, or is in
its China region; a plugin id ending in -cn; a provider of one's own
with a yuan models.dev catalog served at that catalog's site. A relay
made from DeepSeek's preset, Z.ai, Kimi's and MiniMax's international
endpoints stay in dollars: they share a catalog with their Chinese
twins, so the catalog alone can't tell.

Known limit: models.dev has only dollar prices (converted from the
vendors' yuan at ~6.7-7.0), so a yuan figure is that dollar price at
today's rate and can differ a few percent from the vendor's own list.

A second ask from onkashiko: set the currency of the menu bar and of
the totals apart, sums converted by themselves.

So Settings > Usage also gains an Advanced fold (closed by default, open while
set) with one row, Menu bar currency: Same as totals (the default), $ or
¥ (settings.TrayCurrency, TrayCostIn). It sets the menu bar's totals
cards and the tray tooltip's cost; the Usage page, the panel, the TUI,
the CLI and Bark's daily message stay in the totals' currency
(totalsCurrency). Like the other menu bar settings it stays on this
computer (KeepOwn). Every sum is still made in dollars and converted
once, at the live rate, so a mixed-currency total is never added up
from yuan and dollars.

Settings' currency rows (Currency, Totals in, Menu bar currency and the
rate in the tooltip) moved out of app.js into currencyprefs.js, imported
when Settings draws its usage prefs, and costInYuan is packed: the core
is 3 bytes under coreScriptBudget, with no raise.

Run:
- go test -count=1 at this tree on mote: internal/settings,
  settingsapi, tui, cli, catalog, provider, fx and gui all ok
  (TestCoreScriptBudget included). The full go test ./... and the whole
  GUI suite are queued behind other sessions' suites on suite.lock
  (mote and mica, load 35 and 60) and had not started at push.
- GUI files at this tree (mica): currency-provider, currency, i18n-keys,
  i18n-en-no-cjk, tray-cost, tray-totals, every settings-*, old-webkit:
  362 pass, 28 red. Every red is red the same at origin/main ac0b5c287
  on mote, and filed: settings-search (#6133, #6353), settings-hints
  (#6107, #6353), settings-lines-wrap de 440px (#6353), old-webkit
  appearance.js (#6467) and :has() (#5919). The one red of this change,
  settings-groups' list of Usage's parts (now with the Advanced fold),
  is fixed here: 14 of 14.
- currency-provider.test.cjs (new): en, zh, zh-TW, ja, de at 900 and
  420px, both engines; By provider, Totals in ¥, then Advanced: $ for
  the menu bar with totals in ¥, totals stay ¥21.60, the fold opens
  itself after a reload. Plus currency.test.cjs (3 choices now),
  i18n-keys, i18n-en-no-cjk, tray-cost: green in both engines.
- TestTrayCostIn (values, refused eur/provider, KeepOwn),
  TestFXByProvider (trayCurrency vs totalsCurrency), TestCoreScriptBudget.
- gofmt -l clean; GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., GOOS=linux go build -tags nogui,
  GOOS=windows go build on mote at this tree: ok.
- Broken by hand, each red: costInYuan ignoring the provider (GUI
  test: deepseek showed $1.00 for ¥7.20), PricesInYuan without the
  preset's site check (a relay made from DeepSeek's preset read as
  yuan), CostIn without its By provider branch (settings test),
  TrayCostIn ignoring TrayCurrency (TestTrayCostIn, TestFXByProvider),
  the fold not opening while set (webkit), the row saving into
  totalCurrency (chromium).
- Real app in a sandbox HOME on mote (dev build, magpie web and magpie
  usage) with DeepSeek, OpenAI and Z.ai presets and one call each: the
  window and the CLI both show deepseek-v4-pro ≈¥15.44, gpt-4.1 ≈$1.00,
  glm-4.6 ≈$0.290 and the total ≈¥24.07 at 6.685; /api/settings' fx
  carries yuan ["deepseek"].
Not tried: Windows and Linux windows and trays, the real menu bar with
Menu bar currency changed (drawn natively; covered through trayCurrency
in Go), a real Kimi CN or Zhipu account.
2026-11-13 22:46:00 +08:00
..