Skip to content

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

feat(connections): add connection management operations

Steven Enamakel02da77595f80
diff --git a/crates/openhuman-core/src/flows/ops/connections.rs b/crates/openhuman-core/src/flows/ops/connections.rs
index 6bd0e95856..875cfdd04f 100644
--- a/crates/openhuman-core/src/flows/ops/connections.rs
+++ b/crates/openhuman-core/src/flows/ops/connections.rs
@@ -88,7 +88,8 @@ pub async fn flows_list_connections(
count = identities.len(),
"[flows] flows_list_connections: identity-cache load"
);
- let connections = build_flow_connections(composio_conns, http_creds, &identities);
+ let keys = normalize_keys(config, &composio_conns, &identities).await;
+ let connections = build_flow_connections(composio_conns, http_creds, &identities, &keys);
tracing::debug!(
total = connections.len(),
"[flows] flows_list_connections: aggregated picker sources"
@@ -100,6 +101,41 @@ pub async fn flows_list_connections(
Ok(Outcome::new(connections, logs))
}
+/// Normalise every connection key `build_flow_connections` matches on, in one
+/// connector-module call. Returns an empty map when the module is unavailable;
+/// the picker then lists connections without a `platform_user_id`.
+async fn normalize_keys(
+ config: &Config,
+ composio: &[crate::integrations::composio::ComposioConnection],
+ identities: &[crate::integrations::composio::contract::ConnectedIdentity],
+) -> std::collections::HashMap<String, String> {
+ let mut raw: Vec<String> = identities
+ .iter()
+ .flat_map(|id| [id.source.clone(), id.identifier.clone()])
+ .collect();
+ for conn in composio {
+ raw.push(conn.normalized_toolkit());
+ raw.push(conn.id.clone());
+ }
+ raw.sort();
+ raw.dedup();
+ if identities.is_empty() {
+ return std::collections::HashMap::new();
+ }
+ match crate::integrations::composio::contract::normalize_connection_identifiers(config, &raw)
+ .await
+ {
+ Ok(normalized) if normalized.len() == raw.len() => raw.into_iter().zip(normalized).collect(),
+ other => {
+ tracing::debug!(
+ error = ?other.err(),
+ "[flows] flows_list_connections: key normalisation unavailable"
+ );
+ std::collections::HashMap::new()
+ }
+ }
+}
+
/// Fold Composio connected accounts + named HTTP credentials into the flat,
/// secret-free [`FlowConnection`] picker list. Only ACTIVE Composio connections
/// are surfaced — a pending/expired OAuth account cannot execute a tool, so it
@@ -118,8 +154,12 @@ pub(super) fn build_flow_connections(
composio: Vec<crate::integrations::composio::ComposioConnection>,
http: Vec<crate::security::credentials::HttpCredentialSummary>,
identities: &[crate::integrations::composio::contract::ConnectedIdentity],
+ keys: &std::collections::HashMap<String, String>,
) -> Vec<FlowConnection> {
- use crate::integrations::composio::contract::normalize_connection_identifier;
+ // Normalised form of a raw key, from the module-computed `keys`. A key the
+ // module did not return is left as it came.
+ let normalize_connection_identifier =
+ |raw: &str| keys.get(raw).cloned().unwrap_or_else(|| raw.to_string());
let identity_lookup: std::collections::HashMap<(String, String), &_> = identities
.iter()
diff --git a/crates/openhuman-core/src/integrations/composio/ops/connections.rs b/crates/openhuman-core/src/integrations/composio/ops/connections.rs
index fdde3f341e..57c99a714d 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/connections.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/connections.rs
@@ -21,7 +21,7 @@ use super::error_utils::{
backend_mode_without_session, direct_mode_without_key, report_composio_op_error, OpResult,
COMPOSIO_NO_SESSION,
};
-use crate::integrations::composio::contract::normalize_connection_identifier;
+use crate::integrations::composio::contract::normalize_connection_identifiers;
pub async fn composio_list_connections(
config: &Config,
@@ -308,17 +308,30 @@ pub(crate) async fn enrich_connections_with_identity(
return resp;
}
+ // One module call normalises every identity key and every connection key.
+ let mut raw: Vec<String> = identities
+ .iter()
+ .flat_map(|id| [id.source.clone(), id.identifier.clone()])
+ .collect();
+ for conn in &resp.connections {
+ raw.push(conn.toolkit.clone());
+ raw.push(conn.id.clone());
+ }
+ let normalized = match normalize_connection_identifiers(config, &raw).await {
+ Ok(normalized) if normalized.len() == raw.len() => normalized,
+ other => {
+ tracing::debug!(
+ error = ?other.err(),
+ "[composio] enrich_connections_with_identity: key normalisation unavailable"
+ );
+ return resp;
+ }
+ };
+ let (identity_keys, connection_keys) = normalized.split_at(identities.len() * 2);
let lookup: HashMap<(String, String), _> = identities
.iter()
- .map(|id| {
- (
- (
- normalize_connection_identifier(&id.source),
- normalize_connection_identifier(&id.identifier),
- ),
- id,
- )
- })
+ .zip(identity_keys.chunks(2))
+ .map(|(id, keys)| ((keys[0].clone(), keys[1].clone()), id))
.collect();
tracing::debug!(
@@ -327,13 +340,11 @@ pub(crate) async fn enrich_connections_with_identity(
"[composio] enrich_connections_with_identity: enriching connection labels"
);
- for conn in &mut resp.connections {
+ for (conn, keys) in resp.connections.iter_mut().zip(connection_keys.chunks(2)) {
if conn.account_email.is_some() || conn.workspace.is_some() || conn.username.is_some() {
continue;
}
- let toolkit_key = normalize_connection_identifier(&conn.toolkit);
- let conn_id_key = normalize_connection_identifier(&conn.id);
- if let Some(identity) = lookup.get(&(toolkit_key, conn_id_key)) {
+ if let Some(identity) = lookup.get(&(keys[0].clone(), keys[1].clone())) {
conn.account_email = identity.email.clone();
conn.workspace = identity.display_name.clone();
conn.username = identity.handle.clone();