use super::*;
pub(super) fn magi_control_card(input: &ToolCardInput<'_>) -> CardDraft {
let detail = input.detail;
let body = input.body;
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(
ToolCardRole::MagiControl,
title,
&bounded_preview_lines(&body),
);
card.status = input_status(input);
if card.status == CardStatus::Failed && tool_was_canceled(detail) {
card.status = CardStatus::Canceled;
}
card
}