mod aliases;
mod budget;
mod filters;
mod gate;
mod ordering;
mod projection;
mod stream;
mod surface_state;
mod target;
mod truncation;
mod vocabulary;
use super::filter::{FilterExpr, FilterOp};
use super::*;
use serde_json::json;
fn envelope() -> Value {
json!({
"query": "rust",
"elapsed_ms": 12,
"results": [
{ "name": "alpha", "score": 0.9, "type": "note", "snippet": "abcdefghij" },
{ "name": "beta", "score": 0.5, "type": "note", "snippet": "klmnopqrst" },
{ "name": "gamma", "score": 0.7, "type": "decision", "snippet": "uvwxyz" },
{ "name": "beta", "score": 0.1, "type": "note", "snippet": "duplicate" }
]
})
}
fn surface() -> AgentSurface {
AgentSurface::default()
}
fn apply(surface: &AgentSurface, value: Value) -> Value {
super::apply_with_target(surface, value, None)
.expect("this surface must not refuse this envelope")
}
fn try_apply(surface: &AgentSurface, value: Value) -> Result<Value, crate::errors::AppError> {
super::apply_with_target(surface, value, None)
}
fn pagination(applied: usize, total: usize) -> universe::QueryCeiling {
universe::QueryCeiling {
applied,
offset: 0,
source: universe::CeilingSource::Default,
kind: universe::CeilingKind::Pagination,
universe_total: Some(total),
}
}
fn top_k(applied: usize) -> universe::QueryCeiling {
universe::QueryCeiling {
applied,
offset: 0,
source: universe::CeilingSource::Flag,
kind: universe::CeilingKind::TopK,
universe_total: None,
}
}
fn try_apply_under(
surface: &AgentSurface,
value: Value,
ceiling: Option<&universe::QueryCeiling>,
) -> Result<Value, crate::errors::AppError> {
super::apply_with_premises(surface, value, None, ceiling)
}
fn surface_for(command: &str) -> AgentSurface {
AgentSurface {
command: Some(command.to_string()),
..AgentSurface::default()
}
}
fn results(value: &Value) -> &Vec<Value> {
value
.get("results")
.and_then(Value::as_array)
.unwrap_or_else(|| panic!("envelope must keep its results array: {value}"))
}
fn list_envelope() -> Value {
let items = json!([
{ "name": "alpha", "memory_type": "skill" },
{ "name": "beta", "memory_type": "note" },
{ "name": "gamma", "memory_type": "skill" }
]);
json!({ "total_count": 3, "items": items, "memories": items, "elapsed_ms": 1 })
}
impl AgentSurface {
fn clone_with_sort(&self, key: &str) -> Self {
let mut next = self.clone();
next.sort = Some(key.to_string());
next
}
}