Merge branch 'staging' into fnr

cee71707633009388c4d79dec410e33fbabb4961

Cohee <18619528+Cohee1207@users.noreply.github.com>

29 files changed, +537 -177Ignore whitespace
public/css/toggle-dependent.css+5 -0
@@ -472,6 +472,11 @@ label[for="trim_spaces"]:has(input:checked) i.warning {
472472 display: none;
473473}
474474
475+label[for="trim_spaces"]:not(:has(input:checked)) small {
476+ color: var(--warning);
477+ opacity: 1;
478+}
479+
475480#claude_function_prefill_warning {
476481 display: none;
477482 color: red;
public/index.html+16 -23
@@ -1981,13 +1981,13 @@
19811981 <label for="openai_show_thoughts" class="checkbox_label widthFreeExpand">
19821982 <input id="openai_show_thoughts" type="checkbox" />
19831983 <span>
19841984 <span data-i18n="ShowRequest model reasoning">ShowRequest model reasoning</span>
19851985 <i class="opacity50p fa-solid fa-circle-info" title="Gemini 2.0 Thinking / DeepSeek Reasoner"></i>
19861986 </span>
19871987 </label>
19881988 <div class="toggle-description justifyLeft marginBot5">
19891989 <span data-i18n="DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess.">
19901990 DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess.
19911991 </span>
19921992 </div>
19931993 </div>
@@ -3227,32 +3227,19 @@
32273227 <h4 data-i18n="Perplexity Model">Perplexity Model</h4>
32283228 <select id="model_perplexity_select">
32293229 <optgroup label="Perplexity Sonar Models">
3230+ <option value="sonar">sonar</option>
3231+ <option value="sonar-pro">sonar-pro</option>
3232+ <option value="sonar-reasoning">sonar-reasoning</option>
3233+ </optgroup>
3234+ <optgroup label="Deprecated Models">
3235+ <!-- These are scheduled for deprecation after 2/22/2025 -->
32303236 <option value="llama-3.1-sonar-small-128k-online">llama-3.1-sonar-small-128k-online</option>
32313237 <option value="llama-3.1-sonar-large-128k-online">llama-3.1-sonar-large-128k-online</option>
32323238 <option value="llama-3.1-sonar-huge-128k-online">llama-3.1-sonar-huge-128k-online</option>
3233- </optgroup>
3239+ <!-- These are not listed on the site anymore -->
3234- <optgroup label="Perplexity Chat Models">
32353240 <option value="llama-3.1-sonar-small-128k-chat">llama-3.1-sonar-small-128k-chat</option>
32363241 <option value="llama-3.1-sonar-large-128k-chat">llama-3.1-sonar-large-128k-chat</option>
32373242 </optgroup>
3238- <optgroup label="Open-Source Models">
3239- <option value="llama-3.1-8b-instruct">llama-3.1-8b-instruct</option>
3240- <option value="llama-3.1-70b-instruct">llama-3.1-70b-instruct</option>
3241- </optgroup>
3242- <optgroup label="Deprecated Models">
3243- <option value="llama-3-sonar-small-32k-chat">llama-3-sonar-small-32k-chat</option>
3244- <option value="llama-3-sonar-small-32k-online">llama-3-sonar-small-32k-online</option>
3245- <option value="llama-3-sonar-large-32k-chat">llama-3-sonar-large-32k-chat</option>
3246- <option value="llama-3-sonar-large-32k-online">llama-3-sonar-large-32k-online</option>
3247- <option value="sonar-small-chat">sonar-small-chat</option>
3248- <option value="sonar-small-online">sonar-small-online</option>
3249- <option value="sonar-medium-chat">sonar-medium-chat</option>
3250- <option value="sonar-medium-online">sonar-medium-online</option>
3251- <option value="llama-3-8b-instruct">llama-3-8b-instruct</option>
3252- <option value="llama-3-70b-instruct">llama-3-70b-instruct</option>
3253- <option value="mistral-7b-instruct">mistral-7b-instruct (v0.2)</option>
3254- <option value="mixtral-8x7b-instruct">mixtral-8x7b-instruct</option>
3255- </optgroup>
32563243 </select>
32573244 </div>
32583245 <form id="cohere_form" data-source="cohere" action="javascript:void(null);" method="post" enctype="multipart/form-data">
@@ -3804,6 +3791,12 @@
38043791 <span data-i18n="Reasoning">Reasoning</span>
38053792 </h4>
38063793 <div>
3794+ <label class="checkbox_label" for="reasoning_auto_parse" title="Automatically parse reasoning blocks from main content between the reasoning prefix/suffix. Both fields must be defined and non-empty." data-i18n="[title]reasoning_auto_parse">
3795+ <input id="reasoning_auto_parse" type="checkbox" />
3796+ <small data-i18n="Auto-Parse Reasoning">
3797+ Auto-Parse Reasoning
3798+ </small>
3799+ </label>
38073800 <label class="checkbox_label" for="reasoning_add_to_prompts" title="Add existing reasoning blocks to prompts. To add a new reasoning block, use the message edit menu." data-i18n="[title]reasoning_add_to_prompts">
38083801 <input id="reasoning_add_to_prompts" type="checkbox" />
38093802 <small data-i18n="Add Reasoning to Prompts">
public/locales/fr-fr.json+2 -2
@@ -1385,8 +1385,8 @@
13851385 "enable_functions_desc_1": "Autorise l'utilisation",
13861386 "enable_functions_desc_2": "outils de fonction",
13871387 "enable_functions_desc_3": "Peut être utilisé par diverses extensions pour fournir des fonctionnalités supplémentaires.",
13881388 "ShowRequest model reasoning": "AfficherDemander les pensées du modèle",
13891389 "DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess.": "AfficherPermet lesau penséesmodèle internesde duretourner modèleson dansprocessus lade réponseréflexion.",
13901390 "Confirm token parsing with": "Confirmer l'analyse des tokens avec",
13911391 "openai_logit_bias_no_items": "Aucun élément",
13921392 "api_no_connection": "Pas de connection...",
public/locales/zh-cn.json+2 -2
@@ -266,8 +266,8 @@
266266 "Use system prompt": "使用系统提示词",
267267 "Merges_all_system_messages_desc_1": "合并所有系统消息,直到第一条具有非系统角色的消息,然后通过",
268268 "Merges_all_system_messages_desc_2": "字段发送。",
269269 "ShowRequest model reasoning": "展示思维链请求思维链",
270270 "DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess.": "展示模型在回复时的内部思维链允许模型返回其思维过程。",
271271 "Assistant Prefill": "AI预填",
272272 "Expand the editor": "展开编辑器",
273273 "Start Claude's answer with...": "以如下内容开始Claude的回答...",
public/locales/zh-tw.json+2 -2
@@ -2357,8 +2357,8 @@
23572357 "Forbid": "禁止",
23582358 "Aphrodite only. Determines the order of samplers. Skew is always applied post-softmax, so it's not included here.": "僅限 Aphrodite 使用。決定採樣器的順序。偏移總是在 softmax 後應用,因此不包括在此。",
23592359 "Aphrodite only. Determines the order of samplers.": "僅限 Aphrodite 使用。決定採樣器的順序。",
23602360 "ShowRequest model reasoning": "顯示模型思維鏈請求模型思維鏈",
23612361 "DisplayAllows the model's internalto thoughtsreturn inits thethinking responseprocess.": "在回應中顯示模型的思維鏈(內部思考過程)讓模型回傳其思考過程。",
23622362 "Generic (OpenAI-compatible) [LM Studio, LiteLLM, etc.]": "通用(兼容 OpenAI)[LM Studio, LiteLLM 等]",
23632363 "Model ID (optional)": "模型 ID(可選)",
23642364 "DeepSeek API Key": "DeepSeek API 金鑰",
public/script.js+90 -78
@@ -95,6 +95,7 @@ import {
9595 resetMovableStyles,
9696 forceCharacterEditorTokenize,
9797 applyPowerUserSettings,
98+ generatedTextFiltered,
9899} from './scripts/power-user.js';
99100
100101import {
@@ -169,6 +170,7 @@ import {
169170 toggleDrawer,
170171 isElementInViewport,
171172 copyText,
173+ escapeHtml,
172174} from './scripts/utils.js';
173175import { debounce_timeout } from './scripts/constants.js';
174176
@@ -1993,14 +1995,15 @@ export async function sendTextareaMessage() {
19931995 * @param {boolean} isUser If the message was sent by the user
19941996 * @param {number} messageId Message index in chat array
19951997 * @param {object} [sanitizerOverrides] DOMPurify sanitizer option overrides
1998+ * @param {boolean} [isReasoning] If the message is reasoning output
19961999 * @returns {string} HTML string
19972000 */
19982001export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, sanitizerOverrides = {}, isReasoning = false) {
19992002 if (!mes) {
20002003 return '';
20012004 }
20022005
20032006 if (Number(messageId) === 0 && !isSystem && !isUser && !isReasoning) {
20042007 const mesBeforeReplace = mes;
20052008 const chatMessage = chat[messageId];
20062009 mes = substituteParams(mes, undefined, ch_name);
@@ -2029,6 +2032,9 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san
20292032 if (!isSystem) {
20302033 function getRegexPlacement() {
20312034 try {
2035+ if (isReasoning) {
2036+ return regex_placement.REASONING;
2037+ }
20322038 if (isUser) {
20332039 return regex_placement.USER_INPUT;
20342040 } else if (chat[messageId]?.extra?.type === 'narrator') {
@@ -2062,6 +2068,17 @@ export function messageFormatting(mes, ch_name, isSystem, isUser, messageId, san
20622068 mes = mes.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
20632069 }
20642070
2071+ // Make sure reasoning strings are always shown, even if they include "<" or ">"
2072+ [power_user.reasoning.prefix, power_user.reasoning.suffix].forEach((reasoningString) => {
2073+ if (!reasoningString || !reasoningString.trim().length) {
2074+ return;
2075+ }
2076+ // Only replace the first occurrence of the reasoning string
2077+ if (mes.includes(reasoningString)) {
2078+ mes = mes.replace(reasoningString, escapeHtml(reasoningString));
2079+ }
2080+ });
2081+
20652082 if (!isSystem) {
20662083 // Save double quotes in tags as a special character to prevent them from being encoded
20672084 if (!power_user.encode_tags) {
@@ -2250,8 +2267,8 @@ function getMessageFromTemplate({
22502267export function updateMessageBlock(messageId, message) {
22512268 const messageElement = $(`#chat [mesid="${messageId}"]`);
22522269 const text = message?.extra?.display_text ?? message.mes;
22532270 messageElement.find('.mes_text').html(messageFormatting(text, message.name, message.is_system, message.is_user, messageId, {}, false));
22542271 messageElement.find('.mes_reasoning').html(messageFormatting(message.extra?.reasoning ?? '', '', false, false, -1messageId, {}, true));
22552272 addCopyToCodeBlocks(messageElement);
22562273 appendMediaToMessage(message, messageElement);
22572274}
@@ -2408,9 +2425,10 @@ export function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll
24082425 mes.is_user,
24092426 chat.indexOf(mes),
24102427 sanitizerOverrides,
2428+ false,
24112429 );
24122430 const bias = messageFormatting(mes.extra?.bias ?? '', '', false, false, -1, {}, false);
24132431 const reasoning = messageFormatting(mes.extra?.reasoning ?? '', '', false, false, -1chat.indexOf(mes), {}, true);
24142432 let bookmarkLink = mes?.extra?.bookmark_link ?? '';
24152433
24162434 let params = {
@@ -3153,7 +3171,7 @@ class StreamingProcessor {
31533171 this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true }));
31543172 }
31553173 else {
31563174 await saveReply(this.type, text, true, '', [], '');
31573175 messageId = chat.length - 1;
31583176 this.#checkDomElements(messageId);
31593177 this.showMessageButtons(messageId);
@@ -3203,9 +3221,9 @@ class StreamingProcessor {
32033221 }
32043222
32053223 if (this.reasoning) {
32063224 chat[messageId]['extra']['reasoning'] = power_user.trim_spaces ? this.reasoning.trim() : this.reasoning;
32073225 if (this.messageReasoningDom instanceof HTMLElement) {
32083226 const formattedReasoning = messageFormatting(this.reasoning, '', false, false, -1messageId, {}, true);
32093227 this.messageReasoningDom.innerHTML = formattedReasoning;
32103228 }
32113229 }
@@ -3232,6 +3250,8 @@ class StreamingProcessor {
32323250 chat[messageId].is_system,
32333251 chat[messageId].is_user,
32343252 messageId,
3253+ {},
3254+ false,
32353255 );
32363256 if (this.messageTextDom instanceof HTMLElement) {
32373257 this.messageTextDom.innerHTML = formattedText;
@@ -3283,39 +3303,11 @@ class StreamingProcessor {
32833303 unblockGeneration();
32843304 generatedPromptCache = '';
32853305
3286- //console.log("Generated text size:", text.length, text)
3287-
32883306 const isAborted = this.abortController.signal.aborted;
32893307 if (!isAborted && power_user.auto_swipe && !isAbortedgeneratedTextFiltered(text)) {
3290- function containsBlacklistedWords(str, blacklist, threshold) {
3308+ return swipe_right();
3291- const regex = new RegExp(`\\b(${blacklist.join('|')})\\b`, 'gi');
3292- const matches = str.match(regex) || [];
3293- return matches.length >= threshold;
3294- }
3295-
3296- const generatedTextFiltered = (text) => {
3297- if (text) {
3298- if (power_user.auto_swipe_minimum_length) {
3299- if (text.length < power_user.auto_swipe_minimum_length && text.length !== 0) {
3300- console.log('Generated text size too small');
3301- return true;
3302- }
3303- }
3304- if (power_user.auto_swipe_blacklist_threshold) {
3305- if (containsBlacklistedWords(text, power_user.auto_swipe_blacklist, power_user.auto_swipe_blacklist_threshold)) {
3306- console.log('Generated text has blacklisted words');
3307- return true;
3308- }
3309- }
3310- }
3311- return false;
3312- };
3313-
3314- if (generatedTextFiltered(text)) {
3315- swipe_right();
3316- return;
3317- }
33183309 }
3310+
33193311 playMessageSound();
33203312 }
33213313
@@ -3373,7 +3365,7 @@ class StreamingProcessor {
33733365 const timestamps = [];
33743366 for await (const { text, swipes, logprobs, toolCalls, state } of this.generator()) {
33753367 timestamps.push(Date.now());
33763368 if (this.isStopped || this.abortController.signal.aborted) {
33773369 return;
33783370 }
33793371
@@ -3383,7 +3375,7 @@ class StreamingProcessor {
33833375 if (logprobs) {
33843376 this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs]));
33853377 }
33863378 this.reasoning = getRegexedString(state?.reasoning ?? '', regex_placement.REASONING);
33873379 await eventSource.emit(event_types.STREAM_TOKEN_RECEIVED, text);
33883380 await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text));
33893381 }
@@ -3850,14 +3842,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
38503842 coreChat.pop();
38513843 }
38523844
3853- const reasoning = new PromptReasoning();
3854- for (let i = coreChat.length - 1; i >= 0; i--) {
3855- if (reasoning.isLimitReached()) {
3856- break;
3857- }
3858- coreChat[i] = { ...coreChat[i], mes: reasoning.addToMessage(coreChat[i].mes, coreChat[i].extra?.reasoning) };
3859- }
3860-
38613845 coreChat = await Promise.all(coreChat.map(async (chatItem, index) => {
38623846 let message = chatItem.mes;
38633847 let regexType = chatItem.is_user ? regex_placement.USER_INPUT : regex_placement.AI_OUTPUT;
@@ -3877,6 +3861,27 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
38773861 };
38783862 }));
38793863
3864+ const reasoning = new PromptReasoning();
3865+ for (let i = coreChat.length - 1; i >= 0; i--) {
3866+ const depth = coreChat.length - i - 1;
3867+ const isPrefix = isContinue && i === coreChat.length - 1;
3868+ coreChat[i] = {
3869+ ...coreChat[i],
3870+ mes: reasoning.addToMessage(
3871+ coreChat[i].mes,
3872+ getRegexedString(
3873+ String(coreChat[i].extra?.reasoning ?? ''),
3874+ regex_placement.REASONING,
3875+ { isPrompt: true, depth: depth },
3876+ ),
3877+ isPrefix,
3878+ ),
3879+ };
3880+ if (reasoning.isLimitReached()) {
3881+ break;
3882+ }
3883+ }
3884+
38803885 // Determine token limit
38813886 let this_max_context = getMaxContextSize();
38823887
@@ -4785,6 +4790,11 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
47854790 const swipes = extractMultiSwipes(data, type);
47864791
47874792 messageChunk = cleanUpMessage(getMessage, isImpersonate, isContinue, false);
4793+ reasoning = getRegexedString(reasoning, regex_placement.REASONING);
4794+
4795+ if (power_user.trim_spaces) {
4796+ reasoning = reasoning.trim();
4797+ }
47884798
47894799 if (isContinue) {
47904800 getMessage = continue_mag + getMessage;
@@ -4843,32 +4853,9 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
48434853 }
48444854
48454855 const isAborted = abortController && abortController.signal.aborted;
48464856 if (!isAborted && power_user.auto_swipe && !isAbortedgeneratedTextFiltered(getMessage)) {
4847- console.debug('checking for autoswipeblacklist on non-streaming message');
4857+ is_send_press = false;
4848- function containsBlacklistedWords(getMessage, blacklist, threshold) {
4858+ return swipe_right();
4849- console.debug('checking blacklisted words');
4850- const regex = new RegExp(`\\b(${blacklist.join('|')})\\b`, 'gi');
4851- const matches = getMessage.match(regex) || [];
4852- return matches.length >= threshold;
4853- }
4854-
4855- const generatedTextFiltered = (getMessage) => {
4856- if (power_user.auto_swipe_blacklist_threshold) {
4857- if (containsBlacklistedWords(getMessage, power_user.auto_swipe_blacklist, power_user.auto_swipe_blacklist_threshold)) {
4858- console.debug('Generated text has blacklisted words');
4859- return true;
4860- }
4861- }
4862-
4863- return false;
4864- };
4865- if (generatedTextFiltered(getMessage)) {
4866- console.debug('swiping right automatically');
4867- is_send_press = false;
4868- swipe_right();
4869- // TODO: do we want to resolve after an auto-swipe?
4870- return;
4871- }
48724859 }
48734860
48744861 console.debug('/api/chats/save called by /Generate');
@@ -6074,6 +6061,19 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes,
60746061 return { type, getMessage };
60756062}
60766063
6064+export function syncCurrentSwipeInfoExtras() {
6065+ if (!chat.length) {
6066+ return;
6067+ }
6068+ const currentMessage = chat[chat.length - 1];
6069+ if (currentMessage && Array.isArray(currentMessage.swipe_info) && typeof currentMessage.swipe_id === 'number') {
6070+ const swipeInfo = currentMessage.swipe_info[currentMessage.swipe_id];
6071+ if (swipeInfo && typeof swipeInfo === 'object') {
6072+ swipeInfo.extra = structuredClone(currentMessage.extra);
6073+ }
6074+ }
6075+}
6076+
60776077function saveImageToMessage(img, mes) {
60786078 if (mes && img.image) {
60796079 if (!mes.extra || typeof mes.extra !== 'object') {
@@ -7177,9 +7177,11 @@ function messageEditAuto(div) {
71777177 mes.is_system,
71787178 mes.is_user,
71797179 this_edit_mes_id,
7180+ {},
7181+ false,
71807182 ));
71817183 mesBlock.find('.mes_bias').empty();
71827184 mesBlock.find('.mes_bias').append(messageFormatting(bias, '', false, false, -1, {}, false));
71837185 saveChatDebounced();
71847186}
71857187
@@ -7201,10 +7203,12 @@ async function messageEditDone(div) {
72017203 mes.is_system,
72027204 mes.is_user,
72037205 this_edit_mes_id,
7206+ {},
7207+ false,
72047208 ),
72057209 );
72067210 mesBlock.find('.mes_bias').empty();
72077211 mesBlock.find('.mes_bias').append(messageFormatting(bias, '', false, false, -1, {}, false));
72087212 appendMediaToMessage(mes, div.closest('.mes'));
72097213 addCopyToCodeBlocks(div.closest('.mes'));
72107214
@@ -8501,6 +8505,9 @@ function swipe_left() { // when we swipe left..but no generation.
85018505 streamingProcessor.onStopStreaming();
85028506 }
85038507
8508+ // Make sure ad-hoc changes to extras are saved before swiping away
8509+ syncCurrentSwipeInfoExtras();
8510+
85048511 const swipe_duration = 120;
85058512 const swipe_range = '700px';
85068513 chat[chat.length - 1]['swipe_id']--;
@@ -8636,6 +8643,9 @@ const swipe_right = () => {
86368643 return unblockGeneration();
86378644 }
86388645
8646+ // Make sure ad-hoc changes to extras are saved before swiping away
8647+ syncCurrentSwipeInfoExtras();
8648+
86398649 const swipe_duration = 200;
86408650 const swipe_range = 700;
86418651 //console.log(swipe_range);
@@ -10841,6 +10851,8 @@ jQuery(async function () {
1084110851 chat[this_edit_mes_id].is_system,
1084210852 chat[this_edit_mes_id].is_user,
1084310853 this_edit_mes_id,
10854+ {},
10855+ false,
1084410856 ));
1084510857 appendMediaToMessage(chat[this_edit_mes_id], $(this).closest('.mes'));
1084610858 addCopyToCodeBlocks($(this).closest('.mes'));
public/scripts/authors-note.js+1 -1
@@ -566,7 +566,7 @@ export function initAuthorsNote() {
566566 namedArgumentList: [],
567567 unnamedArgumentList: [
568568 new SlashCommandArgument(
569569 'positionrole', [ARGUMENT_TYPE.STRING], false, false, null, ['system', 'user', 'assistant'],
570570 ),
571571 ],
572572 helpString: `
public/scripts/backgrounds.js+15 -5
@@ -96,8 +96,13 @@ function highlightLockedBackground() {
9696 });
9797}
9898
99+/**
100+ * Locks the background for the current chat
101+ * @param {Event} e Click event
102+ * @returns {string} Empty string
103+ */
99104function onLockBackgroundClick(e) {
100105 e?.stopPropagation();
101106
102107 const chatName = getCurrentChatId();
103108
@@ -106,7 +111,7 @@ function onLockBackgroundClick(e) {
106111 return '';
107112 }
108113
109114 const relativeBgImage = getUrlParameter(this) ?? background_settings.url;
110115
111116 saveBackgroundMetadata(relativeBgImage);
112117 setCustomBackground();
@@ -114,8 +119,13 @@ function onLockBackgroundClick(e) {
114119 return '';
115120}
116121
122+/**
123+ * Locks the background for the current chat
124+ * @param {Event} e Click event
125+ * @returns {string} Empty string
126+ */
117127function onUnlockBackgroundClick(e) {
118128 e?.stopPropagation();
119129 removeBackgroundMetadata();
120130 unsetCustomBackground();
121131 highlightLockedBackground();
@@ -513,12 +523,12 @@ export function initBackgrounds() {
513523 $('#add_bg_button').on('change', onBackgroundUploadSelected);
514524 $('#bg-filter').on('input', onBackgroundFilterInput);
515525 SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'lockbg',
516- callback: onLockBackgroundClick,
526+ callback: () => onLockBackgroundClick(new CustomEvent('click')),
517527 aliases: ['bglock'],
518528 helpString: 'Locks a background for the currently selected chat',
519529 }));
520530 SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'unlockbg',
521- callback: onUnlockBackgroundClick,
531+ callback: () => onUnlockBackgroundClick(new CustomEvent('click')),
522532 aliases: ['bgunlock'],
523533 helpString: 'Unlocks a background for the currently selected chat',
524534 }));
public/scripts/extensions/connection-manager/index.js+4 -0
@@ -30,6 +30,7 @@ const CC_COMMANDS = [
3030 'api-url',
3131 'model',
3232 'proxy',
33+ 'stop-strings',
3334];
3435
3536const TC_COMMANDS = [
@@ -43,6 +44,7 @@ const TC_COMMANDS = [
4344 'context',
4445 'instruct-state',
4546 'tokenizer',
47+ 'stop-strings',
4648];
4749
4850const FANCY_NAMES = {
@@ -57,6 +59,7 @@ const FANCY_NAMES = {
5759 'instruct': 'Instruct Template',
5860 'context': 'Context Template',
5961 'tokenizer': 'Tokenizer',
62+ 'stop-strings': 'Custom Stopping Strings',
6063};
6164
6265/**
@@ -138,6 +141,7 @@ const profilesProvider = () => [
138141 * @property {string} [context] Context Template
139142 * @property {string} [instruct-state] Instruct Mode
140143 * @property {string} [tokenizer] Tokenizer
144+ * @property {string} [stop-strings] Custom Stopping Strings
141145 * @property {string[]} [exclude] Commands to exclude
142146 */
143147
public/scripts/extensions/quick-reply/src/SlashCommandHandler.js+4 -0
@@ -883,6 +883,10 @@ export class SlashCommandHandler {
883883 }
884884 }
885885 getQuickReply(args) {
886+ if (!args.id && !args.label) {
887+ toastr.error('Please provide a valid id or label.');
888+ return '';
889+ }
886890 try {
887891 return JSON.stringify(this.api.getQrByLabel(args.set, args.id !== undefined ? Number(args.id) : args.label));
888892 } catch (ex) {
public/scripts/extensions/regex/editor.html+6 -0
@@ -94,6 +94,12 @@
9494 <span data-i18n="World Info">World Info</span>
9595 </label>
9696 </div>
97+ <div data-i18n="[title]ext_regex_reasoning_desc" title="Reasoning block contents. When 'Only Format Prompt' is checked, it will also affect the reasoning contents added to the prompt.">
98+ <label class="checkbox flex-container">
99+ <input type="checkbox" name="replace_position" value="6">
100+ <span data-i18n="Reasoning">Reasoning</span>
101+ </label>
102+ </div>
97103 <div class="flex-container wide100p marginTop5">
98104 <div class="flex1 flex-container flexNoGap">
99105 <small data-i18n="[title]ext_regex_min_depth_desc" title="When applied to prompts or display, only affect messages that are at least N levels deep. 0 = last message, 1 = penultimate message, etc. Only counts WI entries @Depth and usable messages, i.e. not hidden or system.">
public/scripts/extensions/regex/engine.js+2 -1
@@ -20,6 +20,7 @@ const regex_placement = {
2020 SLASH_COMMAND: 3,
2121 // 4 - sendAs (legacy)
2222 WORLD_INFO: 5,
23+ REASONING: 6,
2324};
2425
2526export const substitute_find_regex = {
@@ -94,7 +95,7 @@ function getRegexedString(rawString, placement, { characterOverride, isMarkdown,
9495 // Script applies to Generate and input is Generate
9596 (script.promptOnly && isPrompt) ||
9697 // Script applies to all cases when neither "only"s are true, but there's no need to do it when `isMarkdown`, the as source (chat history) should already be changed beforehand
9798 (!script.markdownOnly && !script.promptOnly && !isMarkdown && !isPrompt)
9899 ) {
99100 if (isEdit && !script.runOnEdit) {
100101 console.debug(`getRegexedString: Skipping script ${script.scriptName} because it does not run on edit`);
public/scripts/extensions/regex/index.js+1 -1
@@ -18,7 +18,7 @@ import { t } from '../../i18n.js';
1818 * @property {string} replaceString - The replace string
1919 * @property {string[]} trimStrings - The trim strings
2020 * @property {string?} findRegex - The find regex
2121 * @property {stringnumber?} substituteRegex - The substitute regex
2222 */
2323
2424/**
public/scripts/extensions/tts/alltalk.js+10 -6
@@ -388,7 +388,7 @@ class AllTalkTtsProvider {
388388 }
389389
390390 async fetchRvcVoiceObjects() {
391391 if (this.settings.server_version == 'v2v1') {
392392 console.log('Skipping RVC voices fetch for V1 server');
393393 return [];
394394 }
@@ -1031,14 +1031,18 @@ class AllTalkTtsProvider {
10311031 console.error('fetchTtsGeneration Error Response Text:', errorText);
10321032 throw new Error(`HTTP ${response.status}: ${errorText}`);
10331033 }
1034+
10341035 const data = await response.json();
10351036
1036- // Handle V1/V2 URL differences
1037+ // V1 returns a complete URL, V2 returns a relative path
10371038 const outputUrl =if (this.settings.server_version === 'v1') {
1038- ? data.output_file_url // V1 returns full URL
1039+ // V1: Use the complete URL directly from the response
1039- : `${this.settings.provider_endpoint}${data.output_file_url}`; // V2 returns relative path
1040+ return data.output_file_url;
1041+ } else {
1042+ // V2: Combine the endpoint with the relative path
1043+ return `${this.settings.provider_endpoint}${data.output_file_url}`;
1044+ }
10401045
1041- return outputUrl;
10421046 } catch (error) {
10431047 console.error('[fetchTtsGeneration] Exception caught:', error);
10441048 throw error;
public/scripts/extensions/tts/index.js+49 -6
@@ -30,6 +30,7 @@ import { GoogleTranslateTtsProvider } from './google-translate.js';
3030export { talkingAnimation };
3131
3232const UPDATE_INTERVAL = 1000;
33+const wrapper = new ModuleWorkerWrapper(moduleWorker);
3334
3435let voiceMapEntries = [];
3536let voiceMap = {}; // {charName:voiceid, charName2:voiceid2}
@@ -120,7 +121,7 @@ async function onNarrateOneMessage() {
120121 }
121122
122123 resetTtsPlayback();
123124 ttsJobQueue.pushprocessAndQueueTtsMessage(message);
124125 moduleWorker();
125126}
126127
@@ -147,7 +148,7 @@ async function onNarrateText(args, text) {
147148 }
148149
149150 resetTtsPlayback();
150151 ttsJobQueue.pushprocessAndQueueTtsMessage({ mes: text, name: name });
151152 await moduleWorker();
152153
153154 // Return back to the chat voices
@@ -220,6 +221,36 @@ function isTtsProcessing() {
220221 return processing;
221222}
222223
224+/**
225+ * Splits a message into lines and adds each non-empty line to the TTS job queue.
226+ * @param {Object} message - The message object to be processed.
227+ * @param {string} message.mes - The text of the message to be split into lines.
228+ * @param {string} message.name - The name associated with the message.
229+ * @returns {void}
230+ */
231+function processAndQueueTtsMessage(message) {
232+ if (!extension_settings.tts.narrate_by_paragraphs) {
233+ ttsJobQueue.push(message);
234+ return;
235+ }
236+
237+ const lines = message.mes.split('\n');
238+
239+ for (let i = 0; i < lines.length; i++) {
240+ const line = lines[i];
241+
242+ if (line.length === 0) {
243+ continue;
244+ }
245+
246+ ttsJobQueue.push(
247+ Object.assign({}, message, {
248+ mes: line,
249+ }),
250+ );
251+ }
252+}
253+
223254function debugTtsPlayback() {
224255 console.log(JSON.stringify(
225256 {
@@ -350,7 +381,7 @@ function onAudioControlClicked() {
350381 talkingAnimation(false);
351382 } else {
352383 // Default play behavior if not processing or playing is to play the last message.
353384 ttsJobQueue.pushprocessAndQueueTtsMessage(context.chat[context.chat.length - 1]);
354385 }
355386 updateUiAudioPlayState();
356387}
@@ -376,6 +407,7 @@ function completeCurrentAudioJob() {
376407 currentAudioJob = null;
377408 talkingAnimation(false); //stop lip animation
378409 // updateUiPlayState();
410+ wrapper.update();
379411}
380412
381413/**
@@ -466,7 +498,7 @@ async function processTtsQueue() {
466498 }
467499
468500 if (extension_settings.tts.skip_tags) {
469501 text = text.replace(/<.*?>.[\s\S]*?<\/.*?>/g, '').trim();
470502 }
471503
472504 if (!extension_settings.tts.pass_asterisks) {
@@ -569,6 +601,7 @@ function loadSettings() {
569601 $('#tts_narrate_quoted').prop('checked', extension_settings.tts.narrate_quoted_only);
570602 $('#tts_auto_generation').prop('checked', extension_settings.tts.auto_generation);
571603 $('#tts_periodic_auto_generation').prop('checked', extension_settings.tts.periodic_auto_generation);
604+ $('#tts_narrate_by_paragraphs').prop('checked', extension_settings.tts.narrate_by_paragraphs);
572605 $('#tts_narrate_translated_only').prop('checked', extension_settings.tts.narrate_translated_only);
573606 $('#tts_narrate_user').prop('checked', extension_settings.tts.narrate_user);
574607 $('#tts_pass_asterisks').prop('checked', extension_settings.tts.pass_asterisks);
@@ -638,6 +671,11 @@ function onPeriodicAutoGenerationClick() {
638671 saveSettingsDebounced();
639672}
640673
674+function onNarrateByParagraphsClick() {
675+ extension_settings.tts.narrate_by_paragraphs = !!$('#tts_narrate_by_paragraphs').prop('checked');
676+ saveSettingsDebounced();
677+}
678+
641679
642680function onNarrateDialoguesClick() {
643681 extension_settings.tts.narrate_dialogues_only = !!$('#tts_narrate_dialogues').prop('checked');
@@ -816,7 +854,12 @@ async function onMessageEvent(messageId, lastCharIndex) {
816854 lastChatId = context.chatId;
817855
818856 console.debug(`Adding message from ${message.name} for TTS processing: "${message.mes}"`);
819- ttsJobQueue.push(message);
857+
858+ if (extension_settings.tts.periodic_auto_generation) {
859+ ttsJobQueue.push(message);
860+ } else {
861+ processAndQueueTtsMessage(message);
862+ }
820863}
821864
822865async function onMessageDeleted() {
@@ -1156,6 +1199,7 @@ jQuery(async function () {
11561199 $('#tts_pass_asterisks').on('click', onPassAsterisksClick);
11571200 $('#tts_auto_generation').on('click', onAutoGenerationClick);
11581201 $('#tts_periodic_auto_generation').on('click', onPeriodicAutoGenerationClick);
1202+ $('#tts_narrate_by_paragraphs').on('click', onNarrateByParagraphsClick);
11591203 $('#tts_narrate_user').on('click', onNarrateUserClick);
11601204
11611205 $('#playback_rate').on('input', function () {
@@ -1177,7 +1221,6 @@ jQuery(async function () {
11771221 loadSettings(); // Depends on Extension Controls and loadTtsProvider
11781222 loadTtsProvider(extension_settings.tts.currentProvider); // No dependencies
11791223 addAudioControl(); // Depends on Extension Controls
1180- const wrapper = new ModuleWorkerWrapper(moduleWorker);
11811224 setInterval(wrapper.update.bind(wrapper), UPDATE_INTERVAL); // Init depends on all the things
11821225 eventSource.on(event_types.MESSAGE_SWIPED, resetTtsPlayback);
11831226 eventSource.on(event_types.CHAT_CHANGED, onChatChanged);
public/scripts/extensions/tts/settings.html+4 -0
@@ -30,6 +30,10 @@
3030 <input type="checkbox" id="tts_periodic_auto_generation">
3131 <small data-i18n="Narrate by paragraphs (when streaming)">Narrate by paragraphs (when streaming)</small>
3232 </label>
33+ <label class="checkbox_label" for="tts_narrate_by_paragraphs">
34+ <input type="checkbox" id="tts_narrate_by_paragraphs">
35+ <small data-i18n="Narrate by paragraphs (when not streaming)">Narrate by paragraphs (when not streaming)</small>
36+ </label>
3337 <label class="checkbox_label" for="tts_narrate_quoted">
3438 <input type="checkbox" id="tts_narrate_quoted">
3539 <small data-i18n="Only narrate quotes">Only narrate "quotes"</small>
public/scripts/loader.js+33 -12
@@ -27,24 +27,45 @@ export async function hideLoader() {
2727 }
2828
2929 return new Promise((resolve) => {
30- // Spinner blurs/fades out
30+ const spinner = $('#load-spinner');
31- $('#load-spinner').on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function () {
31+ if (!spinner.length) {
32+ console.warn('Spinner element not found, skipping animation');
33+ cleanup();
34+ return;
35+ }
36+
37+ // Check if transitions are enabled
38+ const transitionDuration = spinner[0] ? getComputedStyle(spinner[0]).transitionDuration : '0s';
39+ const hasTransitions = parseFloat(transitionDuration) > 0;
40+
41+ if (hasTransitions) {
42+ Promise.race([
43+ new Promise((r) => setTimeout(r, 500)), // Fallback timeout
44+ new Promise((r) => spinner.one('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', r)),
45+ ]).finally(cleanup);
46+ } else {
47+ cleanup();
48+ }
49+
50+ function cleanup() {
3251 $('#loader').remove();
3352 // Yoink preloader entirely; it only exists to cover up unstyled content while loading JS
3453 // If it's present, we remove it once and then it's gone.
3554 yoinkPreloader();
3655
3756 loaderPopup.complete(POPUP_RESULT.AFFIRMATIVE).then(() => {
38- loaderPopup = null;
57+ .catch((err) => console.error('Error completing loaderPopup:', err))
39- resolve();
58+ .finally(() => {
40- });
59+ loaderPopup = null;
41- });
60+ resolve();
61+ });
62+ }
4263
43- $('#load-spinner')
64+ // Apply the styles
4465 spinner.css({
4566 'filter': 'blur(15px)',
4667 'opacity': '0',
4768 });
4869 });
4970}
5071
public/scripts/openai.js+9 -18
@@ -258,7 +258,7 @@ const default_settings = {
258258 ai21_model: 'jamba-1.5-large',
259259 mistralai_model: 'mistral-large-latest',
260260 cohere_model: 'command-r-plus',
261261 perplexity_model: 'llama-3.1-70bsonar-instructpro',
262262 groq_model: 'llama-3.1-70b-versatile',
263263 nanogpt_model: 'gpt-4o-mini',
264264 zerooneai_model: 'yi-large',
@@ -337,7 +337,7 @@ const oai_settings = {
337337 ai21_model: 'jamba-1.5-large',
338338 mistralai_model: 'mistral-large-latest',
339339 cohere_model: 'command-r-plus',
340340 perplexity_model: 'llama-3.1-70bsonar-instructpro',
341341 groq_model: 'llama-3.1-70b-versatile',
342342 nanogpt_model: 'gpt-4o-mini',
343343 zerooneai_model: 'yi-large',
@@ -4380,28 +4380,19 @@ async function onModelChange() {
43804380 if (oai_settings.max_context_unlocked) {
43814381 $('#openai_max_context').attr('max', unlocked_max);
43824382 }
4383+ else if (['sonar', 'sonar-reasoning'].includes(oai_settings.perplexity_model)) {
4384+ $('#openai_max_context').attr('max', 127000);
4385+ }
4386+ else if (['sonar-pro'].includes(oai_settings.perplexity_model)) {
4387+ $('#openai_max_context').attr('max', 200000);
4388+ }
43834389 else if (oai_settings.perplexity_model.includes('llama-3.1')) {
43844390 const isOnline = oai_settings.perplexity_model.includes('online');
43854391 const contextSize = isOnline ? 128 * 1024 - 4000 : 128 * 1024;
43864392 $('#openai_max_context').attr('max', contextSize);
43874393 }
4388- else if (['llama-3-sonar-small-32k-chat', 'llama-3-sonar-large-32k-chat'].includes(oai_settings.perplexity_model)) {
4389- $('#openai_max_context').attr('max', max_32k);
4390- }
4391- else if (['llama-3-sonar-small-32k-online', 'llama-3-sonar-large-32k-online'].includes(oai_settings.perplexity_model)) {
4392- $('#openai_max_context').attr('max', 28000);
4393- }
4394- else if (['sonar-small-chat', 'sonar-medium-chat', 'codellama-70b-instruct', 'mistral-7b-instruct', 'mixtral-8x7b-instruct', 'mixtral-8x22b-instruct'].includes(oai_settings.perplexity_model)) {
4395- $('#openai_max_context').attr('max', max_16k);
4396- }
4397- else if (['llama-3-8b-instruct', 'llama-3-70b-instruct'].includes(oai_settings.perplexity_model)) {
4398- $('#openai_max_context').attr('max', max_8k);
4399- }
4400- else if (['sonar-small-online', 'sonar-medium-online'].includes(oai_settings.perplexity_model)) {
4401- $('#openai_max_context').attr('max', 12000);
4402- }
44034394 else {
44044395 $('#openai_max_context').attr('max', max_4kmax_128k);
44054396 }
44064397 oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context);
44074398 $('#openai_max_context').val(oai_settings.openai_max_context).trigger('input');
public/scripts/power-user.js+82 -0
@@ -254,6 +254,7 @@ let power_user = {
254254 },
255255
256256 reasoning: {
257+ auto_parse: false,
257258 add_to_prompts: false,
258259 prefix: '<think>\n',
259260 suffix: '\n</think>',
@@ -2917,6 +2918,46 @@ export function flushEphemeralStoppingStrings() {
29172918}
29182919
29192920/**
2921+ * Checks if the generated text should be filtered based on the auto-swipe settings.
2922+ * @param {string} text The text to check
2923+ * @returns {boolean} If the generated text should be filtered
2924+ */
2925+export function generatedTextFiltered(text) {
2926+ /**
2927+ * Checks if the given text contains any of the blacklisted words.
2928+ * @param {string} text The text to check
2929+ * @param {string[]} blacklist The list of blacklisted words
2930+ * @param {number} threshold The number of blacklisted words that need to be present to trigger the check
2931+ * @returns {boolean} Whether the text contains blacklisted words
2932+ */
2933+ function containsBlacklistedWords(text, blacklist, threshold) {
2934+ const regex = new RegExp(`\\b(${blacklist.join('|')})\\b`, 'gi');
2935+ const matches = text.match(regex) || [];
2936+ return matches.length >= threshold;
2937+ }
2938+
2939+ // Make sure a generated text is non-empty
2940+ // Otherwise we might get in a loop with a broken API
2941+ text = text.trim();
2942+ if (text.length > 0) {
2943+ if (power_user.auto_swipe_minimum_length) {
2944+ if (text.length < power_user.auto_swipe_minimum_length) {
2945+ console.log('Generated text size too small');
2946+ return true;
2947+ }
2948+ }
2949+ if (power_user.auto_swipe_blacklist.length && power_user.auto_swipe_blacklist_threshold) {
2950+ if (containsBlacklistedWords(text, power_user.auto_swipe_blacklist, power_user.auto_swipe_blacklist_threshold)) {
2951+ console.log('Generated text has blacklisted words');
2952+ return true;
2953+ }
2954+ }
2955+ }
2956+
2957+ return false;
2958+}
2959+
2960+/**
29202961 * Gets the custom stopping strings from the power user settings.
29212962 * @param {number | undefined} limit Number of strings to return. If 0 or undefined, returns all strings.
29222963 * @returns {string[]} An array of custom stopping strings
@@ -4072,4 +4113,45 @@ $(document).ready(() => {
40724113 ],
40734114 helpString: 'activates a movingUI preset by name',
40744115 }));
4116+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
4117+ name: 'stop-strings',
4118+ aliases: ['stopping-strings', 'custom-stopping-strings', 'custom-stop-strings'],
4119+ helpString: `
4120+ <div>
4121+ Sets a list of custom stopping strings. Gets the list if no value is provided.
4122+ </div>
4123+ <div>
4124+ <strong>Examples:</strong>
4125+ </div>
4126+ <ul>
4127+ <li>Value must be a JSON-serialized array: <pre><code class="language-stscript">/stop-strings ["goodbye", "farewell"]</code></pre></li>
4128+ <li>Pipe characters must be escaped with a backslash: <pre><code class="language-stscript">/stop-strings ["left\\|right"]</code></pre></li>
4129+ </ul>
4130+ `,
4131+ returns: ARGUMENT_TYPE.LIST,
4132+ unnamedArgumentList: [
4133+ SlashCommandArgument.fromProps({
4134+ description: 'list of strings',
4135+ typeList: [ARGUMENT_TYPE.LIST],
4136+ acceptsMultiple: false,
4137+ isRequired: false,
4138+ }),
4139+ ],
4140+ callback: (_, value) => {
4141+ if (String(value ?? '').trim()) {
4142+ const parsedValue = ((x) => { try { return JSON.parse(x.toString()); } catch { return null; } })(value);
4143+ if (!parsedValue || !Array.isArray(parsedValue)) {
4144+ throw new Error('Invalid list format. The value must be a JSON-serialized array of strings.');
4145+ }
4146+ parsedValue.forEach((item, index) => {
4147+ parsedValue[index] = String(item);
4148+ });
4149+ power_user.custom_stopping_strings = JSON.stringify(parsedValue);
4150+ $('#custom_stopping_strings').val(power_user.custom_stopping_strings);
4151+ saveSettingsDebounced();
4152+ }
4153+
4154+ return power_user.custom_stopping_strings;
4155+ },
4156+ }));
40754157});
public/scripts/reasoning.js+158 -7
@@ -1,4 +1,5 @@
11import { chat, closeMessageEditor, event_types, eventSource, saveChatConditional, saveSettingsDebounced, substituteParams, updateMessageBlock } from '../script.js';
2+import { getRegexedString, regex_placement } from './extensions/regex/engine.js';
23import { t } from './i18n.js';
34import { MacrosParser } from './macros.js';
45import { Popup } from './popup.js';
@@ -7,7 +8,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js';
78import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
89import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
910import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
1011import { copyText, escapeRegex, isFalseBoolean } from './utils.js';
1112
1213/**
1314 * Gets a message from a jQuery element.
@@ -49,11 +50,12 @@ export class PromptReasoning {
4950 * Add reasoning to a message according to the power user settings.
5051 * @param {string} content Message content
5152 * @param {string} reasoning Message reasoning
53+ * @param {boolean} isPrefix Whether this is the last message prefix
5254 * @returns {string} Message content with reasoning
5355 */
5456 addToMessage(content, reasoning, isPrefix) {
5557 // Disabled or reached limit of additions
5658 if (!isPrefix && (!power_user.reasoning.add_to_prompts || this.counter >= power_user.reasoning.max_additions)) {
5759 return content;
5860 }
5961
@@ -70,6 +72,11 @@ export class PromptReasoning {
7072 const separator = substituteParams(power_user.reasoning.separator || '');
7173 const suffix = substituteParams(power_user.reasoning.suffix || '');
7274
75+ // Combine parts with reasoning only
76+ if (isPrefix && !content) {
77+ return `${prefix}${reasoning}`;
78+ }
79+
7380 // Combine parts with reasoning and content
7481 return `${prefix}${reasoning}${suffix}${separator}${content}`;
7582 }
@@ -105,11 +112,18 @@ function loadReasoningSettings() {
105112 power_user.reasoning.max_additions = Number($(this).val());
106113 saveSettingsDebounced();
107114 });
115+
116+ $('#reasoning_auto_parse').prop('checked', power_user.reasoning.auto_parse);
117+ $('#reasoning_auto_parse').on('change', function () {
118+ power_user.reasoning.auto_parse = !!$(this).prop('checked');
119+ saveSettingsDebounced();
120+ });
108121}
109122
110123function registerReasoningSlashCommands() {
111124 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
112125 name: 'reasoning-get',
126+ aliases: ['get-reasoning'],
113127 returns: ARGUMENT_TYPE.STRING,
114128 helpString: t`Get the contents of a reasoning block of a message. Returns an empty string if the message does not have a reasoning block.`,
115129 unnamedArgumentList: [
@@ -129,6 +143,7 @@ function registerReasoningSlashCommands() {
129143
130144 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
131145 name: 'reasoning-set',
146+ aliases: ['set-reasoning'],
132147 returns: ARGUMENT_TYPE.STRING,
133148 helpString: t`Set the reasoning block of a message. Returns the reasoning block content.`,
134149 namedArgumentList: [
@@ -146,7 +161,7 @@ function registerReasoningSlashCommands() {
146161 }),
147162 ],
148163 callback: async (args, value) => {
149164 const messageId = !isNaN(Number(args[0].at)) ? Number(args[0].at) : chat.length - 1;
150165 const message = chat[messageId];
151166 if (!message?.extra) {
152167 return '';
@@ -160,6 +175,50 @@ function registerReasoningSlashCommands() {
160175 return message.extra.reasoning;
161176 },
162177 }));
178+
179+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
180+ name: 'reasoning-parse',
181+ aliases: ['parse-reasoning'],
182+ returns: 'reasoning string',
183+ helpString: t`Extracts the reasoning block from a string using the Reasoning Formatting settings.`,
184+ namedArgumentList: [
185+ SlashCommandNamedArgument.fromProps({
186+ name: 'regex',
187+ description: 'Whether to apply regex scripts to the reasoning content.',
188+ typeList: [ARGUMENT_TYPE.BOOLEAN],
189+ defaultValue: 'true',
190+ isRequired: false,
191+ enumProvider: commonEnumProviders.boolean('trueFalse'),
192+ }),
193+ ],
194+ unnamedArgumentList: [
195+ SlashCommandArgument.fromProps({
196+ description: 'input string',
197+ typeList: [ARGUMENT_TYPE.STRING],
198+ }),
199+ ],
200+ callback: (args, value) => {
201+ if (!value) {
202+ return '';
203+ }
204+
205+ if (!power_user.reasoning.prefix || !power_user.reasoning.suffix) {
206+ toastr.warning(t`Both prefix and suffix must be set in the Reasoning Formatting settings.`);
207+ return String(value);
208+ }
209+
210+ const parsedReasoning = parseReasoningFromString(String(value));
211+
212+ if (!parsedReasoning) {
213+ return '';
214+ }
215+
216+ const applyRegex = !isFalseBoolean(String(args.regex ?? ''));
217+ return applyRegex
218+ ? getRegexedString(parsedReasoning.reasoning, regex_placement.REASONING)
219+ : parsedReasoning.reasoning;
220+ },
221+ }));
163222}
164223
165224function registerReasoningMacros() {
@@ -168,7 +227,7 @@ function registerReasoningMacros() {
168227 MacrosParser.registerMacro('reasoningSeparator', () => power_user.reasoning.separator, t`Reasoning Separator`);
169228}
170229
171230function setReasoningEventHandlers() {
172231 $(document).on('click', '.mes_reasoning_copy', (e) => {
173232 e.stopPropagation();
174233 e.preventDefault();
@@ -224,7 +283,7 @@ function setReasoningEventHandlers(){
224283 }
225284
226285 const textarea = messageBlock.find('.reasoning_edit_textarea');
227286 const reasoning = getRegexedString(String(textarea.val()), regex_placement.REASONING, { isEdit: true });
228287 message.extra.reasoning = reasoning;
229288 await saveChatConditional();
230289 updateMessageBlock(messageId, message);
@@ -289,9 +348,101 @@ function setReasoningEventHandlers(){
289348 });
290349}
291350
351+/**
352+ * Parses reasoning from a string using the power user reasoning settings.
353+ * @typedef {Object} ParsedReasoning
354+ * @property {string} reasoning Reasoning block
355+ * @property {string} content Message content
356+ * @param {string} str Content of the message
357+ * @returns {ParsedReasoning|null} Parsed reasoning block and message content
358+ */
359+function parseReasoningFromString(str) {
360+ // Both prefix and suffix must be defined
361+ if (!power_user.reasoning.prefix || !power_user.reasoning.suffix) {
362+ return null;
363+ }
364+
365+ try {
366+ const regex = new RegExp(`${escapeRegex(power_user.reasoning.prefix)}(.*?)${escapeRegex(power_user.reasoning.suffix)}`, 's');
367+
368+ let didReplace = false;
369+ let reasoning = '';
370+ let content = String(str).replace(regex, (_match, captureGroup) => {
371+ didReplace = true;
372+ reasoning = captureGroup;
373+ return '';
374+ });
375+
376+ if (didReplace && power_user.trim_spaces) {
377+ reasoning = reasoning.trim();
378+ content = content.trim();
379+ }
380+
381+ return { reasoning, content };
382+ } catch (error) {
383+ console.error('[Reasoning] Error parsing reasoning block', error);
384+ return null;
385+ }
386+}
387+
388+function registerReasoningAppEvents() {
389+ eventSource.makeFirst(event_types.MESSAGE_RECEIVED, (/** @type {number} */ idx) => {
390+ if (!power_user.reasoning.auto_parse) {
391+ return;
392+ }
393+
394+ console.debug('[Reasoning] Auto-parsing reasoning block for message', idx);
395+ const message = chat[idx];
396+
397+ if (!message) {
398+ console.warn('[Reasoning] Message not found', idx);
399+ return null;
400+ }
401+
402+ if (!message.mes || message.mes === '...') {
403+ console.debug('[Reasoning] Message content is empty or a placeholder', idx);
404+ return null;
405+ }
406+
407+ const parsedReasoning = parseReasoningFromString(message.mes);
408+
409+ // No reasoning block found
410+ if (!parsedReasoning) {
411+ return;
412+ }
413+
414+ // Make sure the message has an extra object
415+ if (!message.extra || typeof message.extra !== 'object') {
416+ message.extra = {};
417+ }
418+
419+ const contentUpdated = !!parsedReasoning.reasoning || parsedReasoning.content !== message.mes;
420+
421+ // If reasoning was found, add it to the message
422+ if (parsedReasoning.reasoning) {
423+ message.extra.reasoning = getRegexedString(parsedReasoning.reasoning, regex_placement.REASONING);
424+ }
425+
426+ // Update the message text if it was changed
427+ if (parsedReasoning.content !== message.mes) {
428+ message.mes = parsedReasoning.content;
429+ }
430+
431+ // Find if a message already exists in DOM and must be updated
432+ if (contentUpdated) {
433+ const messageRendered = document.querySelector(`.mes[mesid="${idx}"]`) !== null;
434+ if (messageRendered) {
435+ console.debug('[Reasoning] Updating message block', idx);
436+ updateMessageBlock(idx, message);
437+ }
438+ }
439+ });
440+}
441+
292442export function initReasoning() {
293443 loadReasoningSettings();
294444 setReasoningEventHandlers();
295445 registerReasoningSlashCommands();
296446 registerReasoningMacros();
447+ registerReasoningAppEvents();
297448}
public/scripts/slash-commands.js+4 -0
@@ -42,6 +42,7 @@ import {
4242 showMoreMessages,
4343 stopGeneration,
4444 substituteParams,
45+ syncCurrentSwipeInfoExtras,
4546 system_avatar,
4647 system_message_types,
4748 this_chid,
@@ -2870,8 +2871,11 @@ async function addSwipeCallback(args, value) {
28702871 const newSwipeId = lastMessage.swipes.length - 1;
28712872
28722873 if (isTrueBoolean(args.switch)) {
2874+ // Make sure ad-hoc changes to extras are saved before swiping away
2875+ syncCurrentSwipeInfoExtras();
28732876 lastMessage.swipe_id = newSwipeId;
28742877 lastMessage.mes = lastMessage.swipes[newSwipeId];
2878+ lastMessage.extra = structuredClone(lastMessage.swipe_info?.[newSwipeId]?.extra ?? lastMessage.extra ?? {});
28752879 }
28762880
28772881 await saveChatConditional();
public/scripts/st-context.js+11 -0
@@ -69,6 +69,7 @@ import { textgenerationwebui_settings } from './textgen-settings.js';
6969import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js';
7070import { ToolManager } from './tool-calling.js';
7171import { timestampToMoment, uuidv4 } from './utils.js';
72+import { getGlobalVariable, getLocalVariable, setGlobalVariable, setLocalVariable } from './variables.js';
7273
7374export function getContext() {
7475 return {
@@ -175,6 +176,16 @@ export function getContext() {
175176 humanizedDateTime,
176177 updateMessageBlock,
177178 appendMediaToMessage,
179+ variables: {
180+ local: {
181+ get: getLocalVariable,
182+ set: setLocalVariable,
183+ },
184+ global: {
185+ get: getGlobalVariable,
186+ set: setGlobalVariable,
187+ },
188+ },
178189 };
179190}
180191
public/scripts/textgen-models.js+6 -0
@@ -54,6 +54,12 @@ const OPENROUTER_PROVIDERS = [
5454 'xAI',
5555 'Cloudflare',
5656 'SF Compute',
57+ 'Minimax',
58+ 'Nineteen',
59+ 'Liquid',
60+ 'Nebius',
61+ 'Chutes',
62+ 'Kluster',
5763 '01.AI',
5864 'HuggingFace',
5965 'Mancer',
public/scripts/textgen-settings.js+1 -1
@@ -501,7 +501,7 @@ export function loadTextGenSettings(data, loadedSettings) {
501501 for (const [type, selector] of Object.entries(SERVER_INPUTS)) {
502502 const control = $(selector);
503503 control.val(settings.server_urls[type] ?? '').on('input', function () {
504504 settings.server_urls[type] = String($(this).val()).trim();
505505 saveSettingsDebounced();
506506 });
507507 }
public/scripts/tokenizers.js+3 -0
@@ -679,6 +679,9 @@ export function getTokenizerModel() {
679679 }
680680
681681 if (oai_settings.chat_completion_source === chat_completion_sources.PERPLEXITY) {
682+ if (oai_settings.perplexity_model.includes('sonar-reasoning')) {
683+ return deepseekTokenizer;
684+ }
682685 if (oai_settings.perplexity_model.includes('llama-3') || oai_settings.perplexity_model.includes('llama3')) {
683686 return llama3Tokenizer;
684687 }
public/scripts/utils.js+7 -7
@@ -1733,17 +1733,17 @@ export function hasAnimation(control) {
17331733
17341734/**
17351735 * Run an action once an animation on a control ends. If the control has no animation, the action will be executed immediately.
1736- *
1736+ * The action will be executed after the animation ends or after the timeout, whichever comes first.
17371737 * @param {HTMLElement} control - The control element to listen for animation end event
17381738 * @param {(control:*?) => void} callback - The callback function to be executed when the animation ends
1739+ * @param {number} [timeout=500] - The timeout in milliseconds to wait for the animation to end before executing the callback
17391740 */
17401741export function runAfterAnimation(control, callback, timeout = 500) {
17411742 if (hasAnimation(control)) {
1742- const onAnimationEnd = () => {
1743+ Promise.race([
1743- control.removeEventListener('animationend', onAnimationEnd);
1744+ new Promise((r) => setTimeout(r, timeout)), // Fallback timeout
1744- callback(control);
1745+ new Promise((r) => control.addEventListener('animationend', r, { once: true })),
1745- };
1746+ ]).finally(() => callback(control));
1746- control.addEventListener('animationend', onAnimationEnd);
17471747 } else {
17481748 callback(control);
17491749 }
public/scripts/variables.js+4 -4
@@ -19,7 +19,7 @@ import { isFalseBoolean, convertValueType, isTrueBoolean } from './utils.js';
1919
2020const MAX_LOOPS = 100;
2121
2222export function getLocalVariable(name, args = {}) {
2323 if (!chat_metadata.variables) {
2424 chat_metadata.variables = {};
2525 }
@@ -45,7 +45,7 @@ function getLocalVariable(name, args = {}) {
4545 return (localVariable?.trim?.() === '' || isNaN(Number(localVariable))) ? (localVariable || '') : Number(localVariable);
4646}
4747
4848export function setLocalVariable(name, value, args = {}) {
4949 if (!name) {
5050 throw new Error('Variable name cannot be empty or undefined.');
5151 }
@@ -80,7 +80,7 @@ function setLocalVariable(name, value, args = {}) {
8080 return value;
8181}
8282
8383export function getGlobalVariable(name, args = {}) {
8484 let globalVariable = extension_settings.variables.global[args.key ?? name];
8585 if (args.index !== undefined) {
8686 try {
@@ -102,7 +102,7 @@ function getGlobalVariable(name, args = {}) {
102102 return (globalVariable?.trim?.() === '' || isNaN(Number(globalVariable))) ? (globalVariable || '') : Number(globalVariable);
103103}
104104
105105export function setGlobalVariable(name, value, args = {}) {
106106 if (!name) {
107107 throw new Error('Variable name cannot be empty or undefined.');
108108 }
public/style.css+5 -0
@@ -399,6 +399,11 @@ input[type='checkbox']:focus-visible {
399399 color: var(--SmartThemeEmColor);
400400}
401401
402+.mes_text q i,
403+.mes_text q em {
404+ color: inherit;
405+}
406+
402407.mes_text u,
403408.mes_reasoning u {
404409 color: var(--SmartThemeUnderlineColor);
src/endpoints/stable-diffusion.js+1 -1
@@ -533,6 +533,7 @@ comfy.post('/delete-workflow', jsonParser, async (request, response) => {
533533
534534comfy.post('/generate', jsonParser, async (request, response) => {
535535 try {
536+ let item;
536537 const url = new URL(urlJoin(request.body.url, '/prompt'));
537538
538539 const controller = new AbortController();
@@ -557,7 +558,6 @@ comfy.post('/generate', jsonParser, async (request, response) => {
557558 /** @type {any} */
558559 const data = await promptResult.json();
559560 const id = data.prompt_id;
560- let item;
561561 const historyUrl = new URL(urlJoin(request.body.url, '/history'));
562562 while (true) {
563563 const result = await fetch(historyUrl);