@magpie-community/opencode-qoder-auth 0.2.73 → 0.2.75

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.
Files changed (3) hide show
  1. package/README.md +15 -5
  2. package/index.mjs +167 -23
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -162,7 +162,8 @@ itself.
162
162
  - an MD5 signature;
163
163
  - the machine id and the client's headers.
164
164
  - `Cosy-Version`: the worker runtime version that Qoder's desktop app
165
- ships (1.1.69 in app 0.4.8, since 0.2.23, #281), because
165
+ ships (1.1.96-hotfix.8 in app 0.5.20, since 0.2.75, #1560; before
166
+ that 1.1.69 in app 0.4.8, from 0.2.23, #281), because
166
167
  `Cosy-ClientType` says the desktop app.
167
168
 
168
169
  **Reading the reply**
@@ -592,7 +593,9 @@ Since **0.2.28** a queued request waits its turn as Qoder's own client
592
593
  model and the plan's `queueType`, at once and then every
593
594
  `retryAfterSeconds` (held to 0.5–30s, 30s when unsaid), and once
594
595
  `isQueued` is false it waits that state's `retryAfterSeconds` and sends the
595
- same request again (up to 10 times). Three failed status asks in a row, a
596
+ same request again (up to 10 times). Since **0.2.74** `isQueued` false with
597
+ `serviceAvailable` false is waited on too, as Qoder's client reads it
598
+ (qoderclicn 1.1.98), rather than sent into the queue again. Three failed status asks in a row, a
596
599
  404, or a cancelled request end the wait early.
597
600
 
598
601
  Since **0.2.62** a streamed request (every agent's) waits as long as
@@ -614,9 +617,16 @@ keepalives); magpie can then rest the account or ask the next. A queue with
614
617
  others ahead is still waited out. Nothing needs setting. A request that isn't
615
618
  streamed has nothing to keep its client alive with, so it still waits 4
616
619
  minutes at most before the 503. Claude Code takes a ping as life only 30
617
- times in a row, about 35 minutes, so a longer wait still ends there. Qoder's client also reports the end
618
- of its turn to `/api/v2/service/ask/finish`; the plugin doesn't, and
619
- Qoder releases that lease on its own TTL. `queue.test.mjs` has the wait.
620
+ times in a row, about 35 minutes, so a longer wait still ends there.
621
+
622
+ A queued request holds a lease in Qoder's queue (its `request_set_id` and
623
+ model) until Qoder hears `/api/v2/service/ask/finish`. Before **0.2.74** the
624
+ plugin never told it, so each lease stayed until Qoder's own TTL let it go
625
+ (plugins#1560). Now it tells finish as Qoder's client does: at once when a
626
+ request gives up waiting (the 503 above, or a cancelled request), and
627
+ otherwise when the task ends (the session's next prompt, or the task let go
628
+ after 2 hours idle). A finish that fails changes nothing for the request.
629
+ `queue.test.mjs` has the wait and the finish.
620
630
 
621
631
  Since **0.2.40** the wait is only for the last candidate: when magpie says
622
632
  another account, provider or routing group member follows this request
package/index.mjs CHANGED
@@ -48,10 +48,14 @@ const MODELS_PATH = "/algo/api/v2/model/list?Encode=1"
48
48
  // talks through — the worker runtime bundled in the app — because the
49
49
  // envelope also says Cosy-ClientType: 10 (desktop) and carries that app's
50
50
  // machine identity; the CLI's channel publishes a different, later number
51
- // that no desktop build runs. Taken from app 0.4.8 (build 79743374,
52
- // 2026-10-14), whose transport config names 1.1.69. Raise it when the app
53
- // moves, not when the CLI does.
54
- const COSY_VERSION = "1.1.69"
51
+ // that no desktop build runs. Taken from app 0.5.20 (both feeds, Qoder
52
+ // and Qoder CN, 2026-11-27), whose bundled worker runtime's
53
+ // runtime-info.json names 1.1.96-hotfix.8, the number its envelope and its
54
+ // chat's business.version say. 0.4.8 named 1.1.69: sending that, every
55
+ // request of one Qoder CN account was queued again after each wait, while
56
+ // the app answered the same account at once (plugins#1560). Raise it when
57
+ // the app moves, not when the CLI does.
58
+ const COSY_VERSION = "1.1.96-hotfix.8"
55
59
  const SIGN_IN_TIMEOUT = 15 * 60 * 1000
56
60
  const REFRESH_LEAD = 5 * 60 * 1000 // a chat token this close to its end is refreshed before a request
57
61
  const RENEW_LEAD = 10 * 60 * 1000 // and this close, magpie renews it ahead of time (auth.refresh)
@@ -1427,7 +1431,8 @@ const TASK_IDLE = 2 * 60 * 60 * 1000
1427
1431
  const taskName = (prompt) => (prompt.length > 10 ? prompt.slice(0, 10) : prompt)
1428
1432
 
1429
1433
  // taskOf is the task chat's call belongs to, in session sid: made on its
1430
- // first call, the same one on every call after.
1434
+ // first call, the same one on every call after. A task let go, or one of
1435
+ // the session's before a new prompt, ends (endTask).
1431
1436
  function taskOf(sid, chat, now = Date.now()) {
1432
1437
  const msgs = chat.messages ?? []
1433
1438
  const at = msgs.findLastIndex((x) => x?.role === "user")
@@ -1435,17 +1440,36 @@ function taskOf(sid, chat, now = Date.now()) {
1435
1440
  for (const [k, t] of TASKS) {
1436
1441
  if (now - t.used <= TASK_IDLE) break
1437
1442
  TASKS.delete(k)
1443
+ endTask(t)
1438
1444
  }
1439
1445
  let t = TASKS.get(key)
1440
- if (t && now - t.used > TASK_IDLE) t = undefined
1446
+ if (t && now - t.used > TASK_IDLE) {
1447
+ endTask(t)
1448
+ t = undefined
1449
+ }
1441
1450
  TASKS.delete(key)
1442
- t ??= { id: randomUUID(), begin: now, answered: false, name: taskName(at < 0 ? "" : textOf(msgs[at].content)) }
1451
+ if (!t) {
1452
+ for (const o of TASKS.values()) if (o.sid === sid) endTask(o)
1453
+ t = { id: randomUUID(), sid, begin: now, answered: false, name: taskName(at < 0 ? "" : textOf(msgs[at].content)) }
1454
+ }
1443
1455
  t.used = now
1444
1456
  TASKS.set(key, t)
1445
- while (TASKS.size > TASK_MAX) TASKS.delete(TASKS.keys().next().value)
1457
+ while (TASKS.size > TASK_MAX) {
1458
+ const k = TASKS.keys().next().value
1459
+ endTask(TASKS.get(k))
1460
+ TASKS.delete(k)
1461
+ }
1446
1462
  return t
1447
1463
  }
1448
1464
 
1465
+ // endTask ends task t: its queue leases are let go (release) now, or when
1466
+ // its last request in flight is done.
1467
+ function endTask(t) {
1468
+ if (!t) return
1469
+ if (t.inflight) t.ended = true
1470
+ else void release(t)
1471
+ }
1472
+
1449
1473
  // Qoder CN's kmodel (Kimi K3.1 Pro) fails a chat whose tools hold a oneOf
1450
1474
  // with no type, even of objects only, and takes it with "type": "object"
1451
1475
  // beside it (congee949, #378: dsh's REA tools, a 502 here). typedUnions is
@@ -1523,6 +1547,13 @@ function modelConfig(m, thinking) {
1523
1547
  // 0.4.3 and QwenWork 1.0.46 build their record without it, so a site that
1524
1548
  // ships such a client says businessModelKey: false.
1525
1549
  //
1550
+ // APP_CHAT is what Qoder's desktop app (0.5.20, its worker runtime's
1551
+ // remote chat body) says of every chat request it sends, whatever the
1552
+ // prompt: a streamed free-input turn, version "3". It goes with
1553
+ // COSY_VERSION, so only to the sites that speak as that app; QwenWork and
1554
+ // Lingma, with versions of their own, send their own clients' bodies.
1555
+ const APP_CHAT = { stream: true, chat_task: "FREE_INPUT", is_reply: true, is_retry: false, source: 1, version: "3", aliyun_user_type: "" }
1556
+
1526
1557
  // qoderBody is the plaintext agent_chat_generation takes for a chat
1527
1558
  // completion request, for model m, in the session the agent named (named,
1528
1559
  // "" when none) and the task it is a call of (taskOf's, a new one when
@@ -1552,6 +1583,8 @@ function qoderBody(chat, m, named = "", task, site) {
1552
1583
  request_set_id: task.id,
1553
1584
  chat_record_id: request,
1554
1585
  session_id: session,
1586
+ // what the app's request says of itself beside its version
1587
+ ...(site?.cosyVersion ? {} : APP_CHAT),
1555
1588
  parameters: params,
1556
1589
  business: { product: site?.businessProduct ?? "app", version: site?.cosyVersion ?? COSY_VERSION, type: "agent", id: task.id, name: task.name ?? "", begin_at: task.begin, stage: task.answered ? "processing" : "start", ...(site?.businessModelKey === false ? {} : { model_key: m.key }) },
1557
1590
  agent_id: "agent_common",
@@ -1741,10 +1774,18 @@ const errorResponse = ({ status, message, signIn = status === 401 ? "kept" : und
1741
1774
  // refusal as the stream's error. A request not streamed has nothing to
1742
1775
  // keep its client alive with, and waits QUEUE.budget at most, then the
1743
1776
  // 503 with Retry-After it was before, so magpie may ask another account.
1744
- // Qoder's client also tells
1745
- // /api/v2/service/ask/finish when its turn ends; that is left out, and its
1746
- // own log says Qoder's TTL releases the lease when finish is not heard.
1777
+ // A queued request holds a lease in Qoder's queue, under its
1778
+ // request_set_id and model, until Qoder hears /api/v2/service/ask/finish
1779
+ // (queueFinish); unheard, only Qoder's TTL lets it go. Qoder's client
1780
+ // (qoderclicn 1.1.98 and Qoder.app's qoder-worker-runtime, "[ModelQueue]")
1781
+ // registers one on each 10605 and tells finish when its turn ends, when
1782
+ // its session ends, and at once when the request gives up waiting. The
1783
+ // plugin never told it (plugins#1560: a Qoder CN account queued in p2 and
1784
+ // p4 while its plan's credits went unused). Here a lease ends when the
1785
+ // request gives up the wait, and when its task does: the session's next
1786
+ // prompt, or the task let go for TASK_IDLE or TASK_MAX.
1747
1787
  const QUEUE_STATUS_PATH = "/algo/api/v2/service/ask/queue/status"
1788
+ const QUEUE_FINISH_PATH = "/algo/api/v2/service/ask/finish?Encode=1"
1748
1789
  const QUEUE = {
1749
1790
  budget: 4 * 60 * 1000, // the longest a request not streamed is held, its first answer's wait included
1750
1791
  held: 60 * 60 * 1000, // the longest a streamed one is, as Qoder's client waits
@@ -1755,6 +1796,7 @@ const QUEUE = {
1755
1796
  recoveries: 10, // the queue waited out this many times, at most, for one request
1756
1797
  failures: 3, // status asks failing in a row that end the wait
1757
1798
  ask: 30_000, // the longest one status ask may take
1799
+ finish: 3_000, // the longest a finish may take, as Qoder's client gives it
1758
1800
  // the longest a call waits for Qoder's first event (headers included).
1759
1801
  // Qoder CN once held a call 15 minutes with nothing sent and nothing to
1760
1802
  // log (#1204); after this it is a 504 that says so, which magpie can
@@ -1771,6 +1813,9 @@ const QUEUE = {
1771
1813
  // Qoder's client waits it (#807).
1772
1814
  stuck: 5 * 60 * 1000,
1773
1815
  now: () => Date.now(),
1816
+ // a line for magpie's log (the plugin host's stderr, app.log's
1817
+ // "plugin: " lines): each step of a queued request's wait
1818
+ log: (line) => console.warn(line),
1774
1819
  // every calls fn each ms until the returned stop is called
1775
1820
  every: (fn, ms) => {
1776
1821
  const t = setInterval(fn, ms)
@@ -1801,6 +1846,23 @@ function queuePause(seconds) {
1801
1846
 
1802
1847
  class QueueEnd extends Error {}
1803
1848
 
1849
+ // queueSays is a queue state as Qoder gave it, its fields by Qoder's names,
1850
+ // for magpie's log and the refusal a wait ends with: what the queue said
1851
+ // (plugins#1560: the reporter had no way to see it).
1852
+ const QUEUE_FIELDS = ["isQueued", "serviceAvailable", "queueType", "queueCount", "retryAfterSeconds", "waitTime", "subCode", "modelKey"]
1853
+ function queueSays(st) {
1854
+ if (!st || typeof st !== "object") return "nothing of the queue"
1855
+ const said = QUEUE_FIELDS.filter((k) => st[k] !== undefined && st[k] !== null && st[k] !== "").map((k) => `${k} ${st[k]}`)
1856
+ return said.length ? said.join(", ") : "nothing of the queue"
1857
+ }
1858
+
1859
+ // queueLog logs a step of the wait of ask, the request of site
1860
+ function queueLog(site, ask, text) {
1861
+ try {
1862
+ QUEUE.log(`${site?.id ?? "qoder"}: ${ask.modelKey} in request set ${String(ask.requestSetId).slice(0, 8)}: ${text}`)
1863
+ } catch {}
1864
+ }
1865
+
1804
1866
  // queueState is the queue's state in a status reply, found as Qoder's
1805
1867
  // client finds it: the object, or one under data/result/message/body, as
1806
1868
  // an object or a JSON string, that says isQueued or serviceAvailable.
@@ -1823,7 +1885,7 @@ function queueState(text) {
1823
1885
  if (isQueued !== undefined || serviceAvailable !== undefined) {
1824
1886
  const num = (v) => (v == null || v === "" || !Number.isFinite(Number(v)) ? undefined : Number(v))
1825
1887
  const str = (v) => (typeof v === "string" && v ? v : undefined)
1826
- return { isQueued, serviceAvailable, modelKey: str(o.modelKey), queueType: str(o.queueType), retryAfterSeconds: num(o.retryAfterSeconds), queueCount: num(o.queueCount), subCode: str(o.subCode) }
1888
+ return { isQueued, serviceAvailable, modelKey: str(o.modelKey), queueType: str(o.queueType), retryAfterSeconds: num(o.retryAfterSeconds), queueCount: num(o.queueCount), waitTime: num(o.waitTime), subCode: str(o.subCode) }
1827
1889
  }
1828
1890
  for (const k of ["data", "result", "message", "body"]) {
1829
1891
  const v = o[k]
@@ -1855,6 +1917,49 @@ async function queueStatus(api, cred, { requestSetId, modelKey, queueType, reque
1855
1917
  return st
1856
1918
  }
1857
1919
 
1920
+ // queueReady: the queue lets the request through, as Qoder's client reads
1921
+ // a status (qoderclicn 1.1.98, qoder-worker-runtime: isQueued false and
1922
+ // serviceAvailable not false). isQueued false with the service unavailable
1923
+ // is waited on: sent then, the request is only queued again.
1924
+ const queueReady = (st) => st.isQueued === false && st.serviceAvailable !== false
1925
+
1926
+ // queueFinish tells Qoder's queue a lease is done, as Qoder's client's
1927
+ // finish does: POST /api/v2/service/ask/finish?Encode=1, signed, its body
1928
+ // {payload, encodeVersion: "1"} encoded as a chat's is, the payload the
1929
+ // lease's model_key and request_set_id, the user's id and the
1930
+ // milliseconds since the lease began. Best effort: it waits QUEUE.finish
1931
+ // at most, and a failure leaves the lease to Qoder's TTL, as there.
1932
+ async function queueFinish(lease) {
1933
+ const { api, cred, site, requestSetId, modelKey, began } = lease
1934
+ if (!cred?.uid) return
1935
+ try {
1936
+ const url = api + QUEUE_FINISH_PATH
1937
+ const payload = JSON.stringify({ model_key: modelKey, request_set_id: requestSetId, user_id: cred.uid, time_consumed: Math.max(0, Math.round(QUEUE.now() - began)) })
1938
+ const wire = encodeBody(JSON.stringify({ payload, encodeVersion: "1" }))
1939
+ const res = await fetch(url, { method: "POST", headers: cosyHeaders(url, cred, wire, site), body: wire, signal: AbortSignal.timeout(QUEUE.finish) })
1940
+ await res.arrayBuffer()
1941
+ } catch {}
1942
+ }
1943
+
1944
+ // leaseOf registers the queue's lease for a request of task t, once for
1945
+ // its request_set_id and model, from the first 10605.
1946
+ function leaseOf(t, lease) {
1947
+ t.leases ??= new Map()
1948
+ const key = JSON.stringify([lease.requestSetId, lease.modelKey])
1949
+ if (!t.leases.has(key)) t.leases.set(key, lease)
1950
+ return key
1951
+ }
1952
+
1953
+ // release tells finish for task t's leases (key's alone when given), and
1954
+ // forgets them.
1955
+ function release(t, key) {
1956
+ if (!t?.leases?.size) return Promise.resolve()
1957
+ const done = key === undefined ? [...t.leases.values()] : t.leases.has(key) ? [t.leases.get(key)] : []
1958
+ if (key === undefined) t.leases.clear()
1959
+ else t.leases.delete(key)
1960
+ return Promise.all(done.map(queueFinish))
1961
+ }
1962
+
1858
1963
  // stuckKey is what a queue's state says of the request's place in it, or
1859
1964
  // "" when others are ahead of it (a queue that moves while they are
1860
1965
  // served is waited out, QUEUE.stuck never ends it).
@@ -1869,6 +1974,7 @@ function stuckKey(st) {
1869
1974
  // (false). A wait ended by QUEUE.stuck sets ask.stuck. A cancelled request
1870
1975
  // throws.
1871
1976
  async function queueWait(api, cred, ask, first, signal, deadline, site) {
1977
+ const began = QUEUE.now()
1872
1978
  let q = first ?? {}
1873
1979
  let asked = false
1874
1980
  let failed = 0
@@ -1876,35 +1982,47 @@ async function queueWait(api, cred, ask, first, signal, deadline, site) {
1876
1982
  let since = QUEUE.now()
1877
1983
  for (;;) {
1878
1984
  if (signal?.aborted) throw signal.reason ?? new DOMException("aborted", "AbortError")
1879
- if (QUEUE.now() >= deadline) return false
1985
+ const ranOut = () => (queueLog(site, ask, `the wait ran out after ${Math.round((QUEUE.now() - began) / 1000)}s`), false)
1986
+ if (QUEUE.now() >= deadline) return ranOut()
1880
1987
  if (asked) await QUEUE.pause(Math.min(queuePause(q.retryAfterSeconds), Math.max(0, deadline - QUEUE.now())), signal)
1881
1988
  asked = true
1882
- if (QUEUE.now() >= deadline) return false
1989
+ if (QUEUE.now() >= deadline) return ranOut()
1883
1990
  let st
1884
1991
  try {
1885
1992
  st = await queueStatus(api, cred, { ...ask, modelKey: q.modelKey ?? ask.modelKey, queueType: q.queueType ?? ask.queueType }, signal, deadline, site)
1886
1993
  } catch (e) {
1887
1994
  if (signal?.aborted) throw signal.reason ?? e
1888
- if (e instanceof QueueEnd) return false
1889
- if (++failed >= QUEUE.failures) return false
1995
+ if (e instanceof QueueEnd) {
1996
+ queueLog(site, ask, `the wait ends: ${e.message}`)
1997
+ return false
1998
+ }
1999
+ queueLog(site, ask, `queue status ask failed: ${e?.message ?? e}`)
2000
+ if (++failed >= QUEUE.failures) {
2001
+ queueLog(site, ask, `the wait ends: ${failed} status asks failed in a row`)
2002
+ return false
2003
+ }
1890
2004
  q = { ...q, retryAfterSeconds: undefined }
1891
2005
  continue
1892
2006
  }
1893
2007
  failed = 0
2008
+ ask.last = st
2009
+ queueLog(site, ask, `queue status: ${queueSays(st)}${queueReady(st) ? "; through, sending it again" : ""}`)
1894
2010
  q = { ...st, modelKey: st.modelKey ?? q.modelKey, queueType: st.queueType ?? q.queueType }
1895
2011
  const key = stuckKey(q)
1896
2012
  if (!key || key !== same) {
1897
2013
  same = key
1898
2014
  since = QUEUE.now()
1899
- } else if (QUEUE.now() - since >= QUEUE.stuck && st.isQueued !== false) {
2015
+ } else if (QUEUE.now() - since >= QUEUE.stuck && !queueReady(st)) {
1900
2016
  ask.stuck = true
2017
+ queueLog(site, ask, `the wait ends: the queue hasn't moved in ${Math.round(QUEUE.stuck / 60_000)} minutes with nothing ahead`)
1901
2018
  return false
1902
2019
  }
1903
- if (st.isQueued === false) {
2020
+ if (queueReady(st)) {
1904
2021
  if (st.retryAfterSeconds > 0) await QUEUE.pause(Math.min(queuePause(st.retryAfterSeconds), Math.max(0, deadline - QUEUE.now())), signal)
1905
2022
  return QUEUE.now() < deadline
1906
2023
  }
1907
2024
  if (st.serviceAvailable === false || st.isQueued === true) continue
2025
+ queueLog(site, ask, "the wait ends: the status is neither queued nor through")
1908
2026
  return false
1909
2027
  }
1910
2028
  }
@@ -3905,7 +4023,28 @@ const makePlugin = (site) => async ({ client }) => {
3905
4023
  // with another account, provider or group member after this one
3906
4024
  // (magpie's X-Magpie-Fallback), a queued request isn't waited out:
3907
4025
  // its 503 goes back at once, saying the queue, and the next is asked
3908
- if (!f?.queue || waited >= QUEUE.recoveries || fallback) return f ? errorResponse(f) : answer(open, chat, servedName)
4026
+ if (!f?.queue) return f ? errorResponse(f) : answer(open, chat, servedName)
4027
+ // queued: the lease Qoder's queue now holds for it, let go at once
4028
+ // when the request gives up waiting, else when its task ends
4029
+ const lease = leaseOf(task, { api, cred, site: siteOf(site, cred), requestSetId: ask.requestSetId, modelKey: m.key, began: QUEUE.now() })
4030
+ const giveUp = (r) => {
4031
+ void release(task, lease)
4032
+ return r
4033
+ }
4034
+ const said = siteOf(site, cred)
4035
+ queueLog(said, ask, `queued (${QUEUED}) on send ${sent + 1}: ${queueSays(f.queue)}`)
4036
+ if (fallback) {
4037
+ queueLog(said, ask, "not waited: another candidate follows")
4038
+ return giveUp(errorResponse(f))
4039
+ }
4040
+ // the queue said it was through each time, and each resend was
4041
+ // queued again: said in the refusal, with the queue's last status,
4042
+ // so the reason is readable where the error is (plugins#1560)
4043
+ if (waited >= QUEUE.recoveries) {
4044
+ const again = `Qoder's queue let it through ${waited} times and queued each resend again; its last status: ${queueSays(ask.last)}`
4045
+ queueLog(said, ask, `the wait ends: ${again}`)
4046
+ return giveUp(errorResponse({ ...f, message: `${f.message} (${again})` }))
4047
+ }
3909
4048
  if (chat.stream && !held) {
3910
4049
  held = holdQueued(f, init.signal)
3911
4050
  signal = held.signal
@@ -3914,14 +4053,19 @@ const makePlugin = (site) => async ({ client }) => {
3914
4053
  }
3915
4054
  try {
3916
4055
  if (!(await queueWait(api, cred, ask, f.queue, signal, deadline, siteOf(site, cred))))
3917
- 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)
4056
+ return giveUp(errorResponse(ask.stuck ? { ...f, message: `${f.message} (the queue hasn't moved in ${Math.round(QUEUE.stuck / 60_000)} minutes with nothing ahead)` } : f))
3918
4057
  } catch (e) {
3919
- return errorResponse({ status: 502, message: e?.message ?? String(e) })
4058
+ return giveUp(errorResponse({ status: 502, message: e?.message ?? String(e) }))
3920
4059
  }
3921
4060
  waited++
3922
4061
  }
3923
4062
  }
3924
- const done = run().catch((e) => errorResponse({ status: 502, message: e?.message ?? String(e) }))
4063
+ task.inflight = (task.inflight ?? 0) + 1
4064
+ const done = run()
4065
+ .catch((e) => errorResponse({ status: 502, message: e?.message ?? String(e) }))
4066
+ .finally(() => {
4067
+ if (--task.inflight === 0 && task.ended) void release(task)
4068
+ })
3925
4069
  const res = await Promise.race([done, heard])
3926
4070
  if (res !== held?.response) return res
3927
4071
  held.follow(done)
@@ -4300,4 +4444,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
4300
4444
  export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
4301
4445
 
4302
4446
  // for tests
4303
- 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, asAgentSDK, harnessComma, qoderMessages, kimiModel, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState }
4447
+ 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, asAgentSDK, harnessComma, qoderMessages, kimiModel, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState, queueReady }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.73",
3
+ "version": "0.2.75",
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",