feat(open-webui): tag chats per user, harden error/voice states, add tests
- persistence: tag created/updated Open WebUI chats with a homarr-user:<id> tag (via chat meta.tags) so conversations can be found back per Homarr user even when an integration/account is shared - voice recording: distinguish a denied/dismissed microphone permission from a generic mic failure and show an actionable message - widget: surface the models query loading and connection-error states in the chat empty state instead of silently showing 'no models' - tests: cover the final-SSE-frame flush, the default request timeout (and the streaming opt-out), and multimodal chat parsing round-trip
This commit is contained in:
6 files changed
+122
-8
No files matched your search
@@ -8,6 +8,7 @@ import {
|
||||
CloseButton,
|
||||
Group,
|
||||
Image,
|
||||
Loader,
|
||||
Modal,
|
||||
NavLink,
|
||||
Paper,
|
||||
@@ -73,7 +74,11 @@ export function Chat({
|
||||
const headerRef = useRef<HTMLDivElement>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const { data: models = [], isLoading: modelsLoading } = clientApi.widget.openWebUi.getModels.useQuery(
|
||||
const {
|
||||
data: models = [],
|
||||
isLoading: modelsLoading,
|
||||
isError: modelsError,
|
||||
} = clientApi.widget.openWebUi.getModels.useQuery(
|
||||
{ integrationId: integrationId ?? "" },
|
||||
{ enabled: Boolean(integrationId), refetchOnWindowFocus: false, retry: false },
|
||||
);
|
||||
@@ -111,6 +116,7 @@ export function Chat({
|
||||
onError: setError,
|
||||
onTranscribed: (text) => setInput((previous) => (previous ? `${previous} ${text}` : text)),
|
||||
micErrorMessage: t("widget.openWebUi.micError"),
|
||||
micPermissionErrorMessage: t("widget.openWebUi.micPermissionError"),
|
||||
transcribeErrorMessage: t("widget.openWebUi.transcribeError"),
|
||||
});
|
||||
|
||||
@@ -252,9 +258,20 @@ export function Chat({
|
||||
<ScrollArea className={classes.messages} viewportRef={viewportRef} type="auto">
|
||||
<Stack gap="xs" p="xs" pt={headerHeight + 8} pb={composerHeight + 24}>
|
||||
{stream.messages.length === 0 && !stream.isStreaming ? (
|
||||
<Stack align="center" justify="center" gap="xs" mt="xl" c="dimmed">
|
||||
<IconRobot size={32} />
|
||||
<Text size="sm">{t("widget.openWebUi.emptyState")}</Text>
|
||||
<Stack align="center" justify="center" gap="xs" mt="xl" c={modelsError ? "red.6" : "dimmed"}>
|
||||
{modelsLoading ? (
|
||||
<Loader size="sm" />
|
||||
) : modelsError ? (
|
||||
<>
|
||||
<IconRobot size={32} />
|
||||
<Text size="sm">{t("widget.openWebUi.error.internalServerError")}</Text>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<IconRobot size={32} />
|
||||
<Text size="sm">{t("widget.openWebUi.emptyState")}</Text>
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
) : null}
|
||||
{stream.messages.map((message, index) => (
|
||||
|
||||
@@ -9,6 +9,7 @@ interface UseVoiceRecordingOptions {
|
||||
onError: (message: string) => void;
|
||||
onTranscribed: (text: string) => void;
|
||||
micErrorMessage: string;
|
||||
micPermissionErrorMessage: string;
|
||||
transcribeErrorMessage: string;
|
||||
}
|
||||
|
||||
@@ -22,6 +23,7 @@ export function useVoiceRecording({
|
||||
onError,
|
||||
onTranscribed,
|
||||
micErrorMessage,
|
||||
micPermissionErrorMessage,
|
||||
transcribeErrorMessage,
|
||||
}: UseVoiceRecordingOptions) {
|
||||
const [isRecording, setIsRecording] = useState(false);
|
||||
@@ -106,14 +108,18 @@ export function useVoiceRecording({
|
||||
setRecordingSeconds(0);
|
||||
recordingTimerRef.current = window.setInterval(() => setRecordingSeconds((value) => value + 1), 1000);
|
||||
setIsRecording(true);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// getUserMedia may have succeeded before AudioContext/MediaRecorder setup
|
||||
// threw; release the mic stream and context so it isn't left running.
|
||||
releaseAudioResources();
|
||||
mediaRecorderRef.current = null;
|
||||
setAnalyser(null);
|
||||
setIsRecording(false);
|
||||
onError(micErrorMessage);
|
||||
// Distinguish a denied/dismissed permission prompt from other mic failures
|
||||
// so the user gets an actionable message.
|
||||
const denied =
|
||||
error instanceof DOMException && (error.name === "NotAllowedError" || error.name === "SecurityError");
|
||||
onError(denied ? micPermissionErrorMessage : micErrorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user