+
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();
}