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.
This commit is contained in:
5 files changed
+99
-28
No files matched your search
@@ -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"
|
||||
><Mic data-icon="inline-start" />{{ recording ? "Send" : "" }}</Button
|
||||
>
|
||||
<p v-if="recordError" class="px-1 text-caption text-danger" role="alert">{{ recordError }}</p>
|
||||
<Button
|
||||
v-else
|
||||
size="sm"
|
||||
|
||||
@@ -17,10 +17,17 @@ import {
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import ChatSettings from "./ChatSettings.vue";
|
||||
import {
|
||||
currentSession,
|
||||
promptSessionCommand,
|
||||
runSessionCommand,
|
||||
useEscapeLayer,
|
||||
} from "./state";
|
||||
@@ -44,9 +51,22 @@ function run(command: string): void {
|
||||
void runSessionCommand(command);
|
||||
}
|
||||
|
||||
// Rename and branch ask for a value in a labelled dialog, not window.prompt.
|
||||
const promptOpen = ref(false);
|
||||
const promptCommand = ref("");
|
||||
const promptMessage = ref("");
|
||||
const promptValue = ref("");
|
||||
function prompt(command: string, message: string): void {
|
||||
open.value = false;
|
||||
promptSessionCommand(command, message);
|
||||
promptCommand.value = command;
|
||||
promptMessage.value = message;
|
||||
promptValue.value = "";
|
||||
promptOpen.value = true;
|
||||
}
|
||||
function submitPrompt(): void {
|
||||
const value = promptValue.value.trim();
|
||||
promptOpen.value = false;
|
||||
if (value) void runSessionCommand(`${promptCommand.value} ${value}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -109,4 +129,14 @@ function prompt(command: string, message: string): void {
|
||||
<ChatSettings />
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Dialog :open="promptOpen" @update:open="(v: boolean) => (promptOpen = v)">
|
||||
<DialogContent>
|
||||
<DialogHeader><DialogTitle>{{ promptMessage }}</DialogTitle></DialogHeader>
|
||||
<Input v-model="promptValue" :aria-label="promptMessage" @keydown.enter.prevent="submitPrompt" />
|
||||
<DialogFooter>
|
||||
<Button variant="ghost" @click="promptOpen = false">Cancel</Button>
|
||||
<Button :disabled="!promptValue.trim()" @click="submitPrompt">OK</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -56,7 +56,7 @@ async function later() {
|
||||
<a v-if="c.Changelog" :href="c.Changelog" target="_blank" rel="noopener" class="ml-1 text-caption underline">changes</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-if="state === 'idle'" class="mt-3 flex gap-2">
|
||||
<div v-if="state === 'idle' || state === 'failed'" class="mt-3 flex gap-2">
|
||||
<Button v-if="update.can_install" size="sm" @click="install">Install</Button>
|
||||
<Button size="sm" variant="ghost" @click="later">Not now</Button>
|
||||
</div>
|
||||
|
||||
+11
-4
@@ -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;
|
||||
}
|
||||
+45
-20
@@ -303,10 +303,15 @@ async function readTranscript(id: string): Promise<ChatMessage[]> {
|
||||
*/
|
||||
export async function reloadTranscript(): Promise<void> {
|
||||
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<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// 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<void> {
|
||||
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<string[]>([]);
|
||||
/** 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<void> {
|
||||
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<void> {
|
||||
];
|
||||
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<void> {
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user