fivetech commited on
Commit
9eb0343
·
verified ·
1 Parent(s): f12a0e5

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +84 -1
index.html CHANGED
@@ -154,6 +154,20 @@ footer a{color:var(--accent);text-decoration:none}
154
  #agent-delete{background:transparent;border:1px solid #ea0038;color:#ea0038;border-radius:999px;
155
  padding:10px 18px;cursor:pointer;font-weight:600;margin-right:auto}
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  @media (max-width:760px){
158
  #app{flex-direction:column;max-width:none}
159
  #sidebar{width:100%;flex:none;border-right:none;border-bottom:1px solid var(--border)}
@@ -171,6 +185,7 @@ footer a{color:var(--accent);text-decoration:none}
171
  .msg .avatar{width:32px;height:32px;font-size:16px}
172
  .msg .content{max-width:85%}
173
  #settings{margin:0 8px 8px}
 
174
  }
175
  </style>
176
  </head>
@@ -182,6 +197,10 @@ footer a{color:var(--accent);text-decoration:none}
182
  <span class="side-title">Agentes<span class="side-count" id="side-count">(3)</span></span>
183
  </div>
184
  <div id="contacts"></div>
 
 
 
 
185
  </aside>
186
  <div id="main">
187
  <header>
@@ -269,7 +288,17 @@ const CONFIG = {
269
  autoload: params.get('autoload') !== 'false',
270
  };
271
  if (params.get('theme') === 'light') document.body.classList.add('light');
272
- let agents = DEFAULT_AGENTS;
 
 
 
 
 
 
 
 
 
 
273
  if (params.get('agents')) {
274
  try { agents = JSON.parse(params.get('agents')); } catch (e) { console.warn('agents JSON inv\u00e1lido', e); }
275
  }
