v3.2.5: Always enable JSON cleaning regex with proper settings

This commit is contained in:
Spicy_Marinara
2026-01-08 18:27:16 +01:00
parent e5bd1e0411
commit bd056934e1
4 changed files with 52 additions and 57 deletions
+1 -20
View File
@@ -313,18 +313,6 @@ async function initUI() {
extensionSettings.generationMode = String($(this).val()); extensionSettings.generationMode = String($(this).val());
saveSettings(); saveSettings();
updateGenerationModeUI(); updateGenerationModeUI();
// Add or remove JSON cleaning regex based on mode
// This ensures old messages in chat history are also cleaned
try {
if (extensionSettings.generationMode === 'together') {
await ensureJsonCleaningRegex(st_extension_settings, saveSettingsDebounced);
} else {
removeJsonCleaningRegex(st_extension_settings, saveSettingsDebounced);
}
} catch (error) {
console.error('[RPG Companion] JSON cleaning regex update failed:', error);
}
}); });
$('#rpg-toggle-user-stats').on('change', function() { $('#rpg-toggle-user-stats').on('change', function() {
@@ -1000,17 +988,10 @@ jQuery(async () => {
// Non-critical - continue without it // Non-critical - continue without it
} }
// Import the JSON cleaning regex for Together mode if enabled // Import the JSON cleaning regex to clean up JSON in messages
// This cleans historical messages when displayed // This cleans historical messages when displayed
// Note: We also clean directly in message handler for redundancy
try { try {
// console.log('[RPG Companion] Checking JSON cleaning regex. Generation mode:', extensionSettings.generationMode);
if (extensionSettings.generationMode === 'together') {
await ensureJsonCleaningRegex(st_extension_settings, saveSettingsDebounced); await ensureJsonCleaningRegex(st_extension_settings, saveSettingsDebounced);
} else {
// Remove the regex if switching to separate mode
removeJsonCleaningRegex(st_extension_settings, saveSettingsDebounced);
}
} catch (error) { } catch (error) {
console.error('[RPG Companion] JSON cleaning regex setup failed:', error); console.error('[RPG Companion] JSON cleaning regex setup failed:', error);
// Non-critical - continue without it // Non-critical - continue without it
+1 -1
View File
@@ -6,6 +6,6 @@
"js": "index.js", "js": "index.js",
"css": "style.css", "css": "style.css",
"author": "Marinara", "author": "Marinara",
"version": "3.2.4", "version": "3.2.5",
"homePage": "https://github.com/SpicyMarinara/rpg-companion-sillytavern" "homePage": "https://github.com/SpicyMarinara/rpg-companion-sillytavern"
} }
+1 -1
View File
@@ -48,7 +48,7 @@
</div> </div>
<div style="margin-top: 10px; text-align: center; opacity: 0.6; font-size: 0.85em;"> <div style="margin-top: 10px; text-align: center; opacity: 0.6; font-size: 0.85em;">
v3.2.4 v3.2.5
</div> </div>
</div> </div>
</div> </div>
+41 -27
View File
@@ -35,40 +35,53 @@ export async function ensureJsonCleaningRegex(st_extension_settings, saveSetting
// Update existing script with new regex pattern if it's different // Update existing script with new regex pattern if it's different
const newPattern = '/```json[\\s\\S]*?```/gim'; const newPattern = '/```json[\\s\\S]*?```/gim';
// Always ensure these properties are set correctly
let needsSave = false;
if (existingScript.findRegex !== newPattern) { if (existingScript.findRegex !== newPattern) {
existingScript.findRegex = newPattern; existingScript.findRegex = newPattern;
existingScript.placement = [2]; // 2 = AI Output needsSave = true;
existingScript.disabled = false; // Ensure it's enabled }
existingScript.runOnEdit = true; // Ensure it runs on edit
existingScript.displayOnly = true; // Alter Chat Display
existingScript.onlyFormatDisplay = true; // Ensure display formatting is enabled
if (typeof saveSettingsDebounced === 'function') { if (JSON.stringify(existingScript.placement) !== JSON.stringify([2])) {
saveSettingsDebounced(); existingScript.placement = [2]; // 2 = AI Output
needsSave = true;
} }
console.log('[RPG Companion] Updated regex pattern and placement.');
} else { if (existingScript.disabled !== false) {
// Ensure it's enabled even if pattern matches
if (existingScript.disabled) {
existingScript.disabled = false; existingScript.disabled = false;
if (typeof saveSettingsDebounced === 'function') { needsSave = true;
saveSettingsDebounced();
} }
console.log('[RPG Companion] Re-enabled disabled regex.');
} else { if (existingScript.runOnEdit !== true) {
// Also update placement if it's wrong existingScript.runOnEdit = true;
const expectedPlacement = [2]; // 2 = AI Output needsSave = true;
if (JSON.stringify(existingScript.placement) !== JSON.stringify(expectedPlacement)) {
existingScript.placement = expectedPlacement;
if (typeof saveSettingsDebounced === 'function') {
saveSettingsDebounced();
// Force immediate save after a short delay
setTimeout(() => saveSettingsDebounced(), 100);
} }
console.log('[RPG Companion] Updated regex placement to [2].');
if (existingScript.displayOnly !== true) {
existingScript.displayOnly = true; // Alter Chat Display
needsSave = true;
} }
if (existingScript.onlyFormatDisplay !== true) {
existingScript.onlyFormatDisplay = true; // Alter Chat Display
needsSave = true;
} }
if (existingScript.onlyFormatPrompt !== true) {
existingScript.onlyFormatPrompt = true; // Alter Outgoing Prompt
needsSave = true;
} }
if (existingScript.promptOnly !== true) {
existingScript.promptOnly = true; // Enable prompt processing
needsSave = true;
}
if (existingScript.filterGaslighting !== true) {
existingScript.filterGaslighting = true; // Ephemerality
}
console.log('[RPG Companion] JSON Cleaning Regex is already downloaded and active.'); console.log('[RPG Companion] JSON Cleaning Regex is already downloaded and active.');
return; return;
} }
@@ -97,10 +110,11 @@ export async function ensureJsonCleaningRegex(st_extension_settings, saveSetting
placement: [2], // 2 = AI Output placement: [2], // 2 = AI Output
disabled: false, disabled: false,
markdownOnly: false, markdownOnly: false,
promptOnly: false, promptOnly: true, // Enable prompt processing
runOnEdit: true, runOnEdit: true,
displayOnly: true, // Alter Chat Display onlyFormatDisplay: true, // Alter Chat Display (enabled)
onlyFormatDisplay: true, // Ensure display formatting is enabled onlyFormatPrompt: true, // Alter Outgoing Prompt (enabled)
filterGaslighting: true, // Ephemerality - makes it only affect display
substituteRegex: 0, substituteRegex: 0,
minDepth: null, minDepth: null,
maxDepth: null maxDepth: null