@magpie-community/opencode-workbuddy-auth 0.1.22 → 0.1.23

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 -1
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1209,6 +1209,24 @@ function enterpriseUsageOf(u) {
1209
1209
  return w
1210
1210
  }
1211
1211
 
1212
+ // spareFree has the credits windows not count the models that cost none
1213
+ // (notModels): a model at x0.00 draws no credits, and with the credits
1214
+ // used up WorkBuddy still serves it (deepseek-v4.1-flash at 560 / 560,
1215
+ // magpie-community/plugins#138, hheei). Counted, the window at 100% put
1216
+ // the account last, and behind every other, for its free models too. A
1217
+ // model free only some hours (a night promotion) is not free here, as in
1218
+ // the list (priceOf). A list that can't be read leaves the windows as they
1219
+ // are: every model counted, as before.
1220
+ async function spareFree(site, a, windows) {
1221
+ if (!windows.length) return windows
1222
+ let free = []
1223
+ try {
1224
+ free = (await liveModels(site, a)).filter((m) => m.free).map((m) => m.id)
1225
+ } catch {}
1226
+ if (free.length) for (const w of windows) w.notModels = free
1227
+ return windows
1228
+ }
1229
+
1212
1230
  // The packages' codes, as WorkBuddy's own client lists them when it asks
1213
1231
  // for each package's credits (its COMMODITY_CODES): the API refuses a
1214
1232
  // detail list without them (10001 "PackageCodes required").
@@ -1577,7 +1595,7 @@ function makePlugin(site) {
1577
1595
  try {
1578
1596
  ent = enterpriseUsageOf(await meter(site, a, "/billing/meter/get-enterprise-user-usage"))
1579
1597
  } catch {}
1580
- if (ent) return { plan: auth.plan || "Enterprise", windows: [ent], signIn: "kept" }
1598
+ if (ent) return { plan: auth.plan || "Enterprise", windows: await spareFree(site, a, [ent]), signIn: "kept" }
1581
1599
  }
1582
1600
  // when the credits left run out, for routing to spend them first;
1583
1601
  // a list that can't be read leaves it unknown, the card stands
@@ -1587,6 +1605,7 @@ function makePlugin(site) {
1587
1605
  Object.assign(credits, runsOutOf(sum, await packagesOf(site, a)) ?? {})
1588
1606
  } catch {}
1589
1607
  }
1608
+ await spareFree(site, a, out.windows)
1590
1609
  return { ...out, signIn: "kept" }
1591
1610
  } catch (e) {
1592
1611
  return { error: e?.message ?? String(e), signIn: "kept" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-workbuddy-auth",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
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",