(chunks: string[])
| 352 | } |
| 353 | |
| 354 | private enforceSizeLimit(chunks: string[]): string[] { |
| 355 | const finalChunks: string[] = [] |
| 356 | |
| 357 | for (const chunk of chunks) { |
| 358 | const tokens = estimateTokens(chunk) |
| 359 | |
| 360 | if (tokens <= this.chunkSize) { |
| 361 | finalChunks.push(chunk) |
| 362 | } else { |
| 363 | const lines = chunk.split('\n') |
| 364 | let currentChunk = '' |
| 365 | |
| 366 | for (const line of lines) { |
| 367 | const testChunk = currentChunk ? `${currentChunk}\n${line}` : line |
| 368 | |
| 369 | if (estimateTokens(testChunk) <= this.chunkSize) { |
| 370 | currentChunk = testChunk |
| 371 | } else { |
| 372 | if (currentChunk.trim()) { |
| 373 | finalChunks.push(currentChunk.trim()) |
| 374 | } |
| 375 | currentChunk = line |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | if (currentChunk.trim()) { |
| 380 | finalChunks.push(currentChunk.trim()) |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | return finalChunks.filter((chunk) => chunk.trim().length > 100) |
| 386 | } |
| 387 | } |
no test coverage detected