minimax 0.1.2: claim the account's daily check-in (签到) (#140)

minimax 0.1.2 adds an `auth.checkin` hook for MiniMax Code's daily check-in (每日签到).

- It reads the panel at `/minimax-cloud/api/v1/signin/status` and claims the day at `/signin/claim`.
- Both requests are signed by the package's own `accountCall()`: the same headers, query and x-signature as the rest of the account API, and a `{}` body on the claim.
- On the China site they go to `agent.minimax.cn` (`site.llm`), the host magpie's built-in check-in uses.
- Failed reads come back as `failed`: a non-2xx reply, no panel, or a malformed panel (not 7 days numbered 1-7, or more than one today or claimable day).
- With no day marked today it returns `inactive`, and nothing is claimed.
- The streak counts back from today's index. 401 and 403 are `failed` with the HTTP status.
- The README says the check-in is opt-in. OpenCode ignores the hook.

Run at d21543b76cf0fa19b6e345e6b2d2f0d29976ee93, merged locally onto origin/main 6467760:
- packages/minimax `bun test` (isolated HOME): 50 pass, 0 fail.
- `bun scripts/check.mjs` (all packages): exit 0.
- The new host test, run against 5fb2143's index.mjs: 17 pass, 1 fail (the host test). So it guards the fix.
- A scratch probe at 5fb2143 with separate llm/agent fakes reproduced the wrong host; d21543b's test covers that case.
Not run: a real MiniMax account. No test reaches the network.
This commit is contained in:
Euraxluo
2026-10-17 09:11:18 +08:00
committed by GitHub
parent 646776060f
commit fc9cf6a7b0
4 changed files with 281 additions and 8 deletions
+12 -2
View File
@@ -107,8 +107,18 @@ The usage card shows:
These are read the way MiniMax Code reads them, with its signed account API.
## Check-in
The account's daily check-in (每日签到) is claimed through the same sign-in:
the plugin reads the panel (`/minimax-cloud/api/v1/signin/status`) and
claims the day's credits (`/minimax-cloud/api/v1/signin/claim`) with the
same signed account API. magpie can run it once a day per account, when its
MiniMax check-in switch is on; Settings → Usage → Plugins has that switch
and a *Check in now* button, and the outcome — claimed, done, inactive,
ineligible, with the streak — lands on the account's Usage card.
OpenCode doesn't call this hook: there, check in from MiniMax Code or
MiniMax's site.
## Not here
- **No check-in.** The package never claims the daily check-in's credits.
Check in from MiniMax Code or MiniMax's site.
- **No sign-out.** Signing out doesn't revoke the token on MiniMax's side.
+192
View File
@@ -0,0 +1,192 @@
// The daily check-in (每日签到): the panel's day statuses and the claim's
// answers, as the minimax-cloud endpoints answer them (quota-hub's
// minimax2api worked them out). Everything runs against the local fake.
import "./nonet.mjs"
import { afterEach, expect, test } from "bun:test"
import { MiniMaxCodeAuthPlugin } from "./index.mjs"
import { _internal } from "./index.mjs"
import { fakeMiniMax, json } from "./fake.mjs"
let f
afterEach(() => f?.close())
const STATUS = "/minimax-cloud/api/v1/signin/status"
const CLAIM = "/minimax-cloud/api/v1/signin/claim"
const auth = { type: "oauth", access: "tok", refresh: "r", expires: Date.now() + 3600_000, accountId: "a@example.com" }
const day = (over = {}) => ({ day_no: 1, points: 10, status: 2, is_today: true, ...over })
const week = (todayNo, over = {}) => Array.from({ length: 7 }, (_, i) => {
const dayNo = i + 1
const status = dayNo < todayNo ? 3 : dayNo === todayNo ? 2 : 1
return day({ day_no: dayNo, status, is_today: dayNo === todayNo, ...over })
})
async function checkin() {
const plugin = await MiniMaxCodeAuthPlugin({ client: { auth: { set: async () => {} } } })
return plugin.auth.checkin(async () => auth)
}
test("a claimable day is claimed, its points and the streak reported", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(7) } }))
f.route("POST " + CLAIM, (r) => {
expect(r.headers.get("authorization")).toBe("Bearer tok")
return json({ base_resp: { status_code: 0 }, data: { claim_result: 1, points: 20, day_no: 7 } })
})
expect(await checkin()).toEqual({ outcome: "claimed", credit: 20, streak: 7 })
})
test("a claimed day is done, the streak counting it", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(1, { status: 3 }) } }))
expect(await checkin()).toEqual({ outcome: "done", credit: 10, streak: 1 })
})
test("the claim saying already-today is done", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(1) } }))
f.route("POST " + CLAIM, () => json({ base_resp: { status_code: 0 }, data: { claim_result: 2, points: 10 } }))
expect(await checkin()).toEqual({ outcome: "done", credit: 10, streak: 1 })
})
test("a claimable mid-week day is claimed with the streak before it", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(3) } }))
f.route("POST " + CLAIM, () => json({ base_resp: { status_code: 0 }, data: { claim_result: 1, points: 20 } }))
expect(await checkin()).toEqual({ outcome: "claimed", credit: 20, streak: 3 })
})
test("a claimed mid-week day reports the points and streak", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({
base_resp: { status_code: 0 },
data: { days: week(4, { status: 3 }) },
}))
expect(await checkin()).toEqual({ outcome: "done", credit: 10, streak: 4 })
})
test("the check-in requests are signed like the account API", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(1) } }))
f.route("POST " + CLAIM, () => json({ base_resp: { status_code: 0 }, data: { claim_result: 1, points: 20 } }))
await checkin()
const status = f.seen.find((r) => r.path === STATUS)
const claim = f.seen.find((r) => r.path === CLAIM)
for (const r of [status, claim]) {
expect(r.headers.get("user-agent")).toBe("MiniMaxCode")
expect(r.headers.get("yy")).toBeTruthy()
expect(r.headers.get("x-timestamp")).toBeTruthy()
expect(r.headers.get("x-signature")).toBeTruthy()
expect(r.query.get("device_platform")).toBe("mcode")
expect(r.query.get("timezone_offset")).toBe(String(new Date().getTimezoneOffset() * -60))
}
expect(claim?.text).toBe("{}")
})
test("the China panel is asked on the chat host, not the account host", async () => {
f = fakeMiniMax()
const was = { ..._internal.SITES["minimax-code"] }
Object.assign(_internal.SITES["minimax-code"], {
agent: "https://account.example",
llm: f.origin,
})
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(1, { status: 3 }) } }))
const plugin = await MiniMaxCodeAuthPlugin({ client: { auth: { set: async () => {} } } })
const out = await plugin.auth.checkin(async () => auth)
expect(out).toEqual({ outcome: "done", credit: 10, streak: 1 })
expect(f.seen.filter((r) => r.path === STATUS)).toHaveLength(1)
Object.assign(_internal.SITES["minimax-code"], was)
})
test("a day that hasn't started is inactive", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(8).map((d) => ({ ...d, status: 1 })) } }))
expect(await checkin()).toEqual({ outcome: "inactive" })
})
test("a day that isn't available is ineligible", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(1, { status: 4 }) } }))
expect(await checkin()).toEqual({ outcome: "ineligible" })
})
test("a panel without days is failed", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: [] } }))
const out = await checkin()
expect(out.outcome).toBe("failed")
expect(out.message).toContain("no panel")
})
test("a reply without a panel is failed", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({}))
const out = await checkin()
expect(out.outcome).toBe("failed")
expect(out.message).toContain("no panel")
})
test("a non-2xx panel is failed", async () => {
for (const body of [
json({ error: "invalid signature" }, 400),
json({ message: "internal" }, 502),
]) {
f?.close()
f = fakeMiniMax()
f.route("GET " + STATUS, () => body)
const out = await checkin()
expect(out.outcome).toBe("failed")
expect(out.message).toMatch(/HTTP (400|502)/)
}
})
test("a panel without today is inactive and no claim is made", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(8).map((d) => ({ ...d, is_today: false })) } }))
expect(await checkin()).toEqual({ outcome: "inactive" })
expect(f.seen.filter((r) => r.path === CLAIM)).toHaveLength(0)
})
test("the panel's error is failed with its words", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 1004, status_msg: "login fail" } }))
const out = await checkin()
expect(out.outcome).toBe("failed")
expect(out.message).toContain("login fail")
})
test("a turned-away token is failed without signing the account out", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => new Response("no", { status: 401 }))
const out = await checkin()
expect(out.outcome).toBe("failed")
expect(out.signIn).toBeUndefined()
})
test("a forbidden check-in is failed without signing the account out", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => new Response("no", { status: 403 }))
const out = await checkin()
expect(out.outcome).toBe("failed")
expect(out.message).toContain("403")
expect(out.signIn).toBeUndefined()
})
test("an unknown claim_result is failed", async () => {
f = fakeMiniMax()
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(1) } }))
f.route("POST " + CLAIM, () => json({ base_resp: { status_code: 0 }, data: { claim_result: 9 } }))
const out = await checkin()
expect(out.outcome).toBe("failed")
expect(out.message).toContain("claim_result")
})
test("a not-signed-in account is failed without a request", async () => {
f = fakeMiniMax()
const plugin = await MiniMaxCodeAuthPlugin({ client: { auth: { set: async () => {} } } })
const out = await plugin.auth.checkin(async () => ({ type: "api", key: "k" }))
expect(out.outcome).toBe("failed")
expect(out.message).toBe("not signed in")
expect(f.seen.length).toBe(0)
})
+76 -5
View File
@@ -7,7 +7,8 @@
// device flow with PKCE, client mcode-public): nothing is read from or
// written to MiniMax Code's own sign-in (~/.minimax). Its chats are
// Anthropic messages at <agent>/mavis/api/v1/llm/v1/messages, sent with
// MiniMax Code's headers. No check-in is made for the account.
// MiniMax Code's headers. The account's daily check-in (每日签到) is
// claimed with the same token, on the minimax-cloud endpoints.
import { createHash, randomBytes, randomUUID } from "node:crypto"
@@ -315,8 +316,8 @@ class SignInExpired extends Error {
// signed is a request of MiniMax Code's account API, signed as mcode signs
// one: yy over the path and query, the body ("{}" for a GET) and the time;
// x-signature over the time (and the body of a POST).
function signed(site, path, { access, userID, body, now = Date.now(), tz = new Date().getTimezoneOffset() * -60, platform = process.platform } = {}) {
const url = new URL(path, site.agent)
function signed(site, path, { access, userID, body, origin = site.agent, now = Date.now(), tz = new Date().getTimezoneOffset() * -60, platform = process.platform } = {}) {
const url = new URL(path, origin)
url.search = new URLSearchParams({
device_platform: "mcode", biz_id: "3", app_id: "3001", version_code: "22201",
unix: String(now), timezone_offset: String(tz), sys_language: site.lang, lang: site.lang,
@@ -494,6 +495,58 @@ function usageOf(m, windows = []) {
}
}
// ---- check-in ----------------------------------------------------------------
// MiniMax pays a few credits for the daily check-in (每日签到). The panel
// lists the week's seven days — status 1 not started, 2 claimable, 3
// claimed, 4 not available — and the claim answers 1 claimed now or 2
// already today. Both calls use the same signed account client as the rest
// of the account API: the gateway checks the signature, and a Bearer-only
// Bun fetch is not what MiniMax Code sends.
async function checkinCall(site, access, method, path, body) {
const opts = { access, origin: site.llm }
if (body !== undefined) opts.body = body
return accountCall(site, path, opts, "check-in")
}
// checkinOf reads the panel and claims today: claimed (checked in now,
// credit = the points it paid), done (already today), inactive (the day
// hasn't started, or the panel has none), ineligible (the day isn't
// available); a throw is failed. streak counts the claimed days up to and
// including today.
async function checkinOf(site, access) {
const panel = await checkinCall(site, access, "GET", "/minimax-cloud/api/v1/signin/status")
const days = Array.isArray(panel?.data?.days) ? panel.data.days : null
if (!days?.length) throw new Error("check-in: no panel in the reply")
const sorted = [...days].sort((a, b) => (a?.day_no ?? 0) - (b?.day_no ?? 0))
if (sorted.length !== 7 || sorted.some((d, i) => d?.day_no !== i + 1)) throw new Error("check-in: malformed panel")
const todays = sorted.filter((d) => d?.is_today)
const claimable = sorted.filter((d) => d?.status === 2)
if (todays.length > 1 || claimable.length > 1) throw new Error("check-in: malformed panel")
const today = todays[0]
if (!today) return { outcome: "inactive" }
const streakFrom = (i) => {
let n = 0
for (let j = i; j >= 0 && sorted[j]?.status === 3; j--) n++
return n
}
if (today.status === 3) {
const points = pos(today, "points")
return { outcome: "done", ...(points ? { credit: points } : {}), streak: streakFrom(sorted.indexOf(today)) }
}
if (today.status === 2) {
const claim = await checkinCall(site, access, "POST", "/minimax-cloud/api/v1/signin/claim", {})
const r = pos(claim?.data, "claim_result")
const credit = pos(claim?.data, "points")
const got = { ...(credit ? { credit } : {}), streak: streakFrom(sorted.indexOf(today) - 1) + 1 }
if (r === 1) return { outcome: "claimed", ...got }
if (r === 2) return { outcome: "done", ...got }
throw new Error(`check-in: unknown claim_result ${JSON.stringify(claim?.data?.claim_result)}`)
}
if (today.status === 4) return { outcome: "ineligible" }
return { outcome: "inactive" } // 1: the day hasn't started
}
// ---- requests -----------------------------------------------------------------
// QUOTA says a refusal is about the account's credits or plan running out.
@@ -698,7 +751,7 @@ function makePlugin(site) {
},
}
},
// the account's credits and M Plan; nothing is claimed (no check-in)
// the account's credits and M Plan
async usage(getAuth) {
const auth = await getAuth()
if (auth?.type !== "oauth" || !auth.access) return { error: "not signed in" }
@@ -730,6 +783,24 @@ function makePlugin(site) {
return { error: e?.message ?? String(e), signIn: "kept" }
}
},
// the daily check-in (每日签到): magpie runs it once a day per
// account, and its Check in now button asks right away; the
// outcome lands on the account's Usage card.
async checkin(getAuth) {
const auth = await getAuth()
if (auth?.type !== "oauth" || !auth.access) return { outcome: "failed", message: "not signed in" }
let a
try {
;({ a } = await fresh(getAuth))
} catch (e) {
return { outcome: "failed", message: e?.message ?? String(e), ...(e?.signIn ? { signIn: e.signIn } : {}) }
}
try {
return await checkinOf(site, a.access)
} catch (e) {
return { outcome: "failed", message: e?.message ?? String(e), ...(e?.signIn ? { signIn: e.signIn } : {}) }
}
},
methods: [
{
type: "oauth",
@@ -776,4 +847,4 @@ export const MiniMaxCodeAuthPlugin = makePlugin(SITES["minimax-code"])
export const MiniMaxCodeGlobalAuthPlugin = makePlugin(SITES["minimax-code-global"])
// for tests
export const _internal = { SITES, MODELS, signed, md5, parseModels, planWindows, membershipOf, usageOf, credits, variants, renewing, renewed, startDevice, pollDevice }
export const _internal = { SITES, MODELS, signed, md5, parseModels, planWindows, membershipOf, usageOf, credits, variants, renewing, renewed, startDevice, pollDevice, checkinOf }
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-minimax-auth",
"version": "0.1.1",
"version": "0.1.2",
"description": "OpenCode provider plugins for MiniMax Code accounts: their credits and M Plan, China (minimax-code) and international (minimax-code-global), with MiniMax Code's own device sign-in",
"type": "module",
"main": "./index.mjs",