diff --git a/modules/ena-planner/ena-planner.html b/modules/ena-planner/ena-planner.html index c15fbb7..ce397c0 100644 --- a/modules/ena-planner/ena-planner.html +++ b/modules/ena-planner/ena-planner.html @@ -558,11 +558,12 @@ const sel = $('ep_tpl_select'); sel.innerHTML = ''; const names = Object.keys(cfg?.promptTemplates || {}); + const selectedName = names.includes(selected) ? selected : ''; names.forEach(name => { const opt = document.createElement('option'); opt.value = name; opt.textContent = name; - opt.selected = name === selected; + opt.selected = name === selectedName; sel.appendChild(opt); }); } @@ -675,7 +676,8 @@ setBadge(toBool(cfg.enabled, true)); updatePrefixModeUI(); - renderTemplateSelect(); + const keepSelectedTemplate = $('ep_tpl_select')?.value || ''; + renderTemplateSelect(keepSelectedTemplate); renderPromptList(); renderLogs(); } @@ -916,4 +918,4 @@ - \ No newline at end of file + diff --git a/modules/ena-planner/ena-planner.js b/modules/ena-planner/ena-planner.js index 55f58a2..6d8562d 100644 --- a/modules/ena-planner/ena-planner.js +++ b/modules/ena-planner/ena-planner.js @@ -46,7 +46,7 @@ function getDefaultSettings() { customPrefix: '', apiKey: '', model: '', - stream: false, + stream: true, temperature: 1, top_p: 1, top_k: 0, @@ -1461,4 +1461,3 @@ export function cleanupEnaPlanner() { } delete window.xiaobaixEnaPlanner; } - diff --git a/modules/tts/tts-text.js b/modules/tts/tts-text.js index 97aa756..5d14a5a 100644 --- a/modules/tts/tts-text.js +++ b/modules/tts/tts-text.js @@ -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; }