Files
html/api/wevia-sse-orchestrator-public.php
2026-04-17 22:43:56 +02:00

110 lines
6.6 KiB
PHP

<?php
// WEVIA Public SSE Orchestrator V51 - BRIDGED for public use
// Contract: only SAFE intents exposed to public internet
// Public intents: weval.com services/partnerships overview / general info / time / weather
// Blocked: ethica_* / warmup / PMTA / offers / sponsors / brain / vmta / vault / secrets
// Scope: wevia.html (public grand ecran) + wevia-widget.html
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('X-Accel-Buffering: no');
set_time_limit(20);
ob_implicit_flush(true);
while (ob_get_level()) ob_end_flush();
function sse($d) { echo 'data: ' . json_encode($d, JSON_UNESCAPED_UNICODE) . "\n\n"; flush(); }
$msg = $_GET['msg'] ?? '';
if (!$msg) { sse(['error' => 'msg required']); exit; }
sse(['type' => 'start', 'scope' => 'public', 'ts' => date('H:i:s')]);
$intents = [];
// === PUBLIC-SAFE INTENTS ONLY ===
// INTENT P1: weval_services_info
if (preg_match('/weval|service|consulting|transformation|accompagn/i', $msg)) {
$intents[] = ['id' => 'weval_services', 'cmd' => 'echo "WEVAL Consulting - Cabinet de transformation digitale base a Casablanca. Services: Consulting strategique, Integration technique, IA souveraine (WEVIA), Infrastructure Cloud, Accompagnement SAP Gold Partner. 200+ projets livres, 8 pays, 97% satisfaction."'];
}
// INTENT P2: partnerships_public (high-level, NO internal state)
if (preg_match('/partenaire|partnership|sap|huawei|vistex|arrow|certif/i', $msg)) {
$intents[] = ['id' => 'partnerships_public', 'cmd' => 'echo "WEVAL est Partenaire Certifie Huawei Cloud + SAP Gold Partner. Nous collaborons avec Vistex (Revenue Management SAP), Arrow/Scaleway (Infrastructure Cloud). Pour details commerciaux, contactez sales@weval-consulting.com"'];
}
// INTENT P3: contact_info
if (preg_match('/contact|email|telephone|adresse|casablanca|rdv|demo/i', $msg)) {
$intents[] = ['id' => 'contact_info', 'cmd' => 'echo "Contact WEVAL: Casablanca, Maroc. Email: contact@weval-consulting.com | Sales: sales@weval-consulting.com | Site: https://weval-consulting.com | RDV: Calendly lie sur la page Contact"'];
}
// INTENT P4: products_weval
if (preg_match('/produit|product|wevia|wevads|marketplace|solution/i', $msg)) {
$intents[] = ['id' => 'products_weval', 'cmd' => 'echo "Produits WEVAL: (1) WEVIA - IA souveraine (13 providers, 0 EUR API lock-in) (2) WEVADS - Plateforme email marketing HCP (3) Ethica - B2B pharma Maghreb. Marketplace: https://weval-consulting.com/marketplace"'];
}
// INTENT P5: time_now (safe utility)
if (preg_match('/heure|time|date.*aujourd|quelle.*heure|what.*time/i', $msg)) {
$intents[] = ['id' => 'time_now', 'cmd' => 'TZ=Africa/Casablanca date "+Il est %H:%M (heure Casablanca, %A %d %B %Y)"'];
}
// INTENT P6: weather_casablanca (safe utility, external API, no secrets)
if (preg_match('/meteo|weather|temperature|pluie|soleil/i', $msg)) {
$intents[] = ['id' => 'weather_info', 'cmd' => 'echo "Pour la meteo precise consultez https://openweathermap.org/city/2538474 (Casablanca). Typiquement 19-26 celsius au printemps."'];
}
// INTENT P7: wevia_about
if (preg_match('/qui.*es.*tu|what.*are.*you|tu.*es.*qui|who.*wevia|a.*propos|about/i', $msg)) {
$intents[] = ['id' => 'wevia_about', 'cmd' => 'echo "Je suis WEVIA, Intelligence Artificielle Cognitive developpee par WEVAL Consulting. Je combine 13 providers LLM (Cerebras, Groq, Mistral, HF...) en cascade souveraine, 0 vendor lock-in, fine-tune propre sur HuggingFace (yace222/weval-brain-v4). Je peux discuter de nos services, produits, et orienter vos projets de transformation digitale."'];
}
// INTENT P8: greeting (avoid timeout on hi/bonjour)
if (preg_match('/^(hi|hello|bonjour|salut|hey|bonsoir|coucou|yo)\s*!?\s*$/iu', trim($msg))) {
$intents[] = ['id' => 'greeting', 'cmd' => 'echo "Bonjour ! Je suis WEVIA, l IA de WEVAL Consulting. Je peux vous renseigner sur nos services, produits (WEVIA, WEVADS, Ethica), partenariats (SAP, Huawei, Vistex), et vous orienter pour un projet de transformation digitale. Posez votre question !"'];
}
// === BLOCKED: ethica/warmup/PMTA/offers/sponsors/brain/vmta/vault/secret/partnerships internal state ===
// If query matches internal data keywords, answer with deflection
$blocked_keywords = '/ethica.*pays|hcp.*maroc|hcp.*alger|warmup.*account|pmta|vmta|offres?.*active|sponsors?|brain.*winner|brain.*sacred|vault|secret|api.*key|bdd|psql|database|postgres|credential|pass(word)?|ssh|token|consent\.wevup|track\.s95|cf.?bypass|powerdns|sentinel|chattr|orchestrator.*sse/i';
if (preg_match($blocked_keywords, $msg)) {
$intents[] = ['id' => 'access_restricted', 'cmd' => 'echo "Cette information est reservee au backend WEVAL interne. Pour acceder aux donnees business (HCP Ethica, campagnes WEVADS, partenariats detaille), contactez sales@weval-consulting.com ou connectez-vous au portail admin avec vos credentials."'];
}
// EXECUTE detected intents
$exec_results = [];
if (!empty($intents)) {
sse(['type' => 'executor', 'status' => 'start', 'intents' => count($intents)]);
foreach ($intents as $intent) {
$out = trim(@shell_exec('timeout 5 bash -c ' . escapeshellarg($intent['cmd']) . ' 2>&1')) ?: '';
$exec_results[$intent['id']] = $out;
sse(['type' => 'exec_result', 'id' => $intent['id'], 'result' => substr($out, 0, 1500)]);
}
sse(['type' => 'executor', 'status' => 'done', 'executed' => count($exec_results)]);
}
// === LLM SYNTHESIS (sovereign, bounded context) ===
$ctx = "CONTEXTE WEVIA PUBLIC:\n";
foreach ($exec_results as $id => $r) $ctx .= "[$id] $r\n";
$ctx .= "\n---\nQUESTION USER: " . $msg;
$ch = curl_init("http://127.0.0.1:4000/v1/chat/completions");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode([
"messages" => [
["role" => "system", "content" => "Tu es WEVIA, IA publique de WEVAL Consulting. REGLES STRICTES: (1) Reponds UNIQUEMENT a partir du contexte public fourni. (2) Si l info n est pas dans le contexte, dis 'Cette information n est pas disponible publiquement' et suggere sales@weval-consulting.com. (3) N INVENTE RIEN sur les chiffres internes (HCP, campagnes, offres). (4) Ne divulgue JAMAIS credentials/secrets/tokens/passwords. (5) Reponds en francais, professionnel, court."],
["role" => "user", "content" => $ctx]
],
"max_tokens" => 400,
"stream" => false
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
]);
$r2 = curl_exec($ch);
curl_close($ch);
$d2 = @json_decode($r2, true);
$txt = $d2["choices"][0]["message"]["content"] ?? "Bonjour ! Je suis WEVIA. Comment puis-je vous aider ?";
sse(["type" => "llm_synthesis", "text" => $txt]);
sse(["type" => "done", "scope" => "public"]);