185 lines
8.0 KiB
PHP
Executable File
185 lines
8.0 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* S88 Brain Hook — Wire class modules into weval-chatbot-api.php
|
|
* Include this AFTER cognitive-brain.php in the main API
|
|
*
|
|
* Usage in weval-chatbot-api.php:
|
|
* require_once "/opt/wevia-brain/s88-brain-hook.php";
|
|
*/
|
|
|
|
// === PERSONAS ENGINE ===
|
|
$_pe = "/var/www/weval/wevia-ia/consulting-personas-engine.php";
|
|
if(file_exists($_pe)) require_once $_pe;
|
|
|
|
// === CONSULTING BRAIN SOVEREIGN ===
|
|
$_cb = "/var/www/weval/wevia-ia/consulting-brain-sovereign.php";
|
|
if(file_exists($_cb) && !defined("CONSULTING_BRAIN_LOADED")) require_once $_cb;
|
|
|
|
// Initialize singletons (lazy — only created when first used)
|
|
$_brainModules = [];
|
|
|
|
function getBrainModule(string $class): ?object {
|
|
global $_brainModules;
|
|
if (!isset($_brainModules[$class])) {
|
|
if (!class_exists($class)) return null;
|
|
try {
|
|
$_brainModules[$class] = new $class();
|
|
} catch (\Throwable $e) {
|
|
error_log("WEVIA_BRAIN_MODULE_ERR: $class — " . $e->getMessage());
|
|
return null;
|
|
}
|
|
}
|
|
return $_brainModules[$class];
|
|
}
|
|
|
|
/**
|
|
* Run metacognitive analysis on a query
|
|
* Returns: strategy recommendation + confidence calibration
|
|
*/
|
|
function brainMetacognize(string $message, string $intent): array {
|
|
$meta = getBrainModule('MetacognitionEngine');
|
|
if (!$meta) return ['strategy' => 'default', 'confidence' => 0.5];
|
|
try {
|
|
return $meta->analyze($message, $intent);
|
|
} catch (\Throwable $e) { return ['strategy' => 'default', 'confidence' => 0.5]; }
|
|
}
|
|
|
|
/**
|
|
* Optimize context window allocation
|
|
*/
|
|
function brainOptimizeContext(string $sys, string $msg, array $history, string $kbContext): string {
|
|
$ctx = getBrainModule('ContextManager');
|
|
if (!$ctx) return $sys;
|
|
try {
|
|
return $ctx->optimize($sys, $msg, $history, $kbContext);
|
|
} catch (\Throwable $e) { return $sys; }
|
|
}
|
|
|
|
/**
|
|
* Format output optimally
|
|
*/
|
|
function brainFormatOutput(string $response): string {
|
|
$fmt = getBrainModule('OutputFormatter');
|
|
if (!$fmt) return $response;
|
|
try {
|
|
return $fmt->format($response);
|
|
} catch (\Throwable $e) { return $response; }
|
|
}
|
|
|
|
/**
|
|
* Smart error recovery
|
|
*/
|
|
function brainRecoverError(string $error, string $context): ?string {
|
|
$err = getBrainModule('ErrorTaxonomy');
|
|
if (!$err) return null;
|
|
try {
|
|
$classified = $err->classify($error);
|
|
return $err->suggestRecovery($classified, $context);
|
|
} catch (\Throwable $e) { return null; }
|
|
}
|
|
|
|
// === HOOK: Multi-ERP Intelligence (v1.0 2026-03-04) ===
|
|
function hookMultiERPEnrich($sys, $msg, $intent) {
|
|
$erpKeywords = ["erp","sap","oracle","dynamics","odoo","sage","infor","netsuite","workday","peoplesoft"];
|
|
$msgLow = mb_strtolower($msg);
|
|
$matched = array_filter($erpKeywords, fn($k) => strpos($msgLow, $k) !== false);
|
|
if (!$matched) return $sys;
|
|
|
|
$inject = "\n\n[MULTI-ERP EXPERT MODE]\n";
|
|
$inject .= "Tu es expert multi-ERP. Compare toujours avec les alternatives:\n";
|
|
$inject .= "- SAP S/4HANA (leader enterprise, modules FI/CO MM SD PP IS-H)\n";
|
|
$inject .= "- Oracle Cloud ERP (Fusion, TCO competitif, strong analytics)\n";
|
|
$inject .= "- Microsoft Dynamics 365 (integration M365, Power Platform)\n";
|
|
$inject .= "- Odoo (open source, 82 modules, ideal PME)\n";
|
|
$inject .= "- Sage X3 (mid-market industrie/distribution)\n";
|
|
$inject .= "- Infor CloudSuite (sectoriel: industrie, sante)\n";
|
|
$inject .= "Fournis toujours: comparatif TCO, time-to-value, forces/faiblesses par contexte.\n";
|
|
error_log("WEVIA_HOOK: MultiERP activated for: " . implode(",", $matched));
|
|
return $sys . $inject;
|
|
}
|
|
|
|
// === HOOK: Transformation Digitale Sectorielle ===
|
|
function hookTransfoDigitale($sys, $msg, $intent) {
|
|
$tdKeywords = ["transformation","digitale","digital","modernisation","industrie 4","iot","e-sante","omnicanal","automatisation","rpa"];
|
|
$sectors = [
|
|
"banque" => "Core banking, Open Banking PSD2, KYC, neo-banques, conformite ACPR/AMF/BCE",
|
|
"pharma" => "GMP/BPF, pharmacovigilance, clinical trials, HCP marketing, AMM",
|
|
"industrie" => "Industrie 4.0, IoT, digital twin, MES, SCADA, maintenance predictive",
|
|
"retail" => "Omnicanal, unified commerce, marketplace, personnalisation IA",
|
|
"sante" => "DPI, telemedicine, HL7 FHIR, RGPD sante, HDS, HIMSS EMRAM",
|
|
"rh" => "SIRH, recrutement IA, people analytics, employee experience",
|
|
"assurance" => "Insurtech, sinistres IA, souscription digitale, conformite Solvency II",
|
|
];
|
|
$msgLow = mb_strtolower($msg);
|
|
$hasTD = false;
|
|
foreach ($tdKeywords as $k) { if (strpos($msgLow, $k) !== false) { $hasTD = true; break; } }
|
|
if (!$hasTD) return $sys;
|
|
|
|
$inject = "\n\n[TRANSFORMATION DIGITALE EXPERT]\n";
|
|
$inject .= "Couvre systematiquement: diagnostic maturite, roadmap, conduite du changement, KPIs, ROI.\n";
|
|
foreach ($sectors as $sec => $exp) {
|
|
if (strpos($msgLow, $sec) !== false) {
|
|
$inject .= "Secteur detecte ($sec): $exp\n";
|
|
}
|
|
}
|
|
error_log("WEVIA_HOOK: TransfoDigitale activated");
|
|
return $sys . $inject;
|
|
}
|
|
|
|
// === HOOK: Code Distant Quality (Opus-level coding) ===
|
|
function hookCodeQuality($sys, $msg, $intent) {
|
|
if (!preg_match("/(code|script|programme|fonction|api|endpoint|crud|class|module)/i", $msg)) return $sys;
|
|
|
|
$inject = "\n\n[OPUS CODING STANDARD]\n";
|
|
$inject .= "Genere du code de qualite production:\n";
|
|
$inject .= "- Type hints et docstrings sur chaque fonction\n";
|
|
$inject .= "- Error handling try/except complet\n";
|
|
$inject .= "- Logging structure (pas de print)\n";
|
|
$inject .= "- Validation des inputs (Pydantic si Python)\n";
|
|
$inject .= "- Tests unitaires inclus\n";
|
|
$inject .= "- Commentaires en francais\n";
|
|
$inject .= "- Design patterns appropries (Factory, Strategy, Observer)\n";
|
|
$inject .= "- Security best practices (SQL injection, XSS, CSRF)\n";
|
|
error_log("WEVIA_HOOK: CodeQuality activated");
|
|
return $sys . $inject;
|
|
}
|
|
|
|
// === HOOK: Image Generation Quality Guard ===
|
|
function hookImageQualityGuard($sys, $msg) {
|
|
if (!preg_match("/(image|photo|genere.*image|dessine|illustr|logo|visuel)/i", $msg)) return $sys;
|
|
|
|
$inject = "\n\n[IMAGE QUALITY GUARD]\n";
|
|
$inject .= "Pour les images generees:\n";
|
|
$inject .= "- Decris EXACTEMENT ce que tu veux generer avant de lancer\n";
|
|
$inject .= "- Evite les visages humains realistes (risque hallucination)\n";
|
|
$inject .= "- Privilegie: schemas, diagrammes, logos, paysages, architectures\n";
|
|
$inject .= "- Pour les photos de personnes: utilise des silhouettes ou illustrations\n";
|
|
$inject .= "- Ajoute toujours le contexte professionnel dans le prompt\n";
|
|
error_log("WEVIA_HOOK: ImageQualityGuard activated");
|
|
return $sys . $inject;
|
|
}
|
|
|
|
// === HOOK: Domain Completeness Booster ===
|
|
function hookDomainBoost($sys, $msg) {
|
|
$msgLow = mb_strtolower($msg);
|
|
if (!preg_match("/(service|domaine|expertise|competence|offre|propose|catalogue)/i", $msg)) return $sys;
|
|
|
|
$inject = "\n\n[WEVAL DOMAIN COMPLETENESS]\n";
|
|
$inject .= "WEVAL Consulting couvre 12 domaines:\n";
|
|
$inject .= "1. SAP & ERP multi-vendeur (SAP, Oracle, Dynamics, Odoo)\n";
|
|
$inject .= "2. Cloud Computing multi-provider (AWS, Azure, Huawei, OVH)\n";
|
|
$inject .= "3. Cybersecurite (ISO 27001, RGPD, NIS2, pentest)\n";
|
|
$inject .= "4. IA & Data Science (LLM, RAG, MLOps, analytics)\n";
|
|
$inject .= "5. Formation certifiante (SAP, Cloud, Cyber, IA, DevOps)\n";
|
|
$inject .= "6. Marketing Digital (SEO, SEM, email marketing, social)\n";
|
|
$inject .= "7. Transformation Digitale sectorielle\n";
|
|
$inject .= "8. Conseil Management (OKR, Lean, BSC, change management)\n";
|
|
$inject .= "9. Data Engineering (ETL, BI, data governance)\n";
|
|
$inject .= "10. DevOps & Platform Engineering (K8s, CI/CD, IaC)\n";
|
|
$inject .= "11. Integration & Outsourcing IT (TMA, nearshore)\n";
|
|
$inject .= "12. E-Marketing Pharma (HCP, compliance sante)\n";
|
|
$inject .= "TOUJOURS mentionner les 12 domaines quand on demande les services complets.\n";
|
|
error_log("WEVIA_HOOK: DomainBoost activated");
|
|
return $sys . $inject;
|
|
}
|