Skip to content

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

refactor(config): move module source env helpers to schema

Steven Enamakelabcc958fad83
diff --git a/crates/openhuman-core/src/config/schema/load/env_overlay/modules.rs b/crates/openhuman-core/src/config/schema/load/env_overlay/modules.rs
index 7bcb4e1656..8ab41c1f2e 100644
--- a/crates/openhuman-core/src/config/schema/load/env_overlay/modules.rs
+++ b/crates/openhuman-core/src/config/schema/load/env_overlay/modules.rs
@@ -5,26 +5,9 @@
//! global mode and a `[[modules.overrides]]` entry for that id.
use crate::config::schema::load::env::EnvLookup;
-use crate::config::schema::{Config, ModuleOverride, ModuleSourceMode};
-
-/// Name of the global module-source variable.
-pub const MODULE_SOURCE_ENV: &str = "OPENHUMAN_MODULE_SOURCE";
-
-/// Name of the per-module variable for `id`.
-#[must_use]
-pub fn module_source_env_for(id: &str) -> String {
- let suffix: String = id
- .chars()
- .map(|c| {
- if c.is_ascii_alphanumeric() {
- c.to_ascii_uppercase()
- } else {
- '_'
- }
- })
- .collect();
- format!("{MODULE_SOURCE_ENV}_{suffix}")
-}
+use crate::config::schema::{
+ module_source_env_for, Config, ModuleOverride, ModuleSourceMode, MODULE_SOURCE_ENV,
+};
impl Config {
pub(super) fn apply_modules_env<E: EnvLookup + ?Sized>(&mut self, env: &E) {
diff --git a/crates/openhuman-core/src/config/schema/load/mod.rs b/crates/openhuman-core/src/config/schema/load/mod.rs
index e492f771fa..2f9cd97d6e 100644
--- a/crates/openhuman-core/src/config/schema/load/mod.rs
+++ b/crates/openhuman-core/src/config/schema/load/mod.rs
@@ -3,7 +3,7 @@
mod active_workspace;
mod branches;
mod dirs;
-mod env;
+pub(in crate::config::schema) mod env;
mod env_overlay;
mod impl_load;
mod migrate;
diff --git a/crates/openhuman-core/src/config/schema/mod.rs b/crates/openhuman-core/src/config/schema/mod.rs
index 5fff13cd59..b778f28bd2 100644
--- a/crates/openhuman-core/src/config/schema/mod.rs
+++ b/crates/openhuman-core/src/config/schema/mod.rs
@@ -97,7 +97,9 @@ pub use memory::{
MemoryEngineSettings, MemoryLayoutMode, MemoryRecallConfig, MemorySourceConfig,
MemorySourceKind, MEMORY_CORTEXDB_KEY_NAME,
};
-pub use modules::{ModuleOverride, ModuleSourceMode, ModulesConfig};
+pub use modules::{
+ module_source_env_for, ModuleOverride, ModuleSourceMode, ModulesConfig, MODULE_SOURCE_ENV,
+};
pub use observability::{AgentTracingBackend, AgentTracingConfig, ObservabilityConfig};
pub use privacy::{PrivacyConfig, PrivacyMode};
pub use proxy::{
diff --git a/crates/openhuman-core/src/config/schema/modules.rs b/crates/openhuman-core/src/config/schema/modules.rs
index c961fe9ee8..851dc0c306 100644
--- a/crates/openhuman-core/src/config/schema/modules.rs
+++ b/crates/openhuman-core/src/config/schema/modules.rs
@@ -66,6 +66,26 @@ impl Default for ModulesConfig {
}
}
+/// Name of the global module-source environment variable.
+pub const MODULE_SOURCE_ENV: &str = "OPENHUMAN_MODULE_SOURCE";
+
+/// Name of the per-module source variable for `id`: the id upper-cased, with
+/// non-alphanumerics as `_`.
+#[must_use]
+pub fn module_source_env_for(id: &str) -> String {
+ let suffix: String = id
+ .chars()
+ .map(|c| {
+ if c.is_ascii_alphanumeric() {
+ c.to_ascii_uppercase()
+ } else {
+ '_'
+ }
+ })
+ .collect();
+ format!("{MODULE_SOURCE_ENV}_{suffix}")
+}
+
/// Where a module is resolved from.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
diff --git a/crates/openhuman-core/src/config/schema/modules_tests.rs b/crates/openhuman-core/src/config/schema/modules_tests.rs
index 211e8c0f3c..ce61187a7f 100644
--- a/crates/openhuman-core/src/config/schema/modules_tests.rs
+++ b/crates/openhuman-core/src/config/schema/modules_tests.rs
@@ -79,7 +79,7 @@ fn mode_names_round_trip() {
struct MapEnv(std::collections::HashMap<&'static str, &'static str>);
-impl crate::config::schema::load::env::EnvLookup for MapEnv {
+impl load::env::EnvLookup for MapEnv {
fn get(&self, key: &str) -> Option<String> {
self.0.get(key).map(|v| (*v).to_string())
}
@@ -87,7 +87,7 @@ impl crate::config::schema::load::env::EnvLookup for MapEnv {
fn overlay(pairs: &[(&'static str, &'static str)]) -> crate::config::Config {
let mut config = crate::config::Config::default();
- config.apply_modules_env_for_test(&MapEnv(pairs.iter().copied().collect()));
+ config.apply_env_overlay_with(&MapEnv(pairs.iter().copied().collect()));
config
}
@@ -110,7 +110,7 @@ fn per_module_env_adds_a_source_override_replacing_a_path_entry() {
.modules
.overrides
.push(ModuleOverride::with_path("tinyjuice", "/dev/libtinyjuice.so"));
- config.apply_modules_env_for_test(&MapEnv(
+ config.apply_env_overlay_with(&MapEnv(
[("OPENHUMAN_MODULE_SOURCE_TINYJUICE", "source")]
.into_iter()
.collect(),
@@ -125,7 +125,6 @@ fn per_module_env_adds_a_source_override_replacing_a_path_entry() {
#[test]
fn per_module_env_names_upper_case_the_id() {
- use crate::config::schema::load::env_overlay_modules::module_source_env_for;
assert_eq!(
module_source_env_for("tinyjuice"),
"OPENHUMAN_MODULE_SOURCE_TINYJUICE"