Skip to content

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

refactor(web_chat): split progress bridge into focused modules

Steven Enamakelcba276798fa1
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rs
index 431ffc546a..61cf672675 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs
@@ -692,6 +692,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id: &thread_id,
request_id: &request_id,
config: &config,
+ dispatch: &dispatch_ctx,
};
subagent_events::on_subagent_spawned(
&ctx,
@@ -726,6 +727,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id: &thread_id,
request_id: &request_id,
config: &config,
+ dispatch: &dispatch_ctx,
};
subagent_events::on_subagent_completed(
&ctx,
@@ -755,6 +757,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id: &thread_id,
request_id: &request_id,
config: &config,
+ dispatch: &dispatch_ctx,
};
subagent_events::on_subagent_failed(
&ctx,
@@ -779,6 +782,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id: &thread_id,
request_id: &request_id,
config: &config,
+ dispatch: &dispatch_ctx,
};
subagent_events::on_subagent_awaiting_user(
&ctx,
@@ -804,6 +808,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id: &thread_id,
request_id: &request_id,
config: &config,
+ dispatch: &dispatch_ctx,
};
subagent_events::on_subagent_iteration_started(
&ctx,
@@ -831,6 +836,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id: &thread_id,
request_id: &request_id,
config: &config,
+ dispatch: &dispatch_ctx,
};
subagent_events::on_subagent_tool_call_started(
&ctx,
@@ -868,6 +874,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id: &thread_id,
request_id: &request_id,
config: &config,
+ dispatch: &dispatch_ctx,
};
subagent_events::on_subagent_tool_call_completed(
&ctx,
@@ -900,6 +907,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id: &thread_id,
request_id: &request_id,
config: &config,
+ dispatch: &dispatch_ctx,
};
subagent_events::on_subagent_text_delta(
&ctx,
@@ -922,6 +930,7 @@ pub(crate) fn spawn_progress_bridge(
thread_id: &thread_id,
request_id: &request_id,
config: &config,
+ dispatch: &dispatch_ctx,
};
subagent_events::on_subagent_thinking_delta(
&ctx,
@@ -940,6 +949,7 @@ pub(crate) fn spawn_progress_bridge(
pending_narration.push_str(&delta);
if !metadata.hold_text_stream {
text_events::publish_text_delta(
+ &dispatch_ctx,
&mut emit_seq,
&client_id,
&thread_id,
@@ -1111,7 +1121,7 @@ pub(crate) fn spawn_progress_bridge(
}
AgentProgress::ToolCallProgress { call_id, message } => {
let ids = (client_id.as_str(), thread_id.as_str(), request_id.as_str());
- tool_progress::publish(&mut emit_seq, ids, call_id, message);
+ tool_progress::publish(&dispatch_ctx, &mut emit_seq, ids, call_id, message);
}
AgentProgress::TurnContent { .. } => {
// Prompt/reply content is attached to the trace span by the
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge_subagent_events.rs b/crates/openhuman-core/src/web_chat/progress_bridge_subagent_events.rs
index bf41040bd8..b62af4f2b8 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge_subagent_events.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge_subagent_events.rs
@@ -29,6 +29,7 @@ pub(super) struct BridgeCtx<'a> {
pub(super) thread_id: &'a str,
pub(super) request_id: &'a str,
pub(super) config: &'a crate::config::Config,
+ pub(super) dispatch: &'a crate::core::runtime::DispatchCtx,
}
pub(super) fn on_subagent_spawned(
@@ -101,6 +102,7 @@ pub(super) fn on_subagent_spawned(
},
);
publish_seq_stamped(
+ ctx.dispatch,
emit_seq,
WebChannelEvent {
event: "subagent_spawned".to_string(),
@@ -195,6 +197,7 @@ pub(super) fn on_subagent_completed(
},
);
publish_seq_stamped(
+ ctx.dispatch,
emit_seq,
WebChannelEvent {
event: "subagent_completed".to_string(),
@@ -288,6 +291,7 @@ pub(super) fn on_subagent_failed(
},
);
publish_seq_stamped(
+ ctx.dispatch,
emit_seq,
WebChannelEvent {
event: "subagent_failed".to_string(),
@@ -376,6 +380,7 @@ pub(super) fn on_subagent_awaiting_user(
},
);
publish_seq_stamped(
+ ctx.dispatch,
emit_seq,
WebChannelEvent {
event: "subagent_awaiting_user".to_string(),
@@ -408,6 +413,7 @@ pub(super) fn on_subagent_iteration_started(
extended_policy: bool,
) {
publish_seq_stamped(
+ ctx.dispatch,
emit_seq,
WebChannelEvent {
event: "subagent_iteration_start".to_string(),
@@ -475,6 +481,7 @@ pub(super) fn on_subagent_tool_call_started(
},
);
publish_seq_stamped(
+ ctx.dispatch,
emit_seq,
WebChannelEvent {
event: "subagent_tool_call".to_string(),
@@ -548,6 +555,7 @@ pub(super) fn on_subagent_tool_call_completed(
},
);
publish_seq_stamped(
+ ctx.dispatch,
emit_seq,
WebChannelEvent {
event: "subagent_tool_result".to_string(),
@@ -593,6 +601,7 @@ pub(super) fn on_subagent_text_delta(
iteration: u32,
) {
publish_seq_stamped(
+ ctx.dispatch,
emit_seq,
WebChannelEvent {
event: "subagent_text_delta".to_string(),
@@ -624,6 +633,7 @@ pub(super) fn on_subagent_thinking_delta(
iteration: u32,
) {
publish_seq_stamped(
+ ctx.dispatch,
emit_seq,
WebChannelEvent {
event: "subagent_thinking_delta".to_string(),
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge_text_events.rs b/crates/openhuman-core/src/web_chat/progress_bridge_text_events.rs
index 8e7d88f81c..bc91c1d237 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge_text_events.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge_text_events.rs
@@ -6,6 +6,7 @@
use crate::web_chat::WebChannelEvent;
pub(super) fn publish_text_delta(
+ dispatch: &crate::core::runtime::DispatchCtx,
emit_seq: &mut u64,
client_id: &str,
thread_id: &str,
@@ -14,6 +15,7 @@ pub(super) fn publish_text_delta(
delta: String,
) {
super::publish_seq_stamped(
+ dispatch,
emit_seq,
WebChannelEvent {
event: "text_delta".to_string(),
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge_tool_progress.rs b/crates/openhuman-core/src/web_chat/progress_bridge_tool_progress.rs
index d5c5fbca27..5d70129bc2 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge_tool_progress.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge_tool_progress.rs
@@ -10,6 +10,7 @@ use crate::web_chat::WebChannelEvent;
/// Publish one status line for the running call `call_id`. `ids` is
/// `(client_id, thread_id, request_id)`.
pub(super) fn publish(
+ dispatch: &crate::core::runtime::DispatchCtx,
emit_seq: &mut u64,
(client_id, thread_id, request_id): (&str, &str, &str),
call_id: String,
@@ -17,6 +18,7 @@ pub(super) fn publish(
) {
log::trace!("[web_channel][bridge] tool_progress call_id={call_id} request_id={request_id}");
super::publish_seq_stamped(
+ dispatch,
emit_seq,
WebChannelEvent {
event: "tool_progress".to_string(),