Skip to content

feat(mistral): expand to 13 namespaced metrics from existing payload#97

Open
anthonybaldwin wants to merge 1 commit into
mainfrom
feat/mistral-expand
Open

feat(mistral): expand to 13 namespaced metrics from existing payload#97
anthonybaldwin wants to merge 1 commit into
mainfrom
feat/mistral-expand

Conversation

@anthonybaldwin
Copy link
Copy Markdown
Owner

Summary

Replaces the single session-percent metric on the Mistral provider with the v1 namespaced inventory from plans/mistral-tier-coverage.md. 13 metric IDs total. No new HTTP calls — the existing GET admin.mistral.ai/api/billing/v2/usage already returns every field; the parser was decoding 10+ values it then threw away.

  • Costs (8): 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 (3): monthly-input-tokens, monthly-output-tokens, monthly-cached-tokens (input metric carries a XX% cached caption when both >0)
  • Account (2): model-count, period-end

Migration

Pinned buttons bound to the legacy session-percent auto-rebind to monthly-cost via the existing metricIDAliases map in cmd/plugin/main.go. handleWillAppear now persists the migrated ID back to KeySettings (read-side aliasing already worked) and logs a one-line summary on the first migration per plugin launch:

metricID migration: mistral/session-percent → monthly-cost (rebinding stale buttons silently)

PI changes

METRICS[\"mistral\"] in stat.html is grouped via a new [\"__group__:<label>\"] row marker. populateMetrics renders 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 on model-count per the plan rationale (more models used isn't inherently better).

Tests

  • Fixture at internal/providers/mistral/testdata/billing-v2-usage.json is ported from tmp/CodexBar/Tests/CodexBarTests/MistralUsageParserTests.swift with extra categories (OCR / connectors / libraries / fine-tuning / audio / vibe) added so the new per-category emission paths get exercised.
  • Parser tests: token totals, per-category spend math, period-end parsing, empty response.
  • Snapshot tests: all 13 metric IDs present, legacy session-percent gone, currency formatting, cached-ratio caption.
  • cmd/plugin/main_test.go gains 3 cases locking in the mistral alias.

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 ./... clean
  • golangci-lint run ./... clean (0 issues)
  • go build ./... clean
  • go test ./... passes (mistral tests new; cmd/plugin extended)
  • stat.html JS parses (Function constructor sanity check)
  • Manual: load PI for a Mistral button, confirm 13 metrics in 3 optgroups
  • Manual: button bound to legacy session-percent auto-rebinds to monthly-cost after restart and the migration log line appears

🤖 Generated with Claude Code

…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>
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.

1 participant