@magpie-community/opencode-qoder-auth 0.2.61 → 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 +19 -6
- package/index.mjs +215 -60
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -189,9 +189,10 @@ 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
|
-
| 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 |
|
|
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
|
|
|
@@ -577,11 +578,23 @@ Since **0.2.28** a queued request waits its turn as Qoder's own client
|
|
|
577
578
|
model and the plan's `queueType`, at once and then every
|
|
578
579
|
`retryAfterSeconds` (held to 0.5–30s, 30s when unsaid), and once
|
|
579
580
|
`isQueued` is false it waits that state's `retryAfterSeconds` and sends the
|
|
580
|
-
same request again (up to 10 times).
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
581
|
+
same request again (up to 10 times). Three failed status asks in a row, a
|
|
582
|
+
404, or a cancelled request end the wait early.
|
|
583
|
+
|
|
584
|
+
Since **0.2.62** a streamed request (every agent's) waits as long as
|
|
585
|
+
Qoder's client does, up to an hour from the request's start, where it
|
|
586
|
+
waited at most 4 minutes and then was a 503 that Codex retried, a stop and
|
|
587
|
+
a restart for the user (plugins#807). It is answered 200 at once, with an
|
|
588
|
+
SSE comment saying the queue (": Qoder queued the request for smodel
|
|
589
|
+
(this plan's queue: p3, 284 ahead); try again in 30s") and a comment every
|
|
590
|
+
10 seconds while it waits. magpie counts each comment as the reply going
|
|
591
|
+
on: a Codex client is told `response.in_progress`, the event its 300s idle
|
|
592
|
+
timeout counts, and a Chat client gets the comment. What comes of the wait
|
|
593
|
+
goes on in the same stream: the answer, or a refusal (the queue's own after
|
|
594
|
+
the hour) as the stream's error. Nothing needs setting. A request that isn't
|
|
595
|
+
streamed has nothing to keep its client alive with, so it still waits 4
|
|
596
|
+
minutes at most before the 503. Claude Code takes a ping as life only 30
|
|
597
|
+
times in a row, about 35 minutes, so a longer wait still ends there. Qoder's client also reports the end
|
|
585
598
|
of its turn to `/api/v2/service/ask/finish`; the plugin doesn't, and
|
|
586
599
|
Qoder releases that lease on its own TTL. `queue.test.mjs` has the wait.
|
|
587
600
|
|
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
|
|
@@ -1648,17 +1691,27 @@ const errorResponse = ({ status, message, signIn = status === 401 ? "kept" : und
|
|
|
1648
1691
|
// request again in the same request_set_id under a new request_id and
|
|
1649
1692
|
// chat_record_id, up to 10 times; the refused call's stream is closed. Three failed asks
|
|
1650
1693
|
// in a row, a 404 (no queue there) or a state with neither field end the
|
|
1651
|
-
// wait. Qoder's client waits up to an hour
|
|
1652
|
-
//
|
|
1653
|
-
//
|
|
1654
|
-
//
|
|
1655
|
-
//
|
|
1656
|
-
//
|
|
1694
|
+
// wait. Qoder's client waits up to an hour, and so does a streamed request
|
|
1695
|
+
// here (QUEUE.held, from the request's start): at the first queue answer
|
|
1696
|
+
// it is given its 200 and an SSE comment at once, and one every
|
|
1697
|
+
// QUEUE.beat while it waits, so the agent is never left with nothing.
|
|
1698
|
+
// magpie hears the comments as the reply going on (its plugin host gives
|
|
1699
|
+
// a body 30 minutes between bytes, its translated replies keep the client
|
|
1700
|
+
// alive while the upstream is heard from) and tells a Codex client
|
|
1701
|
+
// response.in_progress for each, the event its 300s idle timeout counts
|
|
1702
|
+
// (plugins#807: at the old 4-minute cap Codex saw a 503 and a restart).
|
|
1703
|
+
// What comes of the wait goes on in the same stream: the answer, or the
|
|
1704
|
+
// refusal as the stream's error. A request not streamed has nothing to
|
|
1705
|
+
// keep its client alive with, and waits QUEUE.budget at most, then the
|
|
1706
|
+
// 503 with Retry-After it was before, so magpie may ask another account.
|
|
1707
|
+
// Qoder's client also tells
|
|
1657
1708
|
// /api/v2/service/ask/finish when its turn ends; that is left out, and its
|
|
1658
1709
|
// own log says Qoder's TTL releases the lease when finish is not heard.
|
|
1659
1710
|
const QUEUE_STATUS_PATH = "/algo/api/v2/service/ask/queue/status"
|
|
1660
1711
|
const QUEUE = {
|
|
1661
|
-
budget: 4 * 60 * 1000, // the longest a request is held, its first answer's wait included
|
|
1712
|
+
budget: 4 * 60 * 1000, // the longest a request not streamed is held, its first answer's wait included
|
|
1713
|
+
held: 60 * 60 * 1000, // the longest a streamed one is, as Qoder's client waits
|
|
1714
|
+
beat: 10_000, // the longest a held stream's client goes without a comment
|
|
1662
1715
|
shortest: 500,
|
|
1663
1716
|
longest: 30_000,
|
|
1664
1717
|
unsaid: 30_000, // a pause when the queue gives no retryAfterSeconds
|
|
@@ -1666,6 +1719,11 @@ const QUEUE = {
|
|
|
1666
1719
|
failures: 3, // status asks failing in a row that end the wait
|
|
1667
1720
|
ask: 30_000, // the longest one status ask may take
|
|
1668
1721
|
now: () => Date.now(),
|
|
1722
|
+
// every calls fn each ms until the returned stop is called
|
|
1723
|
+
every: (fn, ms) => {
|
|
1724
|
+
const t = setInterval(fn, ms)
|
|
1725
|
+
return () => clearInterval(t)
|
|
1726
|
+
},
|
|
1669
1727
|
pause: (ms, signal) =>
|
|
1670
1728
|
new Promise((ok, no) => {
|
|
1671
1729
|
if (signal?.aborted) return no(signal.reason ?? new DOMException("aborted", "AbortError"))
|
|
@@ -1779,6 +1837,73 @@ async function queueWait(api, cred, ask, first, signal, deadline, site) {
|
|
|
1779
1837
|
}
|
|
1780
1838
|
}
|
|
1781
1839
|
|
|
1840
|
+
// holdQueued is a streamed request's reply while Qoder's queue holds it
|
|
1841
|
+
// (queueWait): its 200 and a comment saying the queue now, a comment every
|
|
1842
|
+
// QUEUE.beat after, and then what came of the wait (follow): the answer's
|
|
1843
|
+
// stream, or a refusal as the stream's error, as answer ends a stream that
|
|
1844
|
+
// fails. signal ends the wait when the client goes, by its request's
|
|
1845
|
+
// signal or by cancelling this stream.
|
|
1846
|
+
function holdQueued(f, clientSignal) {
|
|
1847
|
+
const enc = new TextEncoder()
|
|
1848
|
+
const gone = new AbortController()
|
|
1849
|
+
let ctl, stop, reader
|
|
1850
|
+
let closed = false
|
|
1851
|
+
const say = (text) => {
|
|
1852
|
+
if (closed) return
|
|
1853
|
+
try {
|
|
1854
|
+
ctl.enqueue(enc.encode(text))
|
|
1855
|
+
} catch {}
|
|
1856
|
+
}
|
|
1857
|
+
const end = () => {
|
|
1858
|
+
stop?.()
|
|
1859
|
+
if (closed) return
|
|
1860
|
+
closed = true
|
|
1861
|
+
try {
|
|
1862
|
+
ctl.close()
|
|
1863
|
+
} catch {}
|
|
1864
|
+
}
|
|
1865
|
+
const body = new ReadableStream({
|
|
1866
|
+
start(c) {
|
|
1867
|
+
ctl = c
|
|
1868
|
+
say(`: ${String(f.message).replace(/[\r\n]+/g, " ")}\n\n`)
|
|
1869
|
+
stop = QUEUE.every(() => say(": queued\n\n"), QUEUE.beat)
|
|
1870
|
+
},
|
|
1871
|
+
cancel(reason) {
|
|
1872
|
+
stop?.()
|
|
1873
|
+
closed = true
|
|
1874
|
+
gone.abort(reason ?? new DOMException("the client went away", "AbortError"))
|
|
1875
|
+
reader?.cancel(reason).catch(() => {})
|
|
1876
|
+
},
|
|
1877
|
+
})
|
|
1878
|
+
const response = new Response(body, { status: 200, headers: { "Content-Type": "text/event-stream", "Cache-Control": "no-cache" } })
|
|
1879
|
+
const follow = async (done) => {
|
|
1880
|
+
const res = await done
|
|
1881
|
+
stop?.()
|
|
1882
|
+
if (closed) return res.body?.cancel().catch(() => {})
|
|
1883
|
+
if (!res.ok) {
|
|
1884
|
+
let message = res.statusText || `HTTP ${res.status}`
|
|
1885
|
+
try {
|
|
1886
|
+
message = (await res.json())?.error?.message ?? message
|
|
1887
|
+
} catch {}
|
|
1888
|
+
say(`data: ${JSON.stringify({ error: { message, code: res.status } })}\n\n`)
|
|
1889
|
+
return end()
|
|
1890
|
+
}
|
|
1891
|
+
reader = res.body.getReader()
|
|
1892
|
+
try {
|
|
1893
|
+
for (;;) {
|
|
1894
|
+
const { done, value } = await reader.read()
|
|
1895
|
+
if (done || closed) break
|
|
1896
|
+
ctl.enqueue(value)
|
|
1897
|
+
}
|
|
1898
|
+
} catch (e) {
|
|
1899
|
+
say(`data: ${JSON.stringify({ error: { message: e?.message ?? String(e), code: 502 } })}\n\n`)
|
|
1900
|
+
}
|
|
1901
|
+
end()
|
|
1902
|
+
}
|
|
1903
|
+
const signal = clientSignal ? AbortSignal.any([clientSignal, gone.signal]) : gone.signal
|
|
1904
|
+
return { response, signal, follow: (done) => void follow(done) }
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1782
1907
|
// ---- the reply ----------------------------------------------------------------
|
|
1783
1908
|
|
|
1784
1909
|
const CALL_OPEN = "\x3ctool_call\x3e"
|
|
@@ -3376,6 +3501,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3376
3501
|
let m
|
|
3377
3502
|
let relogged = false
|
|
3378
3503
|
let renamed = false
|
|
3504
|
+
let reclamped = false
|
|
3379
3505
|
const listed = (ms) => ms.find((x) => x.key === chat.model)
|
|
3380
3506
|
try {
|
|
3381
3507
|
m = listed(await models(cred)) ?? listed(await models(cred, true))
|
|
@@ -3417,65 +3543,89 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3417
3543
|
// resend). On a real qoder.com account (plugins#427) the free models
|
|
3418
3544
|
// are queued in p3 for RESOURCE_LIMIT, about 30s at a time, and a
|
|
3419
3545
|
// resend can be queued again before it is answered.
|
|
3420
|
-
const
|
|
3546
|
+
const began = QUEUE.now()
|
|
3547
|
+
let deadline = began + QUEUE.budget
|
|
3421
3548
|
const ask = { requestSetId: body.request_set_id, requestId: body.request_id, sessionId: body.session_id, modelKey: m.key }
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
const f = !res.ok ? failure(res.status, (await res.text()).slice(0, 1 << 20)) : open.first.value?.error
|
|
3442
|
-
if (f) call.abort()
|
|
3443
|
-
// a refused job token: renewed once (or the one renewed meanwhile)
|
|
3444
|
-
// and the request sent again, before the refusal is said
|
|
3445
|
-
if (f?.lapsed && getAuth && !relogged) {
|
|
3446
|
-
relogged = true
|
|
3447
|
-
let next
|
|
3549
|
+
// a streamed request queued: its 200 goes to the client at once (held),
|
|
3550
|
+
// and what comes of the wait follows in that stream
|
|
3551
|
+
let held, onHeld
|
|
3552
|
+
let signal = init.signal
|
|
3553
|
+
const heard = new Promise((ok) => (onHeld = ok))
|
|
3554
|
+
const run = async () => {
|
|
3555
|
+
for (let sent = 0, waited = 0; ; sent++) {
|
|
3556
|
+
if (sent) {
|
|
3557
|
+
body.request_id = body.chat_record_id = randomUUID()
|
|
3558
|
+
ask.requestId = body.request_id
|
|
3559
|
+
}
|
|
3560
|
+
const wire = encodeBody(JSON.stringify(body))
|
|
3561
|
+
const headers = chatHeaders(CHAT_URL, cred, wire, siteOf(site, cred), m, chatIdentity(cred.uid))
|
|
3562
|
+
// a refused call's stream is closed: Qoder keeps a 10605 stream open
|
|
3563
|
+
// after its one event, and a connection held open while the call is
|
|
3564
|
+
// waited out and sent again is one more the account holds
|
|
3565
|
+
const call = new AbortController()
|
|
3566
|
+
const callSignal = signal ? AbortSignal.any([signal, call.signal]) : call.signal
|
|
3567
|
+
let res, open
|
|
3448
3568
|
try {
|
|
3449
|
-
|
|
3569
|
+
res = await fetch(CHAT_URL, { method: "POST", headers, body: wire, signal: callSignal })
|
|
3570
|
+
if (res.ok) open = await opened(res, chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function") : [])
|
|
3450
3571
|
} catch (e) {
|
|
3451
|
-
return
|
|
3572
|
+
return errorResponse({ status: 502, message: e.message })
|
|
3452
3573
|
}
|
|
3453
|
-
|
|
3454
|
-
|
|
3574
|
+
const f = !res.ok ? failure(res.status, (await res.text()).slice(0, 1 << 20)) : open.first.value?.error
|
|
3575
|
+
if (f) call.abort()
|
|
3576
|
+
// a refused job token: renewed once (or the one renewed meanwhile)
|
|
3577
|
+
// and the request sent again, before the refusal is said
|
|
3578
|
+
if (f?.lapsed && getAuth && !relogged) {
|
|
3579
|
+
relogged = true
|
|
3580
|
+
let next
|
|
3581
|
+
try {
|
|
3582
|
+
next = await relogin(getAuth, cred.access)
|
|
3583
|
+
} catch (e) {
|
|
3584
|
+
return signedInError(e)
|
|
3585
|
+
}
|
|
3586
|
+
if (next) {
|
|
3587
|
+
cred = asked.cred = next
|
|
3588
|
+
continue
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
// a reply whose only answer was a native tool call the model never
|
|
3592
|
+
// named (plugins#579): nothing of it was given, so it is asked once
|
|
3593
|
+
// more, under a new request_id; a second one is the gateway's 502 to
|
|
3594
|
+
// retry or fail over
|
|
3595
|
+
if (f?.nameless && !renamed) {
|
|
3596
|
+
renamed = true
|
|
3455
3597
|
continue
|
|
3456
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
|
+
}
|
|
3604
|
+
// an answered call moves its task on, as Qoder's client moves it
|
|
3605
|
+
if (!f) task.answered = true
|
|
3606
|
+
// with another account, provider or group member after this one
|
|
3607
|
+
// (magpie's X-Magpie-Fallback), a queued request isn't waited out:
|
|
3608
|
+
// its 503 goes back at once, saying the queue, and the next is asked
|
|
3609
|
+
if (!f?.queue || waited >= QUEUE.recoveries || fallback) return f ? errorResponse(f) : answer(open, chat, servedName)
|
|
3610
|
+
if (chat.stream && !held) {
|
|
3611
|
+
held = holdQueued(f, init.signal)
|
|
3612
|
+
signal = held.signal
|
|
3613
|
+
deadline = began + QUEUE.held
|
|
3614
|
+
onHeld(held.response)
|
|
3615
|
+
}
|
|
3616
|
+
try {
|
|
3617
|
+
if (!(await queueWait(api, cred, ask, f.queue, signal, deadline, siteOf(site, cred)))) return errorResponse(f)
|
|
3618
|
+
} catch (e) {
|
|
3619
|
+
return errorResponse({ status: 502, message: e?.message ?? String(e) })
|
|
3620
|
+
}
|
|
3621
|
+
waited++
|
|
3457
3622
|
}
|
|
3458
|
-
// a reply whose only answer was a native tool call the model never
|
|
3459
|
-
// named (plugins#579): nothing of it was given, so it is asked once
|
|
3460
|
-
// more, under a new request_id; a second one is the gateway's 502 to
|
|
3461
|
-
// retry or fail over
|
|
3462
|
-
if (f?.nameless && !renamed) {
|
|
3463
|
-
renamed = true
|
|
3464
|
-
continue
|
|
3465
|
-
}
|
|
3466
|
-
// an answered call moves its task on, as Qoder's client moves it
|
|
3467
|
-
if (!f) task.answered = true
|
|
3468
|
-
// with another account, provider or group member after this one
|
|
3469
|
-
// (magpie's X-Magpie-Fallback), a queued request isn't waited out:
|
|
3470
|
-
// its 503 goes back at once, saying the queue, and the next is asked
|
|
3471
|
-
if (!f?.queue || waited >= QUEUE.recoveries || fallback) return f ? errorResponse(f) : answer(open, chat, servedName)
|
|
3472
|
-
try {
|
|
3473
|
-
if (!(await queueWait(api, cred, ask, f.queue, init.signal, deadline, siteOf(site, cred)))) return errorResponse(f)
|
|
3474
|
-
} catch (e) {
|
|
3475
|
-
return errorResponse({ status: 502, message: e?.message ?? String(e) })
|
|
3476
|
-
}
|
|
3477
|
-
waited++
|
|
3478
3623
|
}
|
|
3624
|
+
const done = run().catch((e) => errorResponse({ status: 502, message: e?.message ?? String(e) }))
|
|
3625
|
+
const res = await Promise.race([done, heard])
|
|
3626
|
+
if (res !== held?.response) return res
|
|
3627
|
+
held.follow(done)
|
|
3628
|
+
return res
|
|
3479
3629
|
}
|
|
3480
3630
|
|
|
3481
3631
|
// askLingma is ask for a Lingma 1.0 account: the IDE's models, signed as
|
|
@@ -3491,6 +3641,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3491
3641
|
const task = taskOf(sessionOf(chat, named), chat)
|
|
3492
3642
|
const tools = chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function") : []
|
|
3493
3643
|
let relogged = false
|
|
3644
|
+
let reclamped = false
|
|
3494
3645
|
for (let i = 0; ; ) {
|
|
3495
3646
|
const m = order[i]
|
|
3496
3647
|
const s = siteOf(site, cred)
|
|
@@ -3529,6 +3680,10 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3529
3680
|
}
|
|
3530
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)})` })
|
|
3531
3682
|
}
|
|
3683
|
+
if (!reclamped && reclamp(f, body, m)) {
|
|
3684
|
+
reclamped = true
|
|
3685
|
+
continue
|
|
3686
|
+
}
|
|
3532
3687
|
if (f && LINGMA_NOT_HERE.test(f.message) && i + 1 < order.length) {
|
|
3533
3688
|
console.warn(`qoder-cn: ${s.dedicated} doesn't serve ${m.key}; asking ${order[i + 1].key}`)
|
|
3534
3689
|
i++
|
|
@@ -3844,4 +3999,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
3844
3999
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
3845
4000
|
|
|
3846
4001
|
// for tests
|
|
3847
|
-
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",
|