chore: fix all clippy warnings and add Cargo.toml metadata
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
name = "zerogravity"
|
name = "zerogravity"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
license = "MIT"
|
||||||
|
description = "OpenAI-compatible proxy for Google Antigravity"
|
||||||
|
repository = "https://github.com/NikkeTryHard/zerogravity"
|
||||||
|
authors = ["NikkeTryHard"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "zerogravity"
|
name = "zerogravity"
|
||||||
|
|||||||
@@ -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 {
|
if n > 1 && body.stream {
|
||||||
warn!("n={n} requested with streaming — streaming only supports n=1, ignoring n");
|
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
|
// n > 1: fire additional (n-1) parallel cascades
|
||||||
let mut extra_cascade_ids = Vec::with_capacity((n - 1) as usize);
|
let mut extra_cascade_ids = Vec::with_capacity((n - 1) as usize);
|
||||||
for _ in 1..n {
|
for _ in 1..n {
|
||||||
match state.backend.create_cascade().await {
|
if let Ok(cid) = state.backend.create_cascade().await {
|
||||||
Ok(cid) => {
|
// Send the same message on each extra cascade
|
||||||
// Send the same message on each extra cascade
|
if let Ok((200, _)) = state
|
||||||
match state
|
.backend
|
||||||
.backend
|
.send_message_with_image(
|
||||||
.send_message_with_image(
|
&cid,
|
||||||
&cid,
|
&format!(".<cid:{}>", cid),
|
||||||
&format!(".<cid:{}>", cid),
|
model.model_enum,
|
||||||
model.model_enum,
|
image.as_ref(),
|
||||||
image.as_ref(),
|
)
|
||||||
)
|
.await
|
||||||
.await
|
{
|
||||||
{
|
let bg = Arc::clone(&state.backend);
|
||||||
Ok((200, _)) => {
|
let cid2 = cid.clone();
|
||||||
let bg = Arc::clone(&state.backend);
|
tokio::spawn(async move {
|
||||||
let cid2 = cid.clone();
|
let _ = bg.update_annotations(&cid2).await;
|
||||||
tokio::spawn(async move {
|
});
|
||||||
let _ = bg.update_annotations(&cid2).await;
|
extra_cascade_ids.push(cid);
|
||||||
});
|
|
||||||
extra_cascade_ids.push(cid);
|
|
||||||
}
|
|
||||||
_ => {} // Skip failed cascades
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(_) => {} // Skip failed cascade creation
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -714,6 +708,7 @@ pub(crate) async fn handle_completions(
|
|||||||
// ─── Streaming ───────────────────────────────────────────────────────────────
|
// ─── Streaming ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Streaming output in Chat Completions format.
|
/// Streaming output in Chat Completions format.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn chat_completions_stream(
|
async fn chat_completions_stream(
|
||||||
state: Arc<AppState>,
|
state: Arc<AppState>,
|
||||||
completion_id: String,
|
completion_id: String,
|
||||||
|
|||||||
@@ -639,6 +639,7 @@ async fn usage_from_poll(
|
|||||||
|
|
||||||
// ─── Sync response ───────────────────────────────────────────────────────────
|
// ─── Sync response ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn handle_responses_sync(
|
async fn handle_responses_sync(
|
||||||
state: Arc<AppState>,
|
state: Arc<AppState>,
|
||||||
response_id: String,
|
response_id: String,
|
||||||
@@ -1034,6 +1035,7 @@ async fn handle_responses_sync(
|
|||||||
|
|
||||||
// ─── Streaming response ─────────────────────────────────────────────────────
|
// ─── Streaming response ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn handle_responses_stream(
|
async fn handle_responses_stream(
|
||||||
state: Arc<AppState>,
|
state: Arc<AppState>,
|
||||||
response_id: String,
|
response_id: String,
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ pub(crate) fn parse_data_uri(url: &str) -> Option<ImageData> {
|
|||||||
/// Supports:
|
/// Supports:
|
||||||
/// - Chat Completions: `{"type": "image_url", "image_url": {"url": "data:..."}}`
|
/// - Chat Completions: `{"type": "image_url", "image_url": {"url": "data:..."}}`
|
||||||
/// - Responses API: `{"type": "input_image", "image_url": "data:..."}` or
|
/// - 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> {
|
pub(crate) fn extract_image_from_content(item: &serde_json::Value) -> Option<ImageData> {
|
||||||
let item_type = item["type"].as_str().unwrap_or("");
|
let item_type = item["type"].as_str().unwrap_or("");
|
||||||
|
|
||||||
|
|||||||
@@ -38,12 +38,7 @@ pub fn parse_streaming_chunk(chunk: &str, accumulator: &mut StreamingAccumulator
|
|||||||
|
|
||||||
// Extract and process all complete lines (terminated by \n).
|
// Extract and process all complete lines (terminated by \n).
|
||||||
// Leave any trailing partial line in the buffer for the next read.
|
// Leave any trailing partial line in the buffer for the next read.
|
||||||
loop {
|
while let Some(pos) = accumulator.pending_data.find('\n') {
|
||||||
let pos = match accumulator.pending_data.find('\n') {
|
|
||||||
Some(p) => p,
|
|
||||||
None => break,
|
|
||||||
};
|
|
||||||
|
|
||||||
let line = accumulator.pending_data[..pos]
|
let line = accumulator.pending_data[..pos]
|
||||||
.trim_end_matches('\r')
|
.trim_end_matches('\r')
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|||||||
@@ -1431,7 +1431,7 @@ mod tests {
|
|||||||
fn rewrite_function_calls_in_response(json: &mut Value) -> bool {
|
fn rewrite_function_calls_in_response(json: &mut Value) -> bool {
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
|
|
||||||
fn rewrite_candidates(candidates: &mut Vec<Value>) -> bool {
|
fn rewrite_candidates(candidates: &mut [Value]) -> bool {
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
for candidate in candidates.iter_mut() {
|
for candidate in candidates.iter_mut() {
|
||||||
if let Some(parts) = candidate
|
if let Some(parts) = candidate
|
||||||
@@ -1504,12 +1504,7 @@ impl ResponseRewriter {
|
|||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
// Extract all complete lines (terminated by \n)
|
// Extract all complete lines (terminated by \n)
|
||||||
loop {
|
while let Some(pos) = self.pending.find('\n') {
|
||||||
let pos = match self.pending.find('\n') {
|
|
||||||
Some(p) => p,
|
|
||||||
None => break,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Include the \n in the extracted line
|
// Include the \n in the extracted line
|
||||||
let line = self.pending[..=pos].to_string();
|
let line = self.pending[..=pos].to_string();
|
||||||
self.pending = self.pending[pos + 1..].to_string();
|
self.pending = self.pending[pos + 1..].to_string();
|
||||||
|
|||||||
@@ -962,7 +962,7 @@ async fn resolve_upstream(domain: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Try cached IPs file
|
// 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() {
|
for line in contents.lines() {
|
||||||
if let Some((d, ip)) = line.split_once('=') {
|
if let Some((d, ip)) = line.split_once('=') {
|
||||||
if d == domain {
|
if d == domain {
|
||||||
|
|||||||
@@ -215,8 +215,10 @@ pub struct RequestContext {
|
|||||||
/// API handlers wait on this with a timeout to detect match failures.
|
/// API handlers wait on this with a timeout to detect match failures.
|
||||||
pub gate: Arc<tokio::sync::Notify>,
|
pub gate: Arc<tokio::sync::Notify>,
|
||||||
/// Debug trace handle (if tracing is enabled).
|
/// Debug trace handle (if tracing is enabled).
|
||||||
|
#[allow(dead_code)]
|
||||||
pub trace_handle: Option<crate::trace::TraceHandle>,
|
pub trace_handle: Option<crate::trace::TraceHandle>,
|
||||||
/// Current turn index in the trace (for multi-turn tracking).
|
/// Current turn index in the trace (for multi-turn tracking).
|
||||||
|
#[allow(dead_code)]
|
||||||
pub trace_turn: usize,
|
pub trace_turn: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ fn default_os_name() -> &'static str {
|
|||||||
|
|
||||||
// ── Platform queries ──
|
// ── Platform queries ──
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
/// Returns true if running on Linux.
|
/// Returns true if running on Linux.
|
||||||
pub fn is_linux() -> bool {
|
pub fn is_linux() -> bool {
|
||||||
cfg!(target_os = "linux")
|
cfg!(target_os = "linux")
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ impl TraceCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Whether tracing is enabled.
|
/// Whether tracing is enabled.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn enabled(&self) -> bool {
|
pub fn enabled(&self) -> bool {
|
||||||
self.enabled
|
self.enabled
|
||||||
}
|
}
|
||||||
@@ -141,6 +142,7 @@ impl TraceHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Record MITM modify summary for a turn.
|
/// Record MITM modify summary for a turn.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn record_modify(&self, turn: usize, summary: String, original: u64, modified: u64) {
|
pub async fn record_modify(&self, turn: usize, summary: String, original: u64, modified: u64) {
|
||||||
let mut data = self.inner.lock().await;
|
let mut data = self.inner.lock().await;
|
||||||
if let Some(t) = data.turns.get_mut(turn) {
|
if let Some(t) = data.turns.get_mut(turn) {
|
||||||
@@ -150,6 +152,7 @@ impl TraceHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Record upstream wait time.
|
/// Record upstream wait time.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn record_upstream_wait(&self, turn: usize, wait_ms: u64) {
|
pub async fn record_upstream_wait(&self, turn: usize, wait_ms: u64) {
|
||||||
let mut data = self.inner.lock().await;
|
let mut data = self.inner.lock().await;
|
||||||
if let Some(t) = data.turns.get_mut(turn) {
|
if let Some(t) = data.turns.get_mut(turn) {
|
||||||
@@ -166,6 +169,7 @@ impl TraceHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Record an event sent via channel.
|
/// Record an event sent via channel.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn record_event(&self, turn: usize, event_name: &str) {
|
pub async fn record_event(&self, turn: usize, event_name: &str) {
|
||||||
let mut data = self.inner.lock().await;
|
let mut data = self.inner.lock().await;
|
||||||
if let Some(t) = data.turns.get_mut(turn) {
|
if let Some(t) = data.turns.get_mut(turn) {
|
||||||
@@ -174,6 +178,7 @@ impl TraceHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Record the handler action for a turn.
|
/// Record the handler action for a turn.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn record_action(&self, turn: usize, action: &str) {
|
pub async fn record_action(&self, turn: usize, action: &str) {
|
||||||
let mut data = self.inner.lock().await;
|
let mut data = self.inner.lock().await;
|
||||||
if let Some(t) = data.turns.get_mut(turn) {
|
if let Some(t) = data.turns.get_mut(turn) {
|
||||||
|
|||||||
Reference in New Issue
Block a user