@magpie-community/opencode-qoder-auth 0.2.80 → 0.2.82
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/README.md +7 -1
- package/index.mjs +42 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -121,6 +121,11 @@ itself.
|
|
|
121
121
|
two sentences, `You are ZCode. You are an interactive agent` (since
|
|
122
122
|
0.2.79, #1667): Qoder CN parks a request with the name and comma as
|
|
123
123
|
written in the same queue. Qoder's own names stay as they are.
|
|
124
|
+
- Kimi Code's identity line, `You are Kimi Code, an interactive general AI
|
|
125
|
+
agent running on a user's computer.`, goes as `You are a coding agent, ...`
|
|
126
|
+
(since 0.2.81): Qoder CN puts a request whose system prompt opens with
|
|
127
|
+
that line in the same 10605 / p2 / `RESOURCE_LIMIT` queue. The rest of the
|
|
128
|
+
prompt and your messages go as written.
|
|
124
129
|
- Messages become text and image blocks.
|
|
125
130
|
- Tool calls and results become OpenAI tool turns. Images a tool returned
|
|
126
131
|
follow in a user turn.
|
|
@@ -210,7 +215,8 @@ itself.
|
|
|
210
215
|
| A quota (codes 110, 112–119, 122) | 429 |
|
|
211
216
|
| A model the account's listing has off while its usage says no credits are left (since 0.2.64, #880) | 429 usage limit reached, with the credits used and the model; a model off with credits left, or whose usage can't be read, stays 400 `unknown or disabled model`, and an id Qoder never served is that 400 at once |
|
|
212
217
|
| Busy or queued for the model (code 10605) | Since 0.2.28 the request waits in Qoder's queue as Qoder's client does (below), then is sent again; since 0.2.62 a streamed request is answered 200 at once and kept alive with SSE comments for up to an hour (since 0.2.71, 5 minutes when the queue hasn't moved with nothing ahead), its outcome in the stream; past the wait, 503 with `Retry-After` from Qoder's `retryAfterSeconds` (30s when it gives none). Since 0.2.40, when magpie has another candidate after this request (`x-magpie-fallback: 1`), the 503 comes at once, saying the queue and how many are ahead, and magpie asks the next. The sign-in is untouched |
|
|
213
|
-
|
|
|
218
|
+
| Qoder's content safety check refusing the conversation (an HTTP 406 such as "Session blocked, Please clear context try again", or code 406) | Since 0.2.82, 400 with error type `content_filter` and code 406, Qoder's words first: magpie reads it as a refusal of the content, asks the next candidate as its refusal setting allows, and rests no account. The plugin asks Qoder once, and the sign-in is untouched |
|
|
219
|
+
| A refusal of the request itself (codes 416, 430, 80411, 80412, 100400–100403) | 400, with Qoder's words |
|
|
214
220
|
| "Error in upstream response", the model's own vendor behind Qoder failing, which Qoder sends as a 400 (since 0.2.24) | 502, so magpie asks again or another account; the sign-in is untouched |
|
|
215
221
|
| "Range of max_tokens should be [1, N]" behind "Error in upstream response" (since 0.2.63) | Asked again once with max_tokens N, which later requests for that model are sent from the start; refused again, 400 with Qoder's words, the sign-in untouched. QoDuck (`lmodel`) is never sent more than 131072, and a model whose listing entry names `max_output_tokens` never more than that; a smaller max_tokens goes as asked |
|
|
216
222
|
| A failure before the answer starts | Qoder's status |
|
package/index.mjs
CHANGED
|
@@ -113,6 +113,17 @@ const asAgentSDK = (text) => text.replace(CLAUDE_CODE_LINE, AGENT_SDK_LINE)
|
|
|
113
113
|
const HARNESS_OPENER = /(\bYou are (?:an?|the)\s[^\n.,]{0,60}?\b(?:agent|assistant))\s+(powered by|running on|running in|built on|based on)\b/gi
|
|
114
114
|
const harnessComma = (text) => text.replace(HARNESS_OPENER, "$1, $2")
|
|
115
115
|
|
|
116
|
+
// Qoder CN queues a request whose system prompt opens with Kimi Code's
|
|
117
|
+
// identity, "You are Kimi Code, an interactive general AI agent running on a
|
|
118
|
+
// user's computer.", in the same 10605 / p2 / RESOURCE_LIMIT hold as the
|
|
119
|
+
// DeepSeek Harness opener above: queueCount 0, serviceAvailable false, and
|
|
120
|
+
// the queue never moves. Kimi Code Desktop sends exactly that line (its
|
|
121
|
+
// profile.bind systemPrompt), so a Kimi K3.1 Pro call through Qoder CN never
|
|
122
|
+
// starts; the same request with a neutral opening answers at once. The match
|
|
123
|
+
// is the identity at the start of a line only, so later mentions of Kimi Code
|
|
124
|
+
// stay, and the user's own messages go as written.
|
|
125
|
+
const KIMI_CODE_OPENER = /(^|\n)([ \t]*)You\s+are\s+Kimi(?:\s+Code)?\b/gi
|
|
126
|
+
const neutralKimi = (text) => text.replace(KIMI_CODE_OPENER, "$1$2You are a coding agent")
|
|
116
127
|
// Qoder CN parks a request in the same never-moving 10605 queue when its
|
|
117
128
|
// system prompt holds another agent's name, as written, then a comma: "You
|
|
118
129
|
// are ZCode, an interactive agent" (every ZCode request) and "You are
|
|
@@ -1607,7 +1618,7 @@ const APP_CHAT = { stream: true, chat_task: "FREE_INPUT", is_reply: true, is_ret
|
|
|
1607
1618
|
// passes itself last.
|
|
1608
1619
|
function qoderBody(chat, m, named = "", task, site) {
|
|
1609
1620
|
const given = (chat.messages ?? []).filter((x) => x.role === "system" || x.role === "developer").map((x) => textOf(x.content)).filter(Boolean).join("\n\n")
|
|
1610
|
-
const system = nameAlone(harnessComma(asAgentSDK(given)))
|
|
1621
|
+
const system = nameAlone(harnessComma(asAgentSDK(neutralKimi(given))))
|
|
1611
1622
|
const tools = chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function" && t.function?.name) : []
|
|
1612
1623
|
const baseSystem = site?.systemPrompt ?? QODER_SYS
|
|
1613
1624
|
let sysText = system ? baseSystem + "\n\n" + system : baseSystem
|
|
@@ -1697,6 +1708,18 @@ const QUOTA_CODES = new Set(["110", "112", "113", "114", "115", "116", "117", "1
|
|
|
1697
1708
|
// refusals of this request, not of the account: sensitive content, not
|
|
1698
1709
|
// supported, input too long, too many media, a custom model's service
|
|
1699
1710
|
const REQUEST_CODES = new Set(["406", "416", "430", "80411", "80412", "100400", "100401", "100403"])
|
|
1711
|
+
// SENSITIVE is Qoder's content safety check refusing the conversation: its
|
|
1712
|
+
// code 406, or an HTTP 406 whose body names no other code of Qoder's
|
|
1713
|
+
// ("Session blocked, Please clear context try again"). Qwen Code, Qoder's
|
|
1714
|
+
// own CLI on the same backend, reads an HTTP 406 as content filtered
|
|
1715
|
+
// (errorPresentation.ts, CONTENT_FILTERED_MESSAGE), and its maintainers
|
|
1716
|
+
// confirm it is a content-safety rejection that asking again in the same
|
|
1717
|
+
// conversation doesn't clear (QwenLM/qwen-code#16915). It goes to magpie
|
|
1718
|
+
// as its content_filter convention (plugins#1264): a 400 whose error type
|
|
1719
|
+
// is content_filter, Qoder's 406 kept as the code, so magpie's routing
|
|
1720
|
+
// decides whether another candidate is asked (its RefusalRetries) and
|
|
1721
|
+
// rests no account; as a plain 400 or 406 the group ended at it.
|
|
1722
|
+
const SENSITIVE = "406"
|
|
1700
1723
|
const BUSY_WAIT = 30
|
|
1701
1724
|
// UPSTREAM_FAILED is Qoder saying the model's own vendor behind it failed:
|
|
1702
1725
|
// "Error in upstream response", which Qoder sends as a 400 (SlouchyQuill507
|
|
@@ -1751,6 +1774,14 @@ function failure(status, text) {
|
|
|
1751
1774
|
return { status: 503, message: `Qoder ${what}${model}${tier}; try again in ${wait}s`, retryAfter: wait, signIn: "", queue: queue ?? {} }
|
|
1752
1775
|
}
|
|
1753
1776
|
if (QUOTA_CODES.has(code)) return { status: 429, message: "usage limit reached: " + msg, signIn: "" }
|
|
1777
|
+
if (code === SENSITIVE || (status === 406 && !/^\d+$/.test(code)))
|
|
1778
|
+
return {
|
|
1779
|
+
status: 400,
|
|
1780
|
+
message: `${msg} — Qoder's content safety check refused this conversation (406); sent again with the same history it is refused again, so start a new conversation`,
|
|
1781
|
+
signIn: "",
|
|
1782
|
+
type: "content_filter",
|
|
1783
|
+
code: 406,
|
|
1784
|
+
}
|
|
1754
1785
|
if (REQUEST_CODES.has(code)) return { status: 400, message: `Qoder refused the request (${code}): ${msg}`, signIn: "" }
|
|
1755
1786
|
// a max_tokens above the model's ceiling, said behind "Error in upstream
|
|
1756
1787
|
// response": the request's fault on every account, so a 400 that rests
|
|
@@ -1784,9 +1815,11 @@ function failure(status, text) {
|
|
|
1784
1815
|
// errorResponse is a failure as OpenAI's API gives it. signIn is what it
|
|
1785
1816
|
// means for the account (magpie's X-Magpie-Sign-In): a 401 keeps it unless
|
|
1786
1817
|
// told expired, since the built-in marked only a refused refresh. retryAfter
|
|
1787
|
-
// (seconds) is sent as Retry-After.
|
|
1788
|
-
|
|
1789
|
-
|
|
1818
|
+
// (seconds) is sent as Retry-After. type and code, when failure names them
|
|
1819
|
+
// (a content refusal's content_filter and 406), go in place of qoder_error
|
|
1820
|
+
// and the status.
|
|
1821
|
+
const errorResponse = ({ status, message, signIn = status === 401 ? "kept" : undefined, retryAfter, type = "qoder_error", code = status }) =>
|
|
1822
|
+
new Response(JSON.stringify({ error: { message, type, code } }), {
|
|
1790
1823
|
status,
|
|
1791
1824
|
headers: {
|
|
1792
1825
|
"Content-Type": "application/json",
|
|
@@ -2789,7 +2822,10 @@ async function answer({ it, first }, chat, servedName = chat.model) {
|
|
|
2789
2822
|
else if (e.args) ctl.enqueue(chunk({ tool_calls: [{ index: e.args.index, function: { arguments: e.args.text } }] }))
|
|
2790
2823
|
else if (e.stop) ctl.enqueue(chunk({}, e.stop, e.usage ? { usage: e.usage } : {}))
|
|
2791
2824
|
else if (e.error) {
|
|
2792
|
-
|
|
2825
|
+
// a content refusal says its type here too; magpie replays nothing
|
|
2826
|
+
// once the answer has begun
|
|
2827
|
+
const { message, status, type, code = status } = e.error
|
|
2828
|
+
ctl.enqueue(enc.encode(`data: ${JSON.stringify({ error: { message, ...(type ? { type } : {}), code } })}\n\n`))
|
|
2793
2829
|
ctl.close()
|
|
2794
2830
|
}
|
|
2795
2831
|
},
|
|
@@ -4601,4 +4637,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
4601
4637
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
4602
4638
|
|
|
4603
4639
|
// for tests
|
|
4604
|
-
export const _internal = { spentOf, OUTPUT_CAPS, LEARNED_CAPS, outputCap, fetchListing, accountIdentity, deviceRefreshBody, qwenworkClientHeaders, freeView, maskPhone, phoneLabelOf, realEmailOf, orgOf, teamOf, cardNameOf, 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, nameAlone, qoderMessages, kimiModel, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState, queueReady }
|
|
4640
|
+
export const _internal = { spentOf, OUTPUT_CAPS, LEARNED_CAPS, outputCap, fetchListing, accountIdentity, deviceRefreshBody, qwenworkClientHeaders, freeView, maskPhone, phoneLabelOf, realEmailOf, orgOf, teamOf, cardNameOf, 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, neutralKimi, nameAlone, 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.
|
|
3
|
+
"version": "0.2.82",
|
|
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",
|