From 4802e4bed2e5a99c2701238205ad28a49acf6701 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 22 Feb 2025 19:14:01 +0200 Subject: [PATCH 01/28] Reasoning edit/parse updates 1. Parse reasoning on message edit 2. Reasoning edit follow 'auto-save' preference --- public/scripts/reasoning.js | 39 +++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/public/scripts/reasoning.js b/public/scripts/reasoning.js index 815135814..cf9a76352 100644 --- a/public/scripts/reasoning.js +++ b/public/scripts/reasoning.js @@ -1,7 +1,7 @@ import { moment, } from '../lib.js'; -import { chat, closeMessageEditor, event_types, eventSource, main_api, messageFormatting, saveChatConditional, saveSettingsDebounced, substituteParams, updateMessageBlock } from '../script.js'; +import { chat, closeMessageEditor, event_types, eventSource, main_api, messageFormatting, saveChatConditional, saveChatDebounced, saveSettingsDebounced, substituteParams, updateMessageBlock } from '../script.js'; import { getRegexedString, regex_placement } from './extensions/regex/engine.js'; import { getCurrentLocale, t, translate } from './i18n.js'; import { MacrosParser } from './macros.js'; @@ -755,6 +755,17 @@ function registerReasoningMacros() { } function setReasoningEventHandlers() { + /** + * Updates the reasoning block of a message from a value. + * @param {object} message Message object + * @param {string} value Reasoning value + */ + function updateReasoningFromValue(message, value) { + const reasoning = getRegexedString(value, regex_placement.REASONING, { isEdit: true }); + message.extra.reasoning = reasoning; + message.extra.reasoning_type = message.extra.reasoning_type ? ReasoningType.Edited : ReasoningType.Manual; + } + $(document).on('click', '.mes_reasoning_details', function (e) { if (!e.target.closest('.mes_reasoning_actions') && !e.target.closest('.mes_reasoning_header')) { e.preventDefault(); @@ -835,9 +846,7 @@ function setReasoningEventHandlers() { } const textarea = messageBlock.find('.reasoning_edit_textarea'); - const reasoning = getRegexedString(String(textarea.val()), regex_placement.REASONING, { isEdit: true }); - message.extra.reasoning = reasoning; - message.extra.reasoning_type = message.extra.reasoning_type ? ReasoningType.Edited : ReasoningType.Manual; + updateReasoningFromValue(message, String(textarea.val())); await saveChatConditional(); updateMessageBlock(messageId, message); textarea.remove(); @@ -917,6 +926,20 @@ function setReasoningEventHandlers() { await copyText(reasoning); toastr.info(t`Copied!`, '', { timeOut: 2000 }); }); + + $(document).on('input', '.reasoning_edit_textarea', function () { + if (!power_user.auto_save_msg_edits) { + return; + } + + const { message } = getMessageFromJquery(this); + if (!message?.extra) { + return; + } + + updateReasoningFromValue(message, String($(this).val())); + saveChatDebounced(); + }); } /** @@ -973,7 +996,7 @@ function parseReasoningFromString(str, { strict = true } = {}) { } function registerReasoningAppEvents() { - eventSource.makeFirst(event_types.MESSAGE_RECEIVED, (/** @type {number} */ idx) => { + const eventHandler = (/** @type {number} */ idx) => { if (!power_user.reasoning.auto_parse) { return; } @@ -1029,7 +1052,11 @@ function registerReasoningAppEvents() { updateMessageBlock(idx, message); } } - }); + }; + + for (const event of [event_types.MESSAGE_RECEIVED, event_types.MESSAGE_UPDATED]) { + eventSource.on(event, eventHandler); + } } export function initReasoning() { From 5a22e6446680f7eca6b1d58d69b1483a305da7ae Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sun, 23 Feb 2025 02:26:36 +0100 Subject: [PATCH 02/28] Improve tooltip for never_resize_avatars --- public/index.html | 2 +- public/locales/ar-sa.json | 2 +- public/locales/de-de.json | 2 +- public/locales/es-es.json | 2 +- public/locales/fr-fr.json | 2 +- public/locales/is-is.json | 2 +- public/locales/it-it.json | 2 +- public/locales/ja-jp.json | 2 +- public/locales/ko-kr.json | 2 +- public/locales/nl-nl.json | 2 +- public/locales/pt-pt.json | 2 +- public/locales/ru-ru.json | 2 +- public/locales/uk-ua.json | 2 +- public/locales/vi-vn.json | 2 +- public/locales/zh-cn.json | 2 +- public/locales/zh-tw.json | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/public/index.html b/public/index.html index 37c66237f..7a49adc3c 100644 --- a/public/index.html +++ b/public/index.html @@ -4429,7 +4429,7 @@ Prefer Char. Instructions -