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
refactor(config): centralize provider id generation logic
Steven Enamakel5637e41aa25a
diff --git a/crates/openhuman-core/src/config/schema/cloud_providers.rs b/crates/openhuman-core/src/config/schema/cloud_providers.rsindex 02277bbebf..9ca1f98529 100644--- a/crates/openhuman-core/src/config/schema/cloud_providers.rs+++ b/crates/openhuman-core/src/config/schema/cloud_providers.rs@@ -372,36 +372,7 @@ pub fn is_slug_reserved(s: &str) -> bool {/// The random suffix is not cryptographically strong — it only needs to be/// unique within a single user's config file.pub fn generate_provider_id(slug: &str) -> String {- use std::time::{SystemTime, UNIX_EPOCH};- // Cheap pseudo-random from timestamp nanoseconds — adequate for local- // config uniqueness without pulling in a PRNG crate.- let nanos = SystemTime::now()- .duration_since(UNIX_EPOCH)- .unwrap_or_default()- .subsec_nanos();- let chars: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";- let mut suffix = String::with_capacity(5);- let mut seed = nanos as usize;- for _ in 0..5 {- suffix.push(chars[seed % chars.len()] as char);- seed = seed- .wrapping_mul(6364136223846793005)- .wrapping_add(1442695040888963407);- seed = (seed >> 33) ^ seed;- }- // Sanitise slug to only alphanumeric + '-' for the id prefix.- let safe_slug: String = slug- .chars()- .map(|c| {- if c.is_ascii_alphanumeric() || c == '-' {- c- } else {- '_'- }- })- .take(20)- .collect();- format!("p_{}_{}", safe_slug, suffix)+ super::generate_provider_id_with_prefix("p", slug)}#[cfg(test)]diff --git a/crates/openhuman-core/src/config/schema/mod.rs b/crates/openhuman-core/src/config/schema/mod.rsindex e08a894046..af51ef690e 100644--- a/crates/openhuman-core/src/config/schema/mod.rs+++ b/crates/openhuman-core/src/config/schema/mod.rs@@ -4,6 +4,30 @@pub mod cloud_providers;pub use cloud_providers::{generate_provider_id, is_slug_reserved, AuthStyle, CloudProviderCreds};++fn generate_provider_id_with_prefix(prefix: &str, slug: &str) -> String {+ use std::time::{SystemTime, UNIX_EPOCH};+ let nanos = SystemTime::now()+ .duration_since(UNIX_EPOCH)+ .unwrap_or_default()+ .subsec_nanos();+ let chars: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";+ let mut suffix = String::with_capacity(5);+ let mut seed = nanos as usize;+ for _ in 0..5 {+ suffix.push(chars[seed % chars.len()] as char);+ seed = seed+ .wrapping_mul(6364136223846793005)+ .wrapping_add(1442695040888963407);+ seed = (seed >> 33) ^ seed;+ }+ let safe_slug: String = slug+ .chars()+ .map(|c| if c.is_ascii_alphanumeric() || c == '-' { c } else { '_' })+ .take(20)+ .collect();+ format!("{prefix}_{safe_slug}_{suffix}")+}pub mod ephemeral_route;pub use ephemeral_route::{EphemeralRoute, EPHEMERAL_ROUTE_SLUG};pub mod resolved_endpoints;diff --git a/crates/openhuman-core/src/config/schema/voice_providers.rs b/crates/openhuman-core/src/config/schema/voice_providers.rsindex 6ab679a998..a118f5bc9e 100644--- a/crates/openhuman-core/src/config/schema/voice_providers.rs+++ b/crates/openhuman-core/src/config/schema/voice_providers.rs@@ -164,33 +164,7 @@ pub fn is_voice_slug_reserved(s: &str) -> bool {////// Format: `"vp_<slug>_<5 random alphanumerics>"`.pub fn generate_voice_provider_id(slug: &str) -> String {- use std::time::{SystemTime, UNIX_EPOCH};- let nanos = SystemTime::now()- .duration_since(UNIX_EPOCH)- .unwrap_or_default()- .subsec_nanos();- let chars: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";- let mut suffix = String::with_capacity(5);- let mut seed = nanos as usize;- for _ in 0..5 {- suffix.push(chars[seed % chars.len()] as char);- seed = seed- .wrapping_mul(6364136223846793005)- .wrapping_add(1442695040888963407);- seed = (seed >> 33) ^ seed;- }- let safe_slug: String = slug- .chars()- .map(|c| {- if c.is_ascii_alphanumeric() || c == '-' {- c- } else {- '_'- }- })- .take(20)- .collect();- format!("vp_{}_{}", safe_slug, suffix)+ super::generate_provider_id_with_prefix("vp", slug)}#[cfg(test)]diff --git a/crates/openhuman-core/src/inference/ops.rs b/crates/openhuman-core/src/inference/ops.rsindex 339f17e9db..dc7693e3b5 100644--- a/crates/openhuman-core/src/inference/ops.rs+++ b/crates/openhuman-core/src/inference/ops.rs@@ -129,11 +129,7 @@ pub async fn inference_test_provider_model(prompt_len = prompt.len(),"{LOG_PREFIX} test_provider_model:start");- let local = provider.trim().starts_with("lmstudio:")- || provider.trim().starts_with("ollama:")- || provider.trim().starts_with("mlx:")- || provider.trim().starts_with("omlx:")- || provider.trim().starts_with("local-openai:");+ let local = tinyinference_local::profile::is_local_provider_string(provider);let (chat_model, model) = if local {debug!(provider,