use anyhow::Result;
use brainwires_core::{ChatOptions, Message, Provider};
pub struct DreamSummarizer;
impl DreamSummarizer {
pub async fn summarize_messages(
messages: &[Message],
provider: &dyn Provider,
) -> Result<String> {
if messages.is_empty() {
return Ok(String::new());
}
let mut conversation_text = String::new();
for msg in messages {
let role = match msg.role {
brainwires_core::Role::User => "User",
brainwires_core::Role::Assistant => "Assistant",
brainwires_core::Role::System => "System",
brainwires_core::Role::Tool => "Tool",
};
let text = msg.text_or_summary();
conversation_text.push_str(&format!("{role}: {text}\n\n"));
}
let prompt = format!(
"Synthesize the following conversation into a concise summary. \
Preserve key decisions, tool outcomes, and user preferences. \
Convert relative dates to absolute where possible. \
Focus on information that would be useful for future interactions.\n\n\
Conversation:\n{conversation_text}\n\n\
Summary:"
);
let llm_messages = vec![Message::user(&prompt)];
let options = ChatOptions {
temperature: Some(0.3),
max_tokens: Some(1024),
..Default::default()
};
let response = provider.chat(&llm_messages, None, &options).await?;
Ok(response.message.text_or_summary())
}
}