@magpie-community/opencode-qoder-auth 0.2.43 → 0.2.45
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.
- package/index.mjs +35 -2
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2128,7 +2128,20 @@ function when(v) {
|
|
|
2128
2128
|
return new Date(Math.trunc(n < 1e12 ? n * 1000 : n)).toISOString()
|
|
2129
2129
|
}
|
|
2130
2130
|
|
|
2131
|
-
//
|
|
2131
|
+
// SPENT_IN_TURN are the pools Qoder spends one after another before an
|
|
2132
|
+
// account stops: the plan's credits, the account's own add-on credits and,
|
|
2133
|
+
// on a team, the organisation's shared add-on credits (docs.qoder.com/Credits
|
|
2134
|
+
// and account/teams/shared-add-on-credits: the soonest to expire first, the
|
|
2135
|
+
// plan's before add-on on the same day). The envelope's own
|
|
2136
|
+
// totalUsagePercentage counts them as one too. So the account has left what
|
|
2137
|
+
// they have left together: a plan used up beside add-on credits is no
|
|
2138
|
+
// account used up (magpie-community/plugins#454).
|
|
2139
|
+
const SPENT_IN_TURN = new Set(["Credits", "Add-on credits", "Shared credits"])
|
|
2140
|
+
|
|
2141
|
+
// parseUsage is the plan and each pool of credits the envelope tells. When
|
|
2142
|
+
// more than one of the pools spent in turn holds credits, "Total credits"
|
|
2143
|
+
// is what they hold together, the one routing counts, and each pool is
|
|
2144
|
+
// shown beside it, set aside.
|
|
2132
2145
|
function parseUsage(env) {
|
|
2133
2146
|
if (env.displayMode === "enterprise") return { plan: "Enterprise" }
|
|
2134
2147
|
const u = env.qoderUsage
|
|
@@ -2148,13 +2161,33 @@ function parseUsage(env) {
|
|
|
2148
2161
|
if (total == null || total <= 0 || (b.used == null && b.remaining == null)) return
|
|
2149
2162
|
const used = b.used != null ? b.used : total - b.remaining
|
|
2150
2163
|
if (used < 0) return
|
|
2151
|
-
|
|
2164
|
+
const unit = b.unit || "credits"
|
|
2165
|
+
const w = { name: b.name || name, used: Math.min(100, (100 * used) / total), display: `${gfmt(used)} / ${gfmt(total)} ${unit}` }
|
|
2166
|
+
out.windows.push(w)
|
|
2167
|
+
if (SPENT_IN_TURN.has(name)) turn.push({ w, used: Math.min(used, total), total, unit })
|
|
2152
2168
|
}
|
|
2169
|
+
const turn = []
|
|
2153
2170
|
add(field("userQuota", "user_quota"), "Credits")
|
|
2154
2171
|
add(field("addOnQuota", "add_on_quota"), "Add-on credits")
|
|
2155
2172
|
add(field("orgResourcePackage", "org_resource_package"), "Shared credits")
|
|
2173
|
+
// one count only when every pool counts in the same unit
|
|
2174
|
+
if (turn.length > 1 && turn.every((p) => p.unit === turn[0].unit)) {
|
|
2175
|
+
const used = turn.reduce((a, p) => a + p.used, 0)
|
|
2176
|
+
const total = turn.reduce((a, p) => a + p.total, 0)
|
|
2177
|
+
for (const p of turn) p.w.aside = true
|
|
2178
|
+
out.windows.unshift({ name: "Total credits", used: Math.min(100, (100 * used) / total), display: `${gfmt(used)} / ${gfmt(total)} ${turn[0].unit}` })
|
|
2179
|
+
}
|
|
2156
2180
|
const dedicated = field("dedicatedResourcePackages", "dedicated_resource_packages")
|
|
2157
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
|
+
}
|
|
2158
2191
|
return out
|
|
2159
2192
|
}
|
|
2160
2193
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magpie-community/opencode-qoder-auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.45",
|
|
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",
|