From 521a677a375f05f669228cd17fac03e2cc6b694f Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Tue, 15 Sep 2026 02:56:50 +0200 Subject: [PATCH] ui : only show the server error when no backend is available Assisted-by: pi:llama.cpp/DeepSeek-V4.1-Flash --- .../ChatFormActionModels.svelte | 4 +- .../app/chat/ChatScreen/ChatScreen.svelte | 4 +- .../ChatScreen/ChatScreenServerError.svelte | 7 +++- .../hooks/use-backend-availability.svelte.ts | 38 +++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 tools/ui/src/lib/hooks/use-backend-availability.svelte.ts diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionModels.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionModels.svelte index a4baa40bf9..be09f2fdd7 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionModels.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionModels.svelte @@ -1,5 +1,6 @@ -{#if hasError} +{#if hasError || isLoadingModel}
{#if isLoadingModel} diff --git a/tools/ui/src/lib/hooks/use-backend-availability.svelte.ts b/tools/ui/src/lib/hooks/use-backend-availability.svelte.ts new file mode 100644 index 0000000000..c78284c2d5 --- /dev/null +++ b/tools/ui/src/lib/hooks/use-backend-availability.svelte.ts @@ -0,0 +1,38 @@ +/** + * Backend availability for connection error states. + * + * The server error banner and the offline affordances should only appear when + * no backend can serve requests. The active backend failing is not enough: + * with an external backend configured, the UI stays usable. + */ + +import { LOCAL_BACKEND_ID } from '$lib/constants'; +import { backendsModelsStore, backendsStore, serverStore } from '$lib/stores'; + +export interface BackendAvailability { + readonly hasAvailableBackend: boolean; + readonly isOffline: boolean; +} + +export function useBackendAvailability(): BackendAvailability { + const hasAvailableBackend = $derived.by(() => { + // no connection error at all: nothing to report + if (!serverStore.error) return true; + + // the local server failed, but an external backend may still be usable + return backendsStore.enabled.some( + (backend) => + backend.id !== LOCAL_BACKEND_ID && backendsModelsStore.get(backend.id).error === null + ); + }); + + return { + get hasAvailableBackend() { + return hasAvailableBackend; + }, + + get isOffline() { + return !hasAvailableBackend; + } + }; +}