Skip to content

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

fix(codex): read GitHub Copilot reasoning_text from Chat responses

Jason4fb5408580d5
diff --git a/src-tauri/src/proxy/handlers.rs b/src-tauri/src/proxy/handlers.rs
index 9311ee093..53b725177 100644
--- a/src-tauri/src/proxy/handlers.rs
+++ b/src-tauri/src/proxy/handlers.rs
@@ -3499,7 +3499,7 @@ pub(crate) fn chat_sse_to_response_value(body: &str) -> Result<Value, ProxyError
content.push_str(refusal);
}
// reasoning 字段穷举提取直接复用 codex_chat_common(reasoning_content >
- // reasoning 字符串/对象 > reasoning_details),避免第三份手写实现漏档:
+ // reasoning 字符串/对象 > reasoning_text > reasoning_details),避免第三份手写实现漏档:
// MiMo/OpenRouter 等只发 reasoning_details 的 provider 否则会丢思考内容
if let Some(text) = extract_reasoning_field_text(payload) {
reasoning_content.push_str(&text);
diff --git a/src-tauri/src/proxy/providers/codex_chat_common.rs b/src-tauri/src/proxy/providers/codex_chat_common.rs
index ab84326c1..abb20153a 100644
--- a/src-tauri/src/proxy/providers/codex_chat_common.rs
+++ b/src-tauri/src/proxy/providers/codex_chat_common.rs
@@ -1,6 +1,7 @@
use serde_json::{json, Map, Value};
-// 穷举上游可能的 reasoning 回传字段,优先级:reasoning_content > reasoning(字符串/对象) > reasoning_details。
+// 穷举上游可能的 reasoning 回传字段,优先级:reasoning_content > reasoning(字符串/对象) > reasoning_text > reasoning_details。
+// reasoning_text 是 GitHub Copilot `/chat/completions` 的思考字段(#10242)。
// 不依赖 provider meta 的 outputFormat 声明,因此对各家 Chat 兼容接口都能兜底提取。
pub(crate) fn extract_reasoning_field_text(value: &Value) -> Option<String> {
for key in ["reasoning_content", "reasoning"] {
@@ -21,6 +22,12 @@ pub(crate) fn extract_reasoning_field_text(value: &Value) -> Option<String> {
}
}
+ if let Some(text) = value.get("reasoning_text").and_then(|v| v.as_str()) {
+ if !text.is_empty() {
+ return Some(text.to_string());
+ }
+ }
+
if let Some(details) = value.get("reasoning_details") {
if let Some(text) = extract_reasoning_details_text(details) {
return Some(text);
diff --git a/src-tauri/src/proxy/providers/streaming_codex_chat.rs b/src-tauri/src/proxy/providers/streaming_codex_chat.rs
index 4051df8b7..30721c8ec 100644
--- a/src-tauri/src/proxy/providers/streaming_codex_chat.rs
+++ b/src-tauri/src/proxy/providers/streaming_codex_chat.rs
@@ -1014,6 +1014,25 @@ mod tests {
assert!(reasoning_pos < message_pos);
}
+ #[tokio::test]
+ async fn converts_copilot_reasoning_text_chat_sse_to_responses_reasoning_events() {
+ // #10242:GitHub Copilot 的思考流在 delta.reasoning_text,签名另走 reasoning_opaque。
+ let output = collect(vec![
+ "data: {\"id\":\"chatcmpl_copilot\",\"model\":\"gemini-4-neon\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"reasoning_text\":\"Check the config. \"}}]}\n\n",
+ "data: {\"id\":\"chatcmpl_copilot\",\"model\":\"gemini-4-neon\",\"choices\":[{\"delta\":{\"reasoning_opaque\":\"opaque-signature\"}}]}\n\n",
+ "data: {\"id\":\"chatcmpl_copilot\",\"model\":\"gemini-4-neon\",\"choices\":[{\"delta\":{\"content\":\"Done\"},\"finish_reason\":\"stop\"}]}\n\n",
+ "data: [DONE]\n\n",
+ ])
+ .await;
+
+ assert!(output.contains("event: response.reasoning_summary_text.delta"));
+ assert!(output.contains("Check the config. "));
+ assert!(!output.contains("opaque-signature"));
+ let reasoning_pos = output.find("\"type\":\"reasoning\"").unwrap();
+ let message_pos = output.find("\"type\":\"message\"").unwrap();
+ assert!(reasoning_pos < message_pos);
+ }
+
#[tokio::test]
async fn reasoning_item_id_is_never_a_bare_hex_official_lookup_shape() {
// #9054:有的上游回复 id 是 32 位十六进制,旧格式 `rs_resp_<32hex>` 在直连切回
diff --git a/src-tauri/src/proxy/providers/transform_codex_chat/tests.rs b/src-tauri/src/proxy/providers/transform_codex_chat/tests.rs
index 7cc263245..9854ca764 100644
--- a/src-tauri/src/proxy/providers/transform_codex_chat/tests.rs
+++ b/src-tauri/src/proxy/providers/transform_codex_chat/tests.rs
@@ -1880,6 +1880,34 @@ fn chat_response_to_responses_extracts_reasoning_details() {
assert_eq!(result["output"][1]["content"][0]["text"], "Done");
}
+#[test]
+fn chat_response_to_responses_extracts_copilot_reasoning_text() {
+ // #10242:GitHub Copilot `/chat/completions` 把思考放在 message.reasoning_text。
+ let input = json!({
+ "id": "chatcmpl_copilot",
+ "model": "gemini-4-neon",
+ "choices": [{
+ "message": {
+ "role": "assistant",
+ "reasoning_text": "Check the config first.",
+ "reasoning_opaque": "opaque-signature",
+ "content": "Done"
+ },
+ "finish_reason": "stop"
+ }]
+ });
+
+ let result =
+ chat_completion_to_response_with_context(input, &CodexToolContext::default()).unwrap();
+
+ assert_eq!(result["output"][0]["type"], "reasoning");
+ assert_eq!(
+ result["output"][0]["summary"][0]["text"],
+ "Check the config first."
+ );
+ assert_eq!(result["output"][1]["content"][0]["text"], "Done");
+}
+
#[test]
fn chat_completion_reasoning_item_id_avoids_official_lookup_shape() {
// #9054:`rs_resp_<32 位十六进制>` 会被官方 store:false 下按 id 回查 404,带序号就不会。