The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(runtime): clean up imports and structure in runtime components
Steven Enamakel4bf837889467
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rsindex 078dcd024d..b73ef0d8e9 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs@@ -1,7 +1,7 @@use super::*;use crate::core::runtime::DispatchCtx;use std::sync::Arc;-use tokio::sync::{oneshot, Notify};+use tokio::sync::{Notify, oneshot};#[tokio::test]async fn canceled_waiter_closes_handle_returned_by_in_flight_typing_start() {diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rsindex efd1855b5a..8fb505d8b5 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs@@ -20,8 +20,8 @@use std::sync::Arc;use crate::agent::host_agents::HostAgent;-use crate::channels::context::ChannelRuntimeContext;use crate::channels::SendMessage;+use crate::channels::context::ChannelRuntimeContext;use crate::config::Config;use crate::core::bus::BUS;use crate::core::events::DomainEvent;@@ -29,7 +29,7 @@ use tinychannels_bus as traits;pub(crate) mod posture;mod turn;-pub(crate) use turn::{run_host_agent_turn, HostChannelTurn};+pub(crate) use turn::{HostChannelTurn, run_host_agent_turn};/// Resolve the config-owned target selected for an unbound channel into the/// same trusted host-agent carrier used by channel bindings. The effectivediff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture.rsindex 897b06d53f..512bb00296 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture.rs@@ -11,8 +11,8 @@use tinytools::{PermissionLevel, Tool};-use crate::agent::turn_origin::AgentTurnOrigin;use crate::agent::HostTools;+use crate::agent::turn_origin::AgentTurnOrigin;use crate::config::Config;/// The most a host agent may do on a turn from `origin`; `None` leaves thediff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rsindex ee804b5dfe..75b07b6cf6 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs@@ -1,8 +1,8 @@use super::*;use crate::agent::HostTurnTools;-use serde_json::{json, Value};-use std::sync::atomic::{AtomicUsize, Ordering};+use serde_json::{Value, json};use std::sync::Arc;+use std::sync::atomic::{AtomicUsize, Ordering};use tinytools::{ToolCallOptions, ToolResult};fn external() -> AgentTurnOrigin {diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs b/crates/openhuman-core/src/channels/runtime/dispatch/mod.rsindex 43862f6b3a..9bd79b5bb0 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs@@ -17,14 +17,14 @@ mod processor;mod routing;pub(crate) use processor::progressive::{- delivery_succeeded, hosted_relay_target, NativeProgressiveTarget,+ NativeProgressiveTarget, delivery_succeeded, hosted_relay_target,};#[cfg(test)]pub(crate) use processor::process_channel_message;pub(crate) use processor::{- process_channel_runtime_message, reset_durable_channel_session, run_message_dispatch_loop,- RuntimeChannelMessage,+ RuntimeChannelMessage, process_channel_runtime_message, reset_durable_channel_session,+ run_message_dispatch_loop,};// `channel_has_approval_surface` stays pub(crate) on processor; re-export so@@ -40,7 +40,7 @@ pub(crate) use helpers::build_channel_context_block;use helpers::select_acknowledgment_reaction;#[cfg(test)]-use routing::{build_visible_tool_set, AgentScoping};+use routing::{AgentScoping, build_visible_tool_set};#[cfg(any(test, debug_assertions))]use tinychannels_bus as traits;diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rsindex 67770808b1..114c265c62 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs@@ -1,7 +1,7 @@//! The orchestrator path: an unbound channel's turn goes over the native bus//! to the `agent.run_turn` handler, with the orchestrator's tool scoping.-use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, AGENT_RUN_TURN_METHOD};+use crate::agent::bus::{AGENT_RUN_TURN_METHOD, AgentTurnRequest, AgentTurnResponse};use crate::agent::turn_origin::AgentTurnOrigin;use crate::channels::context::{ChannelRouteSelection, ChannelRuntimeContext};use crate::core::bus::BUS;diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rsindex 1d7a1fd0fa..382f1caef4 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs@@ -1,11 +1,11 @@//! The per-message pipeline: typing indicator, ACK reaction, durable-session//! dispatch through the shared runner, and final reply delivery.-use crate::channels::context::{is_context_window_overflow_error, ChannelRuntimeContext};+use crate::channels::SendMessage;+use crate::channels::context::{ChannelRuntimeContext, is_context_window_overflow_error};#[cfg(test)]use crate::channels::routes::get_or_create_turn_model_source;use crate::channels::routes::{get_route_selection, handle_runtime_command_with_reset};-use crate::channels::SendMessage;use crate::core::bus::BUS;use crate::core::events::DomainEvent;use crate::util::truncate_with_ellipsis;@@ -15,12 +15,12 @@ use tokio_util::sync::CancellationToken;use tokio_util::task::AbortOnDropHandle;use super::super::helpers::{- build_channel_context_block, log_worker_join_result, spawn_typing_task,- REPLY_LOG_TRUNCATE_CHARS,+ REPLY_LOG_TRUNCATE_CHARS, build_channel_context_block, log_worker_join_result,+ spawn_typing_task,};use super::super::host_agent::{self, HostRoute};-use super::approval::{channel_has_approval_surface, try_route_approval_reply};use super::RuntimeChannelMessage;+use super::approval::{channel_has_approval_surface, try_route_approval_reply};fn inbound_console_preview(envelope: &tinychannels_bus::ChannelInboundEnvelope,diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/routing.rs b/crates/openhuman-core/src/channels/runtime/dispatch/routing.rsindex 803fd74a03..195095eb90 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/routing.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/routing.rs@@ -10,8 +10,8 @@ use crate::agent::harness::host_definition::{AgentDefinition, AgentDefinitionReguse crate::agent::prompts::ConnectedIntegration;use crate::config::Config;use crate::integrations::composio::{- cached_active_integrations, fetch_connected_integrations_status,- FetchConnectedIntegrationsStatus,+ FetchConnectedIntegrationsStatus, cached_active_integrations,+ fetch_connected_integrations_status,};use crate::tools::orchestrator_tools;use std::collections::HashSet;diff --git a/crates/openhuman-core/src/channels/runtime/mod.rs b/crates/openhuman-core/src/channels/runtime/mod.rsindex 0fb97e9a9b..0fe7ce7382 100644--- a/crates/openhuman-core/src/channels/runtime/mod.rs+++ b/crates/openhuman-core/src/channels/runtime/mod.rs@@ -4,21 +4,23 @@ pub(crate) mod dispatch;pub(crate) mod session;mod startup;+pub(crate) use startup::ChannelHandle;+#[cfg(test)]+pub(crate) use startup::TestChannel;pub(crate) use startup::hydrate_channel_credentials;+#[cfg(test)]+pub(crate) use startup::prepare_module_runtime_for_test_in_context;pub(crate) use startup::prepare_runtime_limits;pub use startup::start_channels;pub(crate) use startup::start_channels_with_session;-pub(crate) use startup::ChannelHandle;-#[cfg(test)]-pub(crate) use startup::TestChannel;#[cfg(test)]-pub(crate) use startup::{prepare_module_runtime_for_test, ModuleRuntimeTestGuard};+pub(crate) use startup::{ModuleRuntimeTestGuard, prepare_module_runtime_for_test};// The hosted-channel relay (`channels::providers::relay`) runs one message// through the same pipeline, with a context built from the caller's config.#[cfg(test)]pub(crate) use dispatch::process_channel_message;-pub(crate) use dispatch::{process_channel_runtime_message, RuntimeChannelMessage};-pub(crate) use startup::{build_channel_turn_parts, runtime_context, PromptToolDescs};+pub(crate) use dispatch::{RuntimeChannelMessage, process_channel_runtime_message};+pub(crate) use startup::{PromptToolDescs, build_channel_turn_parts, runtime_context};#[cfg(test)]pub mod test_support;diff --git a/crates/openhuman-core/src/channels/runtime/session_tests.rs b/crates/openhuman-core/src/channels/runtime/session_tests.rsindex 6aa6d4da36..3502a55425 100644--- a/crates/openhuman-core/src/channels/runtime/session_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/session_tests.rs@@ -1,7 +1,7 @@use super::*;use crate::core::runtime::DispatchCtx;-use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};use std::sync::Arc;+use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};#[tokio::test]async fn independent_local_runtime_does_not_need_an_account_session() {diff --git a/crates/openhuman-core/src/channels/runtime/startup.rs b/crates/openhuman-core/src/channels/runtime/startup.rsindex dbd5fe4f6b..46f330f0a6 100644--- a/crates/openhuman-core/src/channels/runtime/startup.rs+++ b/crates/openhuman-core/src/channels/runtime/startup.rs@@ -277,7 +277,7 @@ pub(crate) async fn prepare_runtime_limits(pub(crate) use credentials::hydrate_channel_credentials;pub use start_channels::start_channels;pub(crate) use start_channels::start_channels_with_session;-pub(crate) use turn_parts::{build_channel_turn_parts, runtime_context, PromptToolDescs};+pub(crate) use turn_parts::{PromptToolDescs, build_channel_turn_parts, runtime_context};/// Owns a real module-backed channel runtime for channel policy tests.///@@ -296,9 +296,8 @@ impl ModuleRuntimeTestGuard {pub(crate) fn module_objects(&self,- ) -> std::sync::Arc<- std::collections::HashMap<String, tinybus::module::ModuleObjectClient>,- > {+ ) -> std::sync::Arc<std::collections::HashMap<String, tinybus::module::ModuleObjectClient>>+ {self.0.module_objects()}@@ -352,7 +351,7 @@ pub(crate) async fn prepare_module_runtime_for_test_in_context(#[cfg(test)]use crate::config::Config;#[cfg(test)]-use chat_workload::{resolve_chat_workload, ChatWorkloadResolution};+use chat_workload::{ChatWorkloadResolution, resolve_chat_workload};#[cfg(any(test, debug_assertions))]use credentials::resolve_yuanbao_app_secret;#[cfg(any(test, debug_assertions))]diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rsindex 1c4827b34f..dd61e0e670 100644--- a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs@@ -163,14 +163,16 @@ fn callback_for_channels(let context_slot: Arc<OnceLock<Weak<ChannelRuntimeContext>>> = Arc::new(OnceLock::new());assert!(context_slot.set(Arc::downgrade(&context)).is_ok());let progressive_slot = Arc::new(OnceLock::new());- assert!(progressive_slot- .set(Arc::new(- progressive_channels- .into_iter()- .map(|(name, adapter)| (name, Arc::downgrade(&adapter)))- .collect()- ))- .is_ok());+ assert!(+ progressive_slot+ .set(Arc::new(+ progressive_channels+ .into_iter()+ .map(|(name, adapter)| (name, Arc::downgrade(&adapter)))+ .collect()+ ))+ .is_ok()+ );let (dispatch, _receiver) = tokio::sync::mpsc::channel::<RuntimeChannelMessage>(1);let mut callback = ChannelHostCallbacks::new(&crate::core::runtime::DispatchCtx::host_default(),@@ -596,14 +598,16 @@ async fn native_progressive_callbacks_stop_after_channel_session_cancellation());callback.cancellation.cancel();- assert!(callback- .dispatch_controller_backend(output_event_request(- Some("telegram:bot-b"),- Some("chat-42"),- Some("turn-15"),- ))- .await- .is_err());+ assert!(+ callback+ .dispatch_controller_backend(output_event_request(+ Some("telegram:bot-b"),+ Some("chat-42"),+ Some("turn-15"),+ ))+ .await+ .is_err()+ );assert!(observer.seen.lock().await.is_empty());}@@ -635,14 +639,16 @@ async fn native_progressive_callbacks_fail_closed_after_transport_owner_drops()drop(context);drop(adapter);- assert!(callback- .dispatch_controller_backend(output_event_request(- Some("telegram:bot-b"),- Some("chat-42"),- Some("turn-16"),- ))- .await- .is_err());+ assert!(+ callback+ .dispatch_controller_backend(output_event_request(+ Some("telegram:bot-b"),+ Some("chat-42"),+ Some("turn-16"),+ ))+ .await+ .is_err()+ );}#[path = "callback_inbound_tests.rs"]diff --git a/crates/openhuman-core/src/channels/runtime/startup/delivery_import.rs b/crates/openhuman-core/src/channels/runtime/startup/delivery_import.rsindex 2b0eb9d56b..ea1823dc6b 100644--- a/crates/openhuman-core/src/channels/runtime/startup/delivery_import.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/delivery_import.rs@@ -23,11 +23,11 @@use std::collections::BTreeMap;use std::path::Path;-use serde_json::{json, Value};+use serde_json::{Value, json};use sha2::Digest;use tinychannels_bus::module_delivery::{- DeliveryQueueEntry, DeliveryTerminalResult, DELIVERY_PENDING_CAPACITY, DELIVERY_RECORD_BYTES,- DELIVERY_RESULT_CAPACITY, DELIVERY_RESULT_TTL_SECONDS,+ DELIVERY_PENDING_CAPACITY, DELIVERY_RECORD_BYTES, DELIVERY_RESULT_CAPACITY,+ DELIVERY_RESULT_TTL_SECONDS, DeliveryQueueEntry, DeliveryTerminalResult,};use tinystoragedrivers::{CollectionSpec, ErrorKind, Precondition};diff --git a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rsindex 0ef78cbd00..3f823619a5 100644--- a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs@@ -9,11 +9,11 @@ use anyhow::{Context, Result};use std::collections::HashMap;use std::sync::{Arc, OnceLock, Weak};use tinybus::module::{ModuleCallError, ModuleClient, ModuleObjectClient};+use tinychannels_bus::SendMessage;use tinychannels_bus::module_runtime::{ChannelIngressKind, ChannelMessagePreparation, ConfiguredChannelInfo,};use tinychannels_bus::module_supervision::ChannelSupervisionPolicy;-use tinychannels_bus::SendMessage;use tinychannels_bus::{ChannelInteraction, ChannelInteractionResult};use tokio::sync::mpsc;diff --git a/crates/openhuman-core/src/channels/runtime/startup/module_providers_hosted_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/module_providers_hosted_tests.rsindex de96908b6f..4e09e82437 100644--- a/crates/openhuman-core/src/channels/runtime/startup/module_providers_hosted_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/module_providers_hosted_tests.rs@@ -301,14 +301,16 @@ async fn hosted_target_projects_typed_media_and_voice_to_web_and_gateway_once()assert_eq!(image_gateway.context().thread_id, thread_id);assert!(image_gateway.belongs_to("relay-typed-output-agent"));assert!(image_gateway.belongs_to_profile("relay-typed-output-profile"));- assert!(image_gateway_wire["structured"]["parts"]- .as_array()- .expect("typed provider parts")- .iter()- .any(|part| {- part["part"]["kind"] == "image"- && part["part"]["media"]["opaqueId"] == "media:tenant7/thread42/image1"- }));+ assert!(+ image_gateway_wire["structured"]["parts"]+ .as_array()+ .expect("typed provider parts")+ .iter()+ .any(|part| {+ part["part"]["kind"] == "image"+ && part["part"]["media"]["opaqueId"] == "media:tenant7/thread42/image1"+ })+ );let voice_gateway = gateway_terminals.iter().find(|event| {@@ -321,15 +323,17 @@ async fn hosted_target_projects_typed_media_and_voice_to_web_and_gateway_once()assert_eq!(voice_gateway.context().thread_id, thread_id);assert!(voice_gateway.belongs_to("relay-typed-output-agent"));assert!(voice_gateway.belongs_to_profile("relay-typed-output-profile"));- assert!(voice_gateway_wire["structured"]["parts"]- .as_array()- .expect("typed voice provider parts")- .iter()- .any(|part| {- part["kind"] == "voice"- && part["voice"]["kind"] == "media"- && part["voice"]["media"]["opaqueId"] == "media:tenant7/thread42/voice1"- }));+ assert!(+ voice_gateway_wire["structured"]["parts"]+ .as_array()+ .expect("typed voice provider parts")+ .iter()+ .any(|part| {+ part["kind"] == "voice"+ && part["voice"]["kind"] == "media"+ && part["voice"]["media"]["opaqueId"] == "media:tenant7/thread42/voice1"+ })+ );let expected_channel_ref = serde_json::to_value(&channel).expect("expected channel ref");let expected_conversation_ref =serde_json::to_value(&conversation).expect("expected conversation ref");diff --git a/crates/openhuman-core/src/channels/runtime/startup/progressive_transport_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/progressive_transport_tests.rsindex 040e6521f0..271b99d4bb 100644--- a/crates/openhuman-core/src/channels/runtime/startup/progressive_transport_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/progressive_transport_tests.rs@@ -39,7 +39,7 @@ fn module_callback_error_does_not_expose_provider_details() {#[test]fn receipt_scope_requires_exact_channel_and_full_conversation_identity() {- use tinychannels_bus::channel::{types::ConversationKind, MessageReceipt};+ use tinychannels_bus::channel::{MessageReceipt, types::ConversationKind};use tinychannels_bus::{ChannelRef, ConversationRef};let channel = ChannelRef {diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rsindex 0073b73aed..5389f2d905 100644--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs@@ -3,7 +3,7 @@use super::super::dispatch::run_message_dispatch_loop;use super::module_providers::ModuleChannelRuntime;-use super::turn_parts::{build_channel_turn_parts, runtime_context, PromptToolDescs};+use super::turn_parts::{PromptToolDescs, build_channel_turn_parts, runtime_context};use crate::config::Config;use crate::core::bus::BUS;use crate::core::events::DomainEvent;diff --git a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rsindex 29e21c6cf9..ac5a8befb5 100644--- a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs@@ -6,7 +6,7 @@//! the caller's own config and policy, so a relayed turn never runs with the//! operator's tools or workspace.-use super::chat_workload::{resolve_chat_workload, ChatWorkloadResolution};+use super::chat_workload::{ChatWorkloadResolution, resolve_chat_workload};use super::prompt::format_access_context;use crate::agent::host_runtime;use crate::channels::context::ChannelRuntimeContext;diff --git a/crates/openhuman-core/src/channels/runtime/startup_tests.rs b/crates/openhuman-core/src/channels/runtime/startup_tests.rsindex 42c2c7dde8..2977d557c1 100644--- a/crates/openhuman-core/src/channels/runtime/startup_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/startup_tests.rs@@ -7,7 +7,7 @@//! (cloud) path is preserved for users who haven't picked a local ///! BYOK model, and the override path activates for those who have.-use super::{resolve_chat_workload, ChatWorkloadResolution};+use super::{ChatWorkloadResolution, resolve_chat_workload};use crate::config::Config;fn config_with_chat_provider(s: Option<&str>) -> Config {