Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(config): add schema storage layer

Steven Enamakelac0e40a0c4e5
diff --git a/crates/openhuman-core/src/config/schema/mod.rs b/crates/openhuman-core/src/config/schema/mod.rs
index ba91256a59..6354b68668 100644
--- a/crates/openhuman-core/src/config/schema/mod.rs
+++ b/crates/openhuman-core/src/config/schema/mod.rs
@@ -29,6 +29,8 @@ mod hooks;
pub use hooks::HooksConfig;
pub mod hosting;
pub use hosting::HostingConfig;
+pub mod storage;
+pub use storage::StorageConfig;
mod identity_cost;
mod load;
pub use load::{
diff --git a/crates/openhuman-core/src/config/schema/storage.rs b/crates/openhuman-core/src/config/schema/storage.rs
new file mode 100644
index 0000000000..d35b4d0448
--- /dev/null
+++ b/crates/openhuman-core/src/config/schema/storage.rs
@@ -0,0 +1,53 @@
+//! Storage backend configuration (`[storage]`).
+//!
+//! Where the core keeps durable state that has moved onto the
+//! `tinystoragedrivers` ports. Empty (the default) keeps the classic on-disk
+//! layout under the workspace, which is what the desktop app uses. A URL
+//! points the process at one backend instead:
+//!
+//! ```toml
+//! [storage]
+//! url = "mongodb://app:[email protected]/openhuman" # cloud, multi-tenant
+//! # url = "sqlite:/var/lib/openhuman/storage" # one SQLite dir
+//! # url = "memory" # tests, keeps nothing
+//! ```
+//!
+//! `OPENHUMAN_STORAGE_URL` overrides it (see [`crate::storage`]). This
+//! section is bootstrap configuration: it is always read from the file or the
+//! environment, never from storage itself.
+
+use schemars::JsonSchema;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
+#[serde(default)]
+pub struct StorageConfig {
+ /// The storage URL: `memory`, `sqlite:<path>`, `mongodb://…/<db>`,
+ /// `mongodb+srv://…/<db>` or `file:<dir>`. Empty or absent keeps the
+ /// classic on-disk layout.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub url: Option<String>,
+}
+
+impl std::fmt::Debug for StorageConfig {
+ /// Redacts credentials: a MongoDB URL carries the database password.
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("StorageConfig")
+ .field("url", &self.url.as_deref().map(redact_url))
+ .finish()
+ }
+}
+
+/// `url` with any `user:password@` userinfo replaced by `***@`.
+pub fn redact_url(url: &str) -> String {
+ match (url.find("://"), url.rfind('@')) {
+ (Some(scheme), Some(at)) if at > scheme => {
+ format!("{}://***@{}", &url[..scheme], &url[at + 1..])
+ }
+ _ => url.to_string(),
+ }
+}
+
+#[cfg(test)]
+#[path = "storage_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/config/schema/storage_tests.rs b/crates/openhuman-core/src/config/schema/storage_tests.rs
new file mode 100644
index 0000000000..d0ecf97ed5
--- /dev/null
+++ b/crates/openhuman-core/src/config/schema/storage_tests.rs
@@ -0,0 +1,26 @@
+use super::*;
+
+#[test]
+fn defaults_to_the_classic_layout() {
+ assert_eq!(StorageConfig::default().url, None);
+ let parsed: StorageConfig = toml::from_str("").unwrap();
+ assert_eq!(parsed, StorageConfig::default());
+}
+
+#[test]
+fn reads_a_url_from_toml() {
+ let parsed: StorageConfig = toml::from_str("url = \"memory\"").unwrap();
+ assert_eq!(parsed.url.as_deref(), Some("memory"));
+}
+
+#[test]
+fn debug_never_prints_credentials() {
+ let config = StorageConfig {
+ url: Some("mongodb://app:[email protected]/openhuman".into()),
+ };
+ let shown = format!("{config:?}");
+ assert!(!shown.contains("hunter2"), "{shown}");
+ assert!(shown.contains("mongodb://***@db.internal/openhuman"), "{shown}");
+ assert_eq!(redact_url("sqlite:/tmp/x"), "sqlite:/tmp/x");
+ assert_eq!(redact_url("mongodb://h/db"), "mongodb://h/db");
+}
diff --git a/crates/openhuman-core/src/config/schema/types/config.rs b/crates/openhuman-core/src/config/schema/types/config.rs
index c38ef51ce9..1e1d277a21 100644
--- a/crates/openhuman-core/src/config/schema/types/config.rs
+++ b/crates/openhuman-core/src/config/schema/types/config.rs
@@ -421,6 +421,11 @@ pub struct Config {
#[serde(default)]
pub hosting: HostingConfig,
+ /// Storage backend for state on the `tinystoragedrivers` ports
+ /// (`[storage]`). Empty keeps the classic on-disk layout.
+ #[serde(default)]
+ pub storage: StorageConfig,
+
#[serde(default)]
pub voice_server: VoiceServerConfig,
diff --git a/crates/openhuman-core/src/config/schema/types/defaults.rs b/crates/openhuman-core/src/config/schema/types/defaults.rs
index f48399118f..2737b33156 100644
--- a/crates/openhuman-core/src/config/schema/types/defaults.rs
+++ b/crates/openhuman-core/src/config/schema/types/defaults.rs
@@ -104,6 +104,7 @@ impl Default for Config {
runtime_pool: RuntimePoolConfig::default(),
tokenjuice: TokenjuiceConfig::default(),
hosting: HostingConfig::default(),
+ storage: StorageConfig::default(),
voice_server: VoiceServerConfig::default(),
voice_providers: Vec::new(),
voice_live: crate::config::schema::voice_live::LiveVoiceConfig::default(),