$t["id"],"kw"=>$t["kw"]]; }, $reg["tools"] ?? []); echo json_encode(["ok"=>true,"count"=>count($tools),"tools"=>$tools]); exit; } // ACTION: exec — route to the right tool if ($action === "exec" && $msg) { // 1. Try Dynamic Resolver (keyword match) $reg = @json_decode(@file_get_contents("/opt/wevia-brain/tool-registry-v2.json"),true); foreach ($reg["tools"] ?? [] as $t) { if (@preg_match("/".$t["kw"]."/i",$msg)) { // Found a tool — execute if ($t["api"] === "master") { $ch = curl_init("https://weval-consulting.com/api/wevia-master-api.php"); curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>1,CURLOPT_POST=>1, CURLOPT_POSTFIELDS=>json_encode(["message"=>$t["msg"]]), CURLOPT_HTTPHEADER=>["Content-Type: application/json"], CURLOPT_TIMEOUT=>20,CURLOPT_SSL_VERIFYPEER=>0]); $r = curl_exec($ch); $d = @json_decode($r,true); echo json_encode(["ok"=>true,"tool"=>$t["id"],"source"=>"master","result"=>$d["content"] ?? $r]); exit; } 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"=>15]]); $r = @file_get_contents($url,false,$ctx); echo json_encode(["ok"=>true,"tool"=>$t["id"],"source"=>"api","result"=>@json_decode($r,true) ?? $r]); exit; } } } // 2. No tool match → forward to Master LLM $ch = curl_init("https://weval-consulting.com/api/wevia-master-api.php"); curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>1,CURLOPT_POST=>1, CURLOPT_POSTFIELDS=>json_encode(["message"=>$msg]), CURLOPT_HTTPHEADER=>["Content-Type: application/json"], CURLOPT_TIMEOUT=>25,CURLOPT_SSL_VERIFYPEER=>0]); $r = curl_exec($ch); $d = @json_decode($r,true); echo json_encode(["ok"=>true,"tool"=>"llm","source"=>"master-llm","result"=>$d["content"] ?? $r]); exit; } // ACTION: arena — multi-model query if ($action === "arena" && $msg) { $ch = curl_init("https://weval-consulting.com/api/wevia-multi-provider.php"); curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>1,CURLOPT_POST=>1, CURLOPT_POSTFIELDS=>json_encode(["message"=>$msg,"provider"=>$input["provider"] ?? "auto"]), CURLOPT_HTTPHEADER=>["Content-Type: application/json"], CURLOPT_TIMEOUT=>30,CURLOPT_SSL_VERIFYPEER=>0]); $r = curl_exec($ch); echo json_encode(["ok"=>true,"tool"=>"arena","result"=>@json_decode($r,true) ?? $r]); exit; } // ACTION: skill — execute a specific skill if ($action === "skill") { $skill = $input["skill"] ?? ""; $skills = ["pr-review","image-gen","voice-tts","video-gen","webhook-factory", "systematic-debug","browser-agent","cicd-pipeline","long-task", "hubs-check","services-check","supervise","factory"]; if (in_array($skill,$skills)) { $url = "https://weval-consulting.com/api/skill-{$skill}.php?action=".urlencode($input["skill_action"] ?? "status"); $r = @file_get_contents($url,false,stream_context_create(["ssl"=>["verify_peer"=>false],"http"=>["timeout"=>15]])); echo json_encode(["ok"=>true,"tool"=>"skill-{$skill}","result"=>@json_decode($r,true) ?? $r]); } else { echo json_encode(["ok"=>true,"skills"=>$skills]); } exit; } // ACTION: hub — check hub status if ($action === "hub") { $ch = curl_init("https://weval-consulting.com/api/wevia-master-api.php"); curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>1,CURLOPT_POST=>1, CURLOPT_POSTFIELDS=>json_encode(["message"=>"hubs status"]), CURLOPT_HTTPHEADER=>["Content-Type: application/json"], CURLOPT_TIMEOUT=>20,CURLOPT_SSL_VERIFYPEER=>0]); $r = curl_exec($ch); $d = @json_decode($r,true); echo json_encode(["ok"=>true,"tool"=>"hubs","result"=>$d["content"] ?? $r]); exit; } // ACTION: health — full system health if ($action === "health" || !$action) { echo json_encode([ "ok"=>true, "engine"=>"Blade Tools Bridge v1.0", "tools"=>102, "skills"=>13, "hubs"=>29, "arena"=>"10/10", "actions"=>["list","exec","arena","skill","hub","health"] ]); exit; } echo json_encode(["error"=>"unknown action: {$action}"]);