@magpie-community/opencode-workbuddy-auth 0.1.34 → 0.1.35

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 +25 -3
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1719,6 +1719,26 @@ function runsOutOf(sum, packages, now = Date.now()) {
1719
1719
  return at ? { runsOutAt: new Date(at).toISOString(), runsOut: amount } : null
1720
1720
  }
1721
1721
 
1722
+ // cycleOf is when the plan's credits start again, as WorkBuddy's own client
1723
+ // says it (getCurrentPlan's refreshAt): the cycle end of the package the
1724
+ // summary names as the subscription (SubscriptionPackageCode), in UTC+8,
1725
+ // with how long the cycle is. Without it the card had used credits and no
1726
+ // reset, and magpie said "Not used yet" beside 46% (windy on Discord,
1727
+ // 2026-10-26). null when the subscription isn't in the lists, or its cycle
1728
+ // is over.
1729
+ function cycleOf(sum, packages, now = Date.now()) {
1730
+ const code = sum?.SubscriptionPackageCode
1731
+ if (!code) return null
1732
+ const at = (v) => (typeof v === "string" && /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(v.trim()) ? Date.parse(v.trim().replace(" ", "T") + "+08:00") : 0)
1733
+ for (const p of packages ?? []) {
1734
+ if (p?.PackageCode !== code) continue
1735
+ const end = at(p?.CycleEndTime), start = at(p?.CycleStartTime)
1736
+ if (!(end > now)) continue
1737
+ return { resetsAt: new Date(end).toISOString(), ...(start > 0 && start < end ? { span: (end - start) / 1000 } : {}) }
1738
+ }
1739
+ return null
1740
+ }
1741
+
1722
1742
  // ---- models -----------------------------------------------------------------
1723
1743
 
1724
1744
  // variants are the reasoning levels as OpenCode gives them to the AI SDK.
@@ -2159,12 +2179,14 @@ function makePlugin(site) {
2159
2179
  } catch {}
2160
2180
  if (ent) return { plan: auth.plan || "Enterprise", windows: await spareFree(site, a, [ent]), signIn: said }
2161
2181
  }
2162
- // when the credits left run out, for routing to spend them first;
2182
+ // when the plan's credits start again (cycleOf), and when the credits
2183
+ // left run out, for routing to spend them first (runsOutOf);
2163
2184
  // a list that can't be read leaves it unknown, the card stands
2164
2185
  const credits = out.windows.find((w) => w.name === "Credits")
2165
2186
  if (credits) {
2166
2187
  try {
2167
- Object.assign(credits, runsOutOf(sum, await packagesOf(site, a)) ?? {})
2188
+ const packages = await packagesOf(site, a)
2189
+ Object.assign(credits, cycleOf(sum, packages) ?? {}, runsOutOf(sum, packages) ?? {})
2168
2190
  } catch {}
2169
2191
  }
2170
2192
  await spareFree(site, a, out.windows)
@@ -2291,4 +2313,4 @@ export const WorkBuddyAuthPlugin = makePlugin(SITES.workbuddy)
2291
2313
  export const WorkBuddyAIAuthPlugin = makePlugin(SITES["workbuddy-ai"])
2292
2314
 
2293
2315
  // for tests
2294
- export const _internal = { typeUnions, systemAsUser, systemKey, DEFAULT_SYSTEM, EDGE_READS, fitShape, replyAfterTools, AFTER_TOOLS_REFUSED, enterpriseUsageOf, notDesktop, textOnly, runsOutOf, packagesOf, endOf, enterpriseHeaders, enterpriseOf, liveModels, browserSignIn, withSystem, normalizeToolChoice, fitTools, fitted, renamed, unflagged, usageOf, desktopHeld, explained, REFUSED_HINT, RESTRICTED_HINT, EXHAUSTED_HINT, freeCredits, creditsOf, priceOf, fresh, SITES, renewing, renewed, SESSION, attend, turnKey, conversationKey, signatureOf, isMessages, withoutUnsigned, withoutSignedThinking, answeredBefore, nativeOf, modelOf, configModels, API_MESSAGES: NPM_MESSAGES, API_CHAT: NPM }
2316
+ export const _internal = { cycleOf, typeUnions, systemAsUser, systemKey, DEFAULT_SYSTEM, EDGE_READS, fitShape, replyAfterTools, AFTER_TOOLS_REFUSED, enterpriseUsageOf, notDesktop, textOnly, runsOutOf, packagesOf, endOf, enterpriseHeaders, enterpriseOf, liveModels, browserSignIn, withSystem, normalizeToolChoice, fitTools, fitted, renamed, unflagged, usageOf, desktopHeld, explained, REFUSED_HINT, RESTRICTED_HINT, EXHAUSTED_HINT, freeCredits, creditsOf, priceOf, fresh, SITES, renewing, renewed, SESSION, attend, turnKey, conversationKey, signatureOf, isMessages, withoutUnsigned, withoutSignedThinking, answeredBefore, nativeOf, modelOf, configModels, API_MESSAGES: NPM_MESSAGES, API_CHAT: NPM }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-workbuddy-auth",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
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",