diff --git a/packages/devin/README.md b/packages/devin/README.md index e195987..6e77252 100644 --- a/packages/devin/README.md +++ b/packages/devin/README.md @@ -70,14 +70,16 @@ default. Variants at no effort (`glm-5-2-1m`) are listed as they are. Adaptive and Fusion aren't listed; they route between models inside Devin's own agent. -The `config` hook declares Devin's list as of 2026-09-30 (87 models). -Once signed in, and with the CLI installed, the `provider.models` hook -replaces it with the account's own, from `devin models list`, when the CLI -answers for the account: it reads the plugin's data folder for it, and -names the account Devin names the token's. When it doesn't (on Windows), -the account keeps the declared list. The list is -cached for 5 minutes; after a failed read, the plugin tries again after 1 -minute. +The `config` hook declares Devin's list as of 2026-10-14 (89 models). +Once signed in, the `provider.models` hook replaces it with the account's +own: what Devin tells the CLI's model picker for the account's token +(`GetCliModelConfigs`, the list `devin models list` prints), with or +without the CLI and on every system. When Devin can't be asked, the list +is the CLI's `devin models list`, if the CLI names the account Devin names +the token's (on Windows it reads its own sign-in whatever folder it is +given, so it answers only for that account); else the declared list. The +list is cached for 5 minutes; after a failed read, the plugin tries again +after 1 minute. Which models take images is what Devin tells its CLI's model picker (`GetCliModelConfigs`, each model's `supports_images`), asked once signed diff --git a/packages/devin/identity.test.mjs b/packages/devin/identity.test.mjs index 23ffe2d..f4323cf 100644 --- a/packages/devin/identity.test.mjs +++ b/packages/devin/identity.test.mjs @@ -8,7 +8,7 @@ import { afterAll, afterEach, beforeEach, expect, test } from "bun:test" import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" -import { _internal } from "./index.mjs" +import { DevinAuthPlugin, _internal } from "./index.mjs" const real = globalThis.fetch const env = { ...process.env } @@ -40,6 +40,7 @@ beforeEach(() => { delete process.env.FAKE_HONOURS delete process.env.FAKE_EMAIL rmSync(log, { force: true }) + asked.length = 0 }) afterEach(() => { globalThis.fetch = real @@ -49,9 +50,15 @@ afterAll(() => rmSync(tmp, { recursive: true, force: true })) const runs = () => (existsSync(log) ? readFileSync(log, "utf8").trim().split("\n") : []) -// GetUserStatus for each key: b's is B's account -const devin = (byKey) => { +// GetUserStatus for each key: b's is B's account. GetCliModelConfigs +// answers with configs (a response body) when given, and 503 when not. +const asked = [] +const devin = (byKey, configs) => { globalThis.fetch = async (url, init) => { + asked.push(String(url).split("/").pop()) + if (String(url) === "https://server.codeium.com/exa.api_server_pb.ApiServerService/GetCliModelConfigs") { + return configs ? new Response(configs) : new Response("", { status: 503 }) + } expect(String(url)).toBe("https://server.codeium.com/exa.seat_management_pb.SeatManagementService/GetUserStatus") return byKey(JSON.parse(init.body).metadata.apiKey) } @@ -124,3 +131,52 @@ test("readsHome and tierName", () => { expect(tierName("TEAMS_TIER_UNSPECIFIED")).toBe("") expect(tierName(undefined)).toBe("") }) + +// Devin's own response to GetCliModelConfigs (2026-10-14), cut to a few of +// its configs: SWE-2, Gemini 4 Argon, GLM-5.2, DeepSeek V4 Flash and +// MODEL_PRIVATE_11, which names no family +const realConfigs = readFileSync(join(import.meta.dir, "testdata", "model-configs.bin")) + +test("Devin's model configs are read as the families `devin models list` prints", () => { + const fams = _internal.parseConfigFamilies(new Uint8Array(realConfigs)) + expect(fams.map((f) => [f.uid, f.label, f.aliases])).toEqual([ + ["swe-2", "SWE-2", ["swe"]], + ["gemini-4-argon", "Gemini 4 Argon", []], + ["glm-5.2", "GLM-5.2", []], + ["deepseek-v4-flash", "DeepSeek V4 Flash", []], + ["Claude Haiku 4.5", "Claude Haiku 4.5", []], + ]) + expect(fams[1].models).toEqual([ + { id: "gemini-4-argon-medium", name: "Gemini 4 Argon Medium", context: 1048576, output: 1000000 }, + { id: "gemini-4-argon-low", name: "Gemini 4 Argon Low", context: 1048576, output: 1000000 }, + { id: "gemini-4-argon-high", name: "Gemini 4 Argon High", context: 1048576, output: 1000000 }, + ]) + expect(fams[4].models).toEqual([{ id: "MODEL_PRIVATE_11", name: "Claude Haiku 4.5", context: 200000, output: 64000 }]) +}) + +test.if(unix)("an account the CLI doesn't answer for gets Devin's list for its key, Gemini 4 Argon in it (plugins #115)", async () => { + // as on Windows: the CLI reads its own credentials.toml, signed in as A + devin(() => statusOf("b@x.dev"), realConfigs) + const fams = await _internal.familiesFor("key-models-win", "https://server.codeium.com") + expect(fams.map((f) => f.uid)).toContain("gemini-4-argon") + expect(fams.map((f) => f.uid)).not.toContain("cli-only") + expect(runs()).toEqual([]) + expect(asked).toEqual(["GetCliModelConfigs"]) +}, SLOW) + +test.if(unix)("a CLI that reads its own folder but is signed in as the key's account gives its list when Devin can't be asked", async () => { + // as on Windows, the CLI signed in to the same account as the key + process.env.FAKE_EMAIL = "b@x.dev" + devin(() => statusOf("B@x.dev")) + const fams = await _internal.familiesFor("key-models-win-same", "https://server.codeium.com") + expect(fams.map((f) => f.uid)).toEqual(["cli-only"]) + expect(runs()).toEqual(["auth status", "models list --format json"]) +}, SLOW) + +test.if(unix)("a list the plugin is asked for names Gemini 4 Argon for an account the CLI doesn't answer for", async () => { + devin(() => statusOf("b@x.dev"), realConfigs) + const got = await (await DevinAuthPlugin()).provider.models({ models: {} }, { auth: { type: "api", key: "key-models-list" } }) + expect(Object.keys(got)).toContain("gemini-4-argon") + expect(got["gemini-4-argon"].name).toBe("Gemini 4 Argon") + expect(got["glm-5.2"].capabilities.input.image).toBe(false) +}, SLOW) diff --git a/packages/devin/images.test.mjs b/packages/devin/images.test.mjs index 7bcd970..cd5f1c1 100644 --- a/packages/devin/images.test.mjs +++ b/packages/devin/images.test.mjs @@ -33,13 +33,17 @@ const withoutCli = () => { } // configs is a GetCliModelConfigsResponse naming each id, with -// supports_images set where it is true (proto3 leaves a false one out) +// supports_images set where it is true (proto3 leaves a false one out), +// and the id's family as SNAPSHOT has it (model_info's family uid, the +// family metadata's label), as Devin's own response has them const configs = (said) => { const out = new PB() for (const [id, images] of Object.entries(said)) { const c = new PB().str(1, "label " + id) if (images) c.varint(5, 1) - out.bytes(1, c.str(22, id)) + const fam = SNAPSHOT.find(([, , , vs]) => vs.some(([v]) => v === id)) + if (fam) c.bytes(23, new PB().str(23, fam[0]).done()).bytes(30, new PB().str(1, fam[1]).done()) + out.bytes(1, c.str(22, id).done()) } return out.done() } @@ -94,11 +98,10 @@ test("an account's list without the CLI takes what Devin says of images now", as expect(asked[0].url).toBe("https://server.codeium.com/exa.api_server_pb.ApiServerService/GetCliModelConfigs") expect(asked[0].headers).toEqual({ "Content-Type": "application/proto", "Connect-Protocol-Version": "1" }) expect(new TextDecoder().decode(asked[0].body)).toContain("devin-key") - expect(got["swe-2"].capabilities).toEqual({ attachment: true, input: { text: true, image: true } }) + expect(got["swe-2"].capabilities).toMatchObject({ attachment: true, input: { text: true, image: true } }) // Devin's word now over the snapshot's expect(got["deepseek-v4-flash"].capabilities.input.image).toBe(true) expect(got["glm-5.2"].capabilities.input.image).toBe(false) - expect(got["not-devins"]).toEqual(given["not-devins"]) }) test("when Devin can't be asked, the list takes the snapshot's word", async () => { diff --git a/packages/devin/index.mjs b/packages/devin/index.mjs index a28ba4c..15db7e3 100644 --- a/packages/devin/index.mjs +++ b/packages/devin/index.mjs @@ -34,11 +34,13 @@ const RETRY = 60 * 1000 // ---- models --------------------------------------------------------------------- -// Devin's list as `devin models list --format json` gave it (2026-09-30), +// Devin's list as `devin models list --format json` gave it (2026-10-14), // less Adaptive and Fusion, which route between models inside Devin's own // agent and aren't served by the API: family id, label, aliases, and each -// variant's id, label, context and output. The CLI's list, when the CLI is -// installed, replaces it. +// variant's id, label, context and output. Inkling and Claude Sonnet 4.5, +// gone from that list, stay for the accounts still offered them. The +// account's own list, from Devin (GetCliModelConfigs) or else the CLI, +// replaces it. const SNAPSHOT = [ ["swe-2","SWE-2",["swe"],[["swe-2-high","SWE-2 High",262000,128000],["swe-2-medium","SWE-2 Medium",262000,128000],["swe-2-max","SWE-2 Max",262000,128000]]], ["swe-1.7-lightning","SWE-1.7 Lightning",[],[["swe-1-7-lightning","SWE-1.7 Lightning Max",202752,96000],["swe-1-7-lightning-medium","SWE-1.7 Lightning Medium",202752,96000]]], @@ -47,6 +49,7 @@ const SNAPSHOT = [ ["gpt-6-astra","GPT-6 Astra",[],[["gpt-6-astra-medium","GPT-6 Astra Medium Thinking",1000000,128000],["gpt-6-astra-low","GPT-6 Astra Low Thinking",1000000,128000],["gpt-6-astra-high","GPT-6 Astra High Thinking",1000000,128000],["gpt-6-astra-xhigh","GPT-6 Astra XHigh Thinking",1000000,128000],["gpt-6-astra-max","GPT-6 Astra Max Thinking",1000000,128000],["gpt-6-astra-low-priority","GPT-6 Astra Low Thinking Fast",1000000,128000],["gpt-6-astra-medium-priority","GPT-6 Astra Medium Thinking Fast",1000000,128000],["gpt-6-astra-high-priority","GPT-6 Astra High Thinking Fast",1000000,128000],["gpt-6-astra-xhigh-priority","GPT-6 Astra XHigh Thinking Fast",1000000,128000],["gpt-6-astra-max-priority","GPT-6 Astra Max Thinking Fast",1000000,128000]]], ["gpt-6-sol","GPT-6 Sol",[],[["gpt-6-sol-medium","GPT-6 Sol Medium Thinking",1000000,128000],["gpt-6-sol-none","GPT-6 Sol No Thinking",1000000,128000],["gpt-6-sol-low","GPT-6 Sol Low Thinking",1000000,128000],["gpt-6-sol-high","GPT-6 Sol High Thinking",1000000,128000],["gpt-6-sol-xhigh","GPT-6 Sol XHigh Thinking",1000000,128000],["gpt-6-sol-max","GPT-6 Sol Max Thinking",1000000,128000],["gpt-6-sol-none-priority","GPT-6 Sol No Thinking Fast",1000000,128000],["gpt-6-sol-low-priority","GPT-6 Sol Low Thinking Fast",1000000,128000],["gpt-6-sol-medium-priority","GPT-6 Sol Medium Thinking Fast",1000000,128000],["gpt-6-sol-high-priority","GPT-6 Sol High Thinking Fast",1000000,128000],["gpt-6-sol-xhigh-priority","GPT-6 Sol XHigh Thinking Fast",1000000,128000],["gpt-6-sol-max-priority","GPT-6 Sol Max Thinking Fast",1000000,128000]]], ["gpt-6-luna","GPT-6 Luna",[],[["gpt-6-luna-medium","GPT-6 Luna Medium Thinking",1000000,128000],["gpt-6-luna-none","GPT-6 Luna No Thinking",1000000,128000],["gpt-6-luna-low","GPT-6 Luna Low Thinking",1000000,128000],["gpt-6-luna-high","GPT-6 Luna High Thinking",1000000,128000],["gpt-6-luna-xhigh","GPT-6 Luna XHigh Thinking",1000000,128000],["gpt-6-luna-max","GPT-6 Luna Max Thinking",1000000,128000],["gpt-6-luna-none-priority","GPT-6 Luna No Thinking Fast",1000000,128000],["gpt-6-luna-low-priority","GPT-6 Luna Low Thinking Fast",1000000,128000],["gpt-6-luna-medium-priority","GPT-6 Luna Medium Thinking Fast",1000000,128000],["gpt-6-luna-high-priority","GPT-6 Luna High Thinking Fast",1000000,128000],["gpt-6-luna-xhigh-priority","GPT-6 Luna XHigh Thinking Fast",1000000,128000],["gpt-6-luna-max-priority","GPT-6 Luna Max Thinking Fast",1000000,128000]]], + ["gemini-4-argon","Gemini 4 Argon",[],[["gemini-4-argon-medium","Gemini 4 Argon Medium",1048576,1000000],["gemini-4-argon-low","Gemini 4 Argon Low",1048576,1000000],["gemini-4-argon-high","Gemini 4 Argon High",1048576,1000000]]], ["kimi-k3","Kimi K3",[],[["kimi-k3-high","Kimi K3 High",1048576,131072],["kimi-k3-low","Kimi K3 Low",1048576,131072],["kimi-k3-max","Kimi K3 Max",1048576,131072]]], ["glm-5.2","GLM-5.2",[],[["glm-5-2","GLM-5.2 High",200000,128000],["glm-5-2-max","GLM-5.2 Max",200000,128000],["glm-5-2-1m","GLM-5.2 High 1M",1000000,128000],["glm-5-2-max-1m","GLM-5.2 Max 1M",1000000,128000],["glm-5-2-none","GLM-5.2 No Thinking",200000,128000],["glm-5-2-none-1m","GLM-5.2 No Thinking 1M",1000000,128000]]], ["glm-5-3","GLM-5.3",[],[["glm-5-3-low","GLM-5.3 Low",1048576,128000],["glm-5-3-high","GLM-5.3 High",1048576,128000],["glm-5-3-max","GLM-5.3 Max",1048576,128000]]], @@ -57,6 +60,7 @@ const SNAPSHOT = [ ["claude-opus-5","Claude Opus 5",["opus"],[["claude-opus-5-medium","Claude Opus 5 Medium",1000000,128000],["claude-opus-5-low","Claude Opus 5 Low",1000000,128000],["claude-opus-5-high","Claude Opus 5 High",1000000,128000],["claude-opus-5-xhigh","Claude Opus 5 XHigh",1000000,128000],["claude-opus-5-max","Claude Opus 5 Max",1000000,128000],["claude-opus-5-low-fast","Claude Opus 5 Low Fast",1000000,128000],["claude-opus-5-medium-fast","Claude Opus 5 Medium Fast",1000000,128000],["claude-opus-5-high-fast","Claude Opus 5 High Fast",1000000,128000],["claude-opus-5-xhigh-fast","Claude Opus 5 XHigh Fast",1000000,128000],["claude-opus-5-max-fast","Claude Opus 5 Max Fast",1000000,128000]]], ["claude-5-fable","Claude Fable 5",[],[["claude-5-fable-low","Claude Fable 5 Low",1000000,128000],["claude-5-fable-medium","Claude Fable 5 Medium",1000000,128000],["claude-5-fable-high","Claude Fable 5 High",1000000,128000],["claude-5-fable-xhigh","Claude Fable 5 XHigh",1000000,128000],["claude-5-fable-max","Claude Fable 5 Max",1000000,128000]]], ["claude-sonnet-5","Claude Sonnet 5",["claude","sonnet"],[["claude-sonnet-5-low","Claude Sonnet 5 Low",1000000,128000],["claude-sonnet-5-medium","Claude Sonnet 5 Medium",1000000,128000],["claude-sonnet-5-high","Claude Sonnet 5 High",1000000,128000],["claude-sonnet-5-xhigh","Claude Sonnet 5 XHigh",1000000,128000],["claude-sonnet-5-max","Claude Sonnet 5 Max",1000000,128000]]], + ["claude-haiku-5-5","Claude Haiku 5.5",[],[["claude-haiku-5-5-low","Claude Haiku 5.5 Low",1000000,128000],["claude-haiku-5-5-medium","Claude Haiku 5.5 Medium",1000000,128000],["claude-haiku-5-5-high","Claude Haiku 5.5 High",1000000,128000],["claude-haiku-5-5-xhigh","Claude Haiku 5.5 XHigh",1000000,128000],["claude-haiku-5-5-max","Claude Haiku 5.5 Max",1000000,128000]]], ["gemini-3.5-flash","Gemini 3.5 Flash",[],[["gemini-3-5-flash-minimal","Gemini 3.5 Flash Minimal",1048576,65535],["gemini-3-5-flash-low","Gemini 3.5 Flash Low",1048576,65535],["gemini-3-5-flash-medium","Gemini 3.5 Flash Medium",1048576,65535],["gemini-3-5-flash-high","Gemini 3.5 Flash High",1048576,65535]]], ["gemini-3.6-flash","Gemini 3.6 Flash",[],[["gemini-3-6-flash-minimal","Gemini 3.6 Flash Minimal",1048576,65535],["gemini-3-6-flash-low","Gemini 3.6 Flash Low",1048576,65535],["gemini-3-6-flash-medium","Gemini 3.6 Flash Medium",1048576,65535],["gemini-3-6-flash-high","Gemini 3.6 Flash High",1048576,65535]]], ["gemini-3-7-flash","Gemini 3.7 Flash",[],[["gemini-3-7-flash-low","Gemini 3.7 Flash Low",1048576,65535],["gemini-3-7-flash-medium","Gemini 3.7 Flash Medium",1048576,65535],["gemini-3-7-flash-high","Gemini 3.7 Flash High",1048576,65535]]], @@ -91,7 +95,7 @@ const SNAPSHOT = [ ["swe-1.6-fast","SWE-1.6 Fast",[],[["swe-1-6-fast","SWE-1.6 Fast",200000,128000]]], ["gemini-3.1-pro","Gemini 3.1 Pro",[],[["gemini-3-1-pro-low","Gemini 3.1 Pro Low Thinking",1048576,65535],["gemini-3-1-pro-high","Gemini 3.1 Pro High Thinking",1048576,65535]]], ["gemini-3.0-flash","Gemini 3 Flash",[],[["MODEL_GOOGLE_GEMINI_3_0_FLASH_MINIMAL","Gemini 3 Flash Minimal",1048576,65535],["MODEL_GOOGLE_GEMINI_3_0_FLASH_LOW","Gemini 3 Flash Low",1048576,65535],["MODEL_GOOGLE_GEMINI_3_0_FLASH_MEDIUM","Gemini 3 Flash Medium",1048576,65535],["MODEL_GOOGLE_GEMINI_3_0_FLASH_HIGH","Gemini 3 Flash High",1048576,65535]]], - ["deepseek-v4-pro","DeepSeek V4 Pro",[],[["deepseek-v4-pro-high","DeepSeek V4 Pro High",1048576,384000],["deepseek-v4-pro-max","DeepSeek V4 Pro Max",1048576,384000]]] + ["deepseek-v4-pro","DeepSeek V4 Pro",[],[["deepseek-v4-pro-high","DeepSeek V4 Pro High",1048576,384000],["deepseek-v4-pro-max","DeepSeek V4 Pro Max",1048576,384000]]], ] const familiesOf = (rows) => rows.map(([uid, label, aliases, vs]) => ({ uid, label, aliases, models: vs.map(([id, name, context, output]) => ({ id, name, context, output })) })) @@ -313,15 +317,60 @@ function parseModelConfigs(b) { return Object.keys(out).length ? out : null } -// Each account's word on images, kept and asked again as its list is. +// 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 +// family's label is its family_metadata's (30) first field. A config that +// names no family is a family of its own under its label, as the CLI makes +// MODEL_PRIVATE_11 "Claude Haiku 4.5". The aliases are the CLI's own, so +// they are taken from SNAPSHOT's family of the same id. +function parseConfigFamilies(b) { + const fams = new Map() + for (const f of fields(b)) { + if (f.num !== 1 || f.wire !== 2) continue + let uid = "" + let name = "" + let context = 0 + let output = 0 + let fam = "" + let famLabel = "" + for (const g of fields(f.data)) { + if (g.num === 22 && g.wire === 2) uid = dec.decode(g.data) + else if (g.num === 1 && g.wire === 2) name = dec.decode(g.data) + else if (g.num === 18 && g.wire === 0) context = g.n + else if (g.num === 23 && g.wire === 2) { + for (const h of fields(g.data)) { + if (h.num === 13 && h.wire === 0) output = h.n + else if (h.num === 23 && h.wire === 2) fam = dec.decode(h.data) + } + } else if (g.num === 30 && g.wire === 2) { + for (const h of fields(g.data)) if (h.num === 1 && h.wire === 2) famLabel = dec.decode(h.data) + } + } + if (!uid) continue + const id = fam || famLabel || name || uid + const low = id.toLowerCase() + if (low === "adaptive" || low === "fusion") continue + let e = fams.get(id) + if (!e) { + const known = SNAPSHOT.find(([u]) => u === id) + fams.set(id, (e = { uid: id, label: famLabel || name || id, aliases: known ? known[2] : [], models: [] })) + } + e.models.push({ id: uid, name: name || uid, context, output }) + } + return [...fams.values()] +} + +// Each account's word on images and its list, kept and asked again as the +// CLI's list is. const said = new Map() -// imagesFor is what Devin says of each model id's images for key's -// account, SNAPSHOT_IMAGES under it; with wait false, a first ask isn't -// waited for. -async function imagesFor(key, server, wait = true) { +// configsFor is what Devin last said of key's account's models +// ({images, families}, each null until it has said); with wait false, a +// 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, at: 0, failed: 0, asking: null })) + if (!c) said.set(key, (c = { images: null, families: null, at: 0, failed: 0, asking: null })) const ask = () => (c.asking ??= (async () => { try { @@ -332,9 +381,11 @@ async function imagesFor(key, server, wait = true) { signal: AbortSignal.timeout(15_000), }) if (!res.ok) throw new Error(`GetCliModelConfigs: ${res.status}`) - const images = parseModelConfigs(new Uint8Array(await res.arrayBuffer())) + const b = new Uint8Array(await res.arrayBuffer()) + const images = parseModelConfigs(b) if (!images) throw new Error("GetCliModelConfigs: no models") - Object.assign(c, { images, at: Date.now(), failed: 0 }) + const families = parseConfigFamilies(b) + Object.assign(c, { images, families: families.length ? families : null, at: Date.now(), failed: 0 }) } catch { c.failed = Date.now() } finally { @@ -347,6 +398,14 @@ async function imagesFor(key, server, wait = true) { if (wait && !c.images) await p } } + return c +} + +// imagesFor is what Devin says of each model id's images for key's +// account, SNAPSHOT_IMAGES under it; with wait false, a first ask isn't +// waited for. +async function imagesFor(key, server, wait = true) { + const c = await configsFor(key, server, wait) return { ...SNAPSHOT_IMAGES, ...(c.images ?? {}) } } @@ -623,9 +682,11 @@ async function whoByKey(key, server) { } // cliAnswersFor says whether the CLI, run with home as its data folder, -// answers for key's account: it reads home's credentials.toml, and the -// account it names is the one Devin says the key is. undefined when it -// can't tell. +// answers for key's account: the account it names is the one Devin says +// the key is. A CLI that reads another credentials.toml than home's (on +// Windows it reads %APPDATA%\devin\ whatever APPDATA it is given, #17) +// answers only when it names that account; one that reads home's is taken +// at its word when Devin can't tell. undefined when it can't tell. async function cliAnswersFor(key, server, home) { let out try { @@ -633,21 +694,36 @@ async function cliAnswersFor(key, server, home) { } catch { return undefined } - if (!readsHome(out, home)) return false + const own = readsHome(out, home) const cli = parseStatus(out)?.user - if (!cli) return true + if (!cli) return own const who = await whoByKey(key, server) - return !who?.user || who.user.toLowerCase() === cli.toLowerCase() + if (!who?.user) return own + return who.user.toLowerCase() === cli.toLowerCase() } // Each account's model list as the CLI last gave it, kept FRESH; one past // its time is served while it is read again, one that failed is asked // again after RETRY. A CLI that doesn't answer for the account (#17: on -// Windows it lists its own account's) is never asked for it: the account -// has Devin's list as of SNAPSHOT. +// Windows it lists its own account's) is never asked for it. const lists = new Map() +// familiesFor is key's account's list: what Devin tells the CLI's model +// picker for the key (GetCliModelConfigs, the list `devin models list` +// prints, asked with the key itself, so on any system and for every +// account), else the CLI's when it answers for the account, else Devin's +// list as of SNAPSHOT. On Windows the CLI answered for no account added +// in the browser, and an account without the CLI had only SNAPSHOT, so +// neither got Gemini 4 Argon (plugins #115). async function familiesFor(key, server, wait = true) { + return (await ownFamilies(key, server, wait)) ?? familiesOf(SNAPSHOT) +} + +// ownFamilies is familiesFor's list when Devin or the CLI gave one, null +// when neither has. +async function ownFamilies(key, server, wait = true) { + const told = (await configsFor(key, server, wait)).families + if (told) return told let c = lists.get(key) if (!c) lists.set(key, (c = { families: null, at: 0, failed: 0, asking: null, cli: undefined })) const ask = () => @@ -674,7 +750,7 @@ async function familiesFor(key, server, wait = true) { const p = ask() if (wait) await p } - return c.families ?? familiesOf(SNAPSHOT) + return c.families } // ---- signing in ---------------------------------------------------------------------- @@ -1569,16 +1645,17 @@ export async function DevinAuthPlugin() { models: { ...Object.fromEntries(listed(familiesOf(SNAPSHOT), [], SNAPSHOT_IMAGES).map((m) => [m.id, configModel(m)])), ...(was.models ?? {}) }, } }, - // the account's list, as the devin CLI gives it, with what Devin says - // of each model's images; with no CLI, the list it was given with that + // the account's list, as Devin or the devin CLI gives it (familiesFor), + // with what Devin says of each model's images; with neither, the list + // it was given with that provider: { id: ID, async models(provider, { auth } = {}) { if (auth?.type !== "api" || !auth.key) return provider.models const { key, server } = await live(auth) const images = await imagesFor(key, server) - if (!cliPath()) return withImages(provider.models, listed(familiesOf(SNAPSHOT), Object.keys(provider?.models ?? {}), images)) - const families = await familiesFor(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).map((m) => [m.id, runtimeModel(m)])) }, }, @@ -1586,4 +1663,4 @@ export async function DevinAuthPlugin() { } // for tests -export const _internal = { outID, inID, objectRoot, seesImages, imagesFor, forgetSaid: () => said.clear(), parseModelConfigs, 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 = { 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 f38ded3..e5d1728 100644 --- a/packages/devin/package.json +++ b/packages/devin/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-devin-auth", - "version": "0.1.14", + "version": "0.1.15", "description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie", "type": "module", "main": "./index.mjs", diff --git a/packages/devin/testdata/model-configs.bin b/packages/devin/testdata/model-configs.bin new file mode 100644 index 0000000..9b9803d Binary files /dev/null and b/packages/devin/testdata/model-configs.bin differ