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): persist channel activity on projected messages
Steven Enamakela4bf9d2eb16b
diff --git a/crates/openhuman-core/src/channels/host/adapters.rs b/crates/openhuman-core/src/channels/host/adapters.rsindex fc5d2a8b45..6af8525e74 100644--- a/crates/openhuman-core/src/channels/host/adapters.rs+++ b/crates/openhuman-core/src/channels/host/adapters.rs@@ -343,7 +343,7 @@ impl OpenHumanEventSink {if domain == "channel" && kind == "channel_event" {let event: tinychannels_bus::ChannelEvent = serde_json::from_value(payload).map_err(|error| anyhow::anyhow!("invalid typed channel event: {error}"))?;- if let Some(projected) = project_channel_event(ctx, event)+ if let Some(projected) = project_channel_event(ctx, event).await.map_err(|error| anyhow::anyhow!("project typed channel event: {error}"))?{crate::web_chat::publish_web_channel_event_in(ctx, projected);@@ -354,7 +354,7 @@ impl OpenHumanEventSink {}}-fn project_channel_event(+async fn project_channel_event(ctx: &crate::core::runtime::DispatchCtx,event: tinychannels_bus::ChannelEvent,) -> Result<Option<crate::web_chat::WebChannelEvent>, String> {@@ -376,6 +376,7 @@ fn project_channel_event(return Ok(None);};+ crate::threads::channel_projection::persist_activity(ctx, &target, &event).await?;Ok(Some(crate::web_chat::WebChannelEvent::ChannelEvent {context: crate::web_chat::event_context("channel-runtime",diff --git a/crates/openhuman-core/src/threads/channel_projection.rs b/crates/openhuman-core/src/threads/channel_projection.rsindex 4869aa88d4..493d8cdfcc 100644--- a/crates/openhuman-core/src/threads/channel_projection.rs+++ b/crates/openhuman-core/src/threads/channel_projection.rs@@ -174,7 +174,7 @@ pub(crate) fn resolve_message(/// Persist provider read/reaction state onto the exact OpenHuman message row./// The caller already resolved the provider receipt through the durable,/// tenant-scoped binding; no message id is inferred here.-pub(crate) fn persist_activity(+pub(crate) async fn persist_activity(ctx: &DispatchCtx,target: &ProjectedMessageTarget,event: &tinychannels_bus::ChannelEvent,@@ -191,6 +191,7 @@ pub(crate) fn persist_activity(workspace.clone(),target.thread_id.clone(),)+ .await.map_err(|error| anyhow!("read projected thread: {error}"))?;let Some(message) = messages.iter().find(|message| message.id == target.row_id) else {return Err(anyhow!("bound OpenHuman message row no longer exists"));@@ -205,6 +206,7 @@ pub(crate) fn persist_activity(extra_metadata: Some(metadata),},)+ .await.map_err(|error| anyhow!("persist channel activity: {error}"))?;Ok(())})();diff --git a/crates/openhuman-core/src/threads/channel_projection_tests.rs b/crates/openhuman-core/src/threads/channel_projection_tests.rsindex b70edeecdf..dec1aa7861 100644--- a/crates/openhuman-core/src/threads/channel_projection_tests.rs+++ b/crates/openhuman-core/src/threads/channel_projection_tests.rs@@ -151,3 +151,61 @@ fn sender_scoped_threads_can_share_a_conversation_without_overwriting() {);assert!(bind_in(&repo, alice, "channel:other").is_err());}++#[test]+fn channel_activity_metadata_applies_reaction_changes_and_read_receipts() {+ use tinychannels_bus::{ChannelEvent, ChannelEventKind, ChannelReaction, ChannelRef};++ let event = |kind| ChannelEvent {+ version: 2,+ event_id: "outer-event-id".into(),+ source_event_id: None,+ source_timestamp: None,+ channel: ChannelRef {+ id: "telegram".into(),+ account_id: Some("account".into()),+ },+ conversation: None,+ event: kind,+ };+ let reaction = ChannelReaction {+ value: "🔥".into(),+ custom_emoji_id: None,+ };+ let added = event(ChannelEventKind::ReactionAdded {+ message_id: "provider-target".into(),+ provider_message_id: None,+ actor: tinychannels_bus::SenderRef {+ id: "alice".into(),+ ..Default::default()+ },+ reaction: reaction.clone(),+ });+ let metadata = channel_activity_metadata(&json!({"existing": true}), &added).unwrap();+ let metadata = channel_activity_metadata(&metadata, &added).unwrap();+ assert_eq!(metadata["existing"], true);+ assert_eq!(metadata["channelActivity"]["reactions"].as_array().unwrap().len(), 1);++ let read = event(ChannelEventKind::ReadReceipt {+ message_id: "provider-target".into(),+ actor: Some(tinychannels_bus::SenderRef {+ id: "bob".into(),+ ..Default::default()+ }),+ timestamp: Some(42),+ });+ let metadata = channel_activity_metadata(&metadata, &read).unwrap();+ assert_eq!(metadata["channelActivity"]["readReceipts"][0]["actorId"], "bob");++ let removed = event(ChannelEventKind::ReactionRemoved {+ message_id: "provider-target".into(),+ provider_message_id: None,+ actor: tinychannels_bus::SenderRef {+ id: "alice".into(),+ ..Default::default()+ },+ reaction,+ });+ let metadata = channel_activity_metadata(&metadata, &removed).unwrap();+ assert!(metadata["channelActivity"]["reactions"].as_array().unwrap().is_empty());+}