129 lines
8.0 KiB
JavaScript
129 lines
8.0 KiB
JavaScript
// BLADE IA UPGRADE v5 — Full Autonomy + Chips + Server Relay
|
|
// Inject after existing scripts
|
|
|
|
// ===== CHIPS BAR =====
|
|
(function injectChips(){
|
|
const bar=document.createElement('div');
|
|
bar.id='chips-bar';
|
|
bar.style.cssText='display:flex;gap:6px;flex-wrap:wrap;padding:8px 16px;background:#0f0a1f;border-bottom:1px solid #1e1040;overflow-x:auto';
|
|
const chips=[
|
|
['WEDROID','diagnostic WEDROID serveurs S204 S95','#22d3ee'],
|
|
['S204','status Docker et services S204','#4da6ff'],
|
|
['S95','status PMTA PostgreSQL Apache S95','#a78bfa'],
|
|
['S151','status OpenClaw Ollama S151','#f472b6'],
|
|
['NonReg','lance NonReg 148 tests','#00e09e'],
|
|
['Docker','liste containers Docker S204','#ffb547'],
|
|
['Deploy','deploy derniers changements git push','#4da6ff'],
|
|
['DB','check base PostgreSQL S95 send_contacts ethica','#a78bfa'],
|
|
['Disk','espace disque tous serveurs','#22d3ee'],
|
|
['Git','git status et derniers commits','#00e09e'],
|
|
['Ethica','stats Ethica HCP Maghreb','#f472b6'],
|
|
['Claw','status Claw Code skills 97','#ffb547'],
|
|
['Logs','derniers logs erreur nginx','#ff4d6a'],
|
|
['PMTA','status PMTA queues email S95','#a78bfa'],
|
|
['Ollama','models Ollama S204 et S151','#22d3ee'],
|
|
['Kill','arreter processus lourd','#ff4d6a'],
|
|
];
|
|
chips.forEach(([label,cmd,color])=>{
|
|
const c=document.createElement('span');
|
|
c.textContent=label;
|
|
c.style.cssText=`font-size:10px;padding:3px 8px;border-radius:6px;background:${color}15;color:${color};border:1px solid ${color}30;cursor:pointer;white-space:nowrap;user-select:none`;
|
|
c.onclick=()=>{document.getElementById('chat-in').value=cmd;sendChat()};
|
|
c.onmouseenter=()=>c.style.background=color+'30';
|
|
c.onmouseleave=()=>c.style.background=color+'15';
|
|
bar.appendChild(c);
|
|
});
|
|
const panel=document.getElementById('panel-ai');
|
|
if(panel)panel.insertBefore(bar,panel.firstChild);
|
|
})();
|
|
|
|
// ===== SERVER RELAY FUNCTIONS =====
|
|
async function cxRelay(cmd){
|
|
try{
|
|
const r=await fetch('/api/cx',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'k=WEVADS2026&c='+btoa(cmd)});
|
|
const d=await r.json();
|
|
return d.stdout||d.output||JSON.stringify(d);
|
|
}catch(e){return 'CX-ERR: '+e.message}
|
|
}
|
|
|
|
async function s95Relay(cmd){
|
|
try{
|
|
const r=await fetch('/api/cx',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'k=WEVADS2026&c='+btoa("curl -sk 'http://10.1.0.3:5890/api/sentinel-brain.php?action=exec&cmd="+encodeURIComponent(cmd)+"' 2>&1 | head -c 500")});
|
|
const d=await r.json();
|
|
if(d.stdout){try{const j=JSON.parse(d.stdout);return j.output||d.stdout}catch(e){return d.stdout}}
|
|
return d.stdout||'no output';
|
|
}catch(e){return 'S95-ERR: '+e.message}
|
|
}
|
|
|
|
async function s151Relay(cmd){
|
|
try{
|
|
const r=await fetch('/api/cx',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'k=WEVADS2026&c='+btoa("sshpass -p REDACTED_SSH ssh -o StrictHostKeyChecking=no ubuntu@151.80.235.110 '"+cmd+"' 2>&1 | head -c 500")});
|
|
const d=await r.json();
|
|
return d.stdout||'no output';
|
|
}catch(e){return 'S151-ERR: '+e.message}
|
|
}
|
|
|
|
// ===== EXTENDED INTENT PARSER =====
|
|
const _origParseIntent=window.parseIntent;
|
|
window.parseIntent=function(msg){
|
|
const m=msg.toLowerCase();
|
|
// Server commands
|
|
if(m.match(/s204.*docker|docker.*s204|containers/))return{type:'server',cmd:'s204',scmd:'docker ps --format "{{.Names}} {{.Status}}" | head -20',label:'Docker S204'};
|
|
if(m.match(/s204.*disk|disk.*s204/))return{type:'server',cmd:'s204',scmd:'df -h / | tail -1',label:'Disk S204'};
|
|
if(m.match(/s204.*status|status.*s204|diagnostic.*s204/))return{type:'server',cmd:'s204',scmd:'uptime && df -h / | tail -1 && docker ps | wc -l',label:'Status S204'};
|
|
if(m.match(/s95.*status|status.*s95|diagnostic.*s95/))return{type:'server',cmd:'s95',scmd:'uptime && systemctl is-active apache2 postgresql pmta',label:'Status S95'};
|
|
if(m.match(/s95.*pmta|pmta/))return{type:'server',cmd:'s95',scmd:'/opt/pmta/bin/pmta show counters | head -10',label:'PMTA Status'};
|
|
if(m.match(/s95.*db|db.*s95|postgresql|ethica.*stat/))return{type:'server',cmd:'s95',scmd:"PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -t -c \"SELECT 'send_contacts: '||count(*) FROM admin.send_contacts UNION ALL SELECT 'ethica: '||count(*) FROM ethica.medecins_real\"",label:'DB Stats'};
|
|
if(m.match(/s151.*status|status.*s151|openclaw/))return{type:'server',cmd:'s151',scmd:'docker ps --format "{{.Names}} {{.Status}}" && uptime',label:'Status S151'};
|
|
if(m.match(/nonreg|non.?reg|148/))return{type:'server',cmd:'s204',scmd:'curl -sk https://weval-consulting.com/api/nonreg-api.php?cat=all | python3 -c "import sys,json;d=json.load(sys.stdin);print(f\\"PASS: {d[\\"pass\\"]}/{d[\\"total\\"]}\\\\nScore: {d[\\"score\\"]}%\\")"',label:'NonReg Status'};
|
|
if(m.match(/git.*status|git.*log|dernier.*commit/))return{type:'server',cmd:'s204',scmd:'cd /var/www/html && git log --oneline -3',label:'Git Log'};
|
|
if(m.match(/deploy|push.*git/))return{type:'server',cmd:'s204',scmd:'cd /var/www/html && git add -A && git commit -m "blade-deploy" 2>/dev/null; git push github main 2>/dev/null; echo PUSHED',label:'Git Deploy'};
|
|
if(m.match(/nginx.*log|erreur.*log|log.*erreur/))return{type:'server',cmd:'s204',scmd:'sudo tail -5 /var/log/nginx/error.log | tr -cd "[:print:]\\n"',label:'Nginx Errors'};
|
|
if(m.match(/ollama.*model|model.*ollama/))return{type:'server',cmd:'s204',scmd:'curl -s http://127.0.0.1:11435/api/tags | python3 -c "import sys,json;[print(m[\\"name\\"]) for m in json.load(sys.stdin)[\\"models\\"]]"',label:'Ollama Models'};
|
|
if(m.match(/claw.*code|skill.*claw|97.*skill/))return{type:'server',cmd:'s204',scmd:'ls /opt/claw-code/weval-skills/*.gpt.md | wc -l && systemctl is-active claw-code',label:'Claw Code Status'};
|
|
if(m.match(/disk.*tous|tous.*disk|espace.*serveur/))return{type:'multi-server',cmd:'all-disk',label:'Disk All Servers'};
|
|
if(m.match(/wedroid|diagnostic.*serveur|status.*all/))return{type:'multi-server',cmd:'all-status',label:'WEDROID Diagnostic'};
|
|
// Fallback to original
|
|
if(typeof _origParseIntent==='function')return _origParseIntent(msg);
|
|
return null;
|
|
};
|
|
|
|
// ===== SERVER TASK EXECUTOR =====
|
|
const _origSendChat=window.sendChat;
|
|
window.sendChat=async function(){
|
|
const input=document.getElementById('chat-in');
|
|
const msg=input.value.trim();if(!msg)return;
|
|
// Check for server commands first
|
|
const intent=parseIntent(msg);
|
|
if(intent&&intent.type==='server'){
|
|
input.value='';
|
|
addChat('user',esc(msg));
|
|
addChat('ai','<div style="color:var(--cyan);font-size:11px">Execution sur '+intent.cmd.toUpperCase()+'...</div>');
|
|
let result='';
|
|
if(intent.cmd==='s204')result=await cxRelay(intent.scmd);
|
|
else if(intent.cmd==='s95')result=await s95Relay(intent.scmd);
|
|
else if(intent.cmd==='s151')result=await s151Relay(intent.scmd);
|
|
addChat('ai','<div style="color:var(--green);font-size:11px;margin-bottom:4px">'+intent.label+' ['+intent.cmd.toUpperCase()+']</div><div class="task-result">'+esc(result)+'</div>');
|
|
return;
|
|
}
|
|
if(intent&&intent.type==='multi-server'){
|
|
input.value='';
|
|
addChat('user',esc(msg));
|
|
addChat('ai','<div style="color:var(--cyan);font-size:11px">Scan multi-serveurs...</div>');
|
|
if(intent.cmd==='all-disk'){
|
|
const[r1,r2]=await Promise.all([cxRelay('df -h / | tail -1'),s95Relay('df -h / | tail -1')]);
|
|
addChat('ai','<div style="color:var(--green);font-size:11px">Disk Usage</div><div class="task-result">S204: '+esc(r1)+'\nS95: '+esc(r2)+'</div>');
|
|
}else if(intent.cmd==='all-status'){
|
|
const[r1,r2]=await Promise.all([
|
|
cxRelay('echo "Docker: $(docker ps | wc -l) | Disk: $(df -h / | tail -1 | awk \'{print $5}\') | Load: $(uptime | grep -o \'load.*\')"'),
|
|
s95Relay('echo "Apache: $(systemctl is-active apache2) | PG: $(systemctl is-active postgresql) | PMTA: $(systemctl is-active pmta)"')
|
|
]);
|
|
addChat('ai','<div style="color:var(--green);font-size:11px">WEDROID Diagnostic</div><div class="task-result">S204: '+esc(r1)+'\nS95: '+esc(r2)+'</div>');
|
|
}
|
|
return;
|
|
}
|
|
// Fallback to original sendChat
|
|
return _origSendChat.call(this);
|
|
};
|
|
console.log('BLADE-UPGRADE-v5 loaded: chips+relay+autonomy');
|