Skip to content

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

feat(web_chat): expose context and event name on ScopedWebEvent

Steven Enamakel3e902453a907
diff --git a/crates/openhuman-core/src/web_chat/channel_event.rs b/crates/openhuman-core/src/web_chat/channel_event.rs
index 113730f10a..64ceefaa70 100644
--- a/crates/openhuman-core/src/web_chat/channel_event.rs
+++ b/crates/openhuman-core/src/web_chat/channel_event.rs
@@ -52,6 +52,19 @@ impl ScopedWebEvent {
self.profile.as_deref() == Some(profile)
}
+ /// Addressing and ordering fields from the canonical TinyChannels event.
+ pub fn context(&self) -> &bus_web::WebEventContext {
+ self.event.context()
+ }
+
+ /// Historical Socket.IO discriminator for this canonical event.
+ pub fn event_name(&self) -> String {
+ serde_json::to_value(&self.event)
+ .ok()
+ .and_then(|value| value.get("event").and_then(serde_json::Value::as_str).map(str::to_owned))
+ .expect("typed web events always serialize an event discriminator")
+ }
+
/// Stamp routing metadata from the host execution context.
pub(crate) fn stamp_tenant(&mut self, tenant: Option<crate::core::runtime::Tenant>) {
let Some(tenant) = tenant else {
diff --git a/crates/openhuman-rpc/src/server/socketio.rs b/crates/openhuman-rpc/src/server/socketio.rs
index d7b36bb3de..bf50c43e18 100644
--- a/crates/openhuman-rpc/src/server/socketio.rs
+++ b/crates/openhuman-rpc/src/server/socketio.rs
@@ -37,7 +37,7 @@ use serde_json::Value;
use socketioxide::extract::{AckSender, Data, SocketRef, TryData};
use socketioxide::SocketIo;
-use crate::core_host::web_chat::{GuardrailPayload, WebChannelEvent};
+use crate::core_host::web_chat::{GuardrailPayload, ScopedWebEvent};
/// Shell-originated companion lifecycle events that still need to reach
/// Socket.IO-only surfaces such as the native macOS notch WKWebView.
@@ -1129,8 +1129,8 @@ fn join_room_logged(socket: &SocketRef, room: &str, client_id: &str) -> bool {
}
}
-fn emit_web_channel_event(io: &SocketIo, event: WebChannelEvent) {
- let name = event.event.clone();
+fn emit_web_channel_event(io: &SocketIo, event: ScopedWebEvent) {
+ let name = event.event_name();
// Deliver to the initiating client's own room AND the per-thread room. The
// thread room lets a socket that reconnected with a new client_id (after
// re-subscribing via `thread:subscribe`) keep receiving an in-flight turn's
@@ -1145,9 +1145,10 @@ fn emit_web_channel_event(io: &SocketIo, event: WebChannelEvent) {
// `client_id` room, then to the thread room EXCEPT the `client_id` room —
// each socket is reached exactly once regardless of room overlap.
// "system" broadcasts and events without a thread_id keep single-room delivery.
- let primary = event.client_id.clone();
- let thread_room = (event.client_id != "system" && !event.thread_id.is_empty())
- .then(|| format!("thread:{}", event.thread_id));
+ let context = event.context();
+ let primary = context.client_id.clone();
+ let thread_room = (context.client_id != "system" && !context.thread_id.is_empty())
+ .then(|| format!("thread:{}", context.thread_id));
if let Ok(payload) = serde_json::to_value(event) {
log::debug!(
"[socketio] send event={} primary={} thread_room={:?} thread_id={} request_id={}",