first commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { toggleSidebar, dom } from './state.js';
|
||||
import { initSessions, createNewChat } from './sessions.js';
|
||||
import { loadPersonas, initPersonaModals } from './personas.js';
|
||||
import { sendMessage, clearHistory } from './chat.js';
|
||||
|
||||
document.getElementById('sidebarToggle').addEventListener('click', () => {
|
||||
const open = toggleSidebar();
|
||||
document.getElementById('sidebar').classList.toggle('collapsed', !open);
|
||||
});
|
||||
|
||||
document.getElementById('newChatBtn').addEventListener('click', createNewChat);
|
||||
|
||||
dom.inputEl.addEventListener('input', () => {
|
||||
dom.inputEl.style.height = 'auto';
|
||||
dom.inputEl.style.height = dom.inputEl.scrollHeight + 'px';
|
||||
});
|
||||
|
||||
dom.inputEl.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
sendMessage();
|
||||
}
|
||||
});
|
||||
|
||||
dom.sendBtn.addEventListener('click', sendMessage);
|
||||
dom.clearBtn.addEventListener('click', clearHistory);
|
||||
|
||||
initPersonaModals();
|
||||
await initSessions();
|
||||
loadPersonas();
|
||||
@@ -0,0 +1,260 @@
|
||||
import { sessionId, currentPersona, dom } from './state.js';
|
||||
import { parseImagePromptFromContent, copyToClipboard } from './utils.js';
|
||||
|
||||
export async function initChat() {
|
||||
if (!sessionId || !currentPersona) return;
|
||||
const res = await fetch('/chat/init', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ message: '', session_id: sessionId, persona_id: currentPersona }),
|
||||
});
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
if (data.first_mes) addMessage('assistant', data.first_mes);
|
||||
}
|
||||
|
||||
export function updateEmptyState() {
|
||||
const hasMessages = dom.messagesEl.querySelector('.message');
|
||||
dom.emptyState?.classList.toggle('hidden', !!hasMessages);
|
||||
}
|
||||
|
||||
export function createImagePromptBlock(promptText) {
|
||||
const block = document.createElement('div');
|
||||
block.className = 'image-prompt-block';
|
||||
|
||||
const header = document.createElement('div');
|
||||
header.className = 'image-prompt-header';
|
||||
header.innerHTML = '<span>🎨 SD prompt</span>';
|
||||
|
||||
const copyBtn = document.createElement('button');
|
||||
copyBtn.type = 'button';
|
||||
copyBtn.className = 'copy-prompt-btn';
|
||||
copyBtn.textContent = 'Копировать';
|
||||
copyBtn.addEventListener('click', async () => {
|
||||
const ok = await copyToClipboard(promptText);
|
||||
copyBtn.textContent = ok ? 'Скопировано' : 'Ошибка';
|
||||
setTimeout(() => { copyBtn.textContent = 'Копировать'; }, 1500);
|
||||
});
|
||||
header.appendChild(copyBtn);
|
||||
|
||||
const genBtn = document.createElement('button');
|
||||
genBtn.type = 'button';
|
||||
genBtn.className = 'gen-image-btn';
|
||||
genBtn.textContent = '🖼 Генерировать';
|
||||
genBtn.addEventListener('click', () => generateImageViaA1111(promptText, block));
|
||||
header.appendChild(genBtn);
|
||||
|
||||
const textEl = document.createElement('span');
|
||||
textEl.className = 'prompt-text';
|
||||
textEl.textContent = promptText;
|
||||
|
||||
block.appendChild(header);
|
||||
block.appendChild(textEl);
|
||||
return block;
|
||||
}
|
||||
|
||||
async function generateImageViaA1111(promptText, block) {
|
||||
block.parentElement.querySelector('.chat-image')?.remove();
|
||||
block.parentElement.querySelector('.image-error')?.remove();
|
||||
|
||||
try {
|
||||
const res = await fetch('/images/generate', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ session_id: sessionId, prompt: promptText }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.detail || res.statusText);
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.className = 'chat-image';
|
||||
img.src = data.image_path;
|
||||
block.parentElement.appendChild(img);
|
||||
} catch (e) {
|
||||
const err = document.createElement('div');
|
||||
err.className = 'image-error';
|
||||
err.textContent = '🖼 ' + e.message;
|
||||
block.parentElement.appendChild(err);
|
||||
}
|
||||
}
|
||||
|
||||
export function appendChatImage(wrapper, imagePath) {
|
||||
if (!imagePath) return;
|
||||
const img = document.createElement('img');
|
||||
img.className = 'chat-image';
|
||||
img.src = imagePath;
|
||||
wrapper.appendChild(img);
|
||||
}
|
||||
|
||||
export function addMessage(role, content = '', imagePrompt = null, imagePath = null) {
|
||||
updateEmptyState();
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.className = `message ${role}`;
|
||||
|
||||
const label = document.createElement('div');
|
||||
label.className = 'label';
|
||||
label.textContent = role === 'user' ? 'Вы' : 'AI';
|
||||
wrapper.appendChild(label);
|
||||
|
||||
let displayContent = content;
|
||||
let prompt = imagePrompt;
|
||||
if (role === 'assistant' && !prompt) {
|
||||
const parsed = parseImagePromptFromContent(content);
|
||||
displayContent = parsed.text;
|
||||
prompt = parsed.prompt;
|
||||
}
|
||||
|
||||
const bubble = document.createElement('div');
|
||||
bubble.className = 'bubble';
|
||||
bubble.textContent = displayContent;
|
||||
wrapper.appendChild(bubble);
|
||||
|
||||
if (role === 'assistant') {
|
||||
const translateBtn = document.createElement('button');
|
||||
translateBtn.type = 'button';
|
||||
translateBtn.className = 'translate-btn';
|
||||
translateBtn.textContent = '🌐 RU';
|
||||
let originalText = null;
|
||||
translateBtn.addEventListener('click', async () => {
|
||||
if (originalText !== null) {
|
||||
bubble.textContent = originalText;
|
||||
originalText = null;
|
||||
translateBtn.textContent = '🌐 RU';
|
||||
return;
|
||||
}
|
||||
originalText = bubble.textContent;
|
||||
translateBtn.disabled = true;
|
||||
translateBtn.textContent = '…';
|
||||
try {
|
||||
const res = await fetch('/translate/', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ text: originalText }),
|
||||
});
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
const data = await res.json();
|
||||
bubble.textContent = data.translated;
|
||||
translateBtn.textContent = '↩ Оригинал';
|
||||
} catch {
|
||||
originalText = null;
|
||||
translateBtn.textContent = '⚠️';
|
||||
setTimeout(() => { translateBtn.textContent = '🌐 RU'; }, 2000);
|
||||
}
|
||||
translateBtn.disabled = false;
|
||||
});
|
||||
wrapper.appendChild(translateBtn);
|
||||
}
|
||||
|
||||
if (prompt) wrapper.appendChild(createImagePromptBlock(prompt));
|
||||
if (imagePath) appendChatImage(wrapper, imagePath);
|
||||
|
||||
dom.messagesEl.appendChild(wrapper);
|
||||
dom.messagesEl.scrollTop = dom.messagesEl.scrollHeight;
|
||||
return bubble;
|
||||
}
|
||||
|
||||
export function showTyping() {
|
||||
const typing = document.createElement('div');
|
||||
typing.className = 'typing';
|
||||
typing.id = 'typing';
|
||||
typing.innerHTML = '<span></span><span></span><span></span>';
|
||||
dom.messagesEl.appendChild(typing);
|
||||
dom.messagesEl.scrollTop = dom.messagesEl.scrollHeight;
|
||||
}
|
||||
|
||||
export function removeTyping() {
|
||||
document.getElementById('typing')?.remove();
|
||||
}
|
||||
|
||||
export function clearMessages() {
|
||||
dom.messagesEl.innerHTML = '';
|
||||
if (dom.emptyState) {
|
||||
dom.messagesEl.appendChild(dom.emptyState);
|
||||
dom.emptyState.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendMessage() {
|
||||
const text = dom.inputEl.value.trim();
|
||||
if (!text || !sessionId) return;
|
||||
|
||||
dom.inputEl.value = '';
|
||||
dom.inputEl.style.height = 'auto';
|
||||
dom.sendBtn.disabled = true;
|
||||
|
||||
addMessage('user', text);
|
||||
showTyping();
|
||||
|
||||
try {
|
||||
const res = await fetch('/chat/stream', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ message: text, session_id: sessionId, persona_id: currentPersona }),
|
||||
});
|
||||
if (!res.ok) throw new Error('Ошибка сервера: ' + res.status);
|
||||
|
||||
const reader = res.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = '';
|
||||
let bubble = null;
|
||||
|
||||
removeTyping();
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
const lines = buffer.split('\n');
|
||||
buffer = lines.pop();
|
||||
|
||||
for (const line of lines) {
|
||||
if (!line.startsWith('data: ')) continue;
|
||||
try {
|
||||
const data = JSON.parse(line.slice(6));
|
||||
|
||||
if (data.chunk !== undefined) {
|
||||
if (!bubble) {
|
||||
bubble = addMessage('assistant', '');
|
||||
bubble.classList.add('typing-active');
|
||||
}
|
||||
bubble.textContent += data.chunk;
|
||||
bubble.textContent = bubble.textContent.replace(/\[IMAGE_PROMPT:.*?\]/gs, '').trim();
|
||||
dom.messagesEl.scrollTop = dom.messagesEl.scrollHeight;
|
||||
}
|
||||
|
||||
if (data.done) {
|
||||
bubble?.classList.remove('typing-active');
|
||||
if (data.image_prompt && bubble) {
|
||||
bubble.parentElement.appendChild(createImagePromptBlock(data.image_prompt));
|
||||
}
|
||||
if (data.image_path && bubble) {
|
||||
appendChatImage(bubble.parentElement, data.image_path);
|
||||
}
|
||||
if (data.image_error && bubble) {
|
||||
const err = document.createElement('div');
|
||||
err.className = 'image-error';
|
||||
err.textContent = '🖼 ' + data.image_error;
|
||||
bubble.parentElement.appendChild(err);
|
||||
}
|
||||
const { loadSessions } = await import('./sessions.js');
|
||||
loadSessions();
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
removeTyping();
|
||||
addMessage('assistant', '⚠️ Ошибка: ' + err.message);
|
||||
} finally {
|
||||
dom.sendBtn.disabled = false;
|
||||
dom.inputEl.focus();
|
||||
}
|
||||
}
|
||||
|
||||
export async function clearHistory() {
|
||||
if (!sessionId) return;
|
||||
await fetch(`/chat/${sessionId}`, { method: 'DELETE' });
|
||||
clearMessages();
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
import { currentPersona, setCurrentPersona, sessionId } from './state.js';
|
||||
import { initChat } from './chat.js';
|
||||
|
||||
export function highlightPersona(personaId) {
|
||||
document.querySelectorAll('.persona-card').forEach(c => {
|
||||
c.classList.toggle('active', c.dataset.id === personaId);
|
||||
});
|
||||
}
|
||||
|
||||
export async function loadPersonas() {
|
||||
const res = await fetch('/personas/');
|
||||
const personas = await res.json();
|
||||
const bar = document.getElementById('personaBar');
|
||||
bar.innerHTML = '';
|
||||
|
||||
personas.forEach(p => {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'persona-card' + (p.persona_id === currentPersona ? ' active' : '');
|
||||
card.dataset.id = p.persona_id;
|
||||
const isCard = p.persona_id.startsWith('card_');
|
||||
card.innerHTML = `
|
||||
<span class="emoji">${p.emoji}</span>
|
||||
<span class="pname">${p.name}</span>
|
||||
${p.custom ? `<button class="del-btn" type="button">✕</button>` : ''}
|
||||
${isCard ? `<button class="edit-btn" type="button">✏️</button>` : ''}
|
||||
`;
|
||||
card.addEventListener('click', () => selectPersona(p.persona_id));
|
||||
card.querySelector('.del-btn')?.addEventListener('click', async (e) => {
|
||||
e.stopPropagation();
|
||||
await fetch(`/personas/${p.persona_id}`, { method: 'DELETE' });
|
||||
if (currentPersona === p.persona_id) await selectPersona('default');
|
||||
loadPersonas();
|
||||
});
|
||||
card.querySelector('.edit-btn')?.addEventListener('click', async (e) => {
|
||||
e.stopPropagation();
|
||||
const cardId = p.persona_id.slice(5);
|
||||
const r = await fetch(`/characters/${cardId}`);
|
||||
const data = await r.json();
|
||||
document.getElementById('editCardId').value = cardId;
|
||||
document.getElementById('editName').value = data.name || '';
|
||||
document.getElementById('editDescription').value = data.description || '';
|
||||
document.getElementById('editPersonality').value = data.personality || '';
|
||||
document.getElementById('editScenario').value = data.scenario || '';
|
||||
document.getElementById('editFirstMes').value = data.first_mes || '';
|
||||
document.getElementById('editMesExample').value = data.mes_example || '';
|
||||
document.getElementById('editAppearance').value = data.appearance_tags || '';
|
||||
document.getElementById('editLora').value = data.lora_name || '';
|
||||
document.getElementById('editLoraWeight').value = data.lora_weight ?? 0.8;
|
||||
document.getElementById('cardEditOverlay').classList.add('open');
|
||||
});
|
||||
bar.appendChild(card);
|
||||
});
|
||||
|
||||
const addBtn = document.createElement('button');
|
||||
addBtn.type = 'button';
|
||||
addBtn.className = 'persona-add';
|
||||
addBtn.innerHTML = '➕<span>Создать</span>';
|
||||
addBtn.addEventListener('click', () => document.getElementById('modalOverlay').classList.add('open'));
|
||||
bar.appendChild(addBtn);
|
||||
|
||||
const importBtn = document.createElement('button');
|
||||
importBtn.type = 'button';
|
||||
importBtn.className = 'card-import-btn';
|
||||
importBtn.innerHTML = '📥<span>Chub</span>';
|
||||
importBtn.addEventListener('click', () => document.getElementById('cardModalOverlay').classList.add('open'));
|
||||
bar.appendChild(importBtn);
|
||||
}
|
||||
|
||||
export async function selectPersona(personaId) {
|
||||
setCurrentPersona(personaId);
|
||||
highlightPersona(personaId);
|
||||
if (sessionId) {
|
||||
await fetch(`/sessions/${sessionId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ persona_id: personaId }),
|
||||
});
|
||||
await initChat();
|
||||
}
|
||||
}
|
||||
|
||||
export function initPersonaModals() {
|
||||
document.getElementById('modalCancel').addEventListener('click', () => {
|
||||
document.getElementById('modalOverlay').classList.remove('open');
|
||||
});
|
||||
document.getElementById('cardModalCancel').addEventListener('click', () => {
|
||||
document.getElementById('cardModalOverlay').classList.remove('open');
|
||||
});
|
||||
document.getElementById('cardEditCancel').addEventListener('click', () => {
|
||||
document.getElementById('cardEditOverlay').classList.remove('open');
|
||||
});
|
||||
|
||||
document.getElementById('modalSave').addEventListener('click', async () => {
|
||||
const data = {
|
||||
persona_id: document.getElementById('pId').value.trim(),
|
||||
name: document.getElementById('pName').value.trim(),
|
||||
emoji: document.getElementById('pEmoji').value.trim() || '🤖',
|
||||
description: document.getElementById('pDesc').value.trim(),
|
||||
prompt: document.getElementById('pPrompt').value.trim(),
|
||||
sd_enabled: document.getElementById('pSdEnabled').checked,
|
||||
lora_name: document.getElementById('pLora').value.trim(),
|
||||
appearance_tags: document.getElementById('pAppearance').value.trim(),
|
||||
};
|
||||
if (!data.persona_id || !data.name || !data.prompt) {
|
||||
alert('Заполни ID, имя и промт');
|
||||
return;
|
||||
}
|
||||
await fetch('/personas/', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
document.getElementById('modalOverlay').classList.remove('open');
|
||||
await loadPersonas();
|
||||
await selectPersona(data.persona_id);
|
||||
});
|
||||
|
||||
document.getElementById('cardEditSave').addEventListener('click', async () => {
|
||||
const cardId = document.getElementById('editCardId').value;
|
||||
const body = {
|
||||
name: document.getElementById('editName').value.trim() || undefined,
|
||||
description: document.getElementById('editDescription').value.trim() || undefined,
|
||||
personality: document.getElementById('editPersonality').value.trim() || undefined,
|
||||
scenario: document.getElementById('editScenario').value.trim() || undefined,
|
||||
first_mes: document.getElementById('editFirstMes').value.trim() || undefined,
|
||||
mes_example: document.getElementById('editMesExample').value.trim() || undefined,
|
||||
appearance_tags: document.getElementById('editAppearance').value.trim() || undefined,
|
||||
lora_name: document.getElementById('editLora').value.trim() || undefined,
|
||||
lora_weight: parseFloat(document.getElementById('editLoraWeight').value) || undefined,
|
||||
};
|
||||
const res = await fetch(`/characters/${cardId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!res.ok) { alert('Ошибка сохранения'); return; }
|
||||
document.getElementById('cardEditOverlay').classList.remove('open');
|
||||
await loadPersonas();
|
||||
});
|
||||
|
||||
document.getElementById('cardModalImport').addEventListener('click', async () => {
|
||||
const fileInput = document.getElementById('cardFile');
|
||||
if (!fileInput.files?.length) {
|
||||
alert('Выберите файл карточки (JSON или PNG)');
|
||||
return;
|
||||
}
|
||||
const form = new FormData();
|
||||
form.append('file', fileInput.files[0]);
|
||||
form.append('lora_name', document.getElementById('cardLora').value.trim());
|
||||
form.append('lora_weight', document.getElementById('cardLoraWeight').value || '0.8');
|
||||
|
||||
const res = await fetch('/characters/import', { method: 'POST', body: form });
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
alert(data.detail || 'Ошибка импорта');
|
||||
return;
|
||||
}
|
||||
document.getElementById('cardModalOverlay').classList.remove('open');
|
||||
fileInput.value = '';
|
||||
await loadPersonas();
|
||||
await selectPersona(data.persona_id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import { sessionId, setSessionId, setCurrentPersona, currentPersona, dom } from './state.js';
|
||||
import { clearMessages, addMessage, initChat } from './chat.js';
|
||||
import { highlightPersona } from './personas.js';
|
||||
|
||||
function escapeTitle(t) {
|
||||
const d = document.createElement('div');
|
||||
d.textContent = t;
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
export async function loadSessions() {
|
||||
const res = await fetch('/sessions/');
|
||||
const sessions = await res.json();
|
||||
dom.sessionList.innerHTML = '';
|
||||
|
||||
sessions.forEach(s => {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'session-item' + (s.session_id === sessionId ? ' active' : '');
|
||||
item.innerHTML = `
|
||||
<div class="s-title">${escapeTitle(s.title || 'Новый чат')}</div>
|
||||
<div class="s-meta">${s.message_count} сообщ.</div>
|
||||
<button class="s-del" type="button">🗑</button>
|
||||
`;
|
||||
item.addEventListener('click', () => switchSession(s.session_id));
|
||||
item.querySelector('.s-del').addEventListener('click', async (e) => {
|
||||
e.stopPropagation();
|
||||
await fetch(`/sessions/${s.session_id}`, { method: 'DELETE' });
|
||||
if (s.session_id === sessionId) createNewChat();
|
||||
else loadSessions();
|
||||
});
|
||||
dom.sessionList.appendChild(item);
|
||||
});
|
||||
}
|
||||
|
||||
export async function switchSession(id) {
|
||||
setSessionId(id);
|
||||
clearMessages();
|
||||
await loadSessions();
|
||||
await loadChatHistory(id);
|
||||
}
|
||||
|
||||
export async function loadChatHistory(id) {
|
||||
const sessionRes = await fetch(`/sessions/${id}`);
|
||||
if (sessionRes.ok) {
|
||||
const s = await sessionRes.json();
|
||||
dom.headerTitle.textContent = s.title || 'Новый чат';
|
||||
if (s.persona_id) {
|
||||
setCurrentPersona(s.persona_id);
|
||||
highlightPersona(s.persona_id);
|
||||
}
|
||||
}
|
||||
|
||||
const histRes = await fetch(`/chat/history/${id}`);
|
||||
if (!histRes.ok) return;
|
||||
|
||||
const messages = await histRes.json();
|
||||
clearMessages();
|
||||
messages.filter(m => m.role !== 'system').forEach(m => {
|
||||
addMessage(
|
||||
m.role === 'user' ? 'user' : 'assistant',
|
||||
m.content,
|
||||
m.image_prompt,
|
||||
m.image_path ? `/static/${m.image_path}` : null,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function createNewChat() {
|
||||
setSessionId('sess_' + Math.random().toString(36).slice(2, 10));
|
||||
clearMessages();
|
||||
dom.headerTitle.textContent = 'Новый чат';
|
||||
highlightPersona(currentPersona);
|
||||
await initChat();
|
||||
loadSessions();
|
||||
}
|
||||
|
||||
export async function initSessions() {
|
||||
await loadSessions();
|
||||
if (sessionId) {
|
||||
const check = await fetch(`/sessions/${sessionId}`);
|
||||
if (check.ok) await switchSession(sessionId);
|
||||
else createNewChat();
|
||||
} else {
|
||||
createNewChat();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
export let sessionId = localStorage.getItem('chat_session_id') || null;
|
||||
export let currentPersona = localStorage.getItem('persona_id') || 'default';
|
||||
export let sidebarOpen = true;
|
||||
export function toggleSidebar() { sidebarOpen = !sidebarOpen; return sidebarOpen; }
|
||||
|
||||
export function setSessionId(id) {
|
||||
sessionId = id;
|
||||
if (id) localStorage.setItem('chat_session_id', id);
|
||||
}
|
||||
|
||||
export function setCurrentPersona(id) {
|
||||
currentPersona = id;
|
||||
localStorage.setItem('persona_id', id);
|
||||
}
|
||||
|
||||
export const dom = {
|
||||
messagesEl: document.getElementById('messages'),
|
||||
inputEl: document.getElementById('input'),
|
||||
sendBtn: document.getElementById('sendBtn'),
|
||||
clearBtn: document.getElementById('clearBtn'),
|
||||
sessionList: document.getElementById('sessionList'),
|
||||
headerTitle: document.getElementById('headerTitle'),
|
||||
emptyState: document.getElementById('emptyState'),
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
export function parseImagePromptFromContent(content) {
|
||||
if (!content || !content.includes('[IMAGE_PROMPT:')) return { text: content, prompt: null };
|
||||
const match = content.match(/\[IMAGE_PROMPT:(.*?)\]/s);
|
||||
const prompt = match ? match[1].trim() : null;
|
||||
const text = content.replace(/\[IMAGE_PROMPT:.*?\]/gs, '').trim();
|
||||
return { text, prompt };
|
||||
}
|
||||
|
||||
export async function copyToClipboard(text) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user