@rigelbuild/omp-catalog 18.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1204 -0
- package/LICENSE +22 -0
- package/README.md +43 -0
- package/THIRD-PARTY-NOTICES.txt +22909 -0
- package/dist/types/build.d.ts +19 -0
- package/dist/types/compat/anthropic.d.ts +18 -0
- package/dist/types/compat/apply.d.ts +7 -0
- package/dist/types/compat/bedrock.d.ts +3 -0
- package/dist/types/compat/devin.d.ts +9 -0
- package/dist/types/compat/openai.d.ts +28 -0
- package/dist/types/discovery/antigravity.d.ts +70 -0
- package/dist/types/discovery/codex.d.ts +36 -0
- package/dist/types/discovery/cursor-proto.d.ts +5368 -0
- package/dist/types/discovery/cursor.d.ts +23 -0
- package/dist/types/discovery/devin-proto.d.ts +1549 -0
- package/dist/types/discovery/devin.d.ts +24 -0
- package/dist/types/discovery/gemini-cli.d.ts +33 -0
- package/dist/types/discovery/gemini.d.ts +25 -0
- package/dist/types/discovery/gitlab-duo-workflow.d.ts +30 -0
- package/dist/types/discovery/index.d.ts +7 -0
- package/dist/types/discovery/openai-compatible.d.ts +89 -0
- package/dist/types/discovery/protobuf.d.ts +102 -0
- package/dist/types/effort.d.ts +10 -0
- package/dist/types/fireworks-model-id.d.ts +23 -0
- package/dist/types/hosts.d.ts +169 -0
- package/dist/types/identity/bundled.d.ts +3 -0
- package/dist/types/identity/classify.d.ts +69 -0
- package/dist/types/identity/dialect.d.ts +3 -0
- package/dist/types/identity/family.d.ts +239 -0
- package/dist/types/identity/id.d.ts +12 -0
- package/dist/types/identity/index.d.ts +8 -0
- package/dist/types/identity/markers.d.ts +4 -0
- package/dist/types/identity/priority.d.ts +1 -0
- package/dist/types/identity/reference.d.ts +29 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/model-cache.d.ts +23 -0
- package/dist/types/model-manager.d.ts +77 -0
- package/dist/types/model-thinking.d.ts +70 -0
- package/dist/types/model-tokenizer.d.ts +8 -0
- package/dist/types/models.d.ts +14 -0
- package/dist/types/openai-pricing.d.ts +17 -0
- package/dist/types/provider-models/bundled-references.d.ts +13 -0
- package/dist/types/provider-models/cache-provider-id.d.ts +11 -0
- package/dist/types/provider-models/descriptor-types.d.ts +76 -0
- package/dist/types/provider-models/descriptors.d.ts +505 -0
- package/dist/types/provider-models/google.d.ts +29 -0
- package/dist/types/provider-models/index.d.ts +7 -0
- package/dist/types/provider-models/ollama.d.ts +22 -0
- package/dist/types/provider-models/openai-compat.d.ts +646 -0
- package/dist/types/provider-models/special.d.ts +53 -0
- package/dist/types/types.d.ts +876 -0
- package/dist/types/utils.d.ts +20 -0
- package/dist/types/variant-collapse.d.ts +137 -0
- package/dist/types/wire/alibaba-token-plan.d.ts +22 -0
- package/dist/types/wire/codex.d.ts +66 -0
- package/dist/types/wire/coreweave.d.ts +12 -0
- package/dist/types/wire/gemini-headers.d.ts +62 -0
- package/dist/types/wire/github-copilot.d.ts +47 -0
- package/dist/types/wire/image-fetchers.d.ts +76 -0
- package/package.json +102 -0
- package/src/build.ts +103 -0
- package/src/compat/anthropic.ts +179 -0
- package/src/compat/apply.ts +15 -0
- package/src/compat/bedrock.ts +153 -0
- package/src/compat/devin.ts +12 -0
- package/src/compat/openai.ts +864 -0
- package/src/discovery/antigravity.ts +257 -0
- package/src/discovery/codex.ts +456 -0
- package/src/discovery/cursor-proto.ts +8329 -0
- package/src/discovery/cursor.ts +409 -0
- package/src/discovery/devin-proto.ts +2037 -0
- package/src/discovery/devin.ts +152 -0
- package/src/discovery/gemini-cli.ts +198 -0
- package/src/discovery/gemini.ts +260 -0
- package/src/discovery/gitlab-duo-workflow.ts +859 -0
- package/src/discovery/index.ts +7 -0
- package/src/discovery/openai-compatible.ts +266 -0
- package/src/discovery/protobuf.ts +1073 -0
- package/src/effort.ts +18 -0
- package/src/fireworks-model-id.ts +50 -0
- package/src/hosts.ts +178 -0
- package/src/identity/bundled.ts +28 -0
- package/src/identity/classify.ts +242 -0
- package/src/identity/dialect.ts +42 -0
- package/src/identity/family.ts +477 -0
- package/src/identity/id.ts +81 -0
- package/src/identity/index.ts +8 -0
- package/src/identity/markers.ts +49 -0
- package/src/identity/priority.ts +59 -0
- package/src/identity/reference.ts +167 -0
- package/src/index.ts +19 -0
- package/src/model-cache.ts +346 -0
- package/src/model-manager.ts +683 -0
- package/src/model-thinking.ts +925 -0
- package/src/model-tokenizer.ts +75 -0
- package/src/models.json +304657 -0
- package/src/models.json.d.ts +9 -0
- package/src/models.ts +108 -0
- package/src/openai-pricing.ts +29 -0
- package/src/provider-models/bundled-references.ts +87 -0
- package/src/provider-models/cache-provider-id.ts +97 -0
- package/src/provider-models/descriptor-types.ts +85 -0
- package/src/provider-models/descriptors.ts +585 -0
- package/src/provider-models/google.ts +117 -0
- package/src/provider-models/index.ts +7 -0
- package/src/provider-models/ollama.ts +204 -0
- package/src/provider-models/openai-compat.ts +6405 -0
- package/src/provider-models/special.ts +213 -0
- package/src/types.ts +1032 -0
- package/src/utils.ts +69 -0
- package/src/variant-collapse.ts +1555 -0
- package/src/wire/alibaba-token-plan.ts +54 -0
- package/src/wire/codex.ts +117 -0
- package/src/wire/coreweave.ts +51 -0
- package/src/wire/gemini-headers.ts +135 -0
- package/src/wire/github-copilot.ts +147 -0
- package/src/wire/image-fetchers.ts +159 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import * as http2 from "node:http2";
|
|
2
|
+
import { type } from "@rigelbuild/omp-omptype";
|
|
3
|
+
import { isKimiK3ModelId } from "../identity";
|
|
4
|
+
import { bareModelId, parseGlmModel, semverGte } from "../identity/classify";
|
|
5
|
+
import { getBundledModels } from "../models";
|
|
6
|
+
import { toModelSpec } from "../provider-models/bundled-references";
|
|
7
|
+
import type { Model, ModelSpec } from "../types";
|
|
8
|
+
import { GetUsableModelsRequestSchema, GetUsableModelsResponseSchema } from "./cursor-proto";
|
|
9
|
+
import { create, fromBinary, toBinary } from "./protobuf";
|
|
10
|
+
|
|
11
|
+
const CURSOR_DEFAULT_BASE_URL = "https://api2.cursor.sh";
|
|
12
|
+
const CURSOR_DEFAULT_CLIENT_VERSION = "cli-2026.02.13-41ac335";
|
|
13
|
+
const CURSOR_GET_USABLE_MODELS_PATH = "/agent.v1.AgentService/GetUsableModels";
|
|
14
|
+
|
|
15
|
+
const DEFAULT_CONTEXT_WINDOW = 200_000;
|
|
16
|
+
const DEFAULT_MAX_TOKENS = 64_000;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `GetUsableModels` carries no context-window field, so the 1M ceiling is
|
|
20
|
+
* recovered from the signals Cursor does send:
|
|
21
|
+
* - display-name labels ("Opus 5 1M", "GPT-5.5 1M High") across families,
|
|
22
|
+
* - natively 1M families Cursor serves unlabeled (Kimi K3, GLM 5.2+),
|
|
23
|
+
* - the max-mode flag on Claude/Gemini ids, whose max-mode ceiling is 1M.
|
|
24
|
+
*/
|
|
25
|
+
const CURSOR_1M_CONTEXT_WINDOW = 1_000_000;
|
|
26
|
+
const CURSOR_1M_NAME_PATTERN = /\b1m\b/i;
|
|
27
|
+
const CURSOR_MAX_MODE_1M_ID_PATTERN = /claude|gemini/;
|
|
28
|
+
/** Kimi's official bare K3 id (`k3`, `kimi/k3`); `k3-256k` is the 256k SKU and stays out. */
|
|
29
|
+
const CURSOR_KIMI_K3_BARE_ID_PATTERN = /(^|\/)k3$/i;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Versioned Cursor Grok ids (`cursor-grok-4.5`, `cursor-grok-4.6-high`) are
|
|
33
|
+
* reasoning models whose effort is carried in the per-tier sibling id.
|
|
34
|
+
* `GetUsableModels` ships no `thinkingDetails` and the bundled references read
|
|
35
|
+
* `reasoning: false`, so classification falls back to the id. The non-reasoning
|
|
36
|
+
* `grok-code-*` coding models lack the version digit and stay out.
|
|
37
|
+
*/
|
|
38
|
+
const CURSOR_GROK_REASONING_ID_PATTERN = /^cursor-grok-\d/i;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Model-id families whose native catalogs (anthropic, openai/openai-codex,
|
|
42
|
+
* google) are multimodal. Cursor-only or text-only families (`composer-*`,
|
|
43
|
+
* `grok-code-*`) intentionally stay outside this pattern.
|
|
44
|
+
*/
|
|
45
|
+
const CURSOR_MULTIMODAL_ID_PATTERN = /claude|gemini|gpt-|codex/;
|
|
46
|
+
|
|
47
|
+
const OptionalDisplayNameSchema = type("unknown").pipe(raw => (typeof raw === "string" ? raw : undefined));
|
|
48
|
+
const CursorAliasesSchema = type("unknown").pipe(raw => {
|
|
49
|
+
if (Array.isArray(raw)) {
|
|
50
|
+
return raw.filter((alias: unknown): alias is string => typeof alias === "string");
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const CursorModelDetailsSchema = type({
|
|
56
|
+
modelId: "string",
|
|
57
|
+
displayName: OptionalDisplayNameSchema.default(undefined),
|
|
58
|
+
displayNameShort: OptionalDisplayNameSchema.default(undefined),
|
|
59
|
+
displayModelId: OptionalDisplayNameSchema.default(undefined),
|
|
60
|
+
aliases: CursorAliasesSchema.default(() => []),
|
|
61
|
+
"thinkingDetails?": "unknown",
|
|
62
|
+
maxMode: "boolean = false",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const CursorModelsInnerSchema = type("unknown[]");
|
|
66
|
+
const ResilientCursorModelsSchema = type("unknown").pipe(raw => {
|
|
67
|
+
const out = CursorModelsInnerSchema(raw);
|
|
68
|
+
return out instanceof type.errors ? [] : out;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const CursorDecodedResponseSchema = type({
|
|
72
|
+
models: ResilientCursorModelsSchema.default(() => []),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
type CursorModelDetailsValue = typeof CursorModelDetailsSchema.infer;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Options for fetching dynamic Cursor models from `GetUsableModels`.
|
|
79
|
+
*/
|
|
80
|
+
export interface CursorModelDiscoveryOptions {
|
|
81
|
+
/** Cursor access token used for bearer authentication. */
|
|
82
|
+
apiKey: string;
|
|
83
|
+
/** Optional Cursor API base URL override. */
|
|
84
|
+
baseUrl?: string;
|
|
85
|
+
/** Optional client version override sent as `x-cursor-client-version`. */
|
|
86
|
+
clientVersion?: string;
|
|
87
|
+
/** Optional request timeout in milliseconds. */
|
|
88
|
+
timeoutMs?: number;
|
|
89
|
+
/** Optional list of custom Cursor model ids to include in request context. */
|
|
90
|
+
customModelIds?: string[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Fetches Cursor models through `GetUsableModels` and normalizes them into canonical model entries.
|
|
95
|
+
*
|
|
96
|
+
* Returns `null` on request/decode failures.
|
|
97
|
+
* Returns `[]` only when the endpoint responds successfully with no usable models.
|
|
98
|
+
*/
|
|
99
|
+
export async function fetchCursorUsableModels(
|
|
100
|
+
options: CursorModelDiscoveryOptions,
|
|
101
|
+
): Promise<ModelSpec<"cursor-agent">[] | null> {
|
|
102
|
+
const timeoutMs = options.timeoutMs ?? 5_000;
|
|
103
|
+
try {
|
|
104
|
+
const requestPayload = create(GetUsableModelsRequestSchema, {
|
|
105
|
+
customModelIds: normalizeCustomModelIds(options.customModelIds),
|
|
106
|
+
});
|
|
107
|
+
const body = toBinary(GetUsableModelsRequestSchema, requestPayload);
|
|
108
|
+
const baseUrl = (options.baseUrl ?? CURSOR_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
109
|
+
|
|
110
|
+
const responseBuffer = await fetchViaHttp2(baseUrl, body, options, timeoutMs);
|
|
111
|
+
|
|
112
|
+
if (!responseBuffer) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const decoded = decodeGetUsableModelsResponse(responseBuffer);
|
|
116
|
+
const parsedDecoded = CursorDecodedResponseSchema(decoded);
|
|
117
|
+
if (parsedDecoded instanceof type.errors) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const references = createCursorReferenceMap();
|
|
122
|
+
return normalizeCursorModels(parsedDecoded.models, options.baseUrl, references);
|
|
123
|
+
} catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function buildRequestHeaders(options: CursorModelDiscoveryOptions): Record<string, string> {
|
|
129
|
+
return {
|
|
130
|
+
"content-type": "application/proto",
|
|
131
|
+
te: "trailers",
|
|
132
|
+
authorization: `Bearer ${options.apiKey}`,
|
|
133
|
+
"x-ghost-mode": "true",
|
|
134
|
+
"x-cursor-client-version": options.clientVersion ?? CURSOR_DEFAULT_CLIENT_VERSION,
|
|
135
|
+
"x-cursor-client-type": "cli",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** HTTP/2 transport required by Cursor API (HTTP/1.1 is rejected with 464). */
|
|
140
|
+
async function fetchViaHttp2(
|
|
141
|
+
baseUrl: string,
|
|
142
|
+
body: Uint8Array,
|
|
143
|
+
options: CursorModelDiscoveryOptions,
|
|
144
|
+
timeoutMs: number,
|
|
145
|
+
): Promise<Uint8Array | null> {
|
|
146
|
+
const { promise, resolve } = Promise.withResolvers<Uint8Array | null>();
|
|
147
|
+
const client = http2.connect(baseUrl);
|
|
148
|
+
const timer = setTimeout(() => {
|
|
149
|
+
client.destroy();
|
|
150
|
+
resolve(null);
|
|
151
|
+
}, timeoutMs);
|
|
152
|
+
|
|
153
|
+
client.on("error", () => {
|
|
154
|
+
clearTimeout(timer);
|
|
155
|
+
resolve(null);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const req = client.request({
|
|
159
|
+
":method": "POST",
|
|
160
|
+
":path": CURSOR_GET_USABLE_MODELS_PATH,
|
|
161
|
+
...buildRequestHeaders(options),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const chunks: Buffer[] = [];
|
|
165
|
+
req.on("data", (chunk: Buffer) => chunks.push(chunk));
|
|
166
|
+
req.on("end", () => {
|
|
167
|
+
clearTimeout(timer);
|
|
168
|
+
client.close();
|
|
169
|
+
resolve(new Uint8Array(Buffer.concat(chunks)));
|
|
170
|
+
});
|
|
171
|
+
req.on("error", () => {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
client.close();
|
|
174
|
+
resolve(null);
|
|
175
|
+
});
|
|
176
|
+
req.on("response", headers => {
|
|
177
|
+
const status = Number(headers[":status"] ?? 0);
|
|
178
|
+
if (status < 200 || status >= 300) {
|
|
179
|
+
clearTimeout(timer);
|
|
180
|
+
client.close();
|
|
181
|
+
resolve(null);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
if (body.length > 0) {
|
|
186
|
+
req.end(Buffer.from(body));
|
|
187
|
+
} else {
|
|
188
|
+
req.end();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return promise;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function normalizeCustomModelIds(customModelIds: readonly string[] | undefined): string[] {
|
|
195
|
+
if (!customModelIds) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
const normalized = new Set<string>();
|
|
199
|
+
for (const value of customModelIds) {
|
|
200
|
+
if (typeof value !== "string") {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const trimmed = value.trim();
|
|
204
|
+
if (!trimmed) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
normalized.add(trimmed);
|
|
208
|
+
}
|
|
209
|
+
return [...normalized];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function createCursorReferenceMap(): Map<string, ModelSpec<"cursor-agent">> {
|
|
213
|
+
const references = new Map<string, ModelSpec<"cursor-agent">>();
|
|
214
|
+
for (const model of getBundledModels("cursor")) {
|
|
215
|
+
references.set(model.id, toModelSpec(model as Model<"cursor-agent">));
|
|
216
|
+
}
|
|
217
|
+
return references;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function decodeGetUsableModelsResponse(payload: Uint8Array) {
|
|
221
|
+
if (payload.length === 0) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const framedBody = decodeConnectUnaryBody(payload);
|
|
226
|
+
if (framedBody) {
|
|
227
|
+
try {
|
|
228
|
+
return fromBinary(GetUsableModelsResponseSchema, framedBody);
|
|
229
|
+
} catch {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
return fromBinary(GetUsableModelsResponseSchema, payload);
|
|
236
|
+
} catch {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function decodeConnectUnaryBody(payload: Uint8Array): Uint8Array | null {
|
|
242
|
+
if (payload.length < 5) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
let offset = 0;
|
|
247
|
+
while (offset + 5 <= payload.length) {
|
|
248
|
+
const flags = payload[offset];
|
|
249
|
+
const view = new DataView(payload.buffer, payload.byteOffset + offset, payload.byteLength - offset);
|
|
250
|
+
const messageLength = view.getUint32(1, false);
|
|
251
|
+
const frameEnd = offset + 5 + messageLength;
|
|
252
|
+
if (frameEnd > payload.length) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
const compressionFlagSet = (flags & 0b0000_0001) !== 0;
|
|
256
|
+
if (compressionFlagSet) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const endStreamFlagSet = (flags & 0b0000_0010) !== 0;
|
|
260
|
+
if (!endStreamFlagSet) {
|
|
261
|
+
return payload.subarray(offset + 5, frameEnd);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
offset = frameEnd;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function normalizeCursorModels(
|
|
271
|
+
models: readonly unknown[] | undefined,
|
|
272
|
+
baseUrlOverride: string | undefined,
|
|
273
|
+
references: Map<string, ModelSpec<"cursor-agent">>,
|
|
274
|
+
): ModelSpec<"cursor-agent">[] {
|
|
275
|
+
if (!models || models.length === 0) {
|
|
276
|
+
return [];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const byId = new Map<string, ModelSpec<"cursor-agent">>();
|
|
280
|
+
for (const model of models) {
|
|
281
|
+
const normalized = normalizeCursorModel(model, baseUrlOverride, references);
|
|
282
|
+
if (!normalized) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
byId.set(normalized.id, normalized);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return [...byId.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function normalizeCursorModel(
|
|
292
|
+
model: unknown,
|
|
293
|
+
baseUrlOverride: string | undefined,
|
|
294
|
+
references: Map<string, ModelSpec<"cursor-agent">>,
|
|
295
|
+
): ModelSpec<"cursor-agent"> | null {
|
|
296
|
+
const parsedModel = CursorModelDetailsSchema(model);
|
|
297
|
+
if (parsedModel instanceof type.errors) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const details = parsedModel;
|
|
302
|
+
const id = details.modelId.trim();
|
|
303
|
+
if (!id) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const name = pickModelDisplayName(details, id);
|
|
308
|
+
const reference = references.get(id);
|
|
309
|
+
const reasoning =
|
|
310
|
+
isKimiK3ModelId(id) ||
|
|
311
|
+
CURSOR_GROK_REASONING_ID_PATTERN.test(id) ||
|
|
312
|
+
Boolean(details.thinkingDetails) ||
|
|
313
|
+
reference?.reasoning === true;
|
|
314
|
+
|
|
315
|
+
if (reference) {
|
|
316
|
+
return {
|
|
317
|
+
...reference,
|
|
318
|
+
id,
|
|
319
|
+
name,
|
|
320
|
+
baseUrl: baseUrlOverride ?? reference.baseUrl,
|
|
321
|
+
reasoning,
|
|
322
|
+
contextWindow: resolveCursorContextWindow(details, id, reference.contextWindow),
|
|
323
|
+
cursorMaxMode: details.maxMode,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
id,
|
|
328
|
+
name,
|
|
329
|
+
api: "cursor-agent",
|
|
330
|
+
provider: "cursor",
|
|
331
|
+
baseUrl: baseUrlOverride ?? CURSOR_DEFAULT_BASE_URL,
|
|
332
|
+
reasoning,
|
|
333
|
+
input: inferInputFromCursorId(id),
|
|
334
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
335
|
+
contextWindow: resolveCursorContextWindow(details, id, DEFAULT_CONTEXT_WINDOW),
|
|
336
|
+
maxTokens: DEFAULT_MAX_TOKENS,
|
|
337
|
+
cursorMaxMode: details.maxMode,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Context window for a discovered Cursor model: the 1M ceiling when any 1M
|
|
343
|
+
* signal fires (never below a larger bundled reference), else the fallback.
|
|
344
|
+
*/
|
|
345
|
+
function resolveCursorContextWindow(
|
|
346
|
+
model: CursorModelDetailsValue,
|
|
347
|
+
id: string,
|
|
348
|
+
fallback: number | null,
|
|
349
|
+
): number | null {
|
|
350
|
+
const labeled1M =
|
|
351
|
+
CURSOR_1M_NAME_PATTERN.test(id) ||
|
|
352
|
+
[model.displayName, model.displayNameShort, model.displayModelId, ...model.aliases].some(
|
|
353
|
+
candidate => typeof candidate === "string" && CURSOR_1M_NAME_PATTERN.test(candidate),
|
|
354
|
+
);
|
|
355
|
+
if (labeled1M || isCursorNative1MModelId(id) || (model.maxMode && CURSOR_MAX_MODE_1M_ID_PATTERN.test(id))) {
|
|
356
|
+
return Math.max(fallback ?? 0, CURSOR_1M_CONTEXT_WINDOW);
|
|
357
|
+
}
|
|
358
|
+
return fallback;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Natively 1M-context families Cursor serves without a "1M" label: Kimi K3 and
|
|
363
|
+
* GLM 5.2+ coding SKUs. The shared family parsers cover namespace forms
|
|
364
|
+
* (`moonshotai/kimi-k3`, `z-ai/glm-5.2`) and future GLM versions (`glm-5.10`,
|
|
365
|
+
* `glm-6`); vision and sub-1M variants stay out via the same gates as
|
|
366
|
+
* `isGlm52ReasoningEffortModelId`.
|
|
367
|
+
*/
|
|
368
|
+
function isCursorNative1MModelId(id: string): boolean {
|
|
369
|
+
if (isKimiK3ModelId(id) || CURSOR_KIMI_K3_BARE_ID_PATTERN.test(id)) {
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
const glm = parseGlmModel(bareModelId(id));
|
|
373
|
+
if (!glm || glm.vision) {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
if (glm.variant !== "base" && glm.variant !== "air" && glm.variant !== "turbo") {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
return semverGte(glm.version, "5.2");
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function pickModelDisplayName(model: CursorModelDetailsValue, fallbackId: string): string {
|
|
383
|
+
const candidates = [model.displayName, model.displayNameShort, model.displayModelId, ...model.aliases, fallbackId];
|
|
384
|
+
for (const candidate of candidates) {
|
|
385
|
+
if (typeof candidate !== "string") {
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
const trimmed = candidate.trim();
|
|
389
|
+
if (trimmed) {
|
|
390
|
+
return trimmed;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return fallbackId;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Infers input modalities for Cursor models without a bundled reference.
|
|
398
|
+
*
|
|
399
|
+
* `GetUsableModels` carries no per-model modality metadata, so classification
|
|
400
|
+
* falls back to the model family: families that are multimodal in OMP's own
|
|
401
|
+
* native catalogs accept images, everything else stays text-only. Mirrors
|
|
402
|
+
* `inferInputFromGeminiId` in ./gemini.ts.
|
|
403
|
+
*/
|
|
404
|
+
function inferInputFromCursorId(id: string): ("text" | "image")[] {
|
|
405
|
+
if (CURSOR_MULTIMODAL_ID_PATTERN.test(id.toLowerCase())) {
|
|
406
|
+
return ["text", "image"];
|
|
407
|
+
}
|
|
408
|
+
return ["text"];
|
|
409
|
+
}
|