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(profiles): add immutable operator provider bindings
Steven Enamakelfe1339835727
diff --git a/crates/openhuman-core/src/config/schema/ephemeral_route.rs b/crates/openhuman-core/src/config/schema/ephemeral_route.rsindex 311ddab324..c1dd27a96d 100644--- a/crates/openhuman-core/src/config/schema/ephemeral_route.rs+++ b/crates/openhuman-core/src/config/schema/ephemeral_route.rs@@ -48,7 +48,7 @@ pub const EPHEMERAL_ROUTE_SLUG: &str = "ephemeral-route";////// Never serialized — see the module docs. `JsonSchema` is derived only because/// [`Config`](crate::config::Config) derives it for the whole struct.-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]+#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]pub struct EphemeralRoute {/// OpenAI-compatible base URL, as a `cloud_providers` endpoint would be/// spelled (`/chat/completions` is appended to it).@@ -65,6 +65,16 @@ pub struct EphemeralRoute {pub headers: Vec<(String, String)>,}+impl std::fmt::Debug for EphemeralRoute {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ f.debug_struct("EphemeralRoute")+ .field("endpoint", &crate::inference::provider::factory::redact_endpoint(&self.endpoint))+ .field("api_key", &"[redacted]")+ .field("header_count", &self.headers.len())+ .finish()+ }+}+impl EphemeralRoute {/// Build a route from a controller's two optional parameters.///diff --git a/crates/openhuman-core/src/config/schema/tools/search.rs b/crates/openhuman-core/src/config/schema/tools/search.rsindex 440048af5d..c5461be0d9 100644--- a/crates/openhuman-core/src/config/schema/tools/search.rs+++ b/crates/openhuman-core/src/config/schema/tools/search.rs@@ -175,13 +175,25 @@ fn default_search_timeout_secs() -> u64 {/// Credentials for a BYO search provider. Considered configured iff the/// trimmed value is non-empty.-#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]+#[derive(Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]#[serde(default)]pub struct SearchEngineCredentials {+ /// Optional direct provider base URL. Operator profile settings validate it.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub base_url: Option<String>,#[serde(default)]pub api_key: Option<String>,}+impl std::fmt::Debug for SearchEngineCredentials {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ f.debug_struct("SearchEngineCredentials")+ .field("has_key", &self.has_key())+ .field("has_base_url", &self.base_url.is_some())+ .finish()+ }+}+impl SearchEngineCredentials {pub fn has_key(&self) -> bool {self.key().is_some()@@ -299,7 +311,7 @@ impl SearchProviderSettings {}/// Search configuration.-#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]#[serde(default)]pub struct SearchConfig {/// Settings format; see [`SEARCH_SCHEMA_VERSION`]. Absent in legacy files.diff --git a/crates/openhuman-core/src/config/schema/types/config.rs b/crates/openhuman-core/src/config/schema/types/config.rsindex c52f93d11d..54250e45b3 100644--- a/crates/openhuman-core/src/config/schema/types/config.rs+++ b/crates/openhuman-core/src/config/schema/types/config.rs@@ -54,6 +54,11 @@ pub struct CustomEmbeddingsConfig {/// `Clone` is implemented by hand in `config_clone.rs` so it is emitted once.#[derive(Debug, Serialize, Deserialize, JsonSchema)]pub struct Config {+ /// Immutable operator provider binding, absent from the user wire format.+ #[serde(skip)]+ #[schemars(skip)]+ #[doc(hidden)]+ pub profile_providers: Option<std::sync::Arc<crate::profiles::provider_settings::ProfileProviderSettings>>,#[serde(skip)]pub workspace_dir: PathBuf,/// Agent action sandbox root — the default cwd for shell/file/git tools.diff --git a/crates/openhuman-core/src/config/schema/types/config_clone.rs b/crates/openhuman-core/src/config/schema/types/config_clone.rsindex 7194a52269..c9602e58e8 100644--- a/crates/openhuman-core/src/config/schema/types/config_clone.rs+++ b/crates/openhuman-core/src/config/schema/types/config_clone.rs@@ -12,6 +12,7 @@ impl Clone for Config {#[inline(never)]fn clone(&self) -> Self {Self {+ profile_providers: self.profile_providers.clone(),workspace_dir: self.workspace_dir.clone(),action_dir: self.action_dir.clone(),action_dir_override: self.action_dir_override.clone(),diff --git a/crates/openhuman-core/src/config/schema/types/defaults.rs b/crates/openhuman-core/src/config/schema/types/defaults.rsindex fc91bfdc43..c2d7c83e94 100644--- a/crates/openhuman-core/src/config/schema/types/defaults.rs+++ b/crates/openhuman-core/src/config/schema/types/defaults.rs@@ -25,6 +25,7 @@ impl Default for Config {});Self {+ profile_providers: None,workspace_dir: openhuman_dir.join("workspace"),action_dir: crate::config::default_action_dir(),action_dir_override: None,diff --git a/crates/openhuman-core/src/core/runtime/saas.rs b/crates/openhuman-core/src/core/runtime/saas.rsindex 309a809f43..8fab322c5e 100644--- a/crates/openhuman-core/src/core/runtime/saas.rs+++ b/crates/openhuman-core/src/core/runtime/saas.rs@@ -32,6 +32,15 @@ pub struct SaasConfig {/// Root of every user's state and the operator's own. Must be an absolute,/// existing directory that is not world-writable.pub root: PathBuf,+ /// Validated direct inference defaults shared by profile chat, relay, and cron.+ #[serde(default)]+ pub chat_provider: Option<super::direct_profile_provider::DirectProfileProvider>,+ /// Operator-owned direct Exa/Gemini policy; never a user settings RPC.+ #[serde(default)]+ pub search: Option<crate::config::SearchConfig>,+ /// Advertised names for the three search roles. Missing entries retain canonical names.+ #[serde(default)]+ pub search_role_names: std::collections::BTreeMap<tinysearch_bus::Role, String>,/// The gateway's bearer, one line in a `0600` file. Defaults to/// `<root>/service.token`.#[serde(default)]@@ -169,6 +178,9 @@ impl SaasConfig {pub fn new(root: impl Into<PathBuf>) -> Self {Self {root: root.into(),+ chat_provider: None,+ search: None,+ search_role_names: std::collections::BTreeMap::new(),service_token_file: None,tool_allowlist: Vec::new(),sandbox: SaasSandboxConfig::default(),diff --git a/crates/openhuman-core/src/profiles/provider_settings.rs b/crates/openhuman-core/src/profiles/provider_settings.rsindex cfdbd9e90b..3acd50dc1b 100644--- a/crates/openhuman-core/src/profiles/provider_settings.rs+++ b/crates/openhuman-core/src/profiles/provider_settings.rs@@ -1,4 +1,150 @@//! Immutable provider bindings for authenticated profile contexts.+//!+//! The binding is skipped by Config serialization. Only private module+//! initialization receives search credentials; public profile configs hold no+//! operator keys. Role aliases are a host policy boundary, never a module tool+//! router that can point at arbitrary native capabilities.++use std::collections::{BTreeMap, HashSet};+use std::sync::Arc;+use tinysearch_bus::Role;+use crate::config::{Config, SearchConfig, SearchPresentation, SearchProviderSettings, SearchRoute};+use crate::core::runtime::direct_profile_provider::{DirectProfileProvider, validate_endpoint};+use crate::core::runtime::SaasConfig;++/// Host-only settings carried by a profile's immutable config/context.+#[derive(Debug, Clone)]+pub struct ProfileProviderSettings {+ chat: Option<DirectProfileProvider>,+ search: SearchConfig,+ role_names: BTreeMap<Role, String>,+}++impl ProfileProviderSettings {+ /// Validate operator-owned direct routes and their presentation.+ ///+ /// # Errors+ /// Rejects managed routes, extra providers, non-role presentation, invalid+ /// endpoints, unsafe aliases, duplicate names, and native tool collisions.+ pub fn from_saas(saas: &SaasConfig) -> anyhow::Result<Self> {+ let mut search = saas.search.clone().unwrap_or_else(|| SearchConfig {+ enabled: Some(false), providers: BTreeMap::new(), ..SearchConfig::default()+ });+ if search.presentation != SearchPresentation::Roles {+ anyhow::bail!("profile search requires role presentation");+ }+ if search.providers.iter().any(|(provider, setting)| {+ setting.enabled && (!matches!(provider.as_str(), "exa" | "gemini") || setting.route != SearchRoute::Direct)+ }) {+ anyhow::bail!("profile search permits only direct Exa and Gemini providers");+ }+ for provider in ["exa", "gemini"] {+ if let Some(endpoint) = search.credentials(provider).and_then(|credential| credential.base_url.as_deref()) {+ validate_endpoint(endpoint)?;+ }+ }+ // The deployment has exactly these roles and fallback order. Arguments+ // and stored user settings cannot add another provider or capability.+ let usable: HashSet<_> = ["exa", "gemini"].into_iter().filter(|provider| {+ search.providers.get(*provider).is_some_and(|setting| setting.enabled)+ && search.credentials(provider).is_some_and(|credential| credential.has_key())+ }).collect();+ search.providers = usable.iter().map(|provider| ((*provider).to_owned(), SearchProviderSettings::direct())).collect();+ search.enabled = Some(!usable.is_empty());+ search.presentation_provider = None;+ search.roles = BTreeMap::from([+ ("search".into(), ["exa", "gemini"].into_iter().filter(|name| usable.contains(name)).map(str::to_owned).collect()),+ ("answer".into(), ["gemini"].into_iter().filter(|name| usable.contains(name)).map(str::to_owned).collect()),+ ("contents".into(), ["exa"].into_iter().filter(|name| usable.contains(name)).map(str::to_owned).collect()),+ ]);+ let role_names = saas.search_role_names.clone();+ let mut used = HashSet::new();+ for role in crate::search::providers::ROLES {+ let canonical = tinysearch_bus::names::role_tool_name(role);+ let name = role_names.get(&role).map(String::as_str).unwrap_or(canonical);+ if !valid_identifier(name) || !used.insert(name.to_owned()) {+ anyhow::bail!("profile search role names require unique safe tool identifiers");+ }+ if name != canonical && collides(name) {+ anyhow::bail!("profile search role name collides with a native tool");+ }+ }+ Ok(Self { chat: saas.chat_provider.clone(), search, role_names })+ }++ /// Attach a serialization-skipped binding to a profile config. The visible+ /// search policy is safe to persist; credentials and endpoint overrides are absent.+ pub fn bind(&self, config: &mut Config) {+ let mut public_search = self.search.clone();+ for provider in crate::config::SEARCH_PROVIDERS {+ if let Some(credential) = public_search.credentials_mut(provider) {+ credential.api_key = None;+ credential.base_url = None;+ }+ }+ config.search = public_search;+ config.profile_providers = Some(Arc::new(self.clone()));+ self.apply_chat(config);+ }++ /// Model fixed by the operator, when direct chat was configured.+ pub(crate) fn chat_model(&self) -> Option<&str> { self.chat.as_ref().map(DirectProfileProvider::model) }++ pub(crate) fn apply_chat(&self, config: &mut Config) {+ if let Some(chat) = &self.chat { chat.apply(config); }+ }++ /// Private search configuration for module initialization only.+ pub(crate) fn effective_search(&self, config: &Config) -> Config {+ let mut effective = config.clone();+ effective.search = self.search.clone();+ // Legacy search integrations cannot widen a direct profile's providers.+ effective.seltz.enabled = false;+ effective.searxng.enabled = false;+ effective+ }++ /// An advertised role maps exactly once to its canonical module operation.+ /// Renamed canonical operations and provider-native names never resolve.+ pub fn canonical_role_name(&self, advertised: &str) -> Option<&'static str> {+ crate::search::providers::ROLES.into_iter().find_map(|role| {+ (self.advertised_role_name(role) == advertised).then(|| tinysearch_bus::names::role_tool_name(role))+ })+ }++ /// The operator-selected name for a role, or the ordinary canonical name.+ pub fn advertised_role_name(&self, role: Role) -> &str {+ self.role_names.get(&role).map(String::as_str).unwrap_or_else(|| tinysearch_bus::names::role_tool_name(role))+ }++ /// Rename only canonical role declarations; no provider extras are exposed.+ pub(crate) fn present(&self, specs: &mut Vec<tinysearch_bus::ToolSpec>) {+ specs.retain_mut(|spec| {+ let Some(role) = tinysearch_bus::role_for_tool(&spec.name) else { return false };+ spec.name = self.advertised_role_name(role).to_owned();+ // Deep research is a separate capability the deployment never grants.+ if let Some(properties) = spec.parameters.get_mut("properties").and_then(serde_json::Value::as_object_mut) {+ properties.remove("depth");+ }+ true+ });+ }+}++fn valid_identifier(name: &str) -> bool {+ let mut characters = name.chars();+ name.len() <= 64 && characters.next().is_some_and(|first| first.is_ascii_alphabetic() || first == '_')+ && characters.all(|character| character.is_ascii_alphanumeric() || character == '_')+}++fn collides(name: &str) -> bool {+ tinysearch_bus::role_for_tool(name).is_some()+ || tinysearch_bus::provider_tool_specs().iter().any(|tool| tool.name == name)+ || crate::tools::toolpacks::pack_for_tool(name).is_some()+ || super::tools::HARD_DENIED.contains(&name)+ || super::tools::HARD_DENIED_PREFIXES.iter().any(|prefix| name.starts_with(prefix))+ || matches!(name, "shell" | "memory" | "show_page" | "search" | "http_request" | "spawn_agent" | "spawn_async_subagent")+}#[cfg(test)]#[path = "provider_settings_tests.rs"]