Skip to content

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

refactor(channels): use thread_ts or topic_id for reply thread

Steven Enamakelf6531b54257d
diff --git a/crates/openhuman-core/src/channels/routes.rs b/crates/openhuman-core/src/channels/routes.rs
index 0906b945a7..595c68787e 100644
--- a/crates/openhuman-core/src/channels/routes.rs
+++ b/crates/openhuman-core/src/channels/routes.rs
@@ -168,6 +168,7 @@ where
return false;
}
let current = get_route_selection(ctx, sender_key);
+ let reply_thread = msg.thread_ts.clone().or_else(|| msg.topic_id.clone());
let history_len =
durable_channel_history_len(ctx, &current, &msg.channel, durable_session_key.as_deref())
.await;
@@ -234,7 +235,7 @@ where
let _ = channel
.send_with_outbound_intent(
&SendMessage::new(&reply, &msg.reply_target)
- .in_thread(msg.thread_ts.clone()),
+ .in_thread(reply_thread.clone()),
)
.await;
}
@@ -248,6 +249,7 @@ where
let _ = channel
.send_with_outbound_intent(
&SendMessage::new(&copy, &msg.reply_target).in_thread(msg.thread_ts.clone()),
+ &SendMessage::new(&copy, &msg.reply_target).in_thread(reply_thread.clone()),
)
.await;
}
@@ -271,7 +273,7 @@ where
if let Some(channel) = target_channel {
if channel
.send_with_outbound_intent(
- &SendMessage::new(reply, &msg.reply_target).in_thread(msg.thread_ts.clone()),
+ &SendMessage::new(reply, &msg.reply_target).in_thread(reply_thread),
)
.await
.is_err()
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index 2f0de9968e..b4b4a181c5 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -83,9 +83,33 @@ async fn handle_linked_runtime_command(
let prepared = crate::modules::channel_controller::prepare_inbound(
&crate::channels::context::module_client(ctx).await,
PrepareChannelInboundRequest {
- source: ChannelInboundSource::Legacy {
- message: msg.clone(),
- envelope: None,
+ source: ChannelInboundSource::Envelope {
+ envelope: tinychannels_bus::ChannelInboundEnvelope {
+ channel: tinychannels_bus::ChannelRef {
+ id: msg.channel.clone(),
+ account_id: None,
+ },
+ message_id: msg.id.clone(),
+ reply_to_id: msg.reply_to_id.clone(),
+ conversation: tinychannels_bus::ConversationRef {
+ id: msg.reply_target.clone(),
+ topic_id: msg.topic_id.clone().or_else(|| msg.thread_ts.clone()),
+ ..Default::default()
+ },
+ sender: tinychannels_bus::SenderRef {
+ id: msg.sender.clone(),
+ name: msg.sender_name.clone(),
+ ..Default::default()
+ },
+ timestamp_unix_ms: Some(msg.timestamp.saturating_mul(1000)),
+ text: msg.content.clone(),
+ parts: vec![tinychannels_bus::ContentPart::Text {
+ text: msg.content.clone(),
+ markdown_dialect: None,
+ }],
+ ..Default::default()
+ },
+ timestamp: msg.timestamp,
},
namespace: "main".into(),
session_policy: Default::default(),