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