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 presentation, progress bridge, and suggestions modules

Steven Enamakel00a01be65d30
diff --git a/crates/openhuman-core/src/web_chat/presentation.rs b/crates/openhuman-core/src/web_chat/presentation.rs
index 89d36e7a10..1a97db870a 100644
--- a/crates/openhuman-core/src/web_chat/presentation.rs
+++ b/crates/openhuman-core/src/web_chat/presentation.rs
@@ -156,6 +156,7 @@ pub(crate) fn announce_reply(
let timing_payload =
timing.map(|snapshot| snapshot.into_payload(usage.map(|u| u.output_tokens)));
publish_chat_done(
+ ctx,
client_id,
thread_id,
request_id,
@@ -186,6 +187,7 @@ pub(crate) fn announce_reply(
/// segment beside that single row (#5933), so the conversational segmentation
/// of [`deliver_response`] is deliberately not offered here.
pub(crate) fn deliver_response_single_bubble(
+ ctx: &crate::core::runtime::DispatchCtx,
client_id: &str,
thread_id: &str,
request_id: &str,
@@ -193,6 +195,7 @@ pub(crate) fn deliver_response_single_bubble(
usage: Option<&LastTurnUsage>,
) {
publish_chat_done(
+ ctx,
client_id,
thread_id,
request_id,
@@ -207,6 +210,7 @@ pub(crate) fn deliver_response_single_bubble(
/// Emit the terminal `chat_done` for an unsegmented reply.
fn publish_chat_done(
+ ctx: &crate::core::runtime::DispatchCtx,
client_id: &str,
thread_id: &str,
request_id: &str,
@@ -215,7 +219,7 @@ fn publish_chat_done(
usage_payload: Option<TurnUsagePayload>,
timing_payload: Option<crate::web_chat::TurnTimingPayload>,
) {
- publish_web_channel_event(WebChannelEvent {
+ publish_web_channel_event(ctx, WebChannelEvent {
event: "chat_done".to_string(),
client_id: client_id.to_string(),
thread_id: thread_id.to_string(),
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rs
index b86177f08e..93a83effd3 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs
@@ -95,6 +95,7 @@ impl ProgressBridgeHandle {
/// vanishing when the turn settles. Clears `buffer` unconditionally; emits
/// nothing for narration that is empty or too short to stand alone.
fn flush_interim_narration(
+ ctx: &crate::core::runtime::DispatchCtx,
buffer: &mut String,
round: u32,
client_id: &str,
@@ -113,6 +114,7 @@ fn flush_interim_narration(
request_id,
);
publish_seq_stamped(
+ ctx,
emit_seq,
WebChannelEvent {
event: "chat_interim".to_string(),
@@ -133,10 +135,14 @@ fn flush_interim_narration(
/// identically to the persisted turn-state snapshot
/// (conversations-timeline-refactor, Phase 4). The counter advances once per
/// emitted event so each `(request_id, seq)` pair is unique within a turn.
-fn publish_seq_stamped(next_seq: &mut u64, mut event: WebChannelEvent) {
+fn publish_seq_stamped(
+ ctx: &crate::core::runtime::DispatchCtx,
+ next_seq: &mut u64,
+ mut event: WebChannelEvent,
+) {
event.seq = Some(*next_seq);
*next_seq = next_seq.saturating_add(1);
- publish_web_channel_event(event);
+ publish_web_channel_event(ctx, event);
}
/// The trimmed narration to surface as an interim bubble, or `None` when it is
@@ -364,7 +370,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id,
request_id,
);
- publish_seq_stamped(&mut emit_seq, WebChannelEvent {
+ publish_seq_stamped(&dispatch_ctx, &mut emit_seq, WebChannelEvent {
event: "inference_heartbeat".to_string(),
client_id: client_id.clone(),
thread_id: thread_id.clone(),
@@ -499,6 +505,7 @@ pub(crate) fn spawn_progress_bridge(
},
);
publish_seq_stamped(
+ &dispatch_ctx,
&mut emit_seq,
WebChannelEvent {
event: "inference_start".to_string(),
@@ -516,6 +523,7 @@ pub(crate) fn spawn_progress_bridge(
round = iteration;
parent_max_iterations = max_iterations;
publish_seq_stamped(
+ &dispatch_ctx,
&mut emit_seq,
WebChannelEvent {
event: "iteration_start".to_string(),
@@ -570,6 +578,7 @@ pub(crate) fn spawn_progress_bridge(
},
);
publish_seq_stamped(
+ &dispatch_ctx,
&mut emit_seq,
WebChannelEvent {
event: "tool_call".to_string(),
@@ -631,6 +640,7 @@ pub(crate) fn spawn_progress_bridge(
request_id
);
publish_seq_stamped(
+ &dispatch_ctx,
&mut emit_seq,
WebChannelEvent {
event: "tool_result".to_string(),
@@ -940,6 +950,7 @@ pub(crate) fn spawn_progress_bridge(
}
AgentProgress::ThinkingDelta { delta, iteration } => {
publish_seq_stamped(
+ &dispatch_ctx,
&mut emit_seq,
WebChannelEvent {
event: "thinking_delta".to_string(),
@@ -960,6 +971,7 @@ pub(crate) fn spawn_progress_bridge(
iteration,
} => {
publish_seq_stamped(
+ &dispatch_ctx,
&mut emit_seq,
WebChannelEvent {
event: "tool_args_delta".to_string(),
diff --git a/crates/openhuman-core/src/web_chat/suggestions.rs b/crates/openhuman-core/src/web_chat/suggestions.rs
index b7a33e41bc..c21f7a43d5 100644
--- a/crates/openhuman-core/src/web_chat/suggestions.rs
+++ b/crates/openhuman-core/src/web_chat/suggestions.rs
@@ -189,7 +189,7 @@ async fn generate_and_emit(
request_id={request_id} count={}",
suggestions.len()
);
- publish_web_channel_event(WebChannelEvent {
+ publish_web_channel_event(ctx, WebChannelEvent {
event: "chat_suggestions".to_string(),
client_id: client_id.to_string(),
thread_id: thread_id.to_string(),