Files
html/api/wevia-orchestrator-v2.php
2026-04-14 10:36:17 +02:00

32 lines
2.9 KiB
PHP

<?php
header("Content-Type:application/json");
set_time_limit(45);
$task=json_decode($_SERVER["WEVIA_RAW"] ?? file_get_contents("php://input"),true)["message"] ?? $_GET["msg"] ?? "";
if(!trim($task)){echo json_encode(["error"=>"task required"]);exit;}
$start=microtime(true);
$agents=[
"infra"=>"echo LOAD:$(cat /proc/loadavg|cut -d' ' -f1-3) DISK:$(df -h /|tail -1|awk '{print $5}') FPM:$(ps aux|grep 'php-fpm.*pool'|grep -c www) HTML:$(ls /var/www/html/*.html|wc -l)",
"sovereign"=>"curl -s --max-time 3 http://127.0.0.1:4000/health 2>/dev/null|python3 -c 'import json,sys;d=json.load(sys.stdin);print(d[\"active\"],\"providers\")' 2>/dev/null||echo DOWN",
"nonreg"=>"php8.4 /var/www/html/api/nonreg-quick.php 2>&1",
"git"=>"cd /var/www/html;echo DIRTY:$(git status --short|wc -l);git log --oneline -2",
"ethica"=>"timeout 5 ssh -p 49222 -o ConnectTimeout=3 -o StrictHostKeyChecking=no -i /var/www/.ssh/wevads_key root@10.1.0.3 \"PGPASSWORD=admin123 psql -U admin -d adx_system -t -c \\\"SELECT pays,count(*) FROM ethica.medecins_validated GROUP BY pays ORDER BY count DESC\\\"\" 2>/dev/null||echo DB-TIMEOUT",
"vault"=>"echo VAULT:$(ls /opt/wevads/vault/|wc -l) WIKI:$(ls /opt/weval-l99/wiki/*.json|wc -l)",
"scraper"=>"pgrep -af scraper 2>/dev/null | grep -v pgrep | wc -l",
"crons"=>"echo ROOT_CRONS:$(crontab -l 2>/dev/null|grep -cv ^#)",
"s95"=>"timeout 3 ssh -p 49222 -o ConnectTimeout=2 -o StrictHostKeyChecking=no -i /var/www/.ssh/wevads_key root@10.1.0.3 uptime 2>/dev/null||echo UNREACHABLE",
"security"=>"echo CROWDSEC:$(systemctl is-active crowdsec) OLLAMA:$(systemctl is-active ollama)",
"paperclip"=>"curl -sk --max-time 2 https://paperclip.weval-consulting.com/ -o /dev/null && echo UP || echo DOWN",
"mirofish"=>"curl -sk --max-time 2 https://mirofish.weval-consulting.com/ -o /dev/null && echo UP || echo DOWN",
"docker"=>"echo CONTAINERS:$(docker ps --format x|wc -l)",
];
$results=[];
foreach($agents as $id=>$cmd){$results[$id]=trim(@shell_exec("timeout 8 bash -c ".escapeshellarg($cmd)." 2>&1"))?:"TIMEOUT";}
$llm=null;
$ch=curl_init("http://127.0.0.1:4000/v1/chat/completions");
$prompt="TASK: $task\nRESULTS:\n".json_encode($results,JSON_UNESCAPED_UNICODE)."\nSynthesize: what works, issues, actions. Max 8 lines.";
curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>1,CURLOPT_POST=>1,CURLOPT_TIMEOUT=>10,CURLOPT_HTTPHEADER=>["Content-Type: application/json"],CURLOPT_POSTFIELDS=>json_encode(["model"=>"auto","messages"=>[["role"=>"system","content"=>"WEVIA Director. Rapport executif."],["role"=>"user","content"=>$prompt]],"max_tokens"=>300])]);
$r=curl_exec($ch);curl_close($ch);
$d=@json_decode($r,true);
$llm=$d["choices"][0]["message"]["content"] ?? null;
echo json_encode(["ok"=>true,"mode"=>"orchestrator-v2","task"=>$task,"agents"=>count($results),"results"=>$results,"synthesis"=>$llm,"duration_ms"=>round((microtime(true)-$start)*1000),"ts"=>date("H:i:s")],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);