remove regex workaround and fix tag format
This commit is contained in:
@@ -138,7 +138,7 @@ import {
|
|||||||
// Feature modules
|
// Feature modules
|
||||||
import { setupPlotButtons, sendPlotProgression } from './src/systems/features/plotProgression.js';
|
import { setupPlotButtons, sendPlotProgression } from './src/systems/features/plotProgression.js';
|
||||||
import { setupClassicStatsButtons } from './src/systems/features/classicStats.js';
|
import { setupClassicStatsButtons } from './src/systems/features/classicStats.js';
|
||||||
import { ensureHtmlCleaningRegex, detectConflictingRegexScripts, ensureTrackerCleaningRegex, ensureOmniscienceFilterCleaningRegex } from './src/systems/features/htmlCleaning.js';
|
import { ensureHtmlCleaningRegex, detectConflictingRegexScripts, ensureTrackerCleaningRegex } from './src/systems/features/htmlCleaning.js';
|
||||||
import { ensureJsonCleaningRegex, removeJsonCleaningRegex } from './src/systems/features/jsonCleaning.js';
|
import { ensureJsonCleaningRegex, removeJsonCleaningRegex } from './src/systems/features/jsonCleaning.js';
|
||||||
import { parseAndStoreSpotifyUrl } from './src/systems/features/musicPlayer.js';
|
import { parseAndStoreSpotifyUrl } from './src/systems/features/musicPlayer.js';
|
||||||
import { DEFAULT_HTML_PROMPT } from './src/systems/generation/promptBuilder.js';
|
import { DEFAULT_HTML_PROMPT } from './src/systems/generation/promptBuilder.js';
|
||||||
@@ -1219,14 +1219,6 @@ jQuery(async () => {
|
|||||||
// Non-critical - continue without it
|
// Non-critical - continue without it
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import the omniscience filter cleaning regex (hides <filter> tags from display)
|
|
||||||
try {
|
|
||||||
await ensureOmniscienceFilterCleaningRegex(st_extension_settings, saveSettingsDebounced);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[RPG Companion] Omniscience filter regex import failed:', error);
|
|
||||||
// Non-critical - continue without it
|
|
||||||
}
|
|
||||||
|
|
||||||
// Import the JSON cleaning regex to clean up JSON in messages
|
// Import the JSON cleaning regex to clean up JSON in messages
|
||||||
// This cleans historical messages when displayed
|
// This cleans historical messages when displayed
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -197,87 +197,3 @@ export async function ensureTrackerCleaningRegex(st_extension_settings, saveSett
|
|||||||
// Don't throw - this is a nice-to-have feature
|
// Don't throw - this is a nice-to-have feature
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Automatically imports a regex script to clean <filter> tags from displayed messages.
|
|
||||||
* This hides omniscience filter content (events the player character cannot perceive)
|
|
||||||
* from the visible chat while keeping them in the message data.
|
|
||||||
* @param {Object} st_extension_settings - SillyTavern extension settings object
|
|
||||||
* @param {Function} saveSettingsDebounced - Function to save settings
|
|
||||||
*/
|
|
||||||
export async function ensureOmniscienceFilterCleaningRegex(st_extension_settings, saveSettingsDebounced) {
|
|
||||||
try {
|
|
||||||
// Validate extension settings structure
|
|
||||||
if (!st_extension_settings || typeof st_extension_settings !== 'object') {
|
|
||||||
console.warn('[RPG Companion] Invalid extension_settings object, skipping omniscience filter regex import');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the omniscience filter cleaning regex already exists
|
|
||||||
const scriptName = 'Clean Omniscience Filter Tags (Display Only)';
|
|
||||||
const existingScripts = st_extension_settings?.regex || [];
|
|
||||||
|
|
||||||
// Validate regex array
|
|
||||||
if (!Array.isArray(existingScripts)) {
|
|
||||||
console.warn('[RPG Companion] extension_settings.regex is not an array, resetting to empty array');
|
|
||||||
st_extension_settings.regex = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const alreadyExists = existingScripts.some(script =>
|
|
||||||
script && typeof script === 'object' && script.scriptName === scriptName
|
|
||||||
);
|
|
||||||
|
|
||||||
if (alreadyExists) {
|
|
||||||
// console.log('[RPG Companion] Omniscience filter cleaning regex already exists, skipping import');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate a UUID for the script
|
|
||||||
const uuidv4 = () => {
|
|
||||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
||||||
const r = Math.random() * 16 | 0;
|
|
||||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
||||||
return v.toString(16);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create the regex script to remove <filter event="..." reason="..."/> tags from display
|
|
||||||
// This regex matches the specific <filter> tag format used by omniscience filter
|
|
||||||
// Pattern: <filter followed by any attributes, ending with /> or </filter>
|
|
||||||
const regexScript = {
|
|
||||||
id: uuidv4(),
|
|
||||||
scriptName: scriptName,
|
|
||||||
findRegex: '/<filter\\s+[^>]*\\/?>(?:<\\/filter>)?/gi',
|
|
||||||
replaceString: '',
|
|
||||||
trimStrings: [],
|
|
||||||
placement: [1], // 1 = Display only (affects visible chat, not outgoing prompts)
|
|
||||||
disabled: false,
|
|
||||||
markdownOnly: false,
|
|
||||||
promptOnly: false,
|
|
||||||
runOnEdit: true,
|
|
||||||
substituteRegex: 0,
|
|
||||||
minDepth: null,
|
|
||||||
maxDepth: null
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add to global regex scripts
|
|
||||||
if (!Array.isArray(st_extension_settings.regex)) {
|
|
||||||
st_extension_settings.regex = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
st_extension_settings.regex.push(regexScript);
|
|
||||||
|
|
||||||
// Save the changes
|
|
||||||
if (typeof saveSettingsDebounced === 'function') {
|
|
||||||
saveSettingsDebounced();
|
|
||||||
} else {
|
|
||||||
console.warn('[RPG Companion] saveSettingsDebounced is not a function, cannot save omniscience filter regex');
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log('[RPG Companion] ✅ Omniscience filter cleaning regex imported successfully');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[RPG Companion] Failed to import omniscience filter cleaning regex:', error);
|
|
||||||
console.error('[RPG Companion] Error details:', error.message, error.stack);
|
|
||||||
// Don't throw - this is a nice-to-have feature
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -41,19 +41,20 @@ export const DEFAULT_OMNISCIENCE_FILTER_PROMPT = `OMNISCIENCE FILTER INSTRUCTION
|
|||||||
You must strictly separate what the player character can directly perceive from what they cannot. The player should only read narrative content that their character can actually see, hear, smell, touch, or otherwise directly sense.
|
You must strictly separate what the player character can directly perceive from what they cannot. The player should only read narrative content that their character can actually see, hear, smell, touch, or otherwise directly sense.
|
||||||
If the player character cannot directly perceive something, but it is happening, it ABSOLUTELY MUST be placed inside of a <filter> tag.
|
If the player character cannot directly perceive something, but it is happening, it ABSOLUTELY MUST be placed inside of a <filter> tag.
|
||||||
BEFORE writing any narrative content that involves events, actions, or details the player character CANNOT directly perceive (because they're not looking, too far away, behind them, in another room, happening silently, etc.), you MUST first output that hidden information inside a <filter> tag using this exact format:
|
BEFORE writing any narrative content that involves events, actions, or details the player character CANNOT directly perceive (because they're not looking, too far away, behind them, in another room, happening silently, etc.), you MUST first output that hidden information inside a <filter> tag using this exact format:
|
||||||
<filter event="[Brief description of what is happening that the player cannot perceive]" reason="[Why the player character cannot perceive this - e.g., 'behind them', 'in another room', 'too quiet to hear', 'focused elsewhere']"/>
|
<filter event="[Brief description of what is happening that the player cannot perceive]" reason="[Why the player character cannot perceive this - e.g., 'behind them', 'in another room', 'too quiet to hear', 'focused elsewhere']">
|
||||||
|
|
||||||
CRITICAL RULES:
|
CRITICAL RULES:
|
||||||
1. The <filter> tag must come BEFORE any sensory hints (sounds, smells, etc.) that the player DOES perceive from that event
|
1. The <filter> tag must come BEFORE any sensory hints (sounds, smells, etc.) that the player DOES perceive from that event
|
||||||
2. Only write narrative that reflects what the player character actually experiences through their senses
|
2. Only write narrative that reflects what the player character actually experiences through their senses
|
||||||
3. Instead of "Jake sweeps the floor behind you", write: <filter event="Jake is sweeping the floor" reason="Jake is behind Michael who is focused on reading"/> followed by narrative like "You hear soft sweeping sounds behind you"
|
3. Instead of "Jake sweeps the floor behind you", write: <filter event="Jake is sweeping the floor" reason="Jake is behind Michael who is focused on reading"> followed by narrative like "You hear soft sweeping sounds behind you"
|
||||||
4. NPCs' internal thoughts, silent actions, and events in other locations MUST go in <filter> tags
|
4. NPCs' internal thoughts, silent actions, and events in other locations MUST go in <filter> tags
|
||||||
5. The player's narrative should create natural mystery and immersion - they experience the world through limited senses, not omniscient narration
|
5. The player's narrative should create natural mystery and immersion - they experience the world through limited senses, not omniscient narration
|
||||||
6. Be liberal and proactive in using <filter> tags to hide information the player cannot perceive directly
|
6. Be liberal and proactive in using <filter> tags to hide information the player cannot perceive directly
|
||||||
|
7. Don't forget to properly enclose the <filter> tag.
|
||||||
|
|
||||||
EXAMPLE:
|
EXAMPLE:
|
||||||
Wrong: "As you read the newspaper, Sarah quietly pockets the key from the table behind you and slips out the back door."
|
Wrong: "As you read the newspaper, Sarah quietly pockets the key from the table behind you and slips out the back door."
|
||||||
Correct: <filter event="Sarah quietly takes the key from the table and slips out the back door" reason="Sarah is behind Michael who is absorbed in reading, and she moves silently"/>You hear a faint click from somewhere behind you, but when you glance up from your newspaper, the room seems unchanged. The afternoon light streams through the windows as you return to your reading.`;
|
Correct: <filter event="Sarah quietly takes the key from the table and slips out the back door" reason="Sarah is behind Michael who is absorbed in reading, and she moves silently">You hear a faint click from somewhere behind you, but when you glance up from your newspaper, the room seems unchanged. The afternoon light streams through the windows as you return to your reading.`;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user