qoder 0.2.2, workbuddy 0.1.6: each model's credit rate goes to magpie (rate, rateWas), as magpie's built-ins read it (yetone/magpie 33acb6bc, v0.1.667)
magpie now shows each model's credit rate in the provider's model list and an agent's picker (01huadalang on Discord: pick the cheap models without opening Qoder or WorkBuddy); a plugin gives it beside free on each model its provider.models hook lists. Qoder and Qoder CN: rate is the price_factor (priceFactor); rateWas an active promotion's before_promotion_price_factor, else an original_price_factor above the price (Qwen3.8-Flash: 0x, 0.1x struck through); a promotion's 0 that isn't free is its price before times its discount_factor; a listing with no price gives none — the rule of internal/qoder/models.go's ModelInfo.free. WorkBuddy and WorkBuddy AI: rate is the model's credits ("x0.03" is 0.03; x0.00 stays free; an unreadable, negative or infinite rate is neither free nor rated), as wbCredits reads it.
usage.test.mjs in each package gets a test fed a fake listing / fake /v3/config (the cases of core's TestParseModelsRate and TestWBCreditsRate); both fail against the previous index.mjs and pass now. No request was made to Qoder or WorkBuddy. bun test (HOME a temp dir) and bun scripts/check.mjs pass.
This commit is contained in:
@@ -465,18 +465,29 @@ function modelOf(site, provider, m) {
|
||||
variants: variants(m.efforts),
|
||||
// magpie's own: served at no cost to the plan's credits
|
||||
free: !!m.free,
|
||||
// magpie's own: the credits a request costs, as a multiple (0: none)
|
||||
rate: m.rate ?? 0,
|
||||
}
|
||||
}
|
||||
|
||||
// liveModels asks WorkBuddy's product config for the plan's models: the
|
||||
// "cli" agent's list, each with its details. The CLI User-Agent picks
|
||||
// WorkBuddy's config (a bare WorkBuddy/<v> gets CodeBuddy IDE's, no cli).
|
||||
// creditsOf reads a model's credits, the multiple WorkBuddy's picker shows
|
||||
// by it: "x0.03", "0" or 0; "x0.00" is free. A rate it can't read (or
|
||||
// none, or an infinite one) is undefined: the model is neither free nor
|
||||
// rated. The same rule as magpie's built-in (wbCredits).
|
||||
function creditsOf(c) {
|
||||
if (c == null || c === "") return undefined
|
||||
const s = String(c).trim().toLowerCase().replace(/^x/, "")
|
||||
const n = Number(s)
|
||||
return s !== "" && Number.isFinite(n) && n >= 0 ? n : undefined
|
||||
}
|
||||
|
||||
// freeCredits says whether a model's credits are none: "x0.00", "0" or 0.
|
||||
// A rate it can't read is not free.
|
||||
function freeCredits(c) {
|
||||
if (c == null || c === "") return false
|
||||
const s = String(c).trim().toLowerCase().replace(/^x/, "")
|
||||
return s !== "" && Number.isFinite(Number(s)) && Number(s) === 0
|
||||
return creditsOf(c) === 0
|
||||
}
|
||||
|
||||
async function liveModels(site, a) {
|
||||
@@ -500,7 +511,11 @@ async function liveModels(site, a) {
|
||||
m.context = d.maxInputTokens
|
||||
m.output = d.maxOutputTokens
|
||||
m.images = d.supportsImages === true
|
||||
m.free = freeCredits(d.credits)
|
||||
const r = creditsOf(d.credits)
|
||||
if (r !== undefined) {
|
||||
m.free = r === 0
|
||||
m.rate = r
|
||||
}
|
||||
const es = d.reasoning?.supportedEfforts ?? []
|
||||
if (es.length) {
|
||||
const canOff = d.reasoning?.canDisableThinking
|
||||
@@ -661,4 +676,4 @@ export const WorkBuddyAuthPlugin = makePlugin(SITES.workbuddy)
|
||||
export const WorkBuddyAIAuthPlugin = makePlugin(SITES["workbuddy-ai"])
|
||||
|
||||
// for tests
|
||||
export const _internal = { withSystem, usageOf, desktopHeld, explained, REFUSED_HINT, freeCredits, fresh, SITES }
|
||||
export const _internal = { withSystem, usageOf, desktopHeld, explained, REFUSED_HINT, freeCredits, creditsOf, fresh, SITES }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-workbuddy-auth",
|
||||
"version": "0.1.5",
|
||||
"version": "0.1.6",
|
||||
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
@@ -143,3 +143,40 @@ test("a desktop sign-in with the app signed out says why it failed", async () =>
|
||||
const r = await (await m.authorize()).callback()
|
||||
expect(r).toEqual({ type: "failed", error: "WorkBuddy AI desktop isn't signed in" })
|
||||
})
|
||||
|
||||
// Each model carries the credits WorkBuddy's picker shows by it, as
|
||||
// magpie's built-in reads them (internal/provider/workbuddy_free_test.go,
|
||||
// TestWBCreditsRate): x0.03 is 0.03, X1.00 is 1; x0.00 is free and no
|
||||
// rate, and one it can't read (or an infinite one) is neither.
|
||||
test("each model's rate is its credits", async () => {
|
||||
for (const plugin of [WorkBuddyAuthPlugin, WorkBuddyAIAuthPlugin]) {
|
||||
const calls = serve({ "/v3/config": () => ok({
|
||||
agents: [{ name: "cli", models: ["deepseek-v4.1-flash", "deepseek-v4.1-flash-sg", "gpt-5.5", "kimi-k3", "hy3", "odd", "inf"] }],
|
||||
models: [
|
||||
{ id: "deepseek-v4.1-flash", name: "Deepseek-V4.1-Flash", credits: "x0.00" },
|
||||
{ id: "deepseek-v4.1-flash-sg", name: "Deepseek-V4.1-Flash SG", credits: "x0.03" },
|
||||
{ id: "gpt-5.5", credits: "X1.00" },
|
||||
{ id: "kimi-k3", credits: 1.5 },
|
||||
{ id: "hy3" },
|
||||
{ id: "odd", credits: "lots" },
|
||||
{ id: "inf", credits: "xInfinity" },
|
||||
],
|
||||
}) })
|
||||
const hooks = await plugin({ client: {} })
|
||||
const auth = { type: "oauth", access: "a", refresh: "r", expires: later(), uid: "u", domain: "" }
|
||||
const ms = await hooks.provider.models({ id: hooks.auth.provider, models: {} }, { auth })
|
||||
expect(calls.map((c) => c.url.pathname)).toEqual(["/v3/config"])
|
||||
expect(Object.fromEntries(Object.entries(ms).map(([k, m]) => [k, [m.rate, m.free]]))).toEqual({
|
||||
"deepseek-v4.1-flash": [0, true],
|
||||
"deepseek-v4.1-flash-sg": [0.03, false],
|
||||
"gpt-5.5": [1, false],
|
||||
"kimi-k3": [1.5, false],
|
||||
hy3: [0, false],
|
||||
odd: [0, false],
|
||||
inf: [0, false],
|
||||
})
|
||||
}
|
||||
const { creditsOf } = _internal
|
||||
expect(["x0.03", " X1.00 ", 1.5, "0"].map(creditsOf)).toEqual([0.03, 1, 1.5, 0])
|
||||
for (const c of ["", null, undefined, "free", "x-1", "Infinity"]) expect(creditsOf(c)).toBeUndefined()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user