Skip to content

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

feat(composio): resolve a host-pinned credential before the credential store

oxoxDev4daf281ec6f2
diff --git a/crates/openhuman-core/src/integrations/composio/client/factory.rs b/crates/openhuman-core/src/integrations/composio/client/factory.rs
index 69fd535e1a..d4f2142a08 100644
--- a/crates/openhuman-core/src/integrations/composio/client/factory.rs
+++ b/crates/openhuman-core/src/integrations/composio/client/factory.rs
@@ -77,6 +77,14 @@ pub enum ComposioClientKind {
pub(crate) fn create_direct_composio_tool_for_api_key(
config: &crate::config::Config,
api_key: &str,
+) -> anyhow::Result<Arc<crate::tools::ComposioTool>> {
+ direct_tool(api_key, config.composio.entity_id.as_str(), None)
+}
+
+fn direct_tool(
+ api_key: &str,
+ entity_id: &str,
+ base_urls: Option<&crate::config::ComposioDirectBaseUrls>,
) -> anyhow::Result<Arc<crate::tools::ComposioTool>> {
let api_key = api_key.trim();
if api_key.is_empty() {
@@ -90,6 +98,16 @@ pub(crate) fn create_direct_composio_tool_for_api_key(
// the `Tool` surface re-acquire the live policy from their own
// context.
let security = Arc::new(crate::security::SecurityPolicy::default());
+ if let Some(urls) = base_urls {
+ let tool = crate::tools::ComposioTool::new_with_base_urls(
+ api_key,
+ Some(entity_id),
+ security,
+ urls.v2.clone(),
+ urls.v3.clone(),
+ )?;
+ return Ok(Arc::new(tool));
+ }
#[cfg(debug_assertions)]
let tool = match (
std::env::var("OPENHUMAN_COMPOSIO_DIRECT_BASE_V2").ok(),
@@ -98,7 +116,7 @@ pub(crate) fn create_direct_composio_tool_for_api_key(
(Some(base_v2), Some(base_v3)) => {
crate::tools::ComposioTool::new_with_base_urls_for_loopback(
api_key,
- Some(config.composio.entity_id.as_str()),
+ Some(entity_id),
security,
base_v2,
base_v3,
@@ -107,18 +125,10 @@ pub(crate) fn create_direct_composio_tool_for_api_key(
anyhow::anyhow!("invalid debug composio direct loopback base override: {e}")
})?
}
- _ => crate::tools::ComposioTool::new(
- api_key,
- Some(config.composio.entity_id.as_str()),
- security,
- ),
+ _ => crate::tools::ComposioTool::new(api_key, Some(entity_id), security),
};
#[cfg(not(debug_assertions))]
- let tool = crate::tools::ComposioTool::new(
- api_key,
- Some(config.composio.entity_id.as_str()),
- security,
- );
+ let tool = crate::tools::ComposioTool::new(api_key, Some(entity_id), security);
Ok(Arc::new(tool))
}
@@ -146,11 +156,20 @@ impl ComposioClientKind {
/// stored key takes precedence so the encrypted keychain remains the
/// source of truth — `config.toml` is a fallback for power users.
///
+/// A host-pinned credential (`config.composio.host_credential`) takes
+/// precedence over both the mode and the credential store.
+///
/// Any other mode string is rejected with an explicit error so a typo
/// in `config.toml` fails loud instead of silently downgrading.
pub fn create_composio_client(
config: &crate::config::Config,
) -> anyhow::Result<ComposioClientKind> {
+ if let Some(pinned) = config.composio.host_credential.as_ref() {
+ let tool = direct_tool(pinned.api_key(), pinned.entity(), pinned.direct_base_urls())?;
+ tracing::debug!("[composio-factory] resolved host-pinned direct variant (key redacted)");
+ return Ok(ComposioClientKind::Direct(tool));
+ }
+
let mode = config.composio.mode.trim();
tracing::debug!(mode = %mode, "[composio-factory] resolving client");
diff --git a/crates/openhuman-core/src/integrations/composio/tools/direct/construction.rs b/crates/openhuman-core/src/integrations/composio/tools/direct/construction.rs
index 9da4c9abd7..46fd9b7891 100644
--- a/crates/openhuman-core/src/integrations/composio/tools/direct/construction.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools/direct/construction.rs
@@ -8,7 +8,6 @@ use crate::security::SecurityPolicy;
use reqwest::Client;
use std::sync::Arc;
-#[cfg(debug_assertions)]
use super::types::is_loopback_http_base;
pub(super) fn normalize_entity_id(entity_id: &str) -> String {
@@ -67,6 +66,33 @@ impl ComposioTool {
))
}
+ /// Construct against explicit v2/v3 API roots. Both must be HTTPS;
+ /// loopback HTTP is accepted only in debug builds.
+ pub fn new_with_base_urls(
+ api_key: &str,
+ default_entity_id: Option<&str>,
+ security: Arc<SecurityPolicy>,
+ base_v2: String,
+ base_v3: String,
+ ) -> anyhow::Result<Self> {
+ let allow_loopback = cfg!(debug_assertions);
+ for base in [&base_v2, &base_v3] {
+ let accepted =
+ base.starts_with("https://") || (allow_loopback && is_loopback_http_base(base));
+ if !accepted {
+ anyhow::bail!("Composio base URL must be HTTPS");
+ }
+ }
+ Ok(Self::new_internal(
+ api_key,
+ default_entity_id,
+ security,
+ base_v2,
+ base_v3,
+ allow_loopback,
+ ))
+ }
+
/// Test-only seam: construct with an explicit Composio v3 base URL so
/// unit tests can point the direct `/tools` request — including the
/// `tags` filter — at a local mock instead of `backend.composio.dev`.
diff --git a/crates/openhuman-core/src/integrations/composio/tools/direct/types.rs b/crates/openhuman-core/src/integrations/composio/tools/direct/types.rs
index d4bb4d99f9..e6a33e4e81 100644
--- a/crates/openhuman-core/src/integrations/composio/tools/direct/types.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools/direct/types.rs
@@ -40,7 +40,6 @@ pub(super) fn is_loopback_http_url(url: &str) -> bool {
}
}
-#[cfg(debug_assertions)]
pub(super) fn is_loopback_http_base(url: &str) -> bool {
is_loopback_http_url(&format!("{}/", url.trim_end_matches('/')))
}