Skip to content

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

refactor(tui): route activity events through a WebEventView adapter

Steven Enamakelf74f3844230c
diff --git a/crates/openhuman-tui/src/activity.rs b/crates/openhuman-tui/src/activity.rs
index ef46008348..e8d2e3d182 100644
--- a/crates/openhuman-tui/src/activity.rs
+++ b/crates/openhuman-tui/src/activity.rs
@@ -1,6 +1,6 @@
//! Bounded, inspectable tool and child-run projections.
use super::theme::safe_text;
-use openhuman_rpc::embed::chat_surface::WebChannelEvent;
+use crate::event_view::WebEventView;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Status {
@@ -48,7 +48,7 @@ pub struct Activity {
}
impl Activity {
- pub fn from_event(id: String, event: &WebChannelEvent, child: bool) -> Self {
+ pub fn from_event(id: String, event: &WebEventView, child: bool) -> Self {
Self {
id,
label: safe_text(
@@ -67,7 +67,7 @@ impl Activity {
tools: 0,
}
}
- pub fn update(&mut self, event: &WebChannelEvent) {
+ pub fn update(&mut self, event: &WebEventView) {
if let Some(args) = &event.args {
self.args = bounded(&args.to_string(), 4096);
}
diff --git a/crates/openhuman-tui/src/event_view.rs b/crates/openhuman-tui/src/event_view.rs
new file mode 100644
index 0000000000..3cd5da860a
--- /dev/null
+++ b/crates/openhuman-tui/src/event_view.rs
@@ -0,0 +1,82 @@
+//! Small typed read model for the fields the terminal transcript displays.
+//!
+//! The wire contract remains TinyChannels' tagged `WebChannelEvent`; this is a
+//! consumer projection rather than another wire DTO.
+
+use openhuman_rpc::embed::chat_surface::WebChannelEvent;
+use serde_json::Value;
+
+#[derive(Debug, Clone, Default)]
+pub(crate) struct SubagentView {
+ pub task_id: Option<String>,
+ pub display_name: Option<String>,
+ pub elapsed_ms: Option<u64>,
+ pub output: Option<String>,
+}
+
+#[derive(Debug, Clone, Default)]
+pub(crate) struct WebEventView {
+ pub event: String,
+ pub client_id: String,
+ pub thread_id: String,
+ pub request_id: String,
+ pub seq: Option<u64>,
+ pub delta: Option<String>,
+ pub full_response: Option<String>,
+ pub message: Option<String>,
+ pub error_retryable: Option<bool>,
+ pub error_retry_after_ms: Option<u64>,
+ pub error_type: Option<String>,
+ pub output: Option<String>,
+ pub skill_id: Option<String>,
+ pub tool_call_id: Option<String>,
+ pub tool_name: Option<String>,
+ pub success: Option<bool>,
+ pub args: Option<Value>,
+ pub elapsed_ms: Option<u64>,
+ pub tool_display_label: Option<String>,
+ pub subagent: Option<SubagentView>,
+ pub failure: Option<Value>,
+}
+
+impl WebEventView {
+ pub(crate) fn from_event(event: &WebChannelEvent) -> Self {
+ let wire = serde_json::to_value(event).expect("typed web events serialize");
+ let context = event.context();
+ let string = |name: &str| wire.get(name).and_then(Value::as_str).map(str::to_owned);
+ let number = |name: &str| wire.get(name).and_then(Value::as_u64);
+ let boolean = |name: &str| wire.get(name).and_then(Value::as_bool);
+ let subagent = wire.get("subagent").map(|detail| SubagentView {
+ task_id: detail.get("task_id").and_then(Value::as_str).map(str::to_owned),
+ display_name: detail
+ .get("display_name")
+ .and_then(Value::as_str)
+ .map(str::to_owned),
+ elapsed_ms: detail.get("elapsed_ms").and_then(Value::as_u64),
+ output: detail.get("output").and_then(Value::as_str).map(str::to_owned),
+ });
+ Self {
+ event: event.event_name().to_owned(),
+ client_id: context.client_id.clone(),
+ thread_id: context.thread_id.clone(),
+ request_id: context.request_id.clone(),
+ seq: context.seq,
+ delta: string("delta"),
+ full_response: string("full_response"),
+ message: string("message"),
+ error_retryable: boolean("error_retryable"),
+ error_retry_after_ms: number("error_retry_after_ms"),
+ error_type: string("error_type"),
+ output: string("output"),
+ skill_id: string("skill_id"),
+ tool_call_id: string("tool_call_id"),
+ tool_name: string("tool_name"),
+ success: boolean("success"),
+ args: wire.get("args").cloned(),
+ elapsed_ms: number("elapsed_ms"),
+ tool_display_label: string("tool_display_label"),
+ subagent,
+ failure: wire.get("failure").cloned(),
+ }
+ }
+}
diff --git a/crates/openhuman-tui/src/lib.rs b/crates/openhuman-tui/src/lib.rs
index 366d4072e7..496b57314c 100644
--- a/crates/openhuman-tui/src/lib.rs
+++ b/crates/openhuman-tui/src/lib.rs
@@ -41,6 +41,7 @@ mod controls;
mod crash_reporting;
mod demo;
mod effects;
+mod event_view;
mod input;
mod presentation;
mod render;
diff --git a/crates/openhuman-tui/src/state.rs b/crates/openhuman-tui/src/state.rs
index 1f9bcd54f2..e726c09617 100644
--- a/crates/openhuman-tui/src/state.rs
+++ b/crates/openhuman-tui/src/state.rs
@@ -12,6 +12,8 @@
use super::activity::{Activity, Status};
use openhuman_rpc::embed::chat_surface::WebChannelEvent;
+
+use crate::event_view::WebEventView;
use std::collections::{HashMap, VecDeque};
use std::sync::atomic::{AtomicU64, Ordering};
@@ -240,6 +242,7 @@ impl TranscriptState {
/// bus is process-wide). Returns nothing; inspect [`Self::entries`] /
/// [`Self::is_streaming`] afterwards.
pub fn apply_event(&mut self, ev: &WebChannelEvent) {
+ let ev = WebEventView::from_event(ev);
if ev.client_id != self.client_id
|| (!self.thread_id.is_empty() && ev.thread_id != self.thread_id)
{
@@ -275,8 +278,8 @@ impl TranscriptState {
self.append_thinking(delta);
}
}
- "tool_call" | "tool_result" | "tool_args_delta" => self.apply_activity(ev, false),
- event if event.starts_with("subagent_") => self.apply_activity(ev, true),
+ "tool_call" | "tool_result" | "tool_args_delta" => self.apply_activity(&ev, false),
+ event if event.starts_with("subagent_") => self.apply_activity(&ev, true),
"artifact_pending" | "artifact_ready" | "artifact_failed" => {
self.viewport_changed(self.entries.len());
let status = ev.event.trim_start_matches("artifact_");
@@ -401,7 +404,7 @@ impl TranscriptState {
}
}
- fn apply_activity(&mut self, ev: &WebChannelEvent, child: bool) {
+ fn apply_activity(&mut self, ev: &WebEventView, child: bool) {
let identity = if child {
ev.subagent
.as_ref()
diff --git a/vendor/tinychannels b/vendor/tinychannels
index 7d076529e2..637a61a165 160000
--- a/vendor/tinychannels
+++ b/vendor/tinychannels
@@ -1 +1 @@
-Subproject commit 7d076529e24dda1d5d7e1bde22773e5677244782
+Subproject commit 637a61a165a536308588873e8a8dc0a77cb4c5d4