Skip to content

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

refactor(channels): migrate inbound dispatch to structured message fields

Steven Enamakel977c1f0a5402
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch.rs b/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch.rs
index 64ee0bbd7b..15e5413ccc 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch.rs
@@ -3,6 +3,7 @@
use super::processor::AdmittedInbound;
use crate::inbound_debounce::DebounceItem;
+use tinychannels_bus::channel::ContentPart;
const MEDIA_MARKERS: [&str; 5] = ["[IMAGE:", "[FILE:", "[VIDEO:", "[DOCUMENT:", "[Attachment:"];
@@ -15,16 +16,16 @@ pub(crate) struct QueuedInbound {
impl DebounceItem for QueuedInbound {
fn chars(&self) -> usize {
- self.inbound.msg.content.chars().count()
+ self.inbound.msg.text.chars().count()
}
fn carries_media(&self) -> bool {
- let content = &self.inbound.msg.content;
+ let content = &self.inbound.msg.text;
MEDIA_MARKERS.iter().any(|marker| content.contains(marker))
}
fn mergeable(&self) -> bool {
- let trimmed = self.inbound.msg.content.trim_start();
+ let trimmed = self.inbound.msg.text.trim_start();
!trimmed.is_empty() && !trimmed.starts_with('/')
}
}
@@ -33,27 +34,48 @@ impl DebounceItem for QueuedInbound {
/// addressed like the newest message, with the non-blank bodies joined by
/// newlines.
pub(crate) fn merge_channel_batch(mut batch: Vec<QueuedInbound>) -> Option<AdmittedInbound> {
- batch.sort_by_key(|item| (item.inbound.msg.timestamp, item.seq));
+ batch.sort_by_key(|item| {
+ (
+ item.inbound.msg.timestamp_unix_ms.unwrap_or_default(),
+ item.seq,
+ )
+ });
if batch.len() <= 1 {
return batch.pop().map(|item| item.inbound);
}
let sender_name = batch
.iter()
.rev()
- .find_map(|item| item.inbound.msg.sender_name.clone());
+ .find_map(|item| item.inbound.msg.sender.name.clone());
let content = batch
.iter()
- .map(|item| item.inbound.msg.content.as_str())
+ .map(|item| item.inbound.msg.text.as_str())
.filter(|content| !content.trim().is_empty())
.collect::<Vec<_>>()
.join("\n");
+ let mut parts = Vec::new();
+ let mut has_content = false;
+ for item in &batch {
+ if item.inbound.msg.text.trim().is_empty() {
+ continue;
+ }
+ if has_content {
+ parts.push(ContentPart::Text {
+ text: "\n".into(),
+ markdown_dialect: None,
+ });
+ }
+ parts.extend(item.inbound.msg.parts.iter().cloned());
+ has_content = true;
+ }
let count = batch.len();
let mut merged = batch.pop()?.inbound;
- merged.msg.content = content;
- merged.msg.sender_name = sender_name;
+ merged.msg.text = content;
+ merged.msg.parts = parts;
+ merged.msg.sender.name = sender_name;
tracing::debug!(
- channel = %merged.msg.channel,
- message_id = %merged.msg.id,
+ channel = %merged.msg.channel.id,
+ message_id = %merged.msg.message_id,
merged = count,
"[dispatch][debounce] merged inbound batch"
);
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor.rs
index 7b7f893fe4..d71268d328 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor.rs
@@ -212,9 +212,9 @@ fn buffer_admitted(
seq: u64,
inbound: AdmittedInbound,
) {
- let settings = debounce.settings_for(&inbound.msg.channel);
- let channel = inbound.msg.channel.clone();
- let reply_target = inbound.msg.reply_target.clone();
+ let settings = debounce.settings_for(&inbound.msg.channel.id);
+ let channel = inbound.msg.channel.id.clone();
+ let reply_target = inbound.msg.conversation.id.clone();
let key = inbound.history_key.clone();
let push = debouncer.push(
key,