From 3ad7d0b1cc9ca46163bbcf85d0b0316027a40421 Mon Sep 17 00:00:00 2001 From: nmsn <136696700@qq.com> Date: Thu, 23 Apr 2026 10:38:08 +0800 Subject: [PATCH] fix: use TOML parser instead of regex for Codex model extraction (#2222) (#2227) * fix(codex): use TOML parser instead of regex for model extraction Regex only matched model=... on first line, TOML parser handles multiline TOML correctly. Fixes #2222 * fix(stream_check): drop unused regex::Regex import The previous commit replaced the only Regex usage in stream_check.rs with toml::Table parsing, leaving `use regex::Regex;` orphaned. Without this removal, `cargo clippy -- -D warnings` (run in CI) fails with `unused import: regex::Regex`. --------- Co-authored-by: Jason --- src-tauri/src/services/stream_check.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/services/stream_check.rs b/src-tauri/src/services/stream_check.rs index 3fd7d97cf..b8ce157e1 100644 --- a/src-tauri/src/services/stream_check.rs +++ b/src-tauri/src/services/stream_check.rs @@ -3,7 +3,6 @@ //! 使用流式 API 进行快速健康检查,只需接收首个 chunk 即判定成功。 use futures::StreamExt; -use regex::Regex; use reqwest::Client; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -1412,10 +1411,11 @@ impl StreamCheckService { return None; } - let re = Regex::new(r#"^model\s*=\s*["']([^"']+)["']"#).ok()?; - re.captures(config_text) - .and_then(|caps| caps.get(1)) - .map(|m| m.as_str().trim().to_string()) + let table = toml::from_str::(config_text).ok()?; + table + .get("model") + .and_then(|v| v.as_str()) + .map(|s| s.trim().to_string()) .filter(|value| !value.is_empty()) }