Truncate a string to `max_len` bytes, breaking at a word boundary where possible and appending `"..."`. Mirrors the same helper in sibling modules.
(prompt: &str, max_len: usize)
| 817 | /// Truncate a string to `max_len` bytes, breaking at a word boundary where |
| 818 | /// possible and appending `"..."`. Mirrors the same helper in sibling modules. |
| 819 | pub(crate) fn truncate_prompt(prompt: &str, max_len: usize) -> String { |
| 820 | let trimmed = prompt.trim(); |
| 821 | if trimmed.len() <= max_len { |
| 822 | return trimmed.to_string(); |
| 823 | } |
| 824 | |
| 825 | // Try to break at a word boundary in the first `max_len - 3` bytes. |
| 826 | let truncated = &trimmed[..max_len.saturating_sub(3)]; |
| 827 | if let Some(last_space) = truncated.rfind(' ') { |
| 828 | if last_space > max_len / 2 { |
| 829 | return format!("{}...", &truncated[..last_space]); |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | format!("{}...", truncated) |
| 834 | } |
| 835 | |
| 836 | impl TurnOrchestrator { |
| 837 | /// Fast check for working copy changes. |
no test coverage detected