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
fix(composio): restructure direct tool integration modules
Steven Enamakel50eec1abffad
diff --git a/crates/openhuman-core/src/integrations/composio/client/direct.rs b/crates/openhuman-core/src/integrations/composio/client/direct.rsindex dec7853cf1..6f72daf6e3 100644--- a/crates/openhuman-core/src/integrations/composio/client/direct.rs+++ b/crates/openhuman-core/src/integrations/composio/client/direct.rs@@ -1,6 +1,6 @@//! Direct-mode response reshapers: `direct_list_connections`, and `direct_list_tools`. Mirror the//! backend-proxied [`super::connections::ComposioClient`] methods but call-//! Composio's v3 API directly (via a bound [`crate::tools::ComposioTool`])+//! Composio's v3 API directly (via a bound [`crate::tools::DirectComposioClient`])//! and reshape the v3 response into the same envelope types, so downstream//! callers in `ops.rs` / `tools.rs` don't have to branch on mode.@@ -12,7 +12,7 @@ use super::super::types::{ComposioConnection, ComposioConnectionsResponse, Compo/// Direct-mode counterpart to [`ComposioClient::list_connections`].////// Calls Composio v3 `/connected_accounts` (via-/// [`crate::tools::ComposioTool::list_connected_accounts`])+/// [`crate::tools::DirectComposioClient::list_connected_accounts`])/// and maps each item to the canonical [`ComposioConnection`] so the/// existing frontend type contract and the 5 s UI poll keep working/// unchanged.@@ -24,7 +24,7 @@ use super::super::types::{ComposioConnection, ComposioConnectionsResponse, Compo/// so a malformed row will simply not be presented as connected — the/// fail-safe shape the user expects.pub async fn direct_list_connections(- direct: &Arc<crate::tools::ComposioTool>,+ direct: &Arc<crate::tools::DirectComposioClient>,) -> anyhow::Result<ComposioConnectionsResponse> {tracing::debug!("[composio-direct] list_connections: GET v3 /connected_accounts");let key_id = direct.auth_key_fingerprint();@@ -97,7 +97,7 @@ pub async fn direct_list_connections(/// Direct-mode counterpart to [`ComposioClient::list_tools`]. Calls/// Composio v3 `/tools?toolkits=<csv>&tags=<a>&tags=<b>` via-/// [`crate::tools::ComposioTool::list_tool_schemas_v3`] and+/// [`crate::tools::DirectComposioClient::list_tool_schemas_v3`] and/// reshapes each item into the same [`ComposioToolSchema`] envelope the/// backend-proxied path returns.///@@ -126,7 +126,7 @@ pub async fn direct_list_connections(/// which this function never applies itself; the filter is layered on by/// its `composio_list_tools` caller, not baked in here.pub(crate) async fn direct_list_tools(- direct: &Arc<crate::tools::ComposioTool>,+ direct: &Arc<crate::tools::DirectComposioClient>,toolkits: &[String],tags: Option<&[String]>,) -> anyhow::Result<ComposioToolsResponse> {diff --git a/crates/openhuman-core/src/integrations/composio/tools.rs b/crates/openhuman-core/src/integrations/composio/tools.rsindex 0601365222..d41b4758e3 100644--- a/crates/openhuman-core/src/integrations/composio/tools.rs+++ b/crates/openhuman-core/src/integrations/composio/tools.rs@@ -43,7 +43,7 @@ mod visibility;#[path = "tools_tests.rs"]mod tests;-pub use direct::{ComposioAction, ComposioConnectedAccount, ComposioTool};+pub use direct::{ComposioConnectedAccount, DirectComposioClient};pub use execute::ComposioExecuteTool;pub(crate) use live_config::live_composio_config;pub(crate) use redact::redact_composio_outcome;diff --git a/crates/openhuman-core/src/integrations/composio/tools/direct.rs b/crates/openhuman-core/src/integrations/composio/tools/direct.rsindex 208897da68..ada78235eb 100644--- a/crates/openhuman-core/src/integrations/composio/tools/direct.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/direct.rs@@ -1,10 +1,10 @@-// Composio Tool Provider — optional managed tool surface with 1000+ OAuth integrations.+// Slim host-side HTTP reader for Composio's own v3 API with the user's key.//-// When enabled, OpenHuman can execute actions on Gmail, Notion, GitHub, Slack, etc.-// through Composio's API without storing raw OAuth tokens locally.-//-// This is opt-in. Users who prefer sovereign/local-only mode skip this entirely.-// The Composio API key is stored in the encrypted secret store.+// Composio execution, the OAuth handoff and connection management all run in+// the `tinyconnectors` module (see `module_client`). What remains here are the+// two direct-mode reads whose request parameters the pinned module route does+// not carry: `/connected_accounts?limit=200` and `/tools` with+// `toolkit_versions=latest` (#3932).#[cfg(test)]#[path = "direct_tests.rs"]@@ -13,31 +13,17 @@ mod tests;mod connections;mod construction;mod discovery;-mod execution;mod http_errors;-mod tool_impl;mod types;pub use connections::ComposioConnectedAccount;-pub use discovery::ComposioAction;-pub use types::ComposioTool;+pub use types::DirectComposioClient;-// Test-only bridges: the flat `direct_tests.rs` module (kept as a rename-only-// group per the unsplit policy) still expects these internal helpers to be-// reachable unqualified via `use super::*`, mirroring the single-scope shape-// `include!` gave it before the split into responsibility-based submodules.-#[cfg(test)]-use connections::ComposioAuthConfig;-#[cfg(test)]-use construction::normalize_entity_id;-#[cfg(test)]-use discovery::{- map_v3_tools_to_actions, ComposioActionsResponse, ComposioToolkitRef, ComposioToolsResponse,- ComposioV3Tool,-};+// Test-only bridges: the flat `direct_tests.rs` module still expects these+// internal helpers to be reachable unqualified via `use super::*`.#[cfg(test)]-use http_errors::{extract_api_error_message, extract_redirect_url, sanitize_error_message};+use discovery::{ComposioToolkitRef, ComposioToolsResponse, ComposioV3Tool};#[cfg(test)]-use tinytools::Tool;+use http_errors::{extract_api_error_message, sanitize_error_message};#[cfg(test)]use types::{ensure_https, is_loopback_http_url, COMPOSIO_API_BASE_V3};diff --git a/crates/openhuman-core/src/integrations/composio/tools/direct/discovery.rs b/crates/openhuman-core/src/integrations/composio/tools/direct/discovery.rsindex 7a0d285f2c..86f200f5c1 100644--- a/crates/openhuman-core/src/integrations/composio/tools/direct/discovery.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/direct/discovery.rs@@ -1,84 +1,13 @@-//! Action/tool listing: `list_actions` (legacy flattened shape, v3-with-v2-fallback)-//! and `list_tool_schemas_v3` (full v3 schema, used by direct-mode-//! `composio_list_tools`), plus the wire types they decode into.+//! Tool-schema listing for the direct route: `list_tool_schemas_v3` (the full+//! v3 schema, used by the direct-mode tool catalog) plus the wire types it+//! decodes into.use super::http_errors::response_error;-use super::types::ComposioTool;+use super::types::DirectComposioClient;use anyhow::Context;-use serde::{Deserialize, Serialize};--impl ComposioTool {- /// List available Composio apps/actions for the authenticated user.- ///- /// Uses v3 endpoint first and falls back to v2 for compatibility.- pub async fn list_actions(- &self,- app_name: Option<&str>,- ) -> anyhow::Result<Vec<ComposioAction>> {- match self.list_actions_v3(app_name).await {- Ok(items) => Ok(items),- Err(v3_err) => {- let v2 = self.list_actions_v2(app_name).await;- match v2 {- Ok(items) => Ok(items),- Err(v2_err) => anyhow::bail!(- "Composio action listing failed on v3 ({v3_err}) and v2 fallback ({v2_err})"- ),- }- }- }- }-- async fn list_actions_v3(&self, app_name: Option<&str>) -> anyhow::Result<Vec<ComposioAction>> {- let url = format!("{}/tools", self.base_v3);- let mut req = self.client().get(&url).header("x-api-key", &self.api_key);-- // #3932: pin toolkit_versions=latest. Composio v3 otherwise defaults to- // the 00000000_00 snapshot, which lists zero tools for any toolkit- // published after it (Outlook and every other post-launch toolkit).- req = req.query(&[("limit", "200"), ("toolkit_versions", "latest")]);- if let Some(app) = app_name.map(str::trim).filter(|app| !app.is_empty()) {- req = req.query(&[("toolkits", app), ("toolkit_slug", app)]);- }-- let resp = req.send().await?;- if !resp.status().is_success() {- let err = response_error(resp).await;- anyhow::bail!("Composio v3 API error: {err}");- }-- let body: ComposioToolsResponse = resp- .json()- .await- .context("Failed to decode Composio v3 tools response")?;- Ok(map_v3_tools_to_actions(body.items))- }-- async fn list_actions_v2(&self, app_name: Option<&str>) -> anyhow::Result<Vec<ComposioAction>> {- let mut url = format!("{}/actions", self.base_v2);- if let Some(app) = app_name {- url = format!("{url}?appNames={app}");- }-- let resp = self- .client()- .get(&url)- .header("x-api-key", &self.api_key)- .send()- .await?;-- if !resp.status().is_success() {- let err = response_error(resp).await;- anyhow::bail!("Composio v2 API error: {err}");- }-- let body: ComposioActionsResponse = resp- .json()- .await- .context("Failed to decode Composio v2 actions response")?;- Ok(body.items)- }+use serde::Deserialize;+impl DirectComposioClient {/// Build the query-parameter pairs for the Composio v3 `GET /tools`/// listing used by [`Self::list_tool_schemas_v3`].///@@ -181,33 +110,8 @@ impl ComposioTool {.collect())}}--pub(super) fn map_v3_tools_to_actions(items: Vec<ComposioV3Tool>) -> Vec<ComposioAction> {- items- .into_iter()- .filter_map(|item| {- let name = item.slug.or(item.name.clone())?;- let app_name = item- .toolkit- .as_ref()- .and_then(|toolkit| toolkit.slug.clone().or(toolkit.name.clone()))- .or(item.app_name);- let description = item.description.or(item.name);- Some(ComposioAction {- name,- app_name,- description,- enabled: true,- })- })- .collect()}-#[derive(Debug, Deserialize)]-pub(super) struct ComposioActionsResponse {- #[serde(default)]- pub(super) items: Vec<ComposioAction>,-}#[derive(Debug, Deserialize)]pub(super) struct ComposioToolsResponse {@@ -253,16 +157,6 @@ pub(super) struct ComposioToolkitRef {pub(super) name: Option<String>,}-#[derive(Debug, Clone, Serialize, Deserialize)]-pub struct ComposioAction {- pub name: String,- #[serde(rename = "appName")]- pub app_name: Option<String>,- pub description: Option<String>,- #[serde(default)]- pub enabled: bool,-}-/// Direct-mode tool definition lifted from Composio v3 `/tools`.////// Carries the `input_parameters` JSON schema so the upstreamdiff --git a/crates/openhuman-core/src/integrations/composio/tools/direct/http_errors.rs b/crates/openhuman-core/src/integrations/composio/tools/direct/http_errors.rsindex 9ba0e007e8..fb0e935250 100644--- a/crates/openhuman-core/src/integrations/composio/tools/direct/http_errors.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/direct/http_errors.rs@@ -1,6 +1,5 @@-//! Response-parsing helpers shared by every Composio HTTP call path:-//! turning a failed `reqwest::Response` into a redacted error string, and-//! pulling a redirect URL out of a connect-flow JSON body.+//! Response-parsing helper shared by every direct Composio HTTP call path:+//! turning a failed `reqwest::Response` into a redacted error string.pub(super) async fn response_error(resp: reqwest::Response) -> String {let status = resp.status();@@ -50,17 +49,3 @@ pub(super) fn extract_api_error_message(body: &str) -> Option<String> {.map(ToString::to_string)})}--pub(super) fn extract_redirect_url(result: &serde_json::Value) -> Option<String> {- result- .get("redirect_url")- .and_then(|v| v.as_str())- .or_else(|| result.get("redirectUrl").and_then(|v| v.as_str()))- .or_else(|| {- result- .get("data")- .and_then(|v| v.get("redirect_url"))- .and_then(|v| v.as_str())- })- .map(ToString::to_string)-}