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
chore: files changed crates/openhuman-core/src/channels/runtime/startup/callback.rs,crates/openhuman
Steven Enamakeld2a89655daa3
diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback.rs b/crates/openhuman-core/src/channels/runtime/startup/callback.rsindex e46a926e1f..fd2ecc77f2 100644--- a/crates/openhuman-core/src/channels/runtime/startup/callback.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/callback.rs@@ -30,6 +30,18 @@ pub(super) trait ProgressiveChannelTransport: Send + Sync {) -> Result<ProgressiveTransportResult>;}+#[async_trait::async_trait]+pub(super) trait ProgressiveOutputObserver: Send + Sync {+ async fn observe(+ &self,+ channel: &tinychannels_bus::ChannelRef,+ conversation: &tinychannels_bus::ConversationRef,+ turn_id: &str,+ sequence: u64,+ event: &tinychannels_bus::module_progressive::ChannelOutputEvent,+ ) -> Result<()>;+}+/// Callbacks capture one immutable host config and a weak runtime context./// The weak reference avoids a cycle from runtime context -> module channel ->/// lease -> TinyBus connection -> callback -> runtime context.@@ -40,6 +52,7 @@ pub(super) struct ChannelHostCallbacks {cancellation: tokio_util::sync::CancellationToken,context: Arc<OnceLock<Weak<ChannelRuntimeContext>>>,progressive_channels: Arc<OnceLock<Arc<HashMap<String, Arc<dyn ProgressiveChannelTransport>>>>>,+ output_observer: Option<Arc<dyn ProgressiveOutputObserver>>,dispatch: mpsc::Sender<RuntimeChannelMessage>,}@@ -51,6 +64,7 @@ impl ChannelHostCallbacks {progressive_channels: Arc<OnceLock<Arc<HashMap<String, Arc<dyn ProgressiveChannelTransport>>>>,>,+ output_observer: Option<Arc<dyn ProgressiveOutputObserver>>,dispatch: mpsc::Sender<RuntimeChannelMessage>,) -> Self {Self {@@ -63,6 +77,7 @@ impl ChannelHostCallbacks {cancellation: crate::channels::runtime::session::channel_session(),context,progressive_channels,+ output_observer,dispatch,}}@@ -269,41 +284,27 @@ impl ChannelHostCallbacks {request: ProgressiveTransportRequest,) -> Result<ProgressiveTransportResult> {if let ProgressiveTransportRequest::OutputEvent {- channel_ref: Some(channel),- conversation: Some(conversation),- turn_id: Some(turn_id),+ channel_ref,+ conversation,+ turn_id,sequence,event,..} = &request{- let event_kind = serde_json::to_value(event.as_ref())- .ok()- .and_then(|value| {- value- .get("type")- .and_then(serde_json::Value::as_str)- .map(str::to_owned)- })- .ok_or_else(|| Error::failed("invalid progressive output event"))?;- let publication = crate::core::events::DomainEvent::ChannelOutputObserved {- channel: channel.clone(),- conversation: conversation.clone(),- turn_id: turn_id.clone(),- sequence: *sequence,- event_kind,- };- let publish = async {- crate::core::bus::BUS.publish(publication);- Ok(ProgressiveTransportResult::Acknowledged)- };- return match &self.core_context {- Some(core_context) => {- crate::core::runtime::CoreContext::scope(Arc::clone(core_context), publish)- .await- }- None => publish.await,- };+ let channel = channel_ref+ .as_ref()+ .ok_or_else(|| Error::failed("progressive output channel identity is required"))?;+ let conversation = conversation.as_ref().ok_or_else(|| {+ Error::failed("progressive output conversation identity is required")+ })?;+ let turn_id = turn_id+ .as_deref()+ .ok_or_else(|| Error::failed("progressive output turn identity is required"))?;+ if let Some(observer) = &self.output_observer {+ observer.observe(channel, conversation, turn_id, *sequence, event).await?;+ }+ return Ok(ProgressiveTransportResult::Acknowledged);}let (channel, channel_ref) = match &request {ProgressiveTransportRequest::OutputEvent {diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rsindex 23c6240bc6..087a392b78 100644--- a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs@@ -10,7 +10,7 @@ use tinychannels_bus::channel::{ChannelOutboundMessage, ChannelSendOutcome, MessageReceipt, OutboundContentPart,};use tinychannels_bus::module_progressive::{- ProgressiveTransportRequest, ProgressiveTransportResult,+ ChannelOutputEvent, ProgressiveTransportRequest, ProgressiveTransportResult,};use tinychannels_bus::{ChannelBackendRequest, ChannelBackendResult, SendMessage};@@ -151,6 +151,7 @@ fn callback_for_channels(Arc::new(crate::config::Config::default()),context_slot,progressive_slot,+ None,dispatch,),context,@@ -323,3 +324,35 @@ async fn native_progressive_transport_rejects_unconfigured_account_without_proviassert!(first_account.sent.lock().await.is_empty());assert!(second_account.sent.lock().await.is_empty());}++#[tokio::test]+async fn native_progressive_output_event_is_acknowledged_by_optional_host_observer() {+ let (callback, _context) = callback_for_channels(HashMap::new(), HashMap::new());+ let result = callback+ .dispatch_controller_backend(ChannelBackendRequest::ProgressiveTransport(Box::new(+ ProgressiveTransportRequest::OutputEvent {+ channel: "telegram:bot-b".into(),+ turn_id: Some("turn-13".into()),+ channel_ref: Some(tinychannels_bus::ChannelRef {+ id: "telegram".into(),+ account_id: Some("telegram:bot-b".into()),+ }),+ conversation: Some(tinychannels_bus::ConversationRef {+ id: "chat-42".into(),+ thread_id: Some("topic-9".into()),+ ..Default::default()+ }),+ sequence: 4,+ event: Box::new(ChannelOutputEvent::TextDelta {+ text: "working".into(),+ iteration: Some(1),+ }),+ },+ )))+ .await+ .expect("an unobserved native progress event is accepted by the host");+ let ChannelBackendResult::ProgressiveTransport(result) = result else {+ panic!("expected progressive transport result");+ };+ assert!(matches!(*result, ProgressiveTransportResult::Acknowledged));+}diff --git a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rsindex fd567afbe2..e712d08b5d 100644--- a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs@@ -79,6 +79,7 @@ impl ModuleChannelRuntime {Arc::clone(&config),context,Arc::clone(&progressive_channels),+ None,dispatch,);let lease = ChannelRuntimeLease::open(client.clone(), callback)diff --git a/crates/openhuman-core/src/channels/runtime/startup/progressive_transport.rs b/crates/openhuman-core/src/channels/runtime/startup/progressive_transport.rsindex ba418b065e..dedc389ea4 100644--- a/crates/openhuman-core/src/channels/runtime/startup/progressive_transport.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/progressive_transport.rs@@ -180,7 +180,7 @@ impl ProgressiveChannelTransport for ModuleChannel {.map_err(|_| tinybus::Error::failed("progressive typing callback failed"))?;Ok(Result::Acknowledged)}- Request::OutputEvent { .. } => Ok(Result::Unavailable),+ Request::OutputEvent { .. } => Ok(Result::Acknowledged),}}}