use super::*;
pub(super) fn magi_control_card(
state: &MissionControlState,
id: TranscriptCardId,
link: Option<&TranscriptActivityLink>,
body: &str,
) -> TranscriptCard {
let node = link.and_then(|link| state.nodes.get(&link.activity_id));
let detail = node.and_then(|node| node.tool_detail.as_ref());
let action = detail
.and_then(|detail| detail.params.get("action"))
.and_then(serde_json::Value::as_str);
let title = match action {
Some("context_usage") => "Magi Control • Context Usage",
Some("compact") => "Magi Control • Compact",
_ => "Magi Control",
};
let output = detail.map_or(body, |detail| detail.output.as_ref());
let context = detail
.filter(|_| action == Some("compact"))
.and_then(|detail| detail.params.get("context"))
.and_then(serde_json::Value::as_str)
.unwrap_or_default();
let body = [output, context]
.into_iter()
.filter(|text| !text.trim().is_empty())
.collect::<Vec<_>>()
.join("\n\n");
let mut card = basic_card(id, TranscriptCardRole::MagiControl, title, &body);
card.status = node
.map(|node| transcript_status_from_activity(node.status))
.unwrap_or_else(|| transcript_tool_status(state, card.id.entry_index));
if card.status == TranscriptCardStatus::Failed && tool_was_canceled(detail) {
card.status = TranscriptCardStatus::Canceled;
}
card
}