use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryResponse {
pub queries: Vec<QueryCommand>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgenticQueryResponse {
pub queries: Vec<QueryCommand>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub results: Vec<crate::models::FileGroupedResult>,
#[serde(skip_serializing_if = "Option::is_none")]
pub total_count: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub gathered_context: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tools_executed: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub answer: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryCommand {
pub command: String,
pub order: i32,
pub merge: bool,
}
pub const RESPONSE_SCHEMA: &str = r#"{
"type": "object",
"properties": {
"queries": {
"type": "array",
"description": "Array of rfx commands to execute. Most queries should have 1 command.",
"items": {
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "The rfx query command WITHOUT the 'rfx' prefix"
},
"order": {
"type": "integer",
"description": "Execution order (1-based, sequential)"
},
"merge": {
"type": "boolean",
"description": "Whether to include in final results (false = context-only)"
}
},
"required": ["command", "order", "merge"]
}
}
},
"required": ["queries"]
}"#;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_deserialize_single_query() {
let json = r#"{
"queries": [{
"command": "query \"TODO\"",
"order": 1,
"merge": true
}]
}"#;
let response: QueryResponse = serde_json::from_str(json).unwrap();
assert_eq!(response.queries.len(), 1);
assert_eq!(response.queries[0].command, "query \"TODO\"");
assert_eq!(response.queries[0].order, 1);
assert_eq!(response.queries[0].merge, true);
}
#[test]
fn test_deserialize_multiple_queries() {
let json = r#"{
"queries": [
{
"command": "query \"User\" --symbols --kind struct --lang rust",
"order": 1,
"merge": false
},
{
"command": "query \"User\" --lang rust",
"order": 2,
"merge": true
}
]
}"#;
let response: QueryResponse = serde_json::from_str(json).unwrap();
assert_eq!(response.queries.len(), 2);
assert_eq!(response.queries[0].order, 1);
assert_eq!(response.queries[0].merge, false);
assert_eq!(response.queries[1].order, 2);
assert_eq!(response.queries[1].merge, true);
}
}