fix: split long memory lines
This commit is contained in:
@@ -144,13 +144,23 @@ export function chunkMarkdown(
|
||||
for (let i = 0; i < lines.length; i += 1) {
|
||||
const line = lines[i] ?? "";
|
||||
const lineNo = i + 1;
|
||||
const lineSize = line.length + 1;
|
||||
if (currentChars + lineSize > maxChars && current.length > 0) {
|
||||
flush();
|
||||
carryOverlap();
|
||||
const segments: string[] = [];
|
||||
if (line.length === 0) {
|
||||
segments.push("");
|
||||
} else {
|
||||
for (let start = 0; start < line.length; start += maxChars) {
|
||||
segments.push(line.slice(start, start + maxChars));
|
||||
}
|
||||
}
|
||||
for (const segment of segments) {
|
||||
const lineSize = segment.length + 1;
|
||||
if (currentChars + lineSize > maxChars && current.length > 0) {
|
||||
flush();
|
||||
carryOverlap();
|
||||
}
|
||||
current.push({ line: segment, lineNo });
|
||||
currentChars += lineSize;
|
||||
}
|
||||
current.push({ line, lineNo });
|
||||
currentChars += lineSize;
|
||||
}
|
||||
flush();
|
||||
return chunks;
|
||||
|
||||
Reference in New Issue
Block a user