P5 of the plugin runtime (docs/subsystems/plugin-runtime.md):
- Panels (magpie.panels): a plugin draws a frame into a slot of a
built-in page (a provider's editor, Settings, Usage); magpie.context
says where it is, and the frame is as tall as what it draws.
- A page can replace a built-in one (magpie.page.replaces); show() opens
it in that page's place, and the sidebar row goes to it.
- page.titles and a panel's titles name it in the window's language
({"zh": …}); a malformed map is dropped, the title kept
(TestWindowTitles).
- main's #2501 already names wails:// in the policy of a page in the
desktop window (through ownWindow), which is why the usage page drew as
bare HTML from v0.1.1259. TestPluginPageLoadsItsFilesInTheWindow loads
a page through ownWindow in a real WKWebView, which Playwright on http
can't; the subsystem page says how.
- The bridge adds magpie's look for what a page leaves unstyled, every
rule in :where() so any rule of the page's wins, and the theme's
colours as --magpie-* variables.
One commit: the panels, the replacing pages and the titles share hunks
in page.go, pluginpage.go, pluginpages.js and the docs, and couldn't be
split cleanly.
Run:
- Full: this series (P5, the Plugins dot, the probe test, P6, and a
built-ins-on commit since dropped for main's own 5a2414acd) was run
together, at load 200-660.
At the pushed tree, 88dfab2d3 on origin/main 5380114da (rebased
from 210bc2b77, no conflicts; its GUI assets and tests are the same
bytes as the tree the GUI runs below used, diff -rq): gofmt clean,
vet darwin/linux nogui/windows ok, TestCoreScriptBudget ok
(1,446,845 of 1,447,000). go test -timeout 45m ./... at load
193-278: 62 packages ok, red in TestMainWindowCorners (#1936) and
TestPluginStreamLargeReplies JSON_fast (client timeout; alone 1 of
3 red here, 0 of 3 on 5380114da side by side at load ~280; the
series doesn't touch the stream path; #2551 reopened with the
output, taken). Two earlier runs at this tree are discarded: one
stopped when the disk filled, one when another session's go clean
-cache emptied the build cache mid-run. The whole GUI suite at
this tree was not finished (the disk filled); the files the series
reaches ran (1318 tests, 124 red), and the 39 red files ran again
at concurrency 1 on both trees: here 148 ok 120 red, origin/main
135 ok 127 red. Both sides' reds are page.goto/launch timeouts
under load (66 here, 71 there) and the same assertions:
title-bar-tools' and settings-proxy-auth's "access control checks"
on a cut-off /api/providers read (#2740, taken next), sidebar's
"the list unrolls" and WebKit "#prefs pressed darkens" (#2684;
alone, 1 red here, 3 on main), side-toggle (#2732); plugin-move
red on main only. Six files again one by one on both trees:
plugin-actions red 1 of 6 here, a 5s goto of ?view=plugins at load
260; plugin-clash red on both; plugin-own-icon, plugin-gateway,
plugin-checkin ok on both; settings-proxy-auth ok here, 3 red on
main.
At 976c9893a (on origin/main 6f950653f): go test -timeout 45m ./...
red only in TestMainWindowCorners (#1936, the window's process
killed at its deadline) and TestSetAnswersWhileDevinAndProvidersHang
(#1375, 3 of 3 alone). The whole GUI suite, both engines: 10834
tests, 237 red in 73 files, 184 of them a 180s browser launch. Those
73 files run again at concurrency 2: 52 green, among them every
plugin-* and agent-* file and plugin-actions; the 21 still red were
run at origin/main f191d6423 and are red there too: codex-predictions
(#2624), lightweight (#2638), segs-glide (#2683), usage-agents-hide
(#2276), provider-advanced-fold (#2552), routing-bodies (#2559),
routing-model-rest and rest-try-now (#2115, #2564), routing-keys-fold
(#1612), routing-wb-restricted (#1905), routing-request-metrics
(#2571), quota-count-wrap and quota-name-translated (#2228), s3-sync
(#2448), usage-checkin (#2549), usage-ledger-abort (#2700),
tencent-access-key (#2733), usage-range (#2734); side-toggle's WebKit
motion red 1 of 3 on main, 0 of 3 here (#2732); usage-fold green alone.
Rebased onto origin/main 717b69f78 (60725faa1, no conflicts): gofmt
clean, vet darwin/linux nogui/windows ok; go test -timeout 45m ./...
red in TestSetAnswersWhileDevinAndProvidersHang (#1375) and agent and
gateway at the 45m alarm with tests still moving at load 400+, both ok
alone (1173s, 1167s); 105 GUI files the series reaches (plugin*,
sidebar*, side-*, settings*, title*, header*, agent-*): 1322 tests,
23 red, run alone 214 of 218 ok, the 4 left in sidebar and
sidebar-overlay-scrollbar (WebKit), red on 717b69f78 too (#2684,
#1863). The whole GUI suite was not run again after the rebase.
- plugin-panels' tall panel (body{margin:0}) measured 220, not 180,
after the look above gave an unstyled body 20px of padding; the
fixture now sets padding:0 too, as a page that wants none would.
plugin-panels ok in chromium and webkit after.
- gofmt -l clean; go vet darwin, linux (-tags nogui) and windows ok.
- GUI: plugin-page and plugin-panels in chromium and webkit, en zh zh-TW
ja de, wide and narrow, ok.
- Broken by hand, each red then green: titled() in pluginpages.js
(the "draws in its frame" test), the wails:// scheme in pagePolicy
(the WKWebView test, before the rebase onto #2501), titles' parsing
(TestWindowTitles).
- Real use: the published @magpie-community/page-usage 0.1.1 in a
sandbox magpie window, its tiles styled.
142 lines
8.8 KiB
JavaScript
142 lines
8.8 KiB
JavaScript
// The Usage page: the allowances, what was spent and on what, the
|
||
// sessions, each request, and what filled the context window.
|
||
//
|
||
// A page the Usage plugin adds to the window (kernel.js), its words in
|
||
// i18n.js beside this file. This file registers the page and its markup,
|
||
// before app.js; page.js, after app.js and the scripts it shares the page
|
||
// with, is the page's code, and start.js then shows the first page. The
|
||
// hooks are what the shell asks of it: open (the reader came to the page),
|
||
// refresh (the window came back: the tab shown read again, quietly when it
|
||
// has its figures), reload (Refresh in the sidebar), costs (the currency
|
||
// or a rate changed) and tab (the tab shown, for the allowance card a
|
||
// link opens on). The allowance cards themselves, which the tray panel
|
||
// shows too, stay app.js's.
|
||
magpie.plugin("usage", (ctx) => {
|
||
ctx.slots.add("page", {
|
||
key: "usage",
|
||
title: "Usage",
|
||
html: `
|
||
<div class="usage-head">
|
||
<div class="segs" id="usageTab"></div>
|
||
<div class="segs" id="period"></div>
|
||
<div class="segs" id="sessRange" hidden></div>
|
||
<span class="ctx-range" id="ctxRange" hidden></span>
|
||
<span class="grow"></span>
|
||
<span class="usage-refresh" id="usageRefresh">
|
||
<button class="icon" id="usageReload" type="button" aria-label="Refresh now" data-tt><svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2.5v3h-3"/></svg></button>
|
||
<button class="sess-pick" id="usageEvery" type="button"></button>
|
||
</span>
|
||
<span class="usage-cost" id="usageCost"></span>
|
||
</div>
|
||
<div class="usage-pane" id="usagePane">
|
||
<div class="row-head quota-head" id="quotaHead" hidden>
|
||
<span class="label" data-t>Allowances</span>
|
||
<span class="grow"></span>
|
||
<button class="sess-pick quota-trend" id="quotaTrend" type="button" hidden></button>
|
||
<button class="text rt-mask" id="usageMask" aria-pressed="false" data-tt="Mask the accounts on this page — email addresses and account names — for a screenshot to share"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9.9 4.2A10.4 10.4 0 0 1 12 4c6.5 0 10 8 10 8a17.6 17.6 0 0 1-2.2 3.2M6.6 6.6C3.9 8.4 2 12 2 12s3.5 8 10 8a9.7 9.7 0 0 0 5.4-1.6M9.9 9.9a3 3 0 0 0 4.2 4.2M2 2l20 20"/></svg><span data-t>Hide accounts</span></button>
|
||
<div class="segs" id="quotaMode" hidden></div>
|
||
</div>
|
||
<section class="subscription-usage" id="subscriptionUsage"></section>
|
||
<p class="usage-note" id="usageScope" data-t>Gateway calls only; session-log calls are in Requests. Local rejections are excluded from totals.</p>
|
||
<section class="stats" id="stats"></section>
|
||
<section class="chart" id="chart"></section>
|
||
<div class="row-head"><button class="fold" type="button" data-fold="agents" aria-expanded="true" aria-controls="usageAgents"><span class="label" data-t>Agents</span></button></div>
|
||
<div class="list" id="usageAgents"></div>
|
||
<div class="us-hid" id="usageAgentsHid" hidden><button class="text us-hidline" type="button" aria-expanded="false"></button><div class="list" hidden></div></div>
|
||
<div class="row-head"><button class="fold" type="button" data-fold="models" aria-expanded="true" aria-controls="usageModels"><span class="label" data-t>Models</span></button></div>
|
||
<div class="list" id="usageModels"></div>
|
||
<div class="row-head" id="usageAccountsHead" hidden><button class="fold" type="button" data-fold="accounts" aria-expanded="true" aria-controls="usageAccounts"><span class="label" data-t>Accounts</span></button></div>
|
||
<div class="list" id="usageAccounts" hidden></div>
|
||
<div class="row-head" id="usageKeysHead" hidden><button class="fold" type="button" data-fold="keys" aria-expanded="true" aria-controls="usageKeys"><span class="label" data-t>Gateway keys</span></button></div>
|
||
<div class="list" id="usageKeys" hidden></div>
|
||
<p class="usage-note" id="usageNote"></p>
|
||
<div class="plugin-slot" data-slot="usage" hidden></div>
|
||
</div>
|
||
<div class="usage-pane" id="ledgerPane" hidden>
|
||
<div class="sess-tools">
|
||
<button class="sess-pick" id="ledComputer" type="button" hidden></button>
|
||
<button class="sess-pick" id="ledAgent" type="button" hidden></button>
|
||
<button class="sess-pick" id="ledPurpose" type="button" hidden></button>
|
||
<button class="sess-pick" id="ledProvider" type="button" hidden></button>
|
||
<button class="sess-pick" id="ledAccount" type="button" hidden></button>
|
||
<button class="sess-pick" id="ledKey" type="button" hidden></button>
|
||
<div class="segs" id="ledStatus"></div>
|
||
<span id="ledRoute" hidden><span id="ledRouteLabel"></span><button class="text" id="ledRouteClear" type="button" data-tt="Clear filter" aria-label="Clear filter">×</button></span>
|
||
<span class="grow"></span>
|
||
<input class="sess-filter" id="ledQ" type="search" spellcheck="false" autocomplete="off" placeholder="Search models, providers, sessions" data-tp>
|
||
<button class="text" id="ledExport" type="button" title="Save every request listed, all pages, as a CSV file in Downloads" data-tt><span data-t>Export CSV</span></button>
|
||
</div>
|
||
<p class="usage-note" id="ledScope" data-t>Gateway and session-log calls; local rejections excluded from totals.</p>
|
||
<div class="led-dash" id="ledDash" hidden>
|
||
<div class="led-strip" id="ledKpi"></div>
|
||
<section class="led-trend">
|
||
<div class="led-bar">
|
||
<div class="segs" id="ledMetric"></div>
|
||
<span class="grow"></span>
|
||
<span class="led-split"><span class="led-by" data-t>Split by</span><span class="segs" id="ledSplit"></span></span>
|
||
</div>
|
||
<div class="led-body">
|
||
<div class="led-chart" id="ledChart"></div>
|
||
<div class="led-rank" id="ledRank"></div>
|
||
<div class="led-rail" id="ledRail" hidden><i></i></div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
<section class="led-heat" id="ledHeat" hidden>
|
||
<div class="led-bar">
|
||
<div class="heat-title"><b data-t>Usage heatmap</b><span data-t>Daily usage over the last 53 weeks</span></div>
|
||
<span class="grow"></span>
|
||
<div class="segs" id="ledHeatMetric"></div>
|
||
</div>
|
||
<div class="heat-scroll" id="ledHeatScroll"></div>
|
||
<div class="heat-foot"></div>
|
||
<div class="heat-tip" id="ledHeatTip" hidden></div>
|
||
</section>
|
||
<div class="led-head"><p class="led-sum" id="ledSum"></p><span class="grow"></span><span class="led-arch" id="ledArchive"></span></div>
|
||
<div class="led-strip led-vias" id="ledVia" hidden></div>
|
||
<div class="led-wrap" id="ledWrap"></div>
|
||
<div class="led-hscroll" id="ledHScroll" hidden><div></div></div>
|
||
<div class="led-pager" id="ledPager" hidden></div>
|
||
<p class="usage-note" id="ledNote"></p>
|
||
</div>
|
||
<div class="usage-pane ctx-pane" id="contextPane" hidden></div>
|
||
<div class="usage-pane sess-pane" id="sessionsPane" hidden>
|
||
<div class="sess-tools">
|
||
<div class="segs" id="sessAgent"></div>
|
||
<button class="sess-pick" id="sessModel" type="button" hidden></button>
|
||
<button class="sess-pick" id="sessFolder" type="button" hidden></button>
|
||
</div>
|
||
<section class="stats" id="sessStats"></section>
|
||
<section class="chart sess-chart" id="sessChart" hidden></section>
|
||
<div class="sess-grid" id="sessGrid" hidden>
|
||
<section class="sess-card" id="sessProjects"></section>
|
||
<section class="sess-card" id="sessModels"></section>
|
||
<section class="sess-card" id="sessHours"></section>
|
||
<section class="sess-card" id="sessTop"></section>
|
||
<section class="sess-card" id="sessShape"></section>
|
||
<section class="sess-card" id="sessSkills"></section>
|
||
<section class="sess-card wide" id="sessTools"></section>
|
||
</div>
|
||
<div class="row-head" id="sessListHead" hidden>
|
||
<span class="label" data-t>Latest sessions</span>
|
||
<span class="grow"></span>
|
||
<button class="text sess-all" id="sessAll" type="button" data-feature="sessions" data-t>All sessions</button>
|
||
<input class="sess-filter" id="sessQ" type="search" spellcheck="false" autocomplete="off" placeholder="Search sessions" data-tp>
|
||
</div>
|
||
<div class="list sess-list" id="sessList"></div>
|
||
<p class="usage-note" id="sessNote"></p>
|
||
</div>
|
||
`,
|
||
mount() { mountUsageFolds(); },
|
||
open() { return loadUsage(true).catch((e) => status(e.message, "err")); },
|
||
refresh(again) {
|
||
// on the Overview, where the allowances are, coming back is opening them (#1588)
|
||
if (again && usageTab === "usage") quotasOpened();
|
||
return (again && usageDrawn() ? refreshUsage() : loadUsage()).catch((e) => status(e.message, "err"));
|
||
},
|
||
reload() { return refreshUsage(true); },
|
||
costs() { renderCosts(); },
|
||
tab() { return usageTab; },
|
||
});
|
||
});
|