fix ena planner template selection and stream defaults; improve tts free text chunking

This commit is contained in:
2026-02-25 21:46:50 +08:00
parent fafdb18eaf
commit 21f09a7bd1
3 changed files with 49 additions and 8 deletions

View File

@@ -218,13 +218,53 @@ function splitTextForFree(text, maxLength = FREE_MAX_TEXT) {
const chunks = [];
const paragraphs = String(text || '').split(/\n\s*\n/).map(s => s.replace(/\n+/g, '\n').trim()).filter(Boolean);
let current = '';
const pushCurrent = () => {
if (!current) return;
chunks.push(current);
current = '';
};
for (const para of paragraphs) {
if (para.length <= maxLength) {
chunks.push(para);
if (!para) continue;
if (para.length > maxLength) {
// Flush buffered short paragraphs before handling a long paragraph.
pushCurrent();
const longParts = splitLongTextBySentence(para, maxLength);
for (const part of longParts) {
const t = String(part || '').trim();
if (!t) continue;
if (!current) {
current = t;
continue;
}
if (current.length + t.length + 2 <= maxLength) {
current += `\n\n${t}`;
continue;
}
pushCurrent();
current = t;
}
continue;
}
chunks.push(...splitLongTextBySentence(para, maxLength));
if (!current) {
current = para;
continue;
}
// Cross-paragraph merge: keep fewer requests while preserving paragraph boundary.
if (current.length + para.length + 2 <= maxLength) {
current += `\n\n${para}`;
continue;
}
pushCurrent();
current = para;
}
pushCurrent();
return chunks;
}