MCPcopy Create free account
hub / github.com/Noumena-Network/code / flushSessionSection

Function flushSessionSection

src/services/SessionMemory/prompts.ts:299–325  ·  view source on GitHub ↗
(
  sectionHeader: string,
  sectionLines: string[],
  maxCharsPerSection: number,
)

Source from the content-addressed store, hash-verified

297}
298
299function 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}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected