From 5f7564e8bba6a6ffbb6b25d5a33400e40f4d15fa Mon Sep 17 00:00:00 2001 From: Nathan Esquenazi Date: Wed, 8 Apr 2026 18:14:47 +0000 Subject: [PATCH] fix: harden thinking block streaming display Hide partial tag prefixes during streaming and rename the local display variable for clarity. References #181. --- static/messages.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/static/messages.js b/static/messages.js index 47461f6..0209c2f 100644 --- a/static/messages.js +++ b/static/messages.js @@ -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(ci!==-1){ - // Thinking block complete — strip it, show the rest - return t.slice(ci+close.length).replace(/^\s+/,''); + if(raw.startsWith(open)){ + const ci=raw.indexOf(close,open.length); + if(ci!==-1){ + // Thinking block complete — strip it, show the rest + return raw.slice(ci+close.length).replace(/^\s+/,''); + } + // Still inside thinking block — show placeholder + return ''; } - // Still inside thinking block — show placeholder - return ''; + // Hide partial tag prefixes while streaming so users don't see + // `