@magpie-community/opencode-qoder-auth 0.2.44 → 0.2.46

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 (3) hide show
  1. package/README.md +13 -0
  2. package/index.mjs +31 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -472,6 +472,19 @@ the plugin factory and its pieces, for another service on this same
472
472
  protocol (QwenWork ships here; a future one can too). Its shape is not a
473
473
  stable API — it changes as the packages on it need.
474
474
 
475
+ ## Free models when the credits run out
476
+
477
+ Qoder serves its free models after the credits are used up: "When Credits
478
+ run out, you can continue using free basic models, subject to daily and
479
+ monthly limits" ([docs.qoder.com/Credits](https://docs.qoder.com/Credits);
480
+ the zh page says the same). So the credit windows the usage hook gives
481
+ (Qoder and Qoder CN, since 0.2.46) name the account's free models in
482
+ `notModels`: a model listed at 0× (not a discount's 0 for a while), from the
483
+ account's own model list. magpie then doesn't count those models as spent
484
+ on a used-up account, or on a free account's "0 credits left". A list that
485
+ can't be read leaves every model counted. QwenWork reads its usage
486
+ elsewhere and is not changed.
487
+
475
488
  ## Not here
476
489
 
477
490
  - Qoder's usage and quota display.
package/index.mjs CHANGED
@@ -2179,6 +2179,15 @@ function parseUsage(env) {
2179
2179
  }
2180
2180
  const dedicated = field("dedicatedResourcePackages", "dedicated_resource_packages")
2181
2181
  for (const b of Array.isArray(dedicated) ? dedicated : []) add(b, "Dedicated credits")
2182
+ // A free account (personal_standard) with no add-on credits has a plan of
2183
+ // 0 and nothing else: Qoder's client shows that pool as 0/0 and counts the
2184
+ // account as out of credits. Without a window of its own magpie showed no
2185
+ // credits at all (Ariel on Discord), so it reads as none left.
2186
+ if (out.windows.length === 0) {
2187
+ const zero = (b) => b !== null && typeof b === "object" && !Array.isArray(b) && (b.total ?? b.cap) === 0
2188
+ const pools = [field("userQuota", "user_quota"), field("addOnQuota", "add_on_quota"), field("orgResourcePackage", "org_resource_package")]
2189
+ if (pools.some(zero)) out.windows.push({ name: "Credits", used: 100, display: "0 credits left" })
2190
+ }
2182
2191
  return out
2183
2192
  }
2184
2193
 
@@ -2506,6 +2515,26 @@ const makePlugin = (site) => async ({ client }) => {
2506
2515
  return dt.token
2507
2516
  })
2508
2517
 
2518
+ // spareFree has the credit windows not count the models that cost none
2519
+ // (notModels): Qoder's own docs say "When Credits run out, you can
2520
+ // continue using free basic models, subject to daily and monthly limits"
2521
+ // (docs.qoder.com/Credits; the zh page the same: "Credits 用尽后,仍可使用
2522
+ // 免费基础模型"). Counted, a plan used up (or a free account's "0 credits
2523
+ // left") put the account last for Qwen3.8-Flash and DeepSeek-Flash too,
2524
+ // which it still serves (coeo91 on Discord). Free is the listing's own
2525
+ // price (freeOf: 0×, not a discount's 0 for a while). A listing that can't
2526
+ // be read leaves every model counted, as before. Qoder and Qoder CN only:
2527
+ // QwenWork reads its usage elsewhere and says nothing of free models.
2528
+ const spareFree = async (cred, out) => {
2529
+ if (!out?.windows?.length) return out
2530
+ let free = []
2531
+ try {
2532
+ free = (await models(cred)).filter((m) => m.free).map((m) => m.key)
2533
+ } catch {}
2534
+ if (free.length) for (const w of out.windows) w.notModels = free
2535
+ return out
2536
+ }
2537
+
2509
2538
  // usage is the account's allowance, magpie's own hook. signIn is what the read means for the sign-in, as the built-in's did:
2510
2539
  // a refused job refresh marks it, a renewed one clears it, and nothing
2511
2540
  // else does — not a clean read, nor a refused device token, which serves
@@ -2553,7 +2582,7 @@ const makePlugin = (site) => async ({ client }) => {
2553
2582
  // no second token here to rotate and retry with.
2554
2583
  if (cred.patAuth && !cred.deviceToken) {
2555
2584
  const env = await fetchUsage(siteOf(site, cred), cred.access)
2556
- return { ...parseUsage(env), signIn }
2585
+ return { ...(await spareFree(cred, parseUsage(env))), signIn }
2557
2586
  }
2558
2587
  let env
2559
2588
  try {
@@ -2562,7 +2591,7 @@ const makePlugin = (site) => async ({ client }) => {
2562
2591
  if (!(e instanceof UsageStatus) || (e.status !== 401 && e.status !== 403)) throw e
2563
2592
  env = await fetchUsage(siteOf(site, cred), await deviceToken(getAuth, cred.deviceToken))
2564
2593
  }
2565
- return { ...parseUsage(env), signIn }
2594
+ return { ...(await spareFree(cred, parseUsage(env))), signIn }
2566
2595
  } catch (e) {
2567
2596
  return { error: e?.message ?? String(e), signIn: e?.expired ? "expired" : signIn }
2568
2597
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.44",
3
+ "version": "0.2.46",
4
4
  "description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship (VPC)",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",