Files
html/api/wevia-dynamic-exec.php
2026-04-12 22:57:03 +02:00

33 lines
1.8 KiB
PHP

<?php
opcache_invalidate(__FILE__,true);
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
$input=json_decode(file_get_contents("php://input"),true);
$msg=$input["message"]??$_POST["message"]??"";
if(!$msg){echo json_encode(["error"=>"no message"]);exit;}
$reg=json_decode(@file_get_contents(__DIR__."/wevia-tool-registry.json"),true);
$tools=$reg["tools"]??[];
$matched=[];
foreach($tools as $t){
if(@preg_match("/".$t["kw"]."/i",$msg)) $matched[]=$t;
}
if(empty($matched)){echo json_encode(["matched"=>0,"action"=>"llm_fallback"]);exit;}
$tool=$matched[0];
if($tool["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"=>$tool["msg"]]),CURLOPT_HTTPHEADER=>["Content-Type: application/json"],CURLOPT_TIMEOUT=>25,CURLOPT_SSL_VERIFYPEER=>0]);
$r=curl_exec($ch);$result=json_decode($r,true);
} elseif(strpos($tool["api"],"GET:")===0){
$url="https://weval-consulting.com".substr($tool["api"],4);
$ctx=stream_context_create(["ssl"=>["verify_peer"=>false],"http"=>["timeout"=>15]]);
$r=@file_get_contents($url,false,$ctx);
$result=json_decode($r,true)?:["raw"=>substr($r??"" ,0,500)];
} elseif(strpos($tool["api"],"POST:")===0){
$url="https://weval-consulting.com".substr($tool["api"],5);
$ch=curl_init($url);curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>1,CURLOPT_POST=>1,CURLOPT_POSTFIELDS=>json_encode(["message"=>$msg,"task"=>$msg]),CURLOPT_HTTPHEADER=>["Content-Type: application/json"],CURLOPT_TIMEOUT=>30,CURLOPT_SSL_VERIFYPEER=>0]);
$r=curl_exec($ch);$result=json_decode($r,true);
}
echo json_encode(["matched"=>count($matched),"tool"=>$tool["id"],"action"=>"executed","result"=>$result,"alt"=>array_map(fn($t)=>$t["id"],array_slice($matched,1,3))]);