MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / forceTruncate

Function forceTruncate

packages/node-runtime/src/ai/compression/compressor.ts:271–282  ·  view source on GitHub ↗
(input: string, targetTokens: number)

Source from the content-addressed store, hash-verified

269}
270
271function forceTruncate(input: string, targetTokens: number): string {
272 const lines = input.split('\n')
273 const result: string[] = []
274 let tokens = 0
275 for (const line of lines) {
276 const lineTokens = countTokens(line)
277 if (tokens + lineTokens > targetTokens) break
278 result.push(line)
279 tokens += lineTokens
280 }
281 return result.join('\n') || input.slice(0, targetTokens * 3)
282}

Callers 1

checkAndCompressFunction · 0.85

Calls 1

countTokensFunction · 0.90

Tested by

no test coverage detected