(text: string, limit: number, guidance?: string)
| 14 | * that tells the LLM how to get more specific data. |
| 15 | */ |
| 16 | export function truncate(text: string, limit: number, guidance?: string): string { |
| 17 | if (text.length <= limit) return text |
| 18 | |
| 19 | const suffix = guidance |
| 20 | ? `\n\n[TRUNCATED — response was ~${(text.length / 1000).toFixed(0)}K chars. ${guidance}]` |
| 21 | : `\n\n[TRUNCATED — response was ~${(text.length / 1000).toFixed(0)}K chars.]` |
| 22 | |
| 23 | return text.slice(0, limit - suffix.length) + suffix |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Serialize data as compact JSON, then truncate if it exceeds the limit. |
no outgoing calls
no test coverage detected