( sectionHeader: string, sectionLines: string[], maxCharsPerSection: number, )
| 296 | } |
| 297 | |
| 298 | function flushSessionSection( |
| 299 | sectionHeader: string, |
| 300 | sectionLines: string[], |
| 301 | maxCharsPerSection: number, |
| 302 | ): { lines: string[]; wasTruncated: boolean } { |
| 303 | if (!sectionHeader) { |
| 304 | return { lines: sectionLines, wasTruncated: false } |
| 305 | } |
| 306 | |
| 307 | const sectionContent = sectionLines.join('\n') |
| 308 | if (sectionContent.length <= maxCharsPerSection) { |
| 309 | return { lines: [sectionHeader, ...sectionLines], wasTruncated: false } |
| 310 | } |
| 311 | |
| 312 | // Truncate at a line boundary near the limit |
| 313 | let charCount = 0 |
| 314 | const keptLines: string[] = [sectionHeader] |
| 315 | for (const line of sectionLines) { |
| 316 | if (charCount + line.length + 1 > maxCharsPerSection) { |
| 317 | break |
| 318 | } |
| 319 | keptLines.push(line) |
| 320 | charCount += line.length + 1 |
| 321 | } |
| 322 | keptLines.push('\n[... section truncated for length ...]') |
| 323 | return { lines: keptLines, wasTruncated: true } |
| 324 | } |
| 325 |
no test coverage detected