diff --git a/Plugin/unraid/Tools/api_cache_writer.php b/Plugin/unraid/Tools/api_cache_writer.php index e579cb2..123cbb7 100644 --- a/Plugin/unraid/Tools/api_cache_writer.php +++ b/Plugin/unraid/Tools/api_cache_writer.php @@ -91,6 +91,21 @@ $t = microtime(true); // Call vv_api_data() once — result is static-cached for the rest of this process. vv_api_data(); +// Must stay in step with api/monitor.php's own block. This file is what the Monitor tab +// normally reads — the endpoint only assembles a payload on a cache miss — so a key added there +// and not here leaves the card that consumes it loading forever on every ordinary page load, +// and working on the one request that happens to miss the cache. +$_vv_ai = null; +if (vv_ai_ui_on()) { + require_once $_base . '/include/ai.php'; + $_vv_ai = [ + 'model' => vv_ai_config()['model'], + 'runtime' => vv_ai_runtime_stats(), + 'index' => vv_ai_index_stats(), + 'tokens' => vv_ai_token_stats()['today'] ?? null, + ]; +} + $monitor = [ 'system' => vv_system_info(), 'fallback' => vv_fallback_state(), @@ -118,6 +133,7 @@ $monitor = [ 'vms' => vv_get_vms(), 'docker_folders' => vv_get_docker_folders(), 'remote_hosts' => vv_remote_hosts_stats(), + 'ai' => $_vv_ai, '_api_status' => vv_api_get_status(), 'ts' => time(), ]; diff --git a/Plugin/unraid/api/monitor.php b/Plugin/unraid/api/monitor.php index 04ad0b6..bb852d4 100644 --- a/Plugin/unraid/api/monitor.php +++ b/Plugin/unraid/api/monitor.php @@ -64,6 +64,7 @@ // A flat object of the keys listed in the assembly below, plus _api_status and ts. // // DEPENDS ON +// include/ai.php AI residency and index figures, only when vv_ai_ui_on() // include/config.php vv_cache_read() // include/common.php raw hardware metrics — system, cpu, mem, net, gpu, disks, // ups, parity, containers, transcodes, remote roll-ups @@ -92,6 +93,24 @@ require_once dirname(__DIR__) . '/include/docker_folders.php'; // Pre-warm the API cache with one request (shared by all API-first functions below). vv_api_data(); +// AI residency, for the Monitor tab's AI row. Collected here rather than by that card polling +// api/ai.php on its own cycle: vv_ai_runtime_stats() calls out to Ollama and shells nvidia-smi, +// and this payload is written once a minute by the background writer — a card polling it +// directly would pay both costs every five seconds on every open tab. +// +// Null on any host that is not the AI host or has AI_ENABLED false, which is also what makes the +// row absent rather than empty there. Same shape as every other optional subsystem on this page. +$_vv_ai = null; +if (vv_ai_ui_on()) { + require_once dirname(__DIR__) . '/include/ai.php'; + $_vv_ai = [ + 'model' => vv_ai_config()['model'], + 'runtime' => vv_ai_runtime_stats(), + 'index' => vv_ai_index_stats(), + 'tokens' => vv_ai_token_stats()['today'] ?? null, + ]; +} + echo json_encode([ 'system' => vv_system_info(), 'fallback' => vv_fallback_state(), @@ -119,6 +138,7 @@ echo json_encode([ 'vms' => vv_get_vms(), 'docker_folders' => vv_get_docker_folders(), 'remote_hosts' => vv_remote_hosts_stats(), + 'ai' => $_vv_ai, '_api_status' => vv_api_get_status(), 'ts' => time(), ]); diff --git a/Plugin/unraid/pages/monitor.php b/Plugin/unraid/pages/monitor.php index 3e4aa4c..6e1aa27 100644 --- a/Plugin/unraid/pages/monitor.php +++ b/Plugin/unraid/pages/monitor.php @@ -29,7 +29,15 @@ // // Missing subsystems simply do not render. // No GPU, no UPS, no VMs — the corresponding card is absent rather than showing zeros -// or an error. The page is built to be correct on hardware lacking any given part. +// or an error. The page is built to be correct on hardware lacking any given part. The +// AI row is the same rule applied to a subsystem rather than a device: it exists only +// where vv_ai_ui_on() is true, which is the AI host with AI_ENABLED set. +// +// The assistant here starts on General Chat, where the AI tab starts on Varaverk Assistant. +// Different jobs. The tab is where you go to interrogate the installation; this is the +// box you type an idle question into while watching the dashboard. The worker escalates +// anything genuinely about this install to the strict profile on its own, so starting +// loose costs nothing and starting strict would refuse ordinary questions. // // OPERATIONAL SAFEGUARDS // The health roll-up must not default to healthy. @@ -63,17 +71,22 @@ // RENDERS // System header, CPU per core, memory breakdown, GPU cards, storage pools and array disks, // network, UPS, VMs, containers, transcode sessions, media now-playing, watchdog summary, -// partner node cards +// partner node cards, and — on the AI host only — model residency, saved conversations and +// an assistant // // DEPENDS ON // include/monitor.php required directly for initial render +// include/ai_chat.php the AI row's chat and conversation list, shared with the AI tab // api/monitor.php full payload, slower cycle // api/monitor_fast.php fast-moving values, 1s // api/media.php now-playing sessions // api/docker_action.php container actions // api/flag_toggle.php toggles +// api/ai.php the AI row's turns and conversation store // ═══════════════════════════════════════════════════════════════════════════════════════════════ require_once dirname(__DIR__) . '/include/monitor.php'; +require_once dirname(__DIR__) . '/include/ai_chat.php'; +if (vv_ai_ui_on()) vv_ai_chat_assets(); ?>