Fixed SD Promt

This commit is contained in:
2026-06-02 15:03:39 +03:00
parent d4cd8f02f4
commit 03cbda5dce
46 changed files with 3285 additions and 429 deletions
+62 -3
View File
@@ -1,7 +1,10 @@
import { sessionId, currentPersona, dom } from './state.js';
import { sessionId, currentPersona, setCurrentPersona, dom } from './state.js';
import { GENRE_LABELS, bindGenreGrid, resetGenreGrid } from './utils.js';
import { personaIndex } from './personas.js';
const chatSettingsGenres = new Set();
let chatSettingsPersonaId = 'default';
let chatSettingsInitialPersonaId = 'default';
function updateChatSettingsGenresLabel() {
const el = document.getElementById('chatSettingsGenresLabel');
@@ -15,6 +18,26 @@ function updateChatSettingsGenresLabel() {
}
}
function fillChatSettingsPersonaGrid() {
const grid = document.getElementById('chatSettingsPersonaGrid');
if (!grid) return;
grid.innerHTML = '';
for (const p of personaIndex.values()) {
const card = document.createElement('button');
card.type = 'button';
card.className = 'persona-pick-card' + (p.persona_id === chatSettingsPersonaId ? ' selected' : '');
card.dataset.id = p.persona_id;
card.innerHTML = `<span class="emoji">${p.emoji || '🤖'}</span>${p.name}`;
card.addEventListener('click', () => {
chatSettingsPersonaId = p.persona_id;
grid.querySelectorAll('.persona-pick-card').forEach(c => {
c.classList.toggle('selected', c.dataset.id === chatSettingsPersonaId);
});
});
grid.appendChild(card);
}
}
function loadRpgSettingsToDom(prefix, settings) {
document.getElementById(`${prefix}SettingDice`).checked = settings.dice !== false;
document.getElementById(`${prefix}SettingNarrator`).checked = settings.narrator !== false;
@@ -67,6 +90,10 @@ export async function openChatSettings() {
const s = await res.json();
document.getElementById('chatSettingsTitle').value = s.title || '';
chatSettingsPersonaId = s.persona_id || 'default';
chatSettingsInitialPersonaId = chatSettingsPersonaId;
fillChatSettingsPersonaGrid();
const rpgOn = !!s.rpg_enabled;
document.getElementById('chatSettingsRpg').checked = rpgOn;
document.getElementById('chatSettingsRpgBlock').classList.toggle('hidden', !rpgOn);
@@ -117,13 +144,45 @@ export function initChatSettings() {
document.getElementById('chatSettingsSave')?.addEventListener('click', async () => {
if (!sessionId) return;
const { loadSessions, applySessionUi } = await import('./sessions.js');
const { loadSessions, applySessionUi, renderSystemBlob } = await import('./sessions.js');
const { reloadChatFromServer } = await import('./chat.js');
const { highlightPersonaBar } = await import('./personas.js');
const title = document.getElementById('chatSettingsTitle').value.trim();
const rpgOn = document.getElementById('chatSettingsRpg').checked;
const genreValue = [...chatSettingsGenres].join(',') || 'adventure';
const settings = readRpgSettingsFromDom('cs');
if (chatSettingsPersonaId !== chatSettingsInitialPersonaId) {
const pName = personaIndex.get(chatSettingsPersonaId)?.name || chatSettingsPersonaId;
const keepHistory = confirm(
`Перепривязать чат к «${pName}»?\n\n`
+ 'OK — сохранить историю сообщений (персонаж в старых репликах может не совпадать).\n'
+ 'Отмена — очистить историю и начать с приветствия нового персонажа.',
);
const clearHistory = !keepHistory;
const rebindRes = await fetch(`/sessions/${sessionId}/rebind-persona`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
persona_id: chatSettingsPersonaId,
clear_history: clearHistory,
}),
});
if (!rebindRes.ok) {
const err = await rebindRes.json().catch(() => ({}));
alert(err.detail || 'Не удалось сменить персонажа');
return;
}
setCurrentPersona(chatSettingsPersonaId);
chatSettingsInitialPersonaId = chatSettingsPersonaId;
highlightPersonaBar(chatSettingsPersonaId);
await reloadChatFromServer(sessionId);
const blobRes = await fetch(`/chat/system/${sessionId}`);
if (blobRes.ok) renderSystemBlob(await blobRes.json());
}
await fetch(`/sessions/${sessionId}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
@@ -141,7 +200,7 @@ export function initChatSettings() {
let arc = {};
try { arc = JSON.parse(s.plot_arc_json || '{}'); } catch { /* ignore */ }
if (!arc || !Object.keys(arc).length) {
await bootstrapRpg(sessionId, currentPersona, genreValue, settings);
await bootstrapRpg(sessionId, chatSettingsPersonaId, genreValue, settings);
}
}