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(agy): keep the effort marker in the logged request model

Jason283c92a322a5
diff --git a/src-tauri/src/proxy/handlers.rs b/src-tauri/src/proxy/handlers.rs
index ad6d1a787..ed4d98c8a 100644
--- a/src-tauri/src/proxy/handlers.rs
+++ b/src-tauri/src/proxy/handlers.rs
@@ -2801,6 +2801,15 @@ pub async fn handle_agy(
Err(rejected) => return Ok(*rejected),
};
let mut body_changed = stack.is_some() && !path.starts_with("/v1beta/");
+ // 客户端选的模型(变体还带着 `@<档位>`),用量的 `request_model` 记它,看得出选了哪档
+ // (和会话导入一致)。genai 在路径里,openai 在请求体里。
+ let client_model = if path.starts_with("/v1beta/") {
+ crate::proxy::handler_context::extract_gemini_model_from_path(&path)
+ } else {
+ body.get("model")
+ .and_then(Value::as_str)
+ .map(str::to_string)
+ };
// 推理强度变体:去掉 `@<档位>`、覆盖强度。只有改过才重写 body 字节(重试按字节重放)。
if let Some((rewritten, level)) =
crate::proxy::providers::agy::rewrite_effort_variant(&path, &mut body)
@@ -2829,16 +2838,20 @@ pub async fn handle_agy(
)
.await?;
// genai 发往上游的模型(改写后的路径里,变体已去掉标记)。请求体里没有 `model`,转发器
- // 取不到出站模型,用量按它记;聚合请求的 `request_model` 留着客户端选的 `ccs-` id。
+ // 取不到出站模型,用量按它记;`request_model` 是客户端选的(聚合请求留着 `ccs-` id)。
let genai_upstream_model =
genai.then(|| crate::proxy::handler_context::extract_gemini_model_from_path(path));
- if genai {
- if !ctx.is_stack {
+ if !ctx.is_stack {
+ if let Some(model) = client_model {
+ ctx.request_model = model;
+ } else if genai {
ctx.request_model = genai_upstream_model
.clone()
.flatten()
.unwrap_or_else(|| "unknown".to_string());
}
+ }
+ if genai {
// 用量记成会话日志里的那一步,会话导入见到同 ID 就跳过(openai 请求没有会话标识,
// 成功的不记,见 `log_usage_internal`)
ctx.usage_request_id = crate::proxy::providers::agy::session_usage_id(path, &body);
@@ -2887,7 +2900,12 @@ pub async fn handle_agy(
if let Some(provider) = err.provider.take() {
ctx.provider = provider;
}
- ctx.outbound_model = err.outbound_model.take();
+ // genai 请求体没有 `model`,失败行也要记上游名,不然会落回带 `@<档位>` 的
+ // `request_model`,按模型统计多出一行
+ ctx.outbound_model = err
+ .outbound_model
+ .take()
+ .or_else(|| genai_upstream_model.clone().flatten());
log_forward_error(&state, &ctx, is_stream, &err.error).await;
return Err(err.error);
}