use ratatui::style::Style;
use ratatui::text::{Line, Span};
use crate::palette;
use super::{
GenericToolCell, render_tool_header_with_family_and_summary, tool_status_label, truncate_text,
};
pub(super) fn render_agent_compact(cell: &GenericToolCell, low_motion: bool) -> Vec<Line<'static>> {
let family = crate::tui::widgets::tool_card::ToolFamily::Delegate;
let agent_id = cell
.output
.as_deref()
.and_then(extract_agent_id)
.unwrap_or("…");
vec![render_tool_header_with_family_and_summary(
family,
Some(agent_id),
tool_status_label(cell.status),
cell.status,
None,
low_motion,
)]
}
pub(super) fn render_activity_group(cell: &GenericToolCell, width: u16) -> Vec<Line<'static>> {
let summary = cell.input_summary.as_deref().unwrap_or("Updated metadata");
let budget = usize::from(width).max(1);
vec![Line::from(Span::styled(
truncate_text(summary, budget),
Style::default().fg(palette::TEXT_MUTED),
))]
}
pub(super) fn extract_agent_id(output: &str) -> Option<&str> {
let key = "\"agent_id\"";
let key_idx = output.find(key)?;
let rest = &output[key_idx + key.len()..];
let colon = rest.find(':')?;
let after_colon = rest[colon + 1..].trim_start();
let after_colon = after_colon.strip_prefix('"')?;
let end = after_colon.find('"')?;
let id = &after_colon[..end];
(!id.is_empty()).then_some(id)
}