v3.2.0: Major update with JSON trackers, locking system, and UI improvements
This commit is contained in:
+6
-6
@@ -111,11 +111,11 @@
|
||||
"template.trackerEditorModal.tabs.userStats": "User Stats",
|
||||
"template.trackerEditorModal.tabs.infoBox": "Info Box",
|
||||
"template.trackerEditorModal.tabs.presentCharacters": "Present Characters",
|
||||
"template.trackerEditorModal.buttons.reset": "Reset to Defaults",
|
||||
"template.trackerEditorModal.buttons.reset": "Reset",
|
||||
"template.trackerEditorModal.buttons.cancel": "Cancel",
|
||||
"template.trackerEditorModal.buttons.save": "Save & Apply",
|
||||
"template.trackerEditorModal.buttons.export": "Export Preset",
|
||||
"template.trackerEditorModal.buttons.import": "Import Preset",
|
||||
"template.trackerEditorModal.buttons.export": "Export",
|
||||
"template.trackerEditorModal.buttons.import": "Import",
|
||||
"template.trackerEditorModal.messages.exportSuccess": "Tracker preset exported successfully!",
|
||||
"template.trackerEditorModal.messages.exportError": "Failed to export tracker preset. Check console for details.",
|
||||
"template.trackerEditorModal.messages.importSuccess": "Tracker preset imported successfully!",
|
||||
@@ -145,10 +145,10 @@
|
||||
"template.trackerEditorModal.infoBoxTab.recentEventsWidget": "Recent Events",
|
||||
"template.trackerEditorModal.presentCharactersTab.relationshipStatusTitle": "Relationship Status Fields",
|
||||
"template.trackerEditorModal.presentCharactersTab.enableRelationshipStatus": "Enable Relationship Status Fields",
|
||||
"template.trackerEditorModal.presentCharactersTab.relationshipStatusHint": "Define relationship types with corresponding emojis shown on character portraits",
|
||||
"template.trackerEditorModal.presentCharactersTab.relationshipStatusHint": "Define relationship types with corresponding emojis shown on character portraits.",
|
||||
"template.trackerEditorModal.presentCharactersTab.newRelationshipButton": "New Relationship",
|
||||
"template.trackerEditorModal.presentCharactersTab.appearanceDemeanorTitle": "Appearance/Demeanor Fields",
|
||||
"template.trackerEditorModal.presentCharactersTab.appearanceDemeanorHint": "Fields shown below character name, separated by |",
|
||||
"template.trackerEditorModal.presentCharactersTab.appearanceDemeanorHint": "Fields shown below character name.",
|
||||
"template.trackerEditorModal.presentCharactersTab.addCustomFieldButton": "Add Custom Field",
|
||||
"template.trackerEditorModal.presentCharactersTab.thoughtsConfigTitle": "Thoughts Configuration",
|
||||
"template.trackerEditorModal.presentCharactersTab.enableCharacterThoughts": "Enable Character Thoughts",
|
||||
@@ -156,7 +156,7 @@
|
||||
"template.trackerEditorModal.presentCharactersTab.aiInstructionLabel": "AI Instruction:",
|
||||
"template.trackerEditorModal.presentCharactersTab.characterStatsTitle": "Character Stats",
|
||||
"template.trackerEditorModal.presentCharactersTab.trackCharacterStats": "Track Character Stats",
|
||||
"template.trackerEditorModal.presentCharactersTab.characterStatsHint": "Create stats to track for each character (displayed as colored bars)",
|
||||
"template.trackerEditorModal.presentCharactersTab.characterStatsHint": "Create stats to track for each character (displayed as colored bars).",
|
||||
"template.trackerEditorModal.presentCharactersTab.addCharacterStatButton": "Add Character Stat",
|
||||
"template.mainPanel.title": "RPG Companion",
|
||||
"template.mainPanel.lastRoll": "Last Roll:",
|
||||
|
||||
+3
-3
@@ -81,11 +81,11 @@
|
||||
"template.trackerEditorModal.tabs.userStats": "User 屬性",
|
||||
"template.trackerEditorModal.tabs.infoBox": "資訊框",
|
||||
"template.trackerEditorModal.tabs.presentCharacters": "在場角色",
|
||||
"template.trackerEditorModal.buttons.reset": "重置為預設值",
|
||||
"template.trackerEditorModal.buttons.reset": "重置",
|
||||
"template.trackerEditorModal.buttons.cancel": "取消",
|
||||
"template.trackerEditorModal.buttons.save": "保存並應用",
|
||||
"template.trackerEditorModal.buttons.export": "匯出預設",
|
||||
"template.trackerEditorModal.buttons.import": "匯入預設",
|
||||
"template.trackerEditorModal.buttons.export": "匯出",
|
||||
"template.trackerEditorModal.buttons.import": "匯入",
|
||||
"template.trackerEditorModal.messages.exportSuccess": "追蹤器預設匯出成功!",
|
||||
"template.trackerEditorModal.messages.exportError": "匯出追蹤器預設失敗。請檢查控制台以獲取詳細資訊。",
|
||||
"template.trackerEditorModal.messages.importSuccess": "追蹤器預設匯入成功!",
|
||||
|
||||
@@ -19,7 +19,7 @@ export function setupClassicStatsButtons() {
|
||||
// Delegated event listener for increase buttons
|
||||
$userStatsContainer.on('click', '.rpg-stat-increase', function() {
|
||||
const stat = $(this).data('stat');
|
||||
if (extensionSettings.classicStats[stat] < 100) {
|
||||
if (extensionSettings.classicStats[stat] < 999) {
|
||||
extensionSettings.classicStats[stat]++;
|
||||
saveSettings();
|
||||
saveChatData();
|
||||
|
||||
@@ -27,17 +27,52 @@ export async function ensureJsonCleaningRegex(st_extension_settings, saveSetting
|
||||
st_extension_settings.regex = [];
|
||||
}
|
||||
|
||||
const alreadyExists = existingScripts.some(script =>
|
||||
const existingScript = existingScripts.find(script =>
|
||||
script && script.scriptName && script.scriptName === scriptName
|
||||
);
|
||||
|
||||
if (alreadyExists) {
|
||||
// console.log('[RPG Companion] JSON cleaning regex already exists, skipping import');
|
||||
if (existingScript) {
|
||||
// Update existing script with new regex pattern if it's different
|
||||
const newPattern = '/```json[\\s\\S]*?```/gim';
|
||||
|
||||
if (existingScript.findRegex !== newPattern) {
|
||||
existingScript.findRegex = newPattern;
|
||||
existingScript.placement = [2]; // 2 = AI Output
|
||||
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') {
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
console.log('[RPG Companion] Updated regex pattern and placement.');
|
||||
} else {
|
||||
// Ensure it's enabled even if pattern matches
|
||||
if (existingScript.disabled) {
|
||||
existingScript.disabled = false;
|
||||
if (typeof saveSettingsDebounced === 'function') {
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
console.log('[RPG Companion] Re-enabled disabled regex.');
|
||||
} else {
|
||||
// Also update placement if it's wrong
|
||||
const expectedPlacement = [2]; // 2 = AI Output
|
||||
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].');
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('[RPG Companion] JSON Cleaning Regex is already downloaded and active.');
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log('[RPG Companion] Importing JSON cleaning regex for Together mode...');
|
||||
|
||||
// Generate a UUID for the script
|
||||
const uuidv4 = () => {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
@@ -50,19 +85,22 @@ export async function ensureJsonCleaningRegex(st_extension_settings, saveSetting
|
||||
// Create the regex script object for cleaning JSON tracker data
|
||||
// This regex matches ```json...``` code blocks containing tracker data
|
||||
// The prompt now explicitly instructs models to use this format
|
||||
// Updated to handle various whitespace scenarios and ensure it catches all variations
|
||||
const regexScript = {
|
||||
id: uuidv4(),
|
||||
scriptName: scriptName,
|
||||
// Match ```json...``` code blocks (non-greedy, multiline)
|
||||
// This is now the guaranteed format since prompts instruct models to use code blocks
|
||||
findRegex: '/```json\\s*[\\s\\S]*?```/gi',
|
||||
// Match ```json...``` code blocks (handles spaces, newlines, any content)
|
||||
// Using a more permissive pattern to catch all variations
|
||||
findRegex: '/```json[\\s\\S]*?```/gim',
|
||||
replaceString: '',
|
||||
trimStrings: [],
|
||||
placement: [0], // 0 = Output (transforms after generation, before display)
|
||||
placement: [2], // 2 = AI Output
|
||||
disabled: false,
|
||||
markdownOnly: false,
|
||||
promptOnly: false, // Apply to both prompts and outputs
|
||||
promptOnly: false,
|
||||
runOnEdit: true,
|
||||
displayOnly: true, // Alter Chat Display
|
||||
onlyFormatDisplay: true, // Ensure display formatting is enabled
|
||||
substituteRegex: 0,
|
||||
minDepth: null,
|
||||
maxDepth: null
|
||||
@@ -74,6 +112,7 @@ export async function ensureJsonCleaningRegex(st_extension_settings, saveSetting
|
||||
}
|
||||
|
||||
st_extension_settings.regex.push(regexScript);
|
||||
console.log('[RPG Companion] JSON Cleaning Regex created and activated.');
|
||||
|
||||
// Save the changes
|
||||
if (typeof saveSettingsDebounced === 'function') {
|
||||
@@ -81,11 +120,8 @@ export async function ensureJsonCleaningRegex(st_extension_settings, saveSetting
|
||||
} else {
|
||||
console.warn('[RPG Companion] saveSettingsDebounced is not a function, cannot save JSON cleaning regex');
|
||||
}
|
||||
|
||||
// console.log('[RPG Companion] ✅ JSON cleaning regex imported successfully');
|
||||
// console.log('[RPG Companion] This regex will automatically remove tracker JSON from Together mode messages');
|
||||
} catch (error) {
|
||||
console.error('[RPG Companion] Failed to import JSON cleaning regex:', error);
|
||||
console.error('[RPG Companion] JSON Cleaning Regex failed to properly initialize!');
|
||||
console.error('[RPG Companion] Error details:', error.message, error.stack);
|
||||
// Don't throw - continue without it
|
||||
}
|
||||
|
||||
@@ -295,8 +295,8 @@ export async function onGenerationStarted(type, data, dryRun) {
|
||||
// Clear Spotify prompt if disabled
|
||||
setExtensionPrompt('rpg-companion-spotify', '', extension_prompt_types.IN_CHAT, 0, false);
|
||||
}
|
||||
} else if (extensionSettings.generationMode === 'separate') {
|
||||
// In SEPARATE mode, inject the contextual summary for main roleplay generation
|
||||
} else if (extensionSettings.generationMode === 'separate' || extensionSettings.generationMode === 'external') {
|
||||
// In SEPARATE and EXTERNAL modes, inject the contextual summary for main roleplay generation
|
||||
const contextSummary = generateContextualSummary();
|
||||
|
||||
if (contextSummary) {
|
||||
@@ -312,7 +312,7 @@ Ensure these details naturally reflect and influence the narrative. Character be
|
||||
if (!shouldSuppress) {
|
||||
setExtensionPrompt('rpg-companion-context', wrappedContext, extension_prompt_types.IN_CHAT, 1, false);
|
||||
}
|
||||
// console.log('[RPG Companion] Injected contextual summary for separate mode:', contextSummary);
|
||||
// console.log('[RPG Companion] Injected contextual summary for separate/external mode:', contextSummary);
|
||||
} else {
|
||||
// Clear if no data yet
|
||||
setExtensionPrompt('rpg-companion-context', '', extension_prompt_types.IN_CHAT, 1, false);
|
||||
@@ -325,7 +325,7 @@ Ensure these details naturally reflect and influence the narrative. Character be
|
||||
const htmlPrompt = `\n${htmlPromptText}`;
|
||||
|
||||
setExtensionPrompt('rpg-companion-html', htmlPrompt, extension_prompt_types.IN_CHAT, 0, false);
|
||||
// console.log('[RPG Companion] Injected HTML prompt at depth 0 for separate mode');
|
||||
// console.log('[RPG Companion] Injected HTML prompt at depth 0 for separate/external mode');
|
||||
} else {
|
||||
// Clear HTML prompt if disabled
|
||||
setExtensionPrompt('rpg-companion-html', '', extension_prompt_types.IN_CHAT, 0, false);
|
||||
@@ -338,7 +338,7 @@ Ensure these details naturally reflect and influence the narrative. Character be
|
||||
const spotifyPrompt = `\n${spotifyPromptText} ${SPOTIFY_FORMAT_INSTRUCTION}`;
|
||||
|
||||
setExtensionPrompt('rpg-companion-spotify', spotifyPrompt, extension_prompt_types.IN_CHAT, 0, false);
|
||||
// console.log('[RPG Companion] Injected Spotify prompt at depth 0 for separate mode');
|
||||
// console.log('[RPG Companion] Injected Spotify prompt at depth 0 for separate/external mode');
|
||||
} else {
|
||||
// Clear Spotify prompt if disabled
|
||||
setExtensionPrompt('rpg-companion-spotify', '', extension_prompt_types.IN_CHAT, 0, false);
|
||||
|
||||
@@ -140,10 +140,8 @@ export async function onMessageReceived(data) {
|
||||
const responseText = lastMessage.mes;
|
||||
const parsedData = parseResponse(responseText);
|
||||
|
||||
// Check if parsing completely failed (no tracker data found)
|
||||
if (parsedData.parsingFailed) {
|
||||
toastr.error(i18n.getTranslation('errors.parsingError'), '', { timeOut: 5000 });
|
||||
}
|
||||
// Note: Don't show parsing error here - this event fires when loading chat history too
|
||||
// Error notification is handled in apiClient.js for fresh generations only
|
||||
|
||||
// Remove locks from parsed data (JSON format only, text format is unaffected)
|
||||
if (parsedData.userStats) {
|
||||
@@ -195,7 +193,9 @@ export async function onMessageReceived(data) {
|
||||
// Only remove trackers if saveTrackerHistory is disabled
|
||||
// When enabled, trackers are in <trackers> XML tags which SillyTavern auto-hides
|
||||
if (!extensionSettings.saveTrackerHistory) {
|
||||
// Remove all code blocks that contain tracker data
|
||||
// Note: JSON code blocks are hidden from display by regex script (but preserved in message data)
|
||||
|
||||
// Remove old text format code blocks (legacy support)
|
||||
cleanedMessage = cleanedMessage.replace(/```[^`]*?Stats\s*\n\s*---[^`]*?```\s*/gi, '');
|
||||
cleanedMessage = cleanedMessage.replace(/```[^`]*?Info Box\s*\n\s*---[^`]*?```\s*/gi, '');
|
||||
cleanedMessage = cleanedMessage.replace(/```[^`]*?Present Characters\s*\n\s*---[^`]*?```\s*/gi, '');
|
||||
|
||||
@@ -443,10 +443,10 @@ export function updateGenerationModeUI() {
|
||||
// Show auto-update toggle
|
||||
$('#rpg-auto-update-container').slideDown(200);
|
||||
} else if (extensionSettings.generationMode === 'external') {
|
||||
// In "external" mode, manual update button is visible AND external settings are shown
|
||||
// In "external" mode, manual update button is visible AND both settings are shown
|
||||
$('#rpg-manual-update').show();
|
||||
$('#rpg-external-api-settings').slideDown(200);
|
||||
$('#rpg-separate-mode-settings').slideUp(200);
|
||||
$('#rpg-separate-mode-settings').slideDown(200);
|
||||
// Show auto-update toggle for external mode too
|
||||
$('#rpg-auto-update-container').slideDown(200);
|
||||
}
|
||||
|
||||
@@ -251,6 +251,48 @@ function exportTrackerPreset() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates old tracker preset format to current format
|
||||
* @param {Object} config - The tracker config to migrate
|
||||
* @returns {Object} - Migrated tracker config
|
||||
*/
|
||||
function migrateTrackerPreset(config) {
|
||||
// Create a deep copy to avoid modifying the original
|
||||
const migrated = JSON.parse(JSON.stringify(config));
|
||||
|
||||
// Migrate relationships structure (v3.0.0 -> v3.1.0)
|
||||
if (migrated.presentCharacters) {
|
||||
// Old format: relationshipEmojis directly on presentCharacters
|
||||
// New format: relationships.relationshipEmojis
|
||||
if (migrated.presentCharacters.relationshipEmojis &&
|
||||
!migrated.presentCharacters.relationships) {
|
||||
migrated.presentCharacters.relationships = {
|
||||
enabled: migrated.presentCharacters.enableRelationships || true,
|
||||
relationshipEmojis: migrated.presentCharacters.relationshipEmojis
|
||||
};
|
||||
// Keep legacy fields for backward compatibility
|
||||
migrated.presentCharacters.relationshipFields = Object.keys(migrated.presentCharacters.relationshipEmojis);
|
||||
}
|
||||
|
||||
// Ensure relationships object exists
|
||||
if (!migrated.presentCharacters.relationships) {
|
||||
migrated.presentCharacters.relationships = {
|
||||
enabled: false,
|
||||
relationshipEmojis: {}
|
||||
};
|
||||
}
|
||||
|
||||
// Ensure relationshipEmojis exists within relationships
|
||||
if (!migrated.presentCharacters.relationships.relationshipEmojis) {
|
||||
migrated.presentCharacters.relationships.relationshipEmojis = {};
|
||||
}
|
||||
}
|
||||
|
||||
// Add any other migration logic here for future format changes
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import tracker configuration from a JSON file
|
||||
*/
|
||||
@@ -278,6 +320,9 @@ function importTrackerPreset() {
|
||||
throw new Error('Invalid preset file: missing required configuration sections');
|
||||
}
|
||||
|
||||
// Migrate old preset format to current format
|
||||
const migratedConfig = migrateTrackerPreset(data.trackerConfig);
|
||||
|
||||
// Ask for confirmation
|
||||
const confirmMessage = i18n.getTranslation('template.trackerEditorModal.messages.importConfirm') ||
|
||||
'This will replace your current tracker configuration. Continue?';
|
||||
@@ -286,8 +331,8 @@ function importTrackerPreset() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply the imported configuration
|
||||
extensionSettings.trackerConfig = JSON.parse(JSON.stringify(data.trackerConfig)); // Deep copy
|
||||
// Apply the migrated configuration
|
||||
extensionSettings.trackerConfig = migratedConfig;
|
||||
|
||||
// Re-render the editor UI
|
||||
renderEditorUI();
|
||||
@@ -794,14 +839,25 @@ function setupPresentCharactersListeners() {
|
||||
extensionSettings.trackerConfig.presentCharacters.relationships.relationshipEmojis = {};
|
||||
}
|
||||
|
||||
// Generate a unique relationship name
|
||||
let baseName = 'New Relationship';
|
||||
let relationshipName = baseName;
|
||||
let counter = 1;
|
||||
const existingRelationships = extensionSettings.trackerConfig.presentCharacters.relationships.relationshipEmojis;
|
||||
|
||||
while (existingRelationships[relationshipName]) {
|
||||
counter++;
|
||||
relationshipName = `${baseName} ${counter}`;
|
||||
}
|
||||
|
||||
// Add to new structure
|
||||
extensionSettings.trackerConfig.presentCharacters.relationships.relationshipEmojis['New Relationship'] = '😊';
|
||||
extensionSettings.trackerConfig.presentCharacters.relationships.relationshipEmojis[relationshipName] = '😊';
|
||||
|
||||
// Also update legacy fields for backward compatibility
|
||||
if (!extensionSettings.trackerConfig.presentCharacters.relationshipEmojis) {
|
||||
extensionSettings.trackerConfig.presentCharacters.relationshipEmojis = {};
|
||||
}
|
||||
extensionSettings.trackerConfig.presentCharacters.relationshipEmojis['New Relationship'] = '😊';
|
||||
extensionSettings.trackerConfig.presentCharacters.relationshipEmojis[relationshipName] = '😊';
|
||||
|
||||
// Sync relationshipFields
|
||||
const emojis = extensionSettings.trackerConfig.presentCharacters.relationships.relationshipEmojis;
|
||||
|
||||
Reference in New Issue
Block a user