Skip to content

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

refactor(composio): move flow connection picker behind a provider trait

Steven Enamakel9645376ff9c9
diff --git a/crates/openhuman-core/src/flows/builder_tools_connection_reads.rs b/crates/openhuman-core/src/flows/builder_tools_connection_reads.rs
index e25f94e5c8..7fc3603643 100644
--- a/crates/openhuman-core/src/flows/builder_tools_connection_reads.rs
+++ b/crates/openhuman-core/src/flows/builder_tools_connection_reads.rs
@@ -1,96 +1,27 @@
-//! Mixed Composio/HTTP connection picker adapter owned by flows.
+//! Flow-owned composition provider for the mixed Composio/HTTP connection picker.
-use std::sync::Arc;
use async_trait::async_trait;
-use serde_json::{json, Value};
-use crate::config::Config;
-use crate::flows::ops;
-use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolResult, ToolRunContext};
+use serde_json::Value;
-// ─────────────────────────────────────────────────────────────────────────────
-// list_flow_connections — read-only: connection refs (ids/names only)
-// ─────────────────────────────────────────────────────────────────────────────
-
-/// `list_flow_connections`: read-only enumeration of the connection sources a
-/// node's `connection_ref` can attach to (Composio connected accounts +
-/// named HTTP credentials) — non-secret metadata only (ids / display labels
-/// / kind / toolkit / scheme / platform_user_id), never secrets.
-pub struct ListFlowConnectionsTool {
- config: Arc<Config>,
-}
-
-impl ListFlowConnectionsTool {
- pub fn new(config: Arc<Config>) -> Self {
- Self { config }
- }
-}
+pub(crate) struct FlowsConnectionProvider;
#[async_trait]
-impl Tool for ListFlowConnectionsTool {
- fn name(&self) -> &str {
- "list_flow_connections"
- }
-
- fn description(&self) -> &str {
- "List the connection sources a flow node's `connection_ref` can attach to: \
- Composio connected accounts and named HTTP credentials. Read-only; \
- returns only non-secret metadata — ids, display labels, kind, and \
- `toolkit`/`scheme` (never any secret). Each \
- Composio entry also carries `platform_user_id` — the connected \
- account's own member id (e.g. Slack `U123ABC`) — use it to wire a \
- self-targeted action like 'DM me' to that account instead of a \
- public channel. Use the `connection_ref` values verbatim on \
- tool_call / http_request nodes so the generated flow carries valid \
- connections."
- }
-
- fn parameters_schema(&self) -> Value {
- json!({ "type": "object", "properties": {}, "additionalProperties": false })
- }
-
- fn permission_level(&self) -> PermissionLevel {
- PermissionLevel::None
- }
-
- fn external_effect(&self) -> bool {
- false
- }
-
- async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
- self.execute_with_context(args, ToolCallOptions::default(), None)
- .await
- }
-
- async fn execute_with_context(
+impl crate::integrations::composio::builder_tools::FlowConnectionProvider
+ for FlowsConnectionProvider
+{
+ async fn list(
&self,
- _args: Value,
- _options: ToolCallOptions,
- tool_context: Option<&dyn ToolRunContext>,
- ) -> anyhow::Result<ToolResult> {
- let ctx = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context);
- tracing::debug!(target: "flows", "[flows] list_flow_connections: enumerating connection refs (read-only)");
- match crate::flows::ops::flows_list_connections(&ctx, &self.config).await {
- Ok(outcome) => {
- let conns: Vec<Value> = outcome.value.iter().map(flow_connection_to_json).collect();
- Ok(ToolResult::success(serde_json::to_string_pretty(
- &json!({ "connections": conns }),
- )?))
- }
- Err(e) => Ok(ToolResult::error(format!(
- "Failed to list flow connections: {e}"
- ))),
- }
+ dispatch: &crate::core::runtime::DispatchCtx,
+ config: &crate::config::Config,
+ ) -> Result<Vec<Value>, String> {
+ let outcome = crate::flows::ops::flows_list_connections(dispatch, config).await?;
+ Ok(outcome.value.iter().map(flow_connection_to_json).collect())
}
}
-/// Render one [`tinyflows_catalog::types::FlowConnection`] as the
-/// picker JSON shape the agent reads — ids/display/kind/toolkit/scheme plus
-/// `platform_user_id` (the connected account's own member id, e.g. Slack
-/// `U123ABC`, or `null` when no identity has synced yet). Never secret
-/// material. A free function (rather than inline in `execute`) so the
-/// mapping is unit-testable without a live Composio backend.
+/// Render a non-secret connection summary for the agent-facing picker.
pub(crate) fn flow_connection_to_json(c: &tinyflows_catalog::types::FlowConnection) -> Value {
- json!({
+ serde_json::json!({
"connection_ref": c.connection_ref,
"kind": c.kind,
"display": c.display,
diff --git a/crates/openhuman-core/src/integrations/composio/builder_tools/connection_reads.rs b/crates/openhuman-core/src/integrations/composio/builder_tools/connection_reads.rs
index 74693040c5..c0d5d12feb 100644
--- a/crates/openhuman-core/src/integrations/composio/builder_tools/connection_reads.rs
+++ b/crates/openhuman-core/src/integrations/composio/builder_tools/connection_reads.rs
@@ -8,6 +8,16 @@ use serde_json::{json, Value};
use crate::config::Config;
use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolResult, ToolRunContext};
+/// Host supplied source for the flow editor's mixed connection picker.
+#[async_trait]
+pub trait FlowConnectionProvider: Send + Sync {
+ async fn list(
+ &self,
+ dispatch: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ ) -> Result<Vec<Value>, String>;
+}
+
/// `list_connectable_toolkits`: read-only list of the Composio toolkits the
/// builder can wire, each tagged connected/unconnected — so the agent can steer
/// toolkit choice toward what's already connected (audit Phase 5, item 19).
@@ -15,6 +25,46 @@ pub struct ListConnectableToolkitsTool {
config: Arc<Config>,
}
+/// Read-only mixed connection picker backed by a host supplied provider.
+pub struct ListFlowConnectionsTool {
+ config: Arc<Config>,
+ provider: Arc<dyn FlowConnectionProvider>,
+}
+
+impl ListFlowConnectionsTool {
+ pub fn new(config: Arc<Config>, provider: Arc<dyn FlowConnectionProvider>) -> Self {
+ Self { config, provider }
+ }
+}
+
+#[async_trait]
+impl Tool for ListFlowConnectionsTool {
+ fn name(&self) -> &str { "list_flow_connections" }
+ fn description(&self) -> &str {
+ "List the connection sources a flow node's `connection_ref` can attach to. Read-only; returns non-secret metadata only."
+ }
+ fn parameters_schema(&self) -> Value {
+ json!({ "type": "object", "properties": {}, "additionalProperties": false })
+ }
+ fn permission_level(&self) -> PermissionLevel { PermissionLevel::None }
+ fn external_effect(&self) -> bool { false }
+ async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ self.execute_with_context(args, ToolCallOptions::default(), None).await
+ }
+ async fn execute_with_context(
+ &self,
+ _args: Value,
+ _options: ToolCallOptions,
+ tool_context: Option<&dyn ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let dispatch = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context);
+ match self.provider.list(&dispatch, &self.config).await {
+ Ok(connections) => Ok(ToolResult::success(serde_json::to_string_pretty(&json!({ "connections": connections }))?)),
+ Err(error) => Ok(ToolResult::error(format!("Failed to list flow connections: {error}"))),
+ }
+ }
+}
+
impl ListConnectableToolkitsTool {
pub fn new(config: Arc<Config>) -> Self {
Self { config }