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(tinyflows): extract caps host manifest handling into its own module
Steven Enamakelcc3774b96161
diff --git a/crates/openhuman-core/src/modules/tinyflows.rs b/crates/openhuman-core/src/modules/tinyflows.rsindex ed15054a42..e0cddd523a 100644--- a/crates/openhuman-core/src/modules/tinyflows.rs+++ b/crates/openhuman-core/src/modules/tinyflows.rs@@ -23,6 +23,10 @@use crate::config::Config;+#[cfg(feature = "modules")]+#[path = "tinyflows_caps_manifest.rs"]+mod caps_manifest;+/// Registry id of the module these calls go to.pub(crate) const MODULE_ID: &str = "tinyflows";@@ -58,7 +62,7 @@ mod imp {#[cfg(not(test))]use crate::modules::ops;use crate::modules::runtime;- use tinybus::{InterfaceName, InterfaceVersion, ObjectPath, PeerManifest, Proxy, Version};+ use tinybus::{ObjectPath, Proxy};use tinyflows_bus::schedule;/// Longest a store or maths call waits. Job execution is not a call to the@@ -70,10 +74,6 @@ mod imp {/// (an agent turn, a shell command) inside the call.const RUN_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(2 * 60 * 60);- /// Serialize CapsHost manifest read-modify-announce operations on the- /// process-wide module-runtime peer.- static CAPS_HOST_MANIFEST_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());-/// Make sure the module serves. In unit tests this attaches the linked/// module built into the test binary; everywhere else it goes through the/// registry resolver (release, `source` or `linked` per configuration).@@ -269,15 +269,7 @@ mod imp {path: String,object: impl tinybus::service::Interface + 'static,) -> Result<ServedObjectRegistration, String> {- let object_interface = tinybus::service::Interface::name(&object);- let announces_caps_host = object_interface.as_str() == tinyflows_bus::runs::CAPS_INTERFACE;- if announces_caps_host {- let cancel_member = tinybus::MemberName::new(tinyflows_bus::runs::caps::AGENT_CANCEL)- .map_err(|error| error.to_string())?;- if !tinybus::service::Interface::members(&object).contains(&cancel_member) {- return Err("CapsHost v2 object does not expose AgentCancel".to_owned());- }- }+ let announces_caps_host = super::caps_manifest::is_caps_host_v2(&object)?;let runtime = runtime::runtime().await.map_err(|error| format!("the module bus is unavailable: {error}"))?;@@ -293,7 +285,8 @@ mod imp {.serve_at(object_path.clone(), object).await.map_err(|error| error.to_string())?;- if announces_caps_host && let Err(error) = announce_caps_host_v2(&connection).await+ if announces_caps_host+ && let Err(error) = super::caps_manifest::announce_caps_host_v2(&connection).await{let _ = connection.unserve(&object_path).await;return Err(error);@@ -304,31 +297,6 @@ mod imp {.map_err(|error| format!("serving the host object did not finish: {error}"))?}- async fn announce_caps_host_v2(connection: &tinybus::Connection) -> Result<(), String> {- let _lock = CAPS_HOST_MANIFEST_LOCK.lock().await;- let interface = InterfaceName::new(tinyflows_bus::runs::CAPS_INTERFACE)- .map_err(|error| error.to_string())?;- let mut manifest = connection- .manifest_of(HOST_BUS_NAME)- .await- .map_err(|error| error.to_string())?- .unwrap_or_else(|| PeerManifest::new("openhuman-module-host"));- let caps_host = InterfaceVersion::provided(interface.clone(), Version::new(2, 0, 0));- if let Some(provided) = manifest- .provides- .iter_mut()- .find(|provided| provided.interface == interface)- {- *provided = caps_host;- } else {- manifest.provides.push(caps_host);- }- connection- .announce(&manifest)- .await- .map_err(|error| format!("announcing the CapsHost v2 contract failed: {error}"))- }-/// Serve two interfaces at one object path and return an RAII token for/// their shared registration. The token is created on the module runtime/// task, so if the caller is cancelled while this operation is in flight,diff --git a/crates/openhuman-core/src/modules/tinyflows_caps_manifest.rs b/crates/openhuman-core/src/modules/tinyflows_caps_manifest.rsnew file mode 100644index 0000000000..f322059ac7--- /dev/null+++ b/crates/openhuman-core/src/modules/tinyflows_caps_manifest.rs@@ -0,0 +1,49 @@+//! CapsHost peer-manifest compatibility for callbacks served to TinyFlows.++use tinybus::{InterfaceName, InterfaceVersion, PeerManifest, Version};++/// Whether `object` is a valid v2 CapsHost service object.+pub(super) fn is_caps_host_v2(+ object: &impl tinybus::service::Interface,+) -> Result<bool, String> {+ let interface = tinybus::service::Interface::name(object);+ if interface.as_str() != tinyflows_bus::runs::CAPS_INTERFACE {+ return Ok(false);+ }+ let cancel_member = tinybus::MemberName::new(tinyflows_bus::runs::caps::AGENT_CANCEL)+ .map_err(|error| error.to_string())?;+ if !tinybus::service::Interface::members(object).contains(&cancel_member) {+ return Err("CapsHost v2 object does not expose AgentCancel".to_owned());+ }+ Ok(true)+}++/// Add CapsHost v2 to the existing peer manifest without dropping its other+/// identities, interfaces, or required contracts.+pub(super) async fn announce_caps_host_v2(+ connection: &tinybus::Connection,+) -> Result<(), String> {+ static MANIFEST_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());+ let _lock = MANIFEST_LOCK.lock().await;+ let interface = InterfaceName::new(tinyflows_bus::runs::CAPS_INTERFACE)+ .map_err(|error| error.to_string())?;+ let mut manifest = connection+ .manifest_of(crate::modules::tinyflows::HOST_BUS_NAME)+ .await+ .map_err(|error| error.to_string())?+ .unwrap_or_else(|| PeerManifest::new("openhuman-module-host"));+ let caps_host = InterfaceVersion::provided(interface.clone(), Version::new(2, 0, 0));+ if let Some(provided) = manifest+ .provides+ .iter_mut()+ .find(|provided| provided.interface == interface)+ {+ *provided = caps_host;+ } else {+ manifest.provides.push(caps_host);+ }+ connection+ .announce(&manifest)+ .await+ .map_err(|error| format!("announcing the CapsHost v2 contract failed: {error}"))+}