use switchyard_protocol::{AggLlmResponse, ContentBlock, StopReason};
pub(super) fn has_tool_use(agg: &AggLlmResponse) -> bool {
agg.outputs.iter().any(|output| {
output.stop_reason == Some(StopReason::ToolUse)
|| output
.content
.iter()
.any(|block| matches!(block, ContentBlock::ToolCall(_)))
})
}
pub(super) fn visible_text(agg: &AggLlmResponse) -> Option<String> {
let text: Vec<&str> = agg
.outputs
.iter()
.flat_map(|output| output.content.iter())
.filter_map(|block| match block {
ContentBlock::Text { text } => Some(text.as_str()),
_ => None,
})
.collect();
if text.is_empty() {
return None;
}
let joined = text.join("\n");
if joined.is_empty() {
None
} else {
Some(joined)
}
}
pub(super) fn reasoning_text(agg: &AggLlmResponse) -> Option<String> {
let text: Vec<&str> = agg
.outputs
.iter()
.flat_map(|output| output.content.iter())
.filter_map(|block| match block {
ContentBlock::Reasoning { text, .. } => Some(text.as_str()),
_ => None,
})
.collect();
if text.is_empty() {
return None;
}
let joined = text.join("\n");
if joined.is_empty() {
None
} else {
Some(joined)
}
}