//! Session state for current conversation.
/// Session state during a voice conversation.
#[derive(Debug, Clone, Default)]
pub struct SessionState {
/// Current skill/character ID
pub current_skill: String,
/// Conversation history (role, content)
pub history: Vec<(String, String)>,
/// Detected emotion from last user speech
pub detected_emotion: Option<String>,
/// Emotion confidence
pub emotion_confidence: Option<f32>,
/// Total tokens used (input)
pub tokens_in: u32,
/// Total tokens used (output)
pub tokens_out: u32,
/// Last response latency in ms
pub latency_ms: u32,
}
impl SessionState {
/// Create a new session with a skill.
pub fn new(skill_id: &str) -> Self {
Self {
current_skill: skill_id.to_string(),
..Default::default()
}
}
/// Add a user message.
pub fn add_user_message(&mut self, content: &str) {
self.history.push(("user".to_string(), content.to_string()));
}
/// Add an assistant message.
pub fn add_assistant_message(&mut self, content: &str) {
self.history.push(("assistant".to_string(), content.to_string()));
}
/// Set detected emotion.
pub fn set_emotion(&mut self, emotion: &str, confidence: f32) {
self.detected_emotion = Some(emotion.to_string());
self.emotion_confidence = Some(confidence);
}
/// Clear emotion.
pub fn clear_emotion(&mut self) {
self.detected_emotion = None;
self.emotion_confidence = None;
}
/// Reset the session.
pub fn reset(&mut self) {
self.history.clear();
self.detected_emotion = None;
self.emotion_confidence = None;
self.tokens_in = 0;
self.tokens_out = 0;
self.latency_ms = 0;
}
/// Get the last few messages for display.
pub fn recent_messages(&self, count: usize) -> &[(String, String)] {
let start = self.history.len().saturating_sub(count);
&self.history[start..]
}
}