use crate::CitationCompactionPolicy;
use merry_llm::ReasoningEffort;
use std::num::{NonZeroU64, NonZeroUsize};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HistoryRetention {
Archive(ArchiveConfig),
ContextOnly,
}
impl Default for HistoryRetention {
fn default() -> Self {
Self::Archive(ArchiveConfig::new())
}
}
impl HistoryRetention {
#[must_use]
pub const fn archive() -> Self {
Self::Archive(ArchiveConfig::new())
}
#[must_use]
pub const fn archive_with(config: ArchiveConfig) -> Self {
Self::Archive(config)
}
#[must_use]
pub const fn context_only() -> Self {
Self::ContextOnly
}
#[must_use]
pub(crate) const fn prunes_compacted_history(&self, has_session_store: bool) -> bool {
match self {
Self::ContextOnly => true,
Self::Archive(_) => has_session_store,
}
}
#[must_use]
pub const fn archive_config(&self) -> Option<ArchiveConfig> {
match self {
Self::Archive(config) => Some(*config),
Self::ContextOnly => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ArchiveConfig {
max_segments: Option<NonZeroUsize>,
max_bytes: Option<NonZeroU64>,
export_markdown: bool,
}
impl ArchiveConfig {
#[must_use]
pub const fn new() -> Self {
Self {
max_segments: None,
max_bytes: None,
export_markdown: true,
}
}
#[must_use]
pub const fn with_max_segments(mut self, max_segments: Option<NonZeroUsize>) -> Self {
self.max_segments = max_segments;
self
}
#[must_use]
pub const fn with_max_bytes(mut self, max_bytes: Option<NonZeroU64>) -> Self {
self.max_bytes = max_bytes;
self
}
#[must_use]
pub const fn with_export_markdown(mut self, export_markdown: bool) -> Self {
self.export_markdown = export_markdown;
self
}
#[must_use]
pub const fn max_segments(&self) -> Option<NonZeroUsize> {
self.max_segments
}
#[must_use]
pub const fn max_bytes(&self) -> Option<NonZeroU64> {
self.max_bytes
}
#[must_use]
pub const fn export_markdown(&self) -> bool {
self.export_markdown
}
}
impl Default for ArchiveConfig {
fn default() -> Self {
Self::new()
}
}
fn default_automatic_compaction_policy() -> CitationCompactionPolicy {
CitationCompactionPolicy::default()
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CompactionConfig {
enabled: bool,
policy: CitationCompactionPolicy,
reasoning_effort: Option<ReasoningEffort>,
}
impl CompactionConfig {
#[must_use]
pub fn enabled(policy: CitationCompactionPolicy) -> Self {
Self {
enabled: true,
policy,
reasoning_effort: None,
}
}
#[must_use]
pub fn disabled() -> Self {
Self {
enabled: false,
policy: default_automatic_compaction_policy(),
reasoning_effort: None,
}
}
#[must_use]
pub const fn is_enabled(&self) -> bool {
self.enabled
}
#[must_use]
pub const fn policy(&self) -> CitationCompactionPolicy {
self.policy
}
#[must_use]
pub fn with_reasoning_effort(mut self, reasoning_effort: Option<ReasoningEffort>) -> Self {
self.reasoning_effort = reasoning_effort;
self
}
#[must_use]
pub fn reasoning_effort(&self) -> Option<&ReasoningEffort> {
self.reasoning_effort.as_ref()
}
}
impl Default for CompactionConfig {
fn default() -> Self {
Self::enabled(default_automatic_compaction_policy())
}
}