Fix: Strip thinking tags from parser and persist tracker data on page refresh

- Added removal of <think> and <thinking> tags from AI responses before parsing
- Fixed Info Box display to use committedTrackerData as fallback after page refresh
- Fixed Present Characters display to use committedTrackerData as fallback after page refresh
- Fixed 4-part character format handling in updateCharacterField to preserve thoughts
- Ensures Recent Events and all tracker data persist correctly across page reloads
This commit is contained in:
Spicy_Marinara
2025-10-28 18:07:15 +01:00
parent a063ae780b
commit 13019c65ee
3 changed files with 57 additions and 19 deletions
+6 -3
View File
@@ -64,8 +64,11 @@ export function renderInfoBox() {
$infoBoxContainer.addClass('rpg-content-updating');
}
// Use committedTrackerData as fallback if lastGeneratedData is empty (e.g., after page refresh)
const infoBoxData = lastGeneratedData.infoBox || committedTrackerData.infoBox;
// If no data yet, show placeholder
if (!lastGeneratedData.infoBox) {
if (!infoBoxData) {
const placeholderHtml = `
<div class="rpg-dashboard rpg-dashboard-row-1">
<div class="rpg-dashboard-widget rpg-placeholder-widget">
@@ -81,10 +84,10 @@ export function renderInfoBox() {
return;
}
// console.log('[RPG Companion] renderInfoBox called with data:', lastGeneratedData.infoBox);
// console.log('[RPG Companion] renderInfoBox called with data:', infoBoxData);
// Parse the info box data
const lines = lastGeneratedData.infoBox.split('\n');
const lines = infoBoxData.split('\n');
// console.log('[RPG Companion] Info Box split into lines:', lines);
const data = {
date: '',
+13 -9
View File
@@ -76,15 +76,13 @@ export function renderThoughts() {
$thoughtsContainer.addClass('rpg-content-updating');
}
// Initialize if no data yet
if (!lastGeneratedData.characterThoughts) {
lastGeneratedData.characterThoughts = '';
}
// Use committedTrackerData as fallback if lastGeneratedData is empty (e.g., after page refresh)
const characterThoughtsData = lastGeneratedData.characterThoughts || committedTrackerData.characterThoughts || '';
debugLog('[RPG Thoughts] Raw characterThoughts data:', lastGeneratedData.characterThoughts);
debugLog('[RPG Thoughts] Data length:', lastGeneratedData.characterThoughts.length + ' chars');
debugLog('[RPG Thoughts] Raw characterThoughts data:', characterThoughtsData);
debugLog('[RPG Thoughts] Data length:', characterThoughtsData.length + ' chars');
const lines = lastGeneratedData.characterThoughts.split('\n');
const lines = characterThoughtsData.split('\n');
const presentCharacters = [];
debugLog('[RPG Thoughts] Split into lines count:', lines.length);
@@ -378,8 +376,14 @@ export function updateCharacterField(characterName, field, value) {
if (emojiMatch) {
let emoji = emojiMatch[1].trim();
let info = emojiMatch[2].trim();
let relationship = parts[1];
let thoughts = parts[2] || '';
let relationship = parts[1] ? parts[1].trim() : '';
let thoughts = parts[2] ? parts[2].trim() : '';
// Handle 4-part format (with demeanor)
if (parts.length >= 4) {
relationship = parts[2] ? parts[2].trim() : '';
thoughts = parts[3] ? parts[3].trim() : '';
}
const infoParts = info.split(',').map(p => p.trim());
let name = infoParts[0];