Skip to content

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

chore: files changed crates/openhuman-core/src/integrations/composio/contract/scopes.rs,crates/openh

Steven Enamakelad31e9a1a2a7
diff --git a/crates/openhuman-core/src/integrations/composio/contract/scopes.rs b/crates/openhuman-core/src/integrations/composio/contract/scopes.rs
index 1a8a7e85f8..f4c9e7be10 100644
--- a/crates/openhuman-core/src/integrations/composio/contract/scopes.rs
+++ b/crates/openhuman-core/src/integrations/composio/contract/scopes.rs
@@ -161,12 +161,40 @@ pub fn find_curated<'a>(catalog: &'a [CuratedTool], slug: &str) -> Option<&'a Cu
catalog.iter().find(|t| t.slug.eq_ignore_ascii_case(slug))
}
+/// Toolkits whose identifier itself contains an underscore, so the first
+/// segment of their action slugs is not the toolkit: `(action prefix, toolkit)`.
+/// Their real action slugs carry the prefix as written.
+const MULTI_SEGMENT_TOOLKIT_PREFIXES: &[(&str, &str)] = &[
+ ("MICROSOFT_TEAMS_", "microsoft_teams"),
+ ("ONE_DRIVE_", "one_drive"),
+ ("ZOHO_MAIL_", "zoho_mail"),
+ ("GOOGLE_MAPS_", "google_maps"),
+];
+
+/// Spellings models use for toolkits whose real slugs have no separator
+/// (`GOOGLE_DRIVE_FIND_FILE` for `GOOGLEDRIVE_FIND_FILE`):
+/// `(alias prefix, toolkit, canonical action prefix)`. Without them the first
+/// segment, `google`, names a toolkit that does not exist.
+const ALIASED_TOOLKIT_PREFIXES: &[(&str, &str, &str)] = &[
+ ("GOOGLE_DRIVE_", "googledrive", "GOOGLEDRIVE_"),
+ ("GOOGLE_CALENDAR_", "googlecalendar", "GOOGLECALENDAR_"),
+ ("GOOGLE_SHEETS_", "googlesheets", "GOOGLESHEETS_"),
+ ("GOOGLE_DOCS_", "googledocs", "GOOGLEDOCS_"),
+ ("GOOGLE_MEET_", "googlemeet", "GOOGLEMEET_"),
+ ("GOOGLE_TASKS_", "googletasks", "GOOGLETASKS_"),
+ ("GOOGLE_SLIDES_", "googleslides", "GOOGLESLIDES_"),
+ ("GOOGLE_PHOTOS_", "googlephotos", "GOOGLEPHOTOS_"),
+ ("MICROSOFT_OUTLOOK_", "outlook", "OUTLOOK_"),
+];
+
/// Extract the toolkit slug from a Composio action slug.
///
/// Most action slugs follow `<TOOLKIT>_<VERB>_…` — `GMAIL_SEND_EMAIL` yields
/// `gmail`. A few toolkit identifiers contain underscores themselves, so those
/// need known-prefix handling or a connected-toolkit check silently drops every
/// action for them (`ZOHO_MAIL_*` would resolve to the non-existent `zoho`).
+/// Separated spellings of separator-less toolkits (`GOOGLE_DRIVE_*`) resolve to
+/// the real toolkit too (`googledrive`); see [`canonical_action_slug`].
///
/// Returns `None` only for an empty or whitespace-only slug.
pub fn toolkit_from_slug(slug: &str) -> Option<String> {
@@ -174,17 +202,17 @@ pub fn toolkit_from_slug(slug: &str) -> Option<String> {
if trimmed.is_empty() {
return None;
}
- const MULTI_SEGMENT_TOOLKIT_PREFIXES: &[(&str, &str)] = &[
- ("MICROSOFT_TEAMS_", "microsoft_teams"),
- ("ONE_DRIVE_", "one_drive"),
- ("ZOHO_MAIL_", "zoho_mail"),
- ];
let upper = trimmed.to_ascii_uppercase();
for (prefix, toolkit) in MULTI_SEGMENT_TOOLKIT_PREFIXES {
if upper.starts_with(prefix) {
return Some((*toolkit).to_string());
}
}
+ for (alias, toolkit, _) in ALIASED_TOOLKIT_PREFIXES {
+ if upper.starts_with(alias) {
+ return Some((*toolkit).to_string());
+ }
+ }
let prefix = trimmed.split('_').next()?;
if prefix.is_empty() {
None
@@ -193,6 +221,27 @@ pub fn toolkit_from_slug(slug: &str) -> Option<String> {
}
}
+/// The real action slug for an aliased spelling — `GOOGLE_DRIVE_FIND_FILE`
+/// becomes `GOOGLEDRIVE_FIND_FILE` — or `None` when `slug` uses no alias.
+pub fn canonical_action_slug(slug: &str) -> Option<String> {
+ let upper = slug.trim().to_ascii_uppercase();
+ ALIASED_TOOLKIT_PREFIXES
+ .iter()
+ .find_map(|(alias, _, canonical)| {
+ upper
+ .strip_prefix(alias)
+ .map(|rest| format!("{canonical}{rest}"))
+ })
+}
+
+/// Whether catalog slug `candidate` is the action `requested` names, ignoring
+/// case and accepting an aliased spelling ([`canonical_action_slug`]).
+pub fn action_slug_matches(candidate: &str, requested: &str) -> bool {
+ let requested = requested.trim();
+ candidate.eq_ignore_ascii_case(requested)
+ || canonical_action_slug(requested).is_some_and(|c| candidate.eq_ignore_ascii_case(&c))
+}
+
/// Every toolkit slug that has a curated, agent-ready catalog.
///
/// This is the source of truth behind the "preview / agent integration coming
diff --git a/crates/openhuman-core/src/integrations/composio/contract/scopes_tests.rs b/crates/openhuman-core/src/integrations/composio/contract/scopes_tests.rs
index c1b038d877..57f14b57eb 100644
--- a/crates/openhuman-core/src/integrations/composio/contract/scopes_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/contract/scopes_tests.rs
@@ -11,8 +11,8 @@
#![allow(clippy::expect_used, clippy::unwrap_used, clippy::panic)]
use super::{
- agent_ready_toolkits, classify_unknown, find_curated, toolkit_from_slug, CuratedTool,
- ToolScope, UserScopePref,
+ action_slug_matches, agent_ready_toolkits, canonical_action_slug, classify_unknown,
+ find_curated, toolkit_from_slug, CuratedTool, ToolScope, UserScopePref,
};
#[test]
@@ -176,3 +176,80 @@ fn the_agent_ready_list_names_the_native_providers() {
assert!(slugs.contains(&native), "{native} is missing from the list");
}
}
+
+#[test]
+fn spaced_google_and_microsoft_prefixes_resolve_to_the_real_toolkit() {
+ // Production: `get_tool_contract { slug: "GOOGLE_DRIVE_FIND_FILE" }` looked
+ // up the non-existent toolkit `google` and told the model to retry a fetch
+ // that could never succeed.
+ for (slug, toolkit) in [
+ ("GOOGLE_DRIVE_FIND_FILE", "googledrive"),
+ ("GOOGLE_CALENDAR_EVENTS_LIST", "googlecalendar"),
+ ("GOOGLE_SHEETS_BATCH_GET", "googlesheets"),
+ ("GOOGLE_DOCS_GET_DOCUMENT_BY_ID", "googledocs"),
+ ("GOOGLE_MEET_CREATE_MEET", "googlemeet"),
+ ("GOOGLE_TASKS_LIST_TASKS", "googletasks"),
+ ("GOOGLE_SLIDES_CREATE_PRESENTATION", "googleslides"),
+ ("GOOGLE_PHOTOS_LIST_ALBUMS", "googlephotos"),
+ ("GOOGLE_MAPS_TEXT_SEARCH", "google_maps"),
+ ("MICROSOFT_OUTLOOK_SEND_EMAIL", "outlook"),
+ ("google_drive_find_file", "googledrive"),
+ ] {
+ assert_eq!(toolkit_from_slug(slug).as_deref(), Some(toolkit), "{slug}");
+ }
+ // The canonical spellings are unchanged.
+ assert_eq!(
+ toolkit_from_slug("GOOGLEDRIVE_FIND_FILE").as_deref(),
+ Some("googledrive")
+ );
+ assert_eq!(
+ toolkit_from_slug("GOOGLECALENDAR_FIND_EVENT").as_deref(),
+ Some("googlecalendar")
+ );
+ // A prefix only matches at a segment boundary.
+ assert_eq!(
+ toolkit_from_slug("GOOGLE_DRIVERS_X").as_deref(),
+ Some("google")
+ );
+}
+
+#[test]
+fn every_resolved_multi_segment_toolkit_is_one_the_app_knows_or_a_real_composio_slug() {
+ let known = agent_ready_toolkits();
+ for slug in [
+ "GOOGLE_DRIVE_X",
+ "GOOGLE_CALENDAR_X",
+ "GOOGLE_SHEETS_X",
+ "GOOGLE_DOCS_X",
+ "MICROSOFT_TEAMS_X",
+ "MICROSOFT_OUTLOOK_X",
+ "ONE_DRIVE_X",
+ ] {
+ let toolkit = toolkit_from_slug(slug).unwrap();
+ assert!(known.contains(&toolkit.as_str()), "{slug} -> {toolkit}");
+ }
+}
+
+#[test]
+fn a_spaced_alias_is_rewritten_to_the_canonical_action_slug() {
+ assert_eq!(
+ canonical_action_slug("GOOGLE_DRIVE_FIND_FILE").as_deref(),
+ Some("GOOGLEDRIVE_FIND_FILE")
+ );
+ assert_eq!(
+ canonical_action_slug("google_calendar_events_list").as_deref(),
+ Some("GOOGLECALENDAR_EVENTS_LIST")
+ );
+ assert_eq!(
+ canonical_action_slug("MICROSOFT_OUTLOOK_SEND_EMAIL").as_deref(),
+ Some("OUTLOOK_SEND_EMAIL")
+ );
+ // Already canonical, or a toolkit whose real actions carry the underscore.
+ assert_eq!(canonical_action_slug("GOOGLEDRIVE_FIND_FILE"), None);
+ assert_eq!(canonical_action_slug("MICROSOFT_TEAMS_SEND_MESSAGE"), None);
+ assert_eq!(canonical_action_slug("GMAIL_SEND_EMAIL"), None);
+
+ assert!(action_slug_matches("GOOGLEDRIVE_FIND_FILE", "GOOGLE_DRIVE_FIND_FILE"));
+ assert!(action_slug_matches("GOOGLEDRIVE_FIND_FILE", "googledrive_find_file"));
+ assert!(!action_slug_matches("GOOGLEDRIVE_FIND_FILE", "GOOGLE_DRIVE_LIST_FILES"));
+}