use serde::{Deserialize, Serialize};
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[repr(u8)]
pub enum ContextFidelity {
#[default]
Full = 0,
Compressed = 1,
Placeholder = 2,
}
impl ContextFidelity {
#[must_use]
pub fn from_u8(v: u8) -> Self {
match v {
1 => Self::Compressed,
2 => Self::Placeholder,
_ => Self::Full, }
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlannedToolHint {
pub tool_name: String,
pub keywords: Vec<String>,
pub distance_from_current: u8,
}
impl PlannedToolHint {
pub fn new(
tool_name: impl Into<String>,
keywords: Vec<String>,
distance_from_current: u8,
) -> Self {
Self {
tool_name: tool_name.into(),
keywords,
distance_from_current,
}
}
}
#[cfg(test)]
mod tests {
use super::ContextFidelity;
#[test]
fn from_u8_round_trip() {
assert_eq!(ContextFidelity::from_u8(0), ContextFidelity::Full);
assert_eq!(ContextFidelity::from_u8(1), ContextFidelity::Compressed);
assert_eq!(ContextFidelity::from_u8(2), ContextFidelity::Placeholder);
}
#[test]
fn from_u8_unknown_defaults_to_full() {
assert_eq!(ContextFidelity::from_u8(3), ContextFidelity::Full);
assert_eq!(ContextFidelity::from_u8(255), ContextFidelity::Full);
}
#[test]
fn as_u8_matches_from_u8() {
for level in [
ContextFidelity::Full,
ContextFidelity::Compressed,
ContextFidelity::Placeholder,
] {
assert_eq!(ContextFidelity::from_u8(level as u8), level);
}
}
}