@magpie-community/opencode-qoder-auth 0.2.50 → 0.2.52

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 +13 -0
  2. package/index.mjs +82 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -83,6 +83,12 @@ Refreshing:
83
83
  full, the listing can have only the free models on (#484). The same
84
84
  5-minute rule holds, and an id Qoder has never served is said unknown at
85
85
  once, with no renewal.
86
+ - The account's model list (what magpie and its agents see) is read the
87
+ same way (since 0.2.52): a listing with every model that costs credits
88
+ off and the free ones on, which is what Qoder CN answers a caller it
89
+ doesn't take for the account, renews the job token once and is read
90
+ again. A renewed token that still lists only the free models isn't
91
+ renewed again for the list.
86
92
  - The device token, which reads usage, has no end on record: it is rotated
87
93
  when Qoder refuses it. On a [Qoder CN](#qoder-cn) device-token account it
88
94
  is the chat token too, and is renewed as above.
@@ -153,6 +159,13 @@ itself.
153
159
  reasoning and usage.
154
160
  - Tool calls Qoder writes as XML or JSON in its text become tool calls.
155
161
  Tool calls it sends the OpenAI way keep Qoder's id.
162
+ - A call sent the OpenAI way that never gets its function name is never
163
+ sent on, and its arguments go nowhere (since 0.2.51, #579). If nothing
164
+ of the answer came before it, the request is sent once more; a second
165
+ such reply is a 502 that magpie can retry or fail over. If the answer
166
+ had begun (text, reasoning or a named call), the unnamed call is dropped
167
+ and the answer ends as it would have without it (`tool_calls` beside a
168
+ named call, `stop` otherwise), with a warning in magpie's log.
156
169
  - A call written in the text that can't be read, or that the stream ends
157
170
  inside, is never sent on as the answer (since 0.2.16, #132): the turn
158
171
  ends as an error, a 502 or the stream's error frame with no finish, so
package/index.mjs CHANGED
@@ -681,6 +681,23 @@ function sceneModels(listing) {
681
681
  // and "default" route inside Qoder and aren't one model. A site with its
682
682
  // own scene reads that scene's list; one that lists all models keeps the
683
683
  // disabled ones too (QwenWork's qwork scene carries its whole catalog).
684
+ // freeView is whether a listing is the one Qoder gives a caller it doesn't
685
+ // take for the account: every model that costs credits off, the free ones
686
+ // on. Qoder CN's gateway answers a caller it doesn't know with that list
687
+ // (2026-11-01: Qwen3.8-Flash on, Auto, Fast, Qwen3.8-Max, DeepSeek, GLM,
688
+ // Kimi and MiniMax off, in every scene), and an enterprise qoder.com
689
+ // account's stale job token was answered the same (plugins#484). A listing
690
+ // with no model that costs credits, or with one of them on, isn't it.
691
+ function freeView(entries) {
692
+ let off = false
693
+ for (const m of entries) {
694
+ if (!m || ["", "auto", "default"].includes(String(m.key ?? "").trim()) || freeOf(m)) continue
695
+ if (m.enable) return false
696
+ off = true
697
+ }
698
+ return off
699
+ }
700
+
684
701
  function modelInfos(listing, site) {
685
702
  if (site?.modelScene) {
686
703
  return (Array.isArray(listing?.[site.modelScene]) ? listing[site.modelScene] : [])
@@ -1711,6 +1728,9 @@ async function* events(body, tools = []) {
1711
1728
  f.call ? { tool: { index: ++index, id: "call_" + hexID(), name: f.call.name, args: f.call.args } } : f.error ? { error: { status: 502, message: f.error } } : { text: f.text }
1712
1729
  let usage
1713
1730
  let fr = ""
1731
+ // said: something of the answer has been given (text, reasoning or a
1732
+ // call), which a client may already show
1733
+ let said = false
1714
1734
  for await (const line of sseLines(body)) {
1715
1735
  if (!line.startsWith("data:")) continue
1716
1736
  const payload = line.slice(5).trim()
@@ -1733,13 +1753,17 @@ async function* events(body, tools = []) {
1733
1753
  continue
1734
1754
  }
1735
1755
  const delta = chunk?.choices?.[0]?.delta ?? {}
1736
- if (delta.reasoning_content) yield { reasoning: delta.reasoning_content }
1756
+ if (delta.reasoning_content) {
1757
+ said = true
1758
+ yield { reasoning: delta.reasoning_content }
1759
+ }
1737
1760
  if (typeof delta.content === "string")
1738
1761
  for (const f of a.feed(delta.content)) {
1739
1762
  if (!f.call && !f.error && !f.text) continue
1740
1763
  const e = piece(f)
1741
1764
  yield e
1742
1765
  if (e.error) return
1766
+ said = true
1743
1767
  }
1744
1768
  // tool calls served the OpenAI way keep Qoder's id: a result answers it
1745
1769
  for (const tc of delta.tool_calls ?? []) {
@@ -1763,7 +1787,7 @@ async function* events(body, tools = []) {
1763
1787
  yield e
1764
1788
  if (e.error) return
1765
1789
  }
1766
- a.sawTool = true
1790
+ a.sawTool = said = true
1767
1791
  call.index = ++index
1768
1792
  yield { tool: { index: call.index, id: call.id || "call_" + hexID(), name, args: call.args } }
1769
1793
  } else if (args) yield { args: { index: call.index, text: args } }
@@ -1786,14 +1810,31 @@ async function* events(body, tools = []) {
1786
1810
  const e = piece(f)
1787
1811
  yield e
1788
1812
  if (e.error) return
1789
- }
1790
- if ([...native.values()].some((call) => call.index === undefined)) {
1791
- yield { error: { status: 502, message: "the model's native tool call has no name; it is not sent on as a tool" } }
1813
+ said = true
1814
+ }
1815
+ // A native call the model began and never named is never given: a
1816
+ // client keeps an unnamed tool in its history and other providers
1817
+ // refuse it. Its arguments, held while it waited for the name, go
1818
+ // nowhere, not into the text either. With nothing said before it, the
1819
+ // reply is no answer: a 502 (nameless) that ask sends once more, then
1820
+ // the gateway's to retry or fail over. After an answer began, the call
1821
+ // is dropped and the answer ends as it would have without it, so the
1822
+ // text, reasoning and named calls already given are kept: qoder-cn's
1823
+ // qfmodel did this now and then, and the whole turn failed with an
1824
+ // error the client didn't retry (plugins#579).
1825
+ const nameless = [...native.values()].filter((call) => call.index === undefined).length
1826
+ if (nameless && !said) {
1827
+ yield { error: { status: 502, message: NAMELESS, nameless: true } }
1792
1828
  return
1793
1829
  }
1830
+ if (nameless) console.warn(`qoder: dropped ${nameless} native tool call${nameless > 1 ? "s" : ""} the model never named (plugins#579)`)
1794
1831
  yield { stop: a.sawTool ? "tool_calls" : fr === "length" ? "length" : "stop", usage }
1795
1832
  }
1796
1833
 
1834
+ // NAMELESS is the error of a reply whose only answer was a native tool
1835
+ // call the model never named.
1836
+ const NAMELESS = "the model's native tool call has no name; it is not sent on as a tool"
1837
+
1797
1838
  // answer turns Qoder's reply into the chat completion OpenAI's API gives.
1798
1839
  // A failure before the answer keeps its status; one after it ends the
1799
1840
  // stream with an error.
@@ -2629,6 +2670,8 @@ const makePlugin = (site) => async ({ client }) => {
2629
2670
  // the ids Qoder serves: the site's shipped list and every key a listing
2630
2671
  // has named, on or off
2631
2672
  const served = new Set(site.models.map((m) => m.id))
2673
+ // the job tokens a renewal gave that Qoder still listed the free view for
2674
+ const stillFree = new Set()
2632
2675
  const knows = (id) => served.has(id)
2633
2676
  const models = async (cred, again = false) => {
2634
2677
  const key = listingKey(cred)
@@ -2641,6 +2684,7 @@ const makePlugin = (site) => async ({ client }) => {
2641
2684
  if (k) served.add(k)
2642
2685
  }
2643
2686
  l = modelInfos(listing, s)
2687
+ if (!s.modelScene) l.freeView = freeView(sceneModels(listing))
2644
2688
  listings.set(key, l)
2645
2689
  }
2646
2690
  return l
@@ -2880,6 +2924,7 @@ const makePlugin = (site) => async ({ client }) => {
2880
2924
  asked.cred = cred
2881
2925
  let m
2882
2926
  let relogged = false
2927
+ let renamed = false
2883
2928
  const listed = (ms) => ms.find((x) => x.key === chat.model)
2884
2929
  try {
2885
2930
  m = listed(await models(cred)) ?? listed(await models(cred, true))
@@ -2954,6 +2999,14 @@ const makePlugin = (site) => async ({ client }) => {
2954
2999
  continue
2955
3000
  }
2956
3001
  }
3002
+ // a reply whose only answer was a native tool call the model never
3003
+ // named (plugins#579): nothing of it was given, so it is asked once
3004
+ // more, under a new request_id; a second one is the gateway's 502 to
3005
+ // retry or fail over
3006
+ if (f?.nameless && !renamed) {
3007
+ renamed = true
3008
+ continue
3009
+ }
2957
3010
  // an answered call moves its task on, as Qoder's client moves it
2958
3011
  if (!f) task.answered = true
2959
3012
  // with another account, provider or group member after this one
@@ -3150,7 +3203,29 @@ const makePlugin = (site) => async ({ client }) => {
3150
3203
  }
3151
3204
  if (renewals.has(cred)) unsaid.add(listingKey(cred))
3152
3205
  try {
3153
- const ms = await models(cred, true)
3206
+ let ms = await models(cred, true)
3207
+ // The free view (freeView) on a job token is what Qoder lists for
3208
+ // a token it no longer takes in full: the token is renewed once,
3209
+ // as a chat for a model the list has off renews it (plugins#484),
3210
+ // and the list read again. Without it the account's list is the
3211
+ // free model alone, and magpie's agents see only that one (Qoder
3212
+ // CN, star21321321124_93024 on Discord, 2026-11-01). A token the
3213
+ // free view came back on after a renewal is not renewed again for
3214
+ // it: that account lists only the free models.
3215
+ if (ms.freeView && !stillFree.has(cred.access)) {
3216
+ let next
3217
+ try {
3218
+ next = await relogin(async () => auth, cred.access)
3219
+ } catch (e) {
3220
+ if (e?.expired) throw Object.assign(new Error(e.message), { signIn: "expired" })
3221
+ }
3222
+ if (next && next.access !== cred.access) {
3223
+ if (renewals.has(next)) unsaid.add(listingKey(next))
3224
+ cred = next
3225
+ ms = await models(cred, true)
3226
+ if (ms.freeView) stillFree.add(cred.access)
3227
+ }
3228
+ }
3154
3229
  if (!ms.length) return provider.models
3155
3230
  const s = siteOf(site, cred)
3156
3231
  return Object.fromEntries(
@@ -3227,4 +3302,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
3227
3302
  export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
3228
3303
 
3229
3304
  // for tests
3230
- export const _internal = { maskPhone, phoneLabelOf, realEmailOf, chatHeaders, machineOS, machineHostname, cosyHeaders, typedUnions, Splitter, campaignRuntime, RUNTIMES, campaignPage, campaignTarget, vpcInstance, vpcSite, parseUsage, gfmt, when, failure, modelInfo, qoderBody, qoderMessages, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState }
3305
+ export const _internal = { freeView, maskPhone, phoneLabelOf, realEmailOf, chatHeaders, machineOS, machineHostname, cosyHeaders, typedUnions, Splitter, campaignRuntime, RUNTIMES, campaignPage, campaignTarget, vpcInstance, vpcSite, 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.50",
3
+ "version": "0.2.52",
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",