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