fix: harden thinking block streaming display

Hide partial <think> tag prefixes during streaming and rename the local display variable for clarity. References #181.
This commit is contained in:
Nathan Esquenazi
2026-04-08 18:14:47 +00:00
parent 8ff5d83e14
commit 5f7564e8bb

View File

@@ -114,18 +114,22 @@ async function send(){
// Extract display text from assistantText, stripping completed thinking blocks
// and hiding content still inside an open thinking block.
function _streamDisplay(){
let t=assistantText;
const raw=assistantText;
for(const {open,close} of _thinkPairs){
if(!t.startsWith(open)) continue;
const ci=t.indexOf(close,open.length);
if(raw.startsWith(open)){
const ci=raw.indexOf(close,open.length);
if(ci!==-1){
// Thinking block complete — strip it, show the rest
return t.slice(ci+close.length).replace(/^\s+/,'');
return raw.slice(ci+close.length).replace(/^\s+/,'');
}
// Still inside thinking block — show placeholder
return '';
}
return t;
// Hide partial tag prefixes while streaming so users don't see
// `<thi`, `<think`, etc. before the model finishes the token.
if(open.startsWith(raw)) return '';
}
return raw;
}
function _scheduleRender(){
if(_renderPending) return;