@magpie-community/opencode-qoder-auth 0.2.69 → 0.2.71
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 +8 -2
- package/index.mjs +50 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -193,7 +193,7 @@ itself.
|
|
|
193
193
|
| A refused sign-in (no code, or code 105) | 401 |
|
|
194
194
|
| A quota (codes 110, 112–119, 122) | 429 |
|
|
195
195
|
| 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 |
|
|
196
|
-
| 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 |
|
|
196
|
+
| 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 (since 0.2.71, 5 minutes when the queue hasn't moved with nothing ahead), 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 |
|
|
197
197
|
| A refusal of the request itself (codes 406, 416, 430, 80411, 80412, 100400–100403) | 400, with Qoder's words |
|
|
198
198
|
| "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 |
|
|
199
199
|
| "Range of max_tokens should be [1, N]" behind "Error in upstream response" (since 0.2.63) | Asked again once with max_tokens N, which later requests for that model are sent from the start; refused again, 400 with Qoder's words, the sign-in untouched. QoDuck (`lmodel`) is never sent more than 131072, and a model whose listing entry names `max_output_tokens` never more than that; a smaller max_tokens goes as asked |
|
|
@@ -596,7 +596,13 @@ SSE comment saying the queue (": Qoder queued the request for smodel
|
|
|
596
596
|
on: a Codex client is told `response.in_progress`, the event its 300s idle
|
|
597
597
|
timeout counts, and a Chat client gets the comment. What comes of the wait
|
|
598
598
|
goes on in the same stream: the answer, or a refusal (the queue's own after
|
|
599
|
-
the hour) as the stream's error.
|
|
599
|
+
the hour) as the stream's error. Since **0.2.71** a wait with nothing ahead of
|
|
600
|
+
the request (`queueCount` 1 or none) whose queue state comes back the same
|
|
601
|
+
at every ask for 5 minutes ends there, with the queue's 503 and "the queue
|
|
602
|
+
hasn't moved in 5 minutes with nothing ahead" (plugins#1220: Qoder CN held
|
|
603
|
+
such a RESOURCE_LIMIT queue unchanged, and the agent heard only
|
|
604
|
+
keepalives); magpie can then rest the account or ask the next. A queue with
|
|
605
|
+
others ahead is still waited out. Nothing needs setting. A request that isn't
|
|
600
606
|
streamed has nothing to keep its client alive with, so it still waits 4
|
|
601
607
|
minutes at most before the 503. Claude Code takes a ping as life only 30
|
|
602
608
|
times in a row, about 35 minutes, so a longer wait still ends there. Qoder's client also reports the end
|
package/index.mjs
CHANGED
|
@@ -1729,6 +1729,21 @@ const QUEUE = {
|
|
|
1729
1729
|
recoveries: 10, // the queue waited out this many times, at most, for one request
|
|
1730
1730
|
failures: 3, // status asks failing in a row that end the wait
|
|
1731
1731
|
ask: 30_000, // the longest one status ask may take
|
|
1732
|
+
// the longest a call waits for Qoder's first event (headers included).
|
|
1733
|
+
// Qoder CN once held a call 15 minutes with nothing sent and nothing to
|
|
1734
|
+
// log (#1204); after this it is a 504 that says so, which magpie can
|
|
1735
|
+
// fail over from. A queued call answers its 10605 at once, and a
|
|
1736
|
+
// thinking model streams its reasoning, so a real answer starts sooner.
|
|
1737
|
+
silent: 120_000,
|
|
1738
|
+
// the longest a wait goes on with nothing ahead of the request
|
|
1739
|
+
// (queueCount 1 or none) and the queue's state the same at every ask.
|
|
1740
|
+
// Qoder CN once held such a RESOURCE_LIMIT queue unchanged, 1 in p4,
|
|
1741
|
+
// for every request from one hour on (plugins#1220): the hour's hold
|
|
1742
|
+
// then left the agent with keepalives only. After this it is the
|
|
1743
|
+
// queue's 503 with Retry-After, which magpie can rest the account on
|
|
1744
|
+
// or fail over from. A queue with others ahead is waited out as
|
|
1745
|
+
// Qoder's client waits it (#807).
|
|
1746
|
+
stuck: 5 * 60 * 1000,
|
|
1732
1747
|
now: () => Date.now(),
|
|
1733
1748
|
// every calls fn each ms until the returned stop is called
|
|
1734
1749
|
every: (fn, ms) => {
|
|
@@ -1782,7 +1797,7 @@ function queueState(text) {
|
|
|
1782
1797
|
if (isQueued !== undefined || serviceAvailable !== undefined) {
|
|
1783
1798
|
const num = (v) => (v == null || v === "" || !Number.isFinite(Number(v)) ? undefined : Number(v))
|
|
1784
1799
|
const str = (v) => (typeof v === "string" && v ? v : undefined)
|
|
1785
|
-
return { isQueued, serviceAvailable, modelKey: str(o.modelKey), queueType: str(o.queueType), retryAfterSeconds: num(o.retryAfterSeconds) }
|
|
1800
|
+
return { isQueued, serviceAvailable, modelKey: str(o.modelKey), queueType: str(o.queueType), retryAfterSeconds: num(o.retryAfterSeconds), queueCount: num(o.queueCount), subCode: str(o.subCode) }
|
|
1786
1801
|
}
|
|
1787
1802
|
for (const k of ["data", "result", "message", "body"]) {
|
|
1788
1803
|
const v = o[k]
|
|
@@ -1814,13 +1829,25 @@ async function queueStatus(api, cred, { requestSetId, modelKey, queueType, reque
|
|
|
1814
1829
|
return st
|
|
1815
1830
|
}
|
|
1816
1831
|
|
|
1832
|
+
// stuckKey is what a queue's state says of the request's place in it, or
|
|
1833
|
+
// "" when others are ahead of it (a queue that moves while they are
|
|
1834
|
+
// served is waited out, QUEUE.stuck never ends it).
|
|
1835
|
+
function stuckKey(st) {
|
|
1836
|
+
const n = Number(st?.queueCount)
|
|
1837
|
+
if (Number.isFinite(n) && n > 1) return ""
|
|
1838
|
+
return JSON.stringify([st?.isQueued, st?.serviceAvailable, Number.isFinite(n) ? n : null, st?.queueType ?? null, st?.subCode ?? null, st?.retryAfterSeconds ?? null])
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1817
1841
|
// queueWait waits in Qoder's queue for the request, from the state its
|
|
1818
1842
|
// refusal gave, until the queue lets it through (true) or the wait ends
|
|
1819
|
-
// (false). A cancelled request
|
|
1843
|
+
// (false). A wait ended by QUEUE.stuck sets ask.stuck. A cancelled request
|
|
1844
|
+
// throws.
|
|
1820
1845
|
async function queueWait(api, cred, ask, first, signal, deadline, site) {
|
|
1821
1846
|
let q = first ?? {}
|
|
1822
1847
|
let asked = false
|
|
1823
1848
|
let failed = 0
|
|
1849
|
+
let same = stuckKey(q)
|
|
1850
|
+
let since = QUEUE.now()
|
|
1824
1851
|
for (;;) {
|
|
1825
1852
|
if (signal?.aborted) throw signal.reason ?? new DOMException("aborted", "AbortError")
|
|
1826
1853
|
if (QUEUE.now() >= deadline) return false
|
|
@@ -1839,6 +1866,14 @@ async function queueWait(api, cred, ask, first, signal, deadline, site) {
|
|
|
1839
1866
|
}
|
|
1840
1867
|
failed = 0
|
|
1841
1868
|
q = { ...st, modelKey: st.modelKey ?? q.modelKey, queueType: st.queueType ?? q.queueType }
|
|
1869
|
+
const key = stuckKey(q)
|
|
1870
|
+
if (!key || key !== same) {
|
|
1871
|
+
same = key
|
|
1872
|
+
since = QUEUE.now()
|
|
1873
|
+
} else if (QUEUE.now() - since >= QUEUE.stuck && st.isQueued !== false) {
|
|
1874
|
+
ask.stuck = true
|
|
1875
|
+
return false
|
|
1876
|
+
}
|
|
1842
1877
|
if (st.isQueued === false) {
|
|
1843
1878
|
if (st.retryAfterSeconds > 0) await QUEUE.pause(Math.min(queuePause(st.retryAfterSeconds), Math.max(0, deadline - QUEUE.now())), signal)
|
|
1844
1879
|
return QUEUE.now() < deadline
|
|
@@ -3792,11 +3827,22 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3792
3827
|
const call = new AbortController()
|
|
3793
3828
|
const callSignal = signal ? AbortSignal.any([signal, call.signal]) : call.signal
|
|
3794
3829
|
let res, open
|
|
3830
|
+
let silent = false
|
|
3831
|
+
const hush = setTimeout(() => {
|
|
3832
|
+
silent = true
|
|
3833
|
+
call.abort()
|
|
3834
|
+
}, QUEUE.silent)
|
|
3795
3835
|
try {
|
|
3796
3836
|
res = await fetch(CHAT_URL, { method: "POST", headers, body: wire, signal: callSignal })
|
|
3797
3837
|
if (res.ok) open = await opened(res, chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function") : [])
|
|
3798
3838
|
} catch (e) {
|
|
3839
|
+
if (silent) {
|
|
3840
|
+
const who = siteOf(site, cred).name ?? "Qoder"
|
|
3841
|
+
return errorResponse({ status: 504, message: `${who} sent nothing for ${Math.round(QUEUE.silent / 1000)}s after the request (${res ? "no first event" : "no reply headers"}); the call was dropped`, signIn: "" })
|
|
3842
|
+
}
|
|
3799
3843
|
return errorResponse({ status: 502, message: e.message })
|
|
3844
|
+
} finally {
|
|
3845
|
+
clearTimeout(hush)
|
|
3800
3846
|
}
|
|
3801
3847
|
const f = !res.ok ? failure(res.status, (await res.text()).slice(0, 1 << 20)) : open.first.value?.error
|
|
3802
3848
|
if (f) call.abort()
|
|
@@ -3841,7 +3887,8 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3841
3887
|
onHeld(held.response)
|
|
3842
3888
|
}
|
|
3843
3889
|
try {
|
|
3844
|
-
if (!(await queueWait(api, cred, ask, f.queue, signal, deadline, siteOf(site, cred))))
|
|
3890
|
+
if (!(await queueWait(api, cred, ask, f.queue, signal, deadline, siteOf(site, cred))))
|
|
3891
|
+
return errorResponse(ask.stuck ? { ...f, message: `${f.message} (the queue hasn't moved in ${Math.round(QUEUE.stuck / 60_000)} minutes with nothing ahead)` } : f)
|
|
3845
3892
|
} catch (e) {
|
|
3846
3893
|
return errorResponse({ status: 502, message: e?.message ?? String(e) })
|
|
3847
3894
|
}
|
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.71",
|
|
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",
|