Refactor reasoning placeholder clean-up
| @@ -3194,10 +3194,6 @@ class StreamingProcessor { | ||
| 3194 | 3194 | this.#checkDomElements(messageId); |
| 3195 | 3195 | this.#updateMessageBlockVisibility(); |
| 3196 | 3196 | const currentTime = new Date(); |
| 3197 | - // Don't waste time calculating token count for streaming | |
| 3198 | - const tokenCountText = (this.reasoning || '') + processedText; | |
| 3199 | - const currentTokenCount = isFinal && power_user.message_token_count_enabled ? getTokenCount(tokenCountText, 0) : 0; | |
| 3200 | - const timePassed = formatGenerationTimer(this.timeStarted, currentTime, currentTokenCount); | |
| 3201 | 3197 | chat[messageId]['mes'] = processedText; |
| 3202 | 3198 | chat[messageId]['gen_started'] = this.timeStarted; |
| 3203 | 3199 | chat[messageId]['gen_finished'] = currentTime; |
| @@ -3214,6 +3210,10 @@ class StreamingProcessor { | ||
| 3214 | 3210 | } |
| 3215 | 3211 | } |
| 3216 | 3212 | |
| 3213 | + // Don't waste time calculating token count for streaming | |
| 3214 | + const tokenCountText = (this.reasoning || '') + processedText; | |
| 3215 | + const currentTokenCount = isFinal && power_user.message_token_count_enabled ? getTokenCount(tokenCountText, 0) : 0; | |
| 3216 | + | |
| 3217 | 3217 | if (currentTokenCount) { |
| 3218 | 3218 | chat[messageId]['extra']['token_count'] = currentTokenCount; |
| 3219 | 3219 | if (this.messageTokenCounterDom instanceof HTMLElement) { |
| @@ -3236,10 +3236,13 @@ class StreamingProcessor { | ||
| 3236 | 3236 | if (this.messageTextDom instanceof HTMLElement) { |
| 3237 | 3237 | this.messageTextDom.innerHTML = formattedText; |
| 3238 | 3238 | } |
| 3239 | + | |
| 3240 | + const timePassed = formatGenerationTimer(this.timeStarted, currentTime, currentTokenCount); | |
| 3239 | 3241 | if (this.messageTimerDom instanceof HTMLElement) { |
| 3240 | 3242 | this.messageTimerDom.textContent = timePassed.timerValue; |
| 3241 | 3243 | this.messageTimerDom.title = timePassed.timerTitle; |
| 3242 | 3244 | } |
| 3245 | + | |
| 3243 | 3246 | this.setFirstSwipe(messageId); |
| 3244 | 3247 | } |
| 3245 | 3248 | |
| @@ -27,6 +27,7 @@ function getMessageFromJquery(element) { | ||
| 27 | 27 | */ |
| 28 | 28 | export class PromptReasoning { |
| 29 | 29 | static REASONING_PLACEHOLDER = '\u200B'; |
| 30 | + static REASONING_PLACEHOLDER_REGEX = new RegExp(`${PromptReasoning.REASONING_PLACEHOLDER}$`); | |
| 30 | 31 | |
| 31 | 32 | constructor() { |
| 32 | 33 | this.counter = 0; |
| @@ -121,8 +122,8 @@ function registerReasoningSlashCommands() { | ||
| 121 | 122 | callback: (_args, value) => { |
| 122 | 123 | const messageId = !isNaN(Number(value)) ? Number(value) : chat.length - 1; |
| 123 | 124 | const message = chat[messageId]; |
| 124 | 125 | const reasoning = String(message?.extra?.reasoning ?? ''); |
| 125 | 126 | return reasoning !== .replace(PromptReasoning.REASONING_PLACEHOLDER ? reasoning :REASONING_PLACEHOLDER_REGEX, ''); |
| 126 | 127 | }, |
| 127 | 128 | })); |
| 128 | 129 | |
| @@ -151,7 +152,7 @@ function registerReasoningSlashCommands() { | ||
| 151 | 152 | return ''; |
| 152 | 153 | } |
| 153 | 154 | |
| 154 | 155 | message.extra.reasoning = String(value ?? ''); |
| 155 | 156 | await saveChatConditional(); |
| 156 | 157 | |
| 157 | 158 | closeMessageEditor('reasoning'); |
| @@ -181,12 +182,12 @@ function setReasoningEventHandlers(){ | ||
| 181 | 182 | return; |
| 182 | 183 | } |
| 183 | 184 | |
| 184 | 185 | const reasoning = String(message?.extra?.reasoning ?? ''); |
| 185 | 186 | const chatElement = document.getElementById('chat'); |
| 186 | 187 | const textarea = document.createElement('textarea'); |
| 187 | 188 | const reasoningBlock = messageBlock.find('.mes_reasoning'); |
| 188 | 189 | textarea.classList.add('reasoning_edit_textarea'); |
| 189 | 190 | textarea.value = reasoning === .replace(PromptReasoning.REASONING_PLACEHOLDER ?REASONING_PLACEHOLDER_REGEX, '' : reasoning); |
| 190 | 191 | $(textarea).insertBefore(reasoningBlock); |
| 191 | 192 | |
| 192 | 193 | if (!CSS.supports('field-sizing', 'content')) { |
| @@ -277,7 +278,7 @@ function setReasoningEventHandlers(){ | ||
| 277 | 278 | |
| 278 | 279 | $(document).on('pointerup', '.mes_reasoning_copy', async function () { |
| 279 | 280 | const { message } = getMessageFromJquery(this); |
| 280 | 281 | const reasoning = String(message?.extra?.reasoning ?? '').replace(PromptReasoning.REASONING_PLACEHOLDER_REGEX, ''); |
| 281 | 282 | |
| 282 | 283 | if (!reasoning) { |
| 283 | 284 | return; |