fix: char-boundary-safe name truncation in cron_add tool
The name fallback used byte-index slice on the prompt, which panics on multi-byte UTF-8 characters like Chinese. Use is_char_boundary() to find a safe truncation point.
This commit is contained in:
parent
62f4326131
commit
db609342f7
@ -131,7 +131,19 @@ impl Tool for CronAddTool {
|
||||
let name = args
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or(&prompt[..prompt.len().min(50)])
|
||||
.unwrap_or_else(|| {
|
||||
// char-boundary-safe truncation to 50 bytes
|
||||
let limit = 50;
|
||||
if prompt.len() <= limit {
|
||||
prompt.as_str()
|
||||
} else {
|
||||
let mut end = limit;
|
||||
while !prompt.is_char_boundary(end) {
|
||||
end -= 1;
|
||||
}
|
||||
&prompt[..end]
|
||||
}
|
||||
})
|
||||
.to_string();
|
||||
let model = args
|
||||
.get("model")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user