42 lines
2.1 KiB
PHP
42 lines
2.1 KiB
PHP
<?php
|
|
// Arena Pre-Intents — Dynamic Resolver v7
|
|
// Routes arena messages through 222 tools before LLM fallback
|
|
header("Content-Type: application/json");
|
|
$msg = $_POST["message"] ?? $_GET["message"] ?? "";
|
|
if(!trim($msg)){echo json_encode(["error"=>"no message"]);exit;}
|
|
|
|
// 1. Try Dynamic Resolver (222 tools)
|
|
$registry = json_decode(file_get_contents("/opt/wevia-brain/tool-registry-v2.json"),true);
|
|
if($registry && isset($registry["tools"])){
|
|
$lower = mb_strtolower($msg);
|
|
foreach($registry["tools"] as $tool){
|
|
$kw = explode("|", $tool["kw"] ?? "");
|
|
foreach($kw as $k){
|
|
if($k && strpos($lower, trim($k)) !== false){
|
|
// Tool matched — route to appropriate API
|
|
$api = $tool["api"] ?? "master";
|
|
$toolMsg = $tool["msg"] ?? $msg;
|
|
if($api === "master"){
|
|
// Route to WEVIA Master
|
|
$ch = curl_init("https://127.0.0.1/api/wevia-autonomous.php");
|
|
curl_setopt_array($ch,[CURLOPT_POST=>1,CURLOPT_POSTFIELDS=>http_build_query(["message"=>$toolMsg]),CURLOPT_RETURNTRANSFER=>1,CURLOPT_TIMEOUT=>25,CURLOPT_SSL_VERIFYPEER=>0,CURLOPT_SSL_VERIFYHOST=>0,CURLOPT_HTTPHEADER=>['Host: weval-consulting.com']]);
|
|
$r = curl_exec($ch);curl_close($ch);
|
|
echo $r;exit;
|
|
}
|
|
if($api === "sentinel"){
|
|
$ch = curl_init("http://10.1.0.3:5890/api/sentinel-brain.php?action=exec");
|
|
curl_setopt_array($ch,[CURLOPT_POST=>1,CURLOPT_POSTFIELDS=>"cmd=".urlencode($toolMsg),CURLOPT_RETURNTRANSFER=>1,CURLOPT_TIMEOUT=>20]);
|
|
$r = curl_exec($ch);curl_close($ch);
|
|
echo $r;exit;
|
|
}
|
|
// Default: return tool info
|
|
echo json_encode(["tool"=>$tool["id"],"matched"=>$k,"api"=>$api,"action"=>$toolMsg]);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. No tool matched — return null (caller will fallback to LLM)
|
|
echo json_encode(["resolved"=>false,"tools_checked"=>$registry["count"]??0]);
|