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.

Track AI runtime store ownership

rcourtman51b076a592df
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index a29afca058..3ff18ba967 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -194,6 +194,10 @@ reads used by chat, Patrol, and AI usage surfaces, while
`frontend-modern/src/components/Settings/useAISettingsState.ts` remains the
write-side settings owner. AI-owned surfaces must not fork their own mount-time
settings/model fetch loops once this store exists.
+`docs/release-control/v6/internal/subsystems/registry.json` must therefore keep
+`frontend-modern/src/stores/aiRuntimeState.ts` and
+`frontend-modern/src/components/AI/Chat/` on the explicit AI runtime proof
+route instead of leaving the shared read model or chat shell unowned.
That same settings/runtime boundary now also governs BYOK first-run setup:
`frontend-modern/src/components/Settings/useAISettingsState.ts` may send only
provider credentials or base URLs when the operator connects a provider, and
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 0df82022e4..9e98f1e344 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -10,6 +10,7 @@
"status_file": "docs/release-control/v6/internal/status.json",
"registry_file": "docs/release-control/v6/internal/subsystems/registry.json",
"dependency_subsystem_ids": [
+ "ai-runtime",
"cloud-paid",
"patrol-intelligence"
]
@@ -373,6 +374,10 @@ Own canonical runtime payload shapes between backend and frontend.
store after an owned settings mutation, but they must not reintroduce
page-local mount loops that fetch `/api/settings/ai` or `/api/ai/models`
separately for chat, Patrol, and cost/budget views.
+ The shared chat shell under `frontend-modern/src/components/AI/Chat/`
+ stays on that same read-side contract: it may coordinate assistant UI
+ state, but it must not reopen page-local fetch loops against
+ `/api/settings/ai` or `/api/ai/models` outside the shared runtime store.
23. Keep API-backed first-target onboarding canonical on that same shared
infrastructure-settings boundary:
`frontend-modern/src/components/Settings/infrastructureOperationsModel.tsx`,
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index 49913c1c04..ea85a4323e 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -954,12 +954,14 @@
"lane": "L6",
"contract": "docs/release-control/v6/internal/subsystems/ai-runtime.md",
"owned_prefixes": [
+ "frontend-modern/src/components/AI/Chat/",
"internal/ai/"
],
"owned_files": [
"frontend-modern/src/api/ai.ts",
"frontend-modern/src/api/patrol.ts",
"frontend-modern/src/components/AI/AICostDashboard.tsx",
+ "frontend-modern/src/stores/aiRuntimeState.ts",
"frontend-modern/src/utils/aiChatPresentation.ts",
"frontend-modern/src/utils/aiControlLevelPresentation.ts",
"frontend-modern/src/utils/aiCostPresentation.ts",
@@ -1015,6 +1017,24 @@
"frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts"
]
},
+ {
+ "id": "ai-chat-runtime-read-model",
+ "label": "AI chat and shared runtime read model proof",
+ "match_prefixes": [
+ "frontend-modern/src/components/AI/Chat/"
+ ],
+ "match_files": [
+ "frontend-modern/src/stores/aiRuntimeState.ts"
+ ],
+ "allow_same_subsystem_tests": false,
+ "test_prefixes": [
+ "frontend-modern/src/components/AI/Chat/__tests__/"
+ ],
+ "exact_files": [
+ "frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx",
+ "tests/integration/tests/42-vmware-ai-chat-read-recovery.spec.ts"
+ ]
+ },
{
"id": "ai-presentation-helpers",
"label": "AI presentation helper proof",
diff --git a/frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx b/frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx
index 192fbb6fc1..1337f95e5b 100644
--- a/frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx
+++ b/frontend-modern/src/components/AI/__tests__/AICostDashboard.test.tsx
@@ -301,6 +301,29 @@ describe('AICostDashboard', () => {
expect(budgetCard.textContent).toMatch(/10\.00/);
});
+ it('reloads shared runtime settings after the runtime store resets', async () => {
+ getSettingsMock
+ .mockResolvedValueOnce(baseSettings({ cost_budget_usd_30d: 10 }))
+ .mockResolvedValueOnce(baseSettings({ cost_budget_usd_30d: 25 }));
+
+ const firstMount = renderDashboard();
+ await waitFor(() => {
+ expect(screen.getByText('Budget alert (USD per 30d)')).toBeInTheDocument();
+ });
+ let budgetCard = screen.getByText('Budget alert (USD per 30d)').closest('.p-3')!;
+ expect(budgetCard.textContent).toMatch(/10\.00/);
+
+ firstMount.unmount();
+ resetAIRuntimeState();
+
+ renderDashboard();
+ await waitFor(() => {
+ expect(getSettingsMock).toHaveBeenCalledTimes(2);
+ });
+ budgetCard = screen.getByText('Budget alert (USD per 30d)').closest('.p-3')!;
+ expect(budgetCard.textContent).toMatch(/25\.00/);
+ });
+
it('shows over-budget warning when spend exceeds budget', async () => {
getCostSummaryMock.mockResolvedValue(
baseSummary({
diff --git a/frontend-modern/src/stores/aiRuntimeState.ts b/frontend-modern/src/stores/aiRuntimeState.ts
new file mode 100644
index 0000000000..142e4fc988
--- /dev/null
+++ b/frontend-modern/src/stores/aiRuntimeState.ts
@@ -0,0 +1,143 @@
+import { createSignal } from 'solid-js';
+import { AIAPI } from '@/api/ai';
+import { eventBus } from '@/stores/events';
+import type { AISettings, ModelInfo } from '@/types/ai';
+import { logger } from '@/utils/logger';
+
+const [aiRuntimeSettings, setAIRuntimeSettings] = createSignal<AISettings | null>(null);
+const [aiRuntimeSettingsLoading, setAIRuntimeSettingsLoading] = createSignal(false);
+const [aiRuntimeSettingsLoaded, setAIRuntimeSettingsLoaded] = createSignal(false);
+const [aiRuntimeSettingsLoadError, setAIRuntimeSettingsLoadError] = createSignal<Error | null>(null);
+
+const [aiRuntimeModels, setAIRuntimeModels] = createSignal<ModelInfo[]>([]);
+const [aiRuntimeModelsLoading, setAIRuntimeModelsLoading] = createSignal(false);
+const [aiRuntimeModelsLoaded, setAIRuntimeModelsLoaded] = createSignal(false);
+const [aiRuntimeModelsError, setAIRuntimeModelsError] = createSignal('');
+
+let inFlightSettingsLoad: Promise<AISettings | null> | null = null;
+let inFlightModelsLoad: Promise<ModelInfo[]> | null = null;
+
+function resetAIRuntimeState() {
+ setAIRuntimeSettings(null);
+ setAIRuntimeSettingsLoading(false);
+ setAIRuntimeSettingsLoaded(false);
+ setAIRuntimeSettingsLoadError(null);
+ setAIRuntimeModels([]);
+ setAIRuntimeModelsLoading(false);
+ setAIRuntimeModelsLoaded(false);
+ setAIRuntimeModelsError('');
+ inFlightSettingsLoad = null;
+ inFlightModelsLoad = null;
+}
+
+export function syncAIRuntimeSettings(next: AISettings | null) {
+ setAIRuntimeSettings(next);
+ setAIRuntimeSettingsLoadError(null);
+ setAIRuntimeSettingsLoaded(true);
+ setAIRuntimeSettingsLoading(false);
+}
+
+export function syncAIRuntimeModels(next: ModelInfo[], error = '') {
+ setAIRuntimeModels(next);
+ setAIRuntimeModelsError(error);
+ setAIRuntimeModelsLoaded(true);
+ setAIRuntimeModelsLoading(false);
+}
+
+export function clearAIRuntimeModels() {
+ syncAIRuntimeModels([]);
+}
+
+export async function loadAIRuntimeSettings(force = false): Promise<AISettings | null> {
+ if (inFlightSettingsLoad) {
+ if (!force) {
+ return inFlightSettingsLoad;
+ }
+ await inFlightSettingsLoad;
+ }
+
+ if (aiRuntimeSettingsLoaded() && !force) {
+ return aiRuntimeSettings();
+ }
+
+ setAIRuntimeSettingsLoading(true);
+ const request = (async () => {
+ try {
+ const next = await AIAPI.getSettings();
+ syncAIRuntimeSettings(next);
+ return next;
+ } catch (error) {
+ const normalized = error instanceof Error ? error : new Error(String(error));
+ setAIRuntimeSettingsLoadError(normalized);
+ setAIRuntimeSettingsLoaded(true);
+ setAIRuntimeSettingsLoading(false);
+ logger.debug('[aiRuntimeState] Failed to load AI settings', normalized);
+ throw normalized;
+ }
+ })();
+
+ inFlightSettingsLoad = request;
+ try {
+ return await request;
+ } finally {
+ if (inFlightSettingsLoad === request) {
+ inFlightSettingsLoad = null;
+ }
+ }
+}
+
+export async function loadAIRuntimeModels(force = false): Promise<ModelInfo[]> {
+ if (inFlightModelsLoad) {
+ if (!force) {
+ return inFlightModelsLoad;
+ }
+ await inFlightModelsLoad;
+ }
+
+ if (aiRuntimeModelsLoaded() && !force) {
+ return aiRuntimeModels();
+ }
+
+ setAIRuntimeModelsLoading(true);
+ setAIRuntimeModelsError('');
+ const request = (async () => {
+ try {
+ const result = await AIAPI.getModels();
+ syncAIRuntimeModels(result.models ?? [], result.error ?? '');
+ return result.models ?? [];
+ } catch (error) {
+ const message = error instanceof Error ? error.message : 'Failed to load models.';
+ setAIRuntimeModelsError(message);
+ setAIRuntimeModels([]);
+ setAIRuntimeModelsLoaded(true);
+ setAIRuntimeModelsLoading(false);
+ logger.debug('[aiRuntimeState] Failed to load AI models', error);
+ throw error;
+ }
+ })();
+
+ inFlightModelsLoad = request;
+ try {
+ return await request;
+ } finally {
+ if (inFlightModelsLoad === request) {
+ inFlightModelsLoad = null;
+ }
+ }
+}
+
+eventBus.on('org_switched', () => {
+ resetAIRuntimeState();
+});
+
+export {
+ aiRuntimeModels,
+ aiRuntimeModelsError,
+ aiRuntimeModelsLoaded,
+ aiRuntimeModelsLoading,
+ aiRuntimeSettings,
+ aiRuntimeSettingsLoaded,
+ aiRuntimeSettingsLoading,
+ aiRuntimeSettingsLoadError,
+ resetAIRuntimeState,
+};