667 lines
34 KiB
PHP
667 lines
34 KiB
PHP
<?php
|
|
/**
|
|
* WEVIA CAPABILITY DISPATCHER v1.0
|
|
* Unified interface to call ANY WEVAL capability from Master AI
|
|
*
|
|
* Usage: POST /api/wevia-dispatcher.php
|
|
* Body: {"capability":"blade_brain","params":{"goal":"check disk"},"auth":"WEVIA2026"}
|
|
*
|
|
* Or: GET /api/wevia-dispatcher.php?cap=blade_power&action=health
|
|
*/
|
|
|
|
header("Content-Type: application/json; charset=utf-8");
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Access-Control-Allow-Headers: Content-Type");
|
|
if ($_SERVER["REQUEST_METHOD"] === "OPTIONS") { http_response_code(200); exit; }
|
|
|
|
require_once "/opt/wevia-brain/wevia-capabilities.php";
|
|
|
|
// Auth
|
|
$auth = $_REQUEST['auth'] ?? '';
|
|
if ($auth !== 'WEVIA2026' && $auth !== 'BLADE2026') {
|
|
$input = json_decode(file_get_contents("php://input"), true);
|
|
$auth = $input['auth'] ?? '';
|
|
}
|
|
|
|
// === CAPABILITY ROUTES ===
|
|
$ROUTES = [
|
|
// TIER 1 CRITICAL
|
|
'blade_brain' => function($p) { return callInternal('/api/blade-brain.php', $p); },
|
|
'blade_agent' => function($p) {
|
|
$goal = $p['goal'] ?? $p['message'] ?? 'health check';
|
|
return callInternal("/api/blade-agent.php?k=BLADE2026&goal=" . urlencode($goal));
|
|
},
|
|
'blade_ops' => function($p) { return callInternal('/api/blade-ops-api.php', $p); },
|
|
'blade_power' => function($p) {
|
|
$action = $p['action'] ?? 'health';
|
|
return callInternal("/api/blade-power.php?action=$action");
|
|
},
|
|
'wedroid' => function($p) { return callInternal('/api/wedroid-brain-api.php', $p); },
|
|
'manager' => function($p) { return callInternal('/api/weval-manager.php', $p); },
|
|
'clawcode' => function($p) { return callInternal('/api/claw-code-api.php', $p); },
|
|
'browser_use' => function($p) { return callInternal('/api/browser-use-api.php', $p); },
|
|
'adx_bridge' => function($p) { return callInternal('/api/adx-bridge.php', $p); },
|
|
|
|
// TIER 2 HIGH
|
|
'autolearn' => function($p) { return execLocal('python3 /var/www/html/tests/wevia-autolearn.py 2>&1 | tail -20'); },
|
|
'benchmark' => function($p) { return callInternal('/api/ai-benchmark-live.php', $p); },
|
|
'chat_proxy' => function($p) { return callInternal('/api/chat-proxy.php', $p); },
|
|
'crm' => function($p) { return callInternal('/api/crm-api.php', $p); },
|
|
'agents_catalog' => function($p) { return callInternal('/api/agents-catalog.php'); },
|
|
'agents_status' => function($p) { return callInternal('/api/agents-status.php'); },
|
|
'coderabbit' => function($p) { return callInternal('/api/coderabbit-webhook.php', $p); },
|
|
'ethica' => function($p) { return callInternal('/api/ethica-api.php', $p); },
|
|
|
|
// TIER 2 BOTS
|
|
'bot_telegram' => function($p) { return callInternal('/api/blade-telegram.php', $p); },
|
|
'bot_mattermost' => function($p) { return callInternal('/api/blade-mattermost.php', $p); },
|
|
|
|
// TIER 3 EXPOSE
|
|
'claude_proxy' => function($p) { return callInternal('/api/wevia-anthropic.php', $p); },
|
|
'openai_proxy' => function($p) { return callInternal('/api/wevia-openai.php', $p); },
|
|
'tool_extensions' => function($p) { return callInternal('/api/wevia-tool-extensions.php', $p); },
|
|
'architecture' => function($p) { return callInternal('/api/wevia-architecture-hooks.php', $p); },
|
|
'artifacts' => function($p) { return callInternal('/api/wevia-artifact-host.php', $p); },
|
|
'wevia_bench' => function($p) { return callInternal('/api/wevia-bench.php', $p); },
|
|
|
|
// DOMAIN
|
|
'wevads_engine' => function($p) { return callInternal('/api/wevads-v2-engine.php', $p); },
|
|
'oss_discovery' => function($p) { return callInternal('/api/oss-discovery.php', $p); },
|
|
|
|
// WEVIA MASTER
|
|
'master_health' => function($p) { return callInternal('/api/wevia-master-api.php?health'); },
|
|
'master_rag' => function($p) {
|
|
$q = $p['query'] ?? $p['q'] ?? '';
|
|
return callInternal("/api/wevia-master-api.php?rag&q=" . urlencode($q));
|
|
},
|
|
'master_agents' => function($p) {
|
|
$agent = $p['agent'] ?? 'monitor';
|
|
$goal = $p['goal'] ?? 'quick check';
|
|
return callInternal("/api/wevia-agent-loop.php?agent=$agent&goal=" . urlencode($goal));
|
|
},
|
|
|
|
// EXEC TOOLS
|
|
'l99_master' => function($p) { return execLocal('cd /opt/weval-l99 && python3 l99-master.py --quick 2>&1 | tail -30'); },
|
|
'l99_visual' => function($p) { return execLocal('cd /opt/weval-l99 && python3 l99-visual-test.py 2>&1 | tail -20'); },
|
|
'l99_security' => function($p) { return execLocal('cd /opt/weval-l99 && python3 l99-security-scan.py 2>&1 | tail -20'); },
|
|
'l99_autofix' => function($p) { return execLocal('cd /opt/weval-l99 && python3 l99-autofix-pipeline.py 2>&1 | tail -20'); },
|
|
'nuclei_scan' => function($p) {
|
|
$target = $p['target'] ?? 'weval-consulting.com';
|
|
return execLocal("nuclei -u $target -severity critical,high -silent 2>&1 | head -30");
|
|
},
|
|
'whisper' => function($p) {
|
|
$file = $p['file'] ?? '';
|
|
return execLocal("whisper $file --language fr --model base 2>&1 | tail -10");
|
|
},
|
|
'search' => function($p) {
|
|
$q = $p['query'] ?? $p['q'] ?? '';
|
|
return json_decode(@file_get_contents("http://127.0.0.1:8888/search?q=" . urlencode($q) . "&format=json"), true);
|
|
},
|
|
|
|
// WEVIA LIFE
|
|
'wevia_life' => function($p) { return callInternal('/products/wevialife-api.php', $p); },
|
|
'qwen_image' => function($p) {
|
|
// Vision via Groq Llama-4-Scout (FREE)
|
|
$payload = ['image' => $p['image'] ?? '', 'image_url' => $p['image_url'] ?? '', 'prompt' => $p['prompt'] ?? 'Analyse cette image'];
|
|
$ch = curl_init('https://weval-consulting.com/api/wevia-vision-api.php');
|
|
curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => false]);
|
|
$r = curl_exec($ch); curl_close($ch);
|
|
return json_decode($r, true) ?: ['raw' => $r];
|
|
},
|
|
'gemini_chat' => function($p) {
|
|
$secrets = mr_loadSecrets();
|
|
return mr_callGemini('gemini-2.5-flash', $secrets['GEMINI_KEY'], '', $p['message'] ?? 'Hello');
|
|
},
|
|
'gemini_image' => function($p) {
|
|
return ['url' => 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent', 'type' => 'image_gen', 'free' => true, 'note' => 'Gemini image generation'];
|
|
},
|
|
'sovereign_claude' => function($p) { return callInternal('/api/chat-proxy.php', $p); },
|
|
|
|
|
|
// === DOCKER SERVICES (RUNNING) ===
|
|
'paperclip' => function($p) { return callInternal('/api/blade-agent.php?k=BLADE2026&goal=' . urlencode($p['goal'] ?? 'CEO report')); },
|
|
'n8n' => function($p) { return ['url' => 'http://127.0.0.1:5678', 'status' => 'Docker UP', 'type' => 'workflow']; },
|
|
'twenty_crm' => function($p) { return ['url' => 'http://127.0.0.1:3000', 'status' => 'Docker UP', 'type' => 'crm']; },
|
|
'plausible' => function($p) { return ['url' => 'http://127.0.0.1:8787', 'status' => 'Docker UP', 'type' => 'analytics']; },
|
|
'uptime_kuma' => function($p) { return ['url' => 'http://127.0.0.1:3088', 'status' => 'Docker UP', 'type' => 'monitoring']; },
|
|
'prometheus' => function($p) { return ['url' => 'http://127.0.0.1:9191', 'status' => 'Docker UP', 'type' => 'metrics']; },
|
|
'mattermost' => function($p) { return ['url' => 'http://127.0.0.1:8065', 'status' => 'Docker UP', 'type' => 'chat']; },
|
|
'open_webui' => function($p) { return ['url' => 'http://127.0.0.1:3000', 'status' => 'Docker UP', 'type' => 'llm_ui']; },
|
|
'flowise' => function($p) { return ['url' => 'http://127.0.0.1:3001', 'status' => 'Docker UP', 'type' => 'workflow']; },
|
|
'vaultwarden' => function($p) { return ['url' => 'http://10.1.0.3:8222', 'status' => 'Docker S95', 'type' => 'passwords']; },
|
|
|
|
// === SCRAPING ===
|
|
'scrapy' => function($p) {
|
|
$spider = $p['spider'] ?? 'dabadoc';
|
|
$args = $p['args'] ?? '';
|
|
return execLocal("cd /var/www/html/api && php ethica-api.php spider=$spider $args 2>&1 | tail -20");
|
|
},
|
|
|
|
// === AI/ML FRAMEWORKS ===
|
|
'langchain' => function($p) { return ['installed' => true, 'path' => '/opt/langchain', 'type' => 'framework']; },
|
|
'crewai' => function($p) { return ['installed' => true, 'path' => '/opt/crewai', 'type' => 'multi_agent']; },
|
|
'autogen' => function($p) { return ['installed' => true, 'path' => '/opt/autogen', 'type' => 'multi_agent']; },
|
|
'llamaindex' => function($p) { return ['installed' => true, 'path' => '/opt/llamaindex', 'type' => 'rag_framework']; },
|
|
|
|
// === DEERFLOW SKILLS ===
|
|
'deerflow_research' => function($p) {
|
|
// Migrated from DeerFlow to Perplexity web provider (16avr)
|
|
$topic = $p['topic'] ?? $p['q'] ?? 'WEVAL AI market';
|
|
$ch = curl_init('http://127.0.0.1/api/wevia-webchat-direct.php');
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => json_encode(['service' => 'perplexity', 'message' => 'Recherche approfondie: ' . $topic]),
|
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 30,
|
|
]);
|
|
$r = curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
if ($code === 200) {
|
|
$d = json_decode($r, true);
|
|
return ['provider' => 'Perplexity (ex-DeerFlow)', 'content' => $d['content'] ?? '', 'cost' => '0EUR'];
|
|
}
|
|
return ['status' => 'research_unavailable', 'http_code' => $code];
|
|
},
|
|
|
|
// === VIDEO/MEDIA ===
|
|
'ltx_video' => function($p) {
|
|
return ['installed' => is_dir('/opt/LTX-Video'), 'status' => 'GPU needed', 'type' => 'video_gen'];
|
|
},
|
|
'whisper_stt' => function($p) {
|
|
$file = $p['file'] ?? '';
|
|
if ($file) return execLocal("cd /opt/whisper.cpp && ./main -m models/ggml-base.bin -f $file -l fr 2>&1 | tail -20");
|
|
return ['installed' => true, 'model' => 'ggml-base', 'path' => '/opt/whisper.cpp'];
|
|
},
|
|
|
|
// === SKILLS INVENTORY ===
|
|
'skill_registry' => function($p) {
|
|
$action = $p['action'] ?? 'stats';
|
|
$q = $p['q'] ?? '';
|
|
return callInternal("/api/wevia-skill-registry.php?action=$action&q=" . urlencode($q));
|
|
},
|
|
'skills_count' => function($p) {
|
|
$count = count(glob('/opt/deer-flow/skills/weval/*') ?: []) + count(glob('/opt/deer-flow/skills/public/*') ?: []);
|
|
return ['total_skills' => $count, 'paths' => ['/opt/deer-flow/skills/weval/', '/opt/deer-flow/skills/public/']];
|
|
},
|
|
'skills_search' => function($p) {
|
|
$q = $p['query'] ?? $p['q'] ?? '';
|
|
$results = [];
|
|
foreach (glob('/opt/deer-flow/skills/weval/*') as $dir) {
|
|
$name = basename($dir);
|
|
if (stripos($name, $q) !== false) $results[] = $name;
|
|
}
|
|
return ['query' => $q, 'results' => array_slice($results, 0, 20), 'total' => count($results)];
|
|
},
|
|
|
|
// === DAILY TOOLS ===
|
|
'daily_brief' => function($p) { return execLocal('python3 /opt/weval-daily-brief.py 2>&1 | tail -30'); },
|
|
'oss_trending' => function($p) { return execLocal('python3 /var/www/html/api/oss-trending-gen.py 2>&1 | tail -20'); },
|
|
'ai_gap' => function($p) { return execLocal('python3 /var/www/html/api/ai-gap-discovery.py 2>&1 | tail -20'); },
|
|
|
|
// === POWERTOYS ===
|
|
'tool_dns' => function($p) { $d=$p['domain']??''; return execLocal("dig +short $d 2>&1"); },
|
|
'tool_ssl' => function($p) { $d=$p['domain']??''; return execLocal("echo | openssl s_client -servername $d -connect $d:443 2>/dev/null | openssl x509 -noout -dates 2>&1"); },
|
|
'tool_whois' => function($p) { $d=$p['domain']??''; return execLocal("whois $d 2>&1 | head -30"); },
|
|
'tool_headers' => function($p) { $u=$p['url']??''; return execLocal("curl -sI $u 2>&1 | head -20"); },
|
|
'tool_port' => function($p) { $h=$p['host']??''; return execLocal("nmap -F $h 2>&1 | tail -20"); },
|
|
|
|
// === NONREG ===
|
|
'nonreg_master' => function($p) { return execLocal('cd /opt/weval-nonreg && python3 nonreg-master.py --quick 2>&1 | tail -30'); },
|
|
'nonreg_sso' => function($p) { return execLocal('cd /opt/weval-nonreg && python3 sso-mega-test.py 2>&1 | tail -20'); },
|
|
|
|
// === DESIGN (URLs) ===
|
|
'dreamina' => function($p) { return ['url' => 'https://dreamina.com', 'type' => 'image_gen', 'free' => true]; },
|
|
'ms_designer' => function($p) { return ['url' => 'https://designer.microsoft.com', 'type' => 'design', 'free' => true]; },
|
|
'google_stitch' => function($p) { return ['url' => 'https://stitch.withgoogle.com', 'type' => 'ui_design', 'free' => true]; },
|
|
|
|
|
|
|
|
// === DORMANT TOOLS — BATCH WIRED 4 AVR 2026 ===
|
|
|
|
// AGENT FRAMEWORKS
|
|
'omc_agents' => function($p) { return ['path'=>'/opt/oh-my-claudecode','type'=>'multi_agent','agents'=>19,'skills'=>28,'status'=>'installed']; },
|
|
'superclaude' => function($p) { return ['path'=>'/opt/SuperClaude_Framework','type'=>'framework','commands'=>30,'status'=>'installed']; },
|
|
'ecc_shield' => function($p) { return ['path'=>'/opt/everything-claude-code','type'=>'agent_shield','skills'=>420,'tests'=>1282,'status'=>'installed']; },
|
|
'antigravity' => function($p) { return ['path'=>'/opt/antigravity-awesome-skills','type'=>'skill_library','skills'=>4198,'status'=>'installed']; },
|
|
'awesome_toolkit' => function($p) { return ['path'=>'/opt/awesome-claude-code-toolkit','type'=>'toolkit','agents'=>135,'commands'=>42,'plugins'=>150,'status'=>'installed']; },
|
|
'skill_creator' => function($p) { return ['path'=>'/opt/FrancyJGLisboa_agent-skill-creator','type'=>'skill_gen','status'=>'installed']; },
|
|
'skillsmith' => function($p) { return ['path'=>'/opt/skillsmith','type'=>'skill_gen','status'=>'installed']; },
|
|
'hf_skills' => function($p) { return ['path'=>'/opt/huggingface-skills','type'=>'hf_skills','count'=>12,'status'=>'installed']; },
|
|
'volt_skills' => function($p) {
|
|
$q = $p['query'] ?? '';
|
|
$results = [];
|
|
foreach (glob('/opt/oh-my-claudecode/skills/*') as $s) {
|
|
if ($q && stripos(basename($s), $q) === false) continue;
|
|
$results[] = basename($s);
|
|
}
|
|
return ['skills' => array_slice($results, 0, 20), 'total' => count($results)];
|
|
},
|
|
|
|
// MEMORY & KNOWLEDGE
|
|
'memory_store' => function($p) { return callInternal('/api/wevia-memory-api.php?action=store', $p); },
|
|
'memory_recall' => function($p) { $q=$p['q']??''; return callInternal('/api/wevia-memory-api.php?action=recall&q='.urlencode($q)); },
|
|
'memory_learn' => function($p) { return callInternal('/api/wevia-memory-api.php?action=learn', $p); },
|
|
'memory_list' => function($p) { return callInternal('/api/wevia-memory-api.php?action=list'); },
|
|
'claude_mem' => function($p) { return ['path'=>'/opt/claude-mem','type'=>'persistent_memory','status'=>'installed']; },
|
|
'supermemory' => function($p) { return ['path'=>'/opt/supermemory','type'=>'ai_memory','status'=>'installed']; },
|
|
|
|
// CODE TOOLS
|
|
'claw_code' => function($p) { return ['path'=>'/opt/claw-code','type'=>'rust_claude_code','size'=>'1.2GB','status'=>'installed']; },
|
|
'holy_claude' => function($p) { return ['path'=>'/opt/HolyClaude','type'=>'claude_enhance','status'=>'installed']; },
|
|
|
|
// INFERENCE ENGINES
|
|
'vllm_engine' => function($p) { return ['path'=>'/opt/vllm','type'=>'inference','status'=>'installed','note'=>'needs GPU']; },
|
|
'localai' => function($p) { return ['path'=>'/opt/localai','type'=>'openai_compat','status'=>'installed']; },
|
|
'jan_ai' => function($p) { return ['path'=>'/opt/jan','type'=>'desktop_llm','status'=>'installed']; },
|
|
|
|
// WORKFLOW & PLATFORMS
|
|
'activepieces' => function($p) { return ['path'=>'/opt/activepieces','type'=>'workflow','status'=>'installed','docker'=>true]; },
|
|
'dify_platform' => function($p) { return ['path'=>'/opt/dify','type'=>'llm_platform','status'=>'installed']; },
|
|
'langflow' => function($p) { return ['path'=>'/opt/langflow','type'=>'visual_agent_builder','status'=>'installed']; },
|
|
'librechat' => function($p) { return ['path'=>'/opt/librechat','type'=>'multi_provider_chat','status'=>'installed']; },
|
|
'anythingllm' => function($p) { return ['path'=>'/opt/anythingllm','type'=>'rag_desktop','status'=>'installed']; },
|
|
|
|
// AGENTS
|
|
'deepagent' => function($p) { return ['path'=>'/opt/deepagent','type'=>'deep_research','status'=>'installed']; },
|
|
'goose_agent' => function($p) { return ['path'=>'/opt/goose','type'=>'ai_agent','size'=>'1.2GB','status'=>'installed']; },
|
|
'aios_runtime' => function($p) { return ['path'=>'/opt/aios','type'=>'agent_os','status'=>'installed']; },
|
|
'paperclip_db' => function($p) {
|
|
$db = @pg_connect('host=127.0.0.1 port=5432 dbname=paperclip user=paperclip password=PaperclipWeval2026');
|
|
if (!$db) return ['error' => 'DB connection failed'];
|
|
$q = $p['query'] ?? 'SELECT COUNT(*) FROM skills';
|
|
$r = @pg_query($db, $q);
|
|
$rows = [];
|
|
while ($row = @pg_fetch_assoc($r)) $rows[] = $row;
|
|
pg_close($db);
|
|
return ['rows' => $rows, 'count' => count($rows)];
|
|
},
|
|
'deerflow_skills' => function($p) {
|
|
$q = $p['query'] ?? '';
|
|
$skills = glob('/opt/deer-flow/skills/weval/*', GLOB_ONLYDIR);
|
|
$results = [];
|
|
foreach ($skills as $s) {
|
|
$name = basename($s);
|
|
if ($q && stripos($name, $q) === false) continue;
|
|
$skillMd = "$s/SKILL.md";
|
|
$desc = file_exists($skillMd) ? mb_substr(file_get_contents($skillMd), 0, 200) : 'No description';
|
|
$results[] = ['name' => $name, 'desc' => $desc];
|
|
}
|
|
return ['total' => count($results), 'results' => array_slice($results, 0, 20)];
|
|
},
|
|
'deerflow_exec' => function($p) {
|
|
$skill = $p['skill'] ?? '';
|
|
if (!$skill) return ['error' => 'specify skill name'];
|
|
$skillDir = "/opt/deer-flow/skills/weval/$skill";
|
|
if (!is_dir($skillDir)) return ['error' => "skill not found: $skill"];
|
|
$skillMd = file_exists("$skillDir/SKILL.md") ? file_get_contents("$skillDir/SKILL.md") : '';
|
|
return ['skill' => $skill, 'path' => $skillDir, 'content' => mb_substr($skillMd, 0, 2000)];
|
|
},
|
|
'paperclip_ceo' => function($p) { return ['path'=>'/opt/paperclip-weval','type'=>'ceo_agent','docker'=>true,'status'=>'installed']; },
|
|
|
|
// SECURITY
|
|
'wazuh_siem' => function($p) { return ['path'=>'/opt/wazuh','type'=>'siem','status'=>'installed']; },
|
|
'keyhacks' => function($p) { return ['path'=>'/opt/keyhacks','type'=>'api_key_test','status'=>'installed']; },
|
|
'weval_security' => function($p) { return execLocal('ls /opt/weval-security/ 2>&1'); },
|
|
|
|
// FINETUNE
|
|
'wevia_finetune' => function($p) { return ['path'=>'/opt/wevia-finetune','type'=>'finetune','dataset'=>'/tmp/weval-dataset.jsonl','pairs'=>171,'status'=>'ready']; },
|
|
|
|
// SOVEREIGN
|
|
'sovereign_api' => function($p) { return ['path'=>'/opt/sovereign-api','type'=>'sovereign','status'=>'installed']; },
|
|
'weval_radar' => function($p) { return execLocal('cat /opt/weval-radar/*.md 2>&1 | head -30'); },
|
|
|
|
// OPEN WEBUI
|
|
'openwebui' => function($p) { return ['path'=>'/opt/open-webui-fresh','type'=>'llm_ui','docker'=>true,'status'=>'installed']; },
|
|
|
|
|
|
// TOOL ACTIVATION
|
|
'activate_tool' => function($p) {
|
|
$tool = $p['tool'] ?? '';
|
|
if (!in_array($tool, ['localai','dify','langflow','activepieces'])) {
|
|
return ['error' => 'Unknown tool', 'available' => ['localai','dify','langflow','activepieces']];
|
|
}
|
|
return execLocal("bash /opt/wevia-brain/activate-tool.sh $tool 2>&1");
|
|
},
|
|
'list_dormants' => function($p) {
|
|
$tools = ['localai','dify','langflow','activepieces','vllm','librechat','anythingllm','jan'];
|
|
$status = [];
|
|
foreach ($tools as $t) {
|
|
$running = trim(shell_exec("docker ps --filter name=$t -q 2>/dev/null"));
|
|
$status[$t] = $running ? 'RUNNING' : 'STOPPED';
|
|
}
|
|
return $status;
|
|
},
|
|
|
|
|
|
// === CLAUDE-MEM: REAL PERSISTENT MEMORY VIA QDRANT ===
|
|
'memory_remember' => function($p) {
|
|
return callInternal('/api/wevia-memory-api.php', array_merge($p, ['action' => 'remember']));
|
|
},
|
|
'memory_recall' => function($p) {
|
|
$q = $p['query'] ?? $p['q'] ?? '';
|
|
return callInternal('/api/wevia-memory-api.php?action=recall&q=' . urlencode($q));
|
|
},
|
|
'memory_list' => function($p) {
|
|
return callInternal('/api/wevia-memory-api.php?action=list&limit=' . ($p['limit'] ?? 20));
|
|
},
|
|
'memory_forget' => function($p) {
|
|
return callInternal('/api/wevia-memory-api.php', array_merge($p, ['action' => 'forget']));
|
|
},
|
|
|
|
|
|
// EMAIL
|
|
'email_send' => function($p) {
|
|
$ch = curl_init('http://127.0.0.1/api/wevia-email-api.php?action=send');
|
|
curl_setopt_array($ch, [CURLOPT_POST=>true, CURLOPT_POSTFIELDS=>json_encode($p), CURLOPT_HTTPHEADER=>['Content-Type: application/json'], CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>10]);
|
|
$r = curl_exec($ch); curl_close($ch);
|
|
return json_decode($r, true);
|
|
},
|
|
'email_read' => function($p) {
|
|
return json_decode(@file_get_contents('http://127.0.0.1/api/wevia-email-api.php?action=read'), true);
|
|
},
|
|
'email_boxes' => function($p) {
|
|
return json_decode(@file_get_contents('http://127.0.0.1/api/wevia-email-api.php?action=list_boxes'), true);
|
|
},
|
|
// REMOTE EXEC
|
|
'exec_s204' => function($p) {
|
|
$cmd = $p['cmd'] ?? 'hostname';
|
|
return execLocal($cmd);
|
|
},
|
|
|
|
|
|
// L99 NONREG
|
|
'l99_run' => function($p) {
|
|
$suite = $p['suite'] ?? 'master';
|
|
return execLocal('cd /opt/weval-l99 && python3 l99-master.py --suite ' . escapeshellarg($suite) . ' 2>&1 | tail -20');
|
|
},
|
|
'l99_results' => function($p) {
|
|
return json_decode(@file_get_contents('/var/www/html/api/l99-results.json'), true) ?: ['error' => 'no results'];
|
|
},
|
|
'l99_suites' => function($p) {
|
|
$suites = glob('/opt/weval-l99/suites/*.py');
|
|
return array_map('basename', $suites);
|
|
},
|
|
|
|
// BLADE FULL CONTROL
|
|
'blade_crons' => function($p) {
|
|
return execLocal('crontab -l 2>/dev/null | grep -v "^#" | grep -c "."');
|
|
},
|
|
'blade_logs' => function($p) {
|
|
return execLocal('tail -20 /tmp/blade-orch.log 2>/dev/null || echo "no blade log"');
|
|
},
|
|
'blade_trigger' => function($p) {
|
|
$action = $p['action'] ?? 'orchestrator';
|
|
return execLocal('bash /opt/wevia-brain/blade-orchestrator.sh 2>&1 && echo DONE');
|
|
},
|
|
|
|
// MANAGER CONSENSUS (Intelligence Collective)
|
|
'consensus' => function($p) {
|
|
$question = $p['question'] ?? $p['q'] ?? 'Should we proceed?';
|
|
$agents = ['cerebras', 'groq', 'mistral'];
|
|
$votes = [];
|
|
|
|
$secrets = [];
|
|
foreach (file('/etc/weval/secrets.env', 2|4) as $l) {
|
|
if (strpos($l, '=') !== false) {
|
|
list($k, $v) = explode('=', $l, 2);
|
|
$secrets[trim($k)] = trim($v, " \t\"'");
|
|
}
|
|
}
|
|
|
|
$providers = [
|
|
['url' => 'https://api.cerebras.ai/v1/chat/completions', 'key' => $secrets['CEREBRAS_API_KEY'], 'model' => 'qwen-3-235b-a22b-instruct-2507', 'name' => 'Cerebras 235B'],
|
|
['url' => 'https://api.groq.com/openai/v1/chat/completions', 'key' => $secrets['GROQ_KEY'], 'model' => 'llama3.1-8b-versatile', 'name' => 'Groq 70B'],
|
|
['url' => 'https://api.mistral.ai/v1/chat/completions', 'key' => $secrets['MISTRAL_KEY'], 'model' => 'mistral-large-latest', 'name' => 'Mistral Large'],
|
|
];
|
|
|
|
foreach ($providers as $p2) {
|
|
$ch = curl_init($p2['url']);
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => json_encode([
|
|
'model' => $p2['model'],
|
|
'messages' => [
|
|
['role' => 'system', 'content' => 'Tu es un expert WEVAL. Reponds en 2-3 phrases maximum. Sois precis et direct.'],
|
|
['role' => 'user', 'content' => $question],
|
|
],
|
|
'max_tokens' => 300,
|
|
'temperature' => 0.3,
|
|
]),
|
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer ' . $p2['key']],
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 15,
|
|
]);
|
|
$start = microtime(true);
|
|
$r = curl_exec($ch);
|
|
$lat = round((microtime(true) - $start) * 1000);
|
|
curl_close($ch);
|
|
$d = json_decode($r, true);
|
|
$answer = $d['choices'][0]['message']['content'] ?? 'no response';
|
|
$votes[] = ['agent' => $p2['name'], 'answer' => $answer, 'latency_ms' => $lat];
|
|
}
|
|
|
|
return ['question' => $question, 'votes' => $votes, 'agents_count' => count($votes), 'method' => 'multi-provider-consensus'];
|
|
},
|
|
|
|
// SYSTEM INFO
|
|
'sys_ram' => function($p) { return execLocal('free -h'); },
|
|
'sys_disk' => function($p) { return execLocal('df -h /'); },
|
|
'sys_docker' => function($p) { return execLocal('docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" 2>/dev/null | head -30'); },
|
|
'sys_ollama' => function($p) { return json_decode(@file_get_contents('http://127.0.0.1:11434/api/tags'), true); },
|
|
'sys_qdrant' => function($p) { return json_decode(@file_get_contents('http://127.0.0.1:6333/collections'), true); },
|
|
'sys_crons' => function($p) { return execLocal('crontab -l 2>/dev/null | grep -v "^#" | grep "."'); },
|
|
|
|
|
|
// FILE OPERATIONS
|
|
'file_browse' => function($p) {
|
|
$path = $p['path'] ?? '/var/www/html';
|
|
$out = shell_exec('ls -la ' . escapeshellarg($path) . ' 2>&1 | head -30');
|
|
return ['path' => $path, 'listing' => $out];
|
|
},
|
|
'file_read' => function($p) {
|
|
$path = $p['path'] ?? '';
|
|
if (!file_exists($path)) return ['error' => 'file not found'];
|
|
return ['path' => $path, 'size' => filesize($path), 'content' => substr(file_get_contents($path), 0, 5000)];
|
|
},
|
|
'file_write' => function($p) {
|
|
$path = $p['path'] ?? '';
|
|
$content = $p['content'] ?? '';
|
|
if (empty($path)) return ['error' => 'path required'];
|
|
file_put_contents($path, $content);
|
|
return ['status' => 'written', 'path' => $path, 'size' => strlen($content)];
|
|
},
|
|
'file_download' => function($p) {
|
|
$path = $p['path'] ?? '';
|
|
if (!file_exists($path)) return ['error' => 'not found'];
|
|
$url = str_replace('/var/www/html', '', $path);
|
|
return ['download_url' => 'https://weval-consulting.com' . $url, 'size' => filesize($path)];
|
|
},
|
|
|
|
|
|
// EXCEL / CSV
|
|
'excel_create' => function($p) {
|
|
$data = $p['data'] ?? [['Col1','Col2'],['val1','val2']];
|
|
$filename = $p['filename'] ?? 'export-' . date('Ymd-His') . '.csv';
|
|
$path = '/var/www/html/api/exports/' . $filename;
|
|
@mkdir(dirname($path), 0777, true);
|
|
$fp = fopen($path, 'w');
|
|
foreach ($data as $row) fputcsv($fp, $row);
|
|
fclose($fp);
|
|
return ['status' => 'created', 'file' => $filename, 'download' => 'https://weval-consulting.com/api/exports/' . $filename, 'rows' => count($data)];
|
|
},
|
|
|
|
|
|
// WEVIA LIFE EMAIL (enhanced)
|
|
'email_compose' => function($p) {
|
|
$to = $p['to'] ?? '';
|
|
$subject = $p['subject'] ?? 'Message WEVIA';
|
|
$body = $p['body'] ?? '';
|
|
$from = $p['from'] ?? 'ymahboub@weval-consulting.com';
|
|
$headers = "From: WEVIA <$from>\r\nContent-Type: text/html; charset=UTF-8\r\n";
|
|
$html = '<html><body style="font-family:Arial">' . nl2br(htmlspecialchars($body)) . '<br><small style="color:#999">WEVIA LIFE</small></body></html>';
|
|
$sent = mail($to, $subject, $html, $headers);
|
|
return ['status' => $sent ? 'sent' : 'failed', 'to' => $to, 'subject' => $subject];
|
|
},
|
|
'email_inbox' => function($p) {
|
|
$box = $p['box'] ?? 'ymahboub@weval-consulting.com';
|
|
$ch = curl_init('http://127.0.0.1/api/wevialife-api.php?action=list&box=' . urlencode($box) . '&limit=' . ($p['limit'] ?? 10));
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15]);
|
|
$r = curl_exec($ch); curl_close($ch);
|
|
return json_decode($r, true) ?: ['status' => 'proxy error'];
|
|
},
|
|
|
|
|
|
// SOVEREIGN CLAUDE 2
|
|
'sovereign_c2_registry' => function($p) {
|
|
$ch = curl_init('http://127.0.0.1/api/registry-local.php');
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5]);
|
|
$r = curl_exec($ch); curl_close($ch);
|
|
$d = json_decode($r, true);
|
|
return ['agents' => count($d['agents'] ?? []), 'source' => 'sovereign-c2'];
|
|
},
|
|
'sovereign_c2_dispatch' => function($p) {
|
|
$task = $p['task'] ?? '';
|
|
$ch = curl_init('http://127.0.0.1/api/sovereign-claude2.php');
|
|
curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode(['task' => $task]), CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60]);
|
|
$r = curl_exec($ch); curl_close($ch);
|
|
return json_decode($r, true) ?: ['raw' => substr($r, 0, 500)];
|
|
},
|
|
|
|
|
|
// WEVIA CODE
|
|
'wevia_code' => function($p) {
|
|
$lang = $p['lang'] ?? 'php';
|
|
$code = $p['code'] ?? '';
|
|
if ($lang === 'php') {
|
|
$tmp = tempnam('/tmp', 'wc_');
|
|
file_put_contents($tmp, '<?php ' . $code);
|
|
$out = shell_exec('php ' . escapeshellarg($tmp) . ' 2>&1');
|
|
unlink($tmp);
|
|
return ['lang' => 'php', 'output' => substr($out, 0, 2000)];
|
|
}
|
|
if ($lang === 'python') {
|
|
$tmp = tempnam('/tmp', 'wc_');
|
|
file_put_contents($tmp, $code);
|
|
$out = shell_exec('python3 ' . escapeshellarg($tmp) . ' 2>&1');
|
|
unlink($tmp);
|
|
return ['lang' => 'python', 'output' => substr($out, 0, 2000)];
|
|
}
|
|
if ($lang === 'bash') {
|
|
$out = shell_exec($code . ' 2>&1');
|
|
return ['lang' => 'bash', 'output' => substr($out, 0, 2000)];
|
|
}
|
|
return ['error' => 'unsupported lang: ' . $lang];
|
|
},
|
|
|
|
|
|
// WEDROID SSH
|
|
'wedroid_ssh' => function($p) {
|
|
$server = $p['server'] ?? 's204';
|
|
$cmd = $p['cmd'] ?? 'hostname';
|
|
if ($server === 's204') return execLocal($cmd);
|
|
if ($server === 's95') {
|
|
$ch = curl_init('http://10.1.0.3:5890/api/sentinel-brain.php?action=exec&cmd=' . urlencode($cmd));
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15]);
|
|
$r = curl_exec($ch); curl_close($ch);
|
|
return json_decode($r, true) ?: ['raw' => $r];
|
|
}
|
|
return ['error' => 'unknown server'];
|
|
},
|
|
|
|
// SCREENS (return URL)
|
|
'screen_enterprise' => function($p) { return ['url' => '/agents-enterprise.html', 'type' => 'screen']; },
|
|
'screen_command' => function($p) { return ['url' => '/command-center.html', 'type' => 'screen']; },
|
|
'screen_crons' => function($p) { return ['url' => '/cron-control.html', 'type' => 'screen']; },
|
|
'screen_blade' => function($p) { return ['url' => '/blade-ai.html', 'type' => 'screen']; },
|
|
'screen_clawcode' => function($p) { return ['url' => '/claw-code.html', 'type' => 'screen']; },
|
|
'screen_wevcode' => function($p) { return ['url' => '/wevcode.html', 'type' => 'screen']; },
|
|
'screen_agents_sim' => function($p) { return ['url' => '/agents-sim.html', 'type' => 'screen']; },
|
|
];
|
|
|
|
// === INTERNAL HTTP CALL ===
|
|
function callInternal($path, $params = null) {
|
|
$url = "https://weval-consulting.com" . $path;
|
|
if ($params && strpos($path, '?') === false) {
|
|
// POST
|
|
$ch = curl_init($url);
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => json_encode($params),
|
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 15,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_SSL_VERIFYPEER => false,
|
|
]);
|
|
} else {
|
|
// GET
|
|
$ch = curl_init($url);
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 15,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_SSL_VERIFYPEER => false,
|
|
]);
|
|
}
|
|
$result = curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
$decoded = json_decode($result, true);
|
|
return $decoded ?: ['raw' => mb_substr($result, 0, 2000), 'http_code' => $code];
|
|
}
|
|
|
|
// === LOCAL EXEC ===
|
|
function execLocal($cmd, $timeout = 30) {
|
|
$result = shell_exec("timeout $timeout bash -c " . escapeshellarg($cmd) . " 2>&1");
|
|
return ['output' => mb_substr($result ?? '', 0, 5000), 'cmd' => $cmd];
|
|
}
|
|
|
|
// === API HANDLER ===
|
|
|
|
// List all routes
|
|
if (isset($_GET['list'])) {
|
|
echo json_encode([
|
|
'total' => count($ROUTES),
|
|
'capabilities' => array_keys($ROUTES),
|
|
'wired' => count($ROUTES),
|
|
], JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
// Get capability
|
|
$cap = $_GET['cap'] ?? '';
|
|
if (empty($cap)) {
|
|
$input = json_decode(file_get_contents("php://input"), true);
|
|
$cap = $input['capability'] ?? $input['cap'] ?? '';
|
|
$params = $input['params'] ?? $input;
|
|
} else {
|
|
$params = $_GET;
|
|
}
|
|
|
|
if (empty($cap)) {
|
|
echo json_encode(['error' => 'Usage: ?cap=blade_power&action=health or POST {"capability":"...","params":{}}', 'available' => array_keys($ROUTES)]);
|
|
exit;
|
|
}
|
|
|
|
if (!isset($ROUTES[$cap])) {
|
|
echo json_encode(['error' => "Unknown capability: $cap", 'available' => array_keys($ROUTES)]);
|
|
exit;
|
|
}
|
|
|
|
// Execute
|
|
$start = microtime(true);
|
|
try {
|
|
$result = $ROUTES[$cap]($params ?? []);
|
|
$latency = round((microtime(true) - $start) * 1000);
|
|
echo json_encode([
|
|
'capability' => $cap,
|
|
'latency_ms' => $latency,
|
|
'result' => $result,
|
|
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['error' => $e->getMessage(), 'capability' => $cap]);
|
|
}
|