Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Add Verify Patrol button to Assistant & Patrol settings

rcourtmanc01282e8c539
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index bcb49bf23d..7961ff68a3 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -868,7 +868,12 @@ prompt explain the same operator-facing priority.
## Completion Obligations
-1. Update guardrail tests when new shared primitives are added
+1. Update guardrail tests when new shared primitives are added, including
+ new Settings controls that drive backend verification surfaces (for
+ example the Verify Patrol button in
+ `AIModelSelectionSection.tsx`, which must drive the typed
+ `runPatrolPreflight` client through `useAISettingsState.ts` rather
+ than inlining fetch calls in the section component)
2. Keep top-level settings surfaces routed through the canonical settings shell
and maintain both `frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts`
plus `tests/integration/tests/15-settings-shell-consistency.spec.ts`
diff --git a/frontend-modern/src/components/Settings/AIModelSelectionSection.tsx b/frontend-modern/src/components/Settings/AIModelSelectionSection.tsx
index 1f9bd90aee..76b3c10f17 100644
--- a/frontend-modern/src/components/Settings/AIModelSelectionSection.tsx
+++ b/frontend-modern/src/components/Settings/AIModelSelectionSection.tsx
@@ -11,6 +11,100 @@ interface AIModelSelectionSectionProps {
state: AISettingsState;
}
+const PatrolPreflightControl: Component<{ state: AISettingsState }> = (controlProps) => {
+ const { state } = controlProps;
+ const result = state.patrolPreflightResult;
+
+ const tone = () => {
+ const r = result();
+ if (!r) return 'idle';
+ if (r.success) return 'success';
+ if (r.cause === 'model_tool_support_unverified') return 'warning';
+ return 'error';
+ };
+
+ const toneClasses = () => {
+ switch (tone()) {
+ case 'success':
+ return 'border-green-200 dark:border-green-800 bg-green-50 dark:bg-green-900 text-green-700 dark:text-green-300';
+ case 'warning':
+ return 'border-amber-200 dark:border-amber-800 bg-amber-50 dark:bg-amber-900 text-amber-700 dark:text-amber-300';
+ case 'error':
+ return 'border-red-200 dark:border-red-800 bg-red-50 dark:bg-red-900 text-red-700 dark:text-red-300';
+ default:
+ return '';
+ }
+ };
+
+ const headline = () => {
+ const r = result();
+ if (!r) return '';
+ if (r.success) {
+ return 'Tool calling verified';
+ }
+ if (r.cause === 'model_tool_support_unverified') {
+ return 'Provider accepted the request but the model did not call the tool';
+ }
+ return r.message || 'Patrol preflight failed';
+ };
+
+ const detail = () => {
+ const r = result();
+ if (!r) return '';
+ return r.summary || r.message || '';
+ };
+
+ const formatDuration = (ms: number) => {
+ if (ms < 1000) return `${ms}ms`;
+ return `${(ms / 1000).toFixed(1)}s`;
+ };
+
+ return (
+ <div class="mt-2 flex flex-col gap-2">
+ <div class="flex items-center justify-between gap-2">
+ <p class="text-[11px] text-muted">
+ Verify that this Patrol model can actually call tools — different from{' '}
+ <span class="font-medium">Run Preflight</span>, which only checks each provider's
+ connection.
+ </p>
+ <button
+ type="button"
+ onClick={() => void state.runPatrolToolPreflight()}
+ disabled={state.patrolPreflightRunning() || state.saving()}
+ class="inline-flex min-h-9 items-center rounded-md px-3 py-1.5 text-sm bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300 hover:bg-blue-200 dark:hover:bg-blue-800 disabled:opacity-50 whitespace-nowrap"
+ >
+ {state.patrolPreflightRunning() ? 'Verifying...' : 'Verify Patrol'}
+ </button>
+ </div>
+ <Show when={result()}>
+ {(r) => (
+ <div class={`rounded border px-3 py-2 ${toneClasses()}`}>
+ <div class="flex items-baseline justify-between gap-2">
+ <p class="text-xs font-medium">{headline()}</p>
+ <Show when={r().duration_ms > 0}>
+ <span class="text-[11px] opacity-80">{formatDuration(r().duration_ms)}</span>
+ </Show>
+ </div>
+ <Show when={detail()}>
+ <p class="text-[11px] mt-1 opacity-90">{detail()}</p>
+ </Show>
+ <Show when={r().recommendation}>
+ <p class="text-[11px] mt-1 opacity-90">{r().recommendation}</p>
+ </Show>
+ <Show when={r().provider || r().model}>
+ <p class="text-[11px] mt-1 opacity-70">
+ {r().provider}
+ {r().provider && r().model ? ' · ' : ''}
+ {r().model}
+ </p>
+ </Show>
+ </div>
+ )}
+ </Show>
+ </div>
+ );
+};
+
export const AIModelSelectionSection: Component<AIModelSelectionSectionProps> = (props) => {
const { state } = props;
const modelLabel = (modelId: string) => {
@@ -277,6 +371,7 @@ export const AIModelSelectionSection: Component<AIModelSelectionSectionProps> =
dropdownClass={pickerDropdownClass}
/>
</Show>
+ <PatrolPreflightControl state={state} />
</div>
</div>
</Show>
diff --git a/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts b/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
index 53688ea87e..33f06ed2ba 100644
--- a/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
+++ b/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
@@ -227,6 +227,23 @@ describe('settings architecture guardrails', () => {
expect(aiSettingsStateSource).not.toContain('OpenRouter returned 401');
});
+ it('keeps Patrol tool-call preflight wired through the canonical settings state', () => {
+ // The Verify Patrol button must drive the canonical
+ // /api/ai/patrol/preflight endpoint via the typed runPatrolPreflight
+ // client and surface the result through state, not via inline fetch
+ // calls in the section component.
+ expect(aiSettingsStateSource).toContain('runPatrolPreflight');
+ expect(aiSettingsStateSource).toContain('runPatrolToolPreflight');
+ expect(aiSettingsStateSource).toContain('patrolPreflightResult');
+ expect(aiSettingsStateSource).toContain('patrolPreflightRunning');
+ expect(aiModelSelectionSectionSource).toContain('PatrolPreflightControl');
+ expect(aiModelSelectionSectionSource).toContain('runPatrolToolPreflight');
+ // The amber soft-warning tone is the operator's signal that the
+ // provider accepted the request but the model did not call the tool.
+ expect(aiModelSelectionSectionSource).toContain('model_tool_support_unverified');
+ expect(aiModelSelectionSectionSource).not.toContain('fetch(\'/api/ai/patrol/preflight');
+ });
+
it('keeps contextual settings feature gates free of retired commercial telemetry wrappers', () => {
for (const source of [
agentProfilesPanelSource,
diff --git a/frontend-modern/src/components/Settings/useAISettingsState.ts b/frontend-modern/src/components/Settings/useAISettingsState.ts
index fd1bbe8924..1448f11642 100644
--- a/frontend-modern/src/components/Settings/useAISettingsState.ts
+++ b/frontend-modern/src/components/Settings/useAISettingsState.ts
@@ -2,6 +2,7 @@ import { createMemo, createSignal, onMount } from 'solid-js';
import { createStore } from 'solid-js/store';
import { AIAPI } from '@/api/ai';
import { AIChatAPI, type ChatSession, type FileChange } from '@/api/aiChat';
+import { runPatrolPreflight, type PatrolPreflightResponse } from '@/api/patrol';
import {
AI_PROVIDERS,
createInitialProviderHealth,
@@ -242,6 +243,9 @@ export const useAISettingsState = () => {
);
const [preflightRunning, setPreflightRunning] = createSignal(false);
const [preflightLastCheckedAt, setPreflightLastCheckedAt] = createSignal<number | null>(null);
+ const [patrolPreflightRunning, setPatrolPreflightRunning] = createSignal(false);
+ const [patrolPreflightResult, setPatrolPreflightResult] =
+ createSignal<PatrolPreflightResponse | null>(null);
const [showSetupModal, setShowSetupModal] = createSignal(false);
const [setupProvider, setSetupProvider] = createSignal<AIProvider>('anthropic');
@@ -561,6 +565,32 @@ export const useAISettingsState = () => {
}
};
+ // runPatrolToolPreflight verifies the configured Patrol provider+model
+ // can actually call tools end-to-end. Distinct from runProviderPreflight,
+ // which only confirms each provider's model catalog is reachable.
+ const runPatrolToolPreflight = async () => {
+ setPatrolPreflightRunning(true);
+ try {
+ const result = await runPatrolPreflight();
+ setPatrolPreflightResult(result);
+ } catch (error) {
+ const message =
+ error instanceof Error && error.message
+ ? error.message
+ : 'Pulse could not run the Patrol tool-call preflight.';
+ setPatrolPreflightResult({
+ success: false,
+ tool_call_observed: false,
+ duration_ms: 0,
+ message,
+ summary:
+ 'Pulse could not reach the preflight endpoint. Check that the backend is running and you have settings-write permission.',
+ });
+ } finally {
+ setPatrolPreflightRunning(false);
+ }
+ };
+
const loadSettings = async () => {
setLoading(true);
setLoadError(false);
@@ -1074,6 +1104,8 @@ export const useAISettingsState = () => {
loadSettings,
modelsError,
modelsLoading,
+ patrolPreflightResult,
+ patrolPreflightRunning,
preflightLastCheckedAt,
preflightRunning,
providerHealth,
@@ -1081,6 +1113,7 @@ export const useAISettingsState = () => {
providerTestResult,
resetForm,
runProviderPreflight,
+ runPatrolToolPreflight,
saving,
selectedChatSession,
selectedSessionId,