minimax 0.2.1: a tool with no account named takes magpie's default account
0.2.0's tools took the first site key in plugin-auth.json's file order. magpie's host (accountsOf) takes the bare site id first, else the first site#... key by name. Once a removed sign-in is made again, the bare key sits last in the file, so a tool spent a different account from the one magpie uses by default. The tools now pick the same way the host does. Run on mote (sandbox HOME) at this tree: bun test in packages/minimax, 123 pass, 0 fail; bun scripts/check.mjs, minimax ok. Broken by hand: with file order back, the default-selection test goes red (1 fail). Not tried: a real MiniMax account.
This commit is contained in:
@@ -89,8 +89,10 @@ Webpage reading is available through Magpie's search MCP server, whose
|
||||
`web_fetch` protects loopback and private network addresses.
|
||||
|
||||
Account-backed tools accept `site`: `minimax-code` (China, the default) or
|
||||
`minimax-code-global`. These tools read the chosen site's first stored account
|
||||
from Magpie's `plugin-auth.json` on each call. To choose a particular account,
|
||||
`minimax-code-global`. These tools read the chosen site's default account
|
||||
from Magpie's `plugin-auth.json` on each call: the one stored under the bare
|
||||
site id, else the first `site#…` key by name, as Magpie picks for a request
|
||||
that names no account. To choose a particular account,
|
||||
set `account` to its full stored key, such as `minimax-code#xxxxxx`. The
|
||||
selected account's tokens are renewed by the same refresh logic as chat.
|
||||
A missing account asks you to sign in; the selected account stays fixed
|
||||
|
||||
@@ -1130,8 +1130,11 @@ function createToolRequest({ client, directory }) {
|
||||
throw new Error("MiniMax tools: Magpie's plugin-auth.json could not be read")
|
||||
}
|
||||
if (!store) throw new Error("MiniMax tools: invalid Magpie account store")
|
||||
// Resolve once per call so a retry stays on the same account.
|
||||
id ??= Object.keys(store).find(belongs) ?? site.id
|
||||
// Resolve once per call so a retry stays on the same account. The
|
||||
// default is the one magpie's host takes for a request that names
|
||||
// none (accountsOf): the bare site id, else the first key by name,
|
||||
// never the order the file happens to hold them in.
|
||||
id ??= Object.keys(store).filter(belongs).sort((x, y) => (x === site.id ? -1 : y === site.id ? 1 : x < y ? -1 : x > y ? 1 : 0))[0] ?? site.id
|
||||
return Object.hasOwn(store, id) ? store[id] : undefined
|
||||
}
|
||||
await wait(getAuth())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-minimax-auth",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"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": "./opencode.mjs",
|
||||
|
||||
@@ -32,24 +32,29 @@ async function fixture(store = { "minimax-code": auth() }) {
|
||||
}
|
||||
const path = "/minimax-cloud/api/v1/connectors/tools/call"
|
||||
|
||||
test("default selection follows the first stored account and refresh saves its exact key", async () => {
|
||||
test("default selection is magpie's own (bare id, else first by name) and refresh saves its exact key", async () => {
|
||||
f = fakeMiniMax()
|
||||
f.route("POST /oauth2/token", () => json({ access_token: "default-new", refresh_token: "default-refresh-new", expires_in: 3600 }))
|
||||
f.route("POST " + path, () => json({}))
|
||||
for (const site of ["minimax-code", "minimax-code-global"]) {
|
||||
const key = site + "#first"
|
||||
// the file's order puts the bare id last, as a sign-in made again after
|
||||
// a removal leaves it; magpie still takes the bare id first
|
||||
const t = await fixture({
|
||||
[site + "-other#unrelated"]: auth("unrelated"),
|
||||
[site + "#zzz"]: auth("later-by-name"),
|
||||
[key]: { ...auth("default-old"), refresh: "default-refresh-" + site, expires: Date.now() - 1 },
|
||||
[site]: auth("bare"),
|
||||
})
|
||||
await t.request(site, path, {})
|
||||
expect(f.seen.at(-1).headers.get("authorization")).toBe("Bearer default-new")
|
||||
expect(t.saves.map(s => s.id)).toEqual([key])
|
||||
expect(f.seen.at(-1).headers.get("authorization")).toBe("Bearer bare")
|
||||
expect(t.saves).toHaveLength(0)
|
||||
delete t.store[site]
|
||||
await t.saveStore()
|
||||
await t.request(site, path, {})
|
||||
expect(f.seen.at(-1).headers.get("authorization")).toBe("Bearer default-new")
|
||||
expect(t.saves.map(s => s.id)).toEqual([key])
|
||||
delete t.store[site + "#zzz"]
|
||||
delete t.store[key]
|
||||
t.store[site + "#next"] = auth("next-default")
|
||||
await t.saveStore()
|
||||
|
||||
Reference in New Issue
Block a user