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

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 (2) hide show
  1. package/index.mjs +42 -4
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -2672,9 +2672,25 @@ const NAMELESS = "the model's native tool call has no name; it is not sent on as
2672
2672
  // opened is a chat reply's events and the first of them, read before
2673
2673
  // anything is answered: a refusal in the stream (Qoder's queue among them)
2674
2674
  // comes first.
2675
- async function opened(res, tools) {
2676
- const it = events(res.body, tools)
2677
- return { it, first: await it.next() }
2675
+ async function opened(res, tools, onReader) {
2676
+ const reader = res.body.getReader()
2677
+ onReader?.(reader)
2678
+ const body = async function* () {
2679
+ while (true) {
2680
+ const { done, value } = await reader.read()
2681
+ if (done) {
2682
+ return
2683
+ }
2684
+ yield value
2685
+ }
2686
+ }()
2687
+ const it = events(body, tools)
2688
+ try {
2689
+ const first = await it.next()
2690
+ return { it, first }
2691
+ } finally {
2692
+ onReader?.(undefined)
2693
+ }
2678
2694
  }
2679
2695
 
2680
2696
  async function answer({ it, first }, chat, servedName = chat.model) {
@@ -3972,13 +3988,28 @@ const makePlugin = (site) => async ({ client }) => {
3972
3988
  const callSignal = signal ? AbortSignal.any([signal, call.signal]) : call.signal
3973
3989
  let res, open
3974
3990
  let silent = false
3991
+ let pendingRead
3975
3992
  const hush = setTimeout(() => {
3976
3993
  silent = true
3977
3994
  call.abort()
3995
+ pendingRead?.cancel().catch(() => {})
3978
3996
  }, QUEUE.silent)
3979
3997
  try {
3980
3998
  res = await fetch(CHAT_URL, { method: "POST", headers, body: wire, signal: callSignal })
3981
- if (res.ok) open = await opened(res, chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function") : [])
3999
+ if (silent)
4000
+ return errorResponse({
4001
+ status: 504,
4002
+ message: `${siteOf(site, cred).name ?? "Qoder"} sent nothing for ${Math.round(QUEUE.silent / 1000)}s after the request (no first event); the call was dropped`,
4003
+ signIn: "",
4004
+ })
4005
+ if (res.ok)
4006
+ open = await opened(
4007
+ res,
4008
+ chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function") : [],
4009
+ (reader) => {
4010
+ pendingRead = reader
4011
+ },
4012
+ )
3982
4013
  } catch (e) {
3983
4014
  if (silent) {
3984
4015
  const who = siteOf(site, cred).name ?? "Qoder"
@@ -3987,7 +4018,14 @@ const makePlugin = (site) => async ({ client }) => {
3987
4018
  return errorResponse({ status: 502, message: e.message })
3988
4019
  } finally {
3989
4020
  clearTimeout(hush)
4021
+ pendingRead = undefined
3990
4022
  }
4023
+ if (silent)
4024
+ return errorResponse({
4025
+ status: 504,
4026
+ message: `${siteOf(site, cred).name ?? "Qoder"} sent nothing for ${Math.round(QUEUE.silent / 1000)}s after the request (no first event); the call was dropped`,
4027
+ signIn: "",
4028
+ })
3991
4029
  const f = !res.ok ? failure(res.status, (await res.text()).slice(0, 1 << 20)) : open.first.value?.error
3992
4030
  if (f) call.abort()
3993
4031
  // a refused job token: renewed once (or the one renewed meanwhile)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.75",
3
+ "version": "0.2.76",
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",