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,
|
() => !!selectorData.value.voice_available && typeof MediaRecorder !== "undefined" && !!navigator.mediaDevices?.getUserMedia,
|
||||||
);
|
);
|
||||||
const recording = ref(false);
|
const recording = ref(false);
|
||||||
|
const recordError = ref("");
|
||||||
let recorder: MediaRecorder | null = null;
|
let recorder: MediaRecorder | null = null;
|
||||||
async function toggleRecording() {
|
async function toggleRecording() {
|
||||||
if (recorder) {
|
if (recorder) {
|
||||||
recorder.stop();
|
recorder.stop();
|
||||||
return;
|
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[] = [];
|
const chunks: Blob[] = [];
|
||||||
recorder = new MediaRecorder(stream);
|
recorder = new MediaRecorder(stream);
|
||||||
recorder.ondataavailable = (e) => chunks.push(e.data);
|
recorder.ondataavailable = (e) => chunks.push(e.data);
|
||||||
@@ -240,6 +248,7 @@ function onKeydown(event: KeyboardEvent): void {
|
|||||||
@click="toggleRecording"
|
@click="toggleRecording"
|
||||||
><Mic data-icon="inline-start" />{{ recording ? "Send" : "" }}</Button
|
><Mic data-icon="inline-start" />{{ recording ? "Send" : "" }}</Button
|
||||||
>
|
>
|
||||||
|
<p v-if="recordError" class="px-1 text-caption text-danger" role="alert">{{ recordError }}</p>
|
||||||
<Button
|
<Button
|
||||||
v-else
|
v-else
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
@@ -17,10 +17,17 @@ import {
|
|||||||
PopoverContent,
|
PopoverContent,
|
||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
} from "@/components/ui/popover";
|
} 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 ChatSettings from "./ChatSettings.vue";
|
||||||
import {
|
import {
|
||||||
currentSession,
|
currentSession,
|
||||||
promptSessionCommand,
|
|
||||||
runSessionCommand,
|
runSessionCommand,
|
||||||
useEscapeLayer,
|
useEscapeLayer,
|
||||||
} from "./state";
|
} from "./state";
|
||||||
@@ -44,9 +51,22 @@ function run(command: string): void {
|
|||||||
void runSessionCommand(command);
|
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 {
|
function prompt(command: string, message: string): void {
|
||||||
open.value = false;
|
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>
|
</script>
|
||||||
|
|
||||||
@@ -109,4 +129,14 @@ function prompt(command: string, message: string): void {
|
|||||||
<ChatSettings />
|
<ChatSettings />
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</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>
|
</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>
|
<a v-if="c.Changelog" :href="c.Changelog" target="_blank" rel="noopener" class="ml-1 text-caption underline">changes</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</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 v-if="update.can_install" size="sm" @click="install">Install</Button>
|
||||||
<Button size="sm" variant="ghost" @click="later">Not now</Button>
|
<Button size="sm" variant="ghost" @click="later">Not now</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+11
-4
@@ -8,10 +8,17 @@ const CHANNEL_KEY = "archie.web.chat.channel";
|
|||||||
* the conversation instead of starting a second one beside it.
|
* the conversation instead of starting a second one beside it.
|
||||||
*/
|
*/
|
||||||
export function channelID(): string {
|
export function channelID(): string {
|
||||||
let id = localStorage.getItem(CHANNEL_KEY);
|
// Storage can be blocked (private mode, policy): fall back to a per-load id
|
||||||
if (!id) {
|
// rather than throwing a DOMException on every send.
|
||||||
id = randomUUID();
|
let id: string | null = null;
|
||||||
localStorage.setItem(CHANNEL_KEY, id);
|
try {
|
||||||
|
id = localStorage.getItem(CHANNEL_KEY);
|
||||||
|
if (!id) {
|
||||||
|
id = randomUUID();
|
||||||
|
localStorage.setItem(CHANNEL_KEY, id);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
id = id ?? randomUUID();
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
+45
-20
@@ -303,10 +303,15 @@ async function readTranscript(id: string): Promise<ChatMessage[]> {
|
|||||||
*/
|
*/
|
||||||
export async function reloadTranscript(): Promise<void> {
|
export async function reloadTranscript(): Promise<void> {
|
||||||
const id = currentSession.value;
|
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 {
|
try {
|
||||||
const transcript = await readTranscript(id);
|
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 {
|
} catch {
|
||||||
// The next outcome or reopening the conversation reads it again.
|
// 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
|
// Rename and branch take a value the server has no form for; the caller opens
|
||||||
// own prompt is the input: a modal built for two commands would be more UI than
|
// a labelled Dialog for it (see ChatSessionActions).
|
||||||
// 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()}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function setModel(model: string): Promise<void> {
|
export async function setModel(model: string): Promise<void> {
|
||||||
selectedModel.value = model;
|
|
||||||
if (!model) return;
|
if (!model) return;
|
||||||
|
const previous = selectedModel.value;
|
||||||
try {
|
try {
|
||||||
const result = await api.chatMessage<{ reply?: string }>(
|
const result = await api.chatMessage<{ reply?: string }>(
|
||||||
channelID(),
|
channelID(),
|
||||||
`/model ${model}`,
|
`/model ${model}`,
|
||||||
);
|
);
|
||||||
|
selectedModel.value = model;
|
||||||
statusText.value = result.reply || "Model updated";
|
statusText.value = result.reply || "Model updated";
|
||||||
await refreshSessions();
|
await refreshSessions();
|
||||||
} catch (err) {
|
} 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. */
|
/** Messages sent while a turn runs, oldest first; each goes when the turn before it ends. */
|
||||||
export const queuedMessages = ref<string[]>([]);
|
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
|
// A turn that ended, stopped included, sends the next queued message. A failed
|
||||||
// one holds the queue so nothing overtakes its retry.
|
// one holds the queue so nothing overtakes its retry.
|
||||||
watch(isSending, (sending) => {
|
watch(isSending, (sending) => {
|
||||||
if (sending || !queuedMessages.value.length || streamingTurn.value?.isError) return;
|
if (sending || streamingTurn.value?.isError) return;
|
||||||
const [next, ...rest] = queuedMessages.value;
|
if (queuedMessages.value.length) {
|
||||||
queuedMessages.value = rest;
|
const [next, ...rest] = queuedMessages.value;
|
||||||
void sendMessage({ textOverride: next });
|
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 {
|
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);
|
const { text, turn, isRetry } = resolveTurn(retryOpts, rawValue);
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
if (isSending.value) {
|
if (isSending.value) {
|
||||||
// A message typed during a turn waits for it; a retry or a voice clip
|
// A message typed during a turn waits for it; a retry has nothing to
|
||||||
// has nothing to wait for.
|
// wait for. A voice clip queues too, so it is not dropped.
|
||||||
if (isRetry || retryOpts?.voice) return;
|
if (isRetry) return;
|
||||||
|
if (retryOpts?.voice) {
|
||||||
|
queuedVoice.value = retryOpts.voice;
|
||||||
|
return;
|
||||||
|
}
|
||||||
queuedMessages.value = [...queuedMessages.value, text];
|
queuedMessages.value = [...queuedMessages.value, text];
|
||||||
if (explicitText === undefined) composerText.value = "";
|
if (explicitText === undefined) composerText.value = "";
|
||||||
closeCommandMenu();
|
closeCommandMenu();
|
||||||
@@ -582,7 +601,11 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
|||||||
];
|
];
|
||||||
streamingTurn.value = null;
|
streamingTurn.value = null;
|
||||||
statusText.value = "Ready";
|
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) {
|
} catch (err) {
|
||||||
const failed = err as Error;
|
const failed = err as Error;
|
||||||
// What already streamed is kept; the stop or failure note follows it.
|
// 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 {
|
export function stopTurn(): void {
|
||||||
statusText.value = "Stopping…";
|
statusText.value = "Stopping…";
|
||||||
if (currentSession.value) {
|
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();
|
abortActiveTurn();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user