From fa14e7da803cde5727d6d209ede3b4344cf5a170 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 7 Nov 2026 00:17:44 +1100 Subject: [PATCH] fix(ui): chat failures are shown where they happen and leave the real state (#1748) Mic permission failure shows an inline alert; setModel only switches on server confirmation and reverts + reports in the transcript on failure; a failed session refresh after a turn no longer becomes a retryable turn error; a voice clip during a turn queues instead of dropping; blocked localStorage falls back to a per-load channel id; a failed install offers Retry/Not now again; rename/branch use a labelled Dialog instead of window.prompt; a failed cancel is reported; a stopped turn no longer blocks transcript reloads. --- ui/src/chat/ChatComposer.vue | 11 ++++- ui/src/chat/ChatSessionActions.vue | 34 +++++++++++++++- ui/src/chat/ChatUpdateCard.vue | 2 +- ui/src/chat/channel.ts | 15 +++++-- ui/src/chat/state.ts | 65 +++++++++++++++++++++--------- 5 files changed, 99 insertions(+), 28 deletions(-) diff --git a/ui/src/chat/ChatComposer.vue b/ui/src/chat/ChatComposer.vue index 4ade1e360..2d3b7add3 100644 --- a/ui/src/chat/ChatComposer.vue +++ b/ui/src/chat/ChatComposer.vue @@ -51,13 +51,21 @@ const canRecord = computed( () => !!selectorData.value.voice_available && typeof MediaRecorder !== "undefined" && !!navigator.mediaDevices?.getUserMedia, ); const recording = ref(false); +const recordError = ref(""); let recorder: MediaRecorder | null = null; async function toggleRecording() { if (recorder) { recorder.stop(); return; } - const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); + recordError.value = ""; + let stream: MediaStream; + try { + stream = await navigator.mediaDevices.getUserMedia({ audio: true }); + } catch (err) { + recordError.value = `Microphone unavailable: ${(err as Error).message || err}`; + return; + } const chunks: Blob[] = []; recorder = new MediaRecorder(stream); recorder.ondataavailable = (e) => chunks.push(e.data); @@ -240,6 +248,7 @@ function onKeydown(event: KeyboardEvent): void { @click="toggleRecording" >{{ recording ? "Send" : "" }} + + + + + diff --git a/ui/src/chat/ChatUpdateCard.vue b/ui/src/chat/ChatUpdateCard.vue index c3f8cc1c6..723c18ae0 100644 --- a/ui/src/chat/ChatUpdateCard.vue +++ b/ui/src/chat/ChatUpdateCard.vue @@ -56,7 +56,7 @@ async function later() { changes -
+
diff --git a/ui/src/chat/channel.ts b/ui/src/chat/channel.ts index 44e46b7b8..850014d33 100644 --- a/ui/src/chat/channel.ts +++ b/ui/src/chat/channel.ts @@ -8,10 +8,17 @@ const CHANNEL_KEY = "archie.web.chat.channel"; * the conversation instead of starting a second one beside it. */ export function channelID(): string { - let id = localStorage.getItem(CHANNEL_KEY); - if (!id) { - id = randomUUID(); - localStorage.setItem(CHANNEL_KEY, id); + // Storage can be blocked (private mode, policy): fall back to a per-load id + // rather than throwing a DOMException on every send. + let id: string | null = null; + try { + id = localStorage.getItem(CHANNEL_KEY); + if (!id) { + id = randomUUID(); + localStorage.setItem(CHANNEL_KEY, id); + } + } catch { + id = id ?? randomUUID(); } return id; } diff --git a/ui/src/chat/state.ts b/ui/src/chat/state.ts index ad0354134..c42d7e2db 100644 --- a/ui/src/chat/state.ts +++ b/ui/src/chat/state.ts @@ -303,10 +303,15 @@ async function readTranscript(id: string): Promise { */ export async function reloadTranscript(): Promise { const id = currentSession.value; - if (!id || streamingTurn.value) return; + // A stopped turn is terminal, not in flight: it must not block reloads. + const stopped = streamingTurn.value?.text === "Turn stopped."; + if (!id || (streamingTurn.value && !stopped)) return; try { const transcript = await readTranscript(id); - if (isCurrentSession(id) && !streamingTurn.value) messages.value = transcript; + if (isCurrentSession(id) && (!streamingTurn.value || streamingTurn.value.text === "Turn stopped.")) { + messages.value = transcript; + if (stopped) streamingTurn.value = null; + } } catch { // The next outcome or reopening the conversation reads it again. } @@ -345,26 +350,26 @@ export async function runSessionCommand(command: string): Promise { } } -// Rename and branch take a value the server has no form for, so the browser's -// own prompt is the input: a modal built for two commands would be more UI than -// the two commands are worth. -export function promptSessionCommand(command: string, message: string): void { - const value = window.prompt(message); - if (value?.trim()) void runSessionCommand(`${command} ${value.trim()}`); -} +// Rename and branch take a value the server has no form for; the caller opens +// a labelled Dialog for it (see ChatSessionActions). + export async function setModel(model: string): Promise { - selectedModel.value = model; if (!model) return; + const previous = selectedModel.value; try { const result = await api.chatMessage<{ reply?: string }>( channelID(), `/model ${model}`, ); + selectedModel.value = model; statusText.value = result.reply || "Model updated"; await refreshSessions(); } catch (err) { - statusText.value = `Model update failed: ${(err as Error).message || err}`; + // The selector keeps the model the server still has, and the failure is + // shown in the transcript, not only in status text. + selectedModel.value = previous; + sessionError.value = `Model update failed: ${(err as Error).message || err}`; } } @@ -380,14 +385,24 @@ export function newChat(): void { /** Messages sent while a turn runs, oldest first; each goes when the turn before it ends. */ export const queuedMessages = ref([]); +/** A voice clip recorded while a turn runs, sent when it ends. */ +export const queuedVoice = ref<{ data: string; mime_type: string } | null>(null); // A turn that ended, stopped included, sends the next queued message. A failed // one holds the queue so nothing overtakes its retry. watch(isSending, (sending) => { - if (sending || !queuedMessages.value.length || streamingTurn.value?.isError) return; - const [next, ...rest] = queuedMessages.value; - queuedMessages.value = rest; - void sendMessage({ textOverride: next }); + if (sending || streamingTurn.value?.isError) return; + if (queuedMessages.value.length) { + const [next, ...rest] = queuedMessages.value; + queuedMessages.value = rest; + void sendMessage({ textOverride: next }); + return; + } + const voice = queuedVoice.value; + if (voice) { + queuedVoice.value = null; + void sendMessage({ textOverride: "šŸŽ¤ Voice message", voice }); + } }); export function removeQueued(index: number): void { @@ -437,9 +452,13 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise { const { text, turn, isRetry } = resolveTurn(retryOpts, rawValue); if (!text) return; if (isSending.value) { - // A message typed during a turn waits for it; a retry or a voice clip - // has nothing to wait for. - if (isRetry || retryOpts?.voice) return; + // A message typed during a turn waits for it; a retry has nothing to + // wait for. A voice clip queues too, so it is not dropped. + if (isRetry) return; + if (retryOpts?.voice) { + queuedVoice.value = retryOpts.voice; + return; + } queuedMessages.value = [...queuedMessages.value, text]; if (explicitText === undefined) composerText.value = ""; closeCommandMenu(); @@ -582,7 +601,11 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise { ]; streamingTurn.value = null; statusText.value = "Ready"; - await refreshSessions(); + // The turn succeeded; a failed session-list refresh is reported on its + // own and must not turn into a "retry this turn" error. + await refreshSessions().catch((err) => { + sessionError.value = `Could not refresh the session list: ${(err as Error).message || err}`; + }); } catch (err) { const failed = err as Error; // What already streamed is kept; the stop or failure note follows it. @@ -624,7 +647,9 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise { export function stopTurn(): void { statusText.value = "Stopping…"; if (currentSession.value) { - void api.chatCancel(currentSession.value).catch(() => {}); + void api.chatCancel(currentSession.value).catch((err) => { + sessionError.value = `Could not stop the turn: ${(err as Error).message || err}`; + }); } abortActiveTurn(); }