Open History to see the last commit
1import {
2 CODEX_REASONING_EFFORT_OPTIONS,
3 CURSOR_MODEL_FAMILY_OPTIONS,
4 CURSOR_REASONING_OPTIONS,
5 DEFAULT_MODEL_BY_PROVIDER,
6 DEFAULT_REASONING_EFFORT_BY_PROVIDER,
7 MODEL_OPTIONS_BY_PROVIDER,
8 MODEL_SLUG_ALIASES_BY_PROVIDER,
9 REASONING_EFFORT_OPTIONS_BY_PROVIDER,
10 type CodexReasoningEffort,
11 type CursorModelFamily,
12 type CursorModelSlug,
13 type CursorReasoningOption,
14 type ModelSlug,
15 type ProviderKind,
16} from "../../contracts/src";
17
18type CursorModelCapability = {
19 readonly supportsReasoning: boolean;
20 readonly supportsFast: boolean;
21 readonly supportsThinking: boolean;
22 readonly defaultReasoning: CursorReasoningOption;
23 readonly defaultThinking: boolean;
24};
25
26const CURSOR_MODEL_CAPABILITY_BY_FAMILY: Record<CursorModelFamily, CursorModelCapability> = {
27 auto: {
28 supportsReasoning: false,
29 supportsFast: false,
30 supportsThinking: false,
31 defaultReasoning: "normal",
32 defaultThinking: false,
33 },
34 "composer-1.5": {
35 supportsReasoning: false,
36 supportsFast: false,
37 supportsThinking: false,
38 defaultReasoning: "normal",
39 defaultThinking: false,
40 },
41 "composer-1": {
42 supportsReasoning: false,
43 supportsFast: false,
44 supportsThinking: false,
45 defaultReasoning: "normal",
46 defaultThinking: false,
47 },
48 "gpt-5.3-codex": {
49 supportsReasoning: true,
50 supportsFast: true,
51 supportsThinking: false,
52 defaultReasoning: "normal",
53 defaultThinking: false,
54 },
55 "gpt-5.3-codex-spark-preview": {
56 supportsReasoning: false,
57 supportsFast: false,
58 supportsThinking: false,
59 defaultReasoning: "normal",
60 defaultThinking: false,
61 },
62 "opus-4.6": {
63 supportsReasoning: false,
64 supportsFast: false,
65 supportsThinking: true,
66 defaultReasoning: "normal",
67 defaultThinking: true,
68 },
69 "opus-4.5": {
70 supportsReasoning: false,
71 supportsFast: false,
72 supportsThinking: true,
73 defaultReasoning: "normal",
74 defaultThinking: true,
75 },
76 "sonnet-4.6": {
77 supportsReasoning: false,
78 supportsFast: false,
79 supportsThinking: true,
80 defaultReasoning: "normal",
81 defaultThinking: true,
82 },
83 "gemini-3.1-pro": {
84 supportsReasoning: false,
85 supportsFast: false,
86 supportsThinking: false,
87 defaultReasoning: "normal",
88 defaultThinking: false,
89 },
90};
91
92const MODEL_SLUG_SET_BY_PROVIDER: Record<ProviderKind, ReadonlySet<ModelSlug>> = {
93 claudeCode: new Set(MODEL_OPTIONS_BY_PROVIDER.claudeCode.map((option) => option.slug)),
94 codex: new Set(MODEL_OPTIONS_BY_PROVIDER.codex.map((option) => option.slug)),
95 cursor: new Set(MODEL_OPTIONS_BY_PROVIDER.cursor.map((option) => option.slug)),
96};
97
98const CURSOR_MODEL_FAMILY_SET = new Set<CursorModelFamily>(
99 CURSOR_MODEL_FAMILY_OPTIONS.map((option) => option.slug),
100);
101
102export interface CursorModelSelection {
103 readonly family: CursorModelFamily;
104 readonly reasoning: CursorReasoningOption;
105 readonly fast: boolean;
106 readonly thinking: boolean;
107}
108
109export function getModelOptions(provider: ProviderKind = "codex") {
110 return MODEL_OPTIONS_BY_PROVIDER[provider];
111}
112
113export function getCursorModelFamilyOptions() {
114 return CURSOR_MODEL_FAMILY_OPTIONS;
115}
116
117export function getCursorModelCapabilities(family: CursorModelFamily) {
118 return CURSOR_MODEL_CAPABILITY_BY_FAMILY[family];
119}
120
121function fallbackCursorModelFamily(): CursorModelFamily {
122 const fallback = parseCursorModelSelection(DEFAULT_MODEL_BY_PROVIDER.cursor);
123 return fallback.family;
124}
125
126function resolveCursorModelFamily(model: string | null | undefined): CursorModelFamily {
127 const normalized = normalizeModelSlug(model, "cursor");
128 if (!normalized) {
129 return fallbackCursorModelFamily();
130 }
131
132 if (
133 normalized === "gpt-5.3-codex" ||
134 normalized === "gpt-5.3-codex-fast" ||
135 normalized === "gpt-5.3-codex-low" ||
136 normalized === "gpt-5.3-codex-low-fast" ||
137 normalized === "gpt-5.3-codex-high" ||
138 normalized === "gpt-5.3-codex-high-fast" ||
139 normalized === "gpt-5.3-codex-xhigh" ||
140 normalized === "gpt-5.3-codex-xhigh-fast"
141 ) {
142 return "gpt-5.3-codex";
143 }
144
145 if (normalized === "sonnet-4.6-thinking") {
146 return "sonnet-4.6";
147 }
148 if (normalized === "opus-4.6-thinking") {
149 return "opus-4.6";
150 }
151 if (normalized === "opus-4.5-thinking") {
152 return "opus-4.5";
153 }
154
155 return CURSOR_MODEL_FAMILY_SET.has(normalized as CursorModelFamily)
156 ? (normalized as CursorModelFamily)
157 : fallbackCursorModelFamily();
158}
159
160function resolveCursorReasoning(model: CursorModelSlug): CursorReasoningOption {
161 if (model.includes("-xhigh")) return "xhigh";
162 if (model.includes("-high")) return "high";
163 if (model.includes("-low")) return "low";
164 return "normal";
165}
166
167export function parseCursorModelSelection(model: string | null | undefined): CursorModelSelection {
168 const family = resolveCursorModelFamily(model);
169 const capability = CURSOR_MODEL_CAPABILITY_BY_FAMILY[family];
170 const normalized = resolveModelSlugForProvider("cursor", model) as CursorModelSlug;
171
172 if (capability.supportsReasoning) {
173 return {
174 family,
175 reasoning: resolveCursorReasoning(normalized),
176 fast: normalized.endsWith("-fast"),
177 thinking: false,
178 };
179 }
180
181 if (capability.supportsThinking) {
182 return {
183 family,
184 reasoning: capability.defaultReasoning,
185 fast: false,
186 thinking: normalized.endsWith("-thinking"),
187 };
188 }
189
190 return {
191 family,
192 reasoning: capability.defaultReasoning,
193 fast: false,
194 thinking: capability.defaultThinking,
195 };
196}
197
198export function resolveCursorModelFromSelection(input: {
199 readonly family: CursorModelFamily;
200 readonly reasoning?: CursorReasoningOption | null;
201 readonly fast?: boolean;
202 readonly thinking?: boolean;
203}): CursorModelSlug {
204 const family = resolveCursorModelFamily(input.family);
205 const capability = CURSOR_MODEL_CAPABILITY_BY_FAMILY[family];
206
207 if (capability.supportsReasoning) {
208 const reasoning = CURSOR_REASONING_OPTIONS.includes(input.reasoning ?? "normal")
209 ? (input.reasoning ?? "normal")
210 : capability.defaultReasoning;
211 const reasoningSuffix = reasoning === "normal" ? "" : `-${reasoning}`;
212 const fastSuffix = input.fast ? "-fast" : "";
213 const candidate = `${family}${reasoningSuffix}${fastSuffix}`;
214 return resolveModelSlugForProvider("cursor", candidate) as CursorModelSlug;
215 }
216
217 if (capability.supportsThinking) {
218 const candidate = input.thinking ? `${family}-thinking` : family;
219 return resolveModelSlugForProvider("cursor", candidate) as CursorModelSlug;
220 }
221
222 return resolveModelSlugForProvider("cursor", family) as CursorModelSlug;
223}
224
225export function getDefaultModel(provider: ProviderKind = "codex"): ModelSlug {
226 return DEFAULT_MODEL_BY_PROVIDER[provider];
227}
228
229export function normalizeModelSlug(
230 model: string | null | undefined,
231 provider: ProviderKind = "codex",
232): ModelSlug | null {
233 if (typeof model !== "string") {
234 return null;
235 }
236
237 const trimmed = model.trim();
238 if (!trimmed) {
239 return null;
240 }
241
242 return MODEL_SLUG_ALIASES_BY_PROVIDER[provider][trimmed] ?? (trimmed as ModelSlug);
243}
244
245export function resolveModelSlug(
246 model: string | null | undefined,
247 provider: ProviderKind = "codex",
248): ModelSlug {
249 const normalized = normalizeModelSlug(model, provider);
250 if (!normalized) {
251 return DEFAULT_MODEL_BY_PROVIDER[provider];
252 }
253
254 return MODEL_SLUG_SET_BY_PROVIDER[provider].has(normalized)
255 ? normalized
256 : DEFAULT_MODEL_BY_PROVIDER[provider];
257}
258
259export function resolveModelSlugForProvider(
260 provider: ProviderKind,
261 model: string | null | undefined,
262): ModelSlug {
263 return resolveModelSlug(model, provider);
264}
265
266export function getReasoningEffortOptions(
267 provider: ProviderKind = "codex",
268): ReadonlyArray<CodexReasoningEffort> {
269 return REASONING_EFFORT_OPTIONS_BY_PROVIDER[provider];
270}
271
272export function getDefaultReasoningEffort(provider: "codex"): CodexReasoningEffort;
273export function getDefaultReasoningEffort(provider: ProviderKind): CodexReasoningEffort | null;
274export function getDefaultReasoningEffort(
275 provider: ProviderKind = "codex",
276): CodexReasoningEffort | null {
277 return DEFAULT_REASONING_EFFORT_BY_PROVIDER[provider];
278}
279
280export { CODEX_REASONING_EFFORT_OPTIONS };