agentswap 0.1.0

AgentSwap CLI — AI-agent-optimized DEX aggregator
// Debug and investigation endpoints for the AgentSwap client.
// Exports: Client::benchmark.
// Deps: super::Client, reqwest, eyre.

use super::Client;
use eyre::{eyre, Result};

#[allow(dead_code)]
impl Client {
    pub async fn benchmark(&self, routing_mode: Option<&str>) -> Result<serde_json::Value> {
        let mut url = format!("{}{}", self.base_url, crate::routes::BENCHMARK_LATEST);
        if let Some(mode) = routing_mode {
            url.push_str(&format!("?routing_mode={mode}"));
        }
        let timeout = if routing_mode.is_some() {
            std::time::Duration::from_secs(300)
        } else {
            std::time::Duration::from_secs(30)
        };
        let mut req = self.http.get(&url).timeout(timeout);
        if let Some(key) = &self.api_key {
            req = req.header("x-api-key", key);
        }
        let resp = req.send().await.map_err(|e| eyre!("request failed: {e}"))?;
        let status = resp.status();
        if status == reqwest::StatusCode::NO_CONTENT {
            return Err(eyre!("benchmark not yet completed — wait for startup sync"));
        }
        if !status.is_success() {
            let body = resp.text().await.unwrap_or_default();
            return Err(eyre!("HTTP {status}: {body}"));
        }
        resp.json().await.map_err(|e| eyre!("parse failed: {e}"))
    }
}