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(config): add env overlay tests and runtime component wiring
Steven Enamakelb1b86725dfd7
diff --git a/crates/openhuman-core/src/config/schema/load_env_overlay_tests.rs b/crates/openhuman-core/src/config/schema/load_env_overlay_tests.rsindex 7f9a167c92..0449bbe648 100644--- a/crates/openhuman-core/src/config/schema/load_env_overlay_tests.rs+++ b/crates/openhuman-core/src/config/schema/load_env_overlay_tests.rs@@ -544,3 +544,22 @@ tts_config_download_url = "https://example.invalid/voice.onnx.json"Some("http://127.0.0.1:11434"));}++#[test]+fn env_overlay_component_switches_apply_and_ignore_garbage() {+ let env = HashMapEnv::new()+ .with("OPENHUMAN_COMPONENT_FLOWS", "0")+ .with("OPENHUMAN_COMPONENT_VOICE", "off")+ .with("OPENHUMAN_COMPONENT_MCP", "maybe");+ let mut cfg = Config::default();+ cfg.components.hosting = false;+ cfg.apply_env_overlay_with(&env);+ assert!(!cfg.components.flows);+ assert!(!cfg.components.voice);+ assert!(cfg.components.mcp, "invalid value must leave the switch alone");+ assert!(!cfg.components.hosting, "unset env must not touch the config");++ let env = HashMapEnv::new().with("OPENHUMAN_COMPONENT_HOSTING", "1");+ cfg.apply_env_overlay_with(&env);+ assert!(cfg.components.hosting, "env can switch a component back on");+}diff --git a/crates/openhuman-core/src/core/runtime/components.rs b/crates/openhuman-core/src/core/runtime/components.rsnew file mode 100644index 0000000000..fec017b80c--- /dev/null+++ b/crates/openhuman-core/src/core/runtime/components.rs@@ -0,0 +1,185 @@+//! [`ComponentSet`]: which tiny dependencies the config leaves switched on.+//!+//! Resolved from `[components]` and applied as `effective = host_choice ∩+//! components` across [`DomainSet`], [`ServiceSet`] and [`ToolGroups`]. It only+//! removes: a component that is on never enables what the host left out. A flag+//! change takes effect on the next core start.++use crate::config::schema::components::ComponentsConfig;+use crate::core::all::DomainGroup;+use crate::core::runtime::{DomainSet, ServiceSet};+use crate::core::StructuredRpcError;+use crate::tools::toolpacks::{GroupMode, ToolGroups};++pub use crate::config::schema::components::COMPONENT_NAMES;++/// The error code carried in the message of a disabled-component answer.+pub const COMPONENT_DISABLED: &str = "COMPONENT_DISABLED";++/// Resolved `[components]` switches. `Default` is everything on.+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub struct ComponentSet {+ pub flows: bool,+ pub memes: bool,+ pub documents: bool,+ pub search: bool,+ pub mcp: bool,+ pub connectors: bool,+ pub hosting: bool,+ pub juice: bool,+ pub memory: bool,+ pub wallet: bool,+ pub computer: bool,+ pub sandbox: bool,+ pub channels: bool,+ pub skills: bool,+ pub voice: bool,+}++impl Default for ComponentSet {+ fn default() -> Self {+ Self::all()+ }+}++impl ComponentSet {+ /// Every component on.+ pub fn all() -> Self {+ Self::from_config(&ComponentsConfig::default())+ }++ /// Resolve from the persisted `[components]` table.+ pub fn from_config(c: &ComponentsConfig) -> Self {+ Self {+ flows: c.flows,+ memes: c.memes,+ documents: c.documents,+ search: c.search,+ mcp: c.mcp,+ connectors: c.connectors,+ hosting: c.hosting,+ juice: c.juice,+ memory: c.memory,+ wallet: c.wallet,+ computer: c.computer,+ sandbox: c.sandbox,+ channels: c.channels,+ skills: c.skills,+ voice: c.voice,+ }+ }++ /// Whether the component named `name` is on. Unknown names are on: this is+ /// a narrowing set, and a name it does not know cannot have been switched off.+ pub fn enabled(&self, name: &str) -> bool {+ let mut c = ComponentsConfig::default();+ c.flows = self.flows;+ c.memes = self.memes;+ c.documents = self.documents;+ c.search = self.search;+ c.mcp = self.mcp;+ c.connectors = self.connectors;+ c.hosting = self.hosting;+ c.juice = self.juice;+ c.memory = self.memory;+ c.wallet = self.wallet;+ c.computer = self.computer;+ c.sandbox = self.sandbox;+ c.channels = self.channels;+ c.skills = self.skills;+ c.voice = self.voice;+ c.get(name).unwrap_or(true)+ }++ /// `Ok` when `name` is on, otherwise the typed `COMPONENT_DISABLED:<name>` error.+ pub fn require(&self, name: &str) -> Result<(), StructuredRpcError> {+ if self.enabled(name) {+ Ok(())+ } else {+ Err(component_disabled(name))+ }+ }++ /// The component that owns a domain family, if any.+ pub fn component_for_group(group: DomainGroup) -> Option<&'static str> {+ Some(match group {+ DomainGroup::Flows => "flows",+ DomainGroup::Skills => "skills",+ DomainGroup::Mcp => "mcp",+ DomainGroup::Channels => "channels",+ DomainGroup::Web3 => "wallet",+ DomainGroup::Voice => "voice",+ DomainGroup::Memory => "memory",+ DomainGroup::Integrations => "connectors",+ _ => return None,+ })+ }++ /// `host ∩ components` for domain families.+ #[must_use]+ pub fn narrow_domains(&self, host: DomainSet) -> DomainSet {+ let mut d = host;+ d.flows &= self.flows;+ d.skills &= self.skills;+ d.mcp &= self.mcp;+ d.channels &= self.channels;+ d.web3 &= self.wallet;+ d.voice &= self.voice;+ d.memory &= self.memory;+ d.integrations &= self.connectors;+ d+ }++ /// `host ∩ components` for background services.+ #[must_use]+ pub fn narrow_services(&self, host: ServiceSet) -> ServiceSet {+ let mut s = host;+ s.channels &= self.channels;+ s.memory_queue &= self.memory;+ s.memory_sync &= self.memory;+ s.skill_catalog_refresh &= self.skills;+ s.mcp_boot &= self.mcp;+ s.integrations &= self.connectors;+ s+ }++ /// `host ∩ components` for tool groups: a disabled component's groups go+ /// `Off`; every other group keeps the host's mode.+ #[must_use]+ pub fn narrow_tool_groups(&self, host: ToolGroups) -> ToolGroups {+ let mut g = host;+ let off: [(bool, &[&str]); 6] = [+ (self.flows, &["workflows"]),+ (self.documents, &["documents"]),+ (self.mcp, &["mcp"]),+ (self.connectors, &["composio"]),+ (self.wallet, &["web3"]),+ (self.skills, &["skills"]),+ ];+ for (on, ids) in off {+ if !on {+ for id in ids {+ g = g.with(id, GroupMode::Off);+ }+ }+ }+ g+ }+}++/// The typed error a disabled component answers with: message+/// `COMPONENT_DISABLED:<name>` and `data.kind = "component_disabled"`.+pub fn component_disabled(name: &str) -> StructuredRpcError {+ StructuredRpcError {+ message: format!("{COMPONENT_DISABLED}:{name}"),+ data: Some(serde_json::json!({+ "kind": "component_disabled",+ "component": name,+ })),+ expected_user_state: true,+ }+}++#[cfg(test)]+#[path = "components_tests.rs"]+mod tests;