A new kind of package: a page in magpie's window (magpie.page), with magpie.permissions ["usage:summary"] and nothing else. Today, 7 or 30 days; models by tokens, calls or cost; the picks are saved through magpie.options.set (debounced past the bridge's once-a-second limit). Theme from --magpie-* variables; en and zh text. Run: - bun test packages/usage: 6 tests (permissions are exactly what the scripts read; no fetch/XHR/WebSocket; no inline scripts; every local reference exists; what tiles and rows say). - Sandbox magpie from yetone/magpie origin/main b03031738: `magpie plugin` lists "page Usage glance (reads usage:summary)". `magpie web` on 127.0.0.1:3595 serves every page file under the sandbox CSP (connect-src 'none'); /api/plugin-pages/read usage:summary answers the sandbox's 10 calls; providers:list is refused 403. Headless Chromium and WebKit (playwright 1.62.0) opened the sidebar tab: tiles "Calls 10, Errors 0, Tokens 70, Cost $0", row "stub-1 70 · 10 calls", no console errors; picking 7 days wrote "period": "7d" to plugins.json.
34 lines
1.6 KiB
Markdown
34 lines
1.6 KiB
Markdown
# @magpie-community/page-usage
|
||
|
||
A page in [magpie](https://usemagpie.ai)'s window with your usage at a glance. It shows calls, errors, tokens and cost for today, 7 days or 30 days, and the models that took them.
|
||
|
||
Install it from magpie's **Plugins › Discover**, or with `magpie plugin add @magpie-community/page-usage`. It then has a tab, **Usage glance**, under Plugins in the sidebar, in the app and in `magpie web`.
|
||
|
||
## What it reads
|
||
|
||
Only `usage:summary`, the one permission its `package.json` declares (`magpie.permissions`). That is magpie's totals for a period, and the top models in it. magpie refuses any other read the page asks for.
|
||
|
||
Like every plugin page, it runs in a sandboxed frame. It has no network (`connect-src 'none'`), no inline scripts, and no access to magpie's API except through `_magpie/bridge.js`.
|
||
|
||
## Options
|
||
|
||
```json
|
||
{ "period": "today", "sort": "tokens" }
|
||
```
|
||
|
||
The page saves the period (`today`, `7d`, `30d`) and the model sort (`tokens`, `calls`, `cost`) you last picked, so it opens the same next time.
|
||
|
||
## Files
|
||
|
||
- `page/index.html`, `page/style.css`: the page. It takes magpie's theme from the `--magpie-*` variables, light or dark.
|
||
- `page/view.js`: what the numbers and rows say, in English and Chinese, with no DOM. The test loads it.
|
||
- `page/app.js`: reads through the bridge, draws, and refreshes every minute.
|
||
|
||
## Test
|
||
|
||
```sh
|
||
bun test packages/usage
|
||
```
|
||
|
||
中文:在 magpie 窗口里加一个「Usage glance」页面,一眼看到今天、7 天或 30 天的调用、错误、token 和费用,以及用到的模型。它只读取声明过的 `usage:summary`,运行在无网络的沙盒 frame 里。
|