Skip to content

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

feat(web_chat): stamp channel events with their owning agent

Steven Enamakel98048a526056
diff --git a/crates/openhuman-core/src/web_chat/channel_event.rs b/crates/openhuman-core/src/web_chat/channel_event.rs
index 3444c05a64..89d747ae47 100644
--- a/crates/openhuman-core/src/web_chat/channel_event.rs
+++ b/crates/openhuman-core/src/web_chat/channel_event.rs
@@ -13,6 +13,11 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct WebChannelEvent {
+ /// The agent whose work produced this event (`CoreContext::session_agent`),
+ /// stamped at publish time. Never serialized: it routes the event to its
+ /// owner's stream in SaaS mode and is not part of the wire payload.
+ #[serde(skip)]
+ pub agent: Option<String>,
/// The event name (e.g., `chat_message`, `tool_call`).
pub event: String,
/// Unique identifier for the Socket.IO client.
diff --git a/crates/openhuman-core/src/web_chat/event_bus.rs b/crates/openhuman-core/src/web_chat/event_bus.rs
index 2560e4684f..9d6191512e 100644
--- a/crates/openhuman-core/src/web_chat/event_bus.rs
+++ b/crates/openhuman-core/src/web_chat/event_bus.rs
@@ -29,9 +29,20 @@ 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());
}
+ if event.agent.is_none() {
+ event.agent = crate::core::runtime::CoreContext::current()
+ .and_then(|context| context.session_agent().map(str::to_owned));
+ }
let _ = EVENT_BUS.send(event);
}
+/// Whether a SaaS user agent's stream may carry `event`: only events stamped
+/// with that agent. An unstamped event (published outside any agent scope) is
+/// dropped rather than guessed at.
+pub fn event_belongs_to(event: &WebChannelEvent, agent: &str) -> bool {
+ event.agent.as_deref() == Some(agent)
+}
+
static APPROVAL_SURFACE_HANDLE: OnceLock<SubscriptionHandle> = OnceLock::new();
pub fn register_approval_surface_subscriber() {