use super::*;
impl Record {
pub(crate) fn single_text_content(&self) -> Option<&str> {
match self.message.as_ref()?.content.as_ref()? {
Content::Text(s) => Some(s.as_str()),
Content::Blocks(blocks) => match blocks.as_slice() {
[Block::Text { text }] => Some(text.as_str()),
_ => None,
},
}
}
#[must_use]
pub fn is_resume_prompt(&self) -> bool {
if !self.is_type("user")
|| !self.is_meta.unwrap_or(false)
|| self.is_compact_summary.unwrap_or(false)
{
return false;
}
let Some(content) = self.message.as_ref().and_then(|m| m.content.as_ref()) else {
return false;
};
match content {
Content::Text(s) => s.trim_start().starts_with(RESUME_PROMPT_MARKER),
Content::Blocks(blocks) => {
if blocks.iter().any(|b| matches!(b, Block::ToolResult { .. })) {
return false;
}
for b in blocks {
let Block::Text { text } = b else { continue };
let head = text.trim_start();
if head.is_empty() {
continue;
}
return head.starts_with(RESUME_PROMPT_MARKER);
}
false
}
}
}
#[must_use]
pub fn is_resume_placeholder(&self) -> bool {
self.is_type("assistant")
&& self.is_api_error_message != Some(true)
&& self.message.as_ref().and_then(Message::model_id) == Some(SYNTHETIC_MODEL)
&& self.single_text_content() == Some(RESUME_PLACEHOLDER_TEXT)
}
#[must_use]
pub fn resume_paired(&self, ctx: &ClassifyCtx) -> Option<bool> {
if !self.is_resume_placeholder() {
return None;
}
let prompts = ctx.resume_prompt_uuids?;
Some(
self.parent_uuid
.as_deref()
.is_some_and(|p| prompts.contains(p)),
)
}
}