@magpie-community/opencode-qoder-auth 0.2.39 → 0.2.40
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 +9 -1
- package/index.mjs +12 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -158,7 +158,7 @@ itself.
|
|
|
158
158
|
|---|---|
|
|
159
159
|
| A refused sign-in (no code, or code 105) | 401 |
|
|
160
160
|
| A quota (codes 110, 112–119, 122) | 429 |
|
|
161
|
-
| 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; past the wait, 503 with `Retry-After` from Qoder's `retryAfterSeconds` (30s when it gives none). The sign-in is untouched |
|
|
161
|
+
| 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; 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 |
|
|
162
162
|
| A refusal of the request itself (codes 406, 416, 430, 80411, 80412, 100400–100403) | 400, with Qoder's words |
|
|
163
163
|
| "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 |
|
|
164
164
|
| A failure before the answer starts | Qoder's status |
|
|
@@ -427,6 +427,14 @@ cancelled request end the wait early. Qoder's client also reports the end
|
|
|
427
427
|
of its turn to `/api/v2/service/ask/finish`; the plugin doesn't, and
|
|
428
428
|
Qoder releases that lease on its own TTL. `queue.test.mjs` has the wait.
|
|
429
429
|
|
|
430
|
+
Since **0.2.40** the wait is only for the last candidate: when magpie says
|
|
431
|
+
another account, provider or routing group member follows this request
|
|
432
|
+
(its `x-magpie-fallback: 1` header, which the plugin host keeps from Qoder),
|
|
433
|
+
a queued request is answered at once with the 503 above, e.g. "Qoder queued
|
|
434
|
+
the request for dfmodel (this plan's queue: p3, 3 ahead); try again in
|
|
435
|
+
30s", and magpie asks the next instead of keeping the agent in Qoder's
|
|
436
|
+
queue.
|
|
437
|
+
|
|
430
438
|
For a bounded offline reproduction, run `packages/qoder/busy.test.mjs`
|
|
431
439
|
from #185 in an isolated temporary HOME. It compares plain queue JSON,
|
|
432
440
|
BOM-prefixed JSON and known message wrappers, keeping explicit login and
|
package/index.mjs
CHANGED
|
@@ -897,6 +897,10 @@ function sessionOf(chat, named = "") {
|
|
|
897
897
|
// conversation by, from the chat.headers hook to the loader's fetch. It
|
|
898
898
|
// goes no further: nothing of the request's headers is sent to Qoder.
|
|
899
899
|
const SESSION = "x-magpie-qoder-session"
|
|
900
|
+
// FALLBACK is "1" when magpie has another candidate after this request
|
|
901
|
+
// (another account, provider or routing group member): a queued request is
|
|
902
|
+
// then answered at once rather than waited out
|
|
903
|
+
const FALLBACK = "x-magpie-fallback"
|
|
900
904
|
|
|
901
905
|
// namedSession is the session a chat.headers hook is told, "" when it
|
|
902
906
|
// names none. magpie, with no session header from the agent, makes one of
|
|
@@ -1090,7 +1094,8 @@ function failure(status, text) {
|
|
|
1090
1094
|
const n = Number(queue?.retryAfterSeconds)
|
|
1091
1095
|
const wait = Number.isFinite(n) && n > 0 ? Math.ceil(n) : BUSY_WAIT
|
|
1092
1096
|
const model = queue?.modelKey ? ` for ${queue.modelKey}` : ""
|
|
1093
|
-
const
|
|
1097
|
+
const ahead = Number(queue?.queueCount) > 0 ? `, ${Math.floor(Number(queue.queueCount))} ahead` : ""
|
|
1098
|
+
const tier = queue?.queueType ? ` (this plan's queue: ${queue.queueType}${ahead})` : ahead ? ` (${ahead.slice(2)})` : ""
|
|
1094
1099
|
const what = queue?.isQueued === true ? "queued the request" : "is busy"
|
|
1095
1100
|
return { status: 503, message: `Qoder ${what}${model}${tier}; try again in ${wait}s`, retryAfter: wait, signIn: "", queue: queue ?? {} }
|
|
1096
1101
|
}
|
|
@@ -2547,7 +2552,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
2547
2552
|
})
|
|
2548
2553
|
|
|
2549
2554
|
// ask is the answer to a chat completion on the live account cred.
|
|
2550
|
-
const ask = async (chat, cred, init, named = "") => {
|
|
2555
|
+
const ask = async (chat, cred, init, named = "", fallback = false) => {
|
|
2551
2556
|
let m
|
|
2552
2557
|
try {
|
|
2553
2558
|
m = (await models(cred)).find((x) => x.key === chat.model) ?? (await models(cred, true)).find((x) => x.key === chat.model)
|
|
@@ -2599,7 +2604,10 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
2599
2604
|
if (f) call.abort()
|
|
2600
2605
|
// an answered call moves its task on, as Qoder's client moves it
|
|
2601
2606
|
if (!f) task.answered = true
|
|
2602
|
-
|
|
2607
|
+
// with another account, provider or group member after this one
|
|
2608
|
+
// (magpie's X-Magpie-Fallback), a queued request isn't waited out:
|
|
2609
|
+
// its 503 goes back at once, saying the queue, and the next is asked
|
|
2610
|
+
if (!f?.queue || waited >= QUEUE.recoveries || fallback) return f ? errorResponse(f) : answer(open, chat, servedName)
|
|
2603
2611
|
try {
|
|
2604
2612
|
if (!(await queueWait(api, cred, ask, f.queue, init.signal, deadline, siteOf(site, cred)))) return errorResponse(f)
|
|
2605
2613
|
} catch (e) {
|
|
@@ -2673,7 +2681,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
2673
2681
|
}
|
|
2674
2682
|
const h = new Headers(input instanceof Request ? input.headers : undefined)
|
|
2675
2683
|
new Headers(init.headers ?? {}).forEach((v, k) => h.set(k, v))
|
|
2676
|
-
return signed(await ask(chat, cred, init, h.get(SESSION)?.trim().slice(0, 128) ?? ""), renewed(cred))
|
|
2684
|
+
return signed(await ask(chat, cred, init, h.get(SESSION)?.trim().slice(0, 128) ?? "", h.get(FALLBACK) === "1"), renewed(cred))
|
|
2677
2685
|
},
|
|
2678
2686
|
}
|
|
2679
2687
|
},
|
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.40",
|
|
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",
|