The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(storage): add schema module
Steven Enamakel534116f61c76
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rsindex b777434070..a52bead3de 100644--- a/crates/openhuman-core/src/storage/mod.rs+++ b/crates/openhuman-core/src/storage/mod.rs@@ -37,6 +37,7 @@ mod lease_documents;mod lease_local;pub mod local;pub mod rebind;+pub mod schema;pub mod scope;pub mod secrets;diff --git a/crates/openhuman-core/src/storage/schema.rs b/crates/openhuman-core/src/storage/schema.rsnew file mode 100644index 0000000000..b6303a3ef1--- /dev/null+++ b/crates/openhuman-core/src/storage/schema.rs@@ -0,0 +1,106 @@+//! The composed storage schema: every owner's `storage_schema()` in one+//! [`Registry`].+//!+//! Each crate that stores records declares what it stores (collections,+//! streams, blob prefixes, and the v1 -> v2 steps that bring older data+//! forward). The host composes them once, `prepare`s the backend from the+//! result, migrates every scope ([`super::boot`]) and generates each module's+//! storage grant from the module-scoped items+//! ([`crate::modules::storage_grants`]). Composition refuses a name outside its+//! owner's prefix, a name claimed twice, a version that goes down and a step+//! gap, so a collision between two owners fails here, at boot and in+//! `scripts/ci/check-storage-schema.mjs`, never at a first write.+//!+//! Owners whose crate is gated off in a build are absent from its registry, as+//! their data is.++use std::sync::OnceLock;++use tinystoragedrivers::schema::{Item, Registry, Schema, ScopeClass};++/// Every owner's schema that this build links.+pub fn owner_schemas() -> Vec<Schema> {+ let mut schemas = vec![+ tinyagents_harness::storage_schema(),+ tinyagents_session::storage_schema(),+ tinyagents_session::ledger_storage_schema(),+ tinyagents_session::history_storage_schema(),+ tinyagents_session::conversations_storage_schema(),+ tinyagents_graph::storage_schema(),+ tinyagents_tasks::storage_schema(),+ ];+ #[cfg(feature = "flows")]+ {+ schemas.push(tinyflows_drivers::storage_schema());+ schemas.push(tinyflows_drivers::cron_storage_schema());+ }+ #[cfg(feature = "skills")]+ schemas.push(tinyskills_drivers::storage_schema());+ #[cfg(feature = "modules")]+ {+ schemas.push(tinymcp::storage::storage_schema());+ schemas.push(tinychannels::storage::storage_schema());+ schemas.push(tinyconnectors::state::storage_schema());+ schemas.push(tinybox_drivers::storage_schema());+ schemas.push(tinyjuice_drivers::storage_schema());+ }+ #[cfg(feature = "web3")]+ schemas.push(tinywallet_x402::ledger::storage_schema());+ #[cfg(feature = "tinymemes")]+ schemas.push(tinymemes_module::storage_schema());+ schemas+}++/// The registry composed from [`owner_schemas`].+///+/// # Errors+///+/// The composition error naming the owner and item at fault. A build that+/// links two owners claiming one name never gets this far in CI.+pub fn registry() -> Result<&'static Registry, super::StorageError> {+ static REGISTRY: OnceLock<Result<Registry, String>> = OnceLock::new();+ REGISTRY+ .get_or_init(|| Registry::compose(owner_schemas()).map_err(|error| error.to_string()))+ .as_ref()+ .map_err(|message| super::StorageError::invalid_input(message.clone()))+}++/// The module-scoped declarations of owner `owner`, for the module's grant:+/// `(collections, stream names, blob prefixes, secret prefixes)`.+pub fn module_items(owner: &str) -> ModuleItems {+ let mut items = ModuleItems::default();+ for schema in owner_schemas()+ .into_iter()+ .filter(|schema| schema.owner.as_str() == owner)+ {+ for item in schema.items {+ if item.scope() != ScopeClass::Module {+ continue;+ }+ match item {+ Item::Collection { spec, .. } => items.collections.push(spec),+ Item::Stream { name, .. } => items.streams.push(name),+ Item::Blobs { prefix, .. } => items.blobs.push(prefix),+ Item::Secrets { prefix, .. } => items.secrets.push(prefix),+ }+ }+ }+ items+}++/// What one owner declares at module scope.+#[derive(Debug, Default, Clone)]+pub struct ModuleItems {+ /// Collections, with their indexes.+ pub collections: Vec<tinystoragedrivers::CollectionSpec>,+ /// Stream family names.+ pub streams: Vec<String>,+ /// Blob key prefixes.+ pub blobs: Vec<String>,+ /// Secret key prefixes.+ pub secrets: Vec<String>,+}++#[cfg(test)]+#[path = "schema_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/storage/schema_tests.rs b/crates/openhuman-core/src/storage/schema_tests.rsnew file mode 100644index 0000000000..fe71ce3cc3--- /dev/null+++ b/crates/openhuman-core/src/storage/schema_tests.rs@@ -0,0 +1,18 @@+use super::*;++#[test]+fn every_owner_composes_without_collision() {+ let registry = registry().expect("the owners compose");+ let owners: Vec<&str> = registry.owners().collect();+ for expected in ["harness", "session", "graph", "tasks"] {+ assert!(owners.contains(&expected), "{expected} missing: {owners:?}");+ }+}++#[test]+fn module_items_are_the_owners_module_scoped_declarations() {+ let mcp = module_items("mcp");+ assert!(mcp.collections.iter().any(|spec| spec.name == "mcp.servers"));+ assert!(mcp.streams.iter().any(|name| name == "mcp.audit"));+ assert!(module_items("no-such-owner").collections.is_empty());+}