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