use chrono::Utc;
#[derive(Clone, Debug)]
pub struct Percept {
pub text: String,
}
#[derive(Clone, Debug)]
pub struct Action {
pub intent: String,
pub note: String,
}
#[derive(Default, Clone, Debug)]
pub struct Memory {
ring: Vec<String>,
cap: usize,
}
impl Memory {
pub fn new(cap: usize) -> Self {
Self {
ring: Vec::with_capacity(cap),
cap,
}
}
pub fn push(&mut self, s: String) {
if self.ring.len() >= self.cap {
self.ring.remove(0);
}
self.ring.push(s);
}
pub fn snapshot(&self) -> Vec<String> {
self.ring.clone()
}
}
pub fn plan(p: &Percept, mem: &Memory) -> Action {
let intent = if p.text.to_lowercase().contains("status") {
"report"
} else {
"log"
}
.to_string();
let note = format!("{} | mem_len={}", p.text.trim(), mem.ring.len());
Action { intent, note }
}
pub fn act(a: &Action, mem: &mut Memory) -> String {
match a.intent.as_str() {
"report" => format!("[{}] STATUS :: {}", Utc::now().to_rfc3339(), a.note),
_ => {
mem.push(a.note.clone());
format!("[{}] LOGGED", Utc::now().to_rfc3339())
}
}
}