use serde::{Deserialize, Serialize};
use trusty_common::memory_core::dream::PersistedDreamStats;
use trusty_common::memory_core::store::kg::Triple;
#[derive(Serialize, Clone, Debug)]
pub struct PalaceInfo {
pub id: String,
pub name: String,
pub description: Option<String>,
pub drawer_count: usize,
pub vector_count: usize,
pub kg_triple_count: usize,
pub wing_count: usize,
pub created_at: chrono::DateTime<chrono::Utc>,
pub last_write_at: Option<chrono::DateTime<chrono::Utc>>,
#[serde(default)]
pub node_count: u64,
#[serde(default)]
pub edge_count: u64,
#[serde(default)]
pub community_count: u64,
#[serde(default)]
pub is_compacting: bool,
}
#[derive(Serialize, Default, Clone, Debug)]
pub struct DreamStatusPayload {
pub last_run_at: Option<chrono::DateTime<chrono::Utc>>,
pub merged: usize,
pub pruned: usize,
pub compacted: usize,
pub closets_updated: usize,
pub duration_ms: u64,
}
impl From<PersistedDreamStats> for DreamStatusPayload {
fn from(p: PersistedDreamStats) -> Self {
Self {
last_run_at: Some(p.last_run_at),
merged: p.stats.merged,
pruned: p.stats.pruned,
compacted: p.stats.compacted,
closets_updated: p.stats.closets_updated,
duration_ms: p.stats.duration_ms,
}
}
}
#[derive(Deserialize, Clone, Debug)]
pub struct CreatePalaceBody {
pub name: String,
#[serde(default)]
pub description: Option<String>,
#[serde(default)]
pub cwd: Option<String>,
#[serde(default)]
pub force: bool,
}
#[derive(Deserialize, Clone, Debug)]
pub struct CreateDrawerBody {
pub content: String,
#[serde(default)]
pub room: Option<String>,
#[serde(default)]
pub tags: Vec<String>,
#[serde(default)]
pub importance: Option<f32>,
}
#[derive(Deserialize, Default, Clone, Debug)]
pub struct ListDrawersQuery {
#[serde(default)]
pub room: Option<String>,
#[serde(default)]
pub tag: Option<String>,
#[serde(default)]
pub limit: Option<usize>,
#[serde(default)]
pub offset: Option<usize>,
#[serde(default)]
pub sort: Option<String>,
}
#[derive(Deserialize, Clone, Debug)]
pub struct KgAssertBody {
pub subject: String,
pub predicate: String,
pub object: String,
#[serde(default)]
pub confidence: Option<f32>,
#[serde(default)]
pub provenance: Option<String>,
}
#[derive(Serialize, Clone, Debug)]
pub struct KgGraphPayload {
pub triples: Vec<Triple>,
pub node_count: u64,
pub edge_count: u64,
pub community_count: u64,
}
#[derive(Serialize, Clone, Debug)]
pub struct StatusPayload {
pub version: String,
pub palace_count: usize,
pub default_palace: Option<String>,
pub data_root: String,
pub total_drawers: usize,
pub total_vectors: usize,
pub total_kg_triples: usize,
}
#[derive(Debug, thiserror::Error)]
pub enum ServiceError {
#[error("{0}")]
BadRequest(String),
#[error("{0}")]
NotFound(String),
#[error("{0}")]
Conflict(String),
#[error("{0}")]
Internal(String),
}
impl ServiceError {
pub fn bad_request(msg: impl Into<String>) -> Self {
Self::BadRequest(msg.into())
}
pub fn not_found(msg: impl Into<String>) -> Self {
Self::NotFound(msg.into())
}
pub fn conflict(msg: impl Into<String>) -> Self {
Self::Conflict(msg.into())
}
pub fn internal(msg: impl Into<String>) -> Self {
Self::Internal(msg.into())
}
}
pub type ServiceResult<T> = std::result::Result<T, ServiceError>;