workbuddy 0.2.28: list an enterprise's custom: models (#1015)

An enterprise account's own models ("custom:<name>|<name>", modelType
"enterprise") come in /v3/config's models but not in the cli agent's
list. WorkBuddy's CLI (bundled in WorkBuddy 5.5.6, AgentManager.
computeModels) appends every config model whose id starts with
"custom:" to the agent's list itself, after the agent's own ones.
liveModels read only the agent's list, so the models were missing
entirely, and a forced chat to them worked. They are now appended in
the config's order with their context, output, images, price and
efforts, and the id goes to WorkBuddy as given, "|" and all. They stay
on chat (nativeOf matches only a bare claude- id), where the reporter's
chat was served. Both sites share liveModels; nothing else enumerates
the config. The CLI also appends models tagged "custom" or "chat":
those in a desktop's cached config are its local models with their own
url and apiKey, so they stay out.

PR #1016 (yetihan) joined the two spellings instead (an agent-listed
custom:x|x against a bare detail id x); the issue's literal entry,
run against d2e21b7b, lists neither model (expected 2, got 0).

Run (mica, HOME=$(mktemp -d), at a181b898, this change on edc6dbcd;
the rebase onto 934e6b33 adds antigravity commits only):
bun test packages/workbuddy 342 pass, 0 fail across 32 files;
bun scripts/check.mjs exit 0. Earlier the same on mote at dba24067.
The root `bun test` was not run before the push: both machines'
suite.lock were held by other sessions' Go and GUI suites (mica's for
6h), and it is queued on mote behind them; its result goes on #1015.
Broken by hand: the append turned off, 5 of 6 custom.test.mjs red
(the no-cli-agent case passes, as it should); the de-duplication
removed, the "listed once" test red.
Not tried: a real enterprise account; none is available, so the
fixture is the issue's own JSON shape and the "not in the cli agent's
list" placement is inferred from the report and the CLI's code.

