|
| 1 | +import type { ModelInfo, ReasoningEffortWithMinimal } from "../model.js" |
| 2 | +import { openAiNativeModels } from "./openai.js" |
| 3 | + |
| 4 | +export type CodexModelId = |
| 5 | + | "gpt-5-codex" |
| 6 | + | "gpt-5-codex-minimal" |
| 7 | + | "gpt-5-codex-low" |
| 8 | + | "gpt-5-codex-medium" |
| 9 | + | "gpt-5-codex-high" |
| 10 | + | "gpt-5" |
| 11 | + | "gpt-5-minimal" |
| 12 | + | "gpt-5-low" |
| 13 | + | "gpt-5-medium" |
| 14 | + | "gpt-5-high" |
| 15 | + | "codex-mini-latest" |
| 16 | + |
| 17 | +export type CodexCliModelInfo = { |
| 18 | + id: string |
| 19 | + label?: string |
| 20 | + description?: string |
| 21 | + model?: string |
| 22 | + effort?: ReasoningEffortWithMinimal |
| 23 | +} |
| 24 | + |
| 25 | +export interface CodexCliPreset { |
| 26 | + id: CodexModelId |
| 27 | + label: string |
| 28 | + description: string |
| 29 | + cliModel: string |
| 30 | + effort?: ReasoningEffortWithMinimal |
| 31 | +} |
| 32 | + |
| 33 | +export const codexDefaultModelId: CodexModelId = "gpt-5-codex" |
| 34 | + |
| 35 | +const CLI_DEFAULT_MODEL = "gpt-5" |
| 36 | + |
| 37 | +const codexBaseModelInfo: ModelInfo = { |
| 38 | + ...openAiNativeModels["gpt-5-2025-08-07"], |
| 39 | + supportsReasoningEffort: true, |
| 40 | +} |
| 41 | + |
| 42 | +export const codexCliPresets: CodexCliPreset[] = [ |
| 43 | + { |
| 44 | + id: "gpt-5-codex", |
| 45 | + label: "gpt-5-codex (auto)", |
| 46 | + description: "— uses your Codex CLI default reasoning effort", |
| 47 | + cliModel: CLI_DEFAULT_MODEL, |
| 48 | + }, |
| 49 | + { |
| 50 | + id: "gpt-5-codex-minimal", |
| 51 | + label: "gpt-5-codex minimal", |
| 52 | + description: "— fastest responses with limited reasoning; ideal for lightweight edits and quick fixes", |
| 53 | + cliModel: CLI_DEFAULT_MODEL, |
| 54 | + effort: "minimal", |
| 55 | + }, |
| 56 | + { |
| 57 | + id: "gpt-5-codex-low", |
| 58 | + label: "gpt-5-codex low", |
| 59 | + description: "— prioritises speed while keeping some reasoning depth for straightforward coding tasks", |
| 60 | + cliModel: CLI_DEFAULT_MODEL, |
| 61 | + effort: "low", |
| 62 | + }, |
| 63 | + { |
| 64 | + id: "gpt-5-codex-medium", |
| 65 | + label: "gpt-5-codex medium", |
| 66 | + description: "— balanced reasoning for everyday development work (Codex CLI default)", |
| 67 | + cliModel: CLI_DEFAULT_MODEL, |
| 68 | + effort: "medium", |
| 69 | + }, |
| 70 | + { |
| 71 | + id: "gpt-5-codex-high", |
| 72 | + label: "gpt-5-codex high", |
| 73 | + description: "— maximum reasoning depth for complex or ambiguous engineering problems", |
| 74 | + cliModel: CLI_DEFAULT_MODEL, |
| 75 | + effort: "high", |
| 76 | + }, |
| 77 | +] |
| 78 | + |
| 79 | +const legacyRedirectEntries: ReadonlyArray<[string, CodexModelId]> = [ |
| 80 | + ["gpt-5", "gpt-5-codex"], |
| 81 | + ["gpt-5-minimal", "gpt-5-codex-minimal"], |
| 82 | + ["gpt-5-low", "gpt-5-codex-low"], |
| 83 | + ["gpt-5-medium", "gpt-5-codex-medium"], |
| 84 | + ["gpt-5-high", "gpt-5-codex-high"], |
| 85 | + ["gpt-5-codex", "gpt-5-codex"], |
| 86 | + ["gpt-5-codex-minimal", "gpt-5-codex-minimal"], |
| 87 | + ["gpt-5-codex-low", "gpt-5-codex-low"], |
| 88 | + ["gpt-5-codex-medium", "gpt-5-codex-medium"], |
| 89 | + ["gpt-5-codex-high", "gpt-5-codex-high"], |
| 90 | + ["codex-mini-latest", "codex-mini-latest"], |
| 91 | +] |
| 92 | + |
| 93 | +export const codexLegacyModelRedirects: Record<string, CodexModelId> = Object.fromEntries(legacyRedirectEntries) |
| 94 | + |
| 95 | +const presetMap = new Map<CodexModelId, CodexCliPreset>() |
| 96 | + |
| 97 | +for (const preset of codexCliPresets) { |
| 98 | + presetMap.set(preset.id, preset) |
| 99 | +} |
| 100 | + |
| 101 | +for (const [legacyId, targetId] of legacyRedirectEntries) { |
| 102 | + const target = presetMap.get(targetId as CodexModelId) |
| 103 | + if (target && !presetMap.has(legacyId as CodexModelId)) { |
| 104 | + presetMap.set(legacyId as CodexModelId, { |
| 105 | + ...target, |
| 106 | + id: legacyId as CodexModelId, |
| 107 | + }) |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +const derivedModels: Record<string, ModelInfo> = {} |
| 112 | + |
| 113 | +for (const preset of presetMap.values()) { |
| 114 | + derivedModels[preset.id] = { |
| 115 | + ...codexBaseModelInfo, |
| 116 | + description: preset.description || codexBaseModelInfo.description, |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +if (openAiNativeModels["codex-mini-latest"]) { |
| 121 | + derivedModels["codex-mini-latest"] = { |
| 122 | + ...openAiNativeModels["codex-mini-latest"], |
| 123 | + supportsReasoningEffort: true, |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +export const codexModels = derivedModels as Record<CodexModelId, ModelInfo> |
| 128 | + |
| 129 | +export const fallbackCodexCliModels: CodexCliModelInfo[] = codexCliPresets.map((preset) => ({ |
| 130 | + id: preset.id, |
| 131 | + label: preset.label, |
| 132 | + description: preset.description, |
| 133 | + model: preset.cliModel, |
| 134 | + effort: preset.effort, |
| 135 | +})) |
| 136 | + |
| 137 | +export const normalizeCodexModelId = (id?: string | null): CodexModelId => { |
| 138 | + const trimmed = (id ?? "").trim() |
| 139 | + if (!trimmed) { |
| 140 | + return codexDefaultModelId |
| 141 | + } |
| 142 | + return (codexLegacyModelRedirects[trimmed] ?? trimmed) as CodexModelId |
| 143 | +} |
| 144 | + |
| 145 | +export const getCodexPreset = (id: string | undefined) => { |
| 146 | + const normalized = normalizeCodexModelId(id) |
| 147 | + return presetMap.get(normalized) |
| 148 | +} |
0 commit comments