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(modules): re-export module_config and billing_route from computer_config
Steven Enamakel2f05069796de
diff --git a/crates/openhuman-core/src/modules/computer_config.rs b/crates/openhuman-core/src/modules/computer_config.rsnew file mode 100644index 0000000000..0c6643dc31--- /dev/null+++ b/crates/openhuman-core/src/modules/computer_config.rs@@ -0,0 +1,123 @@+//! The private configuration OpenHuman hands the TinyComputer module.+//!+//! It is delivered only through the module lifecycle callback+//! (`reinitialize_module`), never logged, and rebuilt on every call so a+//! rotated or revoked credential takes effect at once:+//!+//! - `jev` — the decision model: Jev through TinyHumans when signed in, or+//! the user's OpenRouter key; OpenJev or Sage with their own keys.+//! - `planner` — the planner, rescue and output models: through the+//! TinyHumans proxy when signed in, else the user's OpenRouter key.+//! - `browser` — the Chrome executable the user picked, if any.++use serde_json::{json, Map, Value};++use crate::config::{Config, DecisionModel};+use crate::inference::provider::factory::lookup_key_for_slug;+use crate::security::credentials::session_support::{+ is_local_session_token, resolve_backend_credential, BackendCredential,+};++/// A stored provider key, falling back to its environment variable.+fn provider_key(config: &Config, slug: &str, env: &str) -> Option<String> {+ lookup_key_for_slug(slug, config)+ .ok()+ .filter(|key| !key.trim().is_empty())+ .or_else(|| std::env::var(env).ok().filter(|key| !key.trim().is_empty()))+}++/// The signed-in TinyHumans bearer, if any. The offline local token is not+/// a backend credential.+fn tinyhumans_bearer(config: &Config) -> Option<String> {+ resolve_backend_credential(config)+ .ok()+ .map(BackendCredential::into_secret)+ .filter(|token| !is_local_session_token(token))+}++fn jev(config: &Config, hosted: Option<&str>) -> Option<Value> {+ match config.computer.decision_model {+ DecisionModel::Jev => match hosted {+ Some(api_key) => Some(json!({+ "api_key": api_key,+ "provider": "tiny_humans_open_router",+ "sdk_name": crate::backend::product_identity()+ })),+ // A headless or BYOK host may have no TinyHumans session. Direct+ // OpenRouter Jev remains usable with its own scoped credential.+ None => provider_key(config, "openrouter", "OPENROUTER_API_KEY")+ .map(|api_key| json!({ "api_key": api_key, "provider": "open_router" })),+ },+ DecisionModel::OpenJev => provider_key(config, "openjev", "OPENJEV_API_KEY")+ .map(|api_key| json!({ "api_key": api_key, "provider": "open_jev" })),+ DecisionModel::Sage => provider_key(config, "sage", "SAGE_API_KEY").map(|api_key| {+ json!({ "api_key": api_key, "provider": "sage", "fast": config.computer.sage_fast })+ }),+ }+}++fn planner(config: &Config, hosted: Option<&str>) -> Option<Value> {+ let mut planner = match hosted {+ Some(api_key) => json!({+ "api_key": api_key,+ "provider": "tiny_humans",+ "sdk_name": crate::backend::product_identity()+ }),+ None => {+ let api_key = provider_key(config, "openrouter", "OPENROUTER_API_KEY")?;+ json!({ "api_key": api_key, "provider": "open_router" })+ }+ };+ let computer = &config.computer;+ for (key, value) in [+ ("model", &computer.planner_model),+ ("rescue_model", &computer.rescue_model),+ ] {+ if let Some(model) = value {+ planner[key] = json!(model);+ }+ }+ Some(planner)+}++/// Build the module configuration for `config`.+#[must_use]+pub fn module_config(config: &Config) -> Value {+ let hosted = tinyhumans_bearer(config);+ let mut out = Map::new();+ if let Some(jev) = jev(config, hosted.as_deref()) {+ out.insert("jev".into(), jev);+ }+ if let Some(planner) = planner(config, hosted.as_deref()) {+ out.insert("planner".into(), planner);+ }+ if let Some(executable) = config.browser.chrome_path.as_ref() {+ out.insert("browser".into(), json!({ "executable": executable }));+ }+ tracing::debug!(+ decision_model = config.computer.decision_model.as_str(),+ jev = out.contains_key("jev"),+ planner = out.contains_key("planner"),+ hosted = hosted.is_some(),+ "[computer] module config built"+ );+ Value::Object(out)+}++/// Which account pays for TinyComputer's decisions, for the settings UI:+/// `hosted` (TinyHumans credits), `direct_openrouter` (the user's key),+/// `open_jev` or `sage` (their own keys), or `unavailable` (no credential).+#[must_use]+pub fn billing_route(config: &Config) -> &'static str {+ match module_config(config)["jev"]["provider"].as_str() {+ Some("tiny_humans_open_router") => "hosted",+ Some("open_router") => "direct_openrouter",+ Some("open_jev") => "open_jev",+ Some("sage") => "sage",+ _ => "unavailable",+ }+}++#[cfg(test)]+#[path = "computer_config_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/modules/desktop.rs b/crates/openhuman-core/src/modules/desktop.rsindex a24863bc93..f01597378c 100644--- a/crates/openhuman-core/src/modules/desktop.rs+++ b/crates/openhuman-core/src/modules/desktop.rs@@ -15,59 +15,7 @@ mod tests;pub const MODULE_ID: &str = "tinycomputer";-/// This confidential payload is sent only to the module lifecycle callback.-/// Missing or expired host credentials remove the old Jev client on refresh.-pub fn module_config(config: &Config) -> serde_json::Value {- let credential =- crate::security::credentials::session_support::resolve_backend_credential(config)- .ok()- .map(crate::security::credentials::session_support::BackendCredential::into_secret)- .filter(|token| {- !crate::security::credentials::session_support::is_local_session_token(token)- });- match credential {- Some(api_key) => serde_json::json!({- "jev": {- "api_key": api_key,- "provider": "tiny_humans_open_router",- "sdk_name": crate::backend::product_identity()- }- }),- None => {- // A headless or BYOK host may have no TinyHumans session. Direct- // OpenRouter Jev remains usable with its own scoped credential.- let direct =- crate::inference::provider::factory::lookup_key_for_slug("openrouter", config)- .ok()- .filter(|key| !key.trim().is_empty())- .or_else(|| {- std::env::var("OPENROUTER_API_KEY")- .ok()- .filter(|key| !key.trim().is_empty())- });- direct.map_or_else(- || serde_json::json!({}),- |api_key| {- serde_json::json!({- "jev": { "api_key": api_key, "provider": "open_router" }- })- },- )- }- }-}--/// Which account pays for TinyComputer's Jev decisions, for the settings UI:-/// `hosted` (TinyHumans credits), `direct_openrouter` (the user's key), or-/// `unavailable` (no credential yet).-#[must_use]-pub fn billing_route(config: &Config) -> &'static str {- match module_config(config)["jev"]["provider"].as_str() {- Some("tiny_humans_open_router") => "hosted",- Some("open_router") => "direct_openrouter",- _ => "unavailable",- }-}+pub use super::computer_config::{billing_route, module_config};pub fn jev_ready(config: &Config) -> bool {module_config(config)["jev"].is_object()diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rsindex 2e2977ad48..fd92935538 100644--- a/crates/openhuman-core/src/modules/mod.rs+++ b/crates/openhuman-core/src/modules/mod.rs@@ -43,6 +43,7 @@pub mod boot;pub mod browser;pub mod browser_task;+pub mod computer_config;pub mod connectors;pub mod desktop;#[cfg(feature = "documents")]