From e189a64dddf53ee00a811c5da43ed91e690ebb72 Mon Sep 17 00:00:00 2001 From: Myron Blair Date: Sat, 30 May 2026 03:41:54 +0000 Subject: [PATCH] Fix network scan: return real DB data and queue PVE1 netscan instead of fabricating --- api/endpoints/chat.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/api/endpoints/chat.php b/api/endpoints/chat.php index 9126e8c..f298380 100644 --- a/api/endpoints/chat.php +++ b/api/endpoints/chat.php @@ -494,6 +494,40 @@ if (!$reply) { } } +// ── Tier 1b: Action Intents — handled directly, no LLM ────────────────── +if (!$reply) { + if (!isset($matched)) $matched = KBEngine::match($message); + if ($matched && $matched['action'] === 'action') { + switch ($matched['intent']) { + + case 'network_scan': + $online = JarvisDB::single( + "SELECT COUNT(*) cnt FROM network_devices WHERE status='online' AND last_seen > DATE_SUB(NOW(), INTERVAL 15 MINUTE)" + ); + $total = JarvisDB::single( + "SELECT COUNT(*) cnt FROM network_devices WHERE last_seen > DATE_SUB(NOW(), INTERVAL 15 MINUTE)" + ); + // Queue netscan to PVE1 agent for immediate refresh + $pve1 = JarvisDB::single( + "SELECT agent_id FROM registered_agents WHERE ip_address='10.48.200.90' AND status='online' LIMIT 1" + ); + if ($pve1) { + JarvisDB::execute( + "INSERT INTO agent_commands (agent_id, command_type, command_data, status) VALUES (?,?,?,?)", + [$pve1['agent_id'], 'shell', json_encode(['command'=>'/usr/local/bin/jarvis-netscan.sh','allowed'=>true]), 'pending'] + ); + } + $o = (int)($online['cnt'] ?? 0); + $t = (int)($total['cnt'] ?? 0); + $reply = "Network status as of last scan: {$o} of {$t} devices online on 10.48.200.0/24, {$userAddr}. " . + ($pve1 ? 'Fresh scan dispatched to PVE1 — the network panel will update in approximately 40 seconds.' : + 'Automatic scan via PVE1 runs every 3 minutes.'); + $source = 'intent:network_scan'; + break; + } + } +} + // ── Tier 2: Ollama local LLM (fast local fallback) ─────────────────────── if (!$reply && defined('OLLAMA_HOST') && OLLAMA_HOST) { $ollamaHost = OLLAMA_HOST;