Files
weval-l99/v101_enrich_catalog.py
2026-04-24 04:38:58 +02:00

58 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""V101 - Enrich agents-catalog-api.php to include business agents from enterprise-model
Doctrine #14: ADDITIF PUR - no overwrite, only add new logic
"""
import re
path = "/var/www/html/api/agents-catalog-api.php"
with open(path, "r", encoding="utf-8") as f:
code = f.read()
if "// V101 BUSINESS AGENTS" in code:
print("ALREADY ENRICHED")
exit(0)
# Find insertion point: before "// Categories count"
marker = '// Categories count'
if marker not in code:
print("MARKER NOT FOUND")
exit(1)
addition = '''// V101 BUSINESS AGENTS - parse enterprise-model.html AG variable (572 agents post-V93)
$em_path = "/var/www/html/enterprise-model.html";
if (file_exists($em_path)) {
$em = file_get_contents($em_path);
// Extract agent names: {n:'Agent Name',rm:'dept',...
preg_match_all("/\\{n:'([^']+)',rm:'([^']+)'/", $em, $m);
$added_biz = 0;
$seen = [];
for ($i = 0; $i < count($m[1]); $i++) {
$name = $m[1][$i];
$dept = $m[2][$i];
if ($dept === "dead") continue; // Skip dead agents (V93 fix)
if (isset($seen[$name])) continue; // Dedup
$seen[$name] = 1;
$agents[] = ["name" => $name, "desc" => "Business agent - dept: $dept", "cat" => "business", "status" => "ready", "icon" => ""];
$added_biz++;
}
// Also parse big4 domains
$big4 = "/var/www/html/wevia-em-big4.html";
if (file_exists($big4)) {
$b = file_get_contents($big4);
preg_match_all("/\\{n:'([^']+)'/", $b, $mb);
foreach (array_unique($mb[1]) as $dom) {
if (!isset($seen[$dom])) {
$agents[] = ["name" => "Big4: $dom", "desc" => "Big4 Enterprise Model domain", "cat" => "big4", "status" => "ready", "icon" => ""];
$seen[$dom] = 1;
}
}
}
}
'''
code = code.replace(marker, addition + marker, 1)
with open(path, "w", encoding="utf-8") as f:
f.write(code)
print(f"PATCHED: added business agents logic. Size: {len(code)}")