Skip to content

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

feat(caps_host): add within helper to re-enter request context

Steven Enamakelea0f417e9c04
diff --git a/crates/openhuman-core/src/flows/caps_host/binding.rs b/crates/openhuman-core/src/flows/caps_host/binding.rs
index a84c1c3ac6..a6dd560eb2 100644
--- a/crates/openhuman-core/src/flows/caps_host/binding.rs
+++ b/crates/openhuman-core/src/flows/caps_host/binding.rs
@@ -1,6 +1,7 @@
//! One trusted `CapsHost` callback object for a single TinyFlows run.
use std::{collections::HashMap, sync::Arc};
+use std::future::Future;
use crate::config::Config;
use crate::core::runtime::DispatchCtx;
@@ -31,6 +32,21 @@ pub(crate) struct CapsHostBinding {
tokio::sync::Mutex<HashMap<String, Arc<tokio::sync::Mutex<AgentRunState>>>>,
}
+impl CapsHostBinding {
+ /// Re-enter the request's captured tenant, identity and turn origin for a
+ /// bus callback that runs on the module runtime.
+ pub(crate) async fn within<F: Future>(&self, future: F) -> F::Output {
+ match self.ctx.core() {
+ Some(context) => crate::core::runtime::CoreContext::scope(
+ Arc::clone(context),
+ future,
+ )
+ .await,
+ None => future.await,
+ }
+ }
+}
+
impl CapsHostRegistration {
/// Address to pass unchanged to `Runs.StartRun` or `Runs.ResumeRun`.
pub(crate) fn address(&self) -> CapsHost {