208 lines
8.7 KiB
PHP
208 lines
8.7 KiB
PHP
<?php
|
|
// V71 Extra Orchestrator Agents - extends the 16 hardcoded agents
|
|
// Called by wevia_extended_bilan resolver OR as separate endpoint
|
|
// Returns results for domain-specific agents NOT in the hardcoded $__orch_registry
|
|
header("Content-Type: application/json");
|
|
|
|
$action = $_REQUEST["action"] ?? "list";
|
|
$limit = intval($_REQUEST["limit"] ?? 20);
|
|
|
|
function run_agent($cmd, $timeout = 10) {
|
|
$out = @shell_exec("timeout " . intval($timeout) . " " . $cmd . " 2>&1");
|
|
return trim($out ?: "timeout");
|
|
}
|
|
|
|
$AGENTS = [
|
|
"reg70_scores" => [
|
|
"keywords" => ["test","regression","reg67","reg68","reg69","reg70","score","quality","anti","lean","sigma","6sigma"],
|
|
"fn" => function() {
|
|
$result = [];
|
|
foreach (["","-reg67","-reg68","-reg69","-reg70"] as $suffix) {
|
|
$file = "/var/www/html/api/nonreg" . $suffix . "-latest.json";
|
|
if (file_exists($file)) {
|
|
$d = json_decode(file_get_contents($file), true);
|
|
$name = $suffix ? strtoupper(substr($suffix,1)) : "NonReg";
|
|
$result[$name] = [
|
|
"pass" => $d["pass"] ?? 0,
|
|
"total" => $d["total"] ?? 0,
|
|
"score" => $d["score"] ?? 0
|
|
];
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
],
|
|
"agent_factory_status" => [
|
|
"keywords" => ["agent","factory","gap","missing","erp","stripe","invoice","sap","finance","kpi","45"],
|
|
"fn" => function() {
|
|
$out = run_agent("curl -sk --max-time 5 'http://127.0.0.1/api/wevia-agent-factory.php?action=count' -H 'Host: weval-consulting.com'", 8);
|
|
return json_decode($out, true) ?: ["raw" => $out];
|
|
}
|
|
],
|
|
"skills_total" => [
|
|
"keywords" => ["skill","competence","capability","oss","dormant","inject"],
|
|
"fn" => function() {
|
|
$out = run_agent("curl -sk --max-time 5 'http://127.0.0.1/api/oss-discovery.php?k=WEVADS2026&action=skills' -H 'Host: weval-consulting.com'", 8);
|
|
$d = json_decode($out, true);
|
|
return [
|
|
"total" => $d["total"] ?? 0,
|
|
"active" => $d["active"] ?? $d["total"] ?? 0,
|
|
"dormant" => $d["dormant"] ?? 0
|
|
];
|
|
}
|
|
],
|
|
"departments_kpi" => [
|
|
"keywords" => ["dept","department","finance","controlling","sales","marketing","hr","supply","operations","production","rh","commerce"],
|
|
"fn" => function() {
|
|
$file = "/var/www/html/api/wevia-v64-departments-kpi.php";
|
|
if (!is_readable($file)) return ["error" => "not readable"];
|
|
$c = file_get_contents($file);
|
|
preg_match_all("/'id'\s*=>\s*'([^']+)'/", $c, $m);
|
|
$depts = array_unique($m[1] ?? []);
|
|
preg_match_all("/'gap_agent'\s*=>\s*'([^']+)'/", $c, $m2);
|
|
$gaps = array_unique($m2[1] ?? []);
|
|
return ["departments" => count($depts), "gap_agents" => count($gaps), "depts_list" => $depts];
|
|
}
|
|
],
|
|
"qdrant_collections" => [
|
|
"keywords" => ["qdrant","rag","kb","knowledge","vector","embedding"],
|
|
"fn" => function() {
|
|
$out = run_agent("curl -sk --max-time 5 http://127.0.0.1:6333/collections", 8);
|
|
$d = json_decode($out, true);
|
|
$cols = $d["result"]["collections"] ?? [];
|
|
return ["count" => count($cols), "names" => array_column($cols, "name")];
|
|
}
|
|
],
|
|
"partnerships_status" => [
|
|
"keywords" => ["partner","partnership","vistex","huawei","sap","scaleway"],
|
|
"fn" => function() {
|
|
return [
|
|
"SAP" => "Partenaire Ecosysteme",
|
|
"Huawei Cloud" => "Active",
|
|
"Scaleway" => "Active",
|
|
"Vistex" => "Contested (Olga/Joe/Udo)"
|
|
];
|
|
}
|
|
],
|
|
"secrets_health" => [
|
|
"keywords" => ["secret","key","token","credential","api","provider","llm"],
|
|
"fn" => function() {
|
|
if (!is_readable("/etc/weval/secrets.env")) return ["error" => "not readable"];
|
|
$c = @file_get_contents("/etc/weval/secrets.env");
|
|
$total = preg_match_all("/^[A-Z_]+=/m", $c);
|
|
preg_match_all("/^(CEREBRAS|GROQ|MISTRAL|DEEPSEEK|SAMBANOVA|NVIDIA|OPENROUTER|ANTHROPIC|GEMINI|HF_|COHERE|TOGETHER|ALIBABA|ZHIPU)[A-Z_]*=/m", $c, $m);
|
|
return ["total_secrets" => $total, "llm_providers" => count(array_unique($m[1] ?? []))];
|
|
}
|
|
],
|
|
"ethica_detailed" => [
|
|
"keywords" => ["ethica","hcp","healthcare","pharma","medecin","doctor","pharmacien"],
|
|
"fn" => function() {
|
|
$out = run_agent("curl -sk --max-time 6 'http://127.0.0.1/api/ethica-stats-api.php' -H 'Host: weval-consulting.com'", 8);
|
|
return json_decode($out, true) ?: ["raw" => $out];
|
|
}
|
|
],
|
|
"registry_metadata" => [
|
|
"keywords" => ["registry","tool","resolver","intent","wevia"],
|
|
"fn" => function() {
|
|
$file = "/var/www/html/api/wevia-tool-registry.json";
|
|
if (!is_readable($file)) return ["error" => "not readable"];
|
|
$d = json_decode(@file_get_contents($file), true);
|
|
$tools = $d["tools"] ?? $d ?? [];
|
|
$stats = ["total" => count($tools), "agent_tools" => 0, "reg_tools" => 0, "orchestrator_tools" => 0];
|
|
foreach ($tools as $t) {
|
|
$id = $t["id"] ?? "";
|
|
if (strpos($id, "agent_") === 0) $stats["agent_tools"]++;
|
|
if (strpos($id, "reg") === 0) $stats["reg_tools"]++;
|
|
if (strpos($id, "orchestrator") !== false) $stats["orchestrator_tools"]++;
|
|
}
|
|
return $stats;
|
|
}
|
|
],
|
|
"plan_action_meta" => [
|
|
"keywords" => ["plan","action","vault","session","doctrine","wiki"],
|
|
"fn" => function() {
|
|
$plan = "/opt/wevads/vault/plan-action-dp.md";
|
|
$lines = is_readable($plan) ? count(file($plan)) : 0;
|
|
$sessions = count(glob("/opt/wevads/vault/session-*.md") ?: []);
|
|
$doctrines = count(glob("/opt/obsidian-vault/doctrines/*") ?: []);
|
|
$wiki = count(glob("/var/www/html/wiki/V*.md") ?: []);
|
|
return ["plan_lines" => $lines, "sessions" => $sessions, "doctrines" => $doctrines, "wiki_v" => $wiki];
|
|
}
|
|
]
|
|
];
|
|
|
|
if ($action === "list") {
|
|
$result = [];
|
|
foreach ($AGENTS as $name => $spec) {
|
|
$result[] = ["name" => $name, "keywords" => $spec["keywords"]];
|
|
}
|
|
echo json_encode(["ok" => true, "total" => count($AGENTS), "agents" => $result], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
if ($action === "run") {
|
|
$name = $_REQUEST["agent"] ?? "";
|
|
if (!isset($AGENTS[$name])) {
|
|
echo json_encode(["ok" => false, "error" => "unknown agent: $name", "available" => array_keys($AGENTS)]);
|
|
exit;
|
|
}
|
|
$result = ($AGENTS[$name]["fn"])();
|
|
echo json_encode(["ok" => true, "agent" => $name, "result" => $result], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
if ($action === "multi") {
|
|
// Smart: accept message, match keywords, fire relevant agents
|
|
$msg = strtolower($_REQUEST["message"] ?? "");
|
|
$max = min($limit, 20);
|
|
$fired = [];
|
|
foreach ($AGENTS as $name => $spec) {
|
|
foreach ($spec["keywords"] as $kw) {
|
|
if (strpos($msg, $kw) !== false) {
|
|
$t0 = microtime(true);
|
|
$result = ($spec["fn"])();
|
|
$ms = round((microtime(true) - $t0) * 1000);
|
|
$fired[$name] = ["result" => $result, "ms" => $ms, "matched_kw" => $kw];
|
|
break;
|
|
}
|
|
}
|
|
if (count($fired) >= $max) break;
|
|
}
|
|
|
|
// If nothing matched, fire default set: reg70_scores + skills_total + plan_action_meta
|
|
if (empty($fired)) {
|
|
foreach (["reg70_scores", "skills_total", "plan_action_meta"] as $name) {
|
|
$result = ($AGENTS[$name]["fn"])();
|
|
$fired[$name] = ["result" => $result, "default" => true];
|
|
}
|
|
}
|
|
|
|
echo json_encode([
|
|
"ok" => true,
|
|
"message" => $msg,
|
|
"fired_count" => count($fired),
|
|
"max_limit" => $max,
|
|
"agents" => $fired
|
|
], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
if ($action === "all") {
|
|
// Fire ALL agents regardless of keywords
|
|
$result = [];
|
|
foreach ($AGENTS as $name => $spec) {
|
|
$t0 = microtime(true);
|
|
try {
|
|
$data = ($spec["fn"])();
|
|
$ms = round((microtime(true) - $t0) * 1000);
|
|
$result[$name] = ["result" => $data, "ms" => $ms];
|
|
} catch (Exception $e) {
|
|
$result[$name] = ["error" => $e->getMessage()];
|
|
}
|
|
}
|
|
echo json_encode(["ok" => true, "total_agents" => count($result), "agents" => $result], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode(["ok" => false, "error" => "unknown action", "valid" => ["list","run","multi","all"]]);
|