use crate::middleware::RequestNamespace;
use crate::state::AppState;
use axum::{
extract::{Path, State},
response::IntoResponse,
Json,
};
use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "mcp", derive(schemars::JsonSchema))]
#[derive(Deserialize, Debug)]
pub struct AgentConsistencyRequest {
pub agent_id: String,
}
#[derive(Serialize, Debug)]
pub struct ConsistencyResponse {
pub score: f64,
pub total: usize,
pub verified: usize,
}
#[cfg_attr(feature = "mcp", derive(schemars::JsonSchema))]
#[derive(Deserialize, Debug)]
pub struct BatchVerifyAssertionsRequest {
pub assertions: Vec<AssertionRef>,
}
#[cfg_attr(feature = "mcp", derive(schemars::JsonSchema))]
#[derive(Deserialize, Debug)]
pub struct AssertionRef {
pub subject: String,
pub predicate: String,
}
#[derive(Serialize, Debug)]
pub struct AssertionVerifyResult {
pub subject: String,
pub predicate: String,
pub verified: bool,
}
#[derive(Serialize, Debug)]
pub struct BatchVerifyAssertionsResponse {
pub results: Vec<AssertionVerifyResult>,
}
pub async fn get_agent_consistency(
State(state): State<AppState>,
ns_ext: Option<axum::Extension<RequestNamespace>>,
Path(agent_id): Path<String>,
) -> impl IntoResponse {
let namespace = ns_ext.and_then(|axum::Extension(RequestNamespace(ns))| ns);
let resp = crate::service::reputation::agent_consistency(&state, &agent_id, namespace).await;
Json(resp)
}
pub async fn batch_verify_assertions(
State(state): State<AppState>,
ns_ext: Option<axum::Extension<RequestNamespace>>,
Json(req): Json<BatchVerifyAssertionsRequest>,
) -> impl IntoResponse {
let namespace = ns_ext.and_then(|axum::Extension(RequestNamespace(ns))| ns);
let resp = crate::service::reputation::batch_verify_assertions(&state, req, namespace).await;
Json(resp)
}
pub fn reputation_router() -> axum::Router<AppState> {
axum::Router::new()
.route(
"/api/v1/agents/{id}/consistency",
axum::routing::get(get_agent_consistency),
)
.route(
"/api/v1/assertions/verify-batch",
axum::routing::post(batch_verify_assertions),
)
}