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
feat(channels): route outbound sends through module preparation
Steven Enamakel10621d5779d7
diff --git a/crates/openhuman-core/src/channels/controllers/backend.rs b/crates/openhuman-core/src/channels/controllers/backend.rsindex c7dc585288..0ac82534f5 100644--- a/crates/openhuman-core/src/channels/controllers/backend.rs+++ b/crates/openhuman-core/src/channels/controllers/backend.rs@@ -32,6 +32,30 @@ impl OpenHumanChannelBackend {&self.config}+ /// Deliver module-prepared content through the configured product transport.+ pub(crate) async fn send_prepared(+ &self,+ prepared: tinychannels_bus::PreparedChannelIntent,+ ) -> anyhow::Result<ChannelSendMessageResult> {+ if tinychannels::relay::relay_runtime_fronts_channel(+ &self.config.channels_config,+ &prepared.intent.channel_id,+ ) {+ if let Some(result) = tinychannels::relay::send_outbound_intent(&prepared.intent).await? {+ return Ok(result);+ }+ }+ let value = into_anyhow(+ ops::channel_send_message(+ &self.config,+ &prepared.intent.channel_id,+ prepared.legacy_message,+ )+ .await,+ )?;+ Ok(parse_or_raw(value))+ }+fn config_with_channels(&self, channels_config: &ChannelsConfig) -> Config {let mut config = self.config.clone();config.channels_config = channels_config.clone();diff --git a/crates/openhuman-core/src/channels/controllers/schemas.rs b/crates/openhuman-core/src/channels/controllers/schemas.rsindex 6660fa6327..1ea6a22bf4 100644--- a/crates/openhuman-core/src/channels/controllers/schemas.rs+++ b/crates/openhuman-core/src/channels/controllers/schemas.rs@@ -304,35 +304,16 @@ fn handle_status(params: Map<String, Value>) -> ControllerFuture {fn handle_set_default(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {- let config = config_rpc::load_config_with_timeout().await?;+ let mut config = config_rpc::load_config_with_timeout().await?;let p = deserialize_params::<SetDefaultParams>(params)?;- let channel = p.channel.trim();- let manager = openhuman_channel_manager(config);- manager- .set_default_channel(channel)- .await- .map_err(|e| e.to_string())?;- let canonical = channel.to_ascii_lowercase();- to_json(Outcome::single_log(- serde_json::json!({ "active_channel": canonical, "restart_required": false }),- format!("default messaging channel set to {canonical}"),- ))+ to_json(super::ops::set_default_channel(&mut config, p.channel.trim()).await?)})}fn handle_get_default(_params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let config = config_rpc::load_config_with_timeout().await?;- let manager = openhuman_channel_manager(config);- let active = manager- .get_default_channel()- .await- .map_err(|e| e.to_string())?- .unwrap_or_else(|| "web".to_string());- to_json(Outcome::new(- serde_json::json!({ "active_channel": active }),- vec![],- ))+ to_json(super::ops::get_default_channel(&config)?)})}@@ -357,15 +338,7 @@ async fn test_with_config(config: &Config, params: TestParams) -> Result<Value,fn handle_discord_list_guilds(_params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let config = config_rpc::load_config_with_timeout().await?;- let manager = openhuman_channel_manager(config);- let result = manager- .discord_list_guilds()- .await- .map_err(|e| e.to_string())?;- to_json(Outcome::single_log(- raw_or_typed(result.raw.clone(), &result)?,- "discord guilds listed",- ))+ to_json(super::ops::discord_list_guilds(&config).await?)})}@@ -373,16 +346,7 @@ fn handle_discord_list_channels(params: Map<String, Value>) -> ControllerFutureBox::pin(async move {let config = config_rpc::load_config_with_timeout().await?;let p = deserialize_params::<DiscordListChannelsParams>(params)?;- let guild_id = p.guild_id.trim();- let manager = openhuman_channel_manager(config);- let result = manager- .discord_list_channels(guild_id)- .await- .map_err(|e| e.to_string())?;- to_json(Outcome::single_log(- raw_or_typed(result.raw.clone(), &result)?,- format!("discord channels listed for guild {guild_id}"),- ))+ to_json(super::ops::discord_list_channels(&config, p.guild_id.trim()).await?)})}@@ -390,17 +354,9 @@ fn handle_discord_check_permissions(params: Map<String, Value>) -> ControllerFutBox::pin(async move {let config = config_rpc::load_config_with_timeout().await?;let p = deserialize_params::<DiscordCheckPermissionsParams>(params)?;- let guild_id = p.guild_id.trim();- let channel_id = p.channel_id.trim();- let manager = openhuman_channel_manager(config);- let result = manager- .discord_check_permissions(guild_id, channel_id)- .await- .map_err(|e| e.to_string())?;- to_json(Outcome::single_log(- raw_or_typed(result.raw.clone(), &result)?,- format!("discord permissions checked for channel {channel_id}"),- ))+ to_json(super::ops::discord_check_permissions(+ &config, p.guild_id.trim(), p.channel_id.trim(),+ ).await?)})}@@ -408,18 +364,25 @@ fn handle_send_message(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let config = config_rpc::load_config_with_timeout().await?;let p = deserialize_params::<SendMessageParams>(params)?;- let manager = openhuman_channel_manager(config);- let result = manager- .send_message_value(p.channel.trim(), p.message)- .await- .map_err(|e| e.to_string())?;- to_json(Outcome::new(- raw_or_typed(result.raw.clone(), &result)?,- vec![],- ))+ send_with_config(&config, p).await})}+async fn send_with_config(config: &Config, p: SendMessageParams) -> Result<Value, String> {+ let prepared = crate::modules::channel_controller::prepare_message(+ &crate::modules::client::ModuleClient::new(config.clone()),+ p.channel.trim(),+ p.message,+ )+ .await+ .map_err(|error| error.to_string())?;+ let result = OpenHumanChannelBackend::new(config.clone())+ .send_prepared(prepared)+ .await+ .map_err(|error| error.to_string())?;+ to_json(Outcome::new(raw_or_typed(result.raw.clone(), &result)?, vec![]))+}+fn handle_send_reaction(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let config = config_rpc::load_config_with_timeout().await?;diff --git a/crates/openhuman-core/src/channels/controllers/schemas_tests.rs b/crates/openhuman-core/src/channels/controllers/schemas_tests.rsindex df73ceee11..7ec532488f 100644--- a/crates/openhuman-core/src/channels/controllers/schemas_tests.rs+++ b/crates/openhuman-core/src/channels/controllers/schemas_tests.rs@@ -19,6 +19,24 @@ async fn channel_test_handler_requires_module_before_provider_field_validation()assert!(error.contains("module unavailable"), "{error}");}+#[tokio::test]+async fn rich_channel_send_requires_module_before_normalization_or_backend_delivery() {+ let mut config = Config::default();+ config.modules.enabled = false;+ let error = send_with_config(+ &config,+ SendMessageParams {+ channel: " telegram ".into(),+ message: json!({"text":"fixture-content", "thread_ts":"fixture-thread"}),+ },+ )+ .await+ .unwrap_err();+ assert!(error.contains("module unavailable"), "{error}");+ assert!(!error.contains("fixture-content"));+ assert!(!error.contains("fixture-thread"));+}+#[test]fn schema_handler_parity() {let schemas = all_controller_schemas();diff --git a/crates/openhuman-core/src/modules/channel_controller.rs b/crates/openhuman-core/src/modules/channel_controller.rsindex 2908393d3d..f49a0dcf4f 100644--- a/crates/openhuman-core/src/modules/channel_controller.rs+++ b/crates/openhuman-core/src/modules/channel_controller.rs@@ -59,6 +59,21 @@ pub(crate) async fn prepare_connection(}}+/// Normalize rich outbound content and derive its idempotency key inside the module.+pub(crate) async fn prepare_message(+ client: &ModuleClient,+ channel: &str,+ message: serde_json::Value,+) -> Result<tinychannels_bus::PreparedChannelIntent, ModuleCallError> {+ client+ .call_confidential(+ "tinychannels",+ methods::PREPARE_OUTBOUND_INTENT,+ (channel, tinychannels_bus::ChannelMessagePreparation::Legacy(message)),+ )+ .await+}+/// Resolve OpenHuman's proxy scope before transmitting provider configuration.pub(crate) fn discord_proxy(config: &crate::config::Config) -> HttpProxyPolicy {let proxy = &config.proxy;