1use serde::{Deserialize, Deserializer, Serialize, Serializer};
17use std::fmt;
18
19#[derive(Debug, Clone, PartialEq, Eq, Hash)]
21pub enum CodexModel {
22 Gpt61Sol,
24 Gpt61Terra,
27 Gpt6Astra,
32 Gpt6Sol,
34 Gpt6Luna,
36 DaybreakBlue,
39 DaybreakRed,
42 Gpt56Sol,
44 Gpt56Terra,
46 Gpt56Luna,
48 Gpt55,
50 Gpt54,
52 Gpt54Mini,
54 Gpt52,
56 CodexAutoReview,
59 Custom(String),
62}
63
64impl CodexModel {
65 pub fn cli_arg(&self) -> &str {
67 match self {
68 Self::Gpt61Sol => "gpt-6.1-sol",
69 Self::Gpt61Terra => "gpt-6.1-terra",
70 Self::Gpt6Astra => "gpt-6-astra",
71 Self::Gpt6Sol => "gpt-6-sol",
72 Self::Gpt6Luna => "gpt-6-luna",
73 Self::DaybreakBlue => "gpt-daybreak-blue-latest",
74 Self::DaybreakRed => "gpt-daybreak-red-latest",
75 Self::Gpt56Sol => "gpt-5.6-sol",
76 Self::Gpt56Terra => "gpt-5.6-terra",
77 Self::Gpt56Luna => "gpt-5.6-luna",
78 Self::Gpt55 => "gpt-5.5",
79 Self::Gpt54 => "gpt-5.4",
80 Self::Gpt54Mini => "gpt-5.4-mini",
81 Self::Gpt52 => "gpt-5.2",
82 Self::CodexAutoReview => "codex-auto-review",
83 Self::Custom(s) => s.as_str(),
84 }
85 }
86
87 pub fn as_str(&self) -> &str {
90 self.cli_arg()
91 }
92
93 pub fn display_name(&self) -> &str {
95 match self {
96 Self::Gpt61Sol => "GPT-6.1-Sol",
97 Self::Gpt61Terra => "GPT-6.1 Terra",
98 Self::Gpt6Astra => "GPT-6-Astra",
99 Self::Gpt6Sol => "GPT-6-Sol",
100 Self::Gpt6Luna => "GPT-6-Luna",
101 Self::DaybreakBlue => "Daybreak Blue",
102 Self::DaybreakRed => "Daybreak Red",
103 Self::Gpt56Sol => "GPT-5.6-Sol",
104 Self::Gpt56Terra => "GPT-5.6-Terra",
105 Self::Gpt56Luna => "GPT-5.6-Luna",
106 Self::Gpt55 => "GPT-5.5",
107 Self::Gpt54 => "GPT-5.4",
108 Self::Gpt54Mini => "GPT-5.4-Mini",
109 Self::Gpt52 => "GPT-5.2",
110 Self::CodexAutoReview => "Codex Auto Review",
111 Self::Custom(s) => s.as_str(),
112 }
113 }
114
115 pub fn known() -> &'static [CodexModel] {
117 &[
118 Self::Gpt61Sol,
119 Self::Gpt61Terra,
120 Self::Gpt6Astra,
121 Self::Gpt6Sol,
122 Self::Gpt6Luna,
123 Self::DaybreakBlue,
124 Self::DaybreakRed,
125 Self::Gpt56Sol,
126 Self::Gpt56Terra,
127 Self::Gpt56Luna,
128 Self::Gpt55,
129 Self::Gpt54,
130 Self::Gpt54Mini,
131 Self::Gpt52,
132 Self::CodexAutoReview,
133 ]
134 }
135}
136
137impl fmt::Display for CodexModel {
138 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139 f.write_str(self.cli_arg())
140 }
141}
142
143impl From<&str> for CodexModel {
144 fn from(s: &str) -> Self {
145 match s {
146 "gpt-6.1-sol" => Self::Gpt61Sol,
147 "gpt-6.1-terra" => Self::Gpt61Terra,
148 "gpt-6-astra" => Self::Gpt6Astra,
149 "gpt-6-sol" => Self::Gpt6Sol,
150 "gpt-6-luna" => Self::Gpt6Luna,
151 "gpt-daybreak-blue-latest" => Self::DaybreakBlue,
152 "gpt-daybreak-red-latest" => Self::DaybreakRed,
153 "gpt-5.6-sol" => Self::Gpt56Sol,
154 "gpt-5.6-terra" => Self::Gpt56Terra,
155 "gpt-5.6-luna" => Self::Gpt56Luna,
156 "gpt-5.5" => Self::Gpt55,
157 "gpt-5.4" => Self::Gpt54,
158 "gpt-5.4-mini" => Self::Gpt54Mini,
159 "gpt-5.2" => Self::Gpt52,
160 "codex-auto-review" => Self::CodexAutoReview,
161 other => Self::Custom(other.to_string()),
162 }
163 }
164}
165
166impl From<CodexModel> for String {
167 fn from(model: CodexModel) -> Self {
168 model.cli_arg().to_string()
169 }
170}
171
172impl Serialize for CodexModel {
173 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
174 serializer.serialize_str(self.cli_arg())
175 }
176}
177
178impl<'de> Deserialize<'de> for CodexModel {
179 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
180 let s = String::deserialize(deserializer)?;
181 Ok(Self::from(s.as_str()))
182 }
183}
184
185#[cfg(test)]
186mod tests {
187 use super::CodexModel;
188
189 #[test]
190 fn test_gpt61_sol_catalog_and_wire_round_trip() {
191 let model = CodexModel::from("gpt-6.1-sol");
192 assert_eq!(model, CodexModel::Gpt61Sol);
193 assert!(CodexModel::known().contains(&model));
194 assert_eq!(model.display_name(), "GPT-6.1-Sol");
195 assert_eq!(model.to_string(), "gpt-6.1-sol");
196 let json = serde_json::to_string(&model).unwrap();
197 assert_eq!(json, "\"gpt-6.1-sol\"");
198 assert_eq!(serde_json::from_str::<CodexModel>(&json).unwrap(), model);
199 let slug: String = model.into();
200 assert_eq!(slug, "gpt-6.1-sol");
201 }
202
203 #[test]
204 fn test_gpt6_family_catalog_entries() {
205 for (slug, model, label) in [
206 ("gpt-6-sol", CodexModel::Gpt6Sol, "GPT-6-Sol"),
207 ("gpt-6-luna", CodexModel::Gpt6Luna, "GPT-6-Luna"),
208 ("gpt-6.1-terra", CodexModel::Gpt61Terra, "GPT-6.1 Terra"),
209 ] {
210 assert_eq!(CodexModel::from(slug), model);
211 assert!(CodexModel::known().contains(&model));
212 assert_eq!(model.display_name(), label);
213 let json = serde_json::to_string(&model).unwrap();
214 assert_eq!(json, format!("\"{slug}\""));
215 assert_eq!(serde_json::from_str::<CodexModel>(&json).unwrap(), model);
216 }
217 }
218
219 #[test]
220 fn test_cli_arg_round_trip() {
221 for model in CodexModel::known() {
222 assert_eq!(&CodexModel::from(model.cli_arg()), model);
223 }
224 assert_eq!(
225 CodexModel::from("gpt-9-experimental"),
226 CodexModel::Custom("gpt-9-experimental".to_string())
227 );
228 }
229
230 #[test]
231 fn test_into_string_matches_cli_arg() {
232 let s: String = CodexModel::Gpt56Sol.into();
233 assert_eq!(s, "gpt-5.6-sol");
234 }
235
236 #[test]
237 fn test_converts_into_thread_start_model_field() {
238 let model: Option<String> = Some(CodexModel::Gpt55.into());
240 assert_eq!(model.as_deref(), Some("gpt-5.5"));
241 }
242
243 #[test]
244 fn test_serde_round_trip() {
245 let json = serde_json::to_string(&CodexModel::Gpt54Mini).unwrap();
246 assert_eq!(json, "\"gpt-5.4-mini\"");
247 let back: CodexModel = serde_json::from_str(&json).unwrap();
248 assert_eq!(back, CodexModel::Gpt54Mini);
249 }
250}