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

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 +7 -0
  2. package/index.mjs +38 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -153,6 +153,13 @@ itself.
153
153
  reasoning and usage.
154
154
  - Tool calls Qoder writes as XML or JSON in its text become tool calls.
155
155
  Tool calls it sends the OpenAI way keep Qoder's id.
156
+ - A call sent the OpenAI way that never gets its function name is never
157
+ sent on, and its arguments go nowhere (since 0.2.51, #579). If nothing
158
+ of the answer came before it, the request is sent once more; a second
159
+ such reply is a 502 that magpie can retry or fail over. If the answer
160
+ had begun (text, reasoning or a named call), the unnamed call is dropped
161
+ and the answer ends as it would have without it (`tool_calls` beside a
162
+ named call, `stop` otherwise), with a warning in magpie's log.
156
163
  - A call written in the text that can't be read, or that the stream ends
157
164
  inside, is never sent on as the answer (since 0.2.16, #132): the turn
158
165
  ends as an error, a 502 or the stream's error frame with no finish, so
package/index.mjs CHANGED
@@ -1711,6 +1711,9 @@ async function* events(body, tools = []) {
1711
1711
  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
1712
  let usage
1713
1713
  let fr = ""
1714
+ // said: something of the answer has been given (text, reasoning or a
1715
+ // call), which a client may already show
1716
+ let said = false
1714
1717
  for await (const line of sseLines(body)) {
1715
1718
  if (!line.startsWith("data:")) continue
1716
1719
  const payload = line.slice(5).trim()
@@ -1733,13 +1736,17 @@ async function* events(body, tools = []) {
1733
1736
  continue
1734
1737
  }
1735
1738
  const delta = chunk?.choices?.[0]?.delta ?? {}
1736
- if (delta.reasoning_content) yield { reasoning: delta.reasoning_content }
1739
+ if (delta.reasoning_content) {
1740
+ said = true
1741
+ yield { reasoning: delta.reasoning_content }
1742
+ }
1737
1743
  if (typeof delta.content === "string")
1738
1744
  for (const f of a.feed(delta.content)) {
1739
1745
  if (!f.call && !f.error && !f.text) continue
1740
1746
  const e = piece(f)
1741
1747
  yield e
1742
1748
  if (e.error) return
1749
+ said = true
1743
1750
  }
1744
1751
  // tool calls served the OpenAI way keep Qoder's id: a result answers it
1745
1752
  for (const tc of delta.tool_calls ?? []) {
@@ -1763,7 +1770,7 @@ async function* events(body, tools = []) {
1763
1770
  yield e
1764
1771
  if (e.error) return
1765
1772
  }
1766
- a.sawTool = true
1773
+ a.sawTool = said = true
1767
1774
  call.index = ++index
1768
1775
  yield { tool: { index: call.index, id: call.id || "call_" + hexID(), name, args: call.args } }
1769
1776
  } else if (args) yield { args: { index: call.index, text: args } }
@@ -1786,14 +1793,31 @@ async function* events(body, tools = []) {
1786
1793
  const e = piece(f)
1787
1794
  yield e
1788
1795
  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" } }
1796
+ said = true
1797
+ }
1798
+ // A native call the model began and never named is never given: a
1799
+ // client keeps an unnamed tool in its history and other providers
1800
+ // refuse it. Its arguments, held while it waited for the name, go
1801
+ // nowhere, not into the text either. With nothing said before it, the
1802
+ // reply is no answer: a 502 (nameless) that ask sends once more, then
1803
+ // the gateway's to retry or fail over. After an answer began, the call
1804
+ // is dropped and the answer ends as it would have without it, so the
1805
+ // text, reasoning and named calls already given are kept: qoder-cn's
1806
+ // qfmodel did this now and then, and the whole turn failed with an
1807
+ // error the client didn't retry (plugins#579).
1808
+ const nameless = [...native.values()].filter((call) => call.index === undefined).length
1809
+ if (nameless && !said) {
1810
+ yield { error: { status: 502, message: NAMELESS, nameless: true } }
1792
1811
  return
1793
1812
  }
1813
+ if (nameless) console.warn(`qoder: dropped ${nameless} native tool call${nameless > 1 ? "s" : ""} the model never named (plugins#579)`)
1794
1814
  yield { stop: a.sawTool ? "tool_calls" : fr === "length" ? "length" : "stop", usage }
1795
1815
  }
1796
1816
 
1817
+ // NAMELESS is the error of a reply whose only answer was a native tool
1818
+ // call the model never named.
1819
+ const NAMELESS = "the model's native tool call has no name; it is not sent on as a tool"
1820
+
1797
1821
  // answer turns Qoder's reply into the chat completion OpenAI's API gives.
1798
1822
  // A failure before the answer keeps its status; one after it ends the
1799
1823
  // stream with an error.
@@ -2880,6 +2904,7 @@ const makePlugin = (site) => async ({ client }) => {
2880
2904
  asked.cred = cred
2881
2905
  let m
2882
2906
  let relogged = false
2907
+ let renamed = false
2883
2908
  const listed = (ms) => ms.find((x) => x.key === chat.model)
2884
2909
  try {
2885
2910
  m = listed(await models(cred)) ?? listed(await models(cred, true))
@@ -2954,6 +2979,14 @@ const makePlugin = (site) => async ({ client }) => {
2954
2979
  continue
2955
2980
  }
2956
2981
  }
2982
+ // a reply whose only answer was a native tool call the model never
2983
+ // named (plugins#579): nothing of it was given, so it is asked once
2984
+ // more, under a new request_id; a second one is the gateway's 502 to
2985
+ // retry or fail over
2986
+ if (f?.nameless && !renamed) {
2987
+ renamed = true
2988
+ continue
2989
+ }
2957
2990
  // an answered call moves its task on, as Qoder's client moves it
2958
2991
  if (!f) task.answered = true
2959
2992
  // with another account, provider or group member after this one
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.51",
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",