Merge pull request #14 from paperboygold/main
fix: temporary fix for presets
This commit is contained in:
@@ -17,49 +17,26 @@ import {
|
|||||||
import { saveChatData } from '../../core/persistence.js';
|
import { saveChatData } from '../../core/persistence.js';
|
||||||
import { generateSeparateUpdatePrompt } from './promptBuilder.js';
|
import { generateSeparateUpdatePrompt } from './promptBuilder.js';
|
||||||
import { parseResponse, parseUserStats } from './parser.js';
|
import { parseResponse, parseUserStats } from './parser.js';
|
||||||
import { getCurrentPresetName } from '../../../../../regex/engine.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switches to a specific preset by name using the /preset slash command
|
* Switches to a specific preset by name using the /preset slash command
|
||||||
* @param {string} presetName - Name of the preset to switch to
|
* @param {string} presetName - Name of the preset to switch to
|
||||||
* @returns {Promise<string|null>} The previous preset name, or null if switching failed
|
* @returns {Promise<boolean>} True if switching succeeded, false otherwise
|
||||||
*/
|
*/
|
||||||
async function switchToPreset(presetName) {
|
async function switchToPreset(presetName) {
|
||||||
try {
|
try {
|
||||||
// Get the current preset before switching using SillyTavern's built-in API
|
|
||||||
const previousPreset = getCurrentPresetName();
|
|
||||||
|
|
||||||
// Use the /preset slash command to switch presets
|
// Use the /preset slash command to switch presets
|
||||||
// This is the proper way to change presets in SillyTavern
|
// This is the proper way to change presets in SillyTavern
|
||||||
await executeSlashCommandsOnChatInput(`/preset ${presetName}`, { quiet: true });
|
await executeSlashCommandsOnChatInput(`/preset ${presetName}`, { quiet: true });
|
||||||
|
|
||||||
// console.log(`[RPG Companion] Switched from preset "${previousPreset || 'none'}" to "${presetName}"`);
|
// console.log(`[RPG Companion] Switched to preset "${presetName}"`);
|
||||||
return previousPreset;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[RPG Companion] Error switching preset:', error);
|
console.error('[RPG Companion] Error switching preset:', error);
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Restores a previously saved preset using the /preset slash command
|
|
||||||
* @param {string} presetName - Name of the preset to restore
|
|
||||||
*/
|
|
||||||
async function restorePreset(presetName) {
|
|
||||||
try {
|
|
||||||
if (!presetName) {
|
|
||||||
console.warn('[RPG Companion] No preset name to restore');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the /preset slash command to restore the preset
|
|
||||||
await executeSlashCommandsOnChatInput(`/preset ${presetName}`, { quiet: true });
|
|
||||||
|
|
||||||
// console.log(`[RPG Companion] Restored preset to "${presetName}"`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[RPG Companion] Error restoring preset:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates RPG tracker data using separate API call (separate mode only).
|
* Updates RPG tracker data using separate API call (separate mode only).
|
||||||
@@ -86,8 +63,6 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let previousPreset = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsGenerating(true);
|
setIsGenerating(true);
|
||||||
|
|
||||||
@@ -98,8 +73,8 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough
|
|||||||
|
|
||||||
// Switch to separate preset if enabled
|
// Switch to separate preset if enabled
|
||||||
if (extensionSettings.useSeparatePreset) {
|
if (extensionSettings.useSeparatePreset) {
|
||||||
previousPreset = await switchToPreset('RPG Companion Trackers');
|
const switched = await switchToPreset('RPG Companion Trackers');
|
||||||
if (!previousPreset) {
|
if (!switched) {
|
||||||
console.warn('[RPG Companion] Failed to switch to RPG Companion Trackers preset. Using current preset.');
|
console.warn('[RPG Companion] Failed to switch to RPG Companion Trackers preset. Using current preset.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,19 +171,9 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough
|
|||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[RPG Companion] Error updating RPG data:', error);
|
console.error('[RPG Companion] Error updating RPG data:', error);
|
||||||
|
|
||||||
// Restore preset on error if we switched it
|
|
||||||
if (extensionSettings.useSeparatePreset && previousPreset) {
|
|
||||||
await restorePreset(previousPreset);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsGenerating(false);
|
setIsGenerating(false);
|
||||||
|
|
||||||
// Restore preset after successful generation
|
|
||||||
if (extensionSettings.useSeparatePreset && previousPreset) {
|
|
||||||
await restorePreset(previousPreset);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore button to original state
|
// Restore button to original state
|
||||||
const $updateBtn = $('#rpg-manual-update');
|
const $updateBtn = $('#rpg-manual-update');
|
||||||
$updateBtn.html('<i class="fa-solid fa-sync"></i> Refresh RPG Info').prop('disabled', false);
|
$updateBtn.html('<i class="fa-solid fa-sync"></i> Refresh RPG Info').prop('disabled', false);
|
||||||
|
|||||||
Reference in New Issue
Block a user