diff --git a/src-tauri-cli/src/run.rs b/src-tauri-cli/src/run.rs index 27af093d..5cc28e17 100644 --- a/src-tauri-cli/src/run.rs +++ b/src-tauri-cli/src/run.rs @@ -303,13 +303,28 @@ fn format_reqwest_error(e: &reqwest::Error, url: &str) -> String { } async fn request_status(client: &Client, base_url: &str) -> Result { - let url = format!("{base_url}/health"); - let resp = client.get(&url).send().await.map_err(|e| anyhow!(format_reqwest_error(&e, &url)))?; - if !resp.status().is_success() { - return Err(anyhow!("服务端返回 HTTP {}", resp.status())); + // The HTTP server does not expose a JSON /health route (it serves the SPA there), so probe the + // first endpoint that answers with JSON. + let mut last_error: Option = None; + for path in ["/health", "/v1/observability/summary"] { + let url = format!("{base_url}{path}"); + let resp = match client.get(&url).send().await { + Ok(resp) => resp, + Err(e) => { + last_error = Some(format_reqwest_error(&e, &url)); + continue; + } + }; + if !resp.status().is_success() { + last_error = Some(format!("服务端返回 HTTP {}", resp.status())); + continue; + } + match resp.json::().await { + Ok(body) => return Ok(body), + Err(e) => last_error = Some(format_reqwest_error(&e, &url)), + } } - let body: Value = resp.json().await.map_err(|e| anyhow!(format_reqwest_error(&e, &url)))?; - Ok(body) + Err(anyhow!(last_error.unwrap_or_else(|| format!("无法获取服务端状态: {base_url}")))) } async fn request_command(client: &Client, base_url: &str, command: &str, payload: Value) -> Result { @@ -487,7 +502,10 @@ pub async fn run() -> Result<()> { } }, Some(Commands::Search { query }) => { - let data = request_command(&client, &base_url, "search_sessions_fts", json!({ "query": query })).await?; + // The legacy session-level FTS table (`sessions_fts`) is no longer created: message-level + // FTS is the primary index, so `search_sessions_fts` always fails with + // "no such table: sessions_fts". Query the current index instead. + let data = request_command(&client, &base_url, "full_text_search", json!({ "query": query, "role_filter": "all", "page": 0, "page_size": 20 })).await?; println!("{}", serde_json::to_string_pretty(&data)?.green()); } None => {