Run parsing at least once before rendering reasoning DOM on continue
| @@ -3204,13 +3204,21 @@ class StreamingProcessor { | |||
| 3204 | this.promptReasoning = promptReasoning; | 3204 | this.promptReasoning = promptReasoning; |
| 3205 | } | 3205 | } |
| 3206 | 3206 | ||
| 3207 | #checkDomElements(messageId) { | 3207 | /** |
| 3208 | * Initializes DOM elements for the current message. | ||
| 3209 | * @param {number} messageId Current message ID | ||
| 3210 | * @param {boolean?} continueOnReasoning If continuing on reasoning | ||
| 3211 | */ | ||
| 3212 | async #checkDomElements(messageId, continueOnReasoning = null) { | ||
| 3208 | if (this.messageDom === null || this.messageTextDom === null) { | 3213 | if (this.messageDom === null || this.messageTextDom === null) { |
| 3209 | this.messageDom = document.querySelector(`#chat .mes[mesid="${messageId}"]`); | 3214 | this.messageDom = document.querySelector(`#chat .mes[mesid="${messageId}"]`); |
| 3210 | this.messageTextDom = this.messageDom?.querySelector('.mes_text'); | 3215 | this.messageTextDom = this.messageDom?.querySelector('.mes_text'); |
| 3211 | this.messageTimerDom = this.messageDom?.querySelector('.mes_timer'); | 3216 | this.messageTimerDom = this.messageDom?.querySelector('.mes_timer'); |
| 3212 | this.messageTokenCounterDom = this.messageDom?.querySelector('.tokenCounterDisplay'); | 3217 | this.messageTokenCounterDom = this.messageDom?.querySelector('.tokenCounterDisplay'); |
| 3213 | } | 3218 | } |
| 3219 | if (continueOnReasoning) { | ||
| 3220 | await this.reasoningHandler.process(messageId, false, this.promptReasoning); | ||
| 3221 | } | ||
| 3214 | this.reasoningHandler.updateDom(messageId); | 3222 | this.reasoningHandler.updateDom(messageId); |
| 3215 | } | 3223 | } |
| 3216 | 3224 | ||
| @@ -3230,7 +3238,8 @@ class StreamingProcessor { | |||
| 3230 | } | 3238 | } |
| 3231 | 3239 | ||
| 3232 | async onStartStreaming(text) { | 3240 | async onStartStreaming(text) { |
| 3233 | if (this.type === 'continue' && this.promptReasoning.prefixReasoning) { | 3241 | const continueOnReasoning = !!(this.type === 'continue' && this.promptReasoning.prefixReasoning); |
| 3242 | if (continueOnReasoning) { | ||
| 3234 | this.reasoningHandler.initContinue(this.promptReasoning); | 3243 | this.reasoningHandler.initContinue(this.promptReasoning); |
| 3235 | } | 3244 | } |
| 3236 | 3245 | ||
| @@ -3242,7 +3251,7 @@ class StreamingProcessor { | |||
| 3242 | } else { | 3251 | } else { |
| 3243 | await saveReply(this.type, text, true, '', [], ''); | 3252 | await saveReply(this.type, text, true, '', [], ''); |
| 3244 | messageId = chat.length - 1; | 3253 | messageId = chat.length - 1; |
| 3245 | this.#checkDomElements(messageId); | 3254 | await this.#checkDomElements(messageId, continueOnReasoning); |
| 3246 | this.markUIGenStarted(); | 3255 | this.markUIGenStarted(); |
| 3247 | } | 3256 | } |
| 3248 | hideSwipeButtons(); | 3257 | hideSwipeButtons(); |
| @@ -3275,7 +3284,7 @@ class StreamingProcessor { | |||
| 3275 | this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true })); | 3284 | this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true })); |
| 3276 | } else { | 3285 | } else { |
| 3277 | const mesChanged = chat[messageId]['mes'] !== processedText; | 3286 | const mesChanged = chat[messageId]['mes'] !== processedText; |
| 3278 | this.#checkDomElements(messageId); | 3287 | await this.#checkDomElements(messageId); |
| 3279 | this.#updateMessageBlockVisibility(); | 3288 | this.#updateMessageBlockVisibility(); |
| 3280 | const currentTime = new Date(); | 3289 | const currentTime = new Date(); |
| 3281 | chat[messageId]['mes'] = processedText; | 3290 | chat[messageId]['mes'] = processedText; |