@magpie-community/opencode-qoder-auth 0.2.68 → 0.2.70
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/index.mjs +32 -4
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1200,7 +1200,18 @@ function reasoningOf(m) {
|
|
|
1200
1200
|
// thinking before the call said, and said it had none without it. A turn
|
|
1201
1201
|
// with thinking and nothing else is still left out, as that client leaves
|
|
1202
1202
|
// it.
|
|
1203
|
-
|
|
1203
|
+
// Kimi on QwenWork (kimi-k3.1-pro) answers 400 "Error in upstream response"
|
|
1204
|
+
// to an assistant turn with tool_calls and an empty content, which is how
|
|
1205
|
+
// every OpenAI client records a call-only turn (nanfei892, #1213: 9-token
|
|
1206
|
+
// bodies, DeepSeek, GLM and Qwen on the same account fine, " " served).
|
|
1207
|
+
// QwenWork's own client always writes text beside a call. A Kimi model's
|
|
1208
|
+
// call-only turn carries one space; other models get the turn as written.
|
|
1209
|
+
function kimiModel(m) {
|
|
1210
|
+
const key = String(m?.key ?? "")
|
|
1211
|
+
return /^kmodel/i.test(key) || /kimi/i.test(key + " " + (m?.config?.display_name ?? "") + " " + (m?.name ?? ""))
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
function qoderMessages(msgs, opts = {}) {
|
|
1204
1215
|
const out = []
|
|
1205
1216
|
const names = {}
|
|
1206
1217
|
let seen = []
|
|
@@ -1259,7 +1270,7 @@ function qoderMessages(msgs) {
|
|
|
1259
1270
|
return { id, type: "function", function: { name: c.function?.name, arguments: typeof args === "string" ? args : JSON.stringify(args ?? {}) } }
|
|
1260
1271
|
})
|
|
1261
1272
|
const think = reasoningOf(m)
|
|
1262
|
-
out.push({ role: "assistant", content: textOf(m.content), ...(think ? { reasoning_content: think } : {}), tool_calls: calls })
|
|
1273
|
+
out.push({ role: "assistant", content: textOf(m.content) || (opts.callText ?? ""), ...(think ? { reasoning_content: think } : {}), tool_calls: calls })
|
|
1263
1274
|
const open = calls.map((c) => c.id)
|
|
1264
1275
|
const kept = new Set()
|
|
1265
1276
|
for (let j = i + 1; j < msgs.length && msgs[j].role === "tool"; j++) {
|
|
@@ -1522,7 +1533,7 @@ function qoderBody(chat, m, named = "", task, site) {
|
|
|
1522
1533
|
session_type: site?.sessionType ?? "app",
|
|
1523
1534
|
model_config: modelConfig(m, thinking),
|
|
1524
1535
|
system: [sys],
|
|
1525
|
-
messages: [{ role: "system", content: [sys] }, ...cacheMarked(qoderMessages(chat.messages ?? []))],
|
|
1536
|
+
messages: [{ role: "system", content: [sys] }, ...cacheMarked(qoderMessages(chat.messages ?? [], { callText: kimiModel(m) ? " " : "" }))],
|
|
1526
1537
|
}
|
|
1527
1538
|
if (tools.length)
|
|
1528
1539
|
body.tools = tools.map((t) => ({
|
|
@@ -1718,6 +1729,12 @@ const QUEUE = {
|
|
|
1718
1729
|
recoveries: 10, // the queue waited out this many times, at most, for one request
|
|
1719
1730
|
failures: 3, // status asks failing in a row that end the wait
|
|
1720
1731
|
ask: 30_000, // the longest one status ask may take
|
|
1732
|
+
// the longest a call waits for Qoder's first event (headers included).
|
|
1733
|
+
// Qoder CN once held a call 15 minutes with nothing sent and nothing to
|
|
1734
|
+
// log (#1204); after this it is a 504 that says so, which magpie can
|
|
1735
|
+
// fail over from. A queued call answers its 10605 at once, and a
|
|
1736
|
+
// thinking model streams its reasoning, so a real answer starts sooner.
|
|
1737
|
+
silent: 120_000,
|
|
1721
1738
|
now: () => Date.now(),
|
|
1722
1739
|
// every calls fn each ms until the returned stop is called
|
|
1723
1740
|
every: (fn, ms) => {
|
|
@@ -3781,11 +3798,22 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3781
3798
|
const call = new AbortController()
|
|
3782
3799
|
const callSignal = signal ? AbortSignal.any([signal, call.signal]) : call.signal
|
|
3783
3800
|
let res, open
|
|
3801
|
+
let silent = false
|
|
3802
|
+
const hush = setTimeout(() => {
|
|
3803
|
+
silent = true
|
|
3804
|
+
call.abort()
|
|
3805
|
+
}, QUEUE.silent)
|
|
3784
3806
|
try {
|
|
3785
3807
|
res = await fetch(CHAT_URL, { method: "POST", headers, body: wire, signal: callSignal })
|
|
3786
3808
|
if (res.ok) open = await opened(res, chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function") : [])
|
|
3787
3809
|
} catch (e) {
|
|
3810
|
+
if (silent) {
|
|
3811
|
+
const who = siteOf(site, cred).name ?? "Qoder"
|
|
3812
|
+
return errorResponse({ status: 504, message: `${who} sent nothing for ${Math.round(QUEUE.silent / 1000)}s after the request (${res ? "no first event" : "no reply headers"}); the call was dropped`, signIn: "" })
|
|
3813
|
+
}
|
|
3788
3814
|
return errorResponse({ status: 502, message: e.message })
|
|
3815
|
+
} finally {
|
|
3816
|
+
clearTimeout(hush)
|
|
3789
3817
|
}
|
|
3790
3818
|
const f = !res.ok ? failure(res.status, (await res.text()).slice(0, 1 << 20)) : open.first.value?.error
|
|
3791
3819
|
if (f) call.abort()
|
|
@@ -4216,4 +4244,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
4216
4244
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
4217
4245
|
|
|
4218
4246
|
// for tests
|
|
4219
|
-
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, qoderMessages, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState }
|
|
4247
|
+
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, qoderMessages, kimiModel, 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.70",
|
|
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",
|