Files
wevia-brain/wevia-dynamic-resolver.php
Yanis Mahboub 6a680d2ea2 Wave 114 auto
2026-04-13 04:36:15 +02:00

54 lines
2.7 KiB
PHP

<?php
// WEVIA Dynamic Tool Resolver — auto-matches tools from registry
// No more hardcoded intents needed. Just add tools to wevia-tool-registry.json
function wevia_dynamic_resolve($msg) {
$reg = @json_decode(@file_get_contents("/opt/wevia-brain/tool-registry-v2.json"), true);
if (!$reg || empty($reg["tools"])) return null;
foreach ($reg["tools"] as $t) {
if (!@preg_match("/" . $t["kw"] . "/i", $msg)) continue;
// Match found — execute
if ($t["api"] === "master") {
$ch = curl_init("https://weval-consulting.com/api/wevia-master-api.php");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(["message" => $t["msg"]]),
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_TIMEOUT => 20, CURLOPT_SSL_VERIFYPEER => false
]);
$r = curl_exec($ch);
$d = @json_decode($r, true);
if ($d && strlen($d["content"] ?? "") > 10) {
return ["content" => $d["content"], "tool" => $t["id"], "source" => "dynamic-resolver"];
}
} elseif (strpos($t["api"], "GET:") === 0) {
$url = "https://weval-consulting.com" . substr($t["api"], 4);
$ctx = stream_context_create(["ssl" => ["verify_peer" => false], "http" => ["timeout" => 12]]);
$r = @file_get_contents($url, false, $ctx);
$d = @json_decode($r, true);
if ($d) {
return ["content" => json_encode($d, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), "tool" => $t["id"], "source" => "dynamic-resolver"];
}
} elseif ($t["api"] === "exec" && !empty($t["cmd"])) {
// Direct shell exec — sovereign tool
$r = trim(@shell_exec($t["cmd"] . " 2>&1"));
if ($r) return ["content" => $r, "tool" => $t["id"], "source" => "dynamic-resolver-exec"];
} elseif (strpos($t["api"], "POST:") === 0) {
$url = "https://weval-consulting.com" . substr($t["api"], 5);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(["message" => $msg, "task" => $msg]),
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => false
]);
$r = curl_exec($ch);
$d = @json_decode($r, true);
if ($d) return ["content" => json_encode($d, JSON_PRETTY_PRINT), "tool" => $t["id"], "source" => "dynamic-resolver"];
}
}
return null; // No match — let LLM handle
}