diff --git a/src/api/completions.rs b/src/api/completions.rs index 9ce14e9..9983499 100644 --- a/src/api/completions.rs +++ b/src/api/completions.rs @@ -233,7 +233,7 @@ async fn chat_completions_stream( "finish_reason": "stop", }], })).unwrap_or_default())); - yield Ok(Event::default().data("[DONE]".to_string())); + yield Ok(Event::default().data("[DONE]")); return; } @@ -257,7 +257,7 @@ async fn chat_completions_stream( "finish_reason": "stop", }], })).unwrap_or_default())); - yield Ok(Event::default().data("[DONE]".to_string())); + yield Ok(Event::default().data("[DONE]")); return; } } @@ -284,7 +284,7 @@ async fn chat_completions_stream( "finish_reason": "stop", }], })).unwrap_or_default())); - yield Ok(Event::default().data("[DONE]".to_string())); + yield Ok(Event::default().data("[DONE]")); }; Sse::new(stream) diff --git a/src/api/polling.rs b/src/api/polling.rs index 6e6c45e..8910357 100644 --- a/src/api/polling.rs +++ b/src/api/polling.rs @@ -237,14 +237,14 @@ pub(crate) async fn poll_for_response( info!( "Response done ({short_id}), {:.1}s, {} chars, tokens: {}in/{}out ({}){}{}", elapsed, text.len(), u.input_tokens, u.output_tokens, u.model, - if thinking.is_some() { format!(", thinking: {} chars", thinking.as_ref().unwrap().len()) } else { String::new() }, + thinking.as_ref().map_or(String::new(), |t| format!(", thinking: {} chars", t.len())), if thinking_signature.is_some() { ", has sig" } else { "" } ); } else { info!( "Response done ({short_id}), {:.1}s, {} chars (no usage){}{}", elapsed, text.len(), - if thinking.is_some() { format!(", thinking: {} chars", thinking.as_ref().unwrap().len()) } else { String::new() }, + thinking.as_ref().map_or(String::new(), |t| format!(", thinking: {} chars", t.len())), if thinking_signature.is_some() { ", has sig" } else { "" } ); } diff --git a/src/api/responses.rs b/src/api/responses.rs index 5da0421..a8073c8 100644 --- a/src/api/responses.rs +++ b/src/api/responses.rs @@ -206,7 +206,7 @@ pub(crate) async fn handle_responses( .send_message(&cascade_id, &user_text, model.model_enum) .await { - Ok((status, _)) if status == 200 => { + Ok((200, _)) => { let bg = Arc::clone(&state.backend); let cid = cascade_id.clone(); tokio::spawn(async move { diff --git a/src/api/types.rs b/src/api/types.rs index b076484..328d670 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -141,6 +141,7 @@ pub(crate) struct OutputTokensDetails { } #[derive(Serialize, Clone)] +#[derive(Default)] pub(crate) struct Reasoning { pub effort: Option, pub summary: Option, @@ -161,8 +162,8 @@ impl Usage { /// Estimate token counts from actual text. /// Uses ~4 chars/token heuristic (standard GPT tokenizer average). pub fn estimate(input_text: &str, output_text: &str) -> Self { - let input_tokens = (input_text.len() as u64 + 3) / 4; - let output_tokens = (output_text.len() as u64 + 3) / 4; + let input_tokens = (input_text.len() as u64).div_ceil(4); + let output_tokens = (output_text.len() as u64).div_ceil(4); Self { input_tokens, input_tokens_details: InputTokensDetails { cached_tokens: 0 }, @@ -189,14 +190,6 @@ impl Default for Usage { } } -impl Default for Reasoning { - fn default() -> Self { - Self { - effort: None, - summary: None, - } - } -} impl Default for TextFormat { fn default() -> Self { diff --git a/src/mitm/proto.rs b/src/mitm/proto.rs index a3ed81c..2bff9ad 100644 --- a/src/mitm/proto.rs +++ b/src/mitm/proto.rs @@ -227,10 +227,7 @@ fn looks_like_valid_message(fields: &[ProtoField], original_len: usize) -> bool // (e.g., a long string that happened to have a valid first-field prefix) if fields.len() == 1 && original_len > 100 { // Single-field messages of >100 bytes are suspicious unless the field is bytes/message - match &fields[0].value { - ProtoValue::Bytes(_) | ProtoValue::Message(_) => true, - _ => false, - } + matches!(&fields[0].value, ProtoValue::Bytes(_) | ProtoValue::Message(_)) } else { true } diff --git a/src/mitm/proxy.rs b/src/mitm/proxy.rs index 3de41d0..464194a 100644 --- a/src/mitm/proxy.rs +++ b/src/mitm/proxy.rs @@ -46,6 +46,7 @@ const PASSTHROUGH_DOMAINS: &[&str] = &[ ]; /// Configuration for the MITM proxy. +#[derive(Default)] pub struct MitmConfig { /// Port to listen on (0 = auto-assign). pub port: u16, @@ -53,14 +54,6 @@ pub struct MitmConfig { pub modify_requests: bool, } -impl Default for MitmConfig { - fn default() -> Self { - Self { - port: 0, - modify_requests: false, - } - } -} /// Run the MITM proxy server. /// @@ -405,7 +398,7 @@ async fn handle_http_over_tls( async fn resolve_upstream(domain: &str) -> String { // 1. Try dig @8.8.8.8 (bypasses /etc/hosts) if let Ok(output) = tokio::process::Command::new("dig") - .args(["+short", &format!("@8.8.8.8"), domain]) + .args(["+short", "@8.8.8.8", domain]) .output() .await { diff --git a/src/snapshot.rs b/src/snapshot.rs index 7008734..857f7ac 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -102,12 +102,11 @@ impl Snapshot { } // LS process logs - if line.starts_with('I') || line.starts_with('W') || line.starts_with('E') { - if line.len() > 4 && line.chars().nth(1).map_or(false, |c| c.is_ascii_digit()) { + if (line.starts_with('I') || line.starts_with('W') || line.starts_with('E')) + && line.len() > 4 && line.chars().nth(1).is_some_and(|c| c.is_ascii_digit()) { snap.ls_logs.push(line.to_string()); continue; } - } if line.contains("maxprocs:") { snap.ls_logs.push(line.to_string()); continue;