minimax: a check-in turned away with 401 is renewed and asked again, as MiniMax Code does (0.1.5)
Magic_zero (Discord, MiniMax Code international) saw "check-in: the sign-in was refused (HTTP 401)" on every try while chats worked; signing in again, reinstalling and a proxy didn't change it. 0.1.4 (4d73d22) added user_id and the device fields and was never tried. Diffed against the official client, @minimax-ai/code 0.6.12 from registry.npmjs.org (npm pack), chunk-5ADYFF2U.js: its /checkin class (T9) builds the request with Ej(). Given the same token and user id, 0.1.4's international request is the same field for field: URL, method, query (device_platform web, is_desktop, desktop_version, user_id, ...), Bearer access token, yy, x-timestamp, x-signature, body "{}". So user_id was not the cause. minimax-cloud answers a token it doesn't take with 401 {"error":"invalid access token"} (asked without credentials of agent.minimax.io, agent.minimax.cn and agent.minimaxi.com). MiniMax Code meets that 401 by renewing the sign-in (authContextResolver forceRefresh), reading realUserID again and asking once more. The plugin's chat fetch renews on a 401 too, which is why chats worked; the check-in gave up. - checkin: on a 401 the token is renewed (fresh with the rejected token: a newer held one, else a refresh), the user id read again, and the check-in asked once more. A refresh refused as invalid_grant says signIn "expired"; any other failure keeps the first error and doesn't sign the account out. 403 is not retried. - China sibling: the same missing retry, and the check-in went to the chat host agent.minimax.cn while MiniMax Code asks agent.minimaxi.com (HA() cn), the host the plugin's other China account calls already use. It now uses site.agent. - README's Check-in section says both. Tests (checkin.test.mjs), from the official request shape: a 401 "invalid access token" for the old token, then refresh, user info and status/claim with "Bearer new", for both sites; still refused after the renewal fails after two asks; invalid_grant says expired; 403 is not renewed; the China panel is asked on the minimax-cloud host. Run against origin/main's index.mjs, 5 of them fail (the 403 one passes on both). Ran at7ee60f8+ this change: packages/minimax: H=$(mktemp -d); HOME="$H" bun test -> 59 pass, 0 fail repo root: H=$(mktemp -d); HOME="$H" bun test -> 2127 pass, 0 fail bun scripts/check.mjs -> exit 0 Not tried: a real MiniMax account (none available), so neither that a renewed token is taken by minimax-cloud nor the reporter's own case. magpie has no MiniMax mover or min; plugins update themselves hourly.
This commit is contained in:
@@ -120,7 +120,10 @@ 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, asked as MiniMax Code's own `/checkin` asks them:
|
||||
as the account (its MiniMax user id, looked up first when the sign-in
|
||||
didn't keep it), from the desktop client. magpie can run it once a day per account, when its
|
||||
didn't keep it), from the desktop client, on MiniMax Code's own hosts
|
||||
(agent.minimax.io, agent.minimaxi.com). A check-in turned away with 401 is
|
||||
renewed and asked once more, with the user id read again, as MiniMax Code
|
||||
does. 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.
|
||||
|
||||
@@ -123,19 +123,91 @@ test("an account whose user id can't be read is failed without a check-in", asyn
|
||||
expect(f.seen.filter((r) => r.path === STATUS)).toHaveLength(0)
|
||||
})
|
||||
|
||||
test("the China panel is asked on the chat host, not the account host", async () => {
|
||||
// MiniMax Code 0.6.12's minimax-cloud origins (chunk-5ADYFF2U, HA):
|
||||
// agent.minimaxi.com for cn, agent.minimax.io for en, the account API's
|
||||
// hosts. The China site's chat host (agent.minimax.cn) is not one of them.
|
||||
test("the China panel is asked on MiniMax Code's minimax-cloud host, not the chat host", async () => {
|
||||
f = fakeMiniMax()
|
||||
const was = { ..._internal.SITES["minimax-code"] }
|
||||
Object.assign(_internal.SITES["minimax-code"], {
|
||||
agent: "https://account.example",
|
||||
llm: f.origin,
|
||||
agent: f.origin,
|
||||
llm: "https://chat.example",
|
||||
})
|
||||
f.route("GET " + STATUS, () => json({ base_resp: { status_code: 0 }, data: { days: week(1, { status: 3 }) } }))
|
||||
const plugin = await MiniMaxCodeAuthPlugin({ client: { auth: { set: async () => {} } } })
|
||||
try {
|
||||
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)
|
||||
} finally {
|
||||
Object.assign(_internal.SITES["minimax-code"], was)
|
||||
}
|
||||
})
|
||||
|
||||
// Magic_zero on Discord, with 0.1.4: still "check-in: the sign-in was
|
||||
// refused (HTTP 401)" while chats went through. minimax-cloud answers a
|
||||
// token it doesn't take with 401 {"error":"invalid access token"} (asked
|
||||
// of agent.minimax.io). MiniMax Code's /checkin (T9.request) meets a 401
|
||||
// by renewing the sign-in (handleUnauthorized), reading the user id again
|
||||
// for the new token, and asking once more; the plugin's chat fetch also
|
||||
// renews on a 401, so only the check-in showed it.
|
||||
const refused = () => json({ error: "invalid access token" }, 401)
|
||||
const onlyNew = (r) => (r.headers.get("authorization") === "Bearer new" ? null : refused())
|
||||
|
||||
for (const [name, Plugin] of [["international", MiniMaxCodeGlobalAuthPlugin], ["China", MiniMaxCodeAuthPlugin]]) {
|
||||
test(`a ${name} check-in turned away with 401 is renewed and asked once more, as MiniMax Code does`, async () => {
|
||||
f = fakeMiniMax()
|
||||
const saved = []
|
||||
f.route("POST /oauth2/token", () => json({ access_token: "new", refresh_token: "r2", token_type: "Bearer", expires_in: 3600 }))
|
||||
f.route("GET /v1/api/user/info", (r) => onlyNew(r) ?? json({ statusInfo: { code: 0 }, data: { userInfo: { realUserID: "u-42" } } }))
|
||||
f.route("GET " + STATUS, (r) => onlyNew(r) ?? asTheAccount(r) ?? json({ base_resp: { status_code: 0 }, data: { days: week(2) } }))
|
||||
f.route("POST " + CLAIM, (r) => onlyNew(r) ?? asTheAccount(r) ?? json({ base_resp: { status_code: 0 }, data: { claim_result: 1, points: 20 } }))
|
||||
const plugin = await Plugin({ client: { auth: { set: async (v) => (saved.push(v.body), true) } } })
|
||||
expect(await plugin.auth.checkin(async () => auth)).toEqual({ outcome: "claimed", credit: 20, streak: 2 })
|
||||
const asked = f.seen.map((r) => [r.path, r.headers.get("authorization")])
|
||||
expect(asked).toEqual([
|
||||
[STATUS, "Bearer tok"],
|
||||
["/oauth2/token", null],
|
||||
["/v1/api/user/info", "Bearer new"],
|
||||
[STATUS, "Bearer new"],
|
||||
[CLAIM, "Bearer new"],
|
||||
])
|
||||
expect(f.seen.find((r) => r.path === "/oauth2/token").form).toMatchObject({ grant_type: "refresh_token", refresh_token: "r" })
|
||||
expect(saved.map((a) => a.access)).toEqual(["new"])
|
||||
})
|
||||
}
|
||||
|
||||
test("a check-in still turned away after the renewal is failed, asked only twice", async () => {
|
||||
f = fakeMiniMax()
|
||||
f.route("POST /oauth2/token", () => json({ access_token: "new", refresh_token: "r2", token_type: "Bearer", expires_in: 3600 }))
|
||||
f.route("GET /v1/api/user/info", () => json({ statusInfo: { code: 0 }, data: { userInfo: { realUserID: "u-42" } } }))
|
||||
f.route("GET " + STATUS, refused)
|
||||
const plugin = await MiniMaxCodeGlobalAuthPlugin({ client: { auth: { set: async () => true } } })
|
||||
const out = await plugin.auth.checkin(async () => auth)
|
||||
expect(out).toEqual({ outcome: "done", credit: 10, streak: 1 })
|
||||
expect(out.outcome).toBe("failed")
|
||||
expect(out.message).toBe("check-in: the sign-in was refused (HTTP 401)")
|
||||
expect(out.signIn).toBeUndefined()
|
||||
expect(f.seen.filter((r) => r.path === STATUS)).toHaveLength(2)
|
||||
expect(f.seen.filter((r) => r.path === "/oauth2/token")).toHaveLength(1)
|
||||
})
|
||||
|
||||
test("a 401 whose renewal says the account is signed out says so", async () => {
|
||||
f = fakeMiniMax()
|
||||
f.route("POST /oauth2/token", () => json({ error: "invalid_grant" }, 400))
|
||||
f.route("GET " + STATUS, refused)
|
||||
const plugin = await MiniMaxCodeGlobalAuthPlugin({ client: { auth: { set: async () => true } } })
|
||||
const out = await plugin.auth.checkin(async () => auth)
|
||||
expect(out.outcome).toBe("failed")
|
||||
expect(out.signIn).toBe("expired")
|
||||
expect(f.seen.filter((r) => r.path === STATUS)).toHaveLength(1)
|
||||
Object.assign(_internal.SITES["minimax-code"], was)
|
||||
})
|
||||
|
||||
test("a 403 is not renewed", async () => {
|
||||
f = fakeMiniMax()
|
||||
f.route("GET " + STATUS, () => new Response("no", { status: 403 }))
|
||||
const out = await checkin()
|
||||
expect(out.outcome).toBe("failed")
|
||||
expect(f.seen.filter((r) => r.path === "/oauth2/token")).toHaveLength(0)
|
||||
})
|
||||
|
||||
test("a day that hasn't started is inactive", async () => {
|
||||
|
||||
@@ -365,7 +365,12 @@ function signed(site, path, { access, userID, body, origin = site.agent, query,
|
||||
return { url: url.toString(), init: { method: json === undefined ? "GET" : "POST", headers, ...(json === undefined ? {} : { body: json }) } }
|
||||
}
|
||||
|
||||
class AccountRefused extends Error {}
|
||||
class AccountRefused extends Error {
|
||||
constructor(message, status) {
|
||||
super(message)
|
||||
this.status = status
|
||||
}
|
||||
}
|
||||
|
||||
// checked throws on an answer MiniMax's account API says failed in its body.
|
||||
function checked(env, what) {
|
||||
@@ -382,7 +387,7 @@ function checked(env, what) {
|
||||
async function accountCall(site, path, opts, what) {
|
||||
const { url, init } = signed(site, path, opts)
|
||||
const res = await fetch(url, { ...init, signal: AbortSignal.timeout(15000) })
|
||||
if (res.status === 401 || res.status === 403) throw new AccountRefused(`${what}: the sign-in was refused (HTTP ${res.status})`)
|
||||
if (res.status === 401 || res.status === 403) throw new AccountRefused(`${what}: the sign-in was refused (HTTP ${res.status})`, res.status)
|
||||
if (!res.ok) throw new Error(`${what}: HTTP ${res.status}`)
|
||||
let env
|
||||
try {
|
||||
@@ -535,12 +540,19 @@ function usageOf(m, windows = []) {
|
||||
// gateway, 0.6.12): as the account, user_id its realUserID — MiniMax Code
|
||||
// won't ask without one, and every minimax-cloud call it makes names the
|
||||
// user — and the desktop's device_platform web, is_desktop 1 and its
|
||||
// version. The international site turns away a check-in asked as user 0
|
||||
// with a 401 while the same token chats (Magic_zero on Discord).
|
||||
// version. Its host is the account API's (agent.minimaxi.com on the China
|
||||
// site, agent.minimax.io on the international one), not the chat host:
|
||||
// MiniMax Code's minimax-cloud origin table has these.
|
||||
//
|
||||
// A 401 there ({"error":"invalid access token"}) is answered as MiniMax
|
||||
// Code answers it: the sign-in renewed (a newer token if one is had, else
|
||||
// refreshed), the user id read again for that token, and the check-in
|
||||
// asked once more. The chat path does the same on its 401, which is why a
|
||||
// token minimax-cloud turned away still chatted (Magic_zero on Discord).
|
||||
const CHECKIN_QUERY = { device_platform: "web", is_desktop: "1", desktop_version: "0.6.12" }
|
||||
|
||||
async function checkinCall(site, access, userID, path, body) {
|
||||
const opts = { access, userID, origin: site.llm, query: CHECKIN_QUERY }
|
||||
const opts = { access, userID, origin: site.agent, query: CHECKIN_QUERY }
|
||||
if (body !== undefined) opts.body = body
|
||||
return accountCall(site, path, opts, "check-in")
|
||||
}
|
||||
@@ -832,10 +844,22 @@ function makePlugin(site) {
|
||||
} catch (e) {
|
||||
return { outcome: "failed", message: e?.message ?? String(e), ...(e?.signIn ? { signIn: e.signIn } : {}) }
|
||||
}
|
||||
const failed = (e) => ({ outcome: "failed", message: e?.message ?? String(e), ...(e?.signIn ? { signIn: e.signIn } : {}) })
|
||||
try {
|
||||
return await checkinOf(site, a.access, a.realUserID)
|
||||
} catch (e) {
|
||||
return { outcome: "failed", message: e?.message ?? String(e), ...(e?.signIn ? { signIn: e.signIn } : {}) }
|
||||
if (!(e instanceof AccountRefused && e.status === 401)) return failed(e)
|
||||
// MiniMax Code's /checkin on a 401: renewed, and asked once more
|
||||
try {
|
||||
;({ a } = await fresh(getAuth, a.access))
|
||||
} catch (e2) {
|
||||
return e2 instanceof SignInExpired ? failed(e2) : failed(e)
|
||||
}
|
||||
try {
|
||||
return await checkinOf(site, a.access, undefined)
|
||||
} catch (e2) {
|
||||
return failed(e2)
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-minimax-auth",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"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",
|
||||
|
||||
Reference in New Issue
Block a user