Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
provider: a usage window's count is its share when used is left out (plugins#468)
yetone1390aa458f6d
diff --git a/internal/provider/plugin_usage.go b/internal/provider/plugin_usage.goindex 7bd4a2e63..ce586a07e 100644--- a/internal/provider/plugin_usage.go+++ b/internal/provider/plugin_usage.go@@ -163,8 +163,18 @@ func quotaOfPlugin(q SubscriptionQuota, u plugin.Usage) SubscriptionQuota {b := *x.Balancew.Balance = &b}- if x.Used != nil {- w.Used = *x.Used+ used := x.Used+ if used == nil && x.Limit > 0 && x.Amount > 0 && x.Balance == nil {+ // the plugin told the window's count and not its share: the share+ // is the count's. Before, such a window was text alone and an+ // account with no other was unknown to routing (plugins#468). An+ // amount of 0 is what a count left out reads as, so it says+ // nothing yet.+ u := x.Amount / x.Limit * 100+ used = &u+ }+ if used != nil {+ w.Used = *used} else if !x.Aside && x.Balance == nil {// the plugin didn't say how much of it is used: its text is all// there is, and routing has no share to count (#3650)@@ -173,7 +183,7 @@ func quotaOfPlugin(q SubscriptionQuota, u plugin.Usage) SubscriptionQuota {// 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 = w.Text || x.Aside && x.Display != "" && (x.Used == nil || *x.Used == 0) && x.Amount == 0 && x.Limit == 0 && x.Balance == nil+ w.Text = w.Text || x.Aside && x.Display != "" && (used == nil || *used == 0) && x.Amount == 0 && x.Limit == 0 && x.Balance == nilif t, err := time.Parse(time.RFC3339, x.ResetsAt); err == nil {w.ResetsAt = &t}diff --git a/internal/provider/plugin_usage_absent_test.go b/internal/provider/plugin_usage_absent_test.goindex 97f1d7c69..f3c7471ad 100644--- a/internal/provider/plugin_usage_absent_test.go+++ b/internal/provider/plugin_usage_absent_test.go@@ -132,3 +132,34 @@ func TestPluginHostPassesAnAbsentUsedOn(t *testing.T) {t.Error("a used of 0 that was said is not known")}}++// A window that tells its count (amount of limit) and leaves out used has+// its share in that count: 370 of 1000 is 37% used, read by routing when+// it stops the account and shown with its count when it is aside. Before,+// it was text alone, and an account whose windows all told counts so was+// unknown to routing (plugins#468). A count of 0, what a left-out amount+// reads as, still says nothing.+func TestAWindowsCountIsItsShare(t *testing.T) {+ var u plugin.Usage+ if err := json.Unmarshal([]byte(`{"windows":[+ {"name":"Credits","amount":370,"limit":1000,"unit":"credits","display":"370 / 1000","resetsAt":"2099-01-01T00:00:00Z"},+ {"name":"Bonus","amount":5,"limit":20,"aside":true,"display":"5 / 20"},+ {"name":"Daily","limit":100,"display":"? / 100"}]}`), &u); err != nil {+ t.Fatal(err)+ }+ now := time.Now()+ q := quotaOfPlugin(SubscriptionQuota{Provider: "acme-plugin", User: "u"}, u)+ if w := q.Windows[0]; w.Text || w.Aside || w.Used != 37 {+ t.Errorf("a counted window: Text %v, Aside %v, Used %v", w.Text, w.Aside, w.Used)+ }+ if w := q.Windows[1]; w.Text || !w.Aside || w.Used != 25 {+ t.Errorf("a counted window set aside: Text %v, Aside %v, Used %v", w.Text, w.Aside, w.Used)+ }+ if w := q.Windows[2]; !w.Text || !w.Aside {+ t.Errorf("a limit with no count: Text %v, Aside %v", w.Text, w.Aside)+ }+ a, ok := routedAllowance("plugin:acme", "u", q, now)+ if used, _ := a.For("", now); !ok || used != 37 {+ t.Errorf("routing: known %v, used %v; want the count's 37", ok, used)+ }+}