Skip to content

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

refactor(composio): extract flow backend dispatch into a reusable helper

Steven Enamakel6e099f643078
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs b/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs
index e4310c6b21..97fa173943 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs
@@ -53,6 +53,3 @@ impl ToolBackend for ComposioToolBackend {
}
}
-#[cfg(test)]
-#[path = "composio_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/integrations/composio/flow_backend.rs b/crates/openhuman-core/src/integrations/composio/flow_backend.rs
index aa3673ae9e..060be44e5c 100644
--- a/crates/openhuman-core/src/integrations/composio/flow_backend.rs
+++ b/crates/openhuman-core/src/integrations/composio/flow_backend.rs
@@ -7,6 +7,25 @@ use serde_json::Value;
use crate::{config::Config, core::runtime::DispatchCtx, security::{GateDecision, SecurityPolicy}};
use crate::security::approval::ApprovalTurnContext;
+pub(crate) async fn execute_for_connection(
+ config: &Config,
+ slug: &str,
+ args: Option<Value>,
+ connection_id: Option<&str>,
+) -> Result<crate::integrations::composio::ComposioExecuteResponse, String> {
+ crate::integrations::composio::module_client::call::<_, crate::integrations::composio::ComposioExecuteResponse>(
+ config,
+ tinyconnectors_bus::names::methods::EXECUTE,
+ crate::integrations::composio::types::ComposioExecuteRequest {
+ tool: slug.to_string(),
+ arguments: args,
+ connection_id: connection_id.map(str::to_string),
+ },
+ )
+ .await
+ .map_err(|error| error.to_string())
+}
+
#[async_trait]
pub(crate) trait FlowCallPolicy: Send + Sync {
async fn tier_decision(
@@ -64,15 +83,8 @@ pub(crate) async fn invoke(
};
let connection_id = crate::integrations::composio::flow_gate::composio_connection_id(conn);
- let response = crate::integrations::composio::module_client::call::<_, crate::integrations::composio::ComposioExecuteResponse>(
- &live,
- tinyconnectors_bus::names::methods::EXECUTE,
- crate::integrations::composio::types::ComposioExecuteRequest {
- tool: slug.to_string(),
- arguments: (!args.is_null()).then_some(args),
- connection_id: connection_id.map(str::to_string),
- },
- ).await.map_err(|error| error.to_string())
+ let response = execute_for_connection(&live, slug, (!args.is_null()).then_some(args), connection_id)
+ .await
.and_then(|result| crate::integrations::composio::flow_gate::reject_unsuccessful_composio_response(slug, result).map_err(|error| error.to_string()))
.and_then(|result| serde_json::to_value(result).map_err(|error| error.to_string()));
if let Some(audit_id) = audit_id { ctx.policy.record(&audit_id, &response); }
@@ -82,3 +94,7 @@ pub(crate) async fn invoke(
fn policy_refresh_error() -> String {
format!("{} flows autonomy and Composio settings could not be refreshed; refusing the node", tinytools::status::POLICY_BLOCKED_MARKER)
}
+
+#[cfg(test)]
+#[path = "flow_backend_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio_tests.rs b/crates/openhuman-core/src/integrations/composio/flow_backend_tests.rs
similarity index 96%
rename from crates/openhuman-core/src/flows/tinyflows/caps/tools/composio_tests.rs
rename to crates/openhuman-core/src/integrations/composio/flow_backend_tests.rs
index 96c079e84c..a50aad8448 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/flow_backend_tests.rs
@@ -1,8 +1,9 @@
use axum::{routing::post, Json, Router};
use serde_json::{json, Value};
-use super::*;
use crate::integrations::composio::module_client::module_guard;
+use crate::integrations::composio::flow_backend::execute_for_connection;
+use crate::config::Config;
/// Regression for #5751: the flow adapter used to parse and log the chosen
/// account, then call `execute_tool` without it. The request therefore ran
diff --git a/crates/openhuman-core/src/integrations/composio/mod.rs b/crates/openhuman-core/src/integrations/composio/mod.rs
index 6845a3ca67..f1b0f11a4a 100644
--- a/crates/openhuman-core/src/integrations/composio/mod.rs
+++ b/crates/openhuman-core/src/integrations/composio/mod.rs
@@ -50,6 +50,7 @@ pub mod execute_dispatch;
pub(crate) mod file_store;
mod file_store_documents;
pub mod flow_gate;
+pub(crate) mod flow_backend;
pub mod googlecalendar_args;
pub mod identity;
pub mod identity_store;