mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
feat: 224 voice intents seeded; fix KBEngine fillTemplate — user_title, pending_count, system/network facts
This commit is contained in:
+27
-12
@@ -45,34 +45,49 @@ class KBEngine {
|
||||
'current_date' => date('l, F j Y'),
|
||||
];
|
||||
|
||||
// Fetch all facts for this category (and null-category universal facts)
|
||||
// Load user address preference
|
||||
$prefRows = JarvisDB::query(
|
||||
"SELECT pref_key, pref_value FROM kb_preferences WHERE pref_key IN ('user_name','user_title')"
|
||||
);
|
||||
$prefs = [];
|
||||
foreach ($prefRows ?? [] as $p) { $prefs[$p['pref_key']] = $p['pref_value']; }
|
||||
$builtins['user_title'] = $prefs['user_title'] ?? $prefs['user_name'] ?? 'Sir';
|
||||
$builtins['user_name'] = $prefs['user_name'] ?? 'Myron';
|
||||
|
||||
// Computed builtins
|
||||
$pendingRow = JarvisDB::single("SELECT COUNT(*) cnt FROM tasks WHERE status NOT IN ('done','cancelled')");
|
||||
$builtins['pending_count'] = (string)($pendingRow['cnt'] ?? 0);
|
||||
$overdueRow = JarvisDB::single("SELECT COUNT(*) cnt FROM tasks WHERE due_date < CURDATE() AND status NOT IN ('done','cancelled')");
|
||||
$builtins['overdue_count'] = (string)($overdueRow['cnt'] ?? 0);
|
||||
|
||||
// Fetch all facts for this category
|
||||
$facts = [];
|
||||
if ($category) {
|
||||
$rows = JarvisDB::query(
|
||||
'SELECT fact_key, fact_value FROM kb_facts
|
||||
WHERE category = ?',
|
||||
WHERE category = ? AND (expires_at IS NULL OR expires_at > NOW())',
|
||||
[$category]
|
||||
);
|
||||
foreach ($rows as $r) {
|
||||
foreach ($rows ?? [] as $r) {
|
||||
$facts[$r['fact_key']] = $r['fact_value'];
|
||||
}
|
||||
}
|
||||
// Also pull network facts for network tokens used in any template
|
||||
// Pull network facts if template uses them
|
||||
if (strpos($template, '{online_count}') !== false || strpos($template, '{total_count}') !== false) {
|
||||
$netRows = JarvisDB::query(
|
||||
"SELECT fact_key, fact_value FROM kb_facts
|
||||
WHERE category='network'"
|
||||
);
|
||||
foreach ($netRows as $r) {
|
||||
$facts[$r['fact_key']] = $r['fact_value'];
|
||||
}
|
||||
$netRows = JarvisDB::query("SELECT fact_key, fact_value FROM kb_facts WHERE category='network' AND (expires_at IS NULL OR expires_at > NOW())");
|
||||
foreach ($netRows ?? [] as $r) { $facts[$r['fact_key']] = $r['fact_value']; }
|
||||
}
|
||||
// Pull system facts if template uses them
|
||||
if (preg_match('/\{(cpu_usage|mem_|disk_|uptime|load_)\w*\}/', $template)) {
|
||||
$sysRows = JarvisDB::query("SELECT fact_key, fact_value FROM kb_facts WHERE category='system' AND (expires_at IS NULL OR expires_at > NOW())");
|
||||
foreach ($sysRows ?? [] as $r) { $facts[$r['fact_key']] = $r['fact_value']; }
|
||||
}
|
||||
|
||||
$allTokens = array_merge($builtins, $facts);
|
||||
|
||||
// Replace placeholders
|
||||
return preg_replace_callback('/\{([a-z0-9_]+)\}/', function ($m) use ($allTokens) {
|
||||
return $allTokens[$m[1]] ?? '[unknown]';
|
||||
return $allTokens[$m[1]] ?? '';
|
||||
}, $template);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user