use locode_protocol::{ContentBlock, Usage};
#[derive(Debug, Clone, PartialEq)]
pub struct Completion {
pub content: Vec<ContentBlock>,
pub usage: Usage,
pub stop: StopReason,
}
impl Completion {
pub fn tool_uses(&self) -> impl Iterator<Item = &ContentBlock> {
self.content
.iter()
.filter(|block| matches!(block, ContentBlock::ToolUse { .. }))
}
#[must_use]
pub fn has_tool_calls(&self) -> bool {
self.content
.iter()
.any(|block| matches!(block, ContentBlock::ToolUse { .. }))
}
#[must_use]
pub fn text(&self) -> Option<String> {
let mut out = String::new();
for block in &self.content {
if let ContentBlock::Text { text } = block {
out.push_str(text);
}
}
(!out.is_empty()).then_some(out)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum StopReason {
EndTurn,
MaxTokens,
ToolUse,
StopSequence,
Refusal,
PauseTurn,
Unknown(String),
}