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 contract lookup into composio catalog

Steven Enamakel507257ab00f8
diff --git a/crates/openhuman-core/src/flows/ops/catalog.rs b/crates/openhuman-core/src/flows/ops/catalog.rs
index 9301e02157..184f3300b0 100644
--- a/crates/openhuman-core/src/flows/ops/catalog.rs
+++ b/crates/openhuman-core/src/flows/ops/catalog.rs
@@ -1,42 +1,9 @@
use super::*;
-use crate::flows::tinyflows::caps::{fetch_live_toolkit_catalog, ToolContract};
-pub(crate) const RUNTIME_GATE_WARNING: &str = "This action will be REJECTED on every real run — the runtime tool gate only allows curated actions for this toolkit. Pick a `featured: true` result from search_tool_catalog instead.";
-
-pub(crate) enum ContractLookupError {
- InvalidSlug { slug: String },
- CatalogUnavailable { toolkit: String },
- ActionNotFound { slug: String, toolkit: String },
-}
-
-/// Resolves one live action and the runtime-curation warning used by both
-/// builder surfaces. The runtime allowlist remains authoritative; this only
-/// classifies an action so authoring can explain an inevitable rejection.
-pub(crate) async fn lookup_contract(
- config: &Config,
- slug: &str,
-) -> Result<(ToolContract, Option<&'static str>), ContractLookupError> {
- let trimmed = slug.trim();
- let Some(toolkit) = toolkit_for_contract_slug(trimmed) else {
- return Err(ContractLookupError::InvalidSlug {
- slug: slug.to_string(),
- });
- };
- let Some(catalog) = fetch_live_toolkit_catalog(config, &toolkit).await else {
- return Err(ContractLookupError::CatalogUnavailable { toolkit });
- };
- let Some(contract) = catalog.iter().find(|contract| {
- crate::integrations::composio::contract::action_slug_matches(&contract.slug, trimmed)
- }) else {
- return Err(ContractLookupError::ActionNotFound {
- slug: trimmed.to_string(),
- toolkit,
- });
- };
- let warning = (!contract.is_curated && toolkit_has_curated_catalog(&toolkit))
- .then_some(RUNTIME_GATE_WARNING);
- Ok((contract.clone(), warning))
-}
+pub(crate) use crate::integrations::composio::catalog::{
+ lookup_contract, ContractLookupError,
+};
+pub(crate) use crate::integrations::composio::catalog::has_curated_catalog as toolkit_has_curated_catalog;
// ─────────────────────────────────────────────────────────────────────────────
// Catalog RPCs for the UI (Phase 5, item 16) — one implementation, two consumers
@@ -60,33 +27,6 @@ pub async fn flows_search_tool_catalog(
))
}
-/// Resolves the toolkit for a *single action* slug, rejecting anything that is
-/// not shaped `<TOOLKIT>_<ACTION>`.
-///
-/// [`crate::integrations::composio::contract::toolkit_from_slug`] falls back to the whole
-/// string when there is no `_`, so it answers `Some` for every non-empty input
-/// — `toolkit_from_slug("nodashhere") == Some("nodashhere")`. That permissive
-/// fall-back is load-bearing for `compute_required_connections`, which maps
-/// toolkit-ish tokens and legitimately wants the whole string back, so the
-/// stricter rule belongs to this caller rather than to the shared helper.
-///
-/// A contract fetch returns *one action*, so a slug with no action segment
-/// cannot name anything it could return; rejecting it here also spares the
-/// caller a pointless catalog round trip (which takes a per-toolkit fetch lock)
-/// before failing with an unrelated "could not fetch the catalog" message.
-///
-/// The multi-segment toolkit prefixes (`MICROSOFT_TEAMS_`, `ONE_DRIVE_`,
-/// `ZOHO_MAIL_`) all end in `_`, so a real action under one of them always has
-/// non-empty segments either side of its first `_` and passes unchanged.
-pub(crate) fn toolkit_for_contract_slug(slug: &str) -> Option<String> {
- let trimmed = slug.trim();
- let (toolkit_segment, action_segment) = trimmed.split_once('_')?;
- if toolkit_segment.is_empty() || action_segment.is_empty() {
- return None;
- }
- crate::integrations::composio::contract::toolkit_from_slug(trimmed)
-}
-
/// Fetches one Composio action's full contract (secret-free) — the RPC the
/// canvas tool browser calls to fill in an action's arg schema, reusing the same
/// core as the agent's `get_tool_contract` tool.
diff --git a/crates/openhuman-core/src/integrations/composio/catalog.rs b/crates/openhuman-core/src/integrations/composio/catalog.rs
index bac6fa9897..df067b84a5 100644
--- a/crates/openhuman-core/src/integrations/composio/catalog.rs
+++ b/crates/openhuman-core/src/integrations/composio/catalog.rs
@@ -19,6 +19,55 @@ use tinyconnectors_bus::{
pub use tinyconnectors_bus::ComposioProbedOutputSample as ProbedOutputSample;
pub use tinyconnectors_bus::ComposioToolContract as ToolContract;
+/// Shared authoring lookup failure, kept distinct so callers can preserve
+/// their established user-facing error messages.
+pub(crate) enum ContractLookupError {
+ InvalidSlug { slug: String },
+ CatalogUnavailable { toolkit: String },
+ ActionNotFound { slug: String, toolkit: String },
+}
+
+/// Warning shared by both flow authoring surfaces when an action exists but
+/// the runtime's curated allowlist will reject it.
+pub(crate) const RUNTIME_GATE_WARNING: &str = "This action will be REJECTED on every real run — the runtime tool gate only allows curated actions for this toolkit. Pick a `featured: true` result from search_tool_catalog instead.";
+
+/// Resolves the live contract and runtime-curation warning for a flow action.
+pub(crate) async fn lookup_contract(
+ config: &Config,
+ slug: &str,
+) -> Result<(ToolContract, Option<&'static str>), ContractLookupError> {
+ let trimmed = slug.trim();
+ let Some(toolkit) = toolkit_for_contract_slug(trimmed) else {
+ return Err(ContractLookupError::InvalidSlug { slug: slug.to_string() });
+ };
+ let Some(catalog) = fetch_live_toolkit_catalog(config, &toolkit).await else {
+ return Err(ContractLookupError::CatalogUnavailable { toolkit });
+ };
+ let Some(contract) = catalog.iter().find(|contract| {
+ crate::integrations::composio::contract::action_slug_matches(&contract.slug, trimmed)
+ }) else {
+ return Err(ContractLookupError::ActionNotFound { slug: trimmed.to_string(), toolkit });
+ };
+ let warning = (!contract.is_curated && has_curated_catalog(&toolkit))
+ .then_some(RUNTIME_GATE_WARNING);
+ Ok((contract.clone(), warning))
+}
+
+/// Strictly extracts the toolkit from an action-shaped slug.
+pub(crate) fn toolkit_for_contract_slug(slug: &str) -> Option<String> {
+ let trimmed = slug.trim();
+ let (toolkit_segment, action_segment) = trimmed.split_once('_')?;
+ if toolkit_segment.is_empty() || action_segment.is_empty() {
+ return None;
+ }
+ crate::integrations::composio::contract::toolkit_from_slug(trimmed)
+}
+
+/// Whether the toolkit has a product-curated catalog.
+pub(crate) fn has_curated_catalog(toolkit: &str) -> bool {
+ crate::integrations::composio::contract::catalog_for_toolkit(toolkit).is_some()
+}
+
#[cfg(test)]
#[path = "catalog_seed.rs"]
mod seed;