Skip to content

feat: support configurable cost display currency - #41208

Open
Meinianda-L wants to merge 2 commits into
anomalyco:devfrom
Meinianda-L:feat/usage-display-currency
Open

feat: support configurable cost display currency#41208
Meinianda-L wants to merge 2 commits into
anomalyco:devfrom
Meinianda-L:feat/usage-display-currency

Conversation

@Meinianda-L

@Meinianda-L Meinianda-L commented Aug 8, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #32485

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This is needed for users whose model pricing is in a non-USD currency (e.g. CNY/RMB) to see usage costs in their own currency.

The PR is self-contained and depends on no unmerged PR (#39425 was closed as superseded). The first commit is the provider-currency propagation from #39425 (kagura-agent's authorship preserved, fixing #38667); the second adds the display-currency feature (closes #32485).

Adds display.currency and display.exchangeRates config options:

{
  "display": {
    "currency": "CNY",
    "exchangeRates": { "CNY": 7.15 }
  }
}

Costs stay tracked in the provider's source currency. When display.currency is set, amounts are converted at the display boundaries: ACP usage_update (both paths), TUI (sidebar, prompt footer, subagent footer) and the app (context usage, context tab) — all routed through one core Currency utility. When it is unset, or no rate exists for the pair, the original amount and currency are shown — values are never relabeled without conversion. An invalid user rate disables conversion for that currency rather than silently falling back. display.exchangeRates (units per 1 USD) overrides the built-in approximate rate table, which is display-only and not billing-authoritative.

This supersedes the approach in #32487 (auto-closed after going stale, not rejected): since the provider currency is propagated from provider config, no separate global source-currency knob is needed — custom prices configured in RMB are covered by the provider-level currency field.

Docs: new "Display" section in packages/web/src/content/docs/config.mdx. Not changed: CLI stats / run footer, which aggregate costs across models without source-currency information.

How did you verify your code works?

% bun test test/currency.test.ts        # packages/core
 15 pass
 0 fail

% bun test test/acp                     # packages/opencode
 135 pass
 0 fail

% bun typecheck                         # repo root
 30 successful, 30 total

New tests cover conversion (identity, cross-rate, overrides, invalid override disables conversion, unknown/empty source currency) and sendUpdate behavior (source-currency passthrough with no config, USD→CNY conversion, no-relabel fallback). Existing app/tui session tests still pass, oxlint clean on changed files, SDK regenerated with script/generate.ts, config decode verified.

Screenshots / recordings

N/A — formatting goes through Intl.NumberFormat with the resolved currency (e.g. with exchangeRates: { "CNY": 7.2 }, a $1.50 session shows CN¥10.80). Happy to add screenshots if helpful.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@Meinianda-L

Meinianda-L commented Aug 8, 2026

Copy link
Copy Markdown
Author

Friendly ping for review: @Hona @Brendonovich (code owners for the touched packages/app files) and @StarpTech (assignee of #32485). The PR is self-contained (includes the provider-currency commit from #39425, authorship preserved), so it can be reviewed and merged independently.

kagura-agent and others added 2 commits August 8, 2026 13:24
…ding USD

The usage_update ACP event hardcodes currency: "USD" regardless of the
provider's actual currency configuration. This causes non-USD providers
(e.g. EUR-priced custom providers) to report incorrect currency labels.

Add an optional `currency` field to the ProviderCost schema (defaults to
"USD" when omitted for backward compatibility). Thread the configured
currency through to both usage_update call sites (usage.ts layer and
service.ts ACP client) using a cached lookup pattern matching the
existing contextLimit implementation.

Fixes anomalyco#38667

Signed-off-by: kagura-agent <kagura.agent.ai@gmail.com>
Add a display.currency config option that converts usage costs to the
user's preferred currency at presentation boundaries (ACP usage_update,
TUI, and app). The provider/model currency remains the source currency:
when no display currency is configured, costs are shown unchanged in
the source currency, and amounts are never relabeled when conversion is
impossible (unknown rate).

- Add Currency core module: approximate USD-based display rate table,
  convert() with user rate overrides, and locale-aware format()
- Add display.currency and display.rates to the config schema
- Convert in both ACP usage_update paths (Effect layer and ACP client)
- Replace hardcoded USD formatters in TUI (sidebar, prompt, subagent
  footer) and app (context usage, context tab) with the shared utility
- Regenerate SDK types and document the new options

Relates to anomalyco#32485. Supersedes the approach explored in anomalyco#32487 and
builds on provider-currency propagation from anomalyco#39425.
@Meinianda-L
Meinianda-L force-pushed the feat/usage-display-currency branch from cf8cee6 to 0a4b2cb Compare August 8, 2026 05:32
@Meinianda-L

Copy link
Copy Markdown
Author

Update: this PR is now self-contained — rebased onto latest dev with #39425's commit included (authorship preserved), so it no longer waits on that PR. Also applied pre-review polish: invalid user rates now disable conversion instead of silently falling back, renamed ratesexchangeRates and RatesExchangeRates for clarity, and added negative tests for unknown/empty source currency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Configure usage cost display currency

2 participants