diff --git a/packages/cursor/README.md b/packages/cursor/README.md index 3990a54..258544f 100644 --- a/packages/cursor/README.md +++ b/packages/cursor/README.md @@ -203,7 +203,14 @@ minutes), the way pi-cursor-sdk lists Cursor's catalog: (`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. + 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. - An `@` id the list no longer has (`claude-opus-5-5@1m` when only 300k is listed, or the model is listed unsized) runs at the model's nearest size, in Max Mode when the size asked for is over the model's diff --git a/packages/cursor/context.test.mjs b/packages/cursor/context.test.mjs index e6318bd..f8cffd2 100644 --- a/packages/cursor/context.test.mjs +++ b/packages/cursor/context.test.mjs @@ -378,3 +378,65 @@ test("a picker that covers every usable id is listed as before", async () => { const raw = await usable(tok()) expect(raw.some((m) => m.usableOnly)).toBe(false) }) + +// ysm119 on Discord again (after 0.2.24): the Team account's list showed +// "Claude Opus 5 1M Medium Thinking", "Claude Opus 4.7 1M Medium Thinking", +// "Claude Sonnet 4.6 1M Thinking" and "Claude Haiku 5.5" (Cursor's names, +// word for word), read as one tier each, and claude-haiku-5-5-thinking, an +// id 0.1.x listed and still picked, failed its test. The names are the +// reporter's; the ids are Cursor's pattern for them (claude-opus-5-thinking- +// high is one the picker names), as the reporter's list wasn't sent. +const TIERED = [ + ...["low", "medium", "high", "xhigh", "max"].map((e) => ({ modelId: "claude-opus-5-thinking-" + e, displayName: "Claude Opus 5 1M " + { low: "Low", medium: "Medium", high: "High", xhigh: "Extra High", max: "Max" }[e] + " Thinking" })), + ...["low", "medium", "high"].map((e) => ({ modelId: "claude-opus-4-7-thinking-" + e, displayName: "Claude Opus 4.7 1M " + { low: "Low", medium: "Medium", high: "High" }[e] + " Thinking" })), + { modelId: "claude-opus-4-7-thinking-medium-fast", displayName: "Claude Opus 4.7 1M Medium Thinking Fast", maxMode: true }, + { modelId: "claude-sonnet-4-6-thinking", displayName: "Claude Sonnet 4.6 1M Thinking" }, + { modelId: "claude-haiku-5-5", displayName: "Claude Haiku 5.5" }, + ...["low", "medium", "high"].map((e) => ({ modelId: "gpt-5.1-codex-max-" + e, displayName: "GPT-5.1 Codex Max " + { low: "Low", medium: "Medium", high: "High" }[e] })), + { modelId: "gpt-5.1-codex-max-max", displayName: "GPT-5.1 Codex Max Max" }, +] + +test("a usable-only family is named without its tier, wherever Cursor says it, and offers the tiers as efforts", async () => { + fakeAPI([], TIERED) + const raw = await usable(tok()) + const of = (id) => raw.find((m) => m.id === id) + expect(["claude-opus-5-thinking", "claude-opus-4-7-thinking", "claude-sonnet-4-6-thinking", "claude-haiku-5-5", "gpt-5.1-codex-max"].map((id) => [id, of(id)?.name])).toEqual([ + ["claude-opus-5-thinking", "Claude Opus 5 Thinking"], + ["claude-opus-4-7-thinking", "Claude Opus 4.7 Thinking"], + ["claude-sonnet-4-6-thinking", "Claude Sonnet 4.6 Thinking"], + ["claude-haiku-5-5", "Claude Haiku 5.5"], + ["gpt-5.1-codex-max", "GPT-5.1 Codex Max"], + ]) + expect(Object.keys(of("claude-opus-5-thinking").levels)).toEqual(["low", "medium", "high", "xhigh", "max"]) + expect(of("claude-opus-4-7-thinking").offersFast).toBe(true) + // one entry a family: no tier is listed as a model of its own + expect(raw.length).toBe(5) + const q = (id, effort = "", fast) => request(raw, id, effort, fast).id + expect(q("claude-opus-5-thinking")).toBe("claude-opus-5-thinking-medium") + expect(q("claude-opus-5-thinking", "xhigh")).toBe("claude-opus-5-thinking-xhigh") + expect(q("claude-opus-4-7-thinking", "medium", true)).toBe("claude-opus-4-7-thinking-medium-fast") + expect(q("gpt-5.1-codex-max", "max")).toBe("gpt-5.1-codex-max-max") +}) + +test("an id 0.1.x listed with thinking runs as the model without it when that is all the account has", async () => { + fakeAPI([], TIERED) + const raw = await usable(tok()) + const q = (id, effort = "", fast) => request(raw, id, effort, fast).id + // the reporter's pick: Cursor answered the id as it was "AI Model Not Found" + expect(q("claude-haiku-5-5-thinking")).toBe("claude-haiku-5-5") + expect(q("claude-haiku-5-5-thinking", "low")).toBe("claude-haiku-5-5") + expect(q("claude-haiku-5-5-thinking-high")).toBe("claude-haiku-5-5") + // and the other way: an id without thinking, on a model listed with it only + expect(q("claude-opus-5", "high")).toBe("claude-opus-5-thinking-high") + expect(q("claude-sonnet-4-6")).toBe("claude-sonnet-4-6-thinking") + // nothing of it anywhere: as it is named + expect(q("claude-nothing-thinking")).toBe("claude-nothing-thinking") +}) + +test("a picker model with thinking variants only takes an id 0.1.x listed without thinking", async () => { + const haiku = PICKER.find((m) => m.name === "claude-haiku-5-5") + const thinkingOnly = { ...haiku, variants: haiku.variants.filter((v) => v.legacySlug.includes("thinking")) } + fakeAPI([thinkingOnly], null) + const raw = await usable(tok()) + expect(request(raw, "claude-haiku-5-5-low", "", undefined).id).toBe("claude-haiku-5-5-thinking-low") +}) diff --git a/packages/cursor/index.mjs b/packages/cursor/index.mjs index c88d22b..85aef63 100644 --- a/packages/cursor/index.mjs +++ b/packages/cursor/index.mjs @@ -773,14 +773,31 @@ function fromUsable(fam, effort, fast) { return (at && vs.find((u) => u.effort === at)) || vs.find((u) => u.effort === "") || vs.find((u) => u.effort === "medium") || vs[0] } -// usableTitle is a usable id's name without what the id says apart: the +// usableTitle is a usable id's name without what the id says apart: its // effort, fast, and the 1M Cursor names every Max-capable Claude with -// ("Claude Opus 5.5 1M Low" is Claude Opus 5.5). -function usableTitle(name) { - const drop = new Set(["low", "medium", "high", "xhigh", "extra", "max", "minimal", "none", "fast", "1m", "(1m)"]) - const ws = name.split(" ") - while (ws.length > 1 && drop.has(ws.at(-1).toLowerCase())) ws.pop() - return ws.join(" ") +// ("Claude Opus 5.5 1M Low" is Claude Opus 5.5), wherever Cursor puts +// them: "Claude Opus 5 1M Medium Thinking" is Claude Opus 5 Thinking, as +// its efforts are magpie's reasoning levels and not models of their own +// (ysm119 on Discord read "Medium" in the name as the only tier). A word +// of the model's own name stays: GPT-5.1 Codex Max at high is "GPT-5.1 +// Codex Max". +const EFFORT_WORDS = { none: ["None"], minimal: ["Minimal"], low: ["Low"], medium: ["Medium"], high: ["High"], xhigh: ["Extra High", "XHigh"], max: ["Max"] } +function usableTitle(u) { + const ws = u.name.split(" ") + // the last time a phrase is said, past the name's first word + const cutLast = (phrase) => { + const p = phrase.toLowerCase().split(" ") + for (let i = ws.length - p.length; i >= 1; i--) { + if (p.every((w, k) => ws[i + k].toLowerCase() === w)) { + ws.splice(i, p.length) + return true + } + } + return false + } + for (const p of EFFORT_WORDS[u.effort] ?? []) if (cutLast(p)) break + if (u.fast) cutLast("fast") + return ws.filter((w, i) => i === 0 || !/^\(?1m\)?$/i.test(w)).join(" ") || u.name } // modelsOf is the picker's models as offered: one entry for each context @@ -833,7 +850,7 @@ function modelsOf(picker, ids, listed = []) { const def = fromUsable(fam, "", false) // Cursor's context for it isn't known: its default's, as for a model // the picker gives no limit for - out.push({ id: family, run: family, name: usableTitle(def.name), title: usableTitle(def.name), pid: "", levels, fast: false, variants: [], def: undefined, partial: false, model: { name: family }, fam, ids, usableOnly: true, context: DEFAULT_CONTEXT, size: "", offersFast: fam.some((u) => u.fast) }) + out.push({ id: family, run: family, name: usableTitle(def), title: usableTitle(def), pid: "", levels, fast: false, variants: [], def: undefined, partial: false, model: { name: family }, fam, ids, usableOnly: true, context: DEFAULT_CONTEXT, size: "", offersFast: fam.some((u) => u.fast) }) } return out } @@ -1014,6 +1031,21 @@ function named(raw, id) { if (u) return { entry: e, seed: undefined, effort: u.effort, fast: u.fast } if (e.id === of.family) return { entry: e, seed: undefined, effort: of.effort, fast: of.fast } } + // a family neither has, where the account has the same model with + // thinking or without it (claude-haiku-5-5-thinking, which 0.1.x listed, + // on a Team account whose list has Claude Haiku 5.5 without a thinking + // id; ysm119 on Discord): that one, at the id's effort, never the id as + // it is, which Cursor answers "AI Model Not Found" + const loose = (f) => f.replace(/-thinking$/, "") + const key = loose(of.family) + for (const e of models) { + if (e.usableOnly) { + if (loose(e.id) === key) return { entry: e, seed: undefined, effort: of.effort, fast: of.fast } + continue + } + const vs = e.variants.filter((v) => v.legacySlug && loose(familyOf(v.legacySlug).family) === key) + if (vs.length) return as(e, vs, of.effort) + } // an id at a context size the list no longer has (claude-opus-5-5@1m, // picked from an earlier list, or from another account's): the model at // the nearest size it has; a model listed without sizes, in Max Mode for diff --git a/packages/cursor/package.json b/packages/cursor/package.json index efa66a6..52d3027 100644 --- a/packages/cursor/package.json +++ b/packages/cursor/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-cursor-auth", - "version": "0.2.24", + "version": "0.2.25", "description": "Cursor subscriptions (Pro, Pro+, Ultra, Teams) in OpenCode and magpie, through the API cursor-agent talks to", "type": "module", "main": "./index.mjs",