204 lines
8.5 KiB
PHP
204 lines
8.5 KiB
PHP
<?php
|
|
// WEVIA Chatbot Tool Extensions v2 — AEGIS + Pandoc + Embed + Search
|
|
function wevia_tool_dispatch($message) {
|
|
$msg = strtolower($message);
|
|
$result = null;
|
|
|
|
// AEGIS Security
|
|
if (preg_match('/securit|security|firewall|injection|trust.*grade|aegis/i', $msg)) {
|
|
$scan = @json_decode(@file_get_contents("http://localhost/api/aegis-api.php?action=scan&target=wevia"), true);
|
|
if ($scan && ($scan["ok"]??false)) {
|
|
$result = "**AEGIS Security Report**\n\nTrust Grade: **{$scan['trust_grade']}**\nRisk: {$scan['risk']}\n";
|
|
}
|
|
}
|
|
|
|
// AIOS Kernel
|
|
if (preg_match('/kernel|infrastructure|agent.*list|orchestr/i', $msg)) {
|
|
$status = @json_decode(@file_get_contents("http://localhost/api/aios-api.php?action=status"), true);
|
|
if ($status && ($status["ok"]??false)) {
|
|
$result = ($result ? $result . "\n---\n\n" : "") . "**AIOS Kernel**\n\nTools: " . ($status["kernel"]["tools"]["registered"]??38) . "\n";
|
|
}
|
|
}
|
|
|
|
// PANDOC Document Export (word, pptx, odt, epub)
|
|
if (preg_match('/\b(exporte|convertis|telecharge|download)\b.{0,20}\b(word|docx|pptx|powerpoint|odt|epub)\b/i', $msg)) {
|
|
$format = 'docx';
|
|
if (preg_match('/pptx|powerpoint/i', $msg)) $format = 'pptx';
|
|
if (preg_match('/odt/i', $msg)) $format = 'odt';
|
|
if (preg_match('/epub/i', $msg)) $format = 'epub';
|
|
if (function_exists('weviaConvertDocument')) {
|
|
$topic = trim(preg_replace('/^.*(exporte|convertis|telecharge)\s*(en|au|le)?\s*(word|docx|pptx)?\s*/i', '', $message));
|
|
$doc = weviaConvertDocument("# " . ($topic ?: 'Document') . "\n\nGenere par WEVIA Engine.", $format, $topic ?: 'Document');
|
|
if ($doc && ($doc['ok']??false)) {
|
|
$result = ($result ? $result . "\n---\n\n" : "") . "**Export " . strtoupper($format) . "**\n\n[Telecharger](" . $doc['url'] . ") - " . round($doc['size']/1024) . " KB\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
// Web Search via SearXNG
|
|
if (preg_match('/\b(cherche|recherche|search)\b.{0,15}(internet|web|google)/i', $msg)) {
|
|
if (function_exists('weviaWebSearch')) {
|
|
$q = trim(preg_replace('/^.*(cherche|recherche|search)\s*(sur)?\s*(internet|web)?\s*/i', '', $message));
|
|
$sr = weviaWebSearch($q ?: $message);
|
|
if ($sr) {
|
|
$result = ($result ? $result . "\n---\n\n" : "") . "**Recherche Web**\n\n";
|
|
foreach (array_slice($sr, 0, 5) as $i => $r) {
|
|
$result .= ($i+1) . ". [{$r['title']}]({$r['url']})\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
// === SKILL SEARCH INTEGRATION ===
|
|
function wevia_skills_search($query, $limit = 5) {
|
|
$ch = curl_init("http://127.0.0.1:6333/collections/weval_skills/points/scroll");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST=>true, CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>5,
|
|
CURLOPT_HTTPHEADER=>["Content-Type: application/json"],
|
|
CURLOPT_POSTFIELDS=>json_encode(["limit"=>200, "with_payload"=>true])
|
|
]);
|
|
$resp = json_decode(curl_exec($ch), true); curl_close($ch);
|
|
$results = [];
|
|
foreach (($resp["result"]["points"] ?? []) as $p) {
|
|
$pay = $p["payload"] ?? [];
|
|
if (stripos($pay["name"]??"", $query) !== false || stripos($pay["desc"]??"", $query) !== false) {
|
|
$results[] = $pay;
|
|
if (count($results) >= $limit) break;
|
|
}
|
|
}
|
|
return $results;
|
|
}
|
|
|
|
// === AGENT DISPATCH (oh-my-claudecode 19 agents) ===
|
|
function wevia_agent_dispatch($message) {
|
|
$agents_file = "/var/www/html/api/agents-catalog.php";
|
|
$agents_dir = "/opt/oh-my-claudecode/agents";
|
|
|
|
// Detect agent request in message
|
|
$agent_keywords = [
|
|
"architect" => "architect.md",
|
|
"debugger" => "debugger.md",
|
|
"reviewer" => "code-reviewer.md",
|
|
"designer" => "designer.md",
|
|
"planner" => "planner.md",
|
|
"security" => "security-reviewer.md",
|
|
"tester" => "qa-tester.md",
|
|
"analyst" => "analyst.md",
|
|
"writer" => "writer.md",
|
|
"executor" => "executor.md",
|
|
];
|
|
|
|
foreach ($agent_keywords as $kw => $file) {
|
|
if (stripos($message, $kw) !== false && stripos($message, "agent") !== false) {
|
|
$agent_prompt = @file_get_contents("$agents_dir/$file");
|
|
if ($agent_prompt) {
|
|
return ["active" => true, "agent" => $kw, "system_prompt" => substr($agent_prompt, 0, 2000)];
|
|
}
|
|
}
|
|
}
|
|
return ["active" => false];
|
|
}
|
|
|
|
// === SUPERCLAUDE COMMANDS (/sc:*) ===
|
|
function wevia_sc_command($message) {
|
|
if (strpos($message, "/sc:") === false) return null;
|
|
|
|
$commands = [
|
|
"/sc:research" => "Deep research mode — search multiple sources, synthesize findings",
|
|
"/sc:brainstorm" => "Creative brainstorming — generate 10+ ideas, evaluate each",
|
|
"/sc:debug" => "Systematic debugging — trace, isolate, fix, verify",
|
|
"/sc:refactor" => "Code refactoring — simplify, optimize, document",
|
|
"/sc:review" => "Code review — security, performance, best practices",
|
|
"/sc:test" => "Generate comprehensive tests — unit, integration, edge cases",
|
|
"/sc:plan" => "Project planning — tasks, timeline, dependencies",
|
|
"/sc:doc" => "Documentation — README, API docs, comments",
|
|
"/sc:optimize" => "Performance optimization — profiling, bottlenecks, solutions",
|
|
"/sc:security" => "Security audit — OWASP, vulnerabilities, hardening",
|
|
];
|
|
|
|
foreach ($commands as $cmd => $desc) {
|
|
if (stripos($message, $cmd) !== false) {
|
|
return ["command" => $cmd, "mode" => $desc];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// === PROMPTS LIBRARY ===
|
|
function wevia_prompt_suggest($category) {
|
|
$prompts = json_decode(file_get_contents("/opt/weval-prompts-library.json"), true) ?: [];
|
|
$filtered = array_filter($prompts, fn($p) => stripos($p["category"], $category) !== false);
|
|
return array_values($filtered);
|
|
}
|
|
|
|
// === SKILLS RAG SEARCH ===
|
|
function wevia_skills_rag($query, $limit = 3) {
|
|
$ch = curl_init("http://127.0.0.1:6333/collections/weval_skills/points/scroll");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5,
|
|
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
|
|
CURLOPT_POSTFIELDS => json_encode(["limit" => 200, "with_payload" => true])
|
|
]);
|
|
$resp = json_decode(curl_exec($ch), true); curl_close($ch);
|
|
$results = [];
|
|
foreach (($resp["result"]["points"] ?? []) as $p) {
|
|
$pay = $p["payload"] ?? [];
|
|
if (stripos($pay["name"] ?? "", $query) !== false || stripos($pay["desc"] ?? "", $query) !== false) {
|
|
$results[] = $pay;
|
|
if (count($results) >= $limit) break;
|
|
}
|
|
}
|
|
return $results;
|
|
}
|
|
|
|
|
|
// === DIFFUSIONDB IMAGE PROMPT ENHANCER ===
|
|
function wevia_enhance_image_prompt($user_prompt) {
|
|
$lib = json_decode(@file_get_contents("/var/www/html/api/weval-prompts-library.json"), true) ?: [];
|
|
if (!$lib) return $user_prompt;
|
|
|
|
// Find best matching prompt from library
|
|
$best = null;
|
|
$best_score = 0;
|
|
$words = array_filter(explode(" ", strtolower($user_prompt)), fn($w) => strlen($w) > 3);
|
|
|
|
foreach ($lib as $p) {
|
|
$score = 0;
|
|
foreach ($words as $w) {
|
|
if (stripos($p["prompt"], $w) !== false) $score++;
|
|
}
|
|
if ($score > $best_score) {
|
|
$best_score = $score;
|
|
$best = $p["prompt"];
|
|
}
|
|
}
|
|
|
|
if ($best && $best_score >= 1) {
|
|
// Enhance user prompt with DiffusionDB style keywords
|
|
$style_words = array_slice(explode(",", $best), -2);
|
|
$style = implode(", ", array_map("trim", $style_words));
|
|
return $user_prompt . ", " . $style;
|
|
}
|
|
return $user_prompt;
|
|
}
|
|
|
|
// === IMAGE PROMPT SUGGESTIONS ===
|
|
function wevia_image_suggestions($category = "") {
|
|
$lib = json_decode(@file_get_contents("/var/www/html/api/weval-prompts-library.json"), true) ?: [];
|
|
if ($category) {
|
|
$lib = array_filter($lib, fn($p) => $p["category"] === $category);
|
|
}
|
|
return array_slice(array_values($lib), 0, 5);
|
|
}
|
|
|
|
@include_once __DIR__ . '/wevcode-superclaude.php';
|
|
|
|
function wevia_dreamina_url($p){return 'https://dreamina.capcut.com/ai-tool/image/generate?prompt='.urlencode($p);}
|
|
function wevia_codewiki(){return json_decode(file_get_contents('https://weval-consulting.com/api/code-wiki.php'),true);}
|
|
|
|
function wevia_news_brief(){$r=json_decode(@file_get_contents("http://127.0.0.1/api/feeddough-news.php?action=brief"),true);return $r["brief"]??"Pas de news";}
|