Yoink reasoning placeholder from being saved
| @@ -401,8 +401,7 @@ export class ReasoningHandler { | |||
| 401 | * Keeps track of the number of reasoning additions. | 401 | * Keeps track of the number of reasoning additions. |
| 402 | */ | 402 | */ |
| 403 | export class PromptReasoning { | 403 | export class PromptReasoning { |
| 404 | static REASONING_PLACEHOLDER = '\u200B'; | 404 | static REASONING_UI_PLACEHOLDER = '\u200B'; |
| 405 | static REASONING_PLACEHOLDER_REGEX = new RegExp(`${PromptReasoning.REASONING_PLACEHOLDER}$`); | ||
| 406 | 405 | ||
| 407 | constructor() { | 406 | constructor() { |
| 408 | this.counter = 0; | 407 | this.counter = 0; |
| @@ -433,8 +432,8 @@ export class PromptReasoning { | |||
| 433 | return content; | 432 | return content; |
| 434 | } | 433 | } |
| 435 | 434 | ||
| 436 | // No reasoning provided or a placeholder | 435 | // No reasoning provided |
| 437 | if (!reasoning || reasoning === PromptReasoning.REASONING_PLACEHOLDER) { | 436 | if (!reasoning) { |
| 438 | return content; | 437 | return content; |
| 439 | } | 438 | } |
| 440 | 439 | ||
| @@ -518,7 +517,7 @@ function registerReasoningSlashCommands() { | |||
| 518 | const messageId = !isNaN(parseInt(value.toString())) ? parseInt(value.toString()) : chat.length - 1; | 517 | const messageId = !isNaN(parseInt(value.toString())) ? parseInt(value.toString()) : chat.length - 1; |
| 519 | const message = chat[messageId]; | 518 | const message = chat[messageId]; |
| 520 | const reasoning = String(message?.extra?.reasoning ?? ''); | 519 | const reasoning = String(message?.extra?.reasoning ?? ''); |
| 521 | return reasoning.replace(PromptReasoning.REASONING_PLACEHOLDER_REGEX, ''); | 520 | return reasoning; |
| 522 | }, | 521 | }, |
| 523 | })); | 522 | })); |
| 524 | 523 | ||
| @@ -645,7 +644,7 @@ function setReasoningEventHandlers() { | |||
| 645 | const textarea = document.createElement('textarea'); | 644 | const textarea = document.createElement('textarea'); |
| 646 | const reasoningBlock = messageBlock.find('.mes_reasoning'); | 645 | const reasoningBlock = messageBlock.find('.mes_reasoning'); |
| 647 | textarea.classList.add('reasoning_edit_textarea'); | 646 | textarea.classList.add('reasoning_edit_textarea'); |
| 648 | textarea.value = reasoning.replace(PromptReasoning.REASONING_PLACEHOLDER_REGEX, ''); | 647 | textarea.value = reasoning; |
| 649 | $(textarea).insertBefore(reasoningBlock); | 648 | $(textarea).insertBefore(reasoningBlock); |
| 650 | 649 | ||
| 651 | if (!CSS.supports('field-sizing', 'content')) { | 650 | if (!CSS.supports('field-sizing', 'content')) { |
| @@ -699,11 +698,17 @@ function setReasoningEventHandlers() { | |||
| 699 | const textarea = messageBlock.find('.reasoning_edit_textarea'); | 698 | const textarea = messageBlock.find('.reasoning_edit_textarea'); |
| 700 | textarea.remove(); | 699 | textarea.remove(); |
| 701 | 700 | ||
| 701 | // Make sure we remove the fake placeholder from the reasoning string | ||
| 702 | const text = messageBlock.find('.mes_reasoning').text(); | ||
| 703 | if (text === PromptReasoning.REASONING_UI_PLACEHOLDER) { | ||
| 704 | messageBlock.find('.mes_reasoning').text(''); | ||
| 705 | } | ||
| 706 | |||
| 702 | messageBlock.find('.mes_reasoning_edit_cancel:visible').trigger('click'); | 707 | messageBlock.find('.mes_reasoning_edit_cancel:visible').trigger('click'); |
| 703 | }); | 708 | }); |
| 704 | 709 | ||
| 705 | $(document).on('click', '.mes_edit_add_reasoning', async function () { | 710 | $(document).on('click', '.mes_edit_add_reasoning', async function () { |
| 706 | const { message, messageId, messageBlock } = getMessageFromJquery(this); | 711 | const { message, messageBlock } = getMessageFromJquery(this); |
| 707 | if (!message?.extra) { | 712 | if (!message?.extra) { |
| 708 | return; | 713 | return; |
| 709 | } | 714 | } |
| @@ -713,8 +718,9 @@ function setReasoningEventHandlers() { | |||
| 713 | return; | 718 | return; |
| 714 | } | 719 | } |
| 715 | 720 | ||
| 716 | message.extra.reasoning = PromptReasoning.REASONING_PLACEHOLDER; | 721 | // To be able to edit, we need to "fake" content being there inside the reasoning string |
| 717 | updateMessageBlock(messageId, message, { rerenderMessage: false }); | 722 | messageBlock.find('.mes_reasoning').text(PromptReasoning.REASONING_UI_PLACEHOLDER); |
| 723 | |||
| 718 | messageBlock.find('.mes_reasoning_edit').trigger('click'); | 724 | messageBlock.find('.mes_reasoning_edit').trigger('click'); |
| 719 | await saveChatConditional(); | 725 | await saveChatConditional(); |
| 720 | }); | 726 | }); |
| @@ -742,7 +748,7 @@ function setReasoningEventHandlers() { | |||
| 742 | 748 | ||
| 743 | $(document).on('pointerup', '.mes_reasoning_copy', async function () { | 749 | $(document).on('pointerup', '.mes_reasoning_copy', async function () { |
| 744 | const { message } = getMessageFromJquery(this); | 750 | const { message } = getMessageFromJquery(this); |
| 745 | const reasoning = String(message?.extra?.reasoning ?? '').replace(PromptReasoning.REASONING_PLACEHOLDER_REGEX, ''); | 751 | const reasoning = String(message?.extra?.reasoning ?? ''); |
| 746 | 752 | ||
| 747 | if (!reasoning) { | 753 | if (!reasoning) { |
| 748 | return; | 754 | return; |