Skip to content

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

refactor(composio): split monolithic connected integrations module into submodules

Steven Enamakel206b028fe479
diff --git a/crates/openhuman-core/src/integrations/composio/connected_integrations.rs b/crates/openhuman-core/src/integrations/composio/connected_integrations.rs
index a65601f6fa..db57cb023b 100644
--- a/crates/openhuman-core/src/integrations/composio/connected_integrations.rs
+++ b/crates/openhuman-core/src/integrations/composio/connected_integrations.rs
@@ -1,3 +1,11 @@
+//! Connected-integrations discovery: the process-wide [`cache`] fronting a
+//! mode-aware backend/direct [`fetch`] (whose uncached backend walk lives in
+//! [`fetch_uncached`] since it is one large, sequential routine).
+
+mod cache;
+mod fetch;
+mod fetch_uncached;
+
#[cfg(test)]
#[path = "connected_integrations_connectable_slug_tests_tests.rs"]
mod connectable_slug_tests;
@@ -5,5 +13,21 @@ mod connectable_slug_tests;
#[cfg(test)]
#[path = "connected_integrations_catalog_description_tests_tests.rs"]
mod catalog_description_tests;
-include!("connected_integrations_part_01.rs");
-include!("connected_integrations_part_02.rs");
+
+pub(crate) use cache::{
+ cache_key, cached_active_integrations, cached_active_integrations_including_expired,
+ composio_cache_test_lock, connected_set_hash, invalidate_connected_integrations_cache,
+ sync_cache_with_connections, CachedIntegrations, CACHE_TTL, INTEGRATIONS_CACHE,
+};
+pub(crate) use fetch::{
+ fetch_connected_integrations, fetch_connected_integrations_status, fetch_toolkit_actions,
+ FetchConnectedIntegrationsStatus,
+};
+
+// Brought into this module's own namespace (private `use`, not `pub use`)
+// so `connected_integrations_connectable_slug_tests_tests.rs` /
+// `connected_integrations_catalog_description_tests_tests.rs` — declared as
+// direct child modules of `connected_integrations` above — can still reach
+// these via a plain `use super::<name>;`, exactly as when this was one
+// un-split file. See each item's `pub(super)` in its owning submodule.
+use fetch::{connectable_toolkit_slugs, resolve_toolkit_description};
diff --git a/crates/openhuman-core/src/threads/ops/transcript.rs b/crates/openhuman-core/src/threads/ops/transcript.rs
new file mode 100644
index 0000000000..3925a60d70
--- /dev/null
+++ b/crates/openhuman-core/src/threads/ops/transcript.rs
@@ -0,0 +1,53 @@
+//! Paginated projection of a thread's settled transcript.
+
+use super::support::{counts, envelope, workspace_dir};
+use crate::memory::{ApiEnvelope, PaginationMeta};
+use crate::rpc::RpcOutcome;
+
+/// Request for [`transcript_get`]: the thread to project, plus newest-first
+/// pagination controls. `cursor` is the opaque token from a prior page's
+/// `nextCursor`; `limit` defaults to one screen.
+#[derive(Debug, Clone, serde::Deserialize)]
+pub struct TranscriptGetRequest {
+ pub thread_id: String,
+ #[serde(default)]
+ pub cursor: Option<String>,
+ #[serde(default)]
+ pub limit: Option<usize>,
+}
+
+/// Project a thread's settled transcript (derived from `session_raw/*.jsonl`)
+/// into typed display items, newest-first paginated. Returns an empty page with
+/// `hasTranscript: false` when the thread has no persisted transcript yet.
+pub async fn transcript_get(
+ request: TranscriptGetRequest,
+) -> Result<RpcOutcome<ApiEnvelope<crate::threads::transcript_view::TranscriptPage>>, String> {
+ let dir = workspace_dir().await?;
+ let thread_id = request.thread_id.trim();
+ if thread_id.is_empty() {
+ return Err("thread_id is required".to_string());
+ }
+ let page = crate::threads::transcript_view::get_page(
+ &dir,
+ thread_id,
+ request.cursor.as_deref(),
+ request.limit,
+ );
+ let counts = counts([
+ ("items", page.items.len()),
+ ("total", page.total),
+ ("has_transcript", usize::from(page.has_transcript)),
+ ]);
+ let pagination = Some(PaginationMeta {
+ limit: request
+ .limit
+ .unwrap_or(crate::threads::transcript_view::DEFAULT_LIMIT),
+ offset: request
+ .cursor
+ .as_deref()
+ .and_then(|c| c.trim().parse::<usize>().ok())
+ .unwrap_or(0),
+ count: page.total,
+ });
+ Ok(envelope(page, Some(counts), pagination))
+}
diff --git a/crates/openhuman-core/src/tools/impl/browser/browser_tool_impl.rs b/crates/openhuman-core/src/tools/impl/browser/browser_tool_impl.rs
new file mode 100644
index 0000000000..02c0bf4eaa
--- /dev/null
+++ b/crates/openhuman-core/src/tools/impl/browser/browser_tool_impl.rs
@@ -0,0 +1,175 @@
+//! [`Tool`] trait implementation for [`BrowserTool`]: schema and `execute`.
+
+use super::*;
+
+
+#[async_trait]
+impl Tool for BrowserTool {
+ fn name(&self) -> &str {
+ "browser"
+ }
+
+ fn description(&self) -> &str {
+ concat!(
+ "Web/browser automation with pluggable backends (playwright, agent-browser, rust-native, computer_use). ",
+ "Supports DOM actions plus optional OS-level actions (mouse_move, mouse_click, mouse_drag, ",
+ "key_type, key_press) through a computer-use sidecar. Use 'snapshot' to map ",
+ "interactive elements to refs (@e1, @e2). Enforces browser.allowed_domains for open actions."
+ )
+ }
+
+ fn parameters_schema(&self) -> Value {
+ json!({
+ "type": "object",
+ "properties": {
+ "action": {
+ "type": "string",
+ "enum": ["open", "snapshot", "click", "fill", "type", "get_text",
+ "get_title", "get_url", "wait", "press",
+ "hover", "scroll", "is_visible", "close", "find",
+ "mouse_move", "mouse_click", "mouse_drag", "key_type",
+ "key_press"],
+ "description": "Browser action to perform (OS-level actions require backend=computer_use)"
+ },
+ "url": {
+ "type": "string",
+ "description": "URL to navigate to (for 'open' action)"
+ },
+ "selector": {
+ "type": "string",
+ "description": "Element selector: @ref (e.g. @e1), CSS (#id, .class), or text=..."
+ },
+ "value": {
+ "type": "string",
+ "description": "Value to fill or type"
+ },
+ "text": {
+ "type": "string",
+ "description": "Text to type or wait for"
+ },
+ "key": {
+ "type": "string",
+ "description": "Key to press (Enter, Tab, Escape, etc.)"
+ },
+ "x": {
+ "type": "integer",
+ "description": "Screen X coordinate (computer_use: mouse_move/mouse_click)"
+ },
+ "y": {
+ "type": "integer",
+ "description": "Screen Y coordinate (computer_use: mouse_move/mouse_click)"
+ },
+ "from_x": {
+ "type": "integer",
+ "description": "Drag source X coordinate (computer_use: mouse_drag)"
+ },
+ "from_y": {
+ "type": "integer",
+ "description": "Drag source Y coordinate (computer_use: mouse_drag)"
+ },
+ "to_x": {
+ "type": "integer",
+ "description": "Drag target X coordinate (computer_use: mouse_drag)"
+ },
+ "to_y": {
+ "type": "integer",
+ "description": "Drag target Y coordinate (computer_use: mouse_drag)"
+ },
+ "button": {
+ "type": "string",
+ "enum": ["left", "right", "middle"],
+ "description": "Mouse button for computer_use mouse_click"
+ },
+ "direction": {
+ "type": "string",
+ "enum": ["up", "down", "left", "right"],
+ "description": "Scroll direction"
+ },
+ "pixels": {
+ "type": "integer",
+ "description": "Pixels to scroll"
+ },
+ "interactive_only": {
+ "type": "boolean",
+ "description": "For snapshot: only show interactive elements"
+ },
+ "compact": {
+ "type": "boolean",
+ "description": "For snapshot: remove empty structural elements"
+ },
+ "depth": {
+ "type": "integer",
+ "description": "For snapshot: limit tree depth"
+ },
+ "ms": {
+ "type": "integer",
+ "description": "Milliseconds to wait"
+ },
+ "by": {
+ "type": "string",
+ "enum": ["role", "text", "label", "placeholder", "testid"],
+ "description": "For find: semantic locator type"
+ },
+ "find_action": {
+ "type": "string",
+ "enum": ["click", "fill", "text", "hover", "check"],
+ "description": "For find: action to perform on found element"
+ },
+ "fill_value": {
+ "type": "string",
+ "description": "For find with fill action: value to fill"
+ }
+ },
+ "required": ["action"]
+ })
+ }
+
+ async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ // Security checks
+ if !self.security.can_act() {
+ return Ok(ToolResult::error(
+ "[policy-blocked] Action blocked: autonomy is read-only",
+ ));
+ }
+
+ if !self.security.record_action() {
+ return Ok(ToolResult::error("Action blocked: rate limit exceeded"));
+ }
+
+ // Reject unsupported actions before resolving or dispatching to a backend.
+ let action_str = args
+ .get("action")
+ .and_then(|v| v.as_str())
+ .ok_or_else(|| anyhow::anyhow!("Missing 'action' parameter"))?;
+
+ if !is_supported_browser_action(action_str) {
+ return Ok(ToolResult::error(format!("Unknown action: {action_str}")));
+ }
+
+ let backend = match self.resolve_backend().await {
+ Ok(selected) => selected,
+ Err(error) => {
+ return Ok(ToolResult::error(error.to_string()));
+ }
+ };
+
+ if backend == ResolvedBackend::ComputerUse {
+ return self.execute_computer_use_action(action_str, &args).await;
+ }
+
+ if is_computer_use_only_action(action_str) {
+ return Ok(ToolResult::error(unavailable_action_for_backend_error(
+ action_str, backend,
+ )));
+ }
+
+ let action = match parse_browser_action(action_str, &args) {
+ Ok(a) => a,
+ Err(e) => {
+ return Ok(ToolResult::error(e.to_string()));
+ }
+ };
+
+ self.execute_action(action, backend).await
+ }
+}
diff --git a/crates/openhuman-core/src/voice/realtime_harness/prompt.rs b/crates/openhuman-core/src/voice/realtime_harness/prompt.rs
new file mode 100644
index 0000000000..d2838fad29
--- /dev/null
+++ b/crates/openhuman-core/src/voice/realtime_harness/prompt.rs
@@ -0,0 +1,105 @@
+//! Pure prompt/text helpers shared by the turn handler and the agent builder:
+//! extracting the user prompt from a relayed `messages` array, classifying it
+//! (content-free, answerable, read-back), and picking the spoken text out of
+//! a streamed progress event.
+
+use crate::agent::progress::AgentProgress;
+use serde_json::Value;
+
+/// Instruction prefix used for "speak-back": when a deferred result is ready, the
+/// renderer's live voice session sends it back as a user message wrapped with this
+/// prefix so the agent reads it aloud verbatim. The core recognises the prefix to
+/// avoid re-arming speak-back on the read-back turn itself (which would loop). MUST
+/// match the string the renderer prepends (`useRealtimeVoiceSession.ts`).
+pub(super) const VOICE_READBACK_PREFIX: &str =
+ "Please read the following to me, word for word, and say nothing else:";
+
+/// Convert an OpenAI-style `messages` array into `(role, content)` history pairs
+/// for [`Agent::seed_resume_from_messages`]. Drops `system` turns — the relayed
+/// system prompt is the ElevenLabs agent's, not ours — and flattens multimodal
+/// content the same way [`extract_prompt`] does. Pure + unit-tested.
+pub(super) fn messages_to_history_pairs(messages: &[Value]) -> Vec<(String, String)> {
+ messages
+ .iter()
+ .filter_map(|msg| {
+ let role = msg.get("role").and_then(Value::as_str).unwrap_or("");
+ if role != "user" && role != "assistant" && role != "agent" {
+ return None;
+ }
+ let text = content_to_text(msg.get("content"));
+ if text.trim().is_empty() {
+ return None;
+ }
+ Some((role.to_string(), text))
+ })
+ .collect()
+}
+
+/// Extract the user prompt from an OpenAI-style `messages` array: the content of
+/// the last `user` message. Content may be a plain string or an array of
+/// `{ type: 'text', text }` parts (multimodal shape). Pure + unit-tested.
+pub fn extract_prompt(messages: &[Value]) -> String {
+ for msg in messages.iter().rev() {
+ if msg.get("role").and_then(Value::as_str) == Some("user") {
+ return content_to_text(msg.get("content"));
+ }
+ }
+ String::new()
+}
+
+fn content_to_text(content: Option<&Value>) -> String {
+ match content {
+ Some(Value::String(s)) => s.clone(),
+ Some(Value::Array(parts)) => parts
+ .iter()
+ .filter_map(|p| p.get("text").and_then(Value::as_str))
+ .collect::<Vec<_>>()
+ .join(" "),
+ _ => String::new(),
+ }
+}
+
+/// The spoken text carried by a progress event, or `None` for events that must
+/// not be voiced. Only the top-level assistant `TextDelta` is spoken; sub-agent
+/// deltas, thinking, tool-call args, and lifecycle events are internal. Pure +
+/// unit-tested.
+pub(super) fn spoken_delta(progress: &AgentProgress) -> Option<&str> {
+ match progress {
+ AgentProgress::TextDelta { delta, .. } => Some(delta),
+ _ => None,
+ }
+}
+
+/// The answer a read-back turn is asking to have spoken, or `None` for an
+/// ordinary turn. Leading whitespace is tolerated because the renderer joins the
+/// prefix and payload with a blank line. Pure + unit-tested.
+pub(super) fn readback_payload(prompt: &str) -> Option<&str> {
+ let trimmed = prompt.trim_start();
+ trimmed.strip_prefix(VOICE_READBACK_PREFIX).map(str::trim)
+}
+
+/// Whether a prompt carries nothing to answer. Speech recognition emits `"..."`
+/// (and similar punctuation-only artefacts) for a pause, and the provider relays
+/// those as real turns. Anything with a letter or a digit in it — in any script —
+/// is a genuine prompt. Pure + unit-tested.
+pub(super) fn is_content_free(prompt: &str) -> bool {
+ !prompt.chars().any(char::is_alphanumeric)
+}
+
+/// Whether the user is waiting on this turn's answer, and so should be told when
+/// it fails. False for a read-back (its answer is already in chat) and for a
+/// recognition artefact (nothing was asked). Pure + unit-tested.
+pub(super) fn is_answerable_prompt(prompt: &str) -> bool {
+ !is_content_free(prompt) && should_arm_speak_back(prompt)
+}
+
+/// Whether a completed voice turn should arm speak-back — i.e. push its deferred
+/// answer back into the live session to be read aloud. A read-back turn is itself
+/// a verbatim-read request (its prompt is wrapped with [`VOICE_READBACK_PREFIX`]
+/// by the renderer), so re-arming speak-back on it would deliver the spoken copy
+/// to a turn that then asks to read it again — an unbounded loop. Suppress those.
+/// Pure + unit-tested; leading whitespace is tolerated because the renderer joins
+/// the prefix and payload with a blank line.
+pub(super) fn should_arm_speak_back(prompt: &str) -> bool {
+ !prompt.trim_start().starts_with(VOICE_READBACK_PREFIX)
+}