use serde::{Deserialize, Serialize};
pub const HANDOFF_DEFAULT_TARGET_TOKENS: usize = 15_000;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CompressedBlock {
pub id: String,
pub topic: String,
pub source_range: String,
pub summary: String,
pub created_at: chrono::DateTime<chrono::Utc>,
#[serde(skip_serializing_if = "Option::is_none")]
pub token_estimate_before: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub token_estimate_after: Option<u32>,
}
impl CompressedBlock {
pub fn new(
id: impl Into<String>,
topic: impl Into<String>,
source_range: impl Into<String>,
summary: impl Into<String>,
) -> Self {
Self {
id: id.into(),
topic: topic.into(),
source_range: source_range.into(),
summary: summary.into(),
created_at: chrono::Utc::now(),
token_estimate_before: None,
token_estimate_after: None,
}
}
pub fn render_to_text(&self) -> String {
format!(
"[Compressed context: {}]\nID: {}\nSource range: {}\n{}\n",
self.topic, self.id, self.source_range, self.summary
)
}
}