Skip to content

Commit 379d95f

Browse files
author
jun
committed
fix(server): report the effective context window, not the provider cap
contextWindow is already narrowed by providerContextCaps; contextCap is the raw operator knob and is set on every row of a capped provider even when the cap did not bite, so preferring it over-reported models whose real window sits below the cap. Freeze the shared api_types constant and copy it per row.
1 parent f1a9a2c commit 379d95f

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎src/server/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,9 @@ export function startServer(port?: number, deps: StartServerDeps = {}): Server<W
15661566
...grokEffortFields(m.reasoningEfforts ?? [], m.defaultReasoningEffort),
15671567
...modelCapabilityFields({
15681568
reasoningEfforts: m.reasoningEfforts,
1569-
contextWindow: m.contextCap ?? m.contextWindow,
1569+
// contextWindow is already the post-cap effective value; contextCap is the raw
1570+
// operator knob and over-reports models whose real window sits below it.
1571+
contextWindow: m.contextWindow,
15701572
inputModalities: m.inputModalities,
15711573
}),
15721574
};

‎src/server/models-capabilities.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* when NO OpenAI-family type (`chat_completions`/`responses`/`openai_chat`/`openai_responses`)
1616
* is present. Keep at least one OpenAI-family entry; a unit test guards this.
1717
*/
18-
export const OPENCODEX_MODEL_API_TYPES: readonly string[] = ["chat_completions", "responses", "anthropic_messages"];
18+
export const OPENCODEX_MODEL_API_TYPES: readonly string[] = Object.freeze(["chat_completions", "responses", "anthropic_messages"]);
1919

2020
export const OPENAI_FAMILY_API_TYPES: ReadonlySet<string> = new Set(["chat_completions", "responses", "openai_chat", "openai_responses"]);
2121

@@ -52,7 +52,7 @@ export function modelCapabilityFields(input: ModelCapabilityInput): ModelCapabil
5252
: undefined;
5353
const supportsVision = modalities !== undefined ? modalities.includes("image") : undefined;
5454
return {
55-
api_types: OPENCODEX_MODEL_API_TYPES,
55+
api_types: [...OPENCODEX_MODEL_API_TYPES],
5656
capabilities: {
5757
...(contextLength !== undefined ? { context_length: contextLength } : {}),
5858
// Once a gateway advertises api_types, Cursor keeps only rows whose output_modalities

‎tests/cursor-local-models-schema.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,21 @@ describe("raw /v1/models list advertises Cursor local-agent capabilities", () =>
143143
await server.stop(true);
144144
}
145145
});
146+
147+
test("context_length is the effective window, not the provider cap, when the cap does not bite", async () => {
148+
const config = capabilityConfig();
149+
// Cap above k3's real window: contextWindow stays 200000 while contextCap records 350000.
150+
config.providerContextCaps = { kimi: 350000 };
151+
saveConfig(config);
152+
const server = startServer(0);
153+
try {
154+
const res = await fetch(new URL("/v1/models", server.url));
155+
const body = await res.json() as { data: Array<Record<string, unknown>> };
156+
const k3 = body.data.find(m => m.id === "kimi/k3");
157+
expect(k3).toBeDefined();
158+
expect((k3!.capabilities as Record<string, unknown>).context_length).toBe(200000);
159+
} finally {
160+
await server.stop(true);
161+
}
162+
});
146163
});

0 commit comments

Comments
 (0)