feat(dashboard): display + edit provider max-token limit (#6209)#6238
Conversation
Surface each provider's max-token limit on the Providers page and make it editable from the config drawer.
The headline value is the provider's representative model's per-request max-output-token cap: the user's `max_tokens` override when set, otherwise the model's catalog `max_output_tokens`.
The representative model is the provider's default model (`default_model_for_provider`), falling back to the first catalog model.
Backend: `provider_max_output_tokens` resolves the value once per catalog snapshot and `list_providers` / `providers_snapshot` / `get_provider` emit it as `max_output_tokens`.
Editing reuses the existing per-model override endpoint (`PUT /api/models/overrides/{provider}:{model}`), which composes over the catalog default and is registry-sync-safe, so no new persistence path is introduced.
Frontend: a "max tokens" stat is added to the provider card (grid + list) and a "max tokens" editor to the config drawer; clearing the field drops the override and reverts to the catalog default.
Display strings are translated in en / zh / uk.
Closes #6209
…trim overlong comment block
|
Automated review — 1 CI failure fixed, 1 style fix applied (commit 6688065) CI failure (Dashboard
Fix: added Style fix (CLAUDE.md — "never write multi-line comment blocks; one short line max"): The 10-line comment block before Generated by Claude Code |
Summary
Implements #6209: the Providers (供应商) page now displays each provider's max-token limit, and the value is editable from the provider config drawer.
Interpretation of "最大token"
"最大token限制" is read as the per-request max-output-token limit of the provider's representative model.
max_tokensoverride when the user has set one, otherwise the model's catalogmax_output_tokens.default_model_for_provider), falling back to the first catalog model for the provider.This interpretation was chosen over
context_windowdeliberately. The title says "限制" (a limit you impose) and "支持在UI界面修改" (editable), andmax_tokensis the only per-model numeric value with an existing, registry-sync-safe, fully reversible persistence path (ModelOverrides→model_overrides.json) that works for every provider — builtin and custom alike.context_windowis shipped in the upstreamlibrefang-registryand is overwritten on registry sync, so editing it is not safely persistable, andModelOverridescarries nocontext_windowfield. Usingmax_tokenskeeps the displayed value and the edited value identical (consistent between card and drawer).Changes
Backend (
crates/librefang-api/src/routes/providers.rs):provider_max_output_tokens(catalog, provider_id)helper resolves the representative model's effective output limit (override over catalog).list_providers,providers_snapshot, andget_providernow emitmax_output_tokensper provider. The value is computed once while the catalog snapshot is live so it stays consistent with the rest of the entry. The list/snapshot endpoints compute it for all providers in one pass (no per-card extra query).Frontend (
crates/librefang-api/dashboard/):ProviderItemtype gainsmax_output_tokens(src/api.ts).formatCompact(e.g.16.4K) with the exact number on hover; renders-when unknown (src/pages/ProvidersPage.tsx).ProviderMaxTokensSectionin the config drawer: a number input bound to the representative model'smax_tokensoverride (model switchable when the provider has more than one model). Clearing the field deletes the override and reverts to the catalog default. It persists through the existinguseUpdateModelOverridesmutation — all API access stays in the query/mutation hooks, no inlinefetch/api.*.en.json,zh.json,uk.json.CHANGELOG: entry under
[Unreleased].Backend change needed?
Yes — the per-provider
max_output_tokensfield is added to the provider list/snapshot/detail responses so the card can show it without N per-card queries. Editing itself needed no new endpoint; it reusesPUT/DELETE /api/models/overrides/{provider}:{model}.Verification
Dashboard (
crates/librefang-api/dashboard):pnpm typecheck— clean.pnpm lint— exit 0, no errors and no new warnings inProvidersPage.tsx(only pre-existing warnings in unrelated files).pnpm build—✓ built in ~0.9s.pnpm test:i18n-parity—zh.jsonat parity withen.json; the 6uk.json"extra" keys it flags (mcp.*_count_few,network.*_count_few,prompts.*_count_few) are pre-existing onorigin/mainand unrelated to this change. The 7max_tokens*keys added here are present in all three locales.Backend (via the repo's
Dockerfile.rust-devdev image; no native cargo on this host):cargo check -p librefang-api --lib— clean.cargo clippy -p librefang-api --lib --tests -- -D warnings— clean.cargo fmt -p librefang-api -- --check— clean.cargo test -p librefang-api --test providers_routes_test—39 passed; 0 failed, including the newprovider_max_output_tokens_reflects_catalog_then_override, which asserts the list/detail endpoints expose the catalogmax_output_tokens, reflect amax_tokensoverride afterPUT, and revert to the catalog default after the override is deleted.Closes #6209