usage: a plugin's row of text alone shows its text, not "· 100% left"
AutoClaw's 积分余额, Cline's balance, Cursor's Auto + Composer note and
the other plugin rows that are only words come to magpie as a window set
aside with a display and nothing counted (used 0, no amount, no limit).
Every surface read that used 0 as a share: the usage card said
"1,234 积分 · 100% left" (or "· 0% used") beside an empty meter, the
panel drew an empty ring, the TUI an empty bar, `magpie accounts` and
`magpie quota` "积分余额 0% (1,234 积分)", and the status line
"积分余额 0%".
provider: QuotaWindow.Text (json "text") marks such a row in
quotaOfPlugin: aside, a display, used/amount/limit all 0. Aside is
required: Cursor's On-demand "$0 / $20" isn't set aside and is a real
0%. QuotaSpan carries it to /api/quotas.
GUI (app.js): quotaText gives the display alone; the account row's
meter, the Usage page's track and the panel's rings leave the row out;
a panel card with only such rows shows their text on its line, as an
Unlimited card does. The tray's menu-bar text already skips aside rows.
TUI quotaCell, the CLI's quotaCell (accounts, quota) and statuslineCard
write the name and the text.
app.js stays under its budget (1,322,289, not raised; now 1,322,275):
to make room, the 8 copies of Math.max(0, Math.min(100, x)) are one
to100(x), and 8 one-line [..].filter(Boolean).join("\n") tooltips are
tipLines(..). Same results; the GUI files below cover those callers.
Readings cached before this release have no text flag and show as
before until the account is read again (a minute's cache, or Refresh).
Run, at this commit's tree (rebased on origin/main 9dc7d6eb8):
- internal/gui/tests/quota-text-row.test.cjs (new): a text row alone
and beside a counted window, through accountQuota, panelQuotaCard,
quotaWindows and quotaText; chromium and webkit, en and zh: 4 of 4.
- the GUI files the change reaches (quota*, usage*, panel*, tray*,
profile*, plugin-plan, plugin-quota*, plugin-panels, api-key-usage,
claude-usage, gateway-key-quotas, glm/opencode-go quota errors,
routing-quota-left, gui-de/ja/zh-TW, i18n-keys; 114 files, both
engines, 4 wide, load 130 to 200): 1433 of 1467. The reds, rerun
alone here and with 9dc7d6eb8's own app.js: quota-count-wrap (webkit,
#3404 #2228), usage-agents-hide (#3414 #2276), usage-checkin's Qoder
tab (webkit, #2549), usage-fold (#3415 #2163) and usage-ledger's
return-to-live (#3104) fail the same at both; api-key-usage failed
once 4 wide and passes alone at both (#3589).
- go test -timeout 45m ./internal/gui/ ./internal/cli/ ./internal/tui/
./internal/provider/: ok (TestCoreScriptBudget included).
- gofmt -l internal/ clean; go vet on darwin, linux (nogui) and windows
for provider, cli, tui (and gui on darwin): clean.
Broken by hand:
- app.js at HEAD under the new GUI test: red, quotaText gave
"1,234 积分 · 0% used" / "1,234 积分 · 已用 0%".
- quotaOfPlugin's Text line removed: TestPluginTextRowIsText red.
- the CLI's quotaCell at HEAD: TestQuotaCell red ("积分余额 0% (1,234 积分)");
statuslineCard at HEAD: red ("autoclaw-plugin 积分余额 0% 5h 40%").
- the TUI's quotaCell at HEAD: TestTextQuotaCell red
("积分余额 ░░░░░░░░ 1,234 积分 · 0% used").
Not tried: a real AutoClaw, Cline, Cursor, Factory or ZCode account in
the app (fixtures follow the plugins' own window shapes); the full
`go test ./...` and the whole GUI suite; the Linux and Windows apps.
This commit is contained in:
@@ -360,7 +360,7 @@ func accountRows(ls []provider.Login, now time.Time) []accountRow {
|
||||
// a pool's own windows stand in for the models' drawing on it,
|
||||
// as the usage page shows them
|
||||
for _, w := range provider.PooledWindows(q.Windows) {
|
||||
s := quotaSpan{Name: w.Name, Used: w.Used, Remaining: max(0, 100-w.Used), ResetsAt: w.ResetsAt, Display: w.Display, Pool: w.Pool}
|
||||
s := quotaSpan{Name: w.Name, Used: w.Used, Remaining: max(0, 100-w.Used), ResetsAt: w.ResetsAt, Display: w.Display, Text: w.Text, Pool: w.Pool}
|
||||
if s.ResetsAt == nil && w.ResetSecs > 0 {
|
||||
t := now.Add(time.Duration(w.ResetSecs) * time.Second)
|
||||
s.ResetsAt = &t
|
||||
@@ -382,7 +382,10 @@ func quotaCell(w quotaSpan, now time.Time) string {
|
||||
return name + " unlimited"
|
||||
}
|
||||
cell := fmt.Sprintf("%s %.0f%%", name, w.Used)
|
||||
if w.Display != "" {
|
||||
if w.Text {
|
||||
// a row of text alone has no share to tell
|
||||
cell = name + " " + w.Display
|
||||
} else if w.Display != "" {
|
||||
cell += " (" + w.Display + ")"
|
||||
}
|
||||
if w.ResetsAt != nil {
|
||||
|
||||
@@ -143,6 +143,14 @@ func TestQuotaCell(t *testing.T) {
|
||||
if got := quotaCell(quotaSpan{Name: "Limit", Unlimited: true}, now); got != "Limit unlimited" {
|
||||
t.Fatalf("unlimited: %q", got)
|
||||
}
|
||||
// a plugin's row of text alone is its text, not 0% (its used 0)
|
||||
if got := quotaCell(quotaSpan{Name: "积分余额", Display: "1,234 积分", Text: true}, now); got != "积分余额 1,234 积分" {
|
||||
t.Fatalf("text: %q", got)
|
||||
}
|
||||
// and the status line's cell too
|
||||
if got := statuslineCard(provider.Quota{Provider: "autoclaw-plugin", Windows: []provider.QuotaSpan{{Name: "积分余额", Display: "1,234 积分", Text: true}, {Name: "5 hours", Used: 40}}}, now); got != "autoclaw-plugin 积分余额 1,234 积分 5h 40%" {
|
||||
t.Fatalf("status line: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// accountRows shows a pool's own windows in place of its models', as the
|
||||
|
||||
@@ -155,6 +155,9 @@ func statuslineCard(q provider.Quota, now time.Time) string {
|
||||
switch {
|
||||
case w.Unlimited:
|
||||
cells = append(cells, n+" ∞")
|
||||
case w.Text:
|
||||
// a row of text alone (a plugin's balance) has no share
|
||||
cells = append(cells, n+" "+w.Display)
|
||||
case w.ResetsAt != nil && !w.ResetsAt.After(now):
|
||||
// its window has started again since it was read
|
||||
cells = append(cells, n+" 0%")
|
||||
|
||||
+25
-21
@@ -804,7 +804,7 @@ function renderProfiles() {
|
||||
c._profile = p.name;
|
||||
if (profilePending.has(p.name)) c.classList.add("pending");
|
||||
const lib = profileLibrary(p.library);
|
||||
c.title = [p.inUse && t("In use"), p.summary, lib].filter(Boolean).join("\n");
|
||||
c.title = tipLines(p.inUse && t("In use"), p.summary, lib);
|
||||
// the one the setup is now, ticked as a menu ticks the item in effect
|
||||
if (p.inUse) {
|
||||
c.classList.add("cur");
|
||||
@@ -13551,7 +13551,7 @@ function accountQuota(data, user, capFor = () => 0, settable = null) {
|
||||
if (q?.resets?.count && !q.error) {
|
||||
const words = resetsWords(q.resets);
|
||||
const resets = el("span", "aq-w aq-resets");
|
||||
resets.title = [words.textContent, words.title].filter(Boolean).join("\n");
|
||||
resets.title = tipLines(words.textContent, words.title);
|
||||
resets.append(words.querySelector(".resets-n"));
|
||||
line.append(resets);
|
||||
}
|
||||
@@ -13580,23 +13580,23 @@ function accountQuota(data, user, capFor = () => 0, settable = null) {
|
||||
if (!ws.length) { line.append(el("span", "aq-none", t("Unlimited"))); return line; }
|
||||
if (ws.some((w) => w.members)) return poolLine(line, ws, q, capFor, settable);
|
||||
line.title = ws.slice(2).map((w) => w.tiers ? tiersText(w) : t(w.name) + " " + quotaText(w)).join(ws !== counted ? "\n" : " · ");
|
||||
if (q.asOf) line.title = [line.title, asOfText(q)].filter(Boolean).join("\n");
|
||||
if (q.asOf) line.title = tipLines(line.title, asOfText(q));
|
||||
for (const w of ws.slice(0, 2)) {
|
||||
const used = Math.max(0, Math.min(100, w.used));
|
||||
const used = to100(w.used);
|
||||
const m = el("span", "aq-w" + (used >= 90 ? " full" : ""));
|
||||
const track = el("span", "aq-track");
|
||||
const fill = el("i");
|
||||
fill.style.width = quotaFill(w) + "%";
|
||||
track.append(fill);
|
||||
capMark(track, w, capFor(w));
|
||||
m.append(el("span", "aq-n", t(w.name)), track, el("b", "", quotaText(w)));
|
||||
m.append(el("span", "aq-n", t(w.name)), ...(w.text ? [] : [track]), el("b", "", quotaText(w)));
|
||||
if (w.resetsAt) {
|
||||
const at = new Date(w.resetsAt);
|
||||
m.title = resetText(at, at.toLocaleString(intlLang()));
|
||||
if (used >= 80) m.append(el("span", "aq-r", resetInText(at)));
|
||||
}
|
||||
const out = runsOutText(w, (at) => at.toLocaleString(intlLang()));
|
||||
if (out) m.title = [m.title, out].filter(Boolean).join("\n");
|
||||
if (out) m.title = tipLines(m.title, out);
|
||||
if (w.tiers) m.title = tiersText(w);
|
||||
line.append(settable ? settable(m, w) : m);
|
||||
}
|
||||
@@ -13981,13 +13981,16 @@ setInterval(refreshLanes, 2000);
|
||||
// every meter and the menu bar, kept in the settings (#122). The vendor's
|
||||
// own count, where it gives one, stands before the percentage.
|
||||
let quotaLeft = false;
|
||||
function to100(v) { return Math.max(0, Math.min(100, v)); }
|
||||
function tipLines(...a) { return a.filter(Boolean).join("\n"); }
|
||||
function quotaFill(w) {
|
||||
const used = Math.round(Math.max(0, Math.min(100, w.used)));
|
||||
const used = Math.round(to100(w.used));
|
||||
return quotaLeft ? 100 - used : used;
|
||||
}
|
||||
function quotaText(w) {
|
||||
if (w.unlimited) return t("Unlimited");
|
||||
const used = Math.max(0, Math.min(100, w.used));
|
||||
if (w.text) return w.display;
|
||||
const used = to100(w.used);
|
||||
const n = quotaLeft ? 100 - used : used;
|
||||
const pct = t(quotaLeft ? "{n} left" : "{n} used", { n: (Number.isInteger(n) ? n : n.toFixed(1)) + "%" });
|
||||
const count = quotaCount(w);
|
||||
@@ -14004,7 +14007,7 @@ function quotaPace(w, now = Date.now()) {
|
||||
if (w.unlimited || w.historyMissing || !w.startsAt || !w.resetsAt) return null;
|
||||
const s = Date.parse(w.startsAt), e = Date.parse(w.resetsAt);
|
||||
if (!(e > s) || now < s || now >= e) return null;
|
||||
const d = Math.max(0, Math.min(100, w.used)) - (100 * (now - s)) / (e - s);
|
||||
const d = to100(w.used) - (100 * (now - s)) / (e - s);
|
||||
const n = Math.round(quotaLeft ? -d : d);
|
||||
return { n: n === 0 ? 0 : n, over: Math.round(d) > 0, under: Math.round(d) < 0, by: Math.abs(Math.round(d)) };
|
||||
}
|
||||
@@ -16340,7 +16343,7 @@ function quotaSpan(lines, range, now) {
|
||||
// new subpath at each cycle's start; the point before x0 and the one after
|
||||
// x1 go along, so the line reaches the box's edges
|
||||
function quotaPaths(points, x0, x1, w, h) {
|
||||
const X = (t) => ((t - x0) / (x1 - x0)) * w, Y = (v) => h - (Math.max(0, Math.min(100, v)) / 100) * h;
|
||||
const X = (t) => ((t - x0) / (x1 - x0)) * w, Y = (v) => h - (to100(v) / 100) * h;
|
||||
let d = "", prev = null;
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const p = points[i];
|
||||
@@ -16477,7 +16480,7 @@ function quotaCurve(sub) {
|
||||
pace.textContent = p ? quotaEtaText(longest, now) : "";
|
||||
// which window it is, and the instant with its year, behind a line
|
||||
// that holds day and minute and is cut short rather than wrapped
|
||||
pace.title = p ? [shown.length > 1 ? longest.label : "", pace.textContent, p.out != null ? new Date(p.out).toLocaleString(intlLang()) : ""].filter(Boolean).join("\n") : "";
|
||||
pace.title = p ? tipLines(shown.length > 1 ? longest.label : "", pace.textContent, p.out != null ? new Date(p.out).toLocaleString(intlLang()) : "") : "";
|
||||
};
|
||||
box.append(head, g, axis, legend);
|
||||
box.draw();
|
||||
@@ -16623,7 +16626,7 @@ function sparkGap(points, start, reset, now, w, h) {
|
||||
}
|
||||
if (pts.length < 2) return null;
|
||||
const X = (at) => ((at - start) / (reset - start)) * w;
|
||||
const Y = (v) => h - (Math.max(0, Math.min(100, v)) / 100) * h;
|
||||
const Y = (v) => h - (to100(v) / 100) * h;
|
||||
const E = (at) => ((at - start) / (reset - start)) * h; // the even burn's y
|
||||
const a = pts[0].at, b = pts[pts.length - 1].at;
|
||||
const poly = pts.map((p) => X(p.at).toFixed(1) + "," + Y(p.left).toFixed(1))
|
||||
@@ -17316,9 +17319,10 @@ function panelQuotaCard(q) {
|
||||
const balance = q.balance && balanceRow(q, "What is left on the account besides its windows", false);
|
||||
// a pool's 5-hour and weekly rings, every pool's (a third pool once left
|
||||
// Claude's out: 01huadalang on Discord), else three
|
||||
const fam = familyWindows(q.windows.filter((w) => !w.unlimited));
|
||||
if (!fam.length && q.windows.some((w) => w.unlimited)) {
|
||||
card.append(pqLine(t("Unlimited"), q));
|
||||
const fam = familyWindows(q.windows.filter((w) => !w.unlimited && !w.text));
|
||||
const tx = q.windows.filter((w) => w.text).map((w) => t(w.name) + " " + w.display).join(" · ");
|
||||
if (!fam.length && (tx || q.windows.some((w) => w.unlimited))) {
|
||||
card.append(pqLine(tx || t("Unlimited"), q));
|
||||
if (balance) card.append(balance);
|
||||
return card;
|
||||
}
|
||||
@@ -17346,7 +17350,7 @@ function panelQuotaCard(q) {
|
||||
card.append(pqLine(say, q));
|
||||
const rings = el("span", "pq-rings" + (ws.length > 4 ? " many" : ""));
|
||||
for (const w of ws) {
|
||||
const used = Math.max(0, Math.min(100, w.used));
|
||||
const used = to100(w.used);
|
||||
const r = el("span", "pq-ring" + (used >= 90 ? " full" : ""));
|
||||
const dial = el("span", "pq-dial");
|
||||
dial.style.setProperty("--p", quotaFill(w));
|
||||
@@ -18036,7 +18040,7 @@ function balanceShown(q) {
|
||||
|
||||
// balanceMeter: a balance field's percent, as a meter.
|
||||
function balanceMeter(percent) {
|
||||
const share = Math.max(0, Math.min(100, percent));
|
||||
const share = to100(percent);
|
||||
const track = el("div", "quota-track" + (share >= 90 ? " full" : ""));
|
||||
const fill = el("i");
|
||||
fill.style.width = share + "%";
|
||||
@@ -18308,7 +18312,7 @@ function quotaWindows(sub) {
|
||||
if (w.historyMissing) track.style.visibility = "hidden";
|
||||
track.append(fill);
|
||||
quota.append(labels);
|
||||
if (!w.unlimited) quota.append(track);
|
||||
if (!w.unlimited && !w.text) quota.append(track);
|
||||
// when it starts again, on the clock and how long until then
|
||||
let r = null;
|
||||
if (w.resetsAt) {
|
||||
@@ -18332,7 +18336,7 @@ function quotaWindows(sub) {
|
||||
if (!r) quota.append(r = el("div", "quota-reset"));
|
||||
else r.append(" · ");
|
||||
r.append(el("span", "", out + " ·"), " ", el("span", "", untilText(new Date(w.runsOutAt))));
|
||||
quota.title = [quota.title, runsOutText(w, (at) => at.toLocaleString(intlLang()))].filter(Boolean).join("\n");
|
||||
quota.title = tipLines(quota.title, runsOutText(w, (at) => at.toLocaleString(intlLang())));
|
||||
}
|
||||
// what the whole window holds, by what magpie routed in it (Chiao), on
|
||||
// the reset's line, so the window keeps its three rows
|
||||
@@ -18353,7 +18357,7 @@ function quotaWindows(sub) {
|
||||
// a model family's figure: its models, level by level, in its tooltip
|
||||
if (w.tiers) quota.title = t("{family}: the most used of its models", { family: w.name }) + "\n" + tiersText(w);
|
||||
// a pool's: when it starts again, and the models it counts
|
||||
if (w.members) quota.title = [quota.title, poolTip(w)].filter(Boolean).join("\n");
|
||||
if (w.members) quota.title = tipLines(quota.title, poolTip(w));
|
||||
windows.append(quota);
|
||||
}
|
||||
quotaFit.observe(windows);
|
||||
@@ -18441,7 +18445,7 @@ function ledGroupSpeed(x) {
|
||||
const [a, b] = measured && floor && kf > kv ? [floor, measured] : [measured || floor, measured && floor];
|
||||
const say = (p) => p.count ? p.head + " · " + p.count : p.head;
|
||||
const main = say(a), other = b ? say(b) : "";
|
||||
return { v: a.s, text: other ? t("{a}; {b}", { a: main, b: other }) : main, main, mainParts: a.count ? [a.head, " " + a.count] : [a.head], other, title: [a.title, b?.title].filter(Boolean).join("\n") };
|
||||
return { v: a.s, text: other ? t("{a}; {b}", { a: main, b: other }) : main, main, mainParts: a.count ? [a.head, " " + a.count] : [a.head], other, title: tipLines(a.title, b?.title) };
|
||||
}
|
||||
// their mean wait for the first token, 0 for none
|
||||
const ledTTFT = (x) => x?.timed > 0 ? x.ttft_ms / x.timed : 0;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A plugin's usage row that is its text alone (the server's text: an
|
||||
// aside with a display and nothing counted, as AutoClaw's 积分余额, Cline's
|
||||
// balance or Cursor's Auto + Composer note) reads as that text: no meter,
|
||||
// no ring and no "100% left" or "0% used" after it. Before, its used 0 drew
|
||||
// an empty meter and "· 100% left". A counted window beside it is drawn
|
||||
// as before. English and Chinese; no backend, the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
|
||||
function serve(lang) {
|
||||
const settings = { theme: "light", lang, tray: "panel" };
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings });
|
||||
if (url.pathname === "/api/settings") return json(settings);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh"]) {
|
||||
test(`${engine} ${lang}: a usage row of text alone shows its text only`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width: 900, height: 700 } })).newPage();
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang));
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.waitForFunction(() => typeof panelQuotaCard === "function");
|
||||
const got = await page.evaluate(() => {
|
||||
const read = (windows) => {
|
||||
const q = { windows, name: "AutoClaw", user: "test" };
|
||||
const row = accountQuota({ test: q }, "test"), panel = panelQuotaCard(q), usage = quotaWindows(q);
|
||||
return {
|
||||
row: row.textContent, meters: row.querySelectorAll(".aq-track").length,
|
||||
panel: panel.textContent, rings: panel.querySelectorAll(".pq-ring").length,
|
||||
usage: usage.textContent, tracks: usage.querySelectorAll(".quota-track").length,
|
||||
text: quotaText(windows[windows.length - 1]),
|
||||
};
|
||||
};
|
||||
const balance = { name: "积分余额", used: 0, display: "1,234 积分", text: true };
|
||||
return { alone: read([balance]), beside: read([{ name: "5 hours", used: 40 }, balance]) };
|
||||
});
|
||||
const { alone, beside } = got;
|
||||
assert.equal(alone.text, "1,234 积分");
|
||||
for (const [where, s] of Object.entries({ row: alone.row, panel: alone.panel, usage: alone.usage })) {
|
||||
assert.match(s, /1,234 积分/, where);
|
||||
assert.doesNotMatch(s, /%/, where);
|
||||
}
|
||||
assert.equal(alone.meters, 0);
|
||||
assert.equal(alone.rings, 0);
|
||||
assert.equal(alone.tracks, 0);
|
||||
// the counted window keeps its meter, ring and share; the text row none
|
||||
assert.equal(beside.text, "1,234 积分");
|
||||
assert.equal(beside.meters, 1);
|
||||
assert.equal(beside.rings, 1);
|
||||
assert.equal(beside.tracks, 1);
|
||||
assert.match(beside.usage, /1,234 积分/);
|
||||
assert.equal((beside.usage.match(/%/g) || []).length, 1, beside.usage);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,10 @@ func quotaOfPlugin(q SubscriptionQuota, u plugin.Usage) SubscriptionQuota {
|
||||
w := QuotaWindow{Name: x.Name, Used: x.Used, ResetSecs: x.ResetSecs, Display: x.Display,
|
||||
Amount: x.Amount, Limit: x.Limit, Unit: x.Unit,
|
||||
Span: time.Duration(x.Span * float64(time.Second)), Model: strings.ToLower(x.Model), Aside: x.Aside}
|
||||
// a row set aside with text and nothing counted is that text: a
|
||||
// window that counts nothing yet says 0 with a count, or with no
|
||||
// text, and one that stops the account is a reading at 0
|
||||
w.Text = x.Aside && x.Display != "" && x.Used == 0 && x.Amount == 0 && x.Limit == 0
|
||||
if t, err := time.Parse(time.RFC3339, x.ResetsAt); err == nil {
|
||||
w.ResetsAt = &t
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
)
|
||||
|
||||
// A plugin's row set aside with text and nothing counted (AutoClaw's
|
||||
// 积分余额, Cline's balance, Cursor's Auto + Composer note) is that text:
|
||||
// QuotaWindow.Text, carried to /api/quotas' span, so the GUI, TUI and CLI
|
||||
// don't read its used 0 as "100% left". A window that counts, a 0 with a
|
||||
// limit, and one not set aside (Cursor's On-demand "$0 / $20", a real 0%)
|
||||
// are readings and stay so.
|
||||
func TestPluginTextRowIsText(t *testing.T) {
|
||||
q := quotaOfPlugin(SubscriptionQuota{Provider: "autoclaw-plugin", User: "u"}, plugin.Usage{Windows: []plugin.UsageWindow{
|
||||
{Name: "积分余额", Display: "1,234 积分", Aside: true},
|
||||
{Name: "5 hours", Used: 40, Display: "40 / 100"},
|
||||
{Name: "Credits", Display: "0 / 50", Limit: 50, Aside: true},
|
||||
{Name: "On-demand", Display: "$0 / $20"},
|
||||
{Name: "Bare", Aside: true},
|
||||
}})
|
||||
want := []bool{true, false, false, false, false}
|
||||
for i, w := range q.Windows {
|
||||
if w.Text != want[i] {
|
||||
t.Errorf("%s: Text %v", w.Name, w.Text)
|
||||
}
|
||||
}
|
||||
r := quotaReport([]SubscriptionQuota{q}, nil, nil, time.Now())
|
||||
if len(r) != 1 || len(r[0].Windows) != 5 || !r[0].Windows[0].Text || r[0].Windows[1].Text {
|
||||
t.Fatalf("report %+v", r)
|
||||
}
|
||||
b, _ := json.Marshal(r[0].Windows[:2])
|
||||
if s := string(b); strings.Count(s, `"text":true`) != 1 {
|
||||
t.Fatalf("json %s", s)
|
||||
}
|
||||
}
|
||||
@@ -124,6 +124,9 @@ type QuotaSpan struct {
|
||||
Remaining float64 `json:"remaining"`
|
||||
ResetsAt *time.Time `json:"resetsAt,omitempty"`
|
||||
Display string `json:"display,omitempty"` // the vendor's own count, "1.2k / 3k"
|
||||
// Text: the window is its Display alone, Used and Remaining no
|
||||
// reading (QuotaWindow.Text)
|
||||
Text bool `json:"text,omitempty"`
|
||||
// Amount of Limit in Unit: the window's count, used, when the vendor
|
||||
// counts it so ("credits")
|
||||
Amount float64 `json:"amount,omitempty"`
|
||||
@@ -185,7 +188,7 @@ func quotaReport(subs, plans, balances []SubscriptionQuota, now time.Time) []Quo
|
||||
// a pool's own windows stand in for the models' drawing on it,
|
||||
// as the usage page shows them
|
||||
for _, w := range PooledWindows(q.Windows) {
|
||||
s := QuotaSpan{Unlimited: w.Unlimited, Name: w.Name, Used: w.Used, Remaining: max(0, 100-w.Used), ResetsAt: w.ResetsAt, Display: w.Display,
|
||||
s := QuotaSpan{Unlimited: w.Unlimited, Name: w.Name, Used: w.Used, Remaining: max(0, 100-w.Used), ResetsAt: w.ResetsAt, Display: w.Display, Text: w.Text,
|
||||
Amount: w.Amount, Limit: w.Limit, Unit: w.Unit, Pool: w.Pool, Holds: w.Holds, HoldsWhy: w.HoldsWhy}
|
||||
if s.ResetsAt == nil && w.ResetSecs > 0 {
|
||||
t := now.Add(time.Duration(w.ResetSecs) * time.Second)
|
||||
|
||||
@@ -33,6 +33,13 @@ type QuotaWindow struct {
|
||||
ResetsAt *time.Time `json:"resetsAt,omitempty"`
|
||||
ResetSecs int64 `json:"resetSecs,omitempty"`
|
||||
Display string `json:"display,omitempty"`
|
||||
// Text is set on a window that is its Display alone, with no share
|
||||
// to tell: a plugin's row of what an account holds or has done
|
||||
// (AutoClaw's 积分余额 and 每日签到, Cursor's on-demand spend, ZCode's
|
||||
// gift to claim), which plugins send set aside with used 0 and no
|
||||
// count. Its Used is no reading, so it is told as its text, never as
|
||||
// "100% left".
|
||||
Text bool `json:"text,omitempty"`
|
||||
// Amount of Limit is the window's own count in Unit, when the vendor
|
||||
// counts it so (WorkBuddy's credits): Used is Amount as a share of
|
||||
// Limit. The GUI says it as used or left, as it says the share (#659).
|
||||
|
||||
@@ -1440,6 +1440,10 @@ func quotaCell(w provider.QuotaWindow, left bool, now time.Time) string {
|
||||
pct = c + " · " + pct
|
||||
}
|
||||
c := sMuted.Render(w.Name) + " " + fill.Render(strings.Repeat("█", on)) + sFaint.Render(strings.Repeat("░", cells-on)) + " " + sText.Render(pct)
|
||||
if w.Text {
|
||||
// a row of text alone: no meter, no share to tell
|
||||
c = sMuted.Render(w.Name) + " " + sText.Render(w.Display)
|
||||
}
|
||||
var at time.Time
|
||||
if w.ResetsAt != nil {
|
||||
at = *w.ResetsAt
|
||||
|
||||
@@ -122,6 +122,17 @@ func TestUnlimitedQuotaCell(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin's row of text alone (AutoClaw's 积分余额) reads as its text: no
|
||||
// meter and no share after it, where its used 0 read "100% left".
|
||||
func TestTextQuotaCell(t *testing.T) {
|
||||
for _, left := range []bool{false, true} {
|
||||
got := quotaCell(provider.QuotaWindow{Name: "积分余额", Display: "1,234 积分", Text: true}, left, time.Now())
|
||||
if !strings.Contains(got, "1,234 积分") || strings.Contains(got, "%") || strings.Contains(got, "░") {
|
||||
t.Fatalf("text: %q", got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The Usage page shows, under the gateway's calls, those the agents made
|
||||
// on their own, read from their session files, as the app's Usage page
|
||||
// counts them (Kumo31 on Discord: Codex used outside magpie wasn't in the
|
||||
|
||||
Reference in New Issue
Block a user