@magpie-community/opencode-qoder-auth 0.2.79 → 0.2.81
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 +5 -0
- package/index.mjs +35 -7
- 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.
|
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
|
|
@@ -311,6 +322,12 @@ function expiresAt(jt) {
|
|
|
311
322
|
return Date.now() + DAY
|
|
312
323
|
}
|
|
313
324
|
|
|
325
|
+
// renewedTokens is whether next, what a renewal of a gave, holds another
|
|
326
|
+
// token than a: a new end alone is no new sign-in.
|
|
327
|
+
function renewedTokens(a, next) {
|
|
328
|
+
return ["access", "refresh", "deviceToken", "deviceRefresh"].some((k) => (a?.[k] ?? "") !== (next?.[k] ?? ""))
|
|
329
|
+
}
|
|
330
|
+
|
|
314
331
|
// whenSaid is the time a token's end field names, in milliseconds: a date,
|
|
315
332
|
// or an epoch in seconds or milliseconds; 0 for none (absent, 0, unreadable).
|
|
316
333
|
function whenSaid(v) {
|
|
@@ -1601,7 +1618,7 @@ const APP_CHAT = { stream: true, chat_task: "FREE_INPUT", is_reply: true, is_ret
|
|
|
1601
1618
|
// passes itself last.
|
|
1602
1619
|
function qoderBody(chat, m, named = "", task, site) {
|
|
1603
1620
|
const given = (chat.messages ?? []).filter((x) => x.role === "system" || x.role === "developer").map((x) => textOf(x.content)).filter(Boolean).join("\n\n")
|
|
1604
|
-
const system = nameAlone(harnessComma(asAgentSDK(given)))
|
|
1621
|
+
const system = nameAlone(harnessComma(asAgentSDK(neutralKimi(given))))
|
|
1605
1622
|
const tools = chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function" && t.function?.name) : []
|
|
1606
1623
|
const baseSystem = site?.systemPrompt ?? QODER_SYS
|
|
1607
1624
|
let sysText = system ? baseSystem + "\n\n" + system : baseSystem
|
|
@@ -3673,6 +3690,16 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3673
3690
|
return renewals.has(cred) || was
|
|
3674
3691
|
}
|
|
3675
3692
|
|
|
3693
|
+
// saveRenewed keeps what a renewal of a gave: saved only when it is
|
|
3694
|
+
// another token (a refresh can hand back the one it was asked with, and
|
|
3695
|
+
// a save that changes nothing has magpie read every sign-in again, from a
|
|
3696
|
+
// models listing too: plugins#1670)
|
|
3697
|
+
const saveRenewed = async (a, next) => {
|
|
3698
|
+
if (!renewedTokens(a, next)) return
|
|
3699
|
+
await client.auth.set({ path: { id: ID }, body: next })
|
|
3700
|
+
renewals.add(next)
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3676
3703
|
// fresh is the account with a live job token, refreshed and saved near
|
|
3677
3704
|
// its end.
|
|
3678
3705
|
const fresh = (getAuth) =>
|
|
@@ -3684,8 +3711,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3684
3711
|
const a = latest(stored)
|
|
3685
3712
|
if (a.expires - Date.now() > REFRESH_LEAD) return a
|
|
3686
3713
|
const next = { ...a, ...(await renew(a)) }
|
|
3687
|
-
await
|
|
3688
|
-
renewals.add(next)
|
|
3714
|
+
await saveRenewed(a, next)
|
|
3689
3715
|
return next
|
|
3690
3716
|
})
|
|
3691
3717
|
|
|
@@ -3710,8 +3736,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3710
3736
|
const now = Date.now()
|
|
3711
3737
|
for (const v of spent.values()) if (v.got.access === refused && now - v.at < RELOGIN_GAP) return undefined
|
|
3712
3738
|
const next = { ...a, ...(await renew(a)) }
|
|
3713
|
-
await
|
|
3714
|
-
renewals.add(next)
|
|
3739
|
+
await saveRenewed(a, next)
|
|
3715
3740
|
return next
|
|
3716
3741
|
})
|
|
3717
3742
|
|
|
@@ -4500,7 +4525,10 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
4500
4525
|
} catch (e) {
|
|
4501
4526
|
if (e?.expired) throw Object.assign(new Error(e.message), { signIn: "expired" })
|
|
4502
4527
|
}
|
|
4503
|
-
|
|
4528
|
+
// a renewal that gave the same token back renewed nothing: the
|
|
4529
|
+
// free view is that account's list, as for a renewed token
|
|
4530
|
+
if (next && next.access === cred.access) stillFree.add(cred.access)
|
|
4531
|
+
else if (next) {
|
|
4504
4532
|
if (renewals.has(next)) unsaid.add(listingKey(next))
|
|
4505
4533
|
cred = next
|
|
4506
4534
|
ms = await models(cred, true)
|
|
@@ -4584,4 +4612,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
4584
4612
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
4585
4613
|
|
|
4586
4614
|
// for tests
|
|
4587
|
-
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 }
|
|
4615
|
+
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.81",
|
|
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",
|