cursor: the Claude Cursor hides from an account is listed once per context size (jiaohanying, #634)
By jiaohanying (#634). An account Cursor blocks Claude for has no Claude in the picker (AvailableModels), only in the usable list, so those models were listed as usableOnly fallback entries: a 200K window assumed, no sizes. AvailableModels with scope 3 (the full catalog) is now asked alongside the other two (8s; a failure leaves the list as before). The live Anthropic models the picker lacks (not isHidden, not Auto, not chat-only or Tab-only, with a variant the account has an id for) are listed as the picker's models are: once per context size (claude-opus-5-5@300k, @1m), thinking a parameter, the efforts the account is served, 1m in Max Mode. A catalog variant without a legacySlug gets the one of the model's ids that says its effort, thinking and fast; none or several, it is not offered. Only the parameters the model defines are sent: the catalog's Opus 4.7 to 5.5 variants carry cyber=false, which the picker's don't and cursor-agent never sends. A saved sized id (claude-opus-4-8-thinking@1m) now runs at its size. With no effort asked a catalog model goes at Cursor's default variant (Opus 5 and 4.8: high), as the picker's do. The version is bumped in the next commit: main's17e5ef7already took 0.2.38. Run at the reviewed head f4cb8ed449ee63dfb92fa37509a171ee43de3280 (mote, Bun, temp HOME): - bun test packages/cursor: 393 pass, 0 fail. bun scripts/check.mjs: ok. - Squashed onto origin/maina064cf1with the version at 0.2.39: bun test packages/cursor 393 pass; whole bun test 5199 tests, 0 fail (15 skip); check.mjs ok. Broken by hand: - c588c65's withSlugs (no parameter filter): the cyber test fails (Expected false, Received true); the other 8 pass. - main's index.mjs under the new catalog.test.mjs: 7 of 9 fail. The author ran a real Run on a blocked account at low effort: claude-opus-5-5@300k went as claude-opus-5-5-low [context=300k, effort=low, fast=false], @1m as the same id in Max Mode [context=1m]. Not tried by the reviewer: a real Cursor account (none available for this review), and a long conversation at 300K or 1m. Every account now makes the scope 3 request too, so a slow catalog can hold the list up to 8s, as GetUsableModels can.
This commit is contained in:
+30
-11
@@ -208,17 +208,36 @@ minutes), the way pi-cursor-sdk lists Cursor's catalog:
|
||||
has. A model the usable list has nothing of is the picker's alone
|
||||
(GLM-5.3) and is kept whole; so is every model when Cursor can't give
|
||||
the usable list.
|
||||
- A family the usable list has and the picker doesn't (an account whose
|
||||
picker lacks Claude Opus 5.5 while `cursor-agent models` lists
|
||||
`claude-opus-5-5-low` to `-max`) is listed once under its family id
|
||||
(`claude-opus-5-5`), its efforts as variants, and goes as the usable id
|
||||
those parameters pick, never as the family id Cursor doesn't know. A
|
||||
picker model whose chosen variant isn't one the account can use goes as
|
||||
its family's nearest usable id the same way. Such a family is named
|
||||
without the tier Cursor's names carry ("Claude Opus 5 1M Medium
|
||||
Thinking" is listed as Claude Opus 5 Thinking): the tier is the
|
||||
reasoning level the agent asks for (low to max, as the account has
|
||||
them), fast the request's `service_tier`.
|
||||
- The full catalog (`AvailableModels` with `scope: 3`, asked alongside the
|
||||
other two; it also lists the models Cursor hides from an account, Claude
|
||||
from a Pro one) supplies the Anthropic models the picker lacks: each live
|
||||
one (not `isHidden`, not Auto, not chat-only or Tab-only) with a variant
|
||||
the usable list has an id for is listed as the picker's models are, once
|
||||
for each context size (`claude-opus-5-5@300k`, `claude-opus-5-5@1m`; name
|
||||
"Claude Opus 5.5 @ 300k"), thinking a parameter, the efforts the account
|
||||
is served, and the larger size in Max Mode with that `context`. A catalog
|
||||
variant without its own id gets the one of the model's ids that says its
|
||||
effort, thinking and fast; with none or several it is not offered. Only
|
||||
the parameters the model defines are sent (the catalog's variants also
|
||||
carry `cyber=false`, which the picker's don't and cursor-agent never
|
||||
sends). With no effort asked, a model goes at Cursor's default variant
|
||||
(Opus 5 and 4.8: high), as the picker's models do, not at medium as the
|
||||
fallback entries did. The picker's models and every model that is not
|
||||
Anthropic's don't change.
|
||||
An id saved from an earlier list (`claude-opus-5-5`,
|
||||
`claude-opus-4-8-thinking@1m`) runs as the model at the nearest size it
|
||||
has, as a usable id.
|
||||
- When Cursor can't give the catalog, a family the usable list has and the
|
||||
picker doesn't (`claude-opus-5-5-low` to `-max`) is listed once under its
|
||||
family id (`claude-opus-5-5`), its efforts as variants, and goes as the
|
||||
usable id those parameters pick, never as the family id Cursor doesn't
|
||||
know; it has no window in the usable list, so 200K is assumed. A picker
|
||||
model whose chosen variant isn't one the account can use goes as its
|
||||
family's nearest usable id the same way. Such a family is named without
|
||||
the tier Cursor's names carry ("Claude Opus 5 1M Medium Thinking" is
|
||||
listed as Claude Opus 5 Thinking): the tier is the reasoning level the
|
||||
agent asks for (low to max, as the account has them), fast the request's
|
||||
`service_tier`.
|
||||
- An id for a model with thinking that the account lists only without it
|
||||
(`claude-haiku-5-5-thinking` when the list has Claude Haiku 5.5 alone),
|
||||
or the other way round, runs as the model the account has. So does a
|
||||
|
||||
@@ -0,0 +1,270 @@
|
||||
// A Claude Cursor hides from an account is in the usable list (cursor-agent
|
||||
// models) and not in the picker. The full catalog (AvailableModels with
|
||||
// scope 3) has it: those models are listed as the picker's are, once for each
|
||||
// context size ("claude-opus-5-5@300k", "@1m"), thinking a parameter, the
|
||||
// efforts the account is served, the 1m size in Max Mode. The picker's own
|
||||
// models, and any id of the usable list that is not Anthropic's, stay as they
|
||||
// are; an id saved from an earlier list still runs. Nothing reaches Cursor.
|
||||
import "./nonet.mjs"
|
||||
import { afterEach, expect, test } from "bun:test"
|
||||
import { _internal } from "./index.mjs"
|
||||
|
||||
const { usable, request } = _internal
|
||||
const real = globalThis.fetch
|
||||
afterEach(() => (globalThis.fetch = real))
|
||||
let n = 0
|
||||
const tok = () => "tok-catalog-" + ++n
|
||||
|
||||
const en = (...vs) => ({ enumParameter: { values: vs.map((value) => ({ value })) } })
|
||||
const bool = { booleanParameter: { values: [{ value: "false" }, { value: "true" }] } }
|
||||
|
||||
// a catalog model as scope 3 gives it: its variants without legacySlug, the
|
||||
// ids in the model's legacySlugs. slug(thinking, effort, fast) is Cursor's id.
|
||||
function model(name, title, { thinks, contexts, efforts = [], fast, slug, limit, limitMax, defaults = {}, only = [] }) {
|
||||
const defs = [
|
||||
...(thinks ? [{ id: "thinking", parameterType: bool }] : []),
|
||||
{ id: "context", parameterType: en(...contexts) },
|
||||
...(efforts.length ? [{ id: "effort", parameterType: en(...efforts) }] : []),
|
||||
...(fast ? [{ id: "fast", parameterType: bool }] : []),
|
||||
]
|
||||
const variants = []
|
||||
const slugs = []
|
||||
for (const t of thinks ? [false, true] : [undefined])
|
||||
for (const context of contexts)
|
||||
for (const effort of efforts.length ? efforts : [undefined])
|
||||
for (const f of fast ? [false, true] : [undefined]) {
|
||||
const parameterValues = Object.entries({ thinking: t, context, effort, fast: f }).filter(([, x]) => x !== undefined).map(([id, x]) => ({ id, value: String(x) }))
|
||||
const id = slug(t, effort, f)
|
||||
if (!slugs.includes(id)) slugs.push(id)
|
||||
const maxOnly = context !== contexts[0]
|
||||
const d = (defaults.thinking === undefined || defaults.thinking === t) && (defaults.effort ?? efforts[0]) === effort && !f
|
||||
variants.push({ parameterValues, ...(maxOnly ? { isMaxMode: true } : {}), ...(d && context === contexts[0] ? { isDefaultNonMaxConfig: true } : {}), ...(d && context === contexts.at(-1) ? { isDefaultMaxConfig: true } : {}), ...(only.includes(id) ? { served: true } : {}) })
|
||||
}
|
||||
return { name, clientDisplayName: title, legacySlugs: slugs, contextTokenLimit: limit, contextTokenLimitForMaxMode: limitMax, parameterDefinitions: defs, variants, vendor: { id: "MODEL_VENDOR_ID_ANTHROPIC" } }
|
||||
}
|
||||
|
||||
const OPUS55 = model("claude-opus-5-5", "Claude Opus 5.5", { contexts: ["300k", "1m"], efforts: ["low", "medium", "high"], fast: true, limit: 300000, limitMax: 1000000, defaults: { effort: "medium" }, slug: (t, e, f) => `claude-opus-5-5-${e}${f ? "-fast" : ""}` })
|
||||
const OPUS48 = model("claude-opus-4-8", "Claude Opus 4.8", { thinks: true, contexts: ["300k", "1m"], efforts: ["low", "medium", "high"], fast: true, limit: 300000, limitMax: 1000000, defaults: { thinking: true, effort: "medium" }, slug: (t, e, f) => `claude-opus-4-8-${t ? "thinking-" : ""}${e}${f ? "-fast" : ""}` })
|
||||
// the account is served Sonnet 4.6 at medium only; its picker limit is 1M
|
||||
const SONNET46 = model("claude-sonnet-4-6", "Claude Sonnet 4.6", { thinks: true, contexts: ["200k", "1m"], efforts: ["low", "medium", "high"], limit: 1000000, limitMax: 1000000, defaults: { thinking: true, effort: "medium" }, slug: (t, e) => `claude-4.6-sonnet-${e}${t ? "-thinking" : ""}` })
|
||||
// 200K only: nothing to add
|
||||
const SONNET4 = model("claude-sonnet-4", "Claude Sonnet 4", { thinks: true, contexts: ["200k"], limit: 200000, limitMax: 200000, slug: (t) => `claude-4-sonnet${t ? "-thinking" : ""}` })
|
||||
// Haiku 4.5 is live and in the catalog, and not the account's
|
||||
const HAIKU45 = model("claude-haiku-4-5", "Claude Haiku 4.5", { contexts: ["200k"], limit: 200000, limitMax: 200000, slug: () => "claude-haiku-4-5" })
|
||||
const OLD = { ...model("claude-3-opus", "Claude 3 Opus", { contexts: ["200k"], limit: 200000, limitMax: 200000, slug: () => "claude-3-opus" }), isHidden: true }
|
||||
|
||||
const PICKER = [{ name: "composer-2.5", clientDisplayName: "Composer 2.5", contextTokenLimit: 200000, supportsNonMaxMode: true, variants: [{ parameterValues: [], isDefaultNonMaxConfig: true, legacySlug: "composer-2.5" }] }]
|
||||
const CATALOG = [
|
||||
{ name: "default", clientDisplayName: "Auto" },
|
||||
{ ...PICKER[0], variants: [{ parameterValues: [], isDefaultNonMaxConfig: true }] },
|
||||
OPUS55, OPUS48, SONNET46, SONNET4, HAIKU45, OLD,
|
||||
]
|
||||
|
||||
const u = (modelId, displayName = modelId, o = {}) => ({ modelId, displayModelId: modelId, displayName, maxMode: false, ...o })
|
||||
// Cursor names them as "Claude Opus 4.8 1M Medium Thinking Fast"
|
||||
const word = { low: "Low", medium: "Medium", high: "High" }
|
||||
const named = (title, m) => m.legacySlugs.map((id) => {
|
||||
const effort = Object.keys(word).find((e) => id.includes("-" + e))
|
||||
const name = [title, "1M", word[effort], /thinking/.test(id) && "Thinking", id.endsWith("-fast") && "Fast"].filter(Boolean).join(" ")
|
||||
return u(id, name, { maxMode: id.endsWith("-fast") })
|
||||
})
|
||||
const USABLE = [
|
||||
u("composer-2.5", "Composer 2.5"),
|
||||
...named("Claude Opus 5.5", OPUS55),
|
||||
...named("Claude Opus 4.8", OPUS48),
|
||||
u("claude-4.6-sonnet-medium", "Claude Sonnet 4.6 1M"), u("claude-4.6-sonnet-medium-thinking", "Claude Sonnet 4.6 1M Thinking"),
|
||||
u("claude-4-sonnet", "Claude Sonnet 4"), u("claude-4-sonnet-thinking", "Claude Sonnet 4 Thinking"),
|
||||
u("claude-3-opus", "Claude 3 Opus"),
|
||||
]
|
||||
const usableIDs = new Set(USABLE.map((m) => m.modelId))
|
||||
|
||||
// catalog: the scope 3 answer; null: it fails
|
||||
function fakeAPI(catalog = CATALOG) {
|
||||
globalThis.fetch = async (url, init) => {
|
||||
const s = String(url)
|
||||
if (s.endsWith("/agent.v1.AgentService/GetUsableModels")) return Response.json({ models: USABLE })
|
||||
if (s.endsWith("/aiserver.v1.AiService/AvailableModels")) {
|
||||
if (JSON.parse(init.body).scope === 3) return catalog ? Response.json({ models: catalog }) : new Response("down", { status: 503 })
|
||||
return Response.json({ models: PICKER })
|
||||
}
|
||||
throw new Error("the test asked " + s)
|
||||
}
|
||||
}
|
||||
|
||||
const LV = ["none", "minimal", "low", "medium", "high", "xhigh", "max"]
|
||||
const levels = (e) => LV.filter((l) => l in e.levels)
|
||||
const run = (raw, id, effort = "", fast) => {
|
||||
const r = request(raw, id, effort, fast)
|
||||
return { id: r.id, maxMode: r.maxMode, params: Object.fromEntries(r.params.map((p) => [p.id, p.value])) }
|
||||
}
|
||||
const list = async (catalog) => {
|
||||
fakeAPI(catalog)
|
||||
return usable(tok())
|
||||
}
|
||||
const claude = (raw) => raw.filter((e) => e.run.startsWith("claude") && !e.usableOnly)
|
||||
|
||||
test("the catalog's live Claude is listed once for each size, thinking a parameter, as the picker's models are", async () => {
|
||||
const raw = await list()
|
||||
expect(claude(raw).map((e) => [e.id, e.name, e.context])).toEqual([
|
||||
["claude-opus-5-5@300k", "Claude Opus 5.5 @ 300k", 300000],
|
||||
["claude-opus-5-5@1m", "Claude Opus 5.5 @ 1m", 1000000],
|
||||
["claude-opus-4-8@300k", "Claude Opus 4.8 @ 300k", 300000],
|
||||
["claude-opus-4-8@1m", "Claude Opus 4.8 @ 1m", 1000000],
|
||||
["claude-sonnet-4-6@200k", "Claude Sonnet 4.6 @ 200k", 200000],
|
||||
["claude-sonnet-4-6@1m", "Claude Sonnet 4.6 @ 1m", 1000000],
|
||||
["claude-sonnet-4@200k", "Claude Sonnet 4 @ 200k", 200000],
|
||||
])
|
||||
// the efforts the account is served at each size, and fast where Cursor has it
|
||||
expect(claude(raw).map((e) => [e.id, levels(e), e.offersFast])).toEqual([
|
||||
["claude-opus-5-5@300k", ["low", "medium", "high"], true],
|
||||
["claude-opus-5-5@1m", ["low", "medium", "high"], true],
|
||||
["claude-opus-4-8@300k", ["low", "medium", "high"], true],
|
||||
["claude-opus-4-8@1m", ["low", "medium", "high"], true],
|
||||
["claude-sonnet-4-6@200k", ["medium"], false],
|
||||
["claude-sonnet-4-6@1m", ["medium"], false],
|
||||
["claude-sonnet-4@200k", ["none", "high"], false],
|
||||
])
|
||||
// no entry of the usable list's is left for them, and nothing the account can't run
|
||||
expect(raw.filter((e) => e.usableOnly).map((e) => e.id)).toEqual(["claude-3-opus"])
|
||||
expect(raw.some((e) => /haiku/.test(e.id))).toBe(false)
|
||||
})
|
||||
|
||||
test("the picker's models are as they were, and an id of the usable list that isn't Anthropic's is not the catalog's to list", async () => {
|
||||
const gpt = { ...OPUS55, name: "gpt-new", clientDisplayName: "GPT New", legacySlugs: ["gpt-new-low", "gpt-new-medium", "gpt-new-high"], vendor: { id: "MODEL_VENDOR_ID_OPENAI" } }
|
||||
USABLE.push(u("gpt-new-low", "GPT New Low"))
|
||||
try {
|
||||
const before = await list(null)
|
||||
const raw = await list([...CATALOG, gpt])
|
||||
const key = (e) => JSON.stringify([e.id, e.name, e.context, levels(e), e.offersFast, request([e], e.id, "", false)])
|
||||
// everything that isn't Claude: the same entries in the same order
|
||||
expect(raw.filter((e) => !e.run.startsWith("claude")).map(key)).toEqual(before.filter((e) => !e.run.startsWith("claude")).map(key))
|
||||
expect(raw.find((e) => e.id === "gpt-new")?.usableOnly).toBe(true)
|
||||
expect(raw.some((e) => e.id.startsWith("gpt-new@"))).toBe(false)
|
||||
} finally {
|
||||
USABLE.pop()
|
||||
}
|
||||
})
|
||||
|
||||
test("every entry runs as an id the account has, with its size, in Max Mode where that size needs it, at the effort and thinking asked", async () => {
|
||||
const raw = await list()
|
||||
for (const e of claude(raw))
|
||||
for (const effort of ["", ...levels(e), "off", "ultra"])
|
||||
for (const fast of e.offersFast ? [false, true] : [false]) {
|
||||
const r = run(raw, e.id, effort, fast)
|
||||
const parts = [e.id, effort, fast, usableIDs.has(r.id), r.params.context === e.size, r.maxMode === (e.size === "1m")]
|
||||
expect(parts).toEqual([e.id, effort, fast, true, true, true])
|
||||
if (e.id.startsWith("claude-opus-5-5")) expect("thinking" in r.params).toBe(false)
|
||||
if (fast) expect(r.id.endsWith("-fast")).toBe(true)
|
||||
}
|
||||
expect(run(raw, "claude-opus-5-5@1m")).toEqual({ id: "claude-opus-5-5-medium", maxMode: true, params: { context: "1m", effort: "medium", fast: "false" } })
|
||||
expect(run(raw, "claude-opus-5-5@300k", "high", true)).toEqual({ id: "claude-opus-5-5-high-fast", maxMode: false, params: { context: "300k", effort: "high", fast: "true" } })
|
||||
// thinking is the parameter: on by default, off for none
|
||||
expect(run(raw, "claude-opus-4-8@1m", "high")).toMatchObject({ id: "claude-opus-4-8-thinking-high", maxMode: true, params: { thinking: "true", context: "1m" } })
|
||||
expect(run(raw, "claude-opus-4-8@300k", "none")).toMatchObject({ id: "claude-opus-4-8-medium", maxMode: false, params: { thinking: "false", context: "300k" } })
|
||||
// the account has Sonnet 4.6 at medium alone
|
||||
expect(run(raw, "claude-sonnet-4-6@1m", "low").id).toBe("claude-4.6-sonnet-medium-thinking")
|
||||
})
|
||||
|
||||
test("an id from an earlier list still runs as an id the account has, at its size and with its thinking", async () => {
|
||||
const raw = await list()
|
||||
const q = (id, effort = "", fast) => {
|
||||
const r = run(raw, id, effort, fast)
|
||||
return [r.id, r.maxMode, r.params.context]
|
||||
}
|
||||
// the family 0.1.x and the first 0.2.x listed, and each variant's own id
|
||||
expect(q("claude-opus-5-5")).toEqual(["claude-opus-5-5-medium", false, "300k"])
|
||||
expect(q("claude-opus-5-5", "low")).toEqual(["claude-opus-5-5-low", false, "300k"])
|
||||
expect(q("claude-opus-5-5-high")).toEqual(["claude-opus-5-5-high", false, "300k"])
|
||||
expect(q("claude-opus-4-8-thinking", "low")[0]).toBe("claude-opus-4-8-thinking-low")
|
||||
expect(q("claude-opus-4-8", "low")[0]).toBe("claude-opus-4-8-low")
|
||||
expect(q("claude-4.6-sonnet-thinking")[0]).toBe("claude-4.6-sonnet-medium-thinking")
|
||||
expect(q("claude-4-sonnet")[0]).toBe("claude-4-sonnet")
|
||||
expect(q("claude-4-sonnet-thinking")[0]).toBe("claude-4-sonnet-thinking")
|
||||
// a sized name an earlier list had: the model at that size, thinking kept
|
||||
expect(q("claude-opus-5-5@1m")).toEqual(["claude-opus-5-5-medium", true, "1m"])
|
||||
expect(q("claude-opus-4-8-thinking@1m", "high")).toEqual(["claude-opus-4-8-thinking-high", true, "1m"])
|
||||
expect(q("claude-4.6-sonnet@1m")).toEqual(["claude-4.6-sonnet-medium", true, "1m"])
|
||||
expect(q("claude-opus-5-5@2m")).toEqual(["claude-opus-5-5-medium", true, "1m"])
|
||||
// whatever is asked, an id of Opus or Sonnet goes out as one the account has
|
||||
for (const id of [...USABLE.map((x) => x.modelId), "claude-opus-5-5", "claude-opus-4-8", "claude-opus-4-8-thinking", "claude-opus-4-8-thinking@1m", "claude-4.6-sonnet@1m", "claude-4-sonnet", "claude-opus-5-5-fast"])
|
||||
for (const effort of ["", "none", "low", "high", "max", "ultra"])
|
||||
for (const fast of [undefined, true]) expect([id, effort, fast, usableIDs.has(request(raw, id, effort, fast).id)]).toEqual([id, effort, fast, true])
|
||||
})
|
||||
|
||||
test("a catalog Cursor can't give leaves the list as the picker and the usable list made it", async () => {
|
||||
const raw = await list(null)
|
||||
expect(claude(raw)).toEqual([])
|
||||
expect(raw.filter((e) => e.usableOnly).every((e) => e.context === 200000)).toBe(true)
|
||||
expect(raw.filter((e) => e.usableOnly).map((e) => e.id)).toContain("claude-opus-5-5")
|
||||
expect((await list([])).map((e) => e.id)).toEqual(raw.map((e) => e.id))
|
||||
// a catalog that isn't a list
|
||||
expect((await list({ nope: 1 })).map((e) => e.id)).toEqual(raw.map((e) => e.id))
|
||||
})
|
||||
|
||||
test("a model the catalog has hidden, or the picker leaves out, or the account has no id of, is not listed; malformed entries are skipped", async () => {
|
||||
const only = (extra) => list([CATALOG[0], CATALOG[1], ...extra])
|
||||
expect(claude(await only([{ ...OPUS55, isHidden: true }]))).toEqual([])
|
||||
expect(claude(await only([{ ...OPUS55, isChatOnly: true }, { ...OPUS48, supportsAgent: false }, { ...SONNET4, onlySupportsCmdK: true }]))).toEqual([])
|
||||
expect(claude(await only([HAIKU45]))).toEqual([])
|
||||
// the picker's own model of that name is not added to
|
||||
const picker = [{ ...PICKER[0], name: "claude-opus-5-5", legacySlugs: undefined, variants: [{ parameterValues: [], legacySlug: "claude-opus-5-5-medium" }] }]
|
||||
const { fromCatalog } = _internal
|
||||
expect(fromCatalog(picker, [OPUS55], new Set(usableIDs)).map((m) => m.name)).toEqual([])
|
||||
// what is not an object, a list or a string where one is meant
|
||||
const bad = [null, 5, "x", {}, { ...OPUS55, name: "claude-bad-1", variants: [null, 5, { parameterValues: 7 }] }, { ...OPUS55, name: "claude-bad-2", legacySlugs: "x" }, { ...OPUS55, name: "claude-bad-3", variants: 5 }, { ...OPUS55, name: "claude-bad-4", parameterDefinitions: [null, { id: "effort" }] }]
|
||||
const raw = await only([...bad, OPUS55])
|
||||
expect(claude(raw).map((e) => e.id).filter((id) => !id.startsWith("claude-bad"))).toEqual(["claude-opus-5-5@300k", "claude-opus-5-5@1m"])
|
||||
})
|
||||
|
||||
test("a variant the account has no id for is not offered: not an effort, not a size", async () => {
|
||||
// Cursor names the account high-effort 300k only through an id that says
|
||||
// the same as another (two ids for one variant): left without, it must
|
||||
// not be listed as served
|
||||
const m = model("claude-amb", "Claude Amb", { contexts: ["300k", "1m"], efforts: ["low", "high"], limit: 300000, limitMax: 1000000, defaults: { effort: "low" }, slug: (t, e) => `claude-amb-${e}` })
|
||||
m.legacySlugs = ["claude-amb-low", "claude-amb-high", "claude-amb-high-copy".replace("-copy", "") + "-high"]
|
||||
const ids = [u("claude-amb-low", "Claude Amb 1M Low")]
|
||||
const saved = [...USABLE]
|
||||
USABLE.splice(0, USABLE.length, ...USABLE.filter((x) => x.modelId === "composer-2.5"), ...ids)
|
||||
try {
|
||||
const raw = await list([CATALOG[0], CATALOG[1], m])
|
||||
const e = raw.find((x) => x.id === "claude-amb@300k")
|
||||
expect(levels(e)).toEqual(["low"])
|
||||
expect(run(raw, e.id, "high").id).toBe("claude-amb-low")
|
||||
} finally {
|
||||
USABLE.splice(0, USABLE.length, ...saved)
|
||||
}
|
||||
})
|
||||
|
||||
test("an id the catalog gives a variant no legacySlug of is the one that says its effort, thinking and fast", async () => {
|
||||
const { slugFor } = _internal
|
||||
const v = (thinking, effort, fast) => ({ parameterValues: [{ id: "thinking", value: String(thinking) }, { id: "context", value: "300k" }, { id: "effort", value: effort }, { id: "fast", value: String(fast) }] })
|
||||
expect(slugFor(OPUS48, v(true, "high", false))).toBe("claude-opus-4-8-thinking-high")
|
||||
expect(slugFor(OPUS48, v(false, "low", true))).toBe("claude-opus-4-8-low-fast")
|
||||
// an effort the model has no id for, or one of Cursor's own already there
|
||||
expect(slugFor(OPUS48, v(true, "max", false))).toBe("")
|
||||
expect(slugFor({ ...OPUS48, legacySlugs: [] }, v(true, "high", false))).toBe("")
|
||||
expect(slugFor(OPUS48, { ...v(true, "max", false), legacySlug: "mine" })).toBe("mine")
|
||||
// an id with no effort in it is the default's (gpt-5.3-codex is medium)
|
||||
const codex = { legacySlugs: ["gpt-5.3-codex-low", "gpt-5.3-codex"], variants: [{ parameterValues: [{ id: "reasoning", value: "medium" }], isDefaultNonMaxConfig: true }] }
|
||||
expect(slugFor(codex, codex.variants[0])).toBe("gpt-5.3-codex")
|
||||
// two ids that say the same, or ids that aren't strings: none
|
||||
expect(slugFor({ legacySlugs: ["a-high", "b-high"], variants: [] }, { parameterValues: [{ id: "effort", value: "high" }] })).toBe("")
|
||||
expect(slugFor({ legacySlugs: [null, 5, "a-high"], variants: [] }, { parameterValues: [{ id: "effort", value: "high" }] })).toBe("a-high")
|
||||
})
|
||||
|
||||
test("a parameter the catalog's variants carry and the model doesn't define (cyber=false) is never sent", async () => {
|
||||
// as the real scope 3 answer has Opus 4.7 to 5.5: every variant says cyber, no definition does
|
||||
const cyber = { ...OPUS55, variants: OPUS55.variants.map((v) => ({ ...v, parameterValues: [{ id: "cyber", value: "false" }, ...v.parameterValues] })) }
|
||||
const raw = await list([CATALOG[0], CATALOG[1], cyber])
|
||||
for (const id of ["claude-opus-5-5@300k", "claude-opus-5-5@1m"])
|
||||
for (const effort of ["", "low", "medium", "high"])
|
||||
for (const fast of [false, true]) {
|
||||
const r = run(raw, id, effort, fast)
|
||||
expect("cyber" in r.params).toBe(false)
|
||||
expect(usableIDs.has(r.id)).toBe(true)
|
||||
}
|
||||
expect(run(raw, "claude-opus-5-5@300k", "low")).toEqual({ id: "claude-opus-5-5-low", maxMode: false, params: { context: "300k", effort: "low", fast: "false" } })
|
||||
// the same model without it, as the picker has it, runs with the same params
|
||||
const plain = await list([CATALOG[0], CATALOG[1], OPUS55])
|
||||
expect(run(raw, "claude-opus-5-5@1m", "high", true)).toEqual(run(plain, "claude-opus-5-5@1m", "high", true))
|
||||
})
|
||||
@@ -1082,6 +1082,69 @@ function modelsOf(picker, ids, listed = []) {
|
||||
return out
|
||||
}
|
||||
|
||||
// slugFor is the id of a variant the full catalog (AvailableModels with
|
||||
// scope 3) gives no legacySlug: the one of the model's legacySlugs that says
|
||||
// the variant's effort (any, when it has none), thinking and fast; an id
|
||||
// with no effort in it (gpt-5.3-codex) stands for the default's effort. With
|
||||
// none, or more than one, "": a guess could send an id Cursor refuses.
|
||||
function slugFor(m, v) {
|
||||
if (v.legacySlug) return v.legacySlug
|
||||
const have = valuesOf(v)
|
||||
const level = (p) => String(p[EFFORT_PARAMS.find((k) => p[k])] ?? "").replace("extra-high", "xhigh")
|
||||
const effort = level(have)
|
||||
const slugs = (Array.isArray(m.legacySlugs) ? m.legacySlugs : []).filter((id) => typeof id === "string" && id).map((id) => ({ id, ...familyOf(id) }))
|
||||
const says = (s, at) =>
|
||||
(at === null || s.effort === at) &&
|
||||
(have.thinking === undefined || s.family.endsWith("-thinking") === (have.thinking === "true")) &&
|
||||
(have.fast === undefined || s.fast === (have.fast === "true"))
|
||||
let hits = slugs.filter((s) => says(s, effort || null))
|
||||
const def = m.variants.find((x) => x?.isDefaultNonMaxConfig)
|
||||
if (!hits.length && effort && level(valuesOf(def)) === effort) hits = slugs.filter((s) => says(s, ""))
|
||||
return hits.length === 1 ? hits[0].id : ""
|
||||
}
|
||||
|
||||
// withSlugs is a catalog model with each variant's own id filled in, and
|
||||
// only the parameters the model defines: the full catalog is the admin
|
||||
// settings one, and carries what the picker's variants don't (cyber=false
|
||||
// on Opus 4.7 to 5.5, which cursor-agent never sends). A variant slugFor
|
||||
// can't name keeps no id of its own, but never goes without one: served()
|
||||
// leaves a variant with no legacySlug in, and one the account can't run
|
||||
// would be listed. So it gets a mark no usable id has, and modelsOf lists
|
||||
// it as it does a variant the account hasn't got. The variants are never
|
||||
// null.
|
||||
const NO_ID = "\u0000no-id"
|
||||
function withSlugs(m) {
|
||||
const defined = new Set((Array.isArray(m.parameterDefinitions) ? m.parameterDefinitions : []).map((d) => d?.id))
|
||||
const vs = (Array.isArray(m.variants) ? m.variants : [])
|
||||
.filter((v) => v && typeof v === "object" && Array.isArray(v.parameterValues ?? []))
|
||||
.map((v) => ({ ...v, parameterValues: (v.parameterValues ?? []).filter((p) => defined.has(p?.id)) }))
|
||||
const full = { ...m, variants: vs }
|
||||
return { ...full, variants: vs.map((v) => (v.legacySlug ? v : { ...v, legacySlug: slugFor(full, v) || NO_ID })) }
|
||||
}
|
||||
|
||||
// fromCatalog is the live models of Cursor's full catalog (AvailableModels
|
||||
// with scope 3, which also lists the models Cursor hides from some accounts:
|
||||
// Claude, from a Pro one) that the picker lacks, as picker models, with only
|
||||
// the variants the account can run (withSlugs). modelsOf lists them as it
|
||||
// does the picker's: once for each context size, thinking a parameter, the
|
||||
// efforts the account is served. Only Anthropic's are taken: the models the
|
||||
// picker lists, and every other id of the usable list, stay as they are.
|
||||
// Not offered: one the picker has or lists under another name, a hidden one
|
||||
// (isHidden: no longer offered), Auto, one the picker leaves out (chat-only,
|
||||
// Tab-only, no agent), and one with no variant the account has an id for.
|
||||
function fromCatalog(picker, catalog, ids) {
|
||||
const have = new Set(picker.map((m) => m?.name))
|
||||
const out = []
|
||||
for (const m of Array.isArray(catalog) ? catalog : []) {
|
||||
if (!m?.name || have.has(m.name) || m.isHidden || m.name === "default") continue
|
||||
if (m.vendor?.id !== "MODEL_VENDOR_ID_ANTHROPIC") continue
|
||||
if (m.isChatOnly || m.onlySupportsCmdK || m.supportsAgent === false || PICKER_SKIP.has(m.name)) continue
|
||||
const full = withSlugs(m)
|
||||
if (full.variants.some((v) => ids.has(v.legacySlug))) out.push(full)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// fastAt is whether Cursor has a fast variant the account is served at
|
||||
// the context size (any, for a model without sizes): what magpie offers
|
||||
// fast for, which 0.1.x said with a -fast model of its own.
|
||||
@@ -1215,15 +1278,23 @@ function listing(tok, h) {
|
||||
let p = listings.get(h)
|
||||
if (p) return p
|
||||
p = (async () => {
|
||||
const [j, listed] = await Promise.all([
|
||||
const [j, listed, catalog] = await Promise.all([
|
||||
unary(API, "aiserver.v1.AiService/AvailableModels", tok, { useModelParameters: true, doNotUseMarkdown: true }, 30_000),
|
||||
unary(API, "agent.v1.AgentService/GetUsableModels", tok, {}, 8_000).then(
|
||||
(u) => (Array.isArray(u?.models) ? u.models : []),
|
||||
() => [],
|
||||
),
|
||||
// the full catalog, scope 3: the live models the picker lacks (Claude,
|
||||
// on an account Cursor blocks it for); without it the list is the
|
||||
// picker's and the usable list's, as before
|
||||
unary(API, "aiserver.v1.AiService/AvailableModels", tok, { useModelParameters: true, doNotUseMarkdown: true, scope: 3 }, 8_000).then(
|
||||
(c) => (Array.isArray(c?.models) ? c.models : []),
|
||||
() => [],
|
||||
),
|
||||
])
|
||||
const ids = new Set(listed.flatMap((m) => [m?.modelId, m?.displayModelId]).filter(Boolean))
|
||||
const raw = modelsOf(Array.isArray(j?.models) ? j.models : [], ids.size ? ids : null, listed)
|
||||
const picker = Array.isArray(j?.models) ? j.models : []
|
||||
const raw = modelsOf(ids.size ? [...picker, ...fromCatalog(picker, catalog, ids)] : picker, ids.size ? ids : null, listed)
|
||||
if (!raw.length) throw new Error("Cursor listed no models")
|
||||
lists.set(h, { at: Date.now(), raw })
|
||||
listFailed.delete(h)
|
||||
@@ -1330,7 +1401,16 @@ function named(raw, id) {
|
||||
return { entry: near, seed: undefined, effort: "", fast: false }
|
||||
}
|
||||
const old = named(raw, sized[1])
|
||||
if (old) return { ...old, max: !old.entry.size && want > old.entry.context }
|
||||
if (old) {
|
||||
// the name's model at the nearest size it has (claude-opus-4-8-thinking@1m,
|
||||
// an id an earlier list had, is Opus 4.8 at 1m with thinking)
|
||||
const sizes = raw.filter((e) => e.size && e.model === old.entry.model)
|
||||
if (old.entry.size && sizes.length) {
|
||||
const near = sizes.reduce((a, b) => (Math.abs(tokensOf(b.size) - want) < Math.abs(tokensOf(a.size) - want) ? b : a))
|
||||
return { ...old, entry: near }
|
||||
}
|
||||
return { ...old, max: !old.entry.size && want > old.entry.context }
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -3535,4 +3615,4 @@ export async function CursorAuthPlugin(input) {
|
||||
}
|
||||
|
||||
// for tests
|
||||
export const _internal = { credits, kvReply, listFor, lists, keychain, keychainToken, nativeTransport, onDemandOf,resetH1: () => (h1Until = 0), onH1: () => Date.now() < h1Until, resetTeam: () => { teamRead.at = 0; teamRead.info = null }, expireTeam: () => (teamRead.at = 0),H2, H1, h2Blocked, open, openH1, openH2, STEP_WAIT, stepUsage, usageKey, ledger, owed, flights, misses, unreadable, catalog, usable, request, modelsOf, tokensOf, maxRequired, conversationID, usageOf, sessionOf, SESSION, errorResponse, kept, poolBase, conversation, buildRun, decode, exec, fields, pb, pbValue, pbAny, frame, frames, failure, toolsOf, expiry }
|
||||
export const _internal = { slugFor, fromCatalog, credits, kvReply, listFor, lists, keychain, keychainToken, nativeTransport, onDemandOf,resetH1: () => (h1Until = 0), onH1: () => Date.now() < h1Until, resetTeam: () => { teamRead.at = 0; teamRead.info = null }, expireTeam: () => (teamRead.at = 0),H2, H1, h2Blocked, open, openH1, openH2, STEP_WAIT, stepUsage, usageKey, ledger, owed, flights, misses, unreadable, catalog, usable, request, modelsOf, tokensOf, maxRequired, conversationID, usageOf, sessionOf, SESSION, errorResponse, kept, poolBase, conversation, buildRun, decode, exec, fields, pb, pbValue, pbAny, frame, frames, failure, toolsOf, expiry }
|
||||
|
||||
@@ -55,10 +55,13 @@ afterEach(() => {
|
||||
// Cursor's API; the picker answers (ok) or fails, after ms
|
||||
const PICKER = [{ name: "claude-opus-5-5", clientDisplayName: "Claude Opus 5.5", supportsNonMaxMode: true, contextTokenLimit: 300000 }]
|
||||
function fakeAPI(picker) {
|
||||
globalThis.fetch = async (url) => {
|
||||
globalThis.fetch = async (url, init) => {
|
||||
const u = String(url)
|
||||
if (u.endsWith("/GetServerConfig")) return Response.json({ agentUrlConfig: { agentUrl: base } })
|
||||
if (u.endsWith("/GetUsableModels")) return Response.json({ models: [] })
|
||||
// the full catalog (scope 3) is asked alongside, and fails here: it is
|
||||
// not the list this file times
|
||||
if (u.endsWith("/AvailableModels") && JSON.parse(init?.body || "{}").scope) return new Response("down", { status: 503 })
|
||||
if (u.endsWith("/AvailableModels")) {
|
||||
events.push("list asked")
|
||||
await new Promise((r) => setTimeout(r, picker.ms))
|
||||
|
||||
Reference in New Issue
Block a user