From 43d93b0cf9f78828b6fb2050d3b8657c59ff9a7f Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 15 Oct 2026 17:39:13 +0800 Subject: [PATCH] =?UTF-8?q?devin=200.1.18:=20each=20model=20carries=20the?= =?UTF-8?q?=20price=20Devin=20lists=20for=20it,=20and=20SWE-2=20is=20free?= =?UTF-8?q?=20again=20beside=20its=20Lightning=20variants=20(=E5=A4=AA?= =?UTF-8?q?=E9=99=BD=E3=81=A8=E5=90=91=E6=97=A5=E8=91=B5=20on=20Discord)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 太陽と向日葵 on magpie's Discord: Usage no longer shows what calls through Devin cost. Two causes, both in what the list gives magpie: - Every model went with a price of 0 (runtimeModel's cost), and magpie falls back to models.dev, which has none of Devin's own models (SWE-2, SWE-1.7 Lightning). Devin lists each paid model's price in GetCliModelConfigs: field 32 of a config, one per "Input", "Cached input" and "Output", a float32 in USD per "1M tokens". parsePrices reads it (fields() now keeps a fixed32's bytes), and listed() gives an entry the price its variants share, none when they differ. Read from Devin's own response on 10-15: Opus 5.5 4/20 (cache 0.2), its fast run 8/40, SWE-1.7 Lightning 2.5/12.5, SWE-2 Lightning 1/5, GLM-5.2 1.4/4.4. The Free tier lists none. - Devin now files swe-2-high-, -medium- and -max-lightning under SWE-2 at the High cost tier. A family was free only when every model under it was, so swe-2 lost free (seen in the owner's plugin-providers.json on 0.1.17), and with it 0.1.16's rule that a used-up day and week don't hold SWE-2. A family is now judged by the variants variantFor sends it as: those at an effort and its default. Run: HOME= bun test in packages/devin: 84 pass. prices.test.mjs uses Devin's real GetCliModelConfigs bytes of 10-15, cut to 11 configs (testdata/model-configs-1015.bin, no account data in it). Without the index.mjs change: 3 of its 4 tests red. Broke by hand: the family's free over every model again turns 2 red; cost back at 0 turns 1 red. bun scripts/check.mjs devin: ok. Every price above checked by decoding the full real response with a separate Python reader. Not run: magpie end to end with this version (magpie reads a plugin's price from its next commit on). --- packages/devin/index.mjs | 78 ++++++++++++++---- packages/devin/package.json | 2 +- packages/devin/prices.test.mjs | 66 +++++++++++++++ .../devin/testdata/model-configs-1015.bin | Bin 0 -> 4747 bytes 4 files changed, 131 insertions(+), 15 deletions(-) create mode 100644 packages/devin/prices.test.mjs create mode 100644 packages/devin/testdata/model-configs-1015.bin diff --git a/packages/devin/index.mjs b/packages/devin/index.mjs index 2de2755..e888215 100644 --- a/packages/devin/index.mjs +++ b/packages/devin/index.mjs @@ -234,30 +234,46 @@ function variantFor(families, model, effort) { // run) what all its variants Devin named say; undefined when Devin said // nothing of it or its variants disagree. An entry is free (free: true) when // every variant of Devin's it stands for is in free, the ids Devin says its -// quota doesn't count (parseFree). -function listed(families, keep = [], images = {}, free = new Set()) { +// quota doesn't count (parseFree). A family stands for the variants +// variantFor sends it as, those at an effort and its default, not every +// model Devin files under it: Devin gives SWE-2 three -lightning variants +// at the High cost tier (2026-10-15), which no effort of swe-2 is sent as, +// and with them in, swe-2 was no longer free. An entry's price (cost) is +// what Devin lists for the variants it stands for when they all list the +// same (parsePrices); none when they differ or Devin lists none. +function listed(families, keep = [], images = {}, free = new Set(), prices = new Map()) { const all = (ids) => ids.length > 0 && ids.every((id) => free.has(id)) + const priced = (ids) => { + const ps = ids.map((id) => prices.get(id)) + if (!ps.length || !ps[0] || ps.some((p) => JSON.stringify(p) !== JSON.stringify(ps[0]))) return undefined + return ps[0] + } + const own = (f, t) => { + const ids = Object.values(byLevel(f, t)) + if (!t && f.models.length && !ids.includes(f.models[0].id)) ids.push(f.models[0].id) + return ids + } const out = [] const seen = new Set() - const add = ({ free, ...m }) => { + const add = ({ free, cost, ...m }) => { if (seen.has(m.id)) return seen.add(m.id) - out.push(free ? { ...m, free } : m) + out.push({ ...m, ...(free ? { free } : cost ? { cost } : {}) }) } for (const f of families) { const context = f.models.find((m) => m.context)?.context ?? 0 const output = f.models.find((m) => m.output)?.output ?? 0 const image = familyImages(f, images) - add({ id: f.uid, name: f.label, context, output, efforts: efforts(f, ""), image, free: all(f.models.map((m) => m.id)) }) + add({ id: f.uid, name: f.label, context, output, efforts: efforts(f, ""), image, free: all(own(f, "")), cost: priced(own(f, "")) }) for (const t of tiers(f)) { const id = f.uid + "-" + t if (families.some((g) => named(g, id))) continue - add({ id, name: f.label + " " + TIERS.find(([w]) => w === t)[1], context, output, efforts: efforts(f, t), image, free: all(Object.values(byLevel(f, t))) }) + add({ id, name: f.label + " " + TIERS.find(([w]) => w === t)[1], context, output, efforts: efforts(f, t), image, free: all(own(f, t)), cost: priced(own(f, t)) }) } if (f.models.length === 1) continue for (const m of f.models) { if (m.id === f.uid || tierOf(m.id)[1]) continue - add({ id: m.id, name: m.name, context: m.context || context, output: m.output || output, efforts: [], image: images[m.id], free: free.has(m.id) }) + add({ id: m.id, name: m.name, context: m.context || context, output: m.output || output, efforts: [], image: images[m.id], free: free.has(m.id), cost: prices.get(m.id) }) } } for (const id of keep) { @@ -266,7 +282,7 @@ function listed(families, keep = [], images = {}, free = new Set()) { const m = f?.models.find((m) => m.id === id) const level = tierOf(id)[1] if (!m && !level) continue - add({ id, name: m?.name || id, context: m?.context ?? 0, output: m?.output ?? 0, efforts: level ? [level] : [], image: images[id], free: free.has(id) }) + add({ id, name: m?.name || id, context: m?.context ?? 0, output: m?.output ?? 0, efforts: level ? [level] : [], image: images[id], free: free.has(id), cost: prices.get(id) }) } return out } @@ -346,6 +362,39 @@ function parseFree(b) { return out } +// parsePrices reads the same response for what Devin lists each model at, +// in USD per 1M tokens: a config's model_uid (22) and its prices (32, one +// each), each a label (1: "Input", "Cached input", "Output"), a fixed32 +// float (2) and its unit (3: "1M tokens"). A model in the Free tier lists +// none. Only a price per 1M tokens is taken, and a model is priced only +// when it lists input or output above 0. +function parsePrices(b) { + const out = new Map() + const words = { Input: "input", "Cached input": "read", Output: "output" } + for (const f of fields(b)) { + if (f.num !== 1 || f.wire !== 2) continue + let uid = "" + const p = {} + for (const g of fields(f.data)) { + if (g.num === 22 && g.wire === 2) uid = dec.decode(g.data) + else if (g.num === 32 && g.wire === 2) { + let label = "" + let unit = "" + let v = NaN + for (const h of fields(g.data)) { + if (h.num === 1 && h.wire === 2) label = dec.decode(h.data) + else if (h.num === 3 && h.wire === 2) unit = dec.decode(h.data) + else if (h.num === 2 && h.wire === 5) v = new DataView(h.data.buffer, h.data.byteOffset, 4).getFloat32(0, true) + } + // a float32's 1.4 is 1.39999997…: the price as Devin wrote it + if (words[label] && unit === "1M tokens" && Number.isFinite(v) && v >= 0) p[words[label]] = +v.toPrecision(6) + } + } + if (uid && (p.input > 0 || p.output > 0)) out.set(uid, { input: p.input ?? 0, output: p.output ?? 0, cache: { read: p.read ?? 0 } }) + } + return out +} + // parseConfigFamilies reads the same response as the families `devin // models list` makes of it, in its order: each config's label (1), context // (18), and model_info (23) with its output (13) and family uid (23); the @@ -399,7 +448,7 @@ const said = new Map() // first ask isn't waited for. async function configsFor(key, server, wait = true) { let c = said.get(key) - if (!c) said.set(key, (c = { images: null, families: null, free: new Set(), at: 0, failed: 0, asking: null })) + if (!c) said.set(key, (c = { images: null, families: null, free: new Set(), prices: new Map(), at: 0, failed: 0, asking: null })) const ask = () => (c.asking ??= (async () => { try { @@ -414,7 +463,7 @@ async function configsFor(key, server, wait = true) { const images = parseModelConfigs(b) if (!images) throw new Error("GetCliModelConfigs: no models") const families = parseConfigFamilies(b) - Object.assign(c, { images, families: families.length ? families : null, free: parseFree(b), at: Date.now(), failed: 0 }) + Object.assign(c, { images, families: families.length ? families : null, free: parseFree(b), prices: parsePrices(b), at: Date.now(), failed: 0 }) } catch { c.failed = Date.now() } finally { @@ -495,7 +544,7 @@ function runtimeModel(m) { status: "active", headers: {}, options: {}, - cost: { input: 0, output: 0, cache: { read: 0, write: 0 } }, + cost: { input: m.cost?.input ?? 0, output: m.cost?.output ?? 0, cache: { read: m.cost?.cache?.read ?? 0, write: 0 } }, limit: { context: m.context, output: m.output }, capabilities: { temperature: true, @@ -1008,6 +1057,7 @@ function fields(b) { i += Number(l) } else if (f.wire === 5) { if (i + 4 > b.length) break + f.data = b.subarray(i, i + 4) i += 4 } else break out.push(f) @@ -1757,14 +1807,14 @@ export async function DevinAuthPlugin() { if (auth?.type !== "api" || !auth.key) return provider.models const { key, server } = await live(auth) const images = await imagesFor(key, server) - const { free } = await configsFor(key, server) + const { free, prices } = await configsFor(key, server) const families = await ownFamilies(key, server) if (!families) return withImages(provider.models, listed(familiesOf(SNAPSHOT), Object.keys(provider?.models ?? {}), images)) - return Object.fromEntries(listed(families, Object.keys(provider?.models ?? {}), images, free).map((m) => [m.id, runtimeModel(m)])) + return Object.fromEntries(listed(families, Object.keys(provider?.models ?? {}), images, free, prices).map((m) => [m.id, runtimeModel(m)])) }, }, } } // for tests -export const _internal = { parseFree, geminiSchema, freeIDs, outID, inID, objectRoot, seesImages, imagesFor, forgetSaid: () => said.clear(), parseModelConfigs, parseConfigFamilies, SNAPSHOT_IMAGES, withImages, forgetImages: () => (seen = null), effortOf, runtimeModel, configModel, live, build, failure, complete, parseFamilies, listed, variantFor, familiesOf, SNAPSHOT, parseStatus, readsHome, tierName, whoByKey, success, familiesFor, readCredentials, credentials, fields, frame, PB, events, frames } +export const _internal = { parseFree, parsePrices, geminiSchema, freeIDs, outID, inID, objectRoot, seesImages, imagesFor, forgetSaid: () => said.clear(), parseModelConfigs, parseConfigFamilies, SNAPSHOT_IMAGES, withImages, forgetImages: () => (seen = null), effortOf, runtimeModel, configModel, live, build, failure, complete, parseFamilies, listed, variantFor, familiesOf, SNAPSHOT, parseStatus, readsHome, tierName, whoByKey, success, familiesFor, readCredentials, credentials, fields, frame, PB, events, frames } diff --git a/packages/devin/package.json b/packages/devin/package.json index aad5ed0..94768e0 100644 --- a/packages/devin/package.json +++ b/packages/devin/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-devin-auth", - "version": "0.1.17", + "version": "0.1.18", "description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie", "type": "module", "main": "./index.mjs", diff --git a/packages/devin/prices.test.mjs b/packages/devin/prices.test.mjs new file mode 100644 index 0000000..21d8454 --- /dev/null +++ b/packages/devin/prices.test.mjs @@ -0,0 +1,66 @@ +// 太陽と向日葵 on magpie's Discord (2026-10-15): Usage showed no cost for +// calls through Devin. Devin lists a price for each model it doesn't +// serve free, in USD per 1M tokens, in GetCliModelConfigs (field 32), and +// the list gave every model a price of 0. And Devin now files three +// -lightning variants at the High cost tier under SWE-2, so swe-2, which +// is sent as swe-2-high, -medium or -max, all Free, was no longer free. +import { afterEach, expect, test } from "bun:test" +import { readFileSync } from "node:fs" +import { join } from "node:path" +import { DevinAuthPlugin, _internal } from "./index.mjs" + +const real = globalThis.fetch +afterEach(() => { + globalThis.fetch = real + _internal.forgetSaid() +}) + +// Devin's own response to GetCliModelConfigs (2026-10-15), cut to SWE-2's +// six variants, SWE-1.7 Lightning, Gemini 4 Argon's three and GLM-5.2 +const configs = readFileSync(join(import.meta.dir, "testdata", "model-configs-1015.bin")) + +function serve() { + globalThis.fetch = async (url) => { + if (String(url).endsWith("/GetUserStatus")) return Response.json({ userStatus: { planStatus: { planInfo: { planName: "Teams", isDevin: true }, planEnd: "2026-10-26T21:45:55Z" } } }) + if (String(url).endsWith("/GetCliModelConfigs")) return new Response(configs) + throw new Error("unexpected fetch " + url) + } +} + +test("Devin's prices are read from its model configs, as Devin wrote them", () => { + const p = _internal.parsePrices(new Uint8Array(configs)) + expect(p.get("swe-1-7-lightning")).toEqual({ input: 2.5, output: 12.5, cache: { read: 1 } }) + expect(p.get("swe-2-high-lightning")).toEqual({ input: 1, output: 5, cache: { read: 0.1 } }) + // a float32's 1.4 and 0.26, not 1.39999997… + expect(p.get("glm-5-2")).toEqual({ input: 1.4, output: 4.4, cache: { read: 0.26 } }) + // the Free tier lists none + expect(p.has("swe-2-high")).toBe(false) +}) + +test("the list gives each model Devin's price, and SWE-2 stays free beside its Lightning variants", async () => { + serve() + const got = await (await DevinAuthPlugin()).provider.models({ models: {} }, { auth: { type: "api", key: "key-prices-list" } }) + expect(got["swe-2"].free).toBe(true) + expect(got["swe-2"].cost).toEqual({ input: 0, output: 0, cache: { read: 0, write: 0 } }) + expect(got["swe-2-high-lightning"].free).toBeUndefined() + expect(got["swe-2-high-lightning"].cost).toEqual({ input: 1, output: 5, cache: { read: 0.1, write: 0 } }) + // a family is priced at its variants' one price + expect(got["gemini-4-argon"].cost).toEqual({ input: 1, output: 5, cache: { read: 0.05, write: 0 } }) + const swe17 = got["swe-1.7-lightning"] ?? got["swe-1-7-lightning"] + expect(swe17.cost).toEqual({ input: 2.5, output: 12.5, cache: { read: 1, write: 0 } }) +}) + +test("a family whose variants Devin lists at different prices has none", () => { + const f = { uid: "fam", label: "Fam", aliases: [], models: [{ id: "fam-low" }, { id: "fam-high" }] } + const prices = new Map([["fam-low", { input: 1, output: 2, cache: { read: 0 } }], ["fam-high", { input: 3, output: 6, cache: { read: 0 } }]]) + const [fam] = _internal.listed([f], [], {}, new Set(), prices) + expect(fam.cost).toBeUndefined() + expect(_internal.runtimeModel(fam).cost).toEqual({ input: 0, output: 0, cache: { read: 0, write: 0 } }) +}) + +test("SWE-2 used up a quota doesn't count, with its Lightning variants in the list", async () => { + serve() + const ids = await _internal.freeIDs("key-prices-free", "https://server.self-serve.windsurf.com") + expect(ids).toContain("swe-2") + expect(ids).not.toContain("swe-2-high-lightning") +}) diff --git a/packages/devin/testdata/model-configs-1015.bin b/packages/devin/testdata/model-configs-1015.bin new file mode 100644 index 0000000000000000000000000000000000000000..9c7b1d1f7afc8c3a6a0559836737b3ec1fd3733d GIT binary patch literal 4747 zcmd^CU1(cn7|wf6e!m{J)6;gw!p1=z=-{Ml(%M<+mbBESkZ5tjycldTJx#)zoN#h# zqo5q3f|S9Ae`qH*jaQW6Gw@S9e)9+yi$&s*Gp80`h@LsQG(Wc(i3LZ)80st(;VM7{ z;0C~-04fDYgzm=dj%NnOULt13Sv=A zUICB!XZ^RyGPv}*z5~Wv{b+#2HTm)*D-1)MuDja>R(xkHG3UQ86ETqc*|=T}xF zS>X`gr&A-r58Qs_dnQp(_&6?rqx_U#D;xbqqY-WWcwmZ;;TIKsc|1|Xv|S`)i zU{J45m=acNZjVk{GzT3qHcCZKwP1e`tl)6*Ex5$+W*irmkw zDMoG42nqGX=?lj()Q#ERpwK<6{(_jzKj&TO=S>Cy{~`Q0HQ zFH2?EXDy`y^bSm*eb$|Eyp7_Fm*U*Umi?elghhF)P<<=EU5(9#nq0WUES9Lp2#0MuXXqCi4K*=u299q! zQa{v0y^%Rye<1GdF#0F|XbbuFse-Ph3S!0_j<)RY?wstPP;Y?bIoVdlUZBub3Nd=h zY8;Q1u$C!1B}zTq1?%VH=Y3^L3s^Uy%^2B7syx;)RW^>ymQ;x@P{?OerH9C{9wIyO zBW27y~S7C#jRc~{!=F!Hnh{6-J+avJJK4v zt8&AJa+=SRx*1m|bvL@%BL3&95w}Y_)rc$9o*xZumF>mPOVr*S4VRo~sP1=`2C3AY euWN%0)h&?hk4w9sYdgSyp*^1J(G&l#-SH0w-?5_r literal 0 HcmV?d00001