Files
plugins/packages/page-usage-board/docs/data-semantics.md
T
orinsid 545ed66e74 page-usage-board: a usage dashboard page (#844)
Adds @magpie-community/page-usage-board: a usage dashboard page with its
own zero-dependency local service (quota cards with expiry tiers, TTFT,
7x24 heatmap, optional remote attribution).

Reviewed at 8ca2562: the author's 80137b0 plus a maintainer merge of main
(registry entry re-appended after upstream's newer packages).
Since the 6b2625d review: [::1] in MAGPIE_ADDR stays IPv6 loopback (only
0.0.0.0/[::] map to 127.0.0.1), the config-dir test compares real paths
so it passes on macOS, and the registry-block test tolerates CRLF.

Run on mote at 8ca2562: packages/page-usage-board `bun test` 36 pass,
`node --test test/*.test.mjs` 36 pass; `bun scripts/check.mjs` all ok.
Not tried this round: the page in a live magpie window.
2026-11-10 10:36:04 +08:00

66 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Data semantics
Read this before changing the page or the aggregations. Two different totals are shown on
purpose; they answer different questions and must not be silently reconciled.
## The four exit aliases are two routes
magpie renamed its outbound providers over time:
| Route | Names in `usage.jsonl` | Remote `caller` |
|---|---|---|
| direct | `magpie-direct`, `remote-magpie` | `cloud` |
| Cloudflare | `magpie-cf`, `magpie-2` | `Magpie` |
The page keeps all four in one `REMOTE_ENTRY` set. Never hand-write a single name.
## Charts use real providers
- Local, non-exit providers are taken from the detail log as-is.
- Remote attribution adds per-provider totals under the same provider names.
- When attribution is available, the exit aliases do **not** enter the charts; their traffic
is already attributed.
- When attribution is unavailable, the four exit aliases collapse into one series labelled
"remote (unattributed)", so nothing disappears silently.
- The daily chart stacks providers; the provider pie merges aliases.
## Where the remote side comes from
The local service reads the remote magpie's own `/v1/magpie/usage/requests` (provider key
already in `providers.json`) and keeps rows whose `callerKeyName` is in `REMOTE_CALLERS`
(default `cloud`, `Magpie`). The caller breakdown still lists every caller on that instance
(e.g. `hermes`), but provider/account/day/hourly numbers are this machine's only. The 24-hour
remote curve is caller-filtered too; older builds that read the remote log without that filter
over-counted other callers.
The standalone `/usage2` service is retired: it was only a way to run that filter on the
remote log when the magpie API could not give per-caller rows.
## KPI cards use the local gateway ledger
Cost on the KPI cards is magpie's own pricing (subscription quota converted to money), not
money actually spent. It is intentionally different from the chart totals, which follow real
providers. Label both clearly; do not "fix" one to match the other.
## Quota cards deduplicate by subscription
The same subscription can be read through two routes (direct / proxy) and two instances
(local / remote). The quota wall groups by (normalized subscription + account) and shows one
card per group; the `· Magpie direct/proxy` suffix is stripped from the name. Different
accounts (different phone numbers or keys) are different quotas and stay as separate cards.
## Remote cards have three states
- No remote data source (remote attribution is opt-in and defaults to local): hide the TTFT and account cards.
- Source configured but the fetch fails (45 s client timeout, 10 s per remote page server-side): show a red error card explaining it.
- Success: show the data.
A dead source must never make the card vanish without a trace — silence looks like "zero
usage" and is the one failure mode that misleads.
## What is read
`usage.jsonl` lines are aggregated into daily × provider totals, a 7×24 heatmap, 24-hour
token/cache curves, recent requests and per-account attribution. Probe lines
(`kind: "model_list"`, `source: "probe"`) are filtered out. Prompts, messages and tool output
are never read or displayed.