Fixed SD RPG

This commit is contained in:
2026-06-04 08:05:06 +03:00
parent d4cd8f02f4
commit 6189a5fb74
62 changed files with 6969 additions and 552 deletions
+33 -6
View File
@@ -1,8 +1,10 @@
import {
sessionId, setSessionId, setCurrentPersona, currentPersona, dom, setRpgEnabled,
} from './state.js';
import { updateQuestPanel, updateAffinityDisplay } from './chat.js';
import { highlightPersona, personaIndex } from './personas.js';
import {
updateQuestPanel, updateAffinityDisplay, updateStatsDisplay, hideStatsDisplay,
} from './chat.js';
import { highlightPersonaBar, personaIndex } from './personas.js';
import { formatSessionDate } from './utils.js';
import { openNewChatWizard } from './newChatWizard.js';
@@ -35,6 +37,16 @@ export function applySessionUi(session) {
dom.affinityDisplay?.classList.add('hidden');
}
if (rpgOn && settings.stats) {
try {
updateStatsDisplay(JSON.parse(session.narrative_stats_json || '{}'));
} catch {
hideStatsDisplay();
}
} else {
hideStatsDisplay();
}
if (rpgOn && settings.quests) {
fetch(`/sessions/${session.session_id}/quests`)
.then(r => r.ok ? r.json() : [])
@@ -114,7 +126,7 @@ export async function loadChatHistory(id) {
const s = await sessionRes.json();
if (s.persona_id) {
setCurrentPersona(s.persona_id);
highlightPersona(s.persona_id);
highlightPersonaBar(s.persona_id);
}
applySessionUi(s);
}
@@ -155,7 +167,7 @@ export async function initSessions() {
let _prevBlobSections = {};
function renderSystemBlob(blob) {
export function renderSystemBlob(blob) {
const tryFmt = (str, fallback = '') => {
try { return JSON.stringify(JSON.parse(str), null, 2); } catch { return str || fallback; }
};
@@ -165,13 +177,26 @@ function renderSystemBlob(blob) {
return ` ${icon} [${q.status}] ${q.title}`;
}).join('\n');
const personaLine = blob.persona_id
? `[persona] ${blob.persona_name || blob.persona_id} (${blob.persona_id})`
: '';
const ctx = blob.context_usage;
const ctxLine = ctx
? `[context] ~${ctx.tokens_est} / ${ctx.max_tokens_est} tokens (${ctx.percent}%) · ${ctx.chars} chars`
: '';
const sections = {
context: ctxLine,
persona: personaLine,
system_prompt: blob.system_prompt ? `[system_prompt]\n${blob.system_prompt}` : '',
status_quo: blob.status_quo ? `[status_quo]\n${blob.status_quo}` : '',
affinity: blob.affinity != null ? `[affinity] ${blob.affinity}` : '',
scene: blob.scene_json && blob.scene_json !== '{}' ? `[scene]\n${tryFmt(blob.scene_json)}` : '',
stats: blob.narrative_stats_json && blob.narrative_stats_json !== '{}' ? `[stats]\n${tryFmt(blob.narrative_stats_json)}` : '',
genre: blob.genre ? `[genre] ${blob.genre}` : '',
rpg_settings: blob.rpg_settings_json && blob.rpg_settings_json !== '{}' ? `[rpg_settings]\n${tryFmt(blob.rpg_settings_json)}` : '',
outfit: blob.outfit_json && blob.outfit_json !== '[]' ? `[outfit]\n${tryFmt(blob.outfit_json)}` : '',
outfit: `[outfit]\n${tryFmt(blob.outfit_json ?? '[]')}`,
facts: blob.facts_json && blob.facts_json !== '[]' ? `[facts]\n${tryFmt(blob.facts_json)}` : '',
plot_arc: blob.plot_arc_json && blob.plot_arc_json !== '{}' ? `[plot_arc]\n${tryFmt(blob.plot_arc_json)}` : '',
quests: questLines ? `[quests]\n${questLines}` : '',
@@ -184,7 +209,9 @@ function renderSystemBlob(blob) {
if (!text) continue;
const span = document.createElement('span');
span.textContent = text;
if (_prevBlobSections[key] && _prevBlobSections[key] !== text) {
if (key === 'context' && ctx && ctx.percent > 80) {
span.className = 'blob-context-warn';
} else if (_prevBlobSections[key] && _prevBlobSections[key] !== text) {
span.className = 'blob-changed';
setTimeout(() => span.classList.remove('blob-changed'), 3000);
}