LuckymanJC on Discord ticked Google AI Studio in Settings › Allowances in the menu bar, and the macOS menu bar never showed it. The card comes from the magpie-gemini-web plugin's ai-studio provider (AIStudio2API). Its usage reports no allowance: Google AI Studio gives none to read, and the plugin only knows which models its accounts are cooling down on. With nothing cooling, the card holds just two text lines (代理出口, 管理页). quotaOfPlugin marks those Text and Aside, trayWindows has no window left, and trayCardText gives no label, so the menu bar draws nothing. The picker still offered the card because it asked only q.windows?.length. The picker now offers a card with a window that isn't text, or with a balance. That is what trayCardText can draw (withTrayKinds gives the same set its trayKind). While an account is cooling, the card has a used-100 window and is offered and drawn as before. A card ticked earlier stays in the list, under its card's name instead of its provider id, so it can be unticked. Comments in renderTrayUsage were cut to pay for this: app.js is 1,311,353 bytes against 1,311,462 at origin/main, and no budget was raised. Run on mote at this tree (970a86ff3+ this change): - go test ./internal/gui -run 'TestTray|TestCoreScriptBudget': ok (new TestTrayTextOnlyCardShowsNothing) - go test ./internal/provider -run 'TestPluginTextRowIsText|TestAIStudioServiceLinesAreText': ok - node --test tray-text-only (new), tray-inuse, tray-totals, tray-windows, tray-usage-redraw: ok, Chromium and WebKit, en/zh (tray-totals in five languages) - i18n-keys: "a plugin's words are its own" red, and red the same on origin/main970a86ff3in a clean worktree. It is already filed as #5332, #5327, #5482 and #5426. Nothing in this change touches it. - gofmt -l clean; GOOS=linux go vet -tags nogui and GOOS=windows go vet of internal/gui and internal/provider: ok Broken by hand: putting back q.windows?.length makes tray-text-only red ("nothing cooling: its card is text alone, not offered"). Not tried: the real app with the real plugin and a Google account. The plugin's card shape was read from magpie-gemini-web 0.10.0's lib/studio.mjs (usage, poolUsage, accountUsage, serviceWindows) from npm. Reported-by: LuckymanJC
65 lines
2.6 KiB
Go
65 lines
2.6 KiB
Go
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: fptr(40), Display: "40 / 100"},
|
||
{Name: "Credits", Display: "0 / 50", Limit: 50, Aside: true},
|
||
{Name: "On-demand", Used: fptr(0), 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)
|
||
}
|
||
}
|
||
|
||
// Google AI Studio's plugin (magpie-gemini-web's ai-studio) reports no
|
||
// allowance, only the models its accounts cool down on, beside two lines
|
||
// about its local service: its proxy and its admin page. With nothing
|
||
// cooling those lines are all its card has, and each is text, which the
|
||
// menu bar has no figure for and Settings leaves out of its picker
|
||
// (LuckymanJC on Discord); a cooldown is a reading.
|
||
func TestAIStudioServiceLinesAreText(t *testing.T) {
|
||
service := []plugin.UsageWindow{
|
||
{Name: "代理出口", Display: "不走代理(未设置)"},
|
||
{Name: "管理页", Display: "http://127.0.0.1:5000(用户名 admin)"},
|
||
}
|
||
q := quotaOfPlugin(SubscriptionQuota{Provider: "ai-studio", User: "a@gmail.com"}, plugin.Usage{Windows: service})
|
||
for _, w := range q.Windows {
|
||
if !w.Text {
|
||
t.Errorf("%s: not text", w.Name)
|
||
}
|
||
}
|
||
cooling := append([]plugin.UsageWindow{{Name: "所有模型", Used: fptr(100), ResetsAt: "2026-11-07T15:00:00Z", Display: "冷却中"}}, service...)
|
||
q = quotaOfPlugin(SubscriptionQuota{Provider: "ai-studio", User: "a@gmail.com"}, plugin.Usage{Windows: cooling})
|
||
if q.Windows[0].Text || q.Windows[0].Used != 100 {
|
||
t.Fatalf("cooldown %+v", q.Windows[0])
|
||
}
|
||
}
|