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 Assistant provider route recovery

rcourtman3209a08cf05e
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index bf35efcb53..78e7886cc8 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -75,8 +75,9 @@ runtime cost control, and shared AI transport surfaces.
the selected provider/model through `/api/ai/test/{provider}` before the
next user send. That check must use neutral provider diagnostic copy owned
by `internal/ai/`, not Patrol runtime-finding wording, and the drawer may
- surface the result as actionable settings/retry status without converting
- it into assistant-authored output or disabling model-owned chat by default.
+ surface the result as actionable retry/settings status plus same-model
+ configured-provider alternatives without converting it into
+ assistant-authored output or disabling model-owned chat by default.
4. Add or change Patrol, alert-analysis, or remediation transport through `internal/api/ai_handlers.go`, `internal/api/ai_intelligence_handlers.go`, and `frontend-modern/src/api/patrol.ts`
Provider preflight diagnostics returned from `internal/api/ai_handlers.go`
must reuse the Patrol runtime failure classifier in `internal/ai/` and
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
index 9f5874f91c..25acff5ff9 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -397,6 +397,63 @@ describe('AIChat', () => {
);
});
+ it('offers an equivalent configured-provider route when the selected provider fails', async () => {
+ mockAIAPI.getSettings.mockResolvedValue({
+ model: 'deepseek:deepseek-v4-pro',
+ chat_model: '',
+ control_level: 'read_only',
+ autonomous_mode: false,
+ discovery_enabled: true,
+ configured_providers: ['deepseek', 'openrouter'],
+ });
+ mockAIAPI.getModels.mockResolvedValue({
+ models: [
+ {
+ id: 'deepseek:deepseek-v4-pro',
+ name: 'DeepSeek V4 Pro',
+ provider: 'deepseek',
+ notable: true,
+ },
+ {
+ id: 'openrouter:deepseek/deepseek-v4-pro',
+ name: 'DeepSeek: DeepSeek V4 Pro',
+ provider: 'openrouter',
+ notable: true,
+ },
+ {
+ id: 'openai:gpt-5.5',
+ name: 'GPT-5.5',
+ provider: 'openai',
+ notable: true,
+ },
+ ],
+ });
+ mockAIAPI.testProvider.mockResolvedValueOnce({
+ success: false,
+ message: 'Provider connection issue',
+ provider: 'deepseek',
+ model: 'deepseek:deepseek-v4-pro',
+ cause: 'provider_connection',
+ summary: 'Pulse could not maintain a healthy connection to this provider.',
+ recommendation: 'Check provider reachability.',
+ action: 'open_provider_settings',
+ });
+
+ renderChat();
+
+ const switchButton = await screen.findByRole('button', {
+ name: 'Use OpenRouter provider route',
+ });
+ expect(switchButton).toHaveTextContent('Use OpenRouter');
+
+ fireEvent.click(switchButton);
+
+ expect(mockChat.setModel).toHaveBeenCalledWith('openrouter:deepseek/deepseek-v4-pro');
+ expect(document.activeElement).toBe(
+ screen.getByPlaceholderText('Ask about your infrastructure...'),
+ );
+ });
+
it('rechecks provider readiness from the drawer status banner', async () => {
mockAIAPI.getSettings.mockResolvedValue({
model: 'deepseek:deepseek-v4-pro',
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index dc93a4955e..b8579831d3 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -51,10 +51,12 @@ import {
type AIControlLevel,
} from '@/utils/aiControlLevelPresentation';
import {
+ formatAIModelRouteLabel,
getAIProviderDisplayName,
getProviderFromModelId,
} from '@/utils/aiProviderPresentation';
import { getCachedUnifiedResources } from '@/hooks/useUnifiedResources';
+import type { ModelInfo as RuntimeModelInfo } from '@/types/ai';
import type { Resource } from '@/types/resource';
import { isAppContainerDiscoveryResourceType } from '@/utils/discoveryTarget';
import {
@@ -93,6 +95,13 @@ interface ChatProviderReadinessState {
action?: string;
}
+interface ChatProviderReadinessAlternative {
+ id: string;
+ label: string;
+ provider: string;
+ providerLabel: string;
+}
+
interface AIChatProps {
onClose: () => void;
}
@@ -103,6 +112,72 @@ const compactText = (items: Array<string | undefined>): string[] =>
const pluralizeCount = (count: number, singular: string, plural: string) =>
`${count} ${count === 1 ? singular : plural}`;
+const normalizeComparableModelKey = (modelId: string): string => {
+ const trimmed = modelId.trim().toLowerCase();
+ if (!trimmed) return '';
+ const providerSeparator = trimmed.indexOf(':');
+ const withoutProvider = providerSeparator > 0 ? trimmed.slice(providerSeparator + 1) : trimmed;
+ const routeTail = withoutProvider.split('/').pop() || withoutProvider;
+ return routeTail.replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
+};
+
+const resolveRuntimeModelProvider = (
+ model: Pick<RuntimeModelInfo, 'id'> & Partial<Pick<RuntimeModelInfo, 'provider'>>,
+): string => model.provider?.trim() || getProviderFromModelId(model.id);
+
+const findProviderReadinessAlternative = (args: {
+ configuredProviders?: string[];
+ models: RuntimeModelInfo[];
+ selectedModel: string;
+ selectedProvider: string;
+}): ChatProviderReadinessAlternative | null => {
+ const selectedKey = normalizeComparableModelKey(args.selectedModel);
+ const selectedProvider = args.selectedProvider.trim();
+ if (!selectedKey || !selectedProvider) return null;
+
+ const configuredProviders = (args.configuredProviders ?? [])
+ .map((provider) => provider.trim())
+ .filter(Boolean);
+ const configuredProviderOrder = new Map(
+ configuredProviders.map((provider, index) => [provider, index]),
+ );
+
+ const candidates = args.models
+ .map((model) => {
+ const provider = resolveRuntimeModelProvider(model).trim();
+ return { model, provider };
+ })
+ .filter(({ model, provider }) => {
+ if (!provider || provider === selectedProvider || model.id === args.selectedModel) {
+ return false;
+ }
+ if (configuredProviderOrder.size > 0 && !configuredProviderOrder.has(provider)) {
+ return false;
+ }
+ return normalizeComparableModelKey(model.id) === selectedKey;
+ })
+ .sort((left, right) => {
+ const leftProviderOrder = configuredProviderOrder.get(left.provider) ?? Number.MAX_SAFE_INTEGER;
+ const rightProviderOrder =
+ configuredProviderOrder.get(right.provider) ?? Number.MAX_SAFE_INTEGER;
+ if (leftProviderOrder !== rightProviderOrder) return leftProviderOrder - rightProviderOrder;
+ if (Boolean(left.model.notable) !== Boolean(right.model.notable)) {
+ return right.model.notable ? 1 : -1;
+ }
+ return formatAIModelRouteLabel(left.model).localeCompare(formatAIModelRouteLabel(right.model));
+ });
+
+ const candidate = candidates[0];
+ if (!candidate) return null;
+
+ return {
+ id: candidate.model.id,
+ label: formatAIModelRouteLabel(candidate.model),
+ provider: candidate.provider,
+ providerLabel: getAIProviderDisplayName(candidate.provider),
+ };
+};
+
const shouldShowStructuredPatrolContext = (targetType: string | undefined) =>
STRUCTURED_PATROL_CONTEXT_TARGETS.has(targetType ?? '');
@@ -457,6 +532,17 @@ export const AIChat: Component<AIChatProps> = (props) => {
});
});
+ const providerReadinessAlternative = createMemo(() => {
+ const readiness = providerReadiness();
+ if (readiness.status !== 'error') return null;
+ return findProviderReadinessAlternative({
+ configuredProviders: aiRuntimeSettings()?.configured_providers,
+ models: aiRuntimeModels(),
+ selectedModel: selectedChatModel(),
+ selectedProvider: selectedChatProvider(),
+ });
+ });
+
let providerReadinessRequestId = 0;
let lastProviderReadinessKey = '';
@@ -582,6 +668,13 @@ export const AIChat: Component<AIChatProps> = (props) => {
updateStoredModel(chat.sessionId(), modelId);
};
+ const switchToProviderReadinessAlternative = () => {
+ const alternative = providerReadinessAlternative();
+ if (!alternative) return;
+ selectModel(alternative.id);
+ focusComposer();
+ };
+
createEffect(() => {
const sessionId = chat.sessionId();
const storedModel = getStoredModel(sessionId);
@@ -1664,7 +1757,20 @@ export const AIChat: Component<AIChatProps> = (props) => {
</div>
</div>
<Show when={providerReadiness().status === 'error'}>
- <div class="flex flex-shrink-0 items-center gap-2 sm:justify-end">
+ <div class="flex flex-wrap items-center gap-2 sm:justify-end">
+ <Show when={providerReadinessAlternative()}>
+ {(alternative) => (
+ <button
+ type="button"
+ onClick={switchToProviderReadinessAlternative}
+ class="inline-flex max-w-[11rem] items-center gap-1.5 rounded-md border border-current/20 bg-surface px-2 py-1 text-[10px] font-medium text-base-content hover:bg-surface-hover"
+ aria-label={`Use ${alternative().providerLabel} provider route`}
+ title={alternative().label}
+ >
+ <span class="truncate">Use {alternative().providerLabel}</span>
+ </button>
+ )}
+ </Show>
<button
type="button"
onClick={retrySelectedProviderReadiness}
diff --git a/frontend-modern/src/components/AI/Chat/types.ts b/frontend-modern/src/components/AI/Chat/types.ts
index e0079794d6..5192dc8fdb 100644
--- a/frontend-modern/src/components/AI/Chat/types.ts
+++ b/frontend-modern/src/components/AI/Chat/types.ts
@@ -136,4 +136,5 @@ export interface ModelInfo {
name: string;
description?: string;
notable?: boolean;
+ provider?: string;
}