doubao-work 0.1.8: every model in the app's menu is listed, Kimi K3.1 Pro 高速 too (ul3140773077392 on X)

Two causes of a short list:
- Kimi K3.1 Pro and Kimi K3.1 Pro 高速 both became id kimi-k3.1-pro
  (idFor drops Chinese), so tableFrom kept only the first. 高速 is now
  "fast", and two rows that still collide get a numbered id.
- An account that signed in before 0.1.4 had no models.json, so the list
  stayed at the three built-in models until its first request. The
  provider.models hook now reads the menu once when the list was never
  read (queued behind an ask, once a minute at most), and only from an app
  the plugin has started before (its data folder exists).
Picking sends the row's own label to pickModel, unchanged.

Run on mote (Bun, temp HOME): bun test packages/doubao-work 44 pass,
bun scripts/check.mjs doubao-work ok. Tests use the screenshot's ten
literal labels. Broken by hand, each red: the 高速 mapping, the collision
numbering, the ensureList call (3 fail, restored).
Not tried: the real 豆包工作 app (none on mote or this Mac signed in; the
Windows box has only 豆包, unsigned).
This commit is contained in:
yetone
2026-11-12 23:20:25 +08:00
parent 16e753e8bb
commit b195b4f5a9
5 changed files with 71 additions and 3 deletions
+4
View File
@@ -52,6 +52,10 @@ cached list doesn't have (at most once a minute); it is kept in `models.json` un
macOS, `%LOCALAPPDATA%\magpie-doubao-work` on Windows) and read before
anything else. The three models the plugin was written with stay as the
fallback for when the menu cannot be read.
A list never read (an account that signed in before the plugin read menus) is
read when magpie lists the models, once a minute at most, and only from an app
the plugin has started before. Rows whose names differ only in Chinese get
distinct ids: Kimi K3.1 Pro 高速 is `kimi-k3.1-pro-fast`.
Third-party models you added to 豆包工作 yourself (your own API key) are not
served here: the plugin lists only what the app's model menu offers from
+40
View File
@@ -282,6 +282,12 @@ test("idFor names a model from what its menu row says", () => {
expect(idFor("纯中文模型").startsWith("model-")).toBe(true)
})
test("Kimi K3.1 Pro and Kimi K3.1 Pro 高速 are two models, and an unspellable suffix never merges two rows", () => {
expect(idFor("Kimi K3.1 Pro 高速")).toBe("kimi-k3.1-pro-fast")
const t = tableFrom([{ label: "Kimi K3.1 Pro" }, { label: "Kimi K3.1 Pro 高速" }, { label: "星火 4.0 快" }, { label: "星火 4.0 慢" }])
expect(Object.values(t).map((m) => m.label)).toEqual(["Kimi K3.1 Pro", "Kimi K3.1 Pro 高速", "星火 4.0 快", "星火 4.0 慢"])
})
test("tableFrom keeps every model row, and falls back when nothing was read", () => {
const t = tableFrom([{ label: "自动" }, { label: "GLM 5.3" }, { label: "GLM 5.3" }, { label: "" }])
expect(Object.keys(t)).toEqual(["auto", "glm-5.3"])
@@ -656,3 +662,37 @@ test("the plugin asks Doubao's menu again for a model its list lacks, and names
expect((await loader.fetch(req({ model: "auto", messages: [{ role: "user", content: "hi" }] }))).status).toBe(200)
expect(asked).toEqual(["kimi-k3", "gpt-9"])
})
test("a list never read from the menu is read when the plugin lists models, once a minute at most", async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "doubao-models-"))
const labels = ["自动", "豆包 2.1 Lite", "豆包 2.1 Pro", "DeepSeek V4.1 Flash", "Kimi K3.1 Pro", "Kimi K3.1 Pro 高速", "Kimi K3", "GLM 5.3", "GLM 5.3 Flash", "DeepSeek V4 Pro"]
const page = fakePage([], { steps: { menu: { rows: labels.map((label) => ({ label })) } } })
const d = new Doubao({ app: { start: async () => 1, dataDir: dir }, openPage: async () => page, poll: 1 })
const p = I.createPlugin({ doubao: d })
const listed = await p.provider.models({}, {})
expect(Object.values(listed).map((m) => m.name)).toEqual(labels)
await p.provider.models({}, {})
expect(page.calls.filter((c) => c === MENU).length).toBe(1)
// a menu that fails is not asked again within the minute
const bad = fakePage([], { steps: { menu: { error: "no model menu" } } })
const dir2 = fs.mkdtempSync(path.join(os.tmpdir(), "doubao-models-"))
const d2 = new Doubao({ app: { start: async () => 1, dataDir: dir2 }, openPage: async () => bad, poll: 1 })
await d2.ensureList(); await d2.ensureList()
expect(bad.calls.filter((c) => c === MENU).length).toBe(1)
expect(Object.keys(d2.modelList())).toEqual(Object.keys(MODELS))
// an app never started by the plugin (no data folder) is not opened
const d3 = new Doubao({ app: { start: async () => { throw new Error("opened") }, dataDir: path.join(dir, "none") }, openPage: async () => page })
await d3.ensureList()
fs.rmSync(dir, { recursive: true, force: true }); fs.rmSync(dir2, { recursive: true, force: true })
})
test("picking a model from the full list presses that row in the app", async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "doubao-models-"))
fs.writeFileSync(path.join(dir, "models.json"), JSON.stringify({ at: Date.now(), models: tableFrom([{ label: "自动" }, { label: "Kimi K3.1 Pro 高速" }, { label: "DeepSeek V4 Pro" }]) }))
const page = fakePage([{ sends: 1, reply: true, text: "ok", reasoning: "", finished: true, reason: "succeed" }])
const d = new Doubao({ app: { start: async () => 1, dataDir: dir }, openPage: async () => page, poll: 1 })
expect(Object.keys(d.modelList())).toEqual(["auto", "kimi-k3.1-pro-fast", "deepseek-v4-pro"])
await d.ask("x", { model: "kimi-k3.1-pro-fast" })
expect(page.calls.some((c) => c.includes('"Kimi K3.1 Pro 高速"'))).toBe(true)
fs.rmSync(dir, { recursive: true, force: true })
})
+23 -2
View File
@@ -40,6 +40,7 @@ export function idFor(label) {
if (!text || text === "自动") return "auto"
let id = text
.replace(/豆包/g, "doubao ")
.replace(/高速/g, " fast ")
.toLowerCase()
.replace(/[^a-z0-9.]+/g, "-")
.replace(/-{2,}/g, "-")
@@ -61,8 +62,11 @@ export function tableFrom(rows) {
for (const r of rows ?? []) {
const label = String(r?.label ?? "").trim()
if (!label) continue
const id = idFor(label)
if (out[id]) continue
let id = idFor(label)
if (out[id]?.label === label) continue
// two rows whose names differ only in what idFor can't spell (a
// Chinese suffix) must not become one model
for (let n = 2; out[id]; n++) id = idFor(label) + "-" + n
out[id] = { label, name: label }
}
if (!Object.keys(out).length) return { ...MODELS }
@@ -392,6 +396,7 @@ export class Doubao {
this.app = app
Object.assign(this, { openPage, poll, idle, total, fresh })
this.missAt = 0
this.readAt = 0
this.cacheFile = this.app?.dataDir ? path.join(this.app.dataDir, "models.json") : ""
this.table = null
this.tableAt = 0
@@ -451,6 +456,22 @@ export class Doubao {
return table
}
// ensureList reads the menu once when it has never been read, for an
// account that signed in before the plugin read menus (or whose sign-in
// read failed): without it the list stays at the three built-in models
// until the first request. Only an app this plugin has started before
// (its data folder exists) is opened for it; a failed read is tried
// again after a minute. It queues behind a running ask.
async ensureList({ signal } = {}) {
this.modelList()
if (this.tableAt || !this.app?.start || !this.cacheFile) return
if (!fs.existsSync(path.dirname(this.cacheFile)) || Date.now() - this.readAt < 60000) return
this.readAt = Date.now()
const run = this.queue.then(() => this.tableAt || this.discover({ signal }))
this.queue = run.catch(() => {})
try { await run } catch {}
}
// known says whether Doubao offers model. A model the list read last
// doesn't have sends the plugin back to the menu at once (Doubao adds
// models between reads, #1048), at most once a minute, so a client
+3
View File
@@ -61,6 +61,9 @@ export function createPlugin({ doubao = new Doubao(), newId, pick = choose } = {
provider: {
id: ID,
async models() {
// 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))
},
},
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-doubao-work-auth",
"version": "0.1.7",
"version": "0.1.8",
"type": "module",
"main": "./opencode.mjs",
"files": [