use std::path::PathBuf;
#[cfg(feature = "native")]
use tokio::sync::mpsc;
use crate::transcript::{Entry, SubagentMeta};
mod item;
pub use item::ReplayItem;
pub(crate) use item::Timing;
#[cfg(test)]
pub(crate) use item::date_and_sort;
pub(crate) use item::date_and_sort_live;
pub use item::{DemoSubagent, replay_from_jsonl, replay_from_session};
#[cfg(feature = "native")]
mod bytes;
#[cfg(feature = "native")]
mod live;
#[cfg(feature = "native")]
mod replay;
#[cfg(feature = "native")]
use live::run_live;
#[cfg(feature = "native")]
use replay::run_replay;
#[derive(Debug, Clone)]
pub enum TailRequest {
Watch(PathBuf),
}
#[derive(Debug)]
pub enum UiEvent {
Batch {
session_id: String,
updates: Vec<Update>,
},
ReplayLoaded {
session_id: String,
items: Vec<ReplayItem>,
speed: f64,
info: crate::state::SessionInfo,
},
SessionReset { session_id: String },
Error(String),
}
#[derive(Debug)]
pub enum Update {
Entry { source: Source, entry: Entry },
SubagentMeta {
agent_id: String,
workflow: Option<String>,
meta: SubagentMeta,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Source {
Main,
Sub(String),
Journal(String),
}
#[cfg(feature = "native")]
pub async fn run(
mut req_rx: mpsc::Receiver<TailRequest>,
ui_tx: mpsc::Sender<UiEvent>,
replay: bool,
speed: f64,
) -> anyhow::Result<()> {
let mut current = match wait_for_watch(&mut req_rx).await {
Some(path) => path,
None => return Ok(()),
};
loop {
let next = if replay {
run_replay(¤t, &ui_tx, &mut req_rx, speed).await
} else {
run_live(¤t, &ui_tx, &mut req_rx).await
};
match next {
Flow::Switch(path) => current = path,
Flow::Exit => return Ok(()),
}
}
}
#[cfg(feature = "native")]
pub(crate) enum Flow {
Switch(PathBuf),
Exit,
}
#[cfg(feature = "native")]
async fn wait_for_watch(req_rx: &mut mpsc::Receiver<TailRequest>) -> Option<PathBuf> {
match req_rx.recv().await? {
TailRequest::Watch(path) => Some(path),
}
}