@magpie-community/opencode-workbuddy-auth 0.1.40 → 0.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +20 -3
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1738,14 +1738,31 @@ const compact = (n) => (Number.isInteger(n) ? String(n) : n.toFixed(2).replace(/
1738
1738
  // as used or left beside the share (magpie#659). The free plan is said as a
1739
1739
  // plan: "Free" alone beside the account read as the model being free, and
1740
1740
  // routing as preferring it for that (#337).
1741
+ //
1742
+ // A package with no CycleTotalCapacity has no denominator: it is sent as
1743
+ // magpie's balance-shaped window (#3950), {balance, unit} with no used,
1744
+ // limit or aside, and routing ranks it by what is left. A literal "0" total
1745
+ // is still a total, not a wallet: it stays on the old path, so a lapsed or
1746
+ // placeholder package adds nothing. A literal "0" remainder is a reading
1747
+ // of nothing left, not an absent field; only a package with no
1748
+ // CycleRemainCapacity at all leaves the window out. TotalCredits is not a
1749
+ // fallback: an account with no packages at all keeps its unknown allowance,
1750
+ // as before, so its free models are not skipped.
1741
1751
  function usageOf(sum, plan) {
1742
1752
  const out = { plan: plan || (sum?.IsPaidUser ? "Pro" : "Free plan"), windows: [] }
1743
- let total = 0, used = 0
1753
+ let total = 0, used = 0, left = 0, bags = 0
1744
1754
  for (const p of sum?.Packages ?? []) {
1745
- total += capacity(p?.CycleTotalCapacity)
1746
- used += capacity(p?.CycleUsedCapacity)
1755
+ const hasTotal = p?.CycleTotalCapacity != null && p.CycleTotalCapacity !== ""
1756
+ if (hasTotal) {
1757
+ total += capacity(p.CycleTotalCapacity)
1758
+ used += capacity(p?.CycleUsedCapacity)
1759
+ } else if (p?.CycleRemainCapacity != null && p.CycleRemainCapacity !== "") {
1760
+ left += capacity(p.CycleRemainCapacity)
1761
+ bags++
1762
+ }
1747
1763
  }
1748
1764
  if (total > 0) out.windows.push({ name: "Credits", used: (100 * used) / total, display: `${compact(used)} / ${compact(total)}`, amount: used, limit: total, unit: "credits" })
1765
+ if (bags > 0 && (total === 0 || left > 0)) out.windows.push({ name: "Prepaid credits", balance: left, display: `${compact(left)} credits`, unit: "credits" })
1749
1766
  return out
1750
1767
  }
1751
1768
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-workbuddy-auth",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",