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): route channel turn persistence through the module client
Steven Enamakel7ac0b1e5f760
diff --git a/crates/openhuman-core/src/channels/commands.rs b/crates/openhuman-core/src/channels/commands.rsindex d5aa4a9789..a7ed0b94c4 100644--- a/crates/openhuman-core/src/channels/commands.rs+++ b/crates/openhuman-core/src/channels/commands.rs@@ -86,7 +86,7 @@ pub async fn doctor_channels(config: Config) -> Result<()> {/// Selecting configured providers is host configuration orchestration. The/// module owns construction, platform support, health I/O and timeout handling.-fn configured_providers(config: &Config) -> Vec<&'static str> {+pub(crate) fn configured_providers(config: &Config) -> Vec<&'static str> {let channels = &config.channels_config;[("telegram", channels.telegram.is_some()),diff --git a/crates/openhuman-core/src/channels/runtime/startup.rs b/crates/openhuman-core/src/channels/runtime/startup.rsindex fe988f6947..5138217a71 100644--- a/crates/openhuman-core/src/channels/runtime/startup.rs+++ b/crates/openhuman-core/src/channels/runtime/startup.rs@@ -4,6 +4,7 @@ mod chat_workload;mod callback;mod credentials;mod delivery_store;+mod module_providers;mod prompt;mod relay;mod start_channels;diff --git a/crates/openhuman-core/src/threads/store/bus.rs b/crates/openhuman-core/src/threads/store/bus.rsindex 38c63547d4..e13b39b888 100644--- a/crates/openhuman-core/src/threads/store/bus.rs+++ b/crates/openhuman-core/src/threads/store/bus.rs@@ -32,6 +32,7 @@ use crate::core::events::DomainEvent;use tinybus::EventHandler;use tinybus::SubscriptionHandle;use tinychannels_bus::ChannelMessage;+#[cfg(test)]use tinychannels_runtime::context::conversation_history_key;use super::{@@ -247,9 +248,7 @@ impl EventHandler<DomainEvent> for ConversationPersistenceSubscriber {sender,reply_target,thread_ts: thread_ts.as_deref(),- tinychannels_session_key: inbound_envelope- .as_ref()- .map(tinychannels_session_key),+ inbound_envelope: inbound_envelope.as_ref(),content,role: "user",success: None,@@ -258,7 +257,9 @@ impl EventHandler<DomainEvent> for ConversationPersistenceSubscriber {model: None,source: "channel_received",},- ) {+ )+ .await+ {log::warn!("{LOG_PREFIX} failed to persist inbound channel message channel={} message_id={} error={}",channel,@@ -305,7 +306,7 @@ impl EventHandler<DomainEvent> for ConversationPersistenceSubscriber {sender,reply_target,thread_ts: thread_ts.as_deref(),- tinychannels_session_key: None,+ inbound_envelope: None,content: response,role: "assistant",success: Some(*success),@@ -314,7 +315,9 @@ impl EventHandler<DomainEvent> for ConversationPersistenceSubscriber {model: Some(model),source: "channel_processed",},- ) {+ )+ .await+ {log::warn!("{LOG_PREFIX} failed to persist processed channel message channel={} message_id={} error={}",channel,@@ -334,7 +337,7 @@ struct ChannelTurnDescriptor<'a> {sender: &'a str,reply_target: &'a str,thread_ts: Option<&'a str>,- tinychannels_session_key: Option<String>,+ inbound_envelope: Option<&'a tinychannels_bus::ChannelInboundEnvelope>,content: &'a str,role: &'a str,success: Option<bool>,@@ -344,16 +347,43 @@ struct ChannelTurnDescriptor<'a> {source: &'a str,}-fn persist_channel_turn(+async fn persist_channel_turn(workspace_dir: &Path,descriptor: ChannelTurnDescriptor<'_>,) -> Result<(), String> {- let thread_id = persisted_channel_thread_id(- descriptor.channel,- descriptor.sender,- descriptor.reply_target,- descriptor.thread_ts,- );+ let config = crate::config::rpc::load_config_with_timeout().await?;+ if config.workspace_dir != workspace_dir {+ return Err("channel workspace changed".into());+ }+ let client = crate::modules::client::ModuleClient::new(config);+ let prepared: tinychannels_bus::module_inbound::PreparedChannelInbound = client+ .call_confidential(+ "tinychannels",+ tinychannels_bus::methods::PREPARE_CHANNEL_INBOUND,+ (+ tinychannels_bus::module_inbound::PrepareChannelInboundRequest {+ namespace: "main".into(),+ session_policy: Default::default(),+ source: tinychannels_bus::module_inbound::ChannelInboundSource::Legacy {+ message: ChannelMessage {+ id: descriptor.message_id.into(),+ sender: descriptor.sender.into(),+ reply_target: descriptor.reply_target.into(),+ content: descriptor.content.into(),+ channel: descriptor.channel.into(),+ timestamp: 0,+ thread_ts: descriptor.thread_ts.map(ToOwned::to_owned),+ sender_name: None,+ },+ envelope: descriptor.inbound_envelope.cloned(),+ },+ },+ ),+ )+ .await+ .map_err(|error| error.to_string())?;+ let thread_id = format!("channel:{}", prepared.history_key);+ let session_key = descriptor.inbound_envelope.map(|_| prepared.session_key);let title = channel_thread_title(descriptor.channel,descriptor.sender,@@ -401,7 +431,7 @@ fn persist_channel_turn("channelSender": descriptor.sender,"replyTarget": descriptor.reply_target,"threadTs": descriptor.thread_ts,- "tinychannelsSessionKey": descriptor.tinychannels_session_key,+ "tinychannelsSessionKey": session_key,"sourceEvent": descriptor.source,"success": descriptor.success,"elapsedMs": descriptor.elapsed_ms,@@ -423,14 +453,7 @@ fn persist_channel_turn(Ok(())}-fn tinychannels_session_key(envelope: &tinychannels_bus::ChannelInboundEnvelope) -> String {- tinychannels_runtime::channel::build_session_key_for_inbound_envelope(- "main",- envelope,- tinychannels_bus::channel::SessionKeyPolicy::default(),- )-}-+#[cfg(test)]fn persisted_channel_thread_id(channel: &str,sender: &str,