Consolidate Maria control into the shared Discord-bridge dashboard
Drop the standalone maria-dashboard.service — one common panel now controls both bridges, at the operator's request. discord-bridge's dashboard/api.py gains a Maria section (fixed-unit start/stop/restart for maria-whatsapp/maria-rag, WhatsApp status+QR proxy, document CRUD, reindex, Drive sync trigger, log tail) reached via subprocess/HTTP — no cross-module imports, to avoid colliding with discord-bridge's own `config` module name. index.html gets a matching "Maria — WhatsApp + RAG" section. maria-whatsapp-bridge loses its dashboard/ folder and DASHBOARD_* env keys; install.sh/README point at the shared panel. Co-Authored-By: Claude Agent <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,70 @@
|
||||
<pre class="log" id="log">se încarcă…</pre>
|
||||
</section>
|
||||
|
||||
<!-- ── Maria: WhatsApp + RAG ──────────────────────────────── -->
|
||||
<h2 style="margin-top:var(--space-6)">Maria — WhatsApp + RAG</h2>
|
||||
|
||||
<div class="grid-2">
|
||||
<section class="card">
|
||||
<h2>Punte WhatsApp <span class="count" id="mBridgeUnit"></span></h2>
|
||||
<div class="metrics" id="mBridgeMetrics"></div>
|
||||
<div class="actions" style="margin-top:var(--space-5)">
|
||||
<button onclick="mSvc('bridge','start')">Pornește</button>
|
||||
<button class="danger" onclick="mSvc('bridge','stop')">Oprește</button>
|
||||
<button class="primary" onclick="mSvc('bridge','restart')">Repornește</button>
|
||||
</div>
|
||||
</section>
|
||||
<section class="card">
|
||||
<h2>Consumer RAG <span class="count" id="mRagUnit"></span></h2>
|
||||
<div class="metrics" id="mRagMetrics"></div>
|
||||
<div class="actions" style="margin-top:var(--space-5)">
|
||||
<button onclick="mSvc('rag','start')">Pornește</button>
|
||||
<button class="danger" onclick="mSvc('rag','stop')">Oprește</button>
|
||||
<button class="primary" onclick="mSvc('rag','restart')">Repornește</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="card">
|
||||
<h2>Conectare WhatsApp</h2>
|
||||
<div id="mWaStatus" class="empty">se încarcă…</div>
|
||||
<div id="mWaQr"></div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Documente indexate <span class="count" id="mDocCount"></span></h2>
|
||||
<div class="detail" id="mIndexDetail"></div>
|
||||
<div class="detail" id="mSyncDetail"></div>
|
||||
<div class="actions" style="margin:var(--space-5) 0">
|
||||
<button onclick="mReindex()">Reconstruiește indexul</button>
|
||||
<button onclick="mSyncNow()">Sincronizează din Drive acum</button>
|
||||
</div>
|
||||
<div class="table-scroll">
|
||||
<table class="stack-mobil">
|
||||
<thead><tr><th>Nume</th><th class="num">Mărime</th><th></th></tr></thead>
|
||||
<tbody id="mDocs"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h2 style="margin-top:var(--space-5)">Adaugă document (.txt / .md)</h2>
|
||||
<input type="text" id="mDocName" placeholder="ex: politica-retururi.md" style="width:100%;margin-bottom:var(--space-3)">
|
||||
<textarea id="mDocContent" placeholder="conținutul documentului..." style="width:100%;min-height:120px;font-family:monospace"></textarea>
|
||||
<div class="actions" style="margin-top:var(--space-3)">
|
||||
<button class="primary" onclick="mAddDoc()">Salvează și reindexează</button>
|
||||
</div>
|
||||
<div class="detail" id="mDocMsg"></div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Jurnal Maria
|
||||
<span class="count">
|
||||
<button class="small" id="mTabBridge" onclick="mSetLog('bridge')">whatsapp.log</button>
|
||||
<button class="small" id="mTabRag" onclick="mSetLog('rag')">rag.log</button>
|
||||
<button class="small" onclick="mRefreshLogs()">↻</button>
|
||||
</span>
|
||||
</h2>
|
||||
<pre class="log" id="mLog">se încarcă…</pre>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="toast"></div>
|
||||
@@ -274,10 +338,125 @@ async function refreshLogs() {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
|
||||
// ── Maria: WhatsApp + RAG ───────────────────────────────────────
|
||||
var mBusy = false;
|
||||
function mMetricsHtml(info) {
|
||||
return [
|
||||
['Stare', '<span class="pill ' + (info.active ? 'ok' : 'bad') + '">' + esc(info.state) + '/' + esc(info.sub) + '</span>'],
|
||||
['Uptime', dur(info.uptime_s)],
|
||||
['PID', info.pid || '—'],
|
||||
['Restarturi', info.restarts]
|
||||
].map(function (m) {
|
||||
return '<div class="metric"><div class="label">' + m[0] + '</div><div class="value">' + m[1] + '</div></div>';
|
||||
}).join('');
|
||||
}
|
||||
|
||||
async function mRefresh() {
|
||||
var res = await api('api/maria/status');
|
||||
if (!res.ok) return;
|
||||
var s = res.data;
|
||||
|
||||
document.getElementById('mBridgeUnit').textContent = s.bridge.unit;
|
||||
document.getElementById('mBridgeMetrics').innerHTML = mMetricsHtml(s.bridge);
|
||||
document.getElementById('mRagUnit').textContent = s.rag.unit;
|
||||
document.getElementById('mRagMetrics').innerHTML = mMetricsHtml(s.rag);
|
||||
|
||||
var wa = s.whatsapp || {};
|
||||
var waStatus = document.getElementById('mWaStatus');
|
||||
var waQr = document.getElementById('mWaQr');
|
||||
if (wa.connected) {
|
||||
waStatus.innerHTML = '<span class="pill ok">conectat</span> ca ' + esc(wa.phone || '?');
|
||||
waQr.innerHTML = '';
|
||||
} else if (wa.qr) {
|
||||
waStatus.innerHTML = '<span class="pill bad">neconectat</span> — scanează codul QR din WhatsApp → Dispozitive conectate';
|
||||
waQr.innerHTML = '<img src="' + wa.qr + '" style="width:220px;height:220px;border-radius:8px;background:#fff;padding:8px;margin-top:var(--space-4)">';
|
||||
} else {
|
||||
waStatus.innerHTML = '<span class="pill bad">' + (wa.reachable === false ? 'puntea nu rulează' : 'aștept codul QR…') + '</span>';
|
||||
waQr.innerHTML = '';
|
||||
}
|
||||
|
||||
document.getElementById('mIndexDetail').textContent =
|
||||
s.index.chunks + ' chunk-uri din ' + s.index.documents_indexed + ' documente indexate' +
|
||||
(s.index.mtime ? ' · indexat ' + new Date(s.index.mtime * 1000).toLocaleString('ro-RO') : '');
|
||||
document.getElementById('mDocCount').textContent = s.documents + ' în depozit';
|
||||
|
||||
var sync = s.sync || {};
|
||||
document.getElementById('mSyncDetail').textContent = sync.drive_remote
|
||||
? 'Drive: ' + sync.drive_remote + (sync.synced_at ? ' · ultima sincronizare ' + new Date(sync.synced_at * 1000).toLocaleString('ro-RO') : ' · încă nesincronizat')
|
||||
: 'Sincronizare Drive dezactivată (DRIVE_REMOTE nesetat) — doar upload manual';
|
||||
|
||||
var docsRes = await api('api/maria/documents');
|
||||
var docs = docsRes.ok ? (docsRes.data.documents || []) : [];
|
||||
document.getElementById('mDocs').innerHTML = docs.length ? docs.map(function (d) {
|
||||
return '<tr><td data-label="Nume" class="mono">' + esc(d.name) + '</td>' +
|
||||
'<td data-label="Mărime" class="num">' + d.size + ' B</td>' +
|
||||
'<td><button class="small danger" onclick="mDelDoc(\'' + esc(d.name) + '\')">Șterge</button></td></tr>';
|
||||
}).join('') : '<tr><td colspan="3" class="empty" data-label="">niciun document</td></tr>';
|
||||
}
|
||||
|
||||
async function mSvc(which, action) {
|
||||
if (mBusy) return;
|
||||
if (action !== 'start' && !confirm('Sigur „' + action + '” pe ' + which + '?')) return;
|
||||
mBusy = true;
|
||||
try {
|
||||
var res = await post('api/maria/service', { service: which, action: action });
|
||||
toast(res.ok ? 'Maria ' + which + ': ' + action + ' OK' : ('Eșuat: ' + (res.data.error || res.status)), res.ok ? 'ok' : 'bad');
|
||||
} finally {
|
||||
mBusy = false;
|
||||
mRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
async function mReindex() {
|
||||
var res = await post('api/maria/reindex', {});
|
||||
toast(res.ok && res.data.ok ? 'Index reconstruit' : ('Eșuat: ' + (res.data.error || res.data.stderr || res.status)), res.ok && res.data.ok ? 'ok' : 'bad');
|
||||
mRefresh();
|
||||
}
|
||||
|
||||
async function mSyncNow() {
|
||||
var res = await post('api/maria/sync', { force: true });
|
||||
toast(res.ok && res.data.ok ? 'Sincronizat' : ('Eșuat: ' + (res.data.error || res.data.stderr || res.status)), res.ok && res.data.ok ? 'ok' : 'bad');
|
||||
mRefresh();
|
||||
}
|
||||
|
||||
async function mAddDoc() {
|
||||
var name = document.getElementById('mDocName').value.trim();
|
||||
var content = document.getElementById('mDocContent').value;
|
||||
var msg = document.getElementById('mDocMsg');
|
||||
if (!name || !content) { msg.textContent = 'completează numele și conținutul'; return; }
|
||||
var res = await post('api/maria/documents', { name: name, content: content });
|
||||
if (!res.ok) { msg.textContent = 'eșuat: ' + (res.data.error || res.status); return; }
|
||||
msg.textContent = 'salvat, reindexez…';
|
||||
var ri = await post('api/maria/reindex', {});
|
||||
msg.textContent = ri.ok && ri.data.ok ? 'salvat și reindexat' : ('salvat, reindexarea a eșuat: ' + (ri.data.error || ri.data.stderr || ''));
|
||||
document.getElementById('mDocContent').value = '';
|
||||
mRefresh();
|
||||
}
|
||||
|
||||
async function mDelDoc(name) {
|
||||
if (!confirm('Ștergi ' + name + '?')) return;
|
||||
await post('api/maria/documents/delete', { name: name });
|
||||
await mReindex();
|
||||
}
|
||||
|
||||
var mLogFile = 'bridge';
|
||||
function mSetLog(which) { mLogFile = which; mRefreshLogs(); }
|
||||
async function mRefreshLogs() {
|
||||
document.getElementById('mTabBridge').className = 'small' + (mLogFile === 'bridge' ? ' primary' : '');
|
||||
document.getElementById('mTabRag').className = 'small' + (mLogFile === 'rag' ? ' primary' : '');
|
||||
var res = await api('api/maria/logs?lines=300&service=' + mLogFile);
|
||||
if (!res.ok) return;
|
||||
var el = document.getElementById('mLog');
|
||||
el.textContent = (res.data.lines || []).join('\n') || '(gol)';
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
|
||||
// ── pornire ───────────────────────────────────────────────────
|
||||
refresh(); refreshDoctor(); refreshLogs();
|
||||
mRefresh(); mRefreshLogs();
|
||||
setInterval(refresh, 5000);
|
||||
setInterval(refreshDoctor, 30000);
|
||||
setInterval(mRefresh, 4000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user