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(web_chat): add web chat module with threads and event bus
Steven Enamakelf5098c3a0da4
diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rsindex 14ef326587..5598119986 100644--- a/crates/openhuman-core/src/threads/ops/crud.rs+++ b/crates/openhuman-core/src/threads/ops/crud.rs@@ -459,7 +459,7 @@ async fn thread_delete_inner(// returns early on error; if invalidation ran after, an active// session for the now-deleted thread could linger and try to// append to a thread index row that no longer exists.- web_channel::invalidate_thread_sessions(&request.thread_id).await;+ web_channel::invalidate_thread_sessions(ctx, &request.thread_id).await;// Cancel any detached sub-agents this thread spawned BEFORE clearing their// queued results: abort the in-flight ones first so a child can't record a// completion in the gap between the two calls, then discard anything alreadydiff --git a/crates/openhuman-core/src/threads/ops/edit.rs b/crates/openhuman-core/src/threads/ops/edit.rsindex bc734e5ccb..733eecb0ad 100644--- a/crates/openhuman-core/src/threads/ops/edit.rs+++ b/crates/openhuman-core/src/threads/ops/edit.rs@@ -89,7 +89,7 @@ pub async fn edit_message(let thread_id = request.thread_id;let dir = workspace_dir().await.map_err(ThreadsError::Message)?;- crate::web_chat::cancel_chat_scoped(&client_id, &thread_id, None)+ crate::web_chat::cancel_chat_scoped(ctx, &client_id, &thread_id, None).await.map_err(ThreadsError::Message)?;@@ -121,7 +121,7 @@ pub async fn edit_message(// it and everything after it is replaced by the fresh turn below.super::delete_after(ctx, &thread_id, &request.message_id).await?;- crate::web_chat::invalidate_thread_sessions(&thread_id).await;+ crate::web_chat::invalidate_thread_sessions(ctx, &thread_id).await;let new_request_id = crate::web_chat::start_chat(ctx,@@ -157,7 +157,7 @@ pub async fn regenerate(let thread_id = request.thread_id;let dir = workspace_dir().await.map_err(ThreadsError::Message)?;- crate::web_chat::cancel_chat_scoped(&client_id, &thread_id, None)+ crate::web_chat::cancel_chat_scoped(ctx, &client_id, &thread_id, None).await.map_err(ThreadsError::Message)?;@@ -192,7 +192,7 @@ pub async fn regenerate(clear_dropped_turn_states(&dir, &thread_id, &cut_request_id).await;super::delete_after(ctx, &thread_id, &run_reply_message_id(&cut_request_id)).await?;- crate::web_chat::invalidate_thread_sessions(&thread_id).await;+ crate::web_chat::invalidate_thread_sessions(ctx, &thread_id).await;let new_request_id = crate::web_chat::start_chat(ctx,diff --git a/crates/openhuman-core/src/web_chat/egress_surface.rs b/crates/openhuman-core/src/web_chat/egress_surface.rsindex 9616906e5e..5d526767f4 100644--- a/crates/openhuman-core/src/web_chat/egress_surface.rs+++ b/crates/openhuman-core/src/web_chat/egress_surface.rs@@ -12,7 +12,7 @@ use tinybus::{EventHandler, SubscriptionHandle};use crate::core::events::DomainEvent;use crate::web_chat::WebChannelEvent;-use super::event_bus::publish_web_channel_event;+use super::event_bus::publish_web_channel_event_in;static EGRESS_SURFACE_HANDLE: OnceLock<SubscriptionHandle> = OnceLock::new();diff --git a/crates/openhuman-core/src/web_chat/event_bus.rs b/crates/openhuman-core/src/web_chat/event_bus.rsindex c208529da6..1d367963dd 100644--- a/crates/openhuman-core/src/web_chat/event_bus.rs+++ b/crates/openhuman-core/src/web_chat/event_bus.rs@@ -26,7 +26,13 @@ pub fn subscribe_web_channel_events() -> broadcast::Receiver<WebChannelEvent> {/// `/events` stream, stamping `ts` (epoch ms) when the caller left it unset/// so every emitted event carries a wall-clock time the frontend can use for/// ordering/latency display without guessing at receive time.-pub fn publish_web_channel_event(ctx: &DispatchCtx, mut event: WebChannelEvent) {+pub fn publish_web_channel_event(event: WebChannelEvent) {+ publish_web_channel_event_in(&DispatchCtx::ambient(), event);+}++/// [`publish_web_channel_event`] with the tenant stamped from `ctx`: the one+/// the calling turn runs under, rather than the calling task's own scope.+pub fn publish_web_channel_event_in(ctx: &DispatchCtx, mut event: WebChannelEvent) {if event.ts.is_none() {event.ts = Some(crate::web_chat::progress_bridge::unix_epoch_ms());}diff --git a/crates/openhuman-core/src/web_chat/mod.rs b/crates/openhuman-core/src/web_chat/mod.rsindex 86a7f3665e..bb19365527 100644--- a/crates/openhuman-core/src/web_chat/mod.rs+++ b/crates/openhuman-core/src/web_chat/mod.rs@@ -62,7 +62,7 @@ pub use channel_event::{};pub use egress_surface::register_egress_surface_subscriber;pub use event_bus::{- approval_request_event, plan_review_request_event, publish_web_channel_event,+ approval_request_event, plan_review_request_event, publish_web_channel_event, publish_web_channel_event_in,register_agent_surface_subscriber, register_approval_surface_subscriber,register_artifact_surface_subscriber, register_memory_activity_surface_subscriber,subscribe_web_channel_events,diff --git a/crates/openhuman-core/src/web_chat/ops/channel_ops.rs b/crates/openhuman-core/src/web_chat/ops/channel_ops.rsindex 1f999d16eb..5bb30ff394 100644--- a/crates/openhuman-core/src/web_chat/ops/channel_ops.rs+++ b/crates/openhuman-core/src/web_chat/ops/channel_ops.rs@@ -8,7 +8,7 @@ use crate::core::runtime::DispatchCtx;use crate::core::Outcome;use crate::web_chat::WebChannelEvent;-use super::super::event_bus::publish_web_channel_event;+use super::super::event_bus::publish_web_channel_event_in;use super::super::types::ChatRequestMetadata;use super::parallel_turn::{cancel_parallel_turn_by_request_id, cancel_parallel_turns_for_thread};use super::start_chat::start_chat;diff --git a/crates/openhuman-core/src/web_chat/ops/parallel_turn.rs b/crates/openhuman-core/src/web_chat/ops/parallel_turn.rsindex c44752aa53..674ddd2cdb 100644--- a/crates/openhuman-core/src/web_chat/ops/parallel_turn.rs+++ b/crates/openhuman-core/src/web_chat/ops/parallel_turn.rs@@ -10,7 +10,7 @@ use tokio_util::sync::CancellationToken;use crate::web_chat::WebChannelEvent;-use super::super::event_bus::publish_web_channel_event;+use super::super::event_bus::publish_web_channel_event_in;use super::super::run_task::run_chat_task;use super::super::types::{ChatRequestMetadata, ParallelEntry};use super::super::web_errors::classify_inference_error;diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat.rs b/crates/openhuman-core/src/web_chat/ops/start_chat.rsindex 574a3a2d30..218e9d9764 100644--- a/crates/openhuman-core/src/web_chat/ops/start_chat.rs+++ b/crates/openhuman-core/src/web_chat/ops/start_chat.rs@@ -15,7 +15,7 @@ use crate::security::prompt_injection::{};use crate::web_chat::WebChannelEvent;-use super::super::event_bus::publish_web_channel_event;+use super::super::event_bus::publish_web_channel_event_in;use super::super::run_task::run_chat_task;use super::super::types::{ChatRequestMetadata, InFlightEntry, QueueMode};use super::super::web_errors::classify_inference_error;diff --git a/crates/openhuman-core/src/web_chat/presentation.rs b/crates/openhuman-core/src/web_chat/presentation.rsindex 0f59ad448a..af8d6e5200 100644--- a/crates/openhuman-core/src/web_chat/presentation.rs+++ b/crates/openhuman-core/src/web_chat/presentation.rs@@ -4,7 +4,7 @@use crate::agent::tinyagents::host::LastTurnUsage;use crate::web_chat::{SubagentUsagePayload, TurnUsagePayload, WebChannelEvent};-use super::publish_web_channel_event;+use super::publish_web_channel_event_in;/// Convert a turn's [`LastTurnUsage`] into the wire payload carried on/// `chat_done`. Returns `None` for a turn that recorded no spend at all (e.g. adiff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rsindex 40d9e60fe0..431ffc546a 100644--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs@@ -9,7 +9,7 @@ use crate::threads::turn_state::mirror::ObserveProgress;use crate::web_chat::{SubagentProgressDetail, WebChannelEvent};use tinyagents_session::{port::TurnStates, turn_state::TurnStateMirror};-use super::event_bus::publish_web_channel_event;+use super::event_bus::publish_web_channel_event_in;use super::types::ChatRequestMetadata;#[path = "progress_bridge_subagent_events.rs"]diff --git a/crates/openhuman-core/src/web_chat/suggestions.rs b/crates/openhuman-core/src/web_chat/suggestions.rsindex 99b3afc1d3..ea86ab1c46 100644--- a/crates/openhuman-core/src/web_chat/suggestions.rs+++ b/crates/openhuman-core/src/web_chat/suggestions.rs@@ -37,7 +37,7 @@ use tinyinference_llm::model::ModelRequest;use crate::inference::provider;use crate::web_chat::{ChatSuggestion, WebChannelEvent};-use super::publish_web_channel_event;+use super::publish_web_channel_event_in;/// Upper bound on the whole suggestions round-trip. A cheap `summarization`/// role call should complete in well under this; if it doesn't, the turn has