Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(modules): load linked modules from the host executable

Steven Enamakele803566a4ec7
diff --git a/crates/openhuman-core/src/modules/ops.rs b/crates/openhuman-core/src/modules/ops.rs
index b95390e897..b1156858a7 100644
--- a/crates/openhuman-core/src/modules/ops.rs
+++ b/crates/openhuman-core/src/modules/ops.rs
@@ -304,10 +304,8 @@ async fn resolve(config: &Config, record: &'static ModuleRecord) -> Result<(), S
}
}
ModuleSource::Linked => {
- return Err(mark_terminal(format!(
- "module '{}' is unavailable: its linked factory could not be started",
- record.id
- )));
+ let module_config = module_config(config, record.id);
+ return blocking(move || load_linked(runtime, record.id, module_config)).await;
}
ModuleSource::Release => {}
}
@@ -451,6 +449,39 @@ pub(super) fn load_local(
}
}
+/// Attach the module linked into this executable for `id`.
+///
+/// Runs the same descriptor, manifest, dependency and init checks as a
+/// released module, with the same private configuration; the executable's
+/// digest is the attestation. Errors carry static text only.
+pub(super) fn load_linked(
+ runtime: &host::ModuleRuntime,
+ id: &str,
+ module_config: serde_json::Value,
+) -> Result<(), String> {
+ let Some(factory) = super::linked::factory_for(id) else {
+ return Err(format!(
+ "module '{id}' is unavailable: no linked factory is registered in this binary"
+ ));
+ };
+ let module = factory().map_err(|err| {
+ log::warn!("[modules] linked factory for '{id}' failed: {err}");
+ format!("module '{id}' is unavailable: its linked factory could not be started")
+ })?;
+ match runtime
+ .host()
+ .attach_linked_with_config(module, module_config)
+ {
+ Ok(_) => {
+ log::info!("[modules] loaded '{id}' from the linked executable");
+ Ok(())
+ }
+ Err(err) => Err(format!(
+ "module '{id}' could not be attached from the linked executable: {err}"
+ )),
+ }
+}
+
/// Configuration crossing into a first-party compiled module.
///
/// Credentials are intentionally absent. TinyMemory calls back into the host
diff --git a/crates/openhuman-embed/src/modules.rs b/crates/openhuman-embed/src/modules.rs
index 7a2cd09edb..48ea8ce854 100644
--- a/crates/openhuman-embed/src/modules.rs
+++ b/crates/openhuman-embed/src/modules.rs
@@ -6,6 +6,12 @@
#[cfg(feature = "modules")]
pub use openhuman_core::modules::ops::set_bundled_releases_dir;
+/// Register the in-process factory for a module linked into the host
+/// executable. Local-development builds only: `openhuman-modules-linked` calls
+/// this for each module it links; no shipped host does.
+#[cfg(feature = "modules")]
+pub use openhuman_core::modules::linked::{register_linked, LinkedFactory};
+
/// The browser-control module.
#[cfg(feature = "modules")]
pub mod browser {