Repository navigation
Conversation
Reset cards (yetone/magpie#1884) are read from the MiniMax Code login session and can be spent from the card or, off by default, when the weekly quota is exhausted. Off-peak is labeled from MiniMax's published hours; remaining quota is still remains_percent, and Magpie 0.5x is unverified. Co-authored-by: Klarkxy <klarkxy@users.noreply.github.com>
yetone
left a comment
There was a problem hiding this comment.
Thanks for taking #1884 on, and for keeping the use body to source_type / out_biz_no and the switch off by default. The host side checks out: magpie.option(provider, key), cardActions, auth.action(getAuth, provider, { id }), actions[{ id, label, confirm }], usage.resets { count, until } and the option's confirm / labels / descriptions / confirms are all what magpie's host.js reads. Before this can merge, a few things need changing. I reviewed c3fc76a.
1. Spending a card has to be tried on a real account first. On yetone/magpie#1884 the plan was list first, then auto-use, and "使用一张卡是不可撤销的,所以第二步上线前必须先用真实账号验证". The PR says no real API or account was used, and the list and use JSON shapes are guessed. You offered to test on #1884. Before merging the use button and auto-use, please:
- paste one real
reset_card/listreply (ids and tokens redacted) and build the test fixture from it; - use one card through this plugin, and paste the
usereply and theremains_percentreading right after it.
If you'd rather ship sooner, split it: listing the cards (count and soonest expiry) can go first, and the button and auto-use can follow once the real use is recorded.
2. Auto-use spends another card on every reading while the windows still read exhausted. Nothing stops a second spend after the first one. If MiniMax's windows don't read as reset right after use (we don't know yet whether they do), each usage poll spends one more card. A probe at your head (fake server; the use succeeds and removes the card, but remains still says current_weekly_status: 2):
PROBE lag: cards spent by 3 polls = 3
PROBE concurrent: spent ["c1","c1"] (two usage reads at once POST the same card twice)
Please let auto-use spend at most once per account until a reading shows the week no longer exhausted, or until a cooldown long enough for MiniMax to catch up. Share the single-flight with action's using map, so a click and a poll can't both spend. Add tests for both cases.
3. An unknown status counts as an available card. The description says a shape the plugin doesn't know is a failed read, but spentState only knows English words, so { status: 2 } is counted and can be picked to spend:
resetCardsOf([{ out_biz_no: "a", status: 2 }, { out_biz_no: "b", status: 1 }]) → count 2, spend "a"
Until a real reply shows which values mean "available", treat a status the plugin doesn't know as unknown: leave the count out and never spend that card. Don't count it as available.
4. With no weekly window, a spent 5-hour window counts as the plan exhausted. planExhausted([{ name: "5 hours", used: 100 }]) is true through the gating.every fallback, so on a plan whose reply has no weekly window, auto-use spends a card every time the 5-hour window runs out. That's what the description says it doesn't do. Please make it weekly-only (no weekly window means not exhausted), with a test.
5. The new usage tests stop passing on 2026-12-08. soon = NIGHT + 2 * day is 2026-12-07T16:00Z, but usage() compares expiries with the real clock. With Date.now moved 3 days ahead (preload), 4 of the new tests fail:
(fail) the usage card lists reset cards; a failed list leaves the rest of the card
(fail) the usage-card button spends the soonest card; Magpie without cardActions does not
(fail) auto-use is off unless said, and then only when the weekly quota is exhausted
(fail) auto-use does not fire on a free account or without a magpie host
Freeze _internal.now in these tests too, or build the expiries from Date.now().
6. Scope: please take the Off-peak line out of this PR. #1884 doesn't ask for it, and it adds a line to every plan's card that ends "(unverified on Magpie)". A card shouldn't show a claim it says it can't back. If you want it, open its own issue, and it can be argued there once someone has checked whether Magpie's traffic actually gets 0.5×.
7. The auth.type === "api" branch. The plugin only has the oauth method, so this case shouldn't happen. If it did, it would replace the old { error: "not signed in" } with a "Reset cards" aside and signIn: "kept", which hides that the account isn't signed in. Please drop apiKeyUsage and keep the old error. The action hook's refusal is fine.
What I ran at c3fc76a, on Linux (WSL2 magpie-desktop, Bun 1.4.2, temp HOME):
bun test packages/minimax: 242 pass, 0 fail.bun scripts/check.mjs minimax: ok.bun scripts/bumped.mjs origin/main: ok (0.2.13; npm has 0.2.12).- Broken by hand: skipping
spentStateturns 1 test red, auto-use ignoring the switch turns 2 red, and counting a spent 5-hour window turns 2 red. So the tests guard what they name. - My probes for points 2 to 5 (fake server only, not in the PR): quoted above.
- Not tried: anything against a real MiniMax account.
Implements yetone/magpie#1884 in
@magpie-community/opencode-minimax-auth: the usage card lists MiniMax reset cards (限额重置) and can spend one, and it labels MiniMax's published off-peak hours. yetone/magpie#4609 (reset cards granted by check-in) is related; this PR lists whatever the account API returns, including check-in cards, but does not change check-in itself.Reset cards (yetone/magpie#1884)
yetone confirmed the MiniMax Code login-session APIs on
agent.minimax.cn/agent.minimax.io:GET /backend/account/reset_card/list— available cards and expiryPOST /backend/account/reset_card/use— body{ source_type, out_biz_no }taken from a list item; nothing else is sentGET /backend/account/reset_card/flows— 30-day history, not implemented (optional)These are not on the open-platform API Key surface. The plugin reads them with the same signed account client as usage and check-in (
accountCall/siteFetch). The China site still falls back fromagent.minimaxi.comtoagent.minimax.cnwhen the first host cannot be reached. The international site is covered the same way on its own host.Listing. A logged-in usage card reports
resets: { count, until }(available count and the soonest expiry). Magpie already renders that. A list that cannot be read is omitted, same as a failed credit ledger: the rest of the card still shows. A successful empty list iscount: 0, so “none” and “could not read” do not look the same.Use. Magpie that supports
cardActionsdraws a Use a reset card button. The click spends the unexpired card that expires soonest, then Magpie refreshes usage. Using a card is irreversible; the button asks for confirmation.Auto-use. An independent
auto_use_reset_cardsswitch (auth.options) defaults off (defaultomitted; Magpie treats that as off). When on, a usage reading that finds a token plan whose weekly quota is used up, and an unexpired card remaining, spends the soonest-expiring card and re-reads the windows. A spent general 5-hour window is not treated as exhausting the plan (on Go / Explore / Build, M4 / image / video consume only the weekly window). Auto-use does not run for a free account, an API Key, or a host that does not exposemagpie.option.API Key / no plugin login. Only this plugin's MiniMax Code OAuth session can list or use reset cards. An API Key usage card skips the list and says why; the use action is refused.
Off-peak display
Official docs (CN, global): during the promotion, M Plan and Token Plan subscribers using language models in MiniMax Code from 23:00 to 09:00 UTC+8 have subscription quota deducted at 0.5× (double token quota). Automatic, limited-time, MiniMax Code only, subscription quota only (not credit packs), all language models currently in the plan — not M4-specific.
The card adds an aside Off-peak line for a token plan. Remaining quota still comes from
remains_percent/remains. There is no off-peak API field, andweekly_boost_permilleis a plan bonus, not this multiplier. Official docs limit the offer to MiniMax Code; whether Magpie traffic actually gets 0.5× is unverified, and the card does not claim that it does.Host changes
None, and no PR on yetone/magpie. Magpie already has
usage.resets,magpie.cardActions/auth.action, andmagpie.option/auth.options. List, the use button, and the auto-use switch all live in this plugin. An older Magpie withoutcardActionsstill lists cards and has no button; auto-use stays off unless that host exposesoption.Schema assumptions (the list/use JSON is unpublished)
Parsed defensively; a shape this plugin does not know is a failed read, never a made-up zero.
items/list/cards/reset_cards/records/rows, including nested underdata/result/payload, or a bare array there. camelCase variants ofsource_type/out_biz_no/ expiry keys are accepted.expire_at_ms,expire_at,expires_at,expire_time,valid_until,end_time, and camelCase; unix seconds or ms; a Beijing wall time without a zone is UTC+8.used/spent/expired/invalid/unavailable/consumedonly. Unknown numeric statuses are left as available.remaining_count(or similar) with no item array reports the count but cannot spend (nosource_type/out_biz_no).{ source_type, out_biz_no }from the chosen list item.Tests
packages/minimax/usage.test.mjsagainstfake.mjsonly. No real MiniMax API, no real account.weekly_boost_permilleis not the night multiplier242 pass, 0 fail (package tests).
scripts/check.mjs minimaxexits 0.Patch version 0.2.12 → 0.2.13.