feat(mistral): expand to 13 namespaced metrics from existing payload#97
Open
anthonybaldwin wants to merge 1 commit into
Open
feat(mistral): expand to 13 namespaced metrics from existing payload#97anthonybaldwin wants to merge 1 commit into
anthonybaldwin wants to merge 1 commit into
Conversation
…yload
The single "session-percent" metric was a misnomer — it was always raw
EUR spend, not a quota percent. Replace it with the namespaced metric
inventory the existing parser was already decoding and throwing away:
Costs: monthly-cost, monthly-cost-completion, monthly-cost-ocr,
monthly-cost-audio, monthly-cost-connectors,
monthly-cost-libraries, monthly-cost-fine-tuning,
monthly-cost-vibe
Tokens: monthly-input-tokens, monthly-output-tokens,
monthly-cached-tokens
Account: model-count, period-end
No new HTTP calls — the existing GET admin.mistral.ai/api/billing/v2/usage
already returns every field. The payload's currency symbol is preserved
verbatim (typically EUR) — no synthetic USD conversion.
Pinned buttons bound to the legacy "session-percent" auto-rebind to
"monthly-cost" via metricIDAliases. handleWillAppear now persists the
migrated ID back to KeySettings (was read-only before) and emits a
one-line summary log on the first migration per plugin launch.
stat.html METRICS["mistral"] is grouped via "__group__:" rows; a small
extension to populateMetrics renders them as <optgroup> separators
("Costs" / "Tokens" / "Account"). Other providers continue to render
as flat option lists.
Tests cover the parser (token totals, per-category spend, period-end,
empty response) and the snapshot emission (all 13 metric IDs present,
legacy ID gone, currency formatting). Fixture ported from
tmp/CodexBar/Tests/CodexBarTests/MistralUsageParserTests.swift, with
extra categories added to exercise the new code paths.
Refs plans/mistral-tier-coverage.md (v1).
Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the single
session-percentmetric on the Mistral provider with the v1 namespaced inventory from plans/mistral-tier-coverage.md. 13 metric IDs total. No new HTTP calls — the existingGET admin.mistral.ai/api/billing/v2/usagealready returns every field; the parser was decoding 10+ values it then threw away.monthly-cost,monthly-cost-completion,monthly-cost-ocr,monthly-cost-audio,monthly-cost-connectors,monthly-cost-libraries,monthly-cost-fine-tuning,monthly-cost-vibemonthly-input-tokens,monthly-output-tokens,monthly-cached-tokens(input metric carries aXX% cachedcaption when both >0)model-count,period-endMigration
Pinned buttons bound to the legacy
session-percentauto-rebind tomonthly-costvia the existingmetricIDAliasesmap incmd/plugin/main.go.handleWillAppearnow persists the migrated ID back toKeySettings(read-side aliasing already worked) and logs a one-line summary on the first migration per plugin launch:PI changes
METRICS[\"mistral\"]instat.htmlis grouped via a new[\"__group__:<label>\"]row marker.populateMetricsrenders these as<optgroup>separators ("Costs" / "Tokens" / "Account"). Other providers continue to render as flat lists; behavior is opt-in per provider.Currency
Payload symbol preserved verbatim (typically
€). No synthetic USD conversion.NumericGoodWhen=\"low\"on every cost metric; left unset onmodel-countper the plan rationale (more models used isn't inherently better).Tests
internal/providers/mistral/testdata/billing-v2-usage.jsonis ported fromtmp/CodexBar/Tests/CodexBarTests/MistralUsageParserTests.swiftwith extra categories (OCR / connectors / libraries / fine-tuning / audio / vibe) added so the new per-category emission paths get exercised.session-percentgone, currency formatting, cached-ratio caption.cmd/plugin/main_test.gogains 3 cases locking in themistralalias.Out of scope
v2 (tier-progress, spend-limit-percent, le-chat-plan, le-chat-seats) — those need DevTools spelunking against undocumented
/api/...paths. Documented as a follow-up in the plan.Test plan
go vet ./...cleangolangci-lint run ./...clean (0 issues)go build ./...cleango test ./...passes (mistral tests new; cmd/plugin extended)session-percentauto-rebinds tomonthly-costafter restart and the migration log line appears🤖 Generated with Claude Code