pub mod llm_envelope;
pub use llm_envelope::{Envelope, Envelopable};
pub type OptimizerResult<T> = Result<T, String>;
pub fn minify_text(input: &str) -> String {
let trimmed = input.trim();
if trimmed.is_empty() {
return String::new();
}
if serde_json::from_str::<serde_json::Value>(trimmed).is_ok() {
return input.to_string();
}
if toml::from_str::<toml::Value>(trimmed).is_ok() {
return input.to_string();
}
input
.split_whitespace()
.collect::<Vec<&str>>()
.join(" ")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_minify_ignores_toml() {
let toml_data = "key = \"value\"\n[table]\nitem = 1";
assert_eq!(minify_text(toml_data), toml_data);
}
#[test]
fn test_minify_packs_prose() {
let prose = " This is unstructured text. ";
assert_eq!(minify_text(prose), "This is unstructured text.");
}
}