fix: UTF-8 boundary issue in compactor and remove openfang-runtime from bundle

This commit is contained in:
iven
2026-03-22 09:23:19 +08:00
parent 34f4654039
commit 2fb914c965
2 changed files with 10 additions and 13 deletions

View File

@@ -306,20 +306,24 @@ impl ContextCompactor {
fn extract_topic(&self, content: &str) -> Option<String> {
let trimmed = content.trim();
// First sentence or first 50 chars
// Find sentence end markers (byte position)
let sentence_end = trimmed.find(|c| c == '。' || c == '' || c == '' || c == '\n');
if let Some(pos) = sentence_end {
if pos <= 80 {
return Some(trimmed[..=pos].to_string());
if let Some(byte_pos) = sentence_end {
if byte_pos <= 80 {
// Find the char boundary after the sentence end marker
// The marker itself is a single char (1-3 bytes for Chinese)
let end_boundary = byte_pos + trimmed[byte_pos..].chars().next().map(|c| c.len_utf8()).unwrap_or(1);
return Some(trimmed[..end_boundary].to_string());
}
}
if trimmed.len() <= 50 {
if trimmed.chars().count() <= 50 {
return Some(trimmed.to_string());
}
Some(format!("{}...", &trimmed[..50]))
// Use chars() to safely handle UTF-8 boundaries
Some(format!("{}...", trimmed.chars().take(50).collect::<String>()))
}
/// Extract key conclusions/decisions from assistant messages