diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index dab933158..07b5a1892 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -14019,7 +14019,7 @@ function windowCapsOf(p, user) { return Object.keys(p?.accountWindowCaps?.[Strin function windowCapOf(p, user, w) { const own = windowOwnCapOf(p, user, w); if (own) return own >= 100 ? 0 : own; - return accountCapOf(p, user); + return w?.ownCap ? 0 : accountCapOf(p, user); } // capHeldOf: how the account is held at cap, as the gateway reads it — // a window at or past its cap (capFor: its own, else the account's), not @@ -14112,7 +14112,7 @@ function pillNumber(at, val, ph, cls, label, parse, bad, own, set) { // sets the window's own cap, a family's its models' (tiers); not on-demand's. function windowCapMeter(m, p, user, w) { const ids = (w.tiers || [w]).map((x) => x.capId), owns = ids.map((capId) => windowOwnCapOf(p, user, { capId })); - if (!ids.every(Boolean)) return m; + if (!ids.every(Boolean) || w.ownCap && !(owns[0] % 100)) return m; const own = new Set(owns).size > 1 ? 0 : owns[0], cap = accountCapOf(p, user); const name = t(w.name); const b = spanBtn(el("span", m.className + " aq-set" + (own ? " own" : ""))); diff --git a/internal/gui/tests/window-cap.test.cjs b/internal/gui/tests/window-cap.test.cjs index ec3f7b4ca..50187c384 100644 --- a/internal/gui/tests/window-cap.test.cjs +++ b/internal/gui/tests/window-cap.test.cjs @@ -30,7 +30,9 @@ const fresh = () => ({ ], }, // the friend's five hours stop at 50%, its week at 40%; no account cap - accountWindowCaps: { "friend@example.com": { "5 hours": 50, weekly: 40 } }, + // and its plan's credits at 50%, set before a plugin set that window + // aside (ferock on Discord) + accountWindowCaps: { "friend@example.com": { "5 hours": 50, weekly: 40, credits: 50 } }, }, }); const win = (name, used, h) => ({ name, capId: name.toLowerCase(), used, resetsAt: inHours(h), capped: true }); @@ -44,6 +46,11 @@ const past = () => ({ "me@example.com": under()["me@example.com"], "Friend@Example.com": { provider: "codex", windows: [win("5 hours", 60, 3), win("Weekly", 10, 100)] }, }); +// a window set aside holds at its own cap only (ownCap): WorkBuddy's +// plan's credits and the extra ones, the account stopped by their total +const aside = (name, used) => ({ ...win(name, used, 600), ownCap: true }); +const credits = (plan) => ({ provider: "codex", windows: [aside("Credits", plan), aside("Extra credits", 0), win("Total credits", plan / 4, 600)] }); +const split = () => ({ "me@example.com": credits(60), "Friend@Example.com": credits(60) }); function serve(lang, posts, use) { const ps = fresh(); @@ -170,6 +177,27 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(errors, []); }); + test(`${label}: a window set aside holds the account at the cap set on it before, and only that one`, async (t) => { + const { page, errors, posts } = await open(t, "aside", split); + // the friend's Credits at 60%, past the 50% set on it: held, marked + const held = row(page, "Friend@Example.com").locator(".acap-held"); + if (w.held) assert.match(await held.textContent(), /^[^·]+·/); + assert.equal(await held.count(), 1); + assert.deepEqual(await row(page, "Friend@Example.com").locator(".aq-cap").evaluateAll((ms) => ms.map((m) => m.style.left)), ["50%"]); + // me has none on it: no note, no mark, and no new cap on a window set aside + assert.equal(await row(page, "me@example.com").locator(".acap-held, .aq-cap, .aq-own").count(), 0); + assert.equal(await row(page, "me@example.com").locator('.aq-set[role="button"]').count(), 0); + // the friend's is lifted from its meter + await still(page, "Friend@Example.com", meter(page, "Friend@Example.com", 0)); + await menu(page).waitFor(); + const n = posts.length; + await item(page, w.account).click(); + assert.deepEqual(await posted(posts, n), { id: "codex", account: "Friend@Example.com", window: "credits", cap: 0 }); + await page.waitForFunction(() => !document.querySelector('.editor .acc[data-account-id="Friend@Example.com"] .acap-held')); + assert.equal(await row(page, "Friend@Example.com").locator('.aq-set[role="button"]').count(), 0); + assert.deepEqual(errors, []); + }); + test(`${label}: a window's cap is set from its meter in the app's menu, typed, and lifted`, async (t) => { const { page, errors, posts } = await open(t, "set", under); // me's five hours: the menu, headed by the window, no native select diff --git a/internal/provider/account_caps.go b/internal/provider/account_caps.go index 45c235024..1895f558f 100644 --- a/internal/provider/account_caps.go +++ b/internal/provider/account_caps.go @@ -94,6 +94,16 @@ func (c WindowCaps) Of(name string) (share int, credits bool) { return share, false } +// own is the share at which a window set aside holds the account (Limit's +// aside): only a cap the user set on that window itself, never the +// account's or the credits', 0 for none. +func (c WindowCaps) own(name string) int { + if v := c.Windows[WindowCapID(name)]; v >= MinCap && v <= MaxCap { + return v + } + return 0 +} + // Holds says whether any window can hold the account before the vendor // does. func (c WindowCaps) Holds() bool { @@ -303,6 +313,9 @@ func (a Allowance) CapHeld(model string, caps WindowCaps, now time.Time) *CapHol unknown, byCap := false, false for _, l := range a.capLimits(model) { share, credits := caps.Of(l.Name) + if l.aside { + share, credits = caps.own(l.Name), false + } if share <= 0 || l.Used < float64(share) { continue } @@ -344,6 +357,9 @@ func (a Allowance) NearCap(model string, caps WindowCaps, points float64, now ti model = strings.ToLower(model) for _, l := range a.capLimits(model) { share, _ := caps.Of(l.Name) + if l.aside { + share = caps.own(l.Name) + } if share <= 0 || l.Used < float64(share)-points { continue } @@ -387,6 +403,10 @@ func WithCapped(m map[string]SubscriptionQuota) map[string]SubscriptionQuota { pool := w.PoolWindow() && len(PoolMembers(q.Windows, w)) > 0 w.Capped = (!w.Aside || pool) && !w.Unlimited w.CapsSome = w.Capped && (w.Model != "" || w.matches != nil || pool) + // set aside, it still holds at a cap the user set on it + // before (allowanceOf), and at no other + w.OwnCap = w.Aside && !w.Unlimited && !w.Text && w.Model == "" && !pool + w.Capped = w.Capped || w.OwnCap if w.Capped { w.CapID = WindowCapID(w.Name) } diff --git a/internal/provider/account_caps_test.go b/internal/provider/account_caps_test.go index a27c891f0..91e9ed46a 100644 --- a/internal/provider/account_caps_test.go +++ b/internal/provider/account_caps_test.go @@ -94,8 +94,8 @@ func TestWithCappedMarksPerModelWindows(t *testing.T) { if w[0].CapsSome || !w[1].CapsSome { t.Error("the window one model's own is not told from the account's") } - if w[2].Capped { - t.Error("on-demand spending is marked") + if w[2].Capped && !w[2].OwnCap { + t.Error("on-demand spending is marked for the account's cap, not only a cap of its own") } if w[3].Capped { t.Error("an unlimited window is marked") @@ -395,3 +395,45 @@ func TestSetWindowCaps(t *testing.T) { t.Fatalf("cleared, still %+v", c) } } + +// A cap the user set on a window that a plugin later sets aside still +// holds the account (ferock on Discord): WorkBuddy 0.2.24 sets "Credits" +// aside and stops the account by "Total credits", plan and extra +// together. Only the window's own cap does: the account's never reaches a +// window set aside. +func TestAsideWindowKeepsItsOwnCap(t *testing.T) { + now := time.Now() + month := now.Add(25 * 24 * time.Hour) + ws := []QuotaWindow{ + {Name: "Credits", Used: 60, Amount: 300, Limit: 500, ResetsAt: &month, Aside: true}, + {Name: "Extra credits", Used: 0, Amount: 0, Limit: 1300, Aside: true}, + {Name: "Total credits", Used: 300.0 / 1800 * 100, Amount: 300, Limit: 1800, ResetsAt: &month}, + } + a := allowanceOf(ws, now) + if used, _ := a.For("glm-5.1", now); used > 17 { + t.Fatalf("routing went by a window set aside: %v", used) + } + plan := WindowCaps{Windows: map[string]int{"credits": 50}} + if h := a.CapHeld("glm-5.1", plan, now); h == nil || h.Used != 60 || h.Cap != 50 || !h.Back.Equal(month) || h.Credits { + t.Fatalf("the user's 50%% cap on Credits, at 60%%, no longer held: %+v", h) + } + if !a.NearCap("glm-5.1", WindowCaps{Windows: map[string]int{"credits": 70}}, 15, now) { + t.Fatal("Credits at 60% is not near its own 70% cap") + } + if h := a.CapHeld("glm-5.1", WindowCaps{Windows: map[string]int{"credits": 70}}, now); h != nil { + t.Fatalf("held under its own 70%%: %+v", h) + } + if h := a.CapHeld("glm-5.1", WindowCaps{All: 50}, now); h != nil { + t.Fatalf("the account's 50%% held by a window set aside: %+v", h) + } + if h := a.CapHeld("glm-5.1", WindowCaps{Credits: true}, now); h != nil { + t.Fatalf("a Codex credits hold reached a window set aside: %+v", h) + } + got := WithCapped(map[string]SubscriptionQuota{"me@example.com": {Windows: ws}})["me@example.com"].Windows + if w := got[0]; !w.Capped || !w.OwnCap || w.CapsSome || w.CapID != "credits" { + t.Fatalf("Credits, set aside: capped %v, own %v, some %v, id %q", w.Capped, w.OwnCap, w.CapsSome, w.CapID) + } + if w := got[2]; !w.Capped || w.OwnCap || w.CapID != "total credits" { + t.Fatalf("Total credits: capped %v, own %v, id %q", w.Capped, w.OwnCap, w.CapID) + } +} diff --git a/internal/provider/migrate_workbuddy.go b/internal/provider/migrate_workbuddy.go index 8206ab83b..09b18857b 100644 --- a/internal/provider/migrate_workbuddy.go +++ b/internal/provider/migrate_workbuddy.go @@ -16,7 +16,7 @@ func init() { for _, w := range []*wbSite{wbCN, wbAI} { movers[w.id] = &mover{ pkg: "@magpie-community/opencode-workbuddy-auth", - min: "0.2.23", // 0.2.23: DeepSeek Harness's name is taken out of the system prompt, text and tool descriptions before a chat goes to WorkBuddy, by a "Hide DeepSeek Harness's name" switch on by default, so its built-in identity lines are not sent (NancyTom18 on X, an account banned after use from dsh); 0.2.22: extra credits only the detail lists have keep the account going once the plan's base credits are spent: the plan's Credits window is set aside and Extra credits stops the account, as the summary's own split already did, so routing no longer moves off an account WorkBuddy still serves on its extra credits (ferock on Discord); 0.2.21: the sign-in page opens at the desktop app's version (5.9.3), as WorkBuddy desktop opens it, not 2.0.0, below the 5.8.0 under which the China login page hides 企业微信 (WeCom), so a WeCom user can sign in (shenyebuwu on Discord); 0.2.20: extra credits only the detail lists have also put their soonest lapse on the Credits window, which routing reads, so Smart spends first the China account whose extra-credit packs expire first, as it already did for the summary's packages (Kayphoon on Discord); 0.2.19: the China build's token window is no longer "Free model tokens", since there deepseek-v4.1-flash is charged x0.11 credits: its card is named after its model and says its cap is an estimate, "deepseek-v4.1-flash tokens (est.)", "151.5M / ~200M"; WorkBuddy AI's card is unchanged (kunghim, plugins #663; 0.2.18 was #657's OpenCode 2.x entry); 0.2.17: extra credits only the detail lists have (not the resource summary) are an "Extra credits" window beside the plan's, set aside, as WorkBuddy's own usage panel groups the paid and free lists, so a China free account no longer reads "0 / 500" alone (jiabubu on Discord); 0.2.16: "Extra credits" is every kind of credits but the plan's base, as WorkBuddy's own usage panel and the summary's CreditGroups say: the plan's bonus, top-ups (bought credit packs) and platform rewards, so a Pro account's bonus credits no longer hide in "Credits" (Jiabubu on Discord); 0.2.15: a chat whose max_tokens (or max_completion_tokens) is 1024 or less gets no default reasoning effort, so a short ask such as a session title is not spent on reasoning alone and answered empty, finish "length" (itspig, plugins #643, #644); 0.2.14: the free DeepSeek window's sum is an estimate, shown and set aside, not routed on: only WorkBuddy's own refusal makes it 100% (the gateway already rests that model on that account until the refusal's reset), so a paid account at 190M of its estimate is not stopped (XiaoFeiyu9, plugins #641); 0.2.13: a free model's daily window reads magpie's usage ledger in time linear in its rows, not their square, so a large ledger no longer holds the plugin host's one thread at 99% CPU for seconds on every card refresh and hangs every plugin's sessions (xmoon76 on Discord); 0.2.12: a WorkBuddy (China) account's card shows the free model's daily token window too, about 200M tokens a day, read from magpie's usage ledger apart from WorkBuddy AI's, and a refusal's "将在 … UTC+8 重置" is its reset (kunghim, plugins #625, #288); 0.2.11: the card shows the plan's own credits ("Credits", the packages WorkBuddy's client refreshes each cycle, with the plan's cycle, so its pace line means the month) apart from gifted, activity and bought ones ("Extra credits"), which only lapse; one of the two is set aside, so the account still stops only when both are spent (akic404 on Discord); 0.2.10: "Free models only" gives its label and description in Chinese, Traditional Chinese, Japanese and German, and says filtersModels, so the editor says under the models that the list is filtered while it is on (anewuser6937 on Discord, plugins #590); 0.2.9: a model declared before the account's list is read (an API key, or a /v3/config that failed) takes images, as both builds' config says of every model, so WorkBuddy AI's kimi-k3 no longer reads image: false (a real chat to it with a blue|yellow PNG answered "Blue yellow"); WorkBuddy AI's GLM models stay text-only (kongbai01203, plugins #572); 0.2.8: deepseek-v4.1-flash takes the config's 1000000 tokens on the China build (copilot.tencent.com) again, as China accounts took 110k-992k-token prompts on it; 0.2.7's 100000 cap made every client compact at 100k, and a prompt WorkBuddy finds too long is its own 400 "prompt is too long", which magpie takes as an overflow (plugins #561); 0.2.7: deepseek-v4.1-flash and -sg list a "none" level, which WorkBuddy takes (0 reasoning tokens) though its config says onlyReasoning (plugins #563); 0.2.6: an empty "tool_calls": [], which copilot.tencent.com puts on every delta, is no call, so the filter's refusal is held and taken out, not let through at the first delta (itspig, plugins #540); 0.2.5: the filter's line is taken out with the newline WorkBuddy sends on each side of it ("\nSorry, I can't respond to this question.\n"), which 0.2.4 let through as an answer (itspig, plugins #540); 0.2.4: a streamed chat that WorkBuddy's safety filter ends content_filter after its canned "Sorry, I can't respond to this question." has that line taken out, so the reply says nothing before the filter's stop and magpie hands it to the group's next member, not to the agent as an answer (itspig, plugins #540); 0.2.3: an opening WorkBuddy refuses (11128) that FLAGGED does not know is sent once more with one more comma before the system prompt is moved, only in system and assistant messages, and a system prompt whose comma passed goes with it from the next chat on; a refusal that stands names REFUSED.md, where its fix is written (MYCF711, plugins #513); 0.2.2: DeepSeek Harness's opener goes as "You are an AI agent, powered by DeepSeek Harness.", which passes WorkBuddy's whole-line check (11128) and keeps the harness's name, where 0.1.27's neutral line took it out (MYCF711, plugins #511); 0.2.1: a sign-in to an enterprise account (a team, or 「WorkBuddy 教育公益版」, picked on WorkBuddy's sign-in page) is named "nickname · enterprise", so it no longer replaces the same person's personal account, which shares its uid and nickname (jwaitq on Discord, plugins b9cbb9d); 0.2.0: a WorkBuddy (China) account claims its daily check-in credits through the billing meter, as WorkBuddy's client does, and an API-key account reports itself ineligible for check-in instead of failing and being tried again every 30 minutes (plugins #177); 0.1.48: WorkBuddy AI's card shows the free model's daily token window, read from magpie's usage ledger (plugins #299); 0.1.47: a conversation's X-Conversation-ID and X-Conversation-Request-ID are one account's own (they hash the account too), so a session spread over a group of accounts no longer sends the same ids under every X-User-Id, which WorkBuddy's client, signed in as one account, never does (plugins 1e7122e, leaves5760 on Discord: a group's accounts restricted, not verified as the cause); 0.1.46: WorkBuddy AI's chats carry its current desktop client's headers, WorkBuddy/5.9.3 workbuddy-ai/5.9.3 CLI/2.165.0 with X-IDE-Version 5.9.3 and X-Agent-Runtime local-agent, not 5.8.4's (plugins b08a6c1); 0.1.45: only a chat completion goes gzipped, so magpie's drawings (the Magpie Image MCP, /v1/images/*) reach WorkBuddy's images API as plain JSON again, not 400 11101 "invalid character '\x1f'" (iwinux on Discord, broken since 0.1.43); 0.1.44: a 45 MiB chat's conversation and turn ids are hashed from its pieces, not from fresh copies of the whole message, and "Free models only" and a model that wants a reply after tools read the one parse too, so the repro's peak goes 717-760 to 583 MiB with every byte sent unchanged (plugins #461); 0.1.43: a chat that names no effort goes at the model's own default from WorkBuddy's config (DeepSeek-V4.1-Flash: high), as WorkBuddy's client sends it, so OpenCode's default variant thinks (troilus1011 on X); a chat goes gzipped, as WorkBuddy's client sends it, so the upload is the size the official client's is (runmiNeverstop on X, 2.89 GB up); 0.1.42: a chat is parsed once on its way, not once a step, and goes as it came when nothing changed it, so a 45 MiB chat no longer holds seven parsed copies in the plugin host (plugins #461, #4004); 0.1.41: a package with no cycle total (a prepaid wallet) is a balance window, "Prepaid credits", beside the share of packages that have one (plugins #450, #3950); 0.1.40: a chat carries the headers of each build's current desktop app: its CLI's User-Agent (WorkBuddy/ / CLI/, was WorkBuddy/5.5.6), X-IDE-Version, X-Agent-Type on both builds, X-Agent-Runtime on the China build, and the OpenAI SDK's X-Stainless headers, read from WorkBuddy 5.9.3 and WorkBuddy AI 5.8.4 (accounts restricted, a header-fingerprint check reported on X); 0.1.39: an earlier turn's reasoning_content (or reasoning_details text) goes as `reasoning`, as WorkBuddy's own client sends it, since WorkBuddy drops reasoning_content and Grok Build's history lost its thinking (uk.jent on Discord); 0.1.38: a "Free models only" switch lists only the free models and refuses any other before it is sent, so no credits are spent (plugins #430); 0.1.37: sign in with a WorkBuddy API key from the profile/keys page, sent as WorkBuddy's own client sends it (plugins #407); 0.1.35: used credits say when the plan's cycle starts again, as WorkBuddy's client does, so the card no longer reads "Not used yet" beside them (windy on Discord); 0.1.34: a free account's plan reads "Free plan" (plugins #337); 0.1.33: an untyped object oneOf goes to Kimi as type "object" (plugins #378); 0.1.32: plugins #346; 0.1.31: a 401 is renewed once, whatever the token's time, and sent once more; when the retry is refused too, the 401 says to sign in again (Providers → WorkBuddy → this account), and the account is marked expired only on WorkBuddy's word that the sign-in is gone (refresh token refused, or invalid_token with nothing to renew with) (wenchen855443 on X); 0.1.30: a refused line the model quotes back into an assistant message is reworded there too, so a long DeepSeek Harness chat isn't refused for good (plugins #291); 0.1.29: a system prompt WorkBuddy refuses as an unapproved channel (11128) is sent once more as the first user message's instructions, with WorkBuddy's default system prompt, since WorkBuddy checks only system and assistant messages; the refusal still rests no account (Wing on Discord); 0.1.28: a refusal of words not reworded yet ends in a hint that names no one client (plugins #279); 0.1.27: DeepSeek Harness's opening identity line is reworded to a neutral one, which WorkBuddy otherwise refuses as an unapproved channel (11128) (plugins #279, #280); 0.1.26: a model that says only supportsReasoning and a default effort lists low, high, max and that default, not "doesn't reason" (plugins #255); 0.1.25: WorkBuddy AI's fast, balanced and primary models keep the credit rate its config gives as "x0.34 credits", not unknown (plugins #216); 0.1.24: a refused sign-in on a chat over 2 MiB says the 401 and to sign in again: WorkBuddy's front door resets such a request instead of answering, so it read as 502 ECONNRESET (wyp on Discord); 0.1.23: credits used up leave the free models counted out of the credits window, so an account is not ranked spent for them (plugins #138); 0.1.22: an MCP server's tool schemas reach Kimi and DeepSeek: an enum with no type, or of several types, is typed, and true or false where a schema goes is {} or {"not": {}}, so they aren't 400 11133 "Invalid request parameters" (plugins #122); 0.1.21: a model free only at night (Hy4 preview) is never said free, and a whole-day discount shows the price before it, from WorkBuddy's modelPromotions (plugins #121); 0.1.20: tool results followed by the user's message reach WorkBuddy AI's gemini-3.8-flash, not 400 "the conversation must end with a user message" (plugins #113); 0.1.19: an enterprise account's card shows its credits, from the enterprise meter WorkBuddy's usage page reads (#1904); 0.1.18: WorkBuddy 5.6+ keeps its desktop sign-in encrypted, and the plugin says so and points to the browser sign-in instead of a 502 (plugins #18); 0.1.17: a restricted account's 403 11140 ends in provider.WBRestrictedHint, so it rests 2h as restricted (#1849); 0.1.16: WorkBuddy AI's GLM models are text-only, so magpie's image-describing model reads their images (Yirasumi on Discord); 0.1.15: a system prompt sent as a developer message passes the channel check, an object tool_choice is sent as WorkBuddy takes it, and max_completion_tokens goes as max_tokens so the cap holds (plugins #96); 0.1.14: the Credits window says when the soonest credits left run out, for Smart routing to spend them first (cdredfox on X); an enterprise account names its enterprise, so it lists and uses the enterprise's models, not the personal plan's (plugins #75); a chat's tools get shapes WorkBuddy AI's models take, so ZCode's and DeepSeek Harness's chats on deepseek-v4.1-flash aren't 400 "Invalid request parameters" (wyh on Discord); one user send is one request in the usage list: every step carries one X-Conversation-Request-ID, and both builds name the client (使用端) (plugins #48); credits used up (code 14018) say so, with the nested error message (plugins #25); Codex's and Claude Code's chats pass WorkBuddy's channel check (#182); a failure's status and its sign-in mark as the built-in's; each model's credit rate; the sign-in renewed ahead of time through auth.refresh; the credits' count beside their share (#659) + min: "0.2.24", // 0.2.24: an account with both the plan's credits and extra ones is stopped by a "Total credits" window, the two together, with the plan's cycle and the soonest lapse, both of the two set aside, so the Routing page reads every account the same, its plan's credits spent or not, and an account at 90% of its plan is no longer kept for last with its extra credits untouched (ferock on Discord); 0.2.23: DeepSeek Harness's name is taken out of the system prompt, text and tool descriptions before a chat goes to WorkBuddy, by a "Hide DeepSeek Harness's name" switch on by default, so its built-in identity lines are not sent (NancyTom18 on X, an account banned after use from dsh); 0.2.22: extra credits only the detail lists have keep the account going once the plan's base credits are spent: the plan's Credits window is set aside and Extra credits stops the account, as the summary's own split already did, so routing no longer moves off an account WorkBuddy still serves on its extra credits (ferock on Discord); 0.2.21: the sign-in page opens at the desktop app's version (5.9.3), as WorkBuddy desktop opens it, not 2.0.0, below the 5.8.0 under which the China login page hides 企业微信 (WeCom), so a WeCom user can sign in (shenyebuwu on Discord); 0.2.20: extra credits only the detail lists have also put their soonest lapse on the Credits window, which routing reads, so Smart spends first the China account whose extra-credit packs expire first, as it already did for the summary's packages (Kayphoon on Discord); 0.2.19: the China build's token window is no longer "Free model tokens", since there deepseek-v4.1-flash is charged x0.11 credits: its card is named after its model and says its cap is an estimate, "deepseek-v4.1-flash tokens (est.)", "151.5M / ~200M"; WorkBuddy AI's card is unchanged (kunghim, plugins #663; 0.2.18 was #657's OpenCode 2.x entry); 0.2.17: extra credits only the detail lists have (not the resource summary) are an "Extra credits" window beside the plan's, set aside, as WorkBuddy's own usage panel groups the paid and free lists, so a China free account no longer reads "0 / 500" alone (jiabubu on Discord); 0.2.16: "Extra credits" is every kind of credits but the plan's base, as WorkBuddy's own usage panel and the summary's CreditGroups say: the plan's bonus, top-ups (bought credit packs) and platform rewards, so a Pro account's bonus credits no longer hide in "Credits" (Jiabubu on Discord); 0.2.15: a chat whose max_tokens (or max_completion_tokens) is 1024 or less gets no default reasoning effort, so a short ask such as a session title is not spent on reasoning alone and answered empty, finish "length" (itspig, plugins #643, #644); 0.2.14: the free DeepSeek window's sum is an estimate, shown and set aside, not routed on: only WorkBuddy's own refusal makes it 100% (the gateway already rests that model on that account until the refusal's reset), so a paid account at 190M of its estimate is not stopped (XiaoFeiyu9, plugins #641); 0.2.13: a free model's daily window reads magpie's usage ledger in time linear in its rows, not their square, so a large ledger no longer holds the plugin host's one thread at 99% CPU for seconds on every card refresh and hangs every plugin's sessions (xmoon76 on Discord); 0.2.12: a WorkBuddy (China) account's card shows the free model's daily token window too, about 200M tokens a day, read from magpie's usage ledger apart from WorkBuddy AI's, and a refusal's "将在 … UTC+8 重置" is its reset (kunghim, plugins #625, #288); 0.2.11: the card shows the plan's own credits ("Credits", the packages WorkBuddy's client refreshes each cycle, with the plan's cycle, so its pace line means the month) apart from gifted, activity and bought ones ("Extra credits"), which only lapse; one of the two is set aside, so the account still stops only when both are spent (akic404 on Discord); 0.2.10: "Free models only" gives its label and description in Chinese, Traditional Chinese, Japanese and German, and says filtersModels, so the editor says under the models that the list is filtered while it is on (anewuser6937 on Discord, plugins #590); 0.2.9: a model declared before the account's list is read (an API key, or a /v3/config that failed) takes images, as both builds' config says of every model, so WorkBuddy AI's kimi-k3 no longer reads image: false (a real chat to it with a blue|yellow PNG answered "Blue yellow"); WorkBuddy AI's GLM models stay text-only (kongbai01203, plugins #572); 0.2.8: deepseek-v4.1-flash takes the config's 1000000 tokens on the China build (copilot.tencent.com) again, as China accounts took 110k-992k-token prompts on it; 0.2.7's 100000 cap made every client compact at 100k, and a prompt WorkBuddy finds too long is its own 400 "prompt is too long", which magpie takes as an overflow (plugins #561); 0.2.7: deepseek-v4.1-flash and -sg list a "none" level, which WorkBuddy takes (0 reasoning tokens) though its config says onlyReasoning (plugins #563); 0.2.6: an empty "tool_calls": [], which copilot.tencent.com puts on every delta, is no call, so the filter's refusal is held and taken out, not let through at the first delta (itspig, plugins #540); 0.2.5: the filter's line is taken out with the newline WorkBuddy sends on each side of it ("\nSorry, I can't respond to this question.\n"), which 0.2.4 let through as an answer (itspig, plugins #540); 0.2.4: a streamed chat that WorkBuddy's safety filter ends content_filter after its canned "Sorry, I can't respond to this question." has that line taken out, so the reply says nothing before the filter's stop and magpie hands it to the group's next member, not to the agent as an answer (itspig, plugins #540); 0.2.3: an opening WorkBuddy refuses (11128) that FLAGGED does not know is sent once more with one more comma before the system prompt is moved, only in system and assistant messages, and a system prompt whose comma passed goes with it from the next chat on; a refusal that stands names REFUSED.md, where its fix is written (MYCF711, plugins #513); 0.2.2: DeepSeek Harness's opener goes as "You are an AI agent, powered by DeepSeek Harness.", which passes WorkBuddy's whole-line check (11128) and keeps the harness's name, where 0.1.27's neutral line took it out (MYCF711, plugins #511); 0.2.1: a sign-in to an enterprise account (a team, or 「WorkBuddy 教育公益版」, picked on WorkBuddy's sign-in page) is named "nickname · enterprise", so it no longer replaces the same person's personal account, which shares its uid and nickname (jwaitq on Discord, plugins b9cbb9d); 0.2.0: a WorkBuddy (China) account claims its daily check-in credits through the billing meter, as WorkBuddy's client does, and an API-key account reports itself ineligible for check-in instead of failing and being tried again every 30 minutes (plugins #177); 0.1.48: WorkBuddy AI's card shows the free model's daily token window, read from magpie's usage ledger (plugins #299); 0.1.47: a conversation's X-Conversation-ID and X-Conversation-Request-ID are one account's own (they hash the account too), so a session spread over a group of accounts no longer sends the same ids under every X-User-Id, which WorkBuddy's client, signed in as one account, never does (plugins 1e7122e, leaves5760 on Discord: a group's accounts restricted, not verified as the cause); 0.1.46: WorkBuddy AI's chats carry its current desktop client's headers, WorkBuddy/5.9.3 workbuddy-ai/5.9.3 CLI/2.165.0 with X-IDE-Version 5.9.3 and X-Agent-Runtime local-agent, not 5.8.4's (plugins b08a6c1); 0.1.45: only a chat completion goes gzipped, so magpie's drawings (the Magpie Image MCP, /v1/images/*) reach WorkBuddy's images API as plain JSON again, not 400 11101 "invalid character '\x1f'" (iwinux on Discord, broken since 0.1.43); 0.1.44: a 45 MiB chat's conversation and turn ids are hashed from its pieces, not from fresh copies of the whole message, and "Free models only" and a model that wants a reply after tools read the one parse too, so the repro's peak goes 717-760 to 583 MiB with every byte sent unchanged (plugins #461); 0.1.43: a chat that names no effort goes at the model's own default from WorkBuddy's config (DeepSeek-V4.1-Flash: high), as WorkBuddy's client sends it, so OpenCode's default variant thinks (troilus1011 on X); a chat goes gzipped, as WorkBuddy's client sends it, so the upload is the size the official client's is (runmiNeverstop on X, 2.89 GB up); 0.1.42: a chat is parsed once on its way, not once a step, and goes as it came when nothing changed it, so a 45 MiB chat no longer holds seven parsed copies in the plugin host (plugins #461, #4004); 0.1.41: a package with no cycle total (a prepaid wallet) is a balance window, "Prepaid credits", beside the share of packages that have one (plugins #450, #3950); 0.1.40: a chat carries the headers of each build's current desktop app: its CLI's User-Agent (WorkBuddy/ / CLI/, was WorkBuddy/5.5.6), X-IDE-Version, X-Agent-Type on both builds, X-Agent-Runtime on the China build, and the OpenAI SDK's X-Stainless headers, read from WorkBuddy 5.9.3 and WorkBuddy AI 5.8.4 (accounts restricted, a header-fingerprint check reported on X); 0.1.39: an earlier turn's reasoning_content (or reasoning_details text) goes as `reasoning`, as WorkBuddy's own client sends it, since WorkBuddy drops reasoning_content and Grok Build's history lost its thinking (uk.jent on Discord); 0.1.38: a "Free models only" switch lists only the free models and refuses any other before it is sent, so no credits are spent (plugins #430); 0.1.37: sign in with a WorkBuddy API key from the profile/keys page, sent as WorkBuddy's own client sends it (plugins #407); 0.1.35: used credits say when the plan's cycle starts again, as WorkBuddy's client does, so the card no longer reads "Not used yet" beside them (windy on Discord); 0.1.34: a free account's plan reads "Free plan" (plugins #337); 0.1.33: an untyped object oneOf goes to Kimi as type "object" (plugins #378); 0.1.32: plugins #346; 0.1.31: a 401 is renewed once, whatever the token's time, and sent once more; when the retry is refused too, the 401 says to sign in again (Providers → WorkBuddy → this account), and the account is marked expired only on WorkBuddy's word that the sign-in is gone (refresh token refused, or invalid_token with nothing to renew with) (wenchen855443 on X); 0.1.30: a refused line the model quotes back into an assistant message is reworded there too, so a long DeepSeek Harness chat isn't refused for good (plugins #291); 0.1.29: a system prompt WorkBuddy refuses as an unapproved channel (11128) is sent once more as the first user message's instructions, with WorkBuddy's default system prompt, since WorkBuddy checks only system and assistant messages; the refusal still rests no account (Wing on Discord); 0.1.28: a refusal of words not reworded yet ends in a hint that names no one client (plugins #279); 0.1.27: DeepSeek Harness's opening identity line is reworded to a neutral one, which WorkBuddy otherwise refuses as an unapproved channel (11128) (plugins #279, #280); 0.1.26: a model that says only supportsReasoning and a default effort lists low, high, max and that default, not "doesn't reason" (plugins #255); 0.1.25: WorkBuddy AI's fast, balanced and primary models keep the credit rate its config gives as "x0.34 credits", not unknown (plugins #216); 0.1.24: a refused sign-in on a chat over 2 MiB says the 401 and to sign in again: WorkBuddy's front door resets such a request instead of answering, so it read as 502 ECONNRESET (wyp on Discord); 0.1.23: credits used up leave the free models counted out of the credits window, so an account is not ranked spent for them (plugins #138); 0.1.22: an MCP server's tool schemas reach Kimi and DeepSeek: an enum with no type, or of several types, is typed, and true or false where a schema goes is {} or {"not": {}}, so they aren't 400 11133 "Invalid request parameters" (plugins #122); 0.1.21: a model free only at night (Hy4 preview) is never said free, and a whole-day discount shows the price before it, from WorkBuddy's modelPromotions (plugins #121); 0.1.20: tool results followed by the user's message reach WorkBuddy AI's gemini-3.8-flash, not 400 "the conversation must end with a user message" (plugins #113); 0.1.19: an enterprise account's card shows its credits, from the enterprise meter WorkBuddy's usage page reads (#1904); 0.1.18: WorkBuddy 5.6+ keeps its desktop sign-in encrypted, and the plugin says so and points to the browser sign-in instead of a 502 (plugins #18); 0.1.17: a restricted account's 403 11140 ends in provider.WBRestrictedHint, so it rests 2h as restricted (#1849); 0.1.16: WorkBuddy AI's GLM models are text-only, so magpie's image-describing model reads their images (Yirasumi on Discord); 0.1.15: a system prompt sent as a developer message passes the channel check, an object tool_choice is sent as WorkBuddy takes it, and max_completion_tokens goes as max_tokens so the cap holds (plugins #96); 0.1.14: the Credits window says when the soonest credits left run out, for Smart routing to spend them first (cdredfox on X); an enterprise account names its enterprise, so it lists and uses the enterprise's models, not the personal plan's (plugins #75); a chat's tools get shapes WorkBuddy AI's models take, so ZCode's and DeepSeek Harness's chats on deepseek-v4.1-flash aren't 400 "Invalid request parameters" (wyh on Discord); one user send is one request in the usage list: every step carries one X-Conversation-Request-ID, and both builds name the client (使用端) (plugins #48); credits used up (code 14018) say so, with the nested error message (plugins #25); Codex's and Claude Code's chats pass WorkBuddy's channel check (#182); a failure's status and its sign-in mark as the built-in's; each model's credit rate; the sign-in renewed ahead of time through auth.refresh; the credits' count beside their share (#659) agents: []string{w.id}, out: func() ([]Moving, error) { var out []Moving diff --git a/internal/provider/quota_span_test.go b/internal/provider/quota_span_test.go index d872dffc5..ea699ef21 100644 --- a/internal/provider/quota_span_test.go +++ b/internal/provider/quota_span_test.go @@ -61,6 +61,7 @@ func TestQuotaSpanCarriesEveryWindowField(t *testing.T) { "capped": "the GUI's cap marks (WithCapped)", "capsSome": "the GUI's cap marks (WithCapped)", "capId": "the GUI's cap marks (WithCapped)", + "ownCap": "the GUI's cap marks (WithCapped)", "startsAt": "the GUI's Pace number (WithWindowStarts)", "trayKind": "the GUI's menu bar picker (gui.withTrayKinds)", "trayExtra": "the GUI's menu bar picker (gui.withTrayKinds)", diff --git a/internal/provider/routing.go b/internal/provider/routing.go index 97441fd18..e9d139b6d 100644 --- a/internal/provider/routing.go +++ b/internal/provider/routing.go @@ -311,6 +311,11 @@ type Limit struct { // (Antigravity's "Gemini · 7 days"), which hold the account at its // caps only (capLimits): routing goes on by the model's own window pool []Limit + // aside is set on a window set aside for routing (QuotaWindow.Aside) + // that a cap the user set on it while it counted still holds the + // account at (WindowCaps.own); it rides in pool, never in the + // allowance itself + aside bool // ResetRunsOut is when the reset the account spends by itself before // it runs out does (resetRunsOut): spent then, it starts this window // again — at Restarts, which routing takes for the window's renewal @@ -1156,6 +1161,19 @@ func allowanceOf(ws []QuotaWindow, now time.Time) Allowance { } } } + // a window set aside since the user capped it (WorkBuddy's "Credits" + // once the plan's and the extra credits are counted together, ferock + // on Discord) holds at that cap still: the user's value outlives the + // plugin's change of which window stops the account + for _, w := range ws { + if !w.Aside || w.Text || w.Model != "" || w.PoolWindow() { + continue + } + al := Limit{Used: w.Used, Span: w.Span, Name: w.Name, Resets: resets(w), aside: true} + for i := range a { + a[i].pool = append(a[i].pool, al) + } + } return a } diff --git a/internal/provider/subscription_usage.go b/internal/provider/subscription_usage.go index 808f2c2ce..a6db1e42a 100644 --- a/internal/provider/subscription_usage.go +++ b/internal/provider/subscription_usage.go @@ -97,6 +97,10 @@ type QuotaWindow struct { // CapID is, beside Capped, how the window is known to a cap of its // own (WindowCapID), for the GUI to set and show one. CapID string `json:"capId,omitempty"` + // OwnCap is set beside Capped on a window set aside: only a cap the + // user set on it itself holds the account there (WindowCaps.own), + // never the account's, and the GUI offers none new. + OwnCap bool `json:"ownCap,omitempty"` // Holds is what the whole window holds, reckoned from magpie's own // calls through the account (usage.WithWindowHolds), for the GUI and, // through ReckonHolds, magpie quota --json and /v1/magpie/quotas