diff --git a/src-tauri/src/codex_config.rs b/src-tauri/src/codex_config.rs index 5f1a7ddb6..ac9b43bf1 100644 --- a/src-tauri/src/codex_config.rs +++ b/src-tauri/src/codex_config.rs @@ -766,7 +766,10 @@ pub fn read_codex_model_catalog_simplified_from_live() -> Result, /// Given `config.toml` text, resolve the on-disk path of the cc-switch–owned /// catalog file (returns `None` if `model_catalog_json` is absent or points at /// a file we don't own). Relative paths fall back to `generated_path`. -fn resolve_cc_switch_catalog_path(config_text: &str, generated_path: &Path) -> Option { +pub(crate) fn resolve_cc_switch_catalog_path( + config_text: &str, + generated_path: &Path, +) -> Option { if config_text.trim().is_empty() { return None; } diff --git a/src-tauri/src/proxy/handlers.rs b/src-tauri/src/proxy/handlers.rs index 96076470d..93a51e65c 100644 --- a/src-tauri/src/proxy/handlers.rs +++ b/src-tauri/src/proxy/handlers.rs @@ -62,6 +62,41 @@ pub async fn get_status(State(state): State) -> Result Result, ProxyError> { + let generated_path = crate::codex_config::get_codex_model_catalog_path(); + let active_catalog_path = match crate::codex_config::read_codex_config_text() { + Ok(config_text) => { + crate::codex_config::resolve_cc_switch_catalog_path(&config_text, &generated_path) + } + Err(_) => None, + }; + + let catalog = if let Some(catalog_path) = + active_catalog_path.as_ref().filter(|path| path.exists()) + { + let text = std::fs::read_to_string(catalog_path).unwrap_or_default(); + serde_json::from_str(&text).unwrap_or(json!({"models": []})) + } else { + if active_catalog_path.is_none() { + log::debug!( + "[models] stale guard: catalog not served (model_catalog_json not set to cc-switch catalog)" + ); + } + json!({"models": []}) + }; + Ok(Json(catalog)) +} + // ============================================================================ // Claude API 处理器(包含格式转换逻辑) // ============================================================================ diff --git a/src-tauri/src/proxy/server.rs b/src-tauri/src/proxy/server.rs index b4c551e35..e7b6f601b 100644 --- a/src-tauri/src/proxy/server.rs +++ b/src-tauri/src/proxy/server.rs @@ -315,6 +315,9 @@ impl ProxyServer { "/codex/v1/chat/completions", post(handlers::handle_chat_completions), ) + // OpenAI Models API (Codex CLI reachability check) + .route("/models", get(handlers::handle_models)) + .route("/v1/models", get(handlers::handle_models)) // OpenAI Responses API (Codex CLI,支持带前缀和不带前缀) .route("/responses", post(handlers::handle_responses)) .route("/v1/responses", post(handlers::handle_responses))