@magpie-community/opencode-qoder-auth 0.2.63 → 0.2.64
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/README.md +3 -1
- package/index.mjs +88 -11
- package/opencode2.mjs +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -189,6 +189,7 @@ itself.
|
|
|
189
189
|
|---|---|
|
|
190
190
|
| A refused sign-in (no code, or code 105) | 401 |
|
|
191
191
|
| A quota (codes 110, 112–119, 122) | 429 |
|
|
192
|
+
| A model the account's listing has off while its usage says no credits are left (since 0.2.64, #880) | 429 usage limit reached, with the credits used and the model; a model off with credits left, or whose usage can't be read, stays 400 `unknown or disabled model`, and an id Qoder never served is that 400 at once |
|
|
192
193
|
| Busy or queued for the model (code 10605) | Since 0.2.28 the request waits in Qoder's queue as Qoder's client does (below), then is sent again; since 0.2.62 a streamed request is answered 200 at once and kept alive with SSE comments for up to an hour, its outcome in the stream; past the wait, 503 with `Retry-After` from Qoder's `retryAfterSeconds` (30s when it gives none). Since 0.2.40, when magpie has another candidate after this request (`x-magpie-fallback: 1`), the 503 comes at once, saying the queue and how many are ahead, and magpie asks the next. The sign-in is untouched |
|
|
193
194
|
| A refusal of the request itself (codes 406, 416, 430, 80411, 80412, 100400–100403) | 400, with Qoder's words |
|
|
194
195
|
| "Error in upstream response", the model's own vendor behind Qoder failing, which Qoder sends as a 400 (since 0.2.24) | 502, so magpie asks again or another account; the sign-in is untouched |
|
|
@@ -484,7 +485,8 @@ the account's credentials.
|
|
|
484
485
|
(`Qoder.app` on macOS, `%LOCALAPPDATA%\Programs\Qoder` or, since
|
|
485
486
|
0.2.26, `%ProgramFiles%\Qoder` on Windows, `/opt/Qoder` on Linux) or the runtime the CLI caches in `~/.qoder/.bin`
|
|
486
487
|
(`runtime-info-<platform>-<arch>-*` on macOS and Linux,
|
|
487
|
-
`umid-win32-x64-*\runtime-info.exe`
|
|
488
|
+
`umid-win32-x64-*\runtime-info.exe` or, as qodercli 1.21.2 caches it
|
|
489
|
+
since 0.2.64, `runtime-info-win32-x64-*.exe` on Windows; `QODER_CONFIG_DIR`,
|
|
488
490
|
`QODER_CLI_HOME` and `QODER_CONFIG_DIR_NAME` move it as they move the
|
|
489
491
|
CLI's folder).
|
|
490
492
|
- For another installation location, set `QODER_RUNTIME_INFO` to the
|
package/index.mjs
CHANGED
|
@@ -2607,10 +2607,16 @@ async function campaignRuntime({ home = homedir(), platform = process.platform,
|
|
|
2607
2607
|
const cache = join(config, ".bin")
|
|
2608
2608
|
const entries = await readdir(cache, { withFileTypes: true }).catch(() => [])
|
|
2609
2609
|
const found = []
|
|
2610
|
+
// qodercli 1.1.66 cached it on Windows as a folder umid-win32-<arch>-<hash>
|
|
2611
|
+
// holding runtime-info.exe and sgsdk.dll; qodercli 1.21.2 caches the file
|
|
2612
|
+
// itself, runtime-info-win32-<arch>-<hash>.exe, beside sgsdk.dll in .bin,
|
|
2613
|
+
// as elsewhere (plugins#879). Either is taken, the newest first.
|
|
2610
2614
|
for (const d of entries) {
|
|
2611
2615
|
let path
|
|
2612
|
-
if (platform === "win32") {
|
|
2613
|
-
if (d.
|
|
2616
|
+
if (platform === "win32" && d.isDirectory()) {
|
|
2617
|
+
if (d.name.startsWith(`umid-win32-${arch}-`)) path = join(cache, d.name, name)
|
|
2618
|
+
} else if (platform === "win32") {
|
|
2619
|
+
if (d.isFile() && d.name.startsWith(`runtime-info-win32-${arch}-`) && d.name.toLowerCase().endsWith(".exe")) path = join(cache, d.name)
|
|
2614
2620
|
} else if (d.isFile() && d.name.startsWith(`runtime-info-${platform}-${arch}-`) && !d.name.endsWith(".tmp")) {
|
|
2615
2621
|
path = join(cache, d.name)
|
|
2616
2622
|
}
|
|
@@ -2811,6 +2817,31 @@ function when(v) {
|
|
|
2811
2817
|
// account used up (magpie-community/plugins#454).
|
|
2812
2818
|
const SPENT_IN_TURN = new Set(["Credits", "Add-on credits", "Shared credits"])
|
|
2813
2819
|
|
|
2820
|
+
// spentOf is the credits a usage envelope says the account has used of
|
|
2821
|
+
// what it has ("800 / 800 credits") when the pools spent in turn
|
|
2822
|
+
// (SPENT_IN_TURN) have none left together, and "" when they have some, or
|
|
2823
|
+
// when it says no pool at all. A free account's pools of 0 have none.
|
|
2824
|
+
function spentOf(env) {
|
|
2825
|
+
const u = env?.qoderUsage
|
|
2826
|
+
if (env?.displayMode !== "qoder" || !u || typeof u !== "object" || Array.isArray(u)) return ""
|
|
2827
|
+
let used = 0
|
|
2828
|
+
let total = 0
|
|
2829
|
+
let pools = 0
|
|
2830
|
+
for (const [a, b] of [["userQuota", "user_quota"], ["addOnQuota", "add_on_quota"], ["orgResourcePackage", "org_resource_package"]]) {
|
|
2831
|
+
const p = u[a] !== undefined ? u[a] : u[b]
|
|
2832
|
+
if (p === null || typeof p !== "object" || Array.isArray(p)) continue
|
|
2833
|
+
const t = p.total ?? p.cap
|
|
2834
|
+
if (typeof t !== "number" || !Number.isFinite(t) || t < 0) continue
|
|
2835
|
+
const n = typeof p.used === "number" ? p.used : typeof p.remaining === "number" ? t - p.remaining : NaN
|
|
2836
|
+
if (t > 0 && !Number.isFinite(n)) return ""
|
|
2837
|
+
pools++
|
|
2838
|
+
total += t
|
|
2839
|
+
used += t > 0 ? Math.min(Math.max(n, 0), t) : 0
|
|
2840
|
+
}
|
|
2841
|
+
if (!pools || used < total) return ""
|
|
2842
|
+
return `${gfmt(used)} / ${gfmt(total)} credits`
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2814
2845
|
// parseUsage is the plan and each pool of credits the envelope tells. When
|
|
2815
2846
|
// more than one of the pools spent in turn holds credits, "Total credits"
|
|
2816
2847
|
// is what they hold together, the one routing counts, and each pool is
|
|
@@ -3252,11 +3283,16 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3252
3283
|
if (!l || again) {
|
|
3253
3284
|
const s = siteOf(site, cred)
|
|
3254
3285
|
const listing = await fetchListing(s, cred)
|
|
3286
|
+
const off = new Set()
|
|
3255
3287
|
for (const m of s.modelScene ? (Array.isArray(listing?.[s.modelScene]) ? listing[s.modelScene] : []) : sceneModels(listing)) {
|
|
3256
3288
|
const k = String(m?.key ?? "").trim()
|
|
3257
3289
|
if (k) served.add(k)
|
|
3290
|
+
if (k && !m.enable) off.add(k)
|
|
3258
3291
|
}
|
|
3259
3292
|
l = modelInfos(listing, s)
|
|
3293
|
+
// the keys this listing names and has off (ask tells a model off for
|
|
3294
|
+
// the credits apart by them)
|
|
3295
|
+
l.off = off
|
|
3260
3296
|
if (!s.modelScene) l.freeView = freeView(sceneModels(listing))
|
|
3261
3297
|
listings.set(key, l)
|
|
3262
3298
|
}
|
|
@@ -3350,19 +3386,40 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3350
3386
|
const env = await fetchUsage(siteOf(site, cred), cred.access)
|
|
3351
3387
|
return { ...(await spareFree(cred, parseUsage(env))), signIn, ...who }
|
|
3352
3388
|
}
|
|
3353
|
-
|
|
3354
|
-
try {
|
|
3355
|
-
env = await fetchUsage(siteOf(site, cred), cred.deviceToken)
|
|
3356
|
-
} catch (e) {
|
|
3357
|
-
if (!(e instanceof UsageStatus) || (e.status !== 401 && e.status !== 403)) throw e
|
|
3358
|
-
env = await fetchUsage(siteOf(site, cred), await deviceToken(getAuth, cred.deviceToken))
|
|
3359
|
-
}
|
|
3360
|
-
return { ...(await spareFree(cred, parseUsage(env))), signIn, ...who }
|
|
3389
|
+
return { ...(await spareFree(cred, parseUsage(await usageEnv(getAuth, cred)))), signIn, ...who }
|
|
3361
3390
|
} catch (e) {
|
|
3362
3391
|
return { error: e?.message ?? String(e), signIn: e?.expired ? "expired" : signIn }
|
|
3363
3392
|
}
|
|
3364
3393
|
}
|
|
3365
3394
|
|
|
3395
|
+
// usageEnv is the account's usage envelope on its device token, rotated
|
|
3396
|
+
// once when refused, as usage reads it
|
|
3397
|
+
const usageEnv = async (getAuth, cred) => {
|
|
3398
|
+
try {
|
|
3399
|
+
return await fetchUsage(siteOf(site, cred), cred.deviceToken)
|
|
3400
|
+
} catch (e) {
|
|
3401
|
+
if (!(e instanceof UsageStatus) || (e.status !== 401 && e.status !== 403)) throw e
|
|
3402
|
+
return fetchUsage(siteOf(site, cred), await deviceToken(getAuth, cred.deviceToken))
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
|
|
3406
|
+
// creditsSpent is the credits the account has used of what it has
|
|
3407
|
+
// ("800 / 800 credits") when its usage says none are left (spentOf), and
|
|
3408
|
+
// "" when some are, or when it can't be read. Qoder and Qoder CN only:
|
|
3409
|
+
// QwenWork reads its usage elsewhere. A PAT account's is read on its job
|
|
3410
|
+
// token, as usage reads it.
|
|
3411
|
+
const creditsSpent = async (getAuth) => {
|
|
3412
|
+
if (site.usagePath) return ""
|
|
3413
|
+
try {
|
|
3414
|
+
const cred = await fresh(getAuth)
|
|
3415
|
+
if (cred.lingma) return ""
|
|
3416
|
+
if (cred.patAuth && !cred.deviceToken) return spentOf(await fetchUsage(siteOf(site, cred), cred.access))
|
|
3417
|
+
return spentOf(await usageEnv(getAuth, cred))
|
|
3418
|
+
} catch {
|
|
3419
|
+
return ""
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3366
3423
|
// campaign is a campaigns page (the daily check-in) asked as the account:
|
|
3367
3424
|
// a refused device token is rotated once, as usage does, and asked again
|
|
3368
3425
|
const campaign = async (getAuth, input, url, init) => {
|
|
@@ -3514,6 +3571,26 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3514
3571
|
// could be refused and renew it. An id Qoder has never served is said
|
|
3515
3572
|
// unknown at once, with no renewal spent on it.
|
|
3516
3573
|
if (!m && getAuth && knows(chat.model)) {
|
|
3574
|
+
// Off because the credits are used up (plugins#880): on an
|
|
3575
|
+
// international personal_professional_trial account Qoder's listing
|
|
3576
|
+
// had dfmodel off once the 800 credits were spent, and on again
|
|
3577
|
+
// when the daily credits came back. That is the account's quota,
|
|
3578
|
+
// not the request's fault, so it is said as Qoder's own quota codes
|
|
3579
|
+
// are (429 usage limit reached), which a routing group fails over
|
|
3580
|
+
// on and rests the account for. Only a model the live listing names
|
|
3581
|
+
// and has off, on an account whose usage read says no credits are
|
|
3582
|
+
// left; a usage that can't be read says nothing, and the model goes
|
|
3583
|
+
// on to the renewal and the 400 below as before.
|
|
3584
|
+
if ((await models(cred)).off?.has(chat.model)) {
|
|
3585
|
+
const spent = await creditsSpent(getAuth)
|
|
3586
|
+
if (spent) {
|
|
3587
|
+
return errorResponse({
|
|
3588
|
+
status: 429,
|
|
3589
|
+
message: `usage limit reached: the account's credits are used up (${spent}), and Qoder lists "${chat.model}" off for it until they refresh`,
|
|
3590
|
+
signIn: "",
|
|
3591
|
+
})
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3517
3594
|
relogged = true
|
|
3518
3595
|
const next = await relogin(getAuth, cred.access)
|
|
3519
3596
|
if (next) {
|
|
@@ -3999,4 +4076,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
3999
4076
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
4000
4077
|
|
|
4001
4078
|
// for tests
|
|
4002
|
-
export const _internal = { OUTPUT_CAPS, LEARNED_CAPS, outputCap, fetchListing, accountIdentity, deviceRefreshBody, qwenworkClientHeaders, freeView, maskPhone, phoneLabelOf, realEmailOf, chatHeaders, machineOS, machineHostname, cosyHeaders, typedUnions, Splitter, campaignRuntime, RUNTIMES, campaignPage, campaignTarget, vpcInstance, vpcSite, dedicatedOrigin, dedicatedHost, dedicatedSite, lingmaRoots, lingmaDecode, lingmaSite, lingmaHeaders, LINGMA_MODELS, parseUsage, gfmt, when, failure, modelInfo, qoderBody, qoderMessages, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState }
|
|
4079
|
+
export const _internal = { spentOf, OUTPUT_CAPS, LEARNED_CAPS, outputCap, fetchListing, accountIdentity, deviceRefreshBody, qwenworkClientHeaders, freeView, maskPhone, phoneLabelOf, realEmailOf, chatHeaders, machineOS, machineHostname, cosyHeaders, typedUnions, Splitter, campaignRuntime, RUNTIMES, campaignPage, campaignTarget, vpcInstance, vpcSite, dedicatedOrigin, dedicatedHost, dedicatedSite, lingmaRoots, lingmaDecode, lingmaSite, lingmaHeaders, LINGMA_MODELS, parseUsage, gfmt, when, failure, modelInfo, qoderBody, qoderMessages, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState }
|
package/opencode2.mjs
CHANGED
|
@@ -85,8 +85,10 @@ export function fieldsOf(prompts) {
|
|
|
85
85
|
if (p.placeholder) f.placeholder = String(p.placeholder)
|
|
86
86
|
if (p.type === "select" && Array.isArray(p.options))
|
|
87
87
|
f.options = p.options.map((o) => ({ value: String(o.value), label: String(o.label ?? o.value), ...(o.hint ? { description: String(o.hint) } : {}) }))
|
|
88
|
-
// a prompt shown only when another answer says so can't be required
|
|
89
|
-
|
|
88
|
+
// a prompt shown only when another answer says so can't be required, and
|
|
89
|
+
// neither can one whose own validate() accepts an empty answer (the
|
|
90
|
+
// browser sign-in's optional API key)
|
|
91
|
+
if (!p.condition && p.required !== false) f.required = true
|
|
90
92
|
out.push(f)
|
|
91
93
|
}
|
|
92
94
|
return out.length ? out : undefined
|
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.64",
|
|
4
4
|
"description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship, VPC and dedicated domains",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./opencode.mjs",
|