33 lines
1.2 KiB
Rust
33 lines
1.2 KiB
Rust
//! Live-state callback builder for the Hive Mind TUI panel.
|
|||
|
|
//!
|
||
|
|
//! `build_live` creates a `LiveStateFn` closure that forwards each drone's
|
||
|
|
//! status update to the runtime event queue so LO can watch the Hive work.
|
||
|
|
|
||
|
|
use crate::app::workflow::engine::{AgentStatus, LiveStateFn};
|
||
|
|
use std::sync::{Arc, Mutex};
|
||
|
|
|
||
|
|
/// Build the live-state callback that forwards each drone's status to the
|
||
|
|
/// TUI panel so LO can watch the Hive work.
|
||
|
|
pub fn build_live(
|
||
|
|
turn_events: Option<
|
||
|
|
&Arc<Mutex<std::collections::VecDeque<crate::app::state::runtime::TurnEvent>>>,
|
||
|
|
>,
|
||
|
|
) -> Option<LiveStateFn> {
|
||
|
|
turn_events.map(|events| {
|
||
|
|
let events = events.clone();
|
||
|
|
let f: LiveStateFn = Arc::new(
|
||
|
|
move |_agent_id: String, agent_name: String, status: AgentStatus| {
|
||
|
|
let display_name = agent_name.chars().take(40).collect::<String>();
|
||
|
|
if let Ok(mut q) = events.lock() {
|
||
|
|
q.push_back(crate::app::state::runtime::TurnEvent::WorkflowAgentUpdate {
|
||
|
|
agent_id: display_name.clone(),
|
||
|
|
agent_name: display_name,
|
||
|
|
status,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
);
|
||
|
|
f
|
||
|
|
})
|
||
|
|
}
|