use super::goal::{format_elapsed_with, ElapsedPrecision};
use std::time::{Duration, Instant};
#[derive(Clone, Debug, Default)]
pub(super) struct ReasoningPhase {
open: bool,
started_at: Option<Instant>,
}
impl ReasoningPhase {
pub(super) fn begin_step(&mut self) {
*self = Self {
open: true,
started_at: None,
};
}
pub(super) fn reset(&mut self) {
*self = Self::default();
}
pub(super) fn on_reasoning_delta(&mut self) {
if self.started_at.is_none() {
self.started_at = Some(Instant::now());
}
}
pub(super) fn finalize(&mut self) -> Option<Duration> {
self.open = false;
self.started_at
.take()
.map(|started_at| started_at.elapsed())
}
pub(super) fn is_open(&self) -> bool {
self.open
}
}
pub(super) fn thought_summary(elapsed: Duration) -> String {
format!(
"Thought for {}",
format_elapsed_with(elapsed, ElapsedPrecision::TenthsUnderMinute)
)
}
#[cfg(test)]
#[path = "reasoning_phase_tests.rs"]
mod tests;