Reported-by: CnsMaple
Co-authored-by: zhou.han <18181754+yetihan@users.noreply.github.com>
Refs #1015
This commit is contained in:
yetone
2026-11-12 02:20:29 +08:00
parent 934e6b3312
commit 51f24a363a
4 changed files with 130 additions and 19 deletions
+5
View File
@@ -61,6 +61,11 @@ as WorkBuddy's own client sends them; without them WorkBuddy answers as the
personal account, with the personal plan's models. A browser sign-in made
before 0.1.13 has no enterprise id kept: sign in again.
An enterprise's own models (`custom:<name>|<name>`) are listed after the
plan's, as WorkBuddy's own client lists them, with their context, output,
images and efforts; the id goes to WorkBuddy as it is. Before 0.2.28 they
were left out of the list.
Which account a browser sign-in gives is chosen on WorkBuddy's own sign-in
page. After a phone sign-in it lists the person's accounts (personal, a
team, 「WorkBuddy 教育公益版」…) and binds the one picked to the sign-in, so
+86
View File
@@ -0,0 +1,86 @@
// plugins#1015 (CnsMaple): an enterprise account's own models,
// "custom:<name>|<name>" with modelType "enterprise", are in /v3/config's
// models but in no agent's list. WorkBuddy's CLI appends every "custom:"
// model to the agent's list itself; the plugin read only the agent's list,
// so they were missing. The entries are the issue's shape, word for word.
import { afterEach, expect, test } from "bun:test"
import { _internal } from "./index.mjs"
const real = globalThis.fetch
afterEach(() => (globalThis.fetch = real))
const custom = (name) => ({
id: `custom:${name}|${name}`,
name,
modelType: "enterprise",
maxInputTokens: 256000,
maxOutputTokens: 64000,
supportsImages: true,
supportsReasoning: true,
supportsToolCall: true,
reasoning: { supportedEfforts: ["minimal", "low", "medium", "high", "xhigh", "max"], defaultEffort: "medium", canDisableThinking: true },
})
const config = JSON.stringify({
code: 0,
data: {
agents: [
{ name: "cli", models: ["glm-5.3"] },
{ name: "compact", models: ["glm-5.3"] },
],
models: [
{ id: "glm-5.3", name: "GLM-5.3", maxInputTokens: 1000000, maxOutputTokens: 131072, credits: "x0.08" },
custom("claude-opus-5-5"),
custom("gpt-5.6-sol"),
{ id: "kimi-k2.5", name: "Kimi-K2.5" }, // in no agent's list, and no custom model: left out as before
],
},
})
async function listed(site) {
globalThis.fetch = async () => new Response(config)
return _internal.liveModels(_internal.SITES[site], { access: "a", uid: "u", enterpriseId: "ent-1" })
}
for (const site of ["workbuddy", "workbuddy-ai"]) {
test(`${site}: an enterprise's custom: models are listed after the agent's, id as given`, async () => {
const out = await listed(site)
expect(out.map((m) => m.id)).toEqual(["glm-5.3", "custom:claude-opus-5-5|claude-opus-5-5", "custom:gpt-5.6-sol|gpt-5.6-sol"])
})
test(`${site}: a custom: model carries its context, output, images and efforts`, async () => {
const m = (await listed(site)).find((x) => x.id === "custom:claude-opus-5-5|claude-opus-5-5")
expect(m.name).toBe("claude-opus-5-5")
expect(m.context).toBe(256000)
expect(m.output).toBe(64000)
expect(m.images).toBe(true)
expect(m.efforts).toEqual(["none", "minimal", "low", "medium", "high", "xhigh", "max"])
expect(m.effort).toBe("medium")
// no credits in its entry: neither free nor priced
expect(m.free).toBeUndefined()
expect(m.rate).toBeUndefined()
const info = _internal.modelOf(_internal.SITES[site], { id: site }, m)
expect(info.id).toBe("custom:claude-opus-5-5|claude-opus-5-5")
expect(info.api.id).toBe("custom:claude-opus-5-5|claude-opus-5-5")
// on chat, where the reporter's chat to it was served
expect(info.api.npm).toBe("@ai-sdk/openai-compatible")
expect(info.limit).toEqual({ context: 256000, output: 64000 })
expect(Object.keys(info.variants)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh", "max"])
})
}
test("a custom: model the agent names already is listed once, where the agent put it", async () => {
const cfg = JSON.parse(config)
cfg.data.agents[0].models = ["custom:gpt-5.6-sol|gpt-5.6-sol", "glm-5.3"]
globalThis.fetch = async () => new Response(JSON.stringify(cfg))
const out = await _internal.liveModels(_internal.SITES.workbuddy, { access: "a", uid: "u" })
expect(out.map((m) => m.id)).toEqual(["custom:gpt-5.6-sol|gpt-5.6-sol", "glm-5.3", "custom:claude-opus-5-5|claude-opus-5-5"])
})
test("a config with no cli agent lists nothing, custom: models too", async () => {
const cfg = JSON.parse(config)
cfg.data.agents = [{ name: "compact", models: ["glm-5.3"] }]
globalThis.fetch = async () => new Response(JSON.stringify(cfg))
expect(await _internal.liveModels(_internal.SITES.workbuddy, { access: "a", uid: "u" })).toEqual([])
})
+38 -18
View File
@@ -3425,27 +3425,47 @@ async function liveModels(site, a) {
if (!res.ok) throw new Error(`${site.name}'s config: HTTP ${res.status}`)
if (env.code) throw new Error(`${site.name}'s config: ${env.msg} (${env.code})`)
const cfg = env.data ?? {}
const models = Array.isArray(cfg.models) ? cfg.models : []
const out = []
const seen = new Set()
const add = (id, d) => {
seen.add(id)
const m = { id, name: d?.name || id }
if (d) {
m.context = d.maxInputTokens
m.output = d.maxOutputTokens
m.images = d.supportsImages === true && !textOnly(site, id)
Object.assign(m, priceOf(d, cfg.modelPromotions))
const es = effortsOf(d, site, id)
if (es.length) {
const canOff = d.reasoning?.canDisableThinking
const off = (!d.onlyReasoning && (canOff == null || canOff)) || OFF_TAKEN.has(id)
m.efforts = [...(off ? ["none"] : []), ...es]
const def = defaultEffortOf(d, es)
if (def) m.effort = def
}
}
out.push(m)
}
let cli = false
for (const agent of cfg.agents ?? []) {
if (agent.name !== "cli") continue
for (const id of agent.models ?? []) {
const d = (cfg.models ?? []).find((x) => x.id === id)
const m = { id, name: d?.name || id }
if (d) {
m.context = d.maxInputTokens
m.output = d.maxOutputTokens
m.images = d.supportsImages === true && !textOnly(site, id)
Object.assign(m, priceOf(d, cfg.modelPromotions))
const es = effortsOf(d, site, id)
if (es.length) {
const canOff = d.reasoning?.canDisableThinking
const off = (!d.onlyReasoning && (canOff == null || canOff)) || OFF_TAKEN.has(id)
m.efforts = [...(off ? ["none"] : []), ...es]
const def = defaultEffortOf(d, es)
if (def) m.effort = def
}
}
out.push(m)
cli = true
for (const id of agent.models ?? []) add(id, models.find((x) => x.id === id))
}
// An enterprise's own models ("custom:<name>|<name>", modelType
// "enterprise") come in the config's models, not in the cli agent's
// list: WorkBuddy's CLI (as bundled in WorkBuddy 5.5.6, read from its
// AgentManager.computeModels) appends every model whose id starts with
// "custom:" to the agent's list itself, after the ones the agent names,
// in the config's order (plugins#1015). The id is sent as it is, "|" and
// all: WorkBuddy serves a chat to it. The CLI
// appends models tagged "custom" or "chat" too; those in a desktop's
// config are its own local models, with their own url and apiKey, and
// aren't WorkBuddy's to serve, so they stay out.
if (cli) {
for (const d of models) {
if (typeof d?.id === "string" && d.id.startsWith("custom:") && !seen.has(d.id)) add(d.id, d)
}
}
// tell apart models the config names alike: deepseek-v4.1-flash and
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-workbuddy-auth",
"version": "0.2.27",
"version": "0.2.28",
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
"type": "module",
"main": "./opencode.mjs",