@@ -380,6 +409,7 @@ deleteBtn.addEventListener('click', () => {
380
  if (agents.length <= 2) { alert('Se necesitan al menos 2 agentes.'); return; }
381
  if (!confirm(`\u00bfEliminar a ${a.name} del debate?`)) return;
382
  agents.splice(editingAgent, 1);
 
383
  renderContacts();
384
  agentModal.classList.remove('open');
385
  setStatus(`Agente eliminado: ${a.name}. Quedan ${agents.length}.`);
@@ -393,12 +423,63 @@ document.getElementById('agent-save').addEventListener('click', () => {
393
  if (!system) { alert('Describe las cualidades del agente.'); return; }
394
  if (editingAgent >= 0) agents[editingAgent] = { name, emoji, color, system };
395
  else agents.push({ name, emoji, color, system });
 
396
  renderContacts();
397
  agentModal.classList.remove('open');
398
  setStatus(editingAgent >= 0 ? `Agente actualizado: ${name}.` : `Agente a\u00f1adido: ${name}. Ya son ${agents.length}.`);
399
  });
400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
  renderContacts();
 
402
 
403
  function addMsg(agent, isUser = false) {
404
  const d = document.createElement('div');
@@ -602,6 +683,7 @@ startBtn.addEventListener('click', () => {
602
  const m = addMsg(null, true);
603
  m.body.textContent = newTopic;
604
  transcript.push({ name: null, text: 'Tema propuesto: ' + newTopic });
 
605
  } else if (!topic) {
606
  topic = 'Tema libre';
607
  }
@@ -627,6 +709,7 @@ document.getElementById('apply-settings').addEventListener('click', async () =>
627
  try { agents = JSON.parse(document.getElementById('set-agents').value); }
628
  catch (e) { alert('JSON de agentes inv\u00e1lido: ' + e.message); return; }
629
  if (!Array.isArray(agents) || agents.length < 2) { alert('Se necesitan al menos 2 agentes.'); return; }
 
630
  renderContacts();
631
  CONFIG.maxTokens = parseInt(document.getElementById('set-maxtokens').value) || CONFIG.maxTokens;
632
  CONFIG.temperature = parseFloat(document.getElementById('set-temp').value) || CONFIG.temperature;
 
154
  #agent-delete{background:transparent;border:1px solid #ea0038;color:#ea0038;border-radius:999px;
155
  padding:10px 18px;cursor:pointer;font-weight:600;margin-right:auto}
156
 
157
+
158
+ /* --- Historial de temas --- */
159
+ #history{flex:none;max-height:34%;display:flex;flex-direction:column;border-top:1px solid var(--border)}
160
+ .hist-header{display:flex;align-items:center;justify-content:space-between;padding:8px 16px 4px;
161
+ font-size:12.5px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:.4px}
162
+ #hist-clear{background:none;border:none;color:var(--muted);cursor:pointer;font-size:14px;padding:2px 4px;border-radius:6px}
163
+ #hist-clear:hover{color:var(--text);background:var(--surface2)}
164
+ #hist-list{overflow-y:auto;padding:0 8px 8px}
165
+ .hist-item{padding:7px 10px;border-radius:8px;cursor:pointer}
166
+ .hist-item:hover{background:var(--surface2)}
167
+ .hist-topic{font-size:13.5px;color:var(--text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
168
+ .hist-meta{font-size:11.5px;color:var(--muted);margin-top:1px}
169
+ .hist-empty{font-size:12px;color:var(--muted);font-style:italic;padding:6px 10px}
170
+
171
  @media (max-width:760px){
172
  #app{flex-direction:column;max-width:none}
173
  #sidebar{width:100%;flex:none;border-right:none;border-bottom:1px solid var(--border)}
 
185
  .msg .avatar{width:32px;height:32px;font-size:16px}
186
  .msg .content{max-width:85%}
187
  #settings{margin:0 8px 8px}
188
+ #history{display:none}
189
  }
190
  </style>
191
  </head>
 
197
  <span class="side-title">Agentes<span class="side-count" id="side-count">(3)</span></span>
198
  </div>
199
  <div id="contacts"></div>
200
+ <div id="history">
201
+ <div class="hist-header"><span>Temas debatidos</span><button id="hist-clear" title="Borrar historial">&#128465;</button></div>
202
+ <div id="hist-list"></div>
203
+ </div>
204
  </aside>
205
  <div id="main">
206
  <header>
 
288
  autoload: params.get('autoload') !== 'false',
289
  };
290
  if (params.get('theme') === 'light') document.body.classList.add('light');
291
+ const AGENTS_KEY = 'mad_agents';
292
+ function loadStoredAgents() {
293
+ try {
294
+ const a = JSON.parse(localStorage.getItem(AGENTS_KEY));
295
+ return (Array.isArray(a) && a.length >= 2 && a.every(x => x && x.name && x.system)) ? a : null;
296
+ } catch (e) { return null; }
297
+ }
298
+ function persistAgents() {
299
+ try { localStorage.setItem(AGENTS_KEY, JSON.stringify(agents)); } catch (e) {}
300
+ }
301
+ let agents = loadStoredAgents() || DEFAULT_AGENTS;
302
  if (params.get('agents')) {
303
  try { agents = JSON.parse(params.get('agents')); } catch (e) { console.warn('agents JSON inv\u00e1lido', e); }
304
  }
 
409
  if (agents.length <= 2) { alert('Se necesitan al menos 2 agentes.'); return; }
410
  if (!confirm(`\u00bfEliminar a ${a.name} del debate?`)) return;
411
  agents.splice(editingAgent, 1);
412
+ persistAgents();
413
  renderContacts();
414
  agentModal.classList.remove('open');
415
  setStatus(`Agente eliminado: ${a.name}. Quedan ${agents.length}.`);
 
423
  if (!system) { alert('Describe las cualidades del agente.'); return; }
424
  if (editingAgent >= 0) agents[editingAgent] = { name, emoji, color, system };
425
  else agents.push({ name, emoji, color, system });
426
+ persistAgents();
427
  renderContacts();
428
  agentModal.classList.remove('open');
429
  setStatus(editingAgent >= 0 ? `Agente actualizado: ${name}.` : `Agente a\u00f1adido: ${name}. Ya son ${agents.length}.`);
430
  });
431
 
432
+
433
+ // --- Historial de temas (localStorage) ---
434
+ const HIST_KEY = 'mad_history';
435
+ const histListEl = document.getElementById('hist-list');
436
+ function loadHistory() {
437
+ try { return JSON.parse(localStorage.getItem(HIST_KEY)) || []; } catch (e) { return []; }
438
+ }
439
+ function saveHistory(h) {
440
+ try { localStorage.setItem(HIST_KEY, JSON.stringify(h.slice(0, 30))); } catch (e) {}
441
+ }
442
+ function renderHistory() {
443
+ const h = loadHistory();
444
+ histListEl.innerHTML = '';
445
+ if (!h.length) {
446
+ const e = document.createElement('div');
447
+ e.className = 'hist-empty';
448
+ e.textContent = 'Los temas que debatas se guardar\u00e1n aqu\u00ed, en este navegador.';
449
+ histListEl.appendChild(e);
450
+ return;
451
+ }
452
+ h.forEach(item => {
453
+ const d = document.createElement('div');
454
+ d.className = 'hist-item';
455
+ d.title = 'Reutilizar este tema';
456
+ const t = document.createElement('div');
457
+ t.className = 'hist-topic'; t.textContent = item.topic;
458
+ const m = document.createElement('div');
459
+ m.className = 'hist-meta';
460
+ m.textContent = new Date(item.ts).toLocaleString('es-ES', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' }) +
461
+ ' \u00b7 ' + item.agents + ' agentes';
462
+ d.appendChild(t); d.appendChild(m);
463
+ d.addEventListener('click', () => { topicEl.value = item.topic; topicEl.focus(); });
464
+ histListEl.appendChild(d);
465
+ });
466
+ }
467
+ function recordTopic(topicText) {
468
+ const h = loadHistory();
469
+ if (h[0] && h[0].topic === topicText) return;
470
+ h.unshift({ topic: topicText, ts: Date.now(), agents: agents.length });
471
+ saveHistory(h);
472
+ renderHistory();
473
+ }
474
+ document.getElementById('hist-clear').addEventListener('click', () => {
475
+ if (!loadHistory().length) return;
476
+ if (!confirm('\u00bfBorrar el historial de temas?')) return;
477
+ saveHistory([]);
478
+ renderHistory();
479
+ });
480
+
481
  renderContacts();
482
+ renderHistory();
483
 
484
  function addMsg(agent, isUser = false) {
485
  const d = document.createElement('div');
 
683
  const m = addMsg(null, true);
684
  m.body.textContent = newTopic;
685
  transcript.push({ name: null, text: 'Tema propuesto: ' + newTopic });
686
+ recordTopic(newTopic);
687
  } else if (!topic) {
688
  topic = 'Tema libre';
689
  }
 
709
  try { agents = JSON.parse(document.getElementById('set-agents').value); }
710
  catch (e) { alert('JSON de agentes inv\u00e1lido: ' + e.message); return; }
711
  if (!Array.isArray(agents) || agents.length < 2) { alert('Se necesitan al menos 2 agentes.'); return; }
712
+ persistAgents();
713
  renderContacts();
714
  CONFIG.maxTokens = parseInt(document.getElementById('set-maxtokens').value) || CONFIG.maxTokens;
715
  CONFIG.temperature = parseFloat(document.getElementById('set-temp').value) || CONFIG.temperature;