90 lines
5.4 KiB
PHP
90 lines
5.4 KiB
PHP
<?php
|
|
require_once __DIR__."/wevia-smart-router.php";
|
|
require_once __DIR__."/wevia-dynamic-resolver.php";
|
|
|
|
function wevia_orchestrate($q) {
|
|
$q_lower = mb_strtolower(trim($q));
|
|
$start = microtime(true);
|
|
$is_multi = preg_match("/(multi.?agent|orchestre|mobilise|coordonne|tout finir|rapport|reconcile|6sigma|full scan)/i", $q_lower);
|
|
if (!$is_multi) {
|
|
$r = wevia_resolve($q);
|
|
if ($r) return ["ok"=>true,"mode"=>"resolver","tool"=>$r["tool"],"content"=>$r["content"],"ms"=>round((microtime(true)-$start)*1000)];
|
|
$llm = _sovereign_synth($q);
|
|
return ["ok"=>true,"mode"=>"llm","content"=>$llm,"ms"=>round((microtime(true)-$start)*1000)];
|
|
}
|
|
$results = [];
|
|
|
|
// 1. INFRA
|
|
$results["infra"] = trim(shell_exec("echo \"LOAD:\$(cat /proc/loadavg|cut -d' ' -f1-3) DISK:\$(df -h /|tail -1|awk '{print \$5}') FPM:\$(pgrep -c php-fpm) HTML:\$(ls /var/www/html/*.html|wc -l)\" 2>/dev/null"));
|
|
|
|
// 2. SOVEREIGN
|
|
$sr = @json_decode(@file_get_contents("http://127.0.0.1:4000/health"), true);
|
|
$results["sovereign"] = ($sr["active"] ?? "?") . " providers (" . ($sr["primary"] ?? "?") . ")";
|
|
|
|
// 3. NONREG
|
|
$nr = @json_decode(@file_get_contents("/var/www/html/api/nonreg-latest.json"), true);
|
|
$results["nonreg"] = "NONREG: " . ($nr["pass"]??"?") . "/" . ($nr["total"]??"?") . " (" . ($nr["score"]??"?") . "%)";
|
|
|
|
// 4. ETHICA
|
|
$results["ethica"] = trim(shell_exec("psql -U postgres -d ethica -t -c \"SELECT country, count(*) FROM medecins_validated GROUP BY country ORDER BY count DESC LIMIT 5\" 2>/dev/null")) ?: "CHECK";
|
|
|
|
// 5. GIT
|
|
$results["git"] = trim(shell_exec("cd /var/www/html && echo \"DIRTY:\$(git status -s|wc -l)\" && git log --oneline -2 2>/dev/null"));
|
|
|
|
// 6. VAULT
|
|
$results["vault"] = "VAULT:" . trim(shell_exec("ls /opt/wevads/vault/* 2>/dev/null|wc -l")) . " WIKI:" . trim(shell_exec("ls /opt/weval-l99/wiki/*.json 2>/dev/null|wc -l")) . " GOLD:" . trim(shell_exec("find /opt/wevads/vault -name '*.gold' 2>/dev/null|wc -l"));
|
|
|
|
// 7. DOCKER
|
|
$results["docker"] = trim(shell_exec("docker ps --format '{{.Names}}:{{.Status}}'|head -12 2>/dev/null"));
|
|
|
|
// 8. CRONS
|
|
$results["crons"] = "S204:" . trim(shell_exec("crontab -l 2>/dev/null|grep -v ^#|grep -v '^$'|wc -l")) . " S95:" . trim(shell_exec("ssh -p 49222 -i /var/www/.ssh/wevads_key -o ConnectTimeout=3 -o StrictHostKeyChecking=no root@10.1.0.3 'crontab -l 2>/dev/null|grep -v ^#|grep -v \"^\\$\"|wc -l' 2>/dev/null") ?: "?");
|
|
|
|
// 9. REGISTRY
|
|
$reg = @json_decode(@file_get_contents("/var/www/html/api/wevia-tool-registry.json"), true);
|
|
$wcmd = 0; foreach(($reg["tools"]??[]) as $t) if(!empty($t["cmd"])) $wcmd++;
|
|
$results["registry"] = ($reg["count"]??"?") . " tools (" . $wcmd . " exec)";
|
|
|
|
// 10. PAGES
|
|
$pages = ["blade-ai","wevia-orchestrator","wevia-cortex","paperclip","agents-archi","enterprise-model","wevia-meeting-rooms","growth-engine-v2","weval-arena","sovereign-claude","ethica-hub","admin"];
|
|
$up=0;$down=[];
|
|
foreach($pages as $p){$c=trim(shell_exec("curl -sk -o /dev/null -w '%{http_code}' 'https://127.0.0.1/$p.html' 2>/dev/null"));if($c=="200"||$c=="302")$up++;else $down[]="$p:$c";}
|
|
$results["pages"] = "$up/".count($pages)." UP".($down?" DOWN:".implode(",",$down):"");
|
|
|
|
// 11. SCRAPER
|
|
$results["scraper"] = trim(shell_exec("pgrep -f 'playwright|scrapy|scraper' 2>/dev/null|wc -l")) . " scrapers";
|
|
|
|
// 12. OLLAMA
|
|
$results["ollama"] = trim(shell_exec("pgrep ollama 2>/dev/null|wc -l")) . " (must be 0)";
|
|
|
|
// 13. RESOLVER
|
|
$rpass=0;foreach(["reconcile tout","ethica status","fix nginx"] as $rt){if(wevia_resolve($rt))$rpass++;}
|
|
$results["resolver"] = "$rpass/3 intents OK";
|
|
|
|
// 14. ARENA
|
|
$results["arena"] = trim(shell_exec("curl -sf http://127.0.0.1:4000/health -o /dev/null -w '%{http_code}' 2>/dev/null"))=="200" ? "LIVE" : "CHECK";
|
|
|
|
// 15. BLADE
|
|
$results["blade"] = trim(shell_exec("curl -sk -o /dev/null -w '%{http_code}' 'https://127.0.0.1/blade-ai.html' 2>/dev/null"));
|
|
|
|
// SYNTHESIS via LLM
|
|
$synthesis = _sovereign_synth("Tu es WEVIA Master, cerveau autonome de WEVAL Consulting. " . count($results) . " agents ont rapporte:\n" . json_encode($results, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE) . "\n\nRapport executif en francais: ce qui marche, problemes, actions. Concis, 10 lignes max.");
|
|
|
|
return [
|
|
"ok" => true,
|
|
"mode" => "orchestrator-v3",
|
|
"task" => $q,
|
|
"agents" => count($results),
|
|
"results" => $results,
|
|
"synthesis" => $synthesis,
|
|
"ecosystem" => ["pages"=>169,"apis"=>427,"tools"=>$reg["count"]??346,"tools_exec"=>$wcmd,"wiki"=>1194,"vault"=>1181,"providers"=>$sr["active"]??12],
|
|
"ms" => round((microtime(true)-$start)*1000)
|
|
];
|
|
}
|
|
|
|
$msg = $_GET["msg"] ?? "";
|
|
if ($msg) { header("Content-Type: application/json"); echo " "; flush(); ob_flush(); }
|
|
if ($msg) { echo chr(10).json_encode(wevia_orchestrate($msg), JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE); }
|
|
|
|
function _sovereign_synth($q){$ch=curl_init("http://127.0.0.1:4000/v1/chat/completions");curl_setopt_array($ch,[CURLOPT_POST=>1,CURLOPT_POSTFIELDS=>json_encode(["model"=>"auto","messages"=>[["role"=>"system","content"=>"WEVIA Master. Francais. Concis."],["role"=>"user","content"=>$q]],"max_tokens"=>500]),CURLOPT_RETURNTRANSFER=>1,CURLOPT_TIMEOUT=>10,CURLOPT_HTTPHEADER=>["Content-Type:application/json"]]);$r=@json_decode(curl_exec($ch),true);curl_close($ch);return $r["choices"][0]["message"]["content"]??null;}
|