devin 0.1.3: the card's quota windows are "1 day" and "7 days", shown only when Devin says what is left of them (one left out is no longer taken for used up); usage no longer overwrites the row's plan ("Devin Pro", as devin auth status names it) with planName's bare "Pro"; a refused key says "Devin's sign-in has expired — sign in again"; the efforts none and minimal go as given; a variant the user picked stays, as magpie's devinCollapse keeps it; only a model models.dev says takes images gets image input
This commit is contained in:
+65
-14
@@ -9,7 +9,7 @@ import { createHash, randomBytes, randomUUID } from "node:crypto"
|
||||
import { createServer } from "node:http"
|
||||
import { gunzipSync } from "node:zlib"
|
||||
import { spawn } from "node:child_process"
|
||||
import { existsSync, statSync } from "node:fs"
|
||||
import { existsSync, readFileSync, statSync } from "node:fs"
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises"
|
||||
import { homedir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
@@ -221,7 +221,10 @@ function variantFor(families, model, effort) {
|
||||
// the efforts its variants are at (picked as any model's effort is, and
|
||||
// turned into the variant by variantFor), its fast run likewise, and the
|
||||
// variants at no effort (glm-5-2-1m); a family's only variant is its id.
|
||||
function listed(families) {
|
||||
// A variant in keep (one the user picked: swe-2-medium) stays, at the one
|
||||
// effort its id is at, and goes to Devin as it is, as magpie's built-in
|
||||
// keeps it (devinCollapse).
|
||||
function listed(families, keep = []) {
|
||||
const out = []
|
||||
const seen = new Set()
|
||||
const add = (m) => {
|
||||
@@ -244,24 +247,66 @@ function listed(families) {
|
||||
add({ id: m.id, name: m.name, context: m.context || context, output: m.output || output, efforts: [] })
|
||||
}
|
||||
}
|
||||
for (const id of keep) {
|
||||
if (seen.has(id)) continue
|
||||
const f = families.find((g) => g.models.some((m) => m.id === id))
|
||||
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] : [] })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// seesImages is whether a model takes images, as magpie's built-in tells
|
||||
// it for Devin's ids (models.go: m.Images || catalog.SeesImages): Devin's
|
||||
// list says nothing of images, so it is models.dev's word for the id — most
|
||||
// of the providers listing it taking images — from the catalog magpie's
|
||||
// `magpie sync` or OpenCode keeps, and no when neither has it.
|
||||
let seen = null
|
||||
function seesImages(id) {
|
||||
if (!seen) {
|
||||
seen = new Set()
|
||||
const cache = process.env.XDG_CACHE_HOME || join(homedir(), ".cache")
|
||||
for (const p of [join(cache, "magpie", "models.json"), join(homedir(), ".cache", "opencode", "models.json")]) {
|
||||
let m
|
||||
try {
|
||||
m = JSON.parse(readFileSync(p, "utf8"))
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
if (!m || typeof m !== "object" || !Object.keys(m).length) continue
|
||||
const votes = new Map()
|
||||
for (const pr of Object.values(m))
|
||||
for (const [mid, x] of Object.entries(pr?.models ?? {})) {
|
||||
const b = bare(mid)
|
||||
votes.set(b, (votes.get(b) ?? 0) + ((x?.modalities?.input ?? []).includes("image") ? 1 : -1))
|
||||
}
|
||||
for (const [b, v] of votes) if (v > 0) seen.add(b)
|
||||
break
|
||||
}
|
||||
}
|
||||
return seen.has(bare(id))
|
||||
}
|
||||
const bare = (id) => String(id).toLowerCase().split("/").pop()
|
||||
|
||||
function configModel(m) {
|
||||
const image = seesImages(m.id)
|
||||
return {
|
||||
id: m.id,
|
||||
name: m.name,
|
||||
tool_call: true,
|
||||
reasoning: m.efforts.length > 0,
|
||||
attachment: true,
|
||||
attachment: image,
|
||||
temperature: true,
|
||||
modalities: { input: ["text", "image"], output: ["text"] },
|
||||
modalities: { input: image ? ["text", "image"] : ["text"], output: ["text"] },
|
||||
limit: { context: m.context, output: m.output },
|
||||
...(m.efforts.length ? { variants: Object.fromEntries(m.efforts.map((e) => [e, { reasoningEffort: e }])) } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
function runtimeModel(m) {
|
||||
const image = seesImages(m.id)
|
||||
return {
|
||||
id: m.id,
|
||||
providerID: ID,
|
||||
@@ -275,9 +320,9 @@ function runtimeModel(m) {
|
||||
capabilities: {
|
||||
temperature: true,
|
||||
reasoning: m.efforts.length > 0,
|
||||
attachment: true,
|
||||
attachment: image,
|
||||
toolcall: true,
|
||||
input: { text: true, image: true, audio: false, video: false, pdf: false },
|
||||
input: { text: true, image, audio: false, video: false, pdf: false },
|
||||
output: { text: true, image: false, audio: false, video: false, pdf: false },
|
||||
interleaved: false,
|
||||
},
|
||||
@@ -718,8 +763,9 @@ const textOf = (c) =>
|
||||
// effortOf is the effort a request names, as magpie reads it.
|
||||
function effortOf(s) {
|
||||
const e = String(s ?? "").trim().toLowerCase()
|
||||
if (e === "minimal" || e === "none") return "low"
|
||||
if (["low", "medium", "high", "xhigh", "max"].includes(e)) return e
|
||||
// none and minimal go as given: the family's variant nearest them, as
|
||||
// magpie's built-in picks it (devinVariantIn)
|
||||
if (["none", "minimal", "low", "medium", "high", "xhigh", "max"].includes(e)) return e
|
||||
if (e === "ultra") return "max"
|
||||
return ""
|
||||
}
|
||||
@@ -1080,18 +1126,23 @@ async function usage(key, server) {
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
})
|
||||
const text = await res.text()
|
||||
if (res.status === 401 || failure(res.status, text).status === 401)
|
||||
return { error: "Devin's sign-in has expired — sign in again", windows: [] }
|
||||
if (!res.ok) return { error: failure(res.status, text).message, windows: [] }
|
||||
const st = JSON.parse(text || "{}")?.userStatus?.planStatus ?? {}
|
||||
const info = st.planInfo ?? {}
|
||||
const num = (v) => (typeof v === "number" ? v : typeof v === "string" && v.trim() && !isNaN(Number(v)) ? Number(v) : 0)
|
||||
// no plan: the row keeps the one `devin auth status` gave the sign-in
|
||||
// ("Devin Pro"), as magpie's built-in row said it, not planName's "Pro"
|
||||
const out = { windows: [] }
|
||||
if (info.planName) out.plan = String(info.planName)
|
||||
if (st.planEnd) out.until = st.planEnd
|
||||
// a quota's window is shown when Devin says what is left of it; one it
|
||||
// leaves out is not taken for used up
|
||||
for (const [name, span, left, reset, hide] of [
|
||||
["Daily", 24 * 3600, st.dailyQuotaRemainingPercent, st.dailyQuotaResetAtUnix, info.hideDailyQuota],
|
||||
["Weekly", 7 * 24 * 3600, st.weeklyQuotaRemainingPercent, st.weeklyQuotaResetAtUnix, info.hideWeeklyQuota],
|
||||
["1 day", 24 * 3600, st.dailyQuotaRemainingPercent, st.dailyQuotaResetAtUnix, info.hideDailyQuota],
|
||||
["7 days", 7 * 24 * 3600, st.weeklyQuotaRemainingPercent, st.weeklyQuotaResetAtUnix, info.hideWeeklyQuota],
|
||||
]) {
|
||||
if (hide || (left === undefined && !num(reset))) continue
|
||||
if (hide || left === undefined || left === null) continue
|
||||
const at = num(reset)
|
||||
out.windows.push({ name, used: Math.min(100, Math.max(0, 100 - num(left))), span, ...(at > 0 ? { resetsAt: at } : {}) })
|
||||
}
|
||||
@@ -1180,11 +1231,11 @@ export async function DevinAuthPlugin() {
|
||||
if (auth?.type !== "api" || !auth.key || !cliPath()) return provider.models
|
||||
const { key, server } = await live(auth)
|
||||
const families = await familiesFor(key, server)
|
||||
return Object.fromEntries(listed(families).map((m) => [m.id, runtimeModel(m)]))
|
||||
return Object.fromEntries(listed(families, Object.keys(provider?.models ?? {})).map((m) => [m.id, runtimeModel(m)]))
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// for tests
|
||||
export const _internal = { live, build, failure, complete, parseFamilies, listed, variantFor, familiesOf, SNAPSHOT, parseStatus, readCredentials, credentials, fields, frame, PB, events, frames }
|
||||
export const _internal = { seesImages, forgetImages: () => (seen = null), effortOf, runtimeModel, configModel, live, build, failure, complete, parseFamilies, listed, variantFor, familiesOf, SNAPSHOT, parseStatus, readCredentials, credentials, fields, frame, PB, events, frames }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-devin-auth",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
// shaped as a live Teams account's (magpie's built-in Devin account showed
|
||||
// none of it).
|
||||
import { afterEach, expect, test } from "bun:test"
|
||||
import { DevinAuthPlugin } from "./index.mjs"
|
||||
import { mkdirSync, realpathSync, writeFileSync } from "node:fs"
|
||||
import { homedir, tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { DevinAuthPlugin, _internal } from "./index.mjs"
|
||||
|
||||
const real = globalThis.fetch
|
||||
afterEach(() => (globalThis.fetch = real))
|
||||
@@ -38,13 +41,13 @@ async function run(a, reply) {
|
||||
|
||||
test("a Teams plan: its end, its day and week, the extra usage balance", async () => {
|
||||
const { u, seen } = await run(auth, () => Response.json(status()))
|
||||
// no plan: the row keeps the sign-in's, as `devin auth status` names it
|
||||
expect(u).toEqual({
|
||||
plan: "Teams",
|
||||
until: "2026-10-26T21:45:55Z",
|
||||
balance: "$46.81",
|
||||
windows: [
|
||||
{ name: "Daily", used: 0, span: 86400, resetsAt: 1790841600 },
|
||||
{ name: "Weekly", used: 1, span: 604800, resetsAt: 1791100800 },
|
||||
{ name: "1 day", used: 0, span: 86400, resetsAt: 1790841600 },
|
||||
{ name: "7 days", used: 1, span: 604800, resetsAt: 1791100800 },
|
||||
],
|
||||
})
|
||||
expect(seen[0].url).toBe("https://server.codeium.com/exa.seat_management_pb.SeatManagementService/GetUserStatus")
|
||||
@@ -52,27 +55,80 @@ test("a Teams plan: its end, its day and week, the extra usage balance", async (
|
||||
expect(seen[0].body.metadata).toMatchObject({ ideName: "devin-cli", extensionName: "devin-cli", apiKey: "devin-key", locale: "en" })
|
||||
})
|
||||
|
||||
test("a quota with no share left is used up; a hidden one isn't shown; ACUs with a limit are", async () => {
|
||||
test("a quota Devin says nothing left of isn't taken for used up; a hidden one isn't shown; ACUs with a limit are", async () => {
|
||||
const s = status({ dailyQuotaRemainingPercent: undefined, overageBalanceMicros: undefined, acuConsumed: 12.5, acuLimit: 50 })
|
||||
s.userStatus.planStatus.planInfo.hideWeeklyQuota = true
|
||||
const { u } = await run({ ...auth, metadata: { ...auth.metadata, server: "https://eu.example" } }, () => Response.json(s))
|
||||
expect(u).toEqual({
|
||||
plan: "Teams",
|
||||
until: "2026-10-26T21:45:55Z",
|
||||
windows: [
|
||||
{ name: "Daily", used: 100, span: 86400, resetsAt: 1790841600 },
|
||||
{ name: "ACUs", used: 25, display: "12.5 / 50 ACUs", resetsAt: "2026-10-26T21:45:55Z", aside: true },
|
||||
],
|
||||
windows: [{ name: "ACUs", used: 25, display: "12.5 / 50 ACUs", resetsAt: "2026-10-26T21:45:55Z", aside: true }],
|
||||
})
|
||||
})
|
||||
|
||||
test("a plan without quotas is its name alone", async () => {
|
||||
test("a plan billed otherwise, with resets and no share given, has no quota windows", async () => {
|
||||
const s = status({ dailyQuotaRemainingPercent: undefined, weeklyQuotaRemainingPercent: undefined, overageBalanceMicros: undefined })
|
||||
s.userStatus.planStatus.planInfo.billingStrategy = "BILLING_STRATEGY_CREDITS"
|
||||
expect((await run(auth, () => Response.json(s))).u).toEqual({ until: "2026-10-26T21:45:55Z", windows: [] })
|
||||
})
|
||||
|
||||
test("a plan without quotas has no windows, and leaves the row's plan be", async () => {
|
||||
const s = { userStatus: { planStatus: { planInfo: { planName: "Free" } } } }
|
||||
expect((await run(auth, () => Response.json(s))).u).toEqual({ plan: "Free", windows: [] })
|
||||
expect((await run(auth, () => Response.json(s))).u).toEqual({ windows: [] })
|
||||
})
|
||||
|
||||
test("a refused key says to sign in again", async () => {
|
||||
const { u } = await run(auth, () => Response.json({ code: "unauthenticated", message: "invalid api key" }, { status: 401 }))
|
||||
expect(u).toEqual({ error: "invalid api key — sign in to Devin again", windows: [] })
|
||||
// worded so magpie's /sign-in has expired/ marks the account
|
||||
expect(u).toEqual({ error: "Devin's sign-in has expired — sign in again", windows: [] })
|
||||
expect(u.error).toMatch(/sign-in has expired/)
|
||||
const bare = await run(auth, () => new Response("", { status: 401 }))
|
||||
expect(bare.u.error).toBe("Devin's sign-in has expired — sign in again")
|
||||
expect((await run({ type: "oauth" }, () => Response.json({}))).u).toEqual({ error: "Devin isn't signed in" })
|
||||
})
|
||||
|
||||
// the built-in sends none and minimal as asked (devinVariantIn): the
|
||||
// family's variant nearest them
|
||||
test("the efforts none and minimal go as given", () => {
|
||||
const { effortOf, variantFor, familiesOf, SNAPSHOT } = _internal
|
||||
expect(effortOf("none")).toBe("none")
|
||||
expect(effortOf("minimal")).toBe("minimal")
|
||||
const fs = familiesOf(SNAPSHOT)
|
||||
expect(variantFor(fs, "gpt-6-sol", effortOf("none"))).toBe("gpt-6-sol-none")
|
||||
expect(variantFor(fs, "gemini-3.5-flash", effortOf("minimal"))).toBe("gemini-3-5-flash-minimal")
|
||||
})
|
||||
|
||||
// devinCollapse keeps a variant the user picked, at the effort its id is at
|
||||
test("a variant the user picked stays in the list, at its own effort", () => {
|
||||
const { listed, familiesOf, SNAPSHOT } = _internal
|
||||
const fs = familiesOf(SNAPSHOT)
|
||||
const ids = (ms) => ms.map((m) => m.id)
|
||||
expect(ids(listed(fs))).not.toContain("swe-2-medium")
|
||||
const kept = listed(fs, ["swe-2-medium", "claude-opus-5-5-high-fast", "not-a-devin-model", "swe-2"])
|
||||
expect(kept.find((m) => m.id === "swe-2-medium")).toEqual({ id: "swe-2-medium", name: "SWE-2 Medium", context: 262000, output: 128000, efforts: ["medium"] })
|
||||
expect(kept.find((m) => m.id === "claude-opus-5-5-high-fast").efforts).toEqual(["high"])
|
||||
expect(ids(kept)).not.toContain("not-a-devin-model")
|
||||
expect(ids(kept).filter((id) => id === "swe-2").length).toBe(1)
|
||||
})
|
||||
|
||||
// the built-in marks a model as taking images only when it does
|
||||
// (m.Images || catalog.SeesImages): models.dev's word, from the catalog cache
|
||||
test("only a model models.dev says takes images is given image input", () => {
|
||||
const { seesImages, runtimeModel, configModel, forgetImages } = _internal
|
||||
if (![tmpdir(), realpathSync(tmpdir())].some((t) => homedir().startsWith(t))) throw new Error("run with HOME=$(mktemp -d) bun test")
|
||||
const dir = join(process.env.XDG_CACHE_HOME || join(homedir(), ".cache"), "magpie")
|
||||
mkdirSync(dir, { recursive: true })
|
||||
writeFileSync(join(dir, "models.json"), JSON.stringify({
|
||||
anthropic: { models: { "claude-opus-5-5": { modalities: { input: ["text", "image"] } } } },
|
||||
zai: { models: { "glm-5-2": { modalities: { input: ["text"] } } } },
|
||||
}))
|
||||
forgetImages()
|
||||
const m = (id) => ({ id, name: id, context: 1, output: 1, efforts: [] })
|
||||
expect(seesImages("claude-opus-5-5")).toBe(true)
|
||||
expect(runtimeModel(m("claude-opus-5-5")).capabilities.input.image).toBe(true)
|
||||
expect(configModel(m("claude-opus-5-5")).modalities.input).toEqual(["text", "image"])
|
||||
for (const id of ["glm-5-2", "swe-2"]) {
|
||||
expect(runtimeModel(m(id)).capabilities.input.image).toBe(false)
|
||||
expect(runtimeModel(m(id)).capabilities.attachment).toBe(false)
|
||||
expect(configModel(m(id)).modalities.input).toEqual(["text"])
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user