doubao-work 0.1.13: the built-in models, before the menu is read, are marked fell back

With Doubao closed or the menu read failed, models() served the built-in three (or an older cache) unmarked.

Archivemylife on X (agy-cli): "配置后报存提示成功,再打开还是全部都启用".
The same class as agy-cli 0.1.61: a list that isn't the account's own,
handed back as if it were, makes magpie relist on it and drop the models
the user picked that aren't in it. Marked with
Symbol.for("magpie.fellBack"), magpie's plugin host keeps the last good
list (keepListed) and the picks.

Run (mote-run, HOME=mktemp -d): doubao-work.test.mjs 59 pass on this change: all pass.
Red on the old code with the new test: "models() and usage never start Doubao" fails.
Not tried: a real account.
This commit is contained in:
yetone
2026-11-15 14:03:54 +08:00
parent 6c6677d0f3
commit 42acd18435
3 changed files with 13 additions and 3 deletions
+6 -1
View File
@@ -863,6 +863,9 @@ test("models() and usage never start Doubao: they read from a window already ope
const p = I.createPlugin({ doubao: d })
const listed = await p.provider.models({}, {})
expect(Object.keys(listed).length).toBeGreaterThan(0)
// the built-in three aren't the account's list: magpie keeps the one it
// had, and the models picked from it (Archivemylife on X, agy-cli's sibling)
expect(listed[Symbol.for("magpie.fellBack")]).toBe(true)
const u = await p.auth.usage(async () => ({}))
expect(u.signIn).toBe("kept")
expect(u.error).toContain("没有打开")
@@ -870,7 +873,9 @@ test("models() and usage never start Doubao: they read from a window already ope
// open, the same window is read for both
app.running = async () => 1
d.readAt = 0
expect(Object.values(await p.provider.models({}, {})).map((m) => m.name)).toEqual(WORK)
const read = await p.provider.models({}, {})
expect(Object.values(read).map((m) => m.name)).toEqual(WORK)
expect(read[Symbol.for("magpie.fellBack")]).toBeUndefined()
expect((await p.auth.usage(async () => ({}))).error).toBeUndefined()
expect(started).toBe(0)
fs.rmSync(dir, { recursive: true, force: true })
+6 -1
View File
@@ -79,7 +79,12 @@ export function createPlugin({ doubao = new Doubao(), newId, pick = choose } = {
// a list never read from the menu is read now, so an account that
// signed in before the plugin read menus isn't left with three
if (typeof doubao?.ensureList === "function") await doubao.ensureList({ signal: AbortSignal.timeout(25000) })
return models(modelTable(doubao))
const out = models(modelTable(doubao))
// a menu still never read (Doubao closed, or the read failed) gives
// the built-in three or an older cache: not the account's list, so
// magpie keeps the one it had and the models picked from it
if (typeof doubao?.modelList !== "function" || doubao.tableAt === 0) out[Symbol.for("magpie.fellBack")] = true
return out
},
},
auth: {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-doubao-work-auth",
"version": "0.1.12",
"version": "0.1.13",
"type": "module",
"main": "./opencode.mjs",
"files": [