Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src-tauri-cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,28 @@ fn format_reqwest_error(e: &reqwest::Error, url: &str) -> String {
}

async fn request_status(client: &Client, base_url: &str) -> Result<Value> {
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<String> = 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::<Value>().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<Value> {
Expand Down Expand Up @@ -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 => {
Expand Down
Loading