Skip to content

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

feat(web_chat): add channel event types and event bus

Steven Enamakel54b5b9ec1750
diff --git a/crates/openhuman-core/src/web_chat/channel_event.rs b/crates/openhuman-core/src/web_chat/channel_event.rs
index ff186f985c..05c815f499 100644
--- a/crates/openhuman-core/src/web_chat/channel_event.rs
+++ b/crates/openhuman-core/src/web_chat/channel_event.rs
@@ -248,6 +248,21 @@ impl WebChannelEvent {
pub fn belongs_to_profile(&self, profile: &str) -> bool {
self.profile.as_deref() == Some(profile)
}
+
+ /// Stamp the tenant whose work produced this event where the publisher
+ /// left it unset. A SaaS task with no scope (`None`) stamps nothing, so
+ /// the event reaches no user's stream.
+ pub fn stamp_tenant(&mut self, tenant: Option<crate::core::runtime::Tenant>) {
+ let Some(tenant) = tenant else {
+ return;
+ };
+ if self.agent.is_none() {
+ self.agent = tenant.agent;
+ }
+ if self.profile.is_none() {
+ self.profile = tenant.profile;
+ }
+ }
}
/// Time-to-first-visible timing summary for a completed turn. See
diff --git a/crates/openhuman-core/src/web_chat/event_bus.rs b/crates/openhuman-core/src/web_chat/event_bus.rs
index 5f97531d7d..5a9adfdbe6 100644
--- a/crates/openhuman-core/src/web_chat/event_bus.rs
+++ b/crates/openhuman-core/src/web_chat/event_bus.rs
@@ -29,28 +29,10 @@ pub fn publish_web_channel_event(mut event: WebChannelEvent) {
if event.ts.is_none() {
event.ts = Some(crate::web_chat::progress_bridge::unix_epoch_ms());
}
- stamp_tenant(&mut event, crate::core::runtime::current_tenant().ok());
+ event.stamp_tenant(crate::core::runtime::current_tenant().ok());
let _ = EVENT_BUS.send(event);
}
-/// Stamp `event` with the tenant whose work produced it, where the publisher
-/// left it unset. A SaaS task with no scope (`None`) stamps nothing, so the
-/// event reaches no user's stream.
-pub(crate) fn stamp_tenant(
- event: &mut WebChannelEvent,
- tenant: Option<crate::core::runtime::Tenant>,
-) {
- let Some(tenant) = tenant else {
- return;
- };
- if event.agent.is_none() {
- event.agent = tenant.agent;
- }
- if event.profile.is_none() {
- event.profile = tenant.profile;
- }
-}
-
static APPROVAL_SURFACE_HANDLE: OnceLock<SubscriptionHandle> = OnceLock::new();
pub fn register_approval_surface_subscriber() {