MCPcopy Index your code
hub / github.com/simstudioai/sim / enforceSizeLimit

Method enforceSizeLimit

apps/sim/lib/chunkers/docs-chunker.ts:354–386  ·  view source on GitHub ↗
(chunks: string[])

Source from the content-addressed store, hash-verified

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}

Callers 1

splitContentMethod · 0.95

Calls 2

estimateTokensFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected