Let one gate decide every AI surface, so switching AI off actually removes all of it

The Tools card adopted the AI scripts on the host check alone, and api/ai.php only
tested AI_ENABLED in front of ask, so a disabled subsystem still had rows to run and
an endpoint that answered.
This commit is contained in:
Gmer4Lfe
2026-08-07 09:49:31 -04:00
parent bf7a2cc911
commit be306cf86c
5 changed files with 35 additions and 16 deletions
+13
View File
@@ -268,6 +268,19 @@ function vv_is_ai_host(): bool {
return vv_detect_host() === 'host1';
}
// Whether the UI may offer anything AI at all: the right host, with the master switch on. Every
// AI surface asks this one question — the AI tab, the assistant dock on the Scheduler, and the
// two AI rows on the Tools card — so AI off means AI gone, not gone from most places.
//
// It lives here rather than in include/ai.php because the pages that need it do not all load
// that file; the Scheduler loads only config.php, and a gate that silently answers false where
// its definition is missing is worse than no gate. Reads AI_ENABLED directly for the same
// reason. Fail-closed on anything but the literal "true", matching the conf's own contract.
function vv_ai_ui_on(): bool {
return vv_is_ai_host()
&& strtolower(trim(vv_conf_vars()['AI_ENABLED'] ?? 'false')) === 'true';
}
function vv_read_conf_raw(string $filename): string {
$path = CONF_DIR . '/' . $filename;
return file_exists($path) ? file_get_contents($path) : '';
+6 -6
View File
@@ -319,12 +319,12 @@ function vv_tools_scripts(): array {
// chain. Moving the file to match the UI would break the grouping that explains it.
$ADOPTED = ['System_Essentials/server_reboot.sh'];
// The AI tools are adopted only where the index and the model actually live. Elsewhere they
// are two rows that can only ever fail — the retrieval index is not synced between hosts and
// Ollama runs on one of them. vv_is_ai_host() comes from include/ai.php, which the page loads
// but this file does not require; absent it, assume not, because showing a tool that cannot
// work is worse than omitting one that could.
if (function_exists('vv_is_ai_host') && vv_is_ai_host()) {
// The AI tools are adopted only where the index and the model actually live, and only while
// the subsystem is switched on. Elsewhere they are two rows that can only ever fail — the
// retrieval index is not synced between hosts, Ollama runs on one of them, and both scripts
// refuse on their own unless AI_ENABLED is true. vv_ai_ui_on() is the same gate the AI tab
// and the assistant dock use, so AI off means no AI anywhere in the UI, not most of it.
if (vv_ai_ui_on()) {
array_push($ADOPTED, 'AI/ai_index.sh', 'AI/ai_query.sh');
}