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(modules): add computer module and computer_status controller schema
Steven Enamakel51387841b1f1
diff --git a/crates/openhuman-core/src/modules/computer.rs b/crates/openhuman-core/src/modules/computer.rsnew file mode 100644index 0000000000..a4eaecd88c--- /dev/null+++ b/crates/openhuman-core/src/modules/computer.rs@@ -0,0 +1,103 @@+//! What the Computer settings page shows about the TinyComputer module: its+//! lifecycle state, the routes the host configured, and — when asked — what+//! the module itself reports through `Describe`.++use serde::Serialize;+use tinycomputer_bus::agent::{Capabilities, SurfaceAvailability};++use super::types::{ModuleState, ModuleStatus};+use crate::config::Config;++/// What the module reports about itself.+#[derive(Debug, Clone, Serialize)]+pub struct ComputerCapabilities {+ pub contract_version: (u32, u32),+ /// Whether this host can talk to that contract.+ pub compatible: bool,+ pub jev_configured: bool,+ pub planner_configured: bool,+ pub rescue_configured: bool,+ pub surfaces: Vec<SurfaceAvailability>,+}++impl From<Capabilities> for ComputerCapabilities {+ fn from(value: Capabilities) -> Self {+ Self {+ contract_version: value.contract_version,+ compatible: tinycomputer_bus::is_compatible(value.contract_version),+ jev_configured: value.jev_configured,+ planner_configured: value.planner_configured,+ rescue_configured: value.rescue_configured,+ surfaces: value.surfaces,+ }+ }+}++#[derive(Debug, Clone, Serialize)]+pub struct ComputerStatus {+ pub module: Option<ModuleStatus>,+ /// `[computer] decision_model`.+ pub decision_model: &'static str,+ /// Who pays for decisions: `hosted`, `direct_openrouter`, `open_jev`,+ /// `sage`, or `unavailable`.+ pub decision_route: &'static str,+ /// Where planner and rescue calls go: `hosted`, `direct_openrouter`, or+ /// `unavailable`.+ pub planner_route: &'static str,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub capabilities: Option<ComputerCapabilities>,+ /// Why `Describe` could not be read, when it was asked for.+ #[serde(skip_serializing_if = "Option::is_none")]+ pub error: Option<String>,+}++fn planner_route(config: &Config) -> &'static str {+ match super::computer_config::module_config(config)["planner"]["provider"].as_str() {+ Some("tiny_humans") => "hosted",+ Some("open_router") => "direct_openrouter",+ _ => "unavailable",+ }+}++async fn describe(config: &Config) -> Result<Capabilities, String> {+ let proxy = super::desktop::proxy(config).await?;+ proxy+ .call(tinycomputer_bus::agent::names::methods::DESCRIBE, ())+ .await+ .map_err(|error| format!("TinyComputer Describe failed: {error}"))+}++/// Report the module. `load` asks the module itself (loading it if needed);+/// otherwise it is only asked when already serving.+pub async fn status(config: &Config, load: bool) -> ComputerStatus {+ let module = || {+ super::ops::list(config)+ .into_iter()+ .find(|item| item.id == super::desktop::MODULE_ID)+ };+ let before = module();+ let ask = load || before.as_ref().is_some_and(|m| m.state == ModuleState::Ready);+ let (capabilities, error) = if ask {+ match describe(config).await {+ Ok(capabilities) => (Some(capabilities.into()), None),+ Err(error) => {+ tracing::debug!(%error, "[computer] describe failed");+ (None, Some(error))+ }+ }+ } else {+ (None, None)+ };+ ComputerStatus {+ module: if ask { module() } else { before },+ decision_model: config.computer.decision_model.as_str(),+ decision_route: super::computer_config::billing_route(config),+ planner_route: planner_route(config),+ capabilities,+ error,+ }+}++#[cfg(test)]+#[path = "computer_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/modules/computer_tests.rs b/crates/openhuman-core/src/modules/computer_tests.rsnew file mode 100644index 0000000000..301e03a8c3--- /dev/null+++ b/crates/openhuman-core/src/modules/computer_tests.rs@@ -0,0 +1,49 @@+use super::*;++#[tokio::test]+async fn status_without_load_reports_routes_and_skips_describe() {+ let dir = tempfile::tempdir().unwrap();+ let mut config = Config::default();+ config.config_path = dir.path().join("config.toml");+ config.workspace_dir = dir.path().join("workspace");+ config.secrets.encrypt = false;+ config.computer.decision_model = crate::config::DecisionModel::Sage;+ let status = status(&config, false).await;+ assert_eq!(status.decision_model, "sage");+ assert!(status.module.is_some());+ assert!(status.capabilities.is_none());+ assert!(status.error.is_none());+}++#[tokio::test]+async fn load_on_a_disabled_host_reports_the_failure() {+ let dir = tempfile::tempdir().unwrap();+ let mut config = Config::default();+ config.config_path = dir.path().join("config.toml");+ config.workspace_dir = dir.path().join("workspace");+ config.modules.enabled = false;+ let status = status(&config, true).await;+ assert!(status.capabilities.is_none());+ assert!(status.error.as_deref().is_some_and(|e| !e.is_empty()));+}++#[test]+fn capabilities_report_compatibility() {+ let capabilities: Capabilities = serde_json::from_value(serde_json::json!({+ "contract_version": [tinycomputer_bus::CONTRACT_VERSION.0, 99],+ "surfaces": [{"kind": "browser", "available": true}],+ "jev_configured": true,+ "planner_configured": true,+ "rescue_configured": true,+ "output_configured": false,+ "step_kinds": [],+ "guide": "",+ "members": [],+ "examples": []+ }))+ .unwrap();+ let view = ComputerCapabilities::from(capabilities);+ assert!(view.compatible);+ assert!(view.rescue_configured);+ assert_eq!(view.surfaces.len(), 1);+}diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rsindex afdbc4e7ce..f536237979 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;pub mod computer_config;pub mod connectors;pub mod desktop;diff --git a/crates/openhuman-core/src/modules/schemas.rs b/crates/openhuman-core/src/modules/schemas.rsindex e8e4f721cf..8aa593d427 100644--- a/crates/openhuman-core/src/modules/schemas.rs+++ b/crates/openhuman-core/src/modules/schemas.rs@@ -24,6 +24,7 @@ pub fn all_controller_schemas() -> Vec<ControllerSchema> {schemas("status"),schemas("load"),schemas("browser_check_readiness"),+ schemas("computer_status"),]}@@ -45,6 +46,10 @@ pub fn all_registered_controllers() -> Vec<RegisteredController> {schema: schemas("browser_check_readiness"),handler: handle_browser_check_readiness,},+ RegisteredController {+ schema: schemas("computer_status"),+ handler: handle_computer_status,+ },]}@@ -122,6 +127,23 @@ pub fn schemas(function: &str) -> ControllerSchema {},],},+ "computer_status" => ControllerSchema {+ namespace: "modules",+ function: "computer_status",+ description: "Report the TinyComputer module, its decision and planner routes, and optionally what it says is configured.",+ inputs: vec![FieldSchema {+ name: "load",+ ty: TypeSchema::Option(Box::new(TypeSchema::Bool)),+ comment: "Load the module and ask it (Describe) even when it is not serving yet.",+ required: false,+ }],+ outputs: vec![FieldSchema {+ name: "status",+ ty: TypeSchema::Json,+ comment: "Module status, decision_model, decision_route, planner_route, and capabilities or error.",+ required: true,+ }],+ },_ => ControllerSchema {namespace: "modules",function: "unknown",@@ -175,6 +197,15 @@ fn handle_browser_check_readiness(_params: Map<String, Value>) -> ControllerFutu})}+fn handle_computer_status(params: Map<String, Value>) -> ControllerFuture {+ Box::pin(async move {+ let load = params.get("load").and_then(Value::as_bool).unwrap_or(false);+ let config = config_rpc::load_config_with_timeout().await?;+ Ok(serde_json::to_value(super::computer::status(&config, load).await)+ .map_err(|error| error.to_string())?)+ })+}+fn handle_list(_params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let config = config_rpc::load_config_with_timeout().await?;