@magpie-community/opencode-qoder-auth 0.2.62 → 0.2.63
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 +1 -0
- package/index.mjs +56 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -192,6 +192,7 @@ itself.
|
|
|
192
192
|
| 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
193
|
| A refusal of the request itself (codes 406, 416, 430, 80411, 80412, 100400–100403) | 400, with Qoder's words |
|
|
194
194
|
| "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 |
|
|
195
|
+
| "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 |
|
|
195
196
|
| A failure before the answer starts | Qoder's status |
|
|
196
197
|
| A failure after the answer has started | The stream ends with an error |
|
|
197
198
|
|
package/index.mjs
CHANGED
|
@@ -1501,7 +1501,9 @@ function qoderBody(chat, m, named = "", task, site) {
|
|
|
1501
1501
|
const sys = { type: "text", text: sysText }
|
|
1502
1502
|
const budget = chat.max_completion_tokens || chat.max_tokens || 0
|
|
1503
1503
|
const [thinking, effort] = effortFor(chat.reasoning_effort, m, typeof budget === "number" ? budget : 0)
|
|
1504
|
-
const
|
|
1504
|
+
const asked = chat.max_completion_tokens || chat.max_tokens || 32000
|
|
1505
|
+
const cap = outputCap(m)
|
|
1506
|
+
const params = { enable_thinking: thinking, max_tokens: cap > 0 && asked > cap ? cap : asked }
|
|
1505
1507
|
if (effort) params.reasoning_effort = effort
|
|
1506
1508
|
const window = windowFor(chat, m, params.max_tokens)
|
|
1507
1509
|
if (window > 0) params.context_length = window
|
|
@@ -1530,6 +1532,42 @@ function qoderBody(chat, m, named = "", task, site) {
|
|
|
1530
1532
|
return body
|
|
1531
1533
|
}
|
|
1532
1534
|
|
|
1535
|
+
// OUTPUT_CAPS are the largest max_tokens a model takes where its listing
|
|
1536
|
+
// entry names none: Qoder CN's QoDuck (lmodel) answers a larger one with a
|
|
1537
|
+
// 400 "Error in upstream response: Range of max_tokens should be [1,
|
|
1538
|
+
// 131072]", whatever the account (plugins#822, Gruu6y). A client asking
|
|
1539
|
+
// DeepSeek's 384K output was refused on every try, and each refusal rested
|
|
1540
|
+
// another account.
|
|
1541
|
+
const OUTPUT_CAPS = { lmodel: 131072 }
|
|
1542
|
+
// LEARNED_CAPS are the ceilings Qoder named in such a refusal, by model
|
|
1543
|
+
// key, for a model whose entry and OUTPUT_CAPS give none or a wrong one: the
|
|
1544
|
+
// refused request is asked again once at that ceiling, and later ones are
|
|
1545
|
+
// sent it from the start.
|
|
1546
|
+
const LEARNED_CAPS = new Map()
|
|
1547
|
+
// MAX_TOKENS_RANGE is that refusal's own words.
|
|
1548
|
+
const MAX_TOKENS_RANGE = /\brange of max_tokens should be \[\s*(\d+)\s*,\s*(\d+)\s*\]/i
|
|
1549
|
+
|
|
1550
|
+
// outputCap is the largest max_tokens model m takes, 0 when none is known:
|
|
1551
|
+
// what a refusal named, which is Qoder's own word, else its listing
|
|
1552
|
+
// entry's own (max_output_tokens), else OUTPUT_CAPS. A request's max_tokens is never sent above it, and one
|
|
1553
|
+
// asked lower is sent as asked.
|
|
1554
|
+
function outputCap(m) {
|
|
1555
|
+
const n = (v) => (Number.isInteger(v) && v > 0 ? v : 0)
|
|
1556
|
+
const raw = m?.config ?? {}
|
|
1557
|
+
return n(LEARNED_CAPS.get(m?.key)) || n(raw.max_output_tokens) || n(raw.maxOutputTokens) || n(OUTPUT_CAPS[m?.key])
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// reclamp is whether the request body was refused for a max_tokens above
|
|
1561
|
+
// model m's ceiling (failure's maxTokens), lowered to it if so: the
|
|
1562
|
+
// ceiling is remembered for the model, and the caller asks again once.
|
|
1563
|
+
function reclamp(f, body, m) {
|
|
1564
|
+
const cap = f?.maxTokens
|
|
1565
|
+
if (!(cap > 0) || !(body?.parameters?.max_tokens > cap)) return false
|
|
1566
|
+
if (m?.key) LEARNED_CAPS.set(m.key, cap)
|
|
1567
|
+
body.parameters.max_tokens = cap
|
|
1568
|
+
return true
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1533
1571
|
// failure is the status and message for a Qoder failure. Qoder's own code
|
|
1534
1572
|
// says what it is, read as Qoder's client reads it (QoderErrorCode in the
|
|
1535
1573
|
// app's qoder-agent-sdk worker): only 105 (loginExpired) is a lapsed
|
|
@@ -1598,6 +1636,11 @@ function failure(status, text) {
|
|
|
1598
1636
|
}
|
|
1599
1637
|
if (QUOTA_CODES.has(code)) return { status: 429, message: "usage limit reached: " + msg, signIn: "" }
|
|
1600
1638
|
if (REQUEST_CODES.has(code)) return { status: 400, message: `Qoder refused the request (${code}): ${msg}`, signIn: "" }
|
|
1639
|
+
// a max_tokens above the model's ceiling, said behind "Error in upstream
|
|
1640
|
+
// response": the request's fault on every account, so a 400 that rests
|
|
1641
|
+
// none, with the ceiling for ask to send again at (plugins#822)
|
|
1642
|
+
const range = MAX_TOKENS_RANGE.exec(msg)
|
|
1643
|
+
if (range) return { status: 400, message: `Qoder refused the request's max_tokens: ${msg}`, signIn: "", maxTokens: Number(range[2]) }
|
|
1601
1644
|
if (UPSTREAM_FAILED.test(msg)) return { status: 502, message: msg, signIn: "" }
|
|
1602
1645
|
// a refused chat is the built-in's 401, which never marked the account
|
|
1603
1646
|
// lapsed: only a refused refresh did (errorResponse says kept). Qoder's
|
|
@@ -3458,6 +3501,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3458
3501
|
let m
|
|
3459
3502
|
let relogged = false
|
|
3460
3503
|
let renamed = false
|
|
3504
|
+
let reclamped = false
|
|
3461
3505
|
const listed = (ms) => ms.find((x) => x.key === chat.model)
|
|
3462
3506
|
try {
|
|
3463
3507
|
m = listed(await models(cred)) ?? listed(await models(cred, true))
|
|
@@ -3552,6 +3596,11 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3552
3596
|
renamed = true
|
|
3553
3597
|
continue
|
|
3554
3598
|
}
|
|
3599
|
+
// a max_tokens above the model's ceiling: asked again once at it
|
|
3600
|
+
if (!reclamped && reclamp(f, body, m)) {
|
|
3601
|
+
reclamped = true
|
|
3602
|
+
continue
|
|
3603
|
+
}
|
|
3555
3604
|
// an answered call moves its task on, as Qoder's client moves it
|
|
3556
3605
|
if (!f) task.answered = true
|
|
3557
3606
|
// with another account, provider or group member after this one
|
|
@@ -3592,6 +3641,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3592
3641
|
const task = taskOf(sessionOf(chat, named), chat)
|
|
3593
3642
|
const tools = chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function") : []
|
|
3594
3643
|
let relogged = false
|
|
3644
|
+
let reclamped = false
|
|
3595
3645
|
for (let i = 0; ; ) {
|
|
3596
3646
|
const m = order[i]
|
|
3597
3647
|
const s = siteOf(site, cred)
|
|
@@ -3630,6 +3680,10 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3630
3680
|
}
|
|
3631
3681
|
return errorResponse({ status: 401, message: `the sign-in lapsed — open Qoder CN IDE so it signs in again (${String(f.message).slice(0, 300)})` })
|
|
3632
3682
|
}
|
|
3683
|
+
if (!reclamped && reclamp(f, body, m)) {
|
|
3684
|
+
reclamped = true
|
|
3685
|
+
continue
|
|
3686
|
+
}
|
|
3633
3687
|
if (f && LINGMA_NOT_HERE.test(f.message) && i + 1 < order.length) {
|
|
3634
3688
|
console.warn(`qoder-cn: ${s.dedicated} doesn't serve ${m.key}; asking ${order[i + 1].key}`)
|
|
3635
3689
|
i++
|
|
@@ -3945,4 +3999,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
3945
3999
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
3946
4000
|
|
|
3947
4001
|
// for tests
|
|
3948
|
-
export const _internal = { 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 }
|
|
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 }
|
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.63",
|
|
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",
|