diff --git a/packages/workbuddy/README.md b/packages/workbuddy/README.md index 51a189c..d4b0ba6 100644 --- a/packages/workbuddy/README.md +++ b/packages/workbuddy/README.md @@ -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:|`) 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 diff --git a/packages/workbuddy/custom.test.mjs b/packages/workbuddy/custom.test.mjs new file mode 100644 index 0000000..4db8d33 --- /dev/null +++ b/packages/workbuddy/custom.test.mjs @@ -0,0 +1,86 @@ +// plugins#1015 (CnsMaple): an enterprise account's own models, +// "custom:|" 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([]) +}) diff --git a/packages/workbuddy/index.mjs b/packages/workbuddy/index.mjs index c91bfaa..d60991c 100644 --- a/packages/workbuddy/index.mjs +++ b/packages/workbuddy/index.mjs @@ -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:|", 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 diff --git a/packages/workbuddy/package.json b/packages/workbuddy/package.json index a6c8f91..0f58383 100644 --- a/packages/workbuddy/package.json +++ b/packages/workbuddy/package.json @@ -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",