fix(chat): handle multi-byte character truncation in tool result preview
Some checks are pending
CI / Rust Lint & Check (push) Waiting to run
CI / Rust Tests (push) Waiting to run
CI / Frontend Lint & Type Check (push) Waiting to run
CI / Frontend Build (push) Blocked by required conditions

This commit is contained in:
ZhenYi 2026-04-30 23:37:13 +08:00
parent 5c2369ff47
commit c48f7319ca

View File

@ -791,7 +791,13 @@ impl ChatService {
crate::tool::ToolResult::Error(msg) => msg.clone(), crate::tool::ToolResult::Error(msg) => msg.clone(),
}; };
let preview = if text.len() > 300 { let preview = if text.len() > 300 {
format!("{}...", &text[..300]) let end = text
.char_indices()
.map(|(i, _)| i)
.take_while(|&i| i <= 300)
.last()
.unwrap_or(300);
format!("{}...", &text[..end])
} else { } else {
text.clone() text.clone()
}; };