catpaw 0.1.4: live models carry the client's multiplier and free badge

Reported by star21321321124 (Discord, 0.1.3): LongCat-2.5 showed no
multiplier and no free mark, while the table's LongCat-2.0 is named
"(限时免费)", so users may think it costs credits.

The desktop client (2026.1016.0032, renderer index chunk) draws each
model-types row as: name = description || extendedInfo.shortName ||
modelTypeName; badges = extendedInfo.marketingCopy split on commas;
multiplier = extendedInfo.rateMultiplier + "x". The plugin now reads those:
a live model is named with its badges ("LongCat-2.5 (限时免费)"), carries
magpie's existing `rate` (multiplier) and `free` (marketingCopy says 免费,
or a rate of 0), and a table model gets the list's rate/free unless the
user's config already set one. Ids are unchanged; a missing or unparsable
multiplier shows nothing, not 0.

Run: bun test packages/catpaw on mote (37 pass), bun run check ok. Broke
rateMultiplier parsing by hand: 3 tests red. Not tried: a real CatPaw
account; the fixture's extendedInfo values (string "0"/"1.5", marketingCopy
"限时免费") follow the client code, not a captured reply.
This commit is contained in:
yetone
2026-11-04 01:05:12 +08:00
parent 7e3713233f
commit 75cd0de91c
4 changed files with 64 additions and 7 deletions
+2 -2
View File
@@ -5,8 +5,8 @@ const json = (status, body) => new Response(JSON.stringify(body), { status, head
const defaultModelTypes = () => [
{ modelTypeId: 77, modelTypeName: "LongCat-2.0", provider: "CATPAW", supportImage: true },
{ modelTypeId: 83, modelTypeName: "Kimi-K3", provider: "CATPAW", supportImage: true },
{ modelTypeId: 120, modelTypeName: "LongCat-2.5", provider: "CATPAW", supportImage: true },
{ modelTypeId: 83, modelTypeName: "Kimi-K3", provider: "CATPAW", supportImage: true, extendedInfo: { rateMultiplier: "1.5" } },
{ modelTypeId: 120, modelTypeName: "LongCat-2.5", provider: "CATPAW", supportImage: true, extendedInfo: { rateMultiplier: "0", marketingCopy: "限时免费" } },
{ modelTypeId: -3, modelTypeName: "my-own-model", provider: "USER_CUSTOM", supportImage: false },
]
+44 -3
View File
@@ -70,11 +70,41 @@ function liveModels(rows) {
const name = typeof r.modelTypeName === "string" ? r.modelTypeName.trim() : ""
const id = byType.get(type) ?? name.toLowerCase().replace(/\s+/g, "-")
if (!id || id in out) continue
out[id] = { name: MODELS[id]?.name ?? name, type, image: r.supportImage === true }
const x = extendedOf(r)
const label = (typeof r.description === "string" && r.description.trim()) || (typeof x.shortName === "string" && x.shortName.trim()) || name
// the badges the client draws beside a model's name (extendedInfo.
// marketingCopy, comma-separated: "限时免费"), written the way the table
// writes LongCat-2.0's
const copy = typeof x.marketingCopy === "string" ? x.marketingCopy.split(/[,,]/).map((c) => c.trim()).filter(Boolean) : []
const rate = rateOf(x.rateMultiplier)
const free = copy.some((c) => c.includes("免费")) || rate === 0
out[id] = {
name: MODELS[id]?.name ?? (copy.length ? `${label} (${copy.join("、")})` : label),
type,
image: r.supportImage === true,
...(rate !== undefined ? { rate } : {}),
...(free ? { free: true } : {}),
}
}
return out
}
// extendedInfo as the client reads it: an object (a JSON string is parsed)
function extendedOf(r) {
let x = r?.extendedInfo
if (typeof x === "string") {
try { x = JSON.parse(x) } catch { x = null }
}
return x && typeof x === "object" ? x : {}
}
// the multiplier the client prints as "<n>x" (extendedInfo.rateMultiplier);
// undefined when the vendor gives none, so nothing is shown rather than 0
function rateOf(v) {
const n = typeof v === "number" ? v : typeof v === "string" && /^\s*\d+(?:\.\d+)?\s*[x×]?\s*$/i.test(v) ? Number.parseFloat(v) : NaN
return Number.isFinite(n) && n >= 0 ? n : undefined
}
async function fetchLiveModels(token, signal) {
const res = await fetch(ORIGIN + "/api/agent/maas/model-types", {
method: "POST",
@@ -115,6 +145,9 @@ async function specOf(token, id, signal) {
// window; an invented number would lie to the agent sizing its prompts)
const configModel = (id, m) => ({
name: m.name,
// magpie's own: the credit multiplier and the free mark, as the client shows them
...(m.rate !== undefined ? { rate: m.rate } : {}),
...(m.free ? { free: true } : {}),
})
// ── small helpers ──────────────────────────────────────────────────────────
@@ -706,8 +739,16 @@ export async function CatPawAuthPlugin({ client } = {}) {
}
const live = await liveListFor(token)
if (!live) return provider?.models ?? {}
const extra = Object.fromEntries(Object.entries(live).filter(([id]) => !(id in (provider?.models ?? {}))).map(([id, m]) => [id, configModel(id, m)]))
return { ...(provider?.models ?? {}), ...extra }
const have = provider?.models ?? {}
const extra = Object.fromEntries(Object.entries(live).filter(([id]) => !(id in have)).map(([id, m]) => [id, configModel(id, m)]))
// a table model gets the list's multiplier and free mark unless the
// user's own config already set one
const known = Object.fromEntries(Object.entries(have).map(([id, m]) => {
const l = live[id]
if (!l) return [id, m]
return [id, { ...m, ...(l.rate !== undefined && m.rate === undefined ? { rate: l.rate } : {}), ...(l.free && m.free === undefined ? { free: true } : {}) }]
}))
return { ...known, ...extra }
},
},
async config(config) {
+17 -1
View File
@@ -485,13 +485,29 @@ describe("models the vendor added (the desktop client asks the gateway for its l
const cfg = {}
await plugin.config(cfg)
const got = await plugin.provider.models({ models: cfg.provider.catpaw.models }, { auth: saved })
expect(got["longcat-2.5"]).toEqual({ name: "LongCat-2.5" })
expect(got["longcat-2.5"]).toEqual({ name: "LongCat-2.5 (限时免费)", rate: 0, free: true })
expect(Object.keys(got)).toContain("longcat-2.0")
expect(got["longcat-2.0"].name).toBe("LongCat-2.0 (限时免费)")
// the user's own custom model (negative id) is not the gateway's to serve
expect(Object.keys(got)).not.toContain("my-own-model")
})
test("a table model takes the list's multiplier; the user's own value stays", async () => {
const got = await plugin.provider.models({ models: { "kimi-k3": { name: "Kimi-K3" } } }, { auth: saved })
expect(got["kimi-k3"]).toEqual({ name: "Kimi-K3", rate: 1.5 })
const own = await plugin.provider.models({ models: { "kimi-k3": { name: "Kimi-K3", rate: 9 } } }, { auth: saved })
expect(own["kimi-k3"].rate).toBe(9)
})
test("the multiplier is read as the client reads it, and a missing one is not 0", () => {
const row = (extendedInfo) => ({ modelTypeId: 5, modelTypeName: "X-1", extendedInfo })
expect(_internal.liveModels([row({ rateMultiplier: "2x" })])["x-1"].rate).toBe(2)
expect(_internal.liveModels([row(JSON.stringify({ rateMultiplier: 0.5 }))])["x-1"].rate).toBe(0.5)
expect("rate" in _internal.liveModels([row({})])["x-1"]).toBe(false)
expect("rate" in _internal.liveModels([row({ rateMultiplier: "abc" })])["x-1"]).toBe(false)
expect(_internal.liveModels([row({ shortName: "X One", marketingCopy: "新,限时免费" })])["x-1"]).toEqual({ name: "X One (新、限时免费)", type: 5, image: false, free: true })
})
test("a chat on the new model sends the listed modelType", async () => {
const res = await chatWith("longcat-2.5")
expect(res.status).toBe(200)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-catpaw-auth",
"version": "0.1.3",
"version": "0.1.4",
"description": "OpenCode & Magpie provider plugin for Meituan's 妙手 CatPaw (ai.catpaw.meituan.com): web sign-in or the desktop client's saved credentials, chat through the round/event/turn protocol, models and credit balance",
"type": "module",
"main": "./opencode.mjs",