mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-30 01:19:34 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cb64dd8a7 | ||
|
|
6198c98673 |
+2
-1
@@ -127,7 +127,8 @@ async fn list_settings(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let display_value = if value.len() > 60 {
|
let display_value = if value.len() > 60 {
|
||||||
format!("{}...", &value[..57])
|
let end = crate::util::floor_char_boundary(&value, 57);
|
||||||
|
format!("{}...", &value[..end])
|
||||||
} else {
|
} else {
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
|
|||||||
+15
-1
@@ -256,7 +256,8 @@ fn truncate_content(s: &str, max_len: usize) -> String {
|
|||||||
if s.len() <= max_len {
|
if s.len() <= max_len {
|
||||||
s.to_string()
|
s.to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("{}...", &s[..max_len])
|
let end = crate::util::floor_char_boundary(s, max_len);
|
||||||
|
format!("{}...", &s[..end])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,4 +293,17 @@ mod tests {
|
|||||||
assert_eq!(truncate_content("hello", 10), "hello");
|
assert_eq!(truncate_content("hello", 10), "hello");
|
||||||
assert_eq!(truncate_content("hello world", 5), "hello...");
|
assert_eq!(truncate_content("hello world", 5), "hello...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_truncate_content_multibyte_does_not_panic() {
|
||||||
|
// \u{00e9} is precomposed 'é' (2 bytes in UTF-8)
|
||||||
|
let s = "caf\u{00e9} au lait"; // "café au lait", é starts at byte 3
|
||||||
|
let result = truncate_content(s, 4); // byte 4 is inside 2-byte é
|
||||||
|
assert_eq!(result, "caf...");
|
||||||
|
|
||||||
|
// 4-byte emoji: slicing mid-emoji must not panic
|
||||||
|
let emoji = "Hi \u{1F600} there"; // 😀 is 4 bytes, starts at byte 3
|
||||||
|
let result = truncate_content(emoji, 4); // byte 4 is inside 😀
|
||||||
|
assert_eq!(result, "Hi ...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ impl NearAiChatProvider {
|
|||||||
provider: "nearai_chat".to_string(),
|
provider: "nearai_chat".to_string(),
|
||||||
reason: format!(
|
reason: format!(
|
||||||
"No model names found in response: {}",
|
"No model names found in response: {}",
|
||||||
&response_text[..response_text.len().min(300)]
|
&response_text[..crate::util::floor_char_boundary(&response_text, 300)]
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user