@magpie-community/opencode-qoder-auth 0.2.78 → 0.2.80
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 +40 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,6 +116,11 @@ itself.
|
|
|
116
116
|
powered by DeepSeek Harness.`, goes with a comma before `powered by`
|
|
117
117
|
(since 0.2.73, #1517): Qoder CN puts a request whose system prompt
|
|
118
118
|
holds that line, as written, in a queue that never moves.
|
|
119
|
+
- Another agent's name before a comma, such as ZCode's `You are ZCode, an
|
|
120
|
+
interactive agent` or Codex's `You are Codex, based on GPT-5.`, goes as
|
|
121
|
+
two sentences, `You are ZCode. You are an interactive agent` (since
|
|
122
|
+
0.2.79, #1667): Qoder CN parks a request with the name and comma as
|
|
123
|
+
written in the same queue. Qoder's own names stay as they are.
|
|
119
124
|
- Messages become text and image blocks.
|
|
120
125
|
- Tool calls and results become OpenAI tool turns. Images a tool returned
|
|
121
126
|
follow in a user turn.
|
package/index.mjs
CHANGED
|
@@ -113,6 +113,22 @@ 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 parks a request in the same never-moving 10605 queue when its
|
|
117
|
+
// system prompt holds another agent's name, as written, then a comma: "You
|
|
118
|
+
// are ZCode, an interactive agent" (every ZCode request) and "You are
|
|
119
|
+
// Codex, based on GPT-5." both waited at every resend on the free hmodel,
|
|
120
|
+
// while "You are ZCode. You are an interactive agent", "You are Zcode, ..."
|
|
121
|
+
// or "You are opencode, ..." were answered at once (duiniwukenaihe's bisect
|
|
122
|
+
// on #1667: the match is case-sensitive, and tools, size or a trailing
|
|
123
|
+
// period changed nothing). Rather than a list that grows with each agent
|
|
124
|
+
// found, any capitalized name in "You are <Name>, a/an/the/based/built/
|
|
125
|
+
// powered/running ..." goes as two sentences, "You are <Name>. You are
|
|
126
|
+
// a ...", which says the same; Qoder's own names are left alone. Like the
|
|
127
|
+
// two above, only the system text Qoder is sent changes; the user's own
|
|
128
|
+
// messages go as written.
|
|
129
|
+
const AGENT_NAMED = /\bYou are ((?!Qoder\b|Lingma\b|QwenWork\b)[A-Z][\w.+-]*(?:[ \t][A-Z][\w.+-]*){0,2}),[ \t]*(?=(?:an?|the|based|built|powered|running|made|created|developed|trained)\b)/g
|
|
130
|
+
const nameAlone = (text) => text.replace(AGENT_NAMED, "You are $1. You are ")
|
|
131
|
+
|
|
116
132
|
const hexID = () => randomUUID().replaceAll("-", "")
|
|
117
133
|
|
|
118
134
|
// ---- the COSY envelope --------------------------------------------------------
|
|
@@ -295,6 +311,12 @@ function expiresAt(jt) {
|
|
|
295
311
|
return Date.now() + DAY
|
|
296
312
|
}
|
|
297
313
|
|
|
314
|
+
// renewedTokens is whether next, what a renewal of a gave, holds another
|
|
315
|
+
// token than a: a new end alone is no new sign-in.
|
|
316
|
+
function renewedTokens(a, next) {
|
|
317
|
+
return ["access", "refresh", "deviceToken", "deviceRefresh"].some((k) => (a?.[k] ?? "") !== (next?.[k] ?? ""))
|
|
318
|
+
}
|
|
319
|
+
|
|
298
320
|
// whenSaid is the time a token's end field names, in milliseconds: a date,
|
|
299
321
|
// or an epoch in seconds or milliseconds; 0 for none (absent, 0, unreadable).
|
|
300
322
|
function whenSaid(v) {
|
|
@@ -1585,7 +1607,7 @@ const APP_CHAT = { stream: true, chat_task: "FREE_INPUT", is_reply: true, is_ret
|
|
|
1585
1607
|
// passes itself last.
|
|
1586
1608
|
function qoderBody(chat, m, named = "", task, site) {
|
|
1587
1609
|
const given = (chat.messages ?? []).filter((x) => x.role === "system" || x.role === "developer").map((x) => textOf(x.content)).filter(Boolean).join("\n\n")
|
|
1588
|
-
const system = harnessComma(asAgentSDK(given))
|
|
1610
|
+
const system = nameAlone(harnessComma(asAgentSDK(given)))
|
|
1589
1611
|
const tools = chat.tool_choice !== "none" ? (chat.tools ?? []).filter((t) => t?.type === "function" && t.function?.name) : []
|
|
1590
1612
|
const baseSystem = site?.systemPrompt ?? QODER_SYS
|
|
1591
1613
|
let sysText = system ? baseSystem + "\n\n" + system : baseSystem
|
|
@@ -3657,6 +3679,16 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3657
3679
|
return renewals.has(cred) || was
|
|
3658
3680
|
}
|
|
3659
3681
|
|
|
3682
|
+
// saveRenewed keeps what a renewal of a gave: saved only when it is
|
|
3683
|
+
// another token (a refresh can hand back the one it was asked with, and
|
|
3684
|
+
// a save that changes nothing has magpie read every sign-in again, from a
|
|
3685
|
+
// models listing too: plugins#1670)
|
|
3686
|
+
const saveRenewed = async (a, next) => {
|
|
3687
|
+
if (!renewedTokens(a, next)) return
|
|
3688
|
+
await client.auth.set({ path: { id: ID }, body: next })
|
|
3689
|
+
renewals.add(next)
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3660
3692
|
// fresh is the account with a live job token, refreshed and saved near
|
|
3661
3693
|
// its end.
|
|
3662
3694
|
const fresh = (getAuth) =>
|
|
@@ -3668,8 +3700,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3668
3700
|
const a = latest(stored)
|
|
3669
3701
|
if (a.expires - Date.now() > REFRESH_LEAD) return a
|
|
3670
3702
|
const next = { ...a, ...(await renew(a)) }
|
|
3671
|
-
await
|
|
3672
|
-
renewals.add(next)
|
|
3703
|
+
await saveRenewed(a, next)
|
|
3673
3704
|
return next
|
|
3674
3705
|
})
|
|
3675
3706
|
|
|
@@ -3694,8 +3725,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
3694
3725
|
const now = Date.now()
|
|
3695
3726
|
for (const v of spent.values()) if (v.got.access === refused && now - v.at < RELOGIN_GAP) return undefined
|
|
3696
3727
|
const next = { ...a, ...(await renew(a)) }
|
|
3697
|
-
await
|
|
3698
|
-
renewals.add(next)
|
|
3728
|
+
await saveRenewed(a, next)
|
|
3699
3729
|
return next
|
|
3700
3730
|
})
|
|
3701
3731
|
|
|
@@ -4484,7 +4514,10 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
4484
4514
|
} catch (e) {
|
|
4485
4515
|
if (e?.expired) throw Object.assign(new Error(e.message), { signIn: "expired" })
|
|
4486
4516
|
}
|
|
4487
|
-
|
|
4517
|
+
// a renewal that gave the same token back renewed nothing: the
|
|
4518
|
+
// free view is that account's list, as for a renewed token
|
|
4519
|
+
if (next && next.access === cred.access) stillFree.add(cred.access)
|
|
4520
|
+
else if (next) {
|
|
4488
4521
|
if (renewals.has(next)) unsaid.add(listingKey(next))
|
|
4489
4522
|
cred = next
|
|
4490
4523
|
ms = await models(cred, true)
|
|
@@ -4568,4 +4601,4 @@ export async function QwenWorkEnterpriseAuthPlugin({ client }) {
|
|
|
4568
4601
|
export const protocol = { makePlugin, deviceSignIn, openapi, siteOf }
|
|
4569
4602
|
|
|
4570
4603
|
// for tests
|
|
4571
|
-
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, qoderMessages, kimiModel, cacheMarked, sessionOf, namedSession, taskOf, TASKS, TASK_MAX, TASK_IDLE, SESSION, SITES, decodeBody, events, QUEUE, queueState, queueReady }
|
|
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 }
|
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.80",
|
|
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",
|