( content: string, maxBytes: number, )
| 337 | * Generate a preview of content, truncating at a newline boundary when possible. |
| 338 | */ |
| 339 | export function generatePreview( |
| 340 | content: string, |
| 341 | maxBytes: number, |
| 342 | ): { preview: string; hasMore: boolean } { |
| 343 | if (content.length <= maxBytes) { |
| 344 | return { preview: content, hasMore: false } |
| 345 | } |
| 346 | |
| 347 | // Find the last newline within the limit to avoid cutting mid-line |
| 348 | const truncated = content.slice(0, maxBytes) |
| 349 | const lastNewline = truncated.lastIndexOf('\n') |
| 350 | |
| 351 | // If we found a newline reasonably close to the limit, use it |
| 352 | // Otherwise fall back to the exact limit |
| 353 | const cutPoint = lastNewline > maxBytes * 0.5 ? lastNewline : maxBytes |
| 354 | |
| 355 | return { preview: content.slice(0, cutPoint), hasMore: true } |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Type guard to check if persist result is an error |
no outgoing calls
no test coverage detected