@magpie-community/opencode-qoder-auth 0.2.41 → 0.2.43
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 +13 -0
- package/index.mjs +65 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -390,6 +390,19 @@ Qoder CN's `runtime-info` for environment `0` (the international one is
|
|
|
390
390
|
- `<openapi>` is `openapi.qoder.sh` (Qoder) or `openapi.qoder.com.cn`
|
|
391
391
|
(Qoder CN). Other pages on those hosts are still refused.
|
|
392
392
|
|
|
393
|
+
**When it is asked (0.2.43).** The daily 100 credits are a campaign of
|
|
394
|
+
their own each day, listed from 10:00 (UTC+8) to 09:59 the next day
|
|
395
|
+
(`startAt`/`endAt`; the campaign's own text says "Daily reset: 10:00
|
|
396
|
+
(UTC+8)", a live list on 2026-10-28). A check-in before 10:00 meets the day
|
|
397
|
+
before's campaign: it claims that one if it is still open. Every answer
|
|
398
|
+
that knows the window carries `until`, the next campaign's opening (a day
|
|
399
|
+
after this one's start, or its end when it runs longer) plus a minute, and
|
|
400
|
+
magpie (with `until` support) asks again then, so today's credits are
|
|
401
|
+
claimed a minute or two after 10:00 (UTC+8), whatever the computer's time
|
|
402
|
+
zone, with nothing to set. Between the old campaign's end at 09:59 and
|
|
403
|
+
10:00 the check-in is `failed` with `until` 10:01. An older magpie ignores
|
|
404
|
+
`until` and asks once a Beijing calendar day, as before.
|
|
405
|
+
|
|
393
406
|
Taken from [wallechfox/qoder-checkin](https://github.com/wallechfox/qoder-checkin),
|
|
394
407
|
which a user reports works, and Qoder desktop 0.4.3's campaign requests.
|
|
395
408
|
International campaign discovery was checked with a real account on
|
package/index.mjs
CHANGED
|
@@ -792,6 +792,28 @@ function callID(at, k, c) {
|
|
|
792
792
|
return "call_" + createHash("sha256").update(`${at}\0${k}\0${c.function?.name ?? ""}\0${said}`).digest("hex").slice(0, 32)
|
|
793
793
|
}
|
|
794
794
|
|
|
795
|
+
// reasoningOf is the thinking an assistant turn of the chat carries back:
|
|
796
|
+
// reasoning_content (DeepSeek's spelling, which magpie and most clients
|
|
797
|
+
// send), else reasoning (OpenRouter's), else reasoning_details' text, ""
|
|
798
|
+
// when it carries none.
|
|
799
|
+
function reasoningOf(m) {
|
|
800
|
+
let text = ""
|
|
801
|
+
for (const k of ["reasoning_content", "reasoning"]) if (!text && typeof m[k] === "string") text = m[k]
|
|
802
|
+
if (!text && Array.isArray(m.reasoning_details)) text = m.reasoning_details.map((d) => (typeof d?.text === "string" ? d.text : typeof d?.summary === "string" ? d.summary : "")).join("")
|
|
803
|
+
// A blank one (magpie's gateway sends " " for a tool turn with no
|
|
804
|
+
// thinking) is no thinking at all.
|
|
805
|
+
return text.trim() ? text : ""
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// An assistant turn's thinking goes back in reasoning_content, as Qoder's
|
|
809
|
+
// own client sends it (qoder-agent-sdk, Qoder.app 0.x: its converter sets
|
|
810
|
+
// reasoning_content on every earlier assistant turn that had thinking).
|
|
811
|
+
// It was left out from the plugin's first version on, so a model behind
|
|
812
|
+
// Qoder never saw what it had thought on the turns before (uk.jent on
|
|
813
|
+
// Discord): on Qoder, DeepSeek-V4-Pro in a tool loop now recalls what its
|
|
814
|
+
// thinking before the call said, and said it had none without it. A turn
|
|
815
|
+
// with thinking and nothing else is still left out, as that client leaves
|
|
816
|
+
// it.
|
|
795
817
|
function qoderMessages(msgs) {
|
|
796
818
|
const out = []
|
|
797
819
|
const names = {}
|
|
@@ -850,7 +872,8 @@ function qoderMessages(msgs) {
|
|
|
850
872
|
const args = c.function?.arguments
|
|
851
873
|
return { id, type: "function", function: { name: c.function?.name, arguments: typeof args === "string" ? args : JSON.stringify(args ?? {}) } }
|
|
852
874
|
})
|
|
853
|
-
|
|
875
|
+
const think = reasoningOf(m)
|
|
876
|
+
out.push({ role: "assistant", content: textOf(m.content), ...(think ? { reasoning_content: think } : {}), tool_calls: calls })
|
|
854
877
|
const open = calls.map((c) => c.id)
|
|
855
878
|
const kept = new Set()
|
|
856
879
|
for (let j = i + 1; j < msgs.length && msgs[j].role === "tool"; j++) {
|
|
@@ -864,7 +887,8 @@ function qoderMessages(msgs) {
|
|
|
864
887
|
if (m.role === "assistant") blocks = blocks.filter((b) => b.type === "text")
|
|
865
888
|
if (!blocks.length) continue
|
|
866
889
|
if (m.role === "user" && seen.length) [blocks, seen] = [[...seen, ...blocks], []]
|
|
867
|
-
|
|
890
|
+
const think = m.role === "assistant" ? reasoningOf(m) : ""
|
|
891
|
+
out.push({ role: m.role, content: blocks, ...(think ? { reasoning_content: think } : {}) })
|
|
868
892
|
// a result after the assistant's own words answers no call before it
|
|
869
893
|
turn = null
|
|
870
894
|
}
|
|
@@ -2065,6 +2089,36 @@ function gfmt(n) {
|
|
|
2065
2089
|
|
|
2066
2090
|
const RFC3339 = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(Z|[+-]\d\d:\d\d)$/i
|
|
2067
2091
|
|
|
2092
|
+
// Qoder's daily credits are a campaign of their own each day, listed from
|
|
2093
|
+
// 10:00 (UTC+8) to 09:59 the next day: its startAt and endAt, and its own
|
|
2094
|
+
// words, "Daily reset: 10:00 (UTC+8)" (a live list, 2026-10-28; sdytman on
|
|
2095
|
+
// Discord: qoder每天10点开始签到). So the check-in's day is the campaign's,
|
|
2096
|
+
// not the calendar's in any zone: a check-in before 10:00 meets the day
|
|
2097
|
+
// before's campaign, and the next one opens a day after that one's start,
|
|
2098
|
+
// a minute after its end. A check-in says when (until, RFC 3339), and
|
|
2099
|
+
// magpie asks again then, whatever the machine's time zone.
|
|
2100
|
+
const DAY_MS = 86_400_000
|
|
2101
|
+
// a minute's room for a computer clock that runs ahead of Qoder's
|
|
2102
|
+
const OPEN_ROOM_MS = 60_000
|
|
2103
|
+
|
|
2104
|
+
// at is a time Qoder gives, in seconds or milliseconds, as milliseconds.
|
|
2105
|
+
const at = (v) => {
|
|
2106
|
+
const n = Number(v)
|
|
2107
|
+
if (v === null || v === undefined || v === "" || !Number.isFinite(n) || n <= 0) return undefined
|
|
2108
|
+
return n > 1e12 ? n : n * 1000
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
// nextOpens is when the campaign after c is expected to open: a day after
|
|
2112
|
+
// c's start, or c's end when it runs longer than a day.
|
|
2113
|
+
const nextOpens = (c) => {
|
|
2114
|
+
const start = at(c?.startAt), end = at(c?.endAt)
|
|
2115
|
+
if (end === undefined) return undefined
|
|
2116
|
+
return start === undefined ? end : Math.max(end, start + DAY_MS)
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
// askAgain is a check-in's until: when to ask again, with room.
|
|
2120
|
+
const askAgain = (t) => (Number.isFinite(t) ? { until: new Date(t + OPEN_ROOM_MS).toISOString() } : {})
|
|
2121
|
+
|
|
2068
2122
|
// when is a time Qoder gives: an RFC 3339 string, else seconds or
|
|
2069
2123
|
// milliseconds, as a number or its text.
|
|
2070
2124
|
function when(v) {
|
|
@@ -2562,16 +2616,21 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
2562
2616
|
}
|
|
2563
2617
|
if (listRes.status !== 200) return { outcome: "failed", message: `campaigns: HTTP ${listRes.status}` }
|
|
2564
2618
|
const now = Date.now()
|
|
2565
|
-
const active = (c) => (
|
|
2619
|
+
const active = (c) => (at(c.startAt) ?? -Infinity) <= now && now < (at(c.endAt) ?? Infinity)
|
|
2566
2620
|
const campaigns = (Array.isArray(list.campaigns) ? list.campaigns : []).filter((x) => x?.actionType === "CLAIM_BENEFIT")
|
|
2567
2621
|
const campaign = campaigns.find((x) => x.claimStatus === "CLAIMABLE")
|
|
2568
2622
|
if (!campaign) {
|
|
2569
2623
|
const done = campaigns.find((x) => x.claimStatus === "CLAIMED" && active(x))
|
|
2570
2624
|
if (done) {
|
|
2571
2625
|
const amount = Number(done.benefit?.amount)
|
|
2572
|
-
return { outcome: "done", ...(Number.isFinite(amount) && amount > 0 ? { credit: amount } : {}) }
|
|
2626
|
+
return { outcome: "done", ...(Number.isFinite(amount) && amount > 0 ? { credit: amount } : {}), ...askAgain(nextOpens(done)) }
|
|
2627
|
+
}
|
|
2628
|
+
// the next day's credits open at a time the list says: ask then,
|
|
2629
|
+
// not half an hour later
|
|
2630
|
+
if (campaigns.length) {
|
|
2631
|
+
const next = Math.min(...campaigns.flatMap((c) => [at(c.startAt), nextOpens(c)]).filter((t) => t > now))
|
|
2632
|
+
return { outcome: "failed", message: "campaigns: today's credits aren't offered yet", ...askAgain(next) }
|
|
2573
2633
|
}
|
|
2574
|
-
if (campaigns.length) return { outcome: "failed", message: "campaigns: today's credits aren't offered yet" }
|
|
2575
2634
|
// Asked without Qoder CN's identity and offered nothing: what an
|
|
2576
2635
|
// international list says to a request without one, so say why
|
|
2577
2636
|
// (no Qoder CN on this machine) or ask again (it didn't answer).
|
|
@@ -2596,7 +2655,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|
|
2596
2655
|
if (claimRes.status !== 200) return { outcome: "failed", message: `claim: HTTP ${claimRes.status}` }
|
|
2597
2656
|
if (said === "CLAIMED") {
|
|
2598
2657
|
const amount = Number(claim?.benefit?.amount ?? claim?.data?.benefit?.amount ?? campaign.benefit?.amount)
|
|
2599
|
-
return { outcome: "claimed", ...(Number.isFinite(amount) && amount > 0 ? { credit: amount } : {}) }
|
|
2658
|
+
return { outcome: "claimed", ...(Number.isFinite(amount) && amount > 0 ? { credit: amount } : {}), ...askAgain(nextOpens(campaign)) }
|
|
2600
2659
|
}
|
|
2601
2660
|
return { outcome: "failed", message: `claim: ${said || "unknown answer"}` }
|
|
2602
2661
|
} catch (e) {
|
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.43",
|
|
4
4
|
"description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship (VPC)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|