Dashboard Masticationpedia: differenze tra le versioni
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
| Riga 133: | Riga 133: | ||
<script> | <script> | ||
// ======== Invio prompt via proxy sicuro ======== | // ======== Invio prompt via proxy sicuro ======== | ||
// | // ======== Invio prompt via proxy sicuro ======== | ||
// NOTA: questo codice deve stare dentro allo stesso <script> dove | |||
// sono definiti: let currentProject, let sessionId, let sessionMeta, let history, let attachments | |||
function bindSendHandlersOnce(){ | |||
// Evita doppi listener | |||
if (window.__mpai_bound) return; | |||
window.__mpai_bound = true; | |||
document.addEventListener('click', (e)=>{ | |||
if (e.target && e.target.id === 'mpai-send') sendPrompt(); | |||
}); | |||
document.addEventListener('keydown', (e)=>{ | |||
if ((e.metaKey||e.ctrlKey) && e.key === 'Enter'){ | |||
const ta = document.querySelector('#mpai-input'); | |||
if (ta && ta === document.activeElement){ e.preventDefault(); sendPrompt(); } | |||
} | |||
}); | |||
} | |||
async function sendPrompt(){ | async function sendPrompt(){ | ||
| Riga 145: | Riga 164: | ||
if (!content){ ta.focus(); return; } | if (!content){ ta.focus(); return; } | ||
// Se non | // Se non c’è un progetto attivo, usa una “bozza locale” | ||
if (! | if (!currentProject && !sessionId){ | ||
ensureSession(); | ensureSession(); | ||
loadSession( | loadSession(sessionId); | ||
} | } | ||
| Riga 156: | Riga 175: | ||
ta.value = ''; | ta.value = ''; | ||
// | // Contesto | ||
const contextName = | const contextName = currentProject | ||
? `Progetto: ${ | ? `Progetto: ${currentProject}` | ||
: `Sessione: ${ | : `Sessione: ${sessionMeta?.title || 'Nuova conversazione'}`; | ||
const fileNames = (attachments || []).map(a => a.name).join(', '); | const fileNames = (attachments || []).map(a => a.name).join(', '); | ||
| Riga 188: | Riga 207: | ||
const raw = await r.text(); | const raw = await r.text(); | ||
if (!r.ok){ | if (!r.ok){ | ||
pending.remove(); | pending.remove(); | ||
| Riga 195: | Riga 213: | ||
} | } | ||
let j; | let j; | ||
try{ j = JSON.parse(raw); } | try{ j = JSON.parse(raw); } | ||
| Riga 208: | Riga 225: | ||
if (j.status === 'ok' && j.result){ | if (j.status === 'ok' && j.result){ | ||
// Rinomina la bozza alla prima risposta | // Rinomina la bozza alla prima risposta | ||
if (! | if (!currentProject && sessionMeta && sessionMeta.title === 'Nuova conversazione'){ | ||
sessionMeta.title = (content.slice(0,48) || 'Nuova conversazione'); | |||
saveSession && saveSession(); | saveSession && saveSession(); | ||
} | } | ||
| Riga 225: | Riga 242: | ||
} | } | ||
// | // esponi per test manuali e fai il binding una sola volta | ||
window.sendPrompt = sendPrompt; | |||
bindSendHandlersOnce(); | |||
</script> | </script> | ||
Versione delle 08:05, 28 set 2025
🔧 Dashboard Operativa – Masticationpedia
Centro di comando per progetti, API, file e backup