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(channels): migrate dispatch to typed inbound envelope
Steven Enamakel5417b76b7f6f
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 78b993f54f..dfad28932d 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,7 +20,7 @@ use std::sync::Arc;use crate::agent::host_agents::HostAgent;use crate::channels::context::ChannelRuntimeContext;-use crate::channels::{ChannelSendExt, SendMessage};+use crate::channels::outbound::text_message;use crate::config::Config;use crate::core::bus::BUS;use crate::core::events::DomainEvent;@@ -111,28 +111,32 @@ pub(crate) const AGENT_UNAVAILABLE_REPLY: &str =/// Answer `msg` with [`AGENT_UNAVAILABLE_REPLY`] and record the refusal.pub(crate) async fn refuse_missing_agent(ctx: &ChannelRuntimeContext,- msg: &traits::ChannelMessage,+ msg: &traits::ChannelInboundEnvelope,target_channel: Option<&Arc<dyn crate::channels::Channel>>,agent_id: &str,) {if let Some(channel) = target_channel {- let reply = SendMessage::new(AGENT_UNAVAILABLE_REPLY, &msg.reply_target)- .in_thread(msg.thread_ts.clone());- if let Err(error) = channel.send_with_outbound_intent(&reply).await {+ let reply = text_message(+ &msg.channel.id,+ &msg.conversation.id,+ AGENT_UNAVAILABLE_REPLY,+ msg.conversation.thread_id.clone(),+ );+ if let Err(error) = channel.send_typed(&reply).await {tracing::warn!(- channel = %msg.channel,+ channel = %msg.channel.id,%error,"[channels::dispatch::host_agent] failed to send the unavailable reply");}}BUS.publish(DomainEvent::ChannelMessageProcessed {- channel: msg.channel.clone(),- message_id: msg.id.clone(),- sender: msg.sender.clone(),- reply_target: msg.reply_target.clone(),- content: msg.content.clone(),- thread_ts: msg.thread_ts.clone(),+ channel: msg.channel.id.clone(),+ message_id: msg.message_id.clone(),+ sender: msg.sender.id.clone(),+ reply_target: msg.conversation.id.clone(),+ content: msg.text.clone(),+ thread_ts: msg.conversation.thread_id.clone(),response: AGENT_UNAVAILABLE_REPLY.to_string(),provider: format!("agent:{agent_id}"),model: String::new(),diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rsindex 6bc11f0fa8..e5bde82468 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs@@ -50,11 +50,11 @@ pub(crate) async fn process_channel_runtime_message(/// its reply.pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted: AdmittedInbound) {let AdmittedInbound { msg, history_key } = admitted;- let target_channel = ctx.channels_by_name.get(&msg.channel).cloned();+ let target_channel = ctx.channels_by_name.get(&msg.channel.id).cloned();// A channel bound to a host agent nobody answers for is refused before// any typing or provider work; see `host_agent`.- let bound_agent = match host_agent::route(ctx.as_ref(), &msg.channel) {+ let bound_agent = match host_agent::route(ctx.as_ref(), &msg.channel.id) {HostRoute::Unbound => None,HostRoute::Agent(host) => Some(host),HostRoute::Missing(agent_id) => {@@ -72,7 +72,7 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:// Fire typing indicator as early as possible — before any async I/O — so the// user sees feedback immediately regardless of how fast the LLM responds.if let Some(channel) = target_channel.as_ref() {- if let Err(e) = channel.start_typing(&msg.reply_target).await {+ if let Err(e) = channel.start_typing(&msg.conversation.id).await {tracing::debug!("[dispatch] Early typing start failed on {}: {e}",channel.name()@@ -86,7 +86,7 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:// Keep the reaction owned by this worker so logout also aborts a pending send.let mut _acknowledgment_task = None;if let Some(channel) = target_channel.as_ref() {- if channel.supports_reactions() && msg.thread_ts.is_some() {+ if channel.supports_reactions() && msg.conversation.thread_id.is_some() {let ack_result = crate::channels::context::module_client(&ctx).await.call_confidential::<tinychannels_bus::module_control::ChannelControlResult>(@@ -94,7 +94,7 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:tinychannels_bus::methods::PREPARE_CHANNEL_CONTROL,(tinychannels_bus::module_control::ChannelControlRequest::Acknowledgment {- content: msg.content.clone(),+ content: msg.text.clone(),},),)@@ -111,14 +111,14 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:};if let Some(ack_emoji) = ack_emoji {tracing::debug!(- channel = msg.channel,+ channel = msg.channel.id,emoji = ack_emoji,"[dispatch] Sending acknowledgment reaction");let react_content = format!("[REACTION:{ack_emoji}]");let channel_for_react = Arc::clone(channel);- let react_msg = SendMessage::new(react_content, &msg.reply_target)- .in_thread(msg.thread_ts.clone());+ let react_msg = SendMessage::new(react_content, &msg.conversation.id)+ .in_thread(msg.conversation.thread_id.clone());_acknowledgment_task = Some(AbortOnDropHandle::new(tokio::spawn(async move {if let Err(e) = channel_for_react.send_with_outbound_intent(&react_msg)@@ -153,8 +153,8 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:if let Some(channel) = target_channel.as_ref() {let _ = channel.send_with_outbound_intent(- &SendMessage::new(message, &msg.reply_target)- .in_thread(msg.thread_ts.clone()),+ &SendMessage::new(message, &msg.conversation.id)+ .in_thread(msg.conversation.thread_id.clone()),).await;}@@ -170,9 +170,9 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:// committed turn from `ConversationTurnCommitted`.let channel_context = build_channel_context_block(&msg);let enriched_message = if channel_context.is_empty() {- msg.content.clone()+ msg.text.clone()} else {- format!("{channel_context}{}", msg.content)+ format!("{channel_context}{}", msg.text)};println!(" ⏳ Processing message...");@@ -223,7 +223,7 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:if let Some(channel) = target_channel.as_ref() {match channel.send_draft(- &SendMessage::new("...", &msg.reply_target).in_thread(msg.thread_ts.clone()),+ &SendMessage::new("...", &msg.conversation.id).in_thread(msg.conversation.thread_id.clone()),).await{@@ -247,7 +247,7 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:target_channel.as_ref(),) {let channel = Arc::clone(channel_ref);- let reply_target = msg.reply_target.clone();+ let reply_target = msg.conversation.id.clone();let draft_id = draft_id_ref.to_string();Some(AbortOnDropHandle::new(tokio::spawn(async move {let mut accumulated = String::new();@@ -316,7 +316,7 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:(Some(channel), Some(token)) => Some(AbortOnDropHandle::new(spawn_typing_task(&ctx.dispatch_ctx(),Arc::clone(channel),- msg.reply_target.clone(),+ msg.conversation.id.clone(),token.clone(),))),_ => None,@@ -333,11 +333,11 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:// produce distinct origins, and the wallet preparer / parked-approval// gates compare these for equality before honouring confirmations.let turn_origin = crate::security::turn_origin::AgentTurnOrigin::ExternalChannel {- sender_name: msg.sender_name.clone(),+ sender_name: msg.sender.name.clone(),channel: msg.channel.clone(),- sender: Some(msg.sender.clone()),- reply_target: msg.reply_target.clone(),- message_id: msg.id.clone(),+ sender: Some(msg.sender.id.clone()),+ reply_target: msg.conversation.id.clone(),+ message_id: msg.message_id.clone(),history_key: Some(history_key.clone()),};@@ -352,7 +352,7 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:crate::security::approval::ApprovalChatContext {thread_id: history_key.clone(),client_id: msg.channel.clone(),- request_id: Some(msg.id.clone()),+ request_id: Some(msg.message_id.clone()),},)} else {@@ -437,25 +437,25 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:if let Some(ref draft_id) = draft_message_id {if let Err(e) = channel.finalize_draft(- &msg.reply_target,+ &msg.conversation.id,draft_id,&response_text,- msg.thread_ts.as_deref(),+ msg.conversation.thread_id.as_deref(),).await{tracing::warn!("Failed to finalize draft: {e}; sending as new message");let _ = channel.send_with_outbound_intent(- &SendMessage::new(&response_text, &msg.reply_target)- .in_thread(msg.thread_ts.clone()),+ &SendMessage::new(&response_text, &msg.conversation.id)+ .in_thread(msg.conversation.thread_id.clone()),).await;}} else if let Err(e) = channel.send_with_outbound_intent(- &SendMessage::new(&response_text, &msg.reply_target)- .in_thread(msg.thread_ts.clone()),+ &SendMessage::new(&response_text, &msg.conversation.id)+ .in_thread(msg.conversation.thread_id.clone()),).await{@@ -484,17 +484,17 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:if let Some(ref draft_id) = draft_message_id {let _ = channel.finalize_draft(- &msg.reply_target,+ &msg.conversation.id,draft_id,error_text,- msg.thread_ts.as_deref(),+ msg.conversation.thread_id.as_deref(),).await;} else {let _ = channel.send_with_outbound_intent(- &SendMessage::new(error_text, &msg.reply_target)- .in_thread(msg.thread_ts.clone()),+ &SendMessage::new(error_text, &msg.conversation.id)+ .in_thread(msg.conversation.thread_id.clone()),).await;}@@ -502,11 +502,11 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:BUS.publish(DomainEvent::ChannelMessageProcessed {channel: msg.channel.clone(),- message_id: msg.id.clone(),- sender: msg.sender.clone(),- reply_target: msg.reply_target.clone(),- content: msg.content.clone(),- thread_ts: msg.thread_ts.clone(),+ message_id: msg.message_id.clone(),+ sender: msg.sender.id.clone(),+ reply_target: msg.conversation.id.clone(),+ content: msg.text.clone(),+ thread_ts: msg.conversation.thread_id.clone(),response: error_text.to_string(),provider: route.provider.clone(),model: route.model.clone(),@@ -573,17 +573,17 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:if let Some(ref draft_id) = draft_message_id {let _ = channel.finalize_draft(- &msg.reply_target,+ &msg.conversation.id,draft_id,&error_response,- msg.thread_ts.as_deref(),+ msg.conversation.thread_id.as_deref(),).await;} else {let _ = channel.send_with_outbound_intent(- &SendMessage::new(&error_response, &msg.reply_target)- .in_thread(msg.thread_ts.clone()),+ &SendMessage::new(&error_response, &msg.conversation.id)+ .in_thread(msg.conversation.thread_id.clone()),).await;}@@ -617,17 +617,17 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:if let Some(ref draft_id) = draft_message_id {let _ = channel.finalize_draft(- &msg.reply_target,+ &msg.conversation.id,draft_id,&error_text,- msg.thread_ts.as_deref(),+ msg.conversation.thread_id.as_deref(),).await;} else {let _ = channel.send_with_outbound_intent(- &SendMessage::new(&error_text, &msg.reply_target)- .in_thread(msg.thread_ts.clone()),+ &SendMessage::new(&error_text, &msg.conversation.id)+ .in_thread(msg.conversation.thread_id.clone()),).await;}@@ -643,11 +643,11 @@ pub(crate) async fn run_admitted_turn(ctx: Arc<ChannelRuntimeContext>, admitted:BUS.publish(DomainEvent::ChannelMessageProcessed {channel: msg.channel.clone(),- message_id: msg.id.clone(),- sender: msg.sender.clone(),- reply_target: msg.reply_target.clone(),- content: msg.content.clone(),- thread_ts: msg.thread_ts.clone(),+ message_id: msg.message_id.clone(),+ sender: msg.sender.id.clone(),+ reply_target: msg.conversation.id.clone(),+ content: msg.text.clone(),+ thread_ts: msg.conversation.thread_id.clone(),response: response_text,provider: response_provider,model: response_model,