codetether_agent/search/result.rs
1//! Normalized result type produced by the router and consumed by the CLI.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use super::types::Backend;
7
8/// One successful or failed backend execution.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct BackendRun {
11 pub backend: Backend,
12 pub success: bool,
13 pub output: String,
14 #[serde(default)]
15 pub metadata: Value,
16}
17
18/// Full router result returned to CLI / tool callers.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct RouterResult {
21 pub query: String,
22 pub router_model: String,
23 pub runs: Vec<BackendRun>,
24}
25
26impl RouterResult {
27 /// Shortcut for tests and callers: how many backends succeeded.
28 ///
29 /// # Examples
30 ///
31 /// ```rust
32 /// use codetether_agent::search::result::{BackendRun, RouterResult};
33 /// use codetether_agent::search::types::Backend;
34 /// use serde_json::Value;
35 /// let r = RouterResult {
36 /// query: "q".into(),
37 /// router_model: "zai/glm-5.1".into(),
38 /// runs: vec![BackendRun { backend: Backend::Grep, success: true, output: "ok".into(), metadata: Value::Null }],
39 /// };
40 /// assert_eq!(r.success_count(), 1);
41 /// ```
42 pub fn success_count(&self) -> usize {
43 self.runs.iter().filter(|run| run.success).count()
44 }
45}