cursor 0.1.7: a model Cursor serves only in Max Mode is asked for in Max Mode, and the models Cursor's picker offers beyond the CLI's list (GLM-5.3, GLM-5.3 Flash) are listed (ARNO on Discord: "Cursor: Max Mode Required: The model "gpt-5.6-luna-low" requires Max Mode to be enabled"; "cursor provider 里少了 glm-5.3 和 glm-5.3-flash")

The Run's model went as ModelDetails and RequestedModel with its id alone, never max_mode (ModelDetails field 7, RequestedModel field 2), so a model Cursor serves only in Max Mode was refused. cursor-agent (2026.10.01) turns Max Mode on for such a model itself: requiresMaxMode is supportsNonMaxMode === false or a variant's isMaxMode in AiService/AvailableModels, and a usable model's own maxMode is kept. Now the list notes Max Mode from GetUsableModels' maxMode and from the picker (AvailableModels with useModelParameters, as the CLI asks for it), the Run sends it, and a model neither says it of is asked once more in Max Mode when Cursor answers "Max Mode Required" (the CLI's MAX_MODE_REQUIRED), and in Max Mode from then on. An account Max Mode isn't open to gets Cursor's own answer.

The list was GetUsableModels alone, which is `cursor-agent models`; Cursor's picker offers models it leaves out. The picker's models that no usable id, name or slug names are added: one per variant with a legacy slug, else the model by its name with its default variant's parameters, sent as RequestedModel.parameters; hidden, chat-only, Tab-only and non-agent models, and the four the CLI drops, stay out. A picker Cursor can't give leaves the list as it was.

The tests now import nonet.mjs first: fetch and HTTP/2 reach only this machine, so a test without its fake, or work still running after it, can't send a token to Cursor. maxmode.test.mjs (fake API and agent API: the list with GLM-5.3 and its Flash and Max Mode marked, the picker down, the Run's max_mode and parameters, the retry after Cursor's refusal) fails without the change (5 of 5) and passes with it; bun test packages/cursor (27 pass) and bun scripts/check.mjs pass. No request was made to Cursor.
This commit is contained in:
yetone
2026-10-02 22:10:35 +08:00
parent bcfb867635
commit 3ae3e4393e
8 changed files with 367 additions and 16 deletions
+9
View File
@@ -70,6 +70,15 @@ The `config` hook declares `auto` (Cursor's pick). Once signed in, the
is. `-fast` and `-thinking` models stay models of their own; a
`service_tier` of `priority` picks the fast one.
- The context window is 1M for a model whose name says 1M, else 200K.
- Cursor's model picker (`AiService/AvailableModels`, as the CLI asks for
it) adds the models it offers that the usable list leaves out (GLM-5.3,
GLM-5.3 Flash), run with the picker variant's parameters; hidden and
Tab-only models stay out.
- A model Cursor serves only in Max Mode (the usable list's `maxMode`, a
picker model with no other mode, or a Max Mode variant) is asked for in
Max Mode, as the CLI turns it on for one. A model neither says it of is
asked again in Max Mode when Cursor answers "Max Mode Required", and so
from then on.
## Not included
+1
View File
@@ -3,6 +3,7 @@
// (magpie #498, internal/gateway/cursor_conversation_test.go), against a
// fake Cursor: its API answered by a stand-in fetch, its agent API by an
// HTTP/2 server here. Nothing reaches Cursor.
import "./nonet.mjs" // first: no request leaves this machine
import { afterAll, afterEach, beforeAll, expect, test } from "bun:test"
import http2 from "node:http2"
import { CursorAuthPlugin, _internal } from "./index.mjs"
+1
View File
@@ -1,6 +1,7 @@
// A request Cursor fails is answered with the status and words magpie's
// built-in Cursor (internal/gateway/cursor.go, cursorFailure) gave it, so the
// gateway moves on to the next account or member as it did.
import "./nonet.mjs" // first: no request leaves this machine
import { expect, test } from "bun:test"
import { CursorAuthPlugin, _internal } from "./index.mjs"
+131 -15
View File
@@ -602,14 +602,19 @@ function modelID(raw, model, effort, fast) {
return vs[fitEffort(effort, levels)]
}
// usable is the account's list, as `cursor-agent models` has it: its ids,
// names and the id each is run by; kept a while, by token.
// usable is the account's list: what `cursor-agent models` has
// (GetUsableModels: its ids, names and the id each is run by, and whether
// Cursor serves it in Max Mode), and the models Cursor's model picker
// offers that it leaves out (parameterized). Kept a while, by token.
const lists = new Map()
async function usable(tok) {
const h = createHash("sha256").update(tok).digest("hex")
const had = lists.get(h)
if (had && Date.now() - had.at < MODELS_KEEP) return had.raw
const j = await unary(API, "agent.v1.AgentService/GetUsableModels", tok, {}, 30_000)
const [j, picker] = await Promise.all([
unary(API, "agent.v1.AgentService/GetUsableModels", tok, {}, 30_000),
parameterized(tok),
])
const raw = []
for (const m of j?.models ?? []) {
const id = m.displayModelId || m.modelId
@@ -617,13 +622,88 @@ async function usable(tok) {
// some names come with zero-width spaces and doubled ones
let name = String(m.displayName || id).replaceAll("​", "").split(/\s+/).filter(Boolean).join(" ")
name = name.replace(/\(default\)$/, "").trim().replace(/\(current\)$/, "").trim()
raw.push({ id, name, context: contextOf(name), run: m.modelId || id })
const run = m.modelId || id
// Max Mode as the CLI sends it: the list's own say, else the picker's
// (a model with no other mode, or a variant that is Max Mode's)
const maxMode = m.maxMode === true || !!(picker.slugs.get(id)?.maxMode || picker.slugs.get(run)?.maxMode)
raw.push({ id, name, context: contextOf(name), run, ...(maxMode ? { maxMode } : {}) })
}
if (!raw.length) throw new Error("Cursor listed no models")
for (const m of picker.extra(raw)) raw.push(m)
lists.set(h, { at: Date.now(), raw })
return raw
}
// left out of the CLI's picker as it leaves them out (model-service.ts)
const PICKER_SKIP = new Set(["claude-4.5-haiku", "claude-4.5-haiku-thinking", "gemini-2.5-pro", "gemini-2.5-flash"])
// needsMax is whether a variant of a picker's model is run in Max Mode
// only, as the CLI reads it: a model with no other mode, or a Max Mode
// variant.
const needsMax = (m, v) => m?.supportsNonMaxMode === false || v?.isMaxMode === true
// parameterized is Cursor's model picker (AiService/AvailableModels, as
// the CLI asks for it): each id a model goes by (its name, legacy slugs,
// each variant's slug) with the model and variant it is, and extra(raw),
// the picker's models the usable list doesn't have, as entries of it (a
// model added since, such as GLM-5.3, or one the account hasn't turned
// on). A picker Cursor can't give is none.
async function parameterized(tok) {
let models = []
try {
const j = await unary(API, "aiserver.v1.AiService/AvailableModels", tok, { useModelParameters: true, doNotUseMarkdown: true }, 8_000)
models = Array.isArray(j?.models) ? j.models : []
} catch {}
const slugs = new Map()
const namesOf = (m) => {
const vs = m.variants ?? []
return [m.name, m.serverModelName, ...(m.legacySlugs ?? []), ...(m.idAliases ?? []), ...vs.flatMap((v) => [v.legacySlug, v.variantStringRepresentation])].filter(Boolean)
}
for (const m of models) {
const vs = m.variants ?? []
for (const v of vs) for (const s of [v.legacySlug, v.variantStringRepresentation]) if (s && !slugs.has(s)) slugs.set(s, { maxMode: needsMax(m, v) })
for (const s of [m.name, m.serverModelName, ...(m.legacySlugs ?? [])]) if (s && !slugs.has(s)) slugs.set(s, { maxMode: needsMax(m, defaultVariant(m)) })
}
const extra = (raw) => {
const have = new Set(raw.flatMap((r) => [r.id, r.run]))
const out = []
for (const m of models) {
if (!m?.name || m.isHidden || m.isChatOnly || m.onlySupportsCmdK || m.supportsAgent === false || PICKER_SKIP.has(m.name)) continue
if (namesOf(m).some((s) => have.has(s))) continue
const title = clean(m.clientDisplayName || m.name)
const params = (v) => (v?.parameterValues ?? []).map((p) => ({ id: String(p.id ?? ""), value: String(p.value ?? "") })).filter((p) => p.id)
const entry = (id, name, v) => {
const maxMode = needsMax(m, v)
const limit = (maxMode && m.contextTokenLimitForMaxMode) || m.contextTokenLimit
return { id, name, context: limit > 0 ? limit : contextOf(name), run: m.name, params: params(v), ...(maxMode ? { maxMode } : {}) }
}
const named = (m.variants ?? []).filter((v) => v.legacySlug)
if (named.length) {
for (const v of named) {
if (have.has(v.legacySlug)) continue
have.add(v.legacySlug)
const label = clean(v.displayNameOutsidePicker || [title, v.displayName].filter(Boolean).join(" "))
out.push(entry(v.legacySlug, label, v))
}
} else if (!have.has(m.name)) {
have.add(m.name)
out.push(entry(m.name, title, defaultVariant(m)))
}
}
return out
}
return { slugs, extra }
}
// defaultVariant is the variant the CLI picks for a model asked for by
// name: its default without Max Mode, else with it, else the first.
const defaultVariant = (m) => {
const vs = m?.variants ?? []
return vs.find((v) => v.isDefaultNonMaxConfig) ?? vs.find((v) => v.isDefaultMaxConfig) ?? vs[0]
}
const clean = (s) => String(s ?? "").replaceAll("​", "").split(/\s+/).filter(Boolean).join(" ")
function runtimeModel(m) {
return {
id: m.id,
@@ -1084,8 +1164,11 @@ function usageOf(uf) {
// buildRun is the Run's first message, an AgentClientMessage with its
// run_request, and the blobs it names. The conversation state is the
// messages and one turn, which the server wants there to sample at all.
// conv is the conversation_id (conversationID), a new one when "".
function buildRun(msgs, lastUser, tools, model, conv = "") {
// conv is the conversation_id (conversationID), a new one when "". The
// model goes as the CLI sends it: in Max Mode when maxMode is set (Cursor
// refuses a model it serves only that way otherwise: "Max Mode
// Required"), with the picker variant's parameters when it has them.
function buildRun(msgs, lastUser, tools, model, conv = "", { maxMode = false, params = [] } = {}) {
const blobs = new Map()
const put = (b) => {
const id = createHash("sha256").update(b).digest()
@@ -1106,13 +1189,22 @@ function buildRun(msgs, lastUser, tools, model, conv = "") {
mcp.bytes(1, d)
}
const action = pb().bytes(2, pb().bytes(2, rc)) // resume_action
// ModelDetails: model_id, display_model_id, display_name, max_mode (7);
// RequestedModel: model_id, max_mode (2), parameters (3)
const details = pb().str(1, model).str(3, model).str(4, model)
const requested = pb().str(1, model)
if (maxMode) {
details.varint(7, 1)
requested.varint(2, 1)
}
for (const p of params) requested.bytes(3, pb().str(1, p.id).str(2, p.value))
const rr = pb()
.bytes(1, state)
.bytes(2, action)
.bytes(3, pb().str(1, model).str(3, model).str(4, model))
.bytes(3, details)
.bytes(4, mcp)
.str(5, conv || randomUUID())
.bytes(9, pb().str(1, model))
.bytes(9, requested)
.varint(19, 1) // inline images
return { first: pb().bytes(1, rr).done(), blobs }
}
@@ -1179,8 +1271,8 @@ function open(base, headers, signal) {
// runOnce is one Run of the chat on the agent API at base: an async
// iterator of the answer's pieces, or the error it failed with before any.
async function runOnce({ tok, base, id, tools, conv, convID, signal }) {
const { first, blobs } = buildRun(conv.msgs, conv.last, tools, id, convID)
async function runOnce({ tok, base, id, tools, conv, convID, signal, maxMode, params }) {
const { first, blobs } = buildRun(conv.msgs, conv.last, tools, id, convID, { maxMode, params })
const o = await open(
base,
{
@@ -1438,6 +1530,14 @@ function kept(res) {
// answer runs a chat completion on Cursor, the account kept (errorResponse).
const answer = async (auth, chat, signal, session) => kept(await answerOf(auth, chat, signal, session))
// maxOnly are the ids Cursor said it serves in Max Mode only.
const maxOnly = new Set()
// maxRequired is Cursor's refusal of a model asked for without Max Mode
// (the CLI's MAX_MODE_REQUIRED): "Max Mode Required: The model "x"
// requires Max Mode to be enabled. …"
const maxRequired = (msg) => /max[ _]mode[ _]required|requires max mode/i.test(String(msg ?? ""))
// answerOf runs a chat completion on Cursor and answers it as one, streamed
// or not.
async function answerOf(auth, chat, signal, session = "") {
@@ -1454,18 +1554,34 @@ async function answerOf(auth, chat, signal, session = "") {
} catch {}
const fast = chat.service_tier === "priority" || chat.service_tier === "fast"
let id = modelID(raw, model, chat.reasoning_effort ?? "", fast)
id = raw.find((m) => m.id === id)?.run ?? id
const entry = raw.find((m) => m.id === id)
id = entry?.run ?? id
if (id === "auto") id = "default" // Cursor's pick, which its API calls default
const params = entry?.params ?? []
let maxMode = !!entry?.maxMode || maxOnly.has(id)
const tools = toolsOf(chat)
const conv = conversation(chat, tools)
const convID = conversationID(chat, session)
const base = await agentURL(tok, false)
let r = await runOnce({ tok, base, id, tools, conv, convID, signal })
let base = await agentURL(tok, false)
const once = () => runOnce({ tok, base, id, tools, conv, convID, signal, maxMode, params })
let r = await once()
if (r.error && regional(r.error.message)) {
// the team moved, or the config was kept from before: once more with
// what the config says now
const fresh = await agentURL(tok, true)
if (fresh !== base) r = await runOnce({ tok, base: fresh, id, tools, conv, convID, signal })
if (fresh !== base) {
base = fresh
r = await once()
}
}
if (r.error && !maxMode && maxRequired(r.error.message)) {
// a model Cursor serves only in Max Mode that neither list said so of:
// in Max Mode, as the CLI turns it on for such a model, and so from
// now on. An account Max Mode isn't open to is answered as Cursor
// answers that.
maxMode = true
maxOnly.add(id)
r = await once()
}
if (r.error) return errorResponse(r.error)
const it = r.events
@@ -1609,4 +1725,4 @@ export async function CursorAuthPlugin() {
}
// for tests
export const _internal = { conversationID, usageOf, sessionOf, SESSION, errorResponse, kept, poolBase, splitID, families, byEffort, offered, modelID, conversation, buildRun, decode, exec, fields, pb, pbValue, pbAny, frame, frames, failure, toolsOf, expiry }
export const _internal = { usable, maxRequired, conversationID, usageOf, sessionOf, SESSION, errorResponse, kept, poolBase, splitID, families, byEffort, offered, modelID, conversation, buildRun, decode, exec, fields, pb, pbValue, pbAny, frame, frames, failure, toolsOf, expiry }
+205
View File
@@ -0,0 +1,205 @@
// A model Cursor serves only in Max Mode is asked for in Max Mode, as the
// CLI does ("Max Mode Required: The model "gpt-5.6-luna-low" requires Max
// Mode to be enabled", ARNO on Discord), and the models Cursor's picker
// offers beyond the CLI's usable list (GLM-5.3, GLM-5.3 Flash) are listed
// and run — against a fake Cursor: its API a stand-in fetch, its agent API
// an HTTP/2 server here. Nothing reaches Cursor.
import "./nonet.mjs" // first: no request leaves this machine
import { afterAll, afterEach, beforeAll, expect, test } from "bun:test"
import http2 from "node:http2"
import { CursorAuthPlugin, _internal } from "./index.mjs"
const { fields, pb, frame, usable, offered, maxRequired } = _internal
const real = globalThis.fetch
afterEach(() => (globalThis.fetch = real))
const jwt = (exp) => ["e30", Buffer.from(JSON.stringify({ exp })).toString("base64url"), "sig"].join(".")
let n = 0
// a sign-in of its own, so no list kept for another is used
const fresh = () => ({ type: "oauth", access: jwt(Math.floor(Date.now() / 1000) + 7200 + 50_000 + ++n), refresh: "", expires: 0, accountId: "a@b.c" })
const USABLE = [
{ modelId: "gpt-5.6-luna-low", displayName: "GPT-5.6 Luna Low" },
{ modelId: "gpt-5.6-luna-high", displayName: "GPT-5.6 Luna High" },
{ modelId: "claude-opus-5-5-max", displayName: "Claude Opus 5.5 1M Max", maxMode: true },
{ modelId: "composer-2.5", displayName: "Composer 2.5" },
{ modelId: "grok-4.7-low", displayName: "Grok 4.7 Low" },
]
// Cursor's picker, as AvailableModels answers it in JSON
const PICKER = [
{
name: "gpt-5.6-luna",
clientDisplayName: "GPT-5.6 Luna",
supportsMaxMode: true,
supportsNonMaxMode: false,
variants: [
{ parameterValues: [{ id: "reasoning", value: "low" }], displayName: "Low", isMaxMode: true, legacySlug: "gpt-5.6-luna-low" },
{ parameterValues: [{ id: "reasoning", value: "high" }], displayName: "High", isMaxMode: true, legacySlug: "gpt-5.6-luna-high" },
],
},
{ name: "composer-2.5", clientDisplayName: "Composer 2.5", supportsNonMaxMode: true, variants: [{ displayName: "", isMaxMode: false, legacySlug: "composer-2.5" }] },
{
name: "glm-5.3",
clientDisplayName: "GLM-5.3",
supportsNonMaxMode: true,
supportsMaxMode: true,
contextTokenLimit: 200000,
variants: [
{ parameterValues: [{ id: "thinking", value: "true" }], displayName: "", isMaxMode: false, isDefaultNonMaxConfig: true },
{ parameterValues: [{ id: "thinking", value: "true" }], displayName: "", isMaxMode: true, isDefaultMaxConfig: true },
],
},
{ name: "glm-5.3-flash", clientDisplayName: "GLM-5.3 Flash", supportsNonMaxMode: true },
{ name: "secret-model", clientDisplayName: "Secret", isHidden: true },
{ name: "tab-only", clientDisplayName: "Tab", onlySupportsCmdK: true },
{ name: "claude-4.5-haiku", clientDisplayName: "Haiku 4.5" },
]
// the agent API: each Run's model noted; one asked for without Max Mode
// that only has it is refused as Cursor refuses it
let server, base
const runs = []
const maxOnly = new Set(["gpt-5.6-luna-low", "gpt-5.6-luna-high", "secret-max"])
const str = (fs, num) => fs.find((f) => f.num === num)?.data?.toString() ?? ""
const num = (fs, k) => fs.find((f) => f.num === k)?.n ?? 0
beforeAll(async () => {
server = http2.createServer()
server.on("stream", (stream) => {
stream.respond({ ":status": 200, "content-type": "application/connect+proto" })
let buf = Buffer.alloc(0)
let answered = false
stream.on("data", (c) => {
buf = Buffer.concat([buf, c])
if (answered || buf.length < 5 || buf.length < 5 + buf.readUInt32BE(1)) return
answered = true
const rr = fields(fields(buf.subarray(5, 5 + buf.readUInt32BE(1))).find((f) => f.num === 1).data)
const details = fields(rr.find((f) => f.num === 3).data)
const requested = fields(rr.find((f) => f.num === 9).data)
const run = {
model: str(details, 1),
detailsMax: num(details, 7),
requested: str(requested, 1),
requestedMax: num(requested, 2),
params: requested.filter((f) => f.num === 3).map((f) => fields(f.data)).map((p) => [str(p, 1), str(p, 2)]),
}
runs.push(run)
const end = (body) => {
const b = Buffer.from(JSON.stringify(body))
const head = Buffer.alloc(5)
head[0] = 2
head.writeUInt32BE(b.length, 1)
stream.end(Buffer.concat([head, b]))
}
if (maxOnly.has(run.model) && !run.detailsMax) {
const detail = `The model "${run.model}" requires Max Mode to be enabled. Please enable Max Mode and try again.`
return end({ error: { code: "failed_precondition", message: "Error", details: [{ debug: { error: "ERROR_MAX_MODE_REQUIRED", details: { title: "Max Mode Required", detail } } }] } })
}
const update = (k, body) => frame(pb().bytes(1, pb().bytes(k, body)).done())
stream.write(update(1, pb().str(1, "hi").done()))
stream.write(update(14, pb().varint(1, 10).varint(2, 1).done()))
end({})
})
stream.on("error", () => {})
})
await new Promise((r) => server.listen(0, "127.0.0.1", r))
base = `http://127.0.0.1:${server.address().port}`
})
afterAll(() => server.close())
function fakeAPI({ picker = PICKER, pickerDown = false } = {}) {
const asked = []
globalThis.fetch = async (url, init) => {
const u = String(url)
asked.push(u)
if (u === "https://api2.cursor.sh/aiserver.v1.ServerConfigService/GetServerConfig") return Response.json({ agentUrlConfig: { agentUrl: base } })
if (u === "https://api2.cursor.sh/agent.v1.AgentService/GetUsableModels") return Response.json({ models: USABLE })
if (u === "https://api2.cursor.sh/aiserver.v1.AiService/AvailableModels") {
if (pickerDown) return new Response("down", { status: 503 })
expect(JSON.parse(init.body)).toEqual({ useModelParameters: true, doNotUseMarkdown: true })
return Response.json({ models: picker })
}
throw new Error("the test asked " + u)
}
return asked
}
async function ask(auth, model, effort) {
const hooks = await CursorAuthPlugin()
const l = await hooks.auth.loader(async () => auth)
const chat = { model, messages: [{ role: "user", content: "hello" }], ...(effort ? { reasoning_effort: effort } : {}) }
const res = await l.fetch(base + "/v1/chat/completions", { method: "POST", body: JSON.stringify(chat) })
return { status: res.status, body: await res.json() }
}
test("Cursor's Max Mode refusal is recognised", () => {
expect(maxRequired('Max Mode Required: The model "gpt-5.6-luna-low" requires Max Mode to be enabled. Please enable M')).toBe(true)
expect(maxRequired("MAX_MODE_REQUIRED")).toBe(true)
expect(maxRequired("usage limit reached: slow down")).toBe(false)
})
test("the list has the picker's models the usable list lacks, and says which need Max Mode", async () => {
fakeAPI()
const tok = fresh().access
const raw = await usable(tok)
const by = Object.fromEntries(raw.map((m) => [m.id, m]))
expect(by["gpt-5.6-luna-low"].maxMode).toBe(true) // the picker's say
expect(by["claude-opus-5-5-max"].maxMode).toBe(true) // the usable list's own
expect(by["composer-2.5"].maxMode).toBeUndefined()
expect(by["grok-4.7-low"].maxMode).toBeUndefined() // in neither: as before
expect(by["glm-5.3"]).toEqual({ id: "glm-5.3", name: "GLM-5.3", context: 200000, run: "glm-5.3", params: [{ id: "thinking", value: "true" }] })
expect(by["glm-5.3-flash"]).toMatchObject({ id: "glm-5.3-flash", name: "GLM-5.3 Flash", run: "glm-5.3-flash", params: [] })
for (const gone of ["secret-model", "tab-only", "claude-4.5-haiku", "gpt-5.6-luna", "composer-2.5-1"]) expect(by[gone]).toBeUndefined()
// offered: GLM-5.3 and its Flash beside the families
const ids = offered(raw).map((m) => m.id)
expect(ids).toEqual(["gpt-5.6-luna", "claude-opus-5-5-max", "composer-2.5", "grok-4.7-low", "glm-5.3", "glm-5.3-flash"])
// the provider's list, as magpie asks for it
fakeAPI()
const hooks = await CursorAuthPlugin()
const listed = await hooks.provider.models({ models: {} }, { auth: fresh() })
expect(Object.keys(listed)).toContain("glm-5.3")
expect(Object.keys(listed)).toContain("glm-5.3-flash")
})
test("a picker Cursor can't give leaves the usable list as it was", async () => {
fakeAPI({ pickerDown: true })
const raw = await usable(fresh().access)
expect(raw.map((m) => m.id)).toEqual(USABLE.map((m) => m.modelId))
expect(raw.find((m) => m.id === "claude-opus-5-5-max").maxMode).toBe(true)
})
test("a Max Mode model is run in Max Mode, once, and a picker-only model with its parameters", async () => {
fakeAPI()
const auth = fresh()
runs.length = 0
let r = await ask(auth, "gpt-5.6-luna", "low")
expect([r.status, r.body.error]).toEqual([200, undefined])
expect(r.body.choices[0].message.content).toBe("hi")
expect(runs).toEqual([{ model: "gpt-5.6-luna-low", detailsMax: 1, requested: "gpt-5.6-luna-low", requestedMax: 1, params: [] }])
runs.length = 0
r = await ask(auth, "glm-5.3")
expect(r.status).toBe(200)
expect(runs).toEqual([{ model: "glm-5.3", detailsMax: 0, requested: "glm-5.3", requestedMax: 0, params: [["thinking", "true"]] }])
runs.length = 0
r = await ask(auth, "composer-2.5")
expect(r.status).toBe(200)
expect(runs).toEqual([{ model: "composer-2.5", detailsMax: 0, requested: "composer-2.5", requestedMax: 0, params: [] }])
})
test("a model neither list says needs Max Mode is asked again in Max Mode when Cursor says so", async () => {
// no picker: the usable list alone, which doesn't say it
fakeAPI({ pickerDown: true })
const auth = fresh()
runs.length = 0
let r = await ask(auth, "gpt-5.6-luna", "high")
expect([r.status, r.body.error]).toEqual([200, undefined])
expect(runs.map((x) => [x.model, x.detailsMax, x.requestedMax])).toEqual([["gpt-5.6-luna-high", 0, 0], ["gpt-5.6-luna-high", 1, 1]])
// and from then on in Max Mode at once
runs.length = 0
r = await ask(auth, "gpt-5.6-luna", "high")
expect(r.status).toBe(200)
expect(runs.map((x) => [x.model, x.detailsMax])).toEqual([["gpt-5.6-luna-high", 1]])
})
+18
View File
@@ -0,0 +1,18 @@
// Imported first by every test here: nothing a test runs reaches Cursor.
// fetch and HTTP/2 go to this machine (a test's fake) or fail, so a test
// left without its fake, or work still going after it, can't send a token
// to api2.cursor.sh or the agent API.
import http2 from "node:http2"
const local = (u) => /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\])(:\d+)?(\/|$)/.test(u)
const realFetch = globalThis.fetch
globalThis.fetch = async (input, init) => {
const u = typeof input === "string" ? input : input instanceof URL ? input.href : input.url
if (!local(u)) throw new Error("a test asked " + u + " with no fake in place")
return realFetch(input, init)
}
const connect = http2.connect
http2.connect = (origin, ...rest) => {
if (!local(String(origin))) throw new Error("a test connected to " + origin)
return connect(origin, ...rest)
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-cursor-auth",
"version": "0.1.6",
"version": "0.1.7",
"description": "Cursor subscriptions (Pro, Pro+, Ultra, Teams) in OpenCode and magpie, through the API cursor-agent talks to",
"type": "module",
"main": "./index.mjs",
+1
View File
@@ -1,6 +1,7 @@
// auth.usage tells what magpie's built-in Cursor account shows
// (internal/provider/cursor_usage.go), against Cursor's replies as its tests
// give them (cursor_usage_test.go).
import "./nonet.mjs" // first: no request leaves this machine
import { afterEach, expect, test } from "bun:test"
import { CursorAuthPlugin, _internal } from "./index.mjs"