chore: fix all clippy warnings and add Cargo.toml metadata

This commit is contained in:
Nikketryhard
2026-02-18 02:50:47 -06:00
parent ad0aa1556c
commit 22177a28a1
10 changed files with 39 additions and 40 deletions

View File

@@ -2,6 +2,10 @@
name = "zerogravity"
version = "1.0.0"
edition = "2021"
license = "MIT"
description = "OpenAI-compatible proxy for Google Antigravity"
repository = "https://github.com/NikkeTryHard/zerogravity"
authors = ["NikkeTryHard"]
[[bin]]
name = "zerogravity"

View File

@@ -401,7 +401,7 @@ pub(crate) async fn handle_completions(
);
}
let n = (body.n.max(1)).min(5); // Cap at 5 to prevent abuse
let n = body.n.clamp(1, 5); // Cap at 5 to prevent abuse
if n > 1 && body.stream {
warn!("n={n} requested with streaming — streaming only supports n=1, ignoring n");
}
@@ -594,31 +594,25 @@ pub(crate) async fn handle_completions(
// n > 1: fire additional (n-1) parallel cascades
let mut extra_cascade_ids = Vec::with_capacity((n - 1) as usize);
for _ in 1..n {
match state.backend.create_cascade().await {
Ok(cid) => {
// Send the same message on each extra cascade
match state
.backend
.send_message_with_image(
&cid,
&format!(".<cid:{}>", cid),
model.model_enum,
image.as_ref(),
)
.await
{
Ok((200, _)) => {
let bg = Arc::clone(&state.backend);
let cid2 = cid.clone();
tokio::spawn(async move {
let _ = bg.update_annotations(&cid2).await;
});
extra_cascade_ids.push(cid);
}
_ => {} // Skip failed cascades
}
if let Ok(cid) = state.backend.create_cascade().await {
// Send the same message on each extra cascade
if let Ok((200, _)) = state
.backend
.send_message_with_image(
&cid,
&format!(".<cid:{}>", cid),
model.model_enum,
image.as_ref(),
)
.await
{
let bg = Arc::clone(&state.backend);
let cid2 = cid.clone();
tokio::spawn(async move {
let _ = bg.update_annotations(&cid2).await;
});
extra_cascade_ids.push(cid);
}
Err(_) => {} // Skip failed cascade creation
}
}
@@ -714,6 +708,7 @@ pub(crate) async fn handle_completions(
// ─── Streaming ───────────────────────────────────────────────────────────────
/// Streaming output in Chat Completions format.
#[allow(clippy::too_many_arguments)]
async fn chat_completions_stream(
state: Arc<AppState>,
completion_id: String,

View File

@@ -639,6 +639,7 @@ async fn usage_from_poll(
// ─── Sync response ───────────────────────────────────────────────────────────
#[allow(clippy::too_many_arguments)]
async fn handle_responses_sync(
state: Arc<AppState>,
response_id: String,
@@ -1034,6 +1035,7 @@ async fn handle_responses_sync(
// ─── Streaming response ─────────────────────────────────────────────────────
#[allow(clippy::too_many_arguments)]
async fn handle_responses_stream(
state: Arc<AppState>,
response_id: String,

View File

@@ -158,7 +158,7 @@ pub(crate) fn parse_data_uri(url: &str) -> Option<ImageData> {
/// Supports:
/// - Chat Completions: `{"type": "image_url", "image_url": {"url": "data:..."}}`
/// - Responses API: `{"type": "input_image", "image_url": "data:..."}` or
/// `{"type": "input_image", "url": "data:..."}`
/// `{"type": "input_image", "url": "data:..."}`
pub(crate) fn extract_image_from_content(item: &serde_json::Value) -> Option<ImageData> {
let item_type = item["type"].as_str().unwrap_or("");

View File

@@ -38,12 +38,7 @@ pub fn parse_streaming_chunk(chunk: &str, accumulator: &mut StreamingAccumulator
// Extract and process all complete lines (terminated by \n).
// Leave any trailing partial line in the buffer for the next read.
loop {
let pos = match accumulator.pending_data.find('\n') {
Some(p) => p,
None => break,
};
while let Some(pos) = accumulator.pending_data.find('\n') {
let line = accumulator.pending_data[..pos]
.trim_end_matches('\r')
.to_string();

View File

@@ -1431,7 +1431,7 @@ mod tests {
fn rewrite_function_calls_in_response(json: &mut Value) -> bool {
let mut changed = false;
fn rewrite_candidates(candidates: &mut Vec<Value>) -> bool {
fn rewrite_candidates(candidates: &mut [Value]) -> bool {
let mut changed = false;
for candidate in candidates.iter_mut() {
if let Some(parts) = candidate
@@ -1504,12 +1504,7 @@ impl ResponseRewriter {
let mut output = String::new();
// Extract all complete lines (terminated by \n)
loop {
let pos = match self.pending.find('\n') {
Some(p) => p,
None => break,
};
while let Some(pos) = self.pending.find('\n') {
// Include the \n in the extracted line
let line = self.pending[..=pos].to_string();
self.pending = self.pending[pos + 1..].to_string();

View File

@@ -962,7 +962,7 @@ async fn resolve_upstream(domain: &str) -> String {
}
// 2. Try cached IPs file
if let Ok(contents) = tokio::fs::read_to_string("/tmp/antigravity-mitm-real-ips").await {
if let Ok(contents) = tokio::fs::read_to_string("/tmp/zerogravity-real-ips").await {
for line in contents.lines() {
if let Some((d, ip)) = line.split_once('=') {
if d == domain {

View File

@@ -215,8 +215,10 @@ pub struct RequestContext {
/// API handlers wait on this with a timeout to detect match failures.
pub gate: Arc<tokio::sync::Notify>,
/// Debug trace handle (if tracing is enabled).
#[allow(dead_code)]
pub trace_handle: Option<crate::trace::TraceHandle>,
/// Current turn index in the trace (for multi-turn tracking).
#[allow(dead_code)]
pub trace_turn: usize,
}

View File

@@ -257,6 +257,7 @@ fn default_os_name() -> &'static str {
// ── Platform queries ──
#[allow(dead_code)]
/// Returns true if running on Linux.
pub fn is_linux() -> bool {
cfg!(target_os = "linux")

View File

@@ -28,6 +28,7 @@ impl TraceCollector {
}
/// Whether tracing is enabled.
#[allow(dead_code)]
pub fn enabled(&self) -> bool {
self.enabled
}
@@ -141,6 +142,7 @@ impl TraceHandle {
}
/// Record MITM modify summary for a turn.
#[allow(dead_code)]
pub async fn record_modify(&self, turn: usize, summary: String, original: u64, modified: u64) {
let mut data = self.inner.lock().await;
if let Some(t) = data.turns.get_mut(turn) {
@@ -150,6 +152,7 @@ impl TraceHandle {
}
/// Record upstream wait time.
#[allow(dead_code)]
pub async fn record_upstream_wait(&self, turn: usize, wait_ms: u64) {
let mut data = self.inner.lock().await;
if let Some(t) = data.turns.get_mut(turn) {
@@ -166,6 +169,7 @@ impl TraceHandle {
}
/// Record an event sent via channel.
#[allow(dead_code)]
pub async fn record_event(&self, turn: usize, event_name: &str) {
let mut data = self.inner.lock().await;
if let Some(t) = data.turns.get_mut(turn) {
@@ -174,6 +178,7 @@ impl TraceHandle {
}
/// Record the handler action for a turn.
#[allow(dead_code)]
pub async fn record_action(&self, turn: usize, action: &str) {
let mut data = self.inner.lock().await;
if let Some(t) = data.turns.get_mut(turn) {