Skip to main content

entrenar/sovereign/registry/
manifest.rs

1//! Registry manifest containing all model entries.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6use super::types::ModelEntry;
7
8/// Registry manifest containing all model entries
9#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10pub struct RegistryManifest {
11    /// List of model entries
12    pub models: Vec<ModelEntry>,
13    /// Last sync timestamp
14    pub last_sync: Option<DateTime<Utc>>,
15    /// Registry version
16    pub version: String,
17}
18
19impl RegistryManifest {
20    /// Create a new empty manifest
21    pub fn new() -> Self {
22        Self { models: Vec::new(), last_sync: None, version: "1.0".to_string() }
23    }
24
25    /// Add a model entry
26    pub fn add(&mut self, entry: ModelEntry) {
27        // Update or insert
28        if let Some(existing) = self.models.iter_mut().find(|m| m.name == entry.name) {
29            *existing = entry;
30        } else {
31            self.models.push(entry);
32        }
33    }
34
35    /// Find a model by name
36    pub fn find(&self, name: &str) -> Option<&ModelEntry> {
37        self.models.iter().find(|m| m.name == name)
38    }
39
40    /// Find a model by name (mutable)
41    pub fn find_mut(&mut self, name: &str) -> Option<&mut ModelEntry> {
42        self.models.iter_mut().find(|m| m.name == name)
43    }
44
45    /// List all available models (those with local paths)
46    pub fn available(&self) -> Vec<&ModelEntry> {
47        self.models.iter().filter(|m| m.is_local()).collect()
48    }
49
50    /// Update sync timestamp
51    pub fn mark_synced(&mut self) {
52        self.last_sync = Some(Utc::now());
53    }
54
55    /// Get total size of all models
56    pub fn total_size_bytes(&self) -> u64 {
57        self.models.iter().map(|m| m.size_bytes).sum()
58    }
59
60    /// Get count of models
61    pub fn len(&self) -> usize {
62        self.models.len()
63    }
64
65    /// Check if manifest is empty
66    pub fn is_empty(&self) -> bool {
67        self.models.is_empty()
68    }
69}