fix: chat streaming blocking the UI. extensions not showing accepted policies once accepted. (#1809)

* fix(ui): show an extension's accepted authority after it is accepted

* fix(ui): keep a chat reply's streamed text when the turn is stopped or fails

* feat(ui): queue chat messages sent while a turn runs
This commit is contained in:
sam authored and GitHub committed 2026-10-19 18:53:13 +11:00
1 parent 3a0c52dcb3
commit 7a49fd6efd
4 files changed
+182 -107

No files matched your search

+22 -3
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, nextTick, ref, watch } from "vue";
import { Mic } from "@lucide/vue";
import { Clock, Mic, Pencil, X } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
@@ -14,9 +14,12 @@ import {
commandSelection,
commandSpecs,
composerText,
editQueued,
isCommandMenuOpen,
isSending,
moveCommandSelection,
queuedMessages,
removeQueued,
sendMessage,
selectorData,
sendVoice,
@@ -162,6 +165,22 @@ function onKeydown(event: KeyboardEvent): void {
<template>
<div class="border-t p-3">
<ul v-if="queuedMessages.length" aria-label="Queued messages" class="mb-2 flex flex-col gap-1">
<li
v-for="(queued, index) in queuedMessages"
:key="index"
class="flex items-center gap-1 rounded-md border border-dashed border-border px-2 py-1 text-sm text-fg-muted"
>
<Clock class="size-3.5 flex-none" aria-hidden="true" />
<span class="min-w-0 flex-1 truncate">{{ queued }}</span>
<Button variant="ghost" size="icon" class="size-7" aria-label="Edit queued message" title="Edit" @click="editQueued(index)"
><Pencil
/></Button>
<Button variant="ghost" size="icon" class="size-7" aria-label="Remove queued message" title="Remove" @click="removeQueued(index)"
><X
/></Button>
</li>
</ul>
<div
:class="
cn(
@@ -206,9 +225,9 @@ function onKeydown(event: KeyboardEvent): void {
<Button
v-else
size="sm"
:disabled="isSending || !composerText.trim()"
:disabled="!composerText.trim()"
@click="sendMessage()"
>Send</Button
>{{ isSending ? "Queue" : "Send" }}</Button
>
</div>
</div>
+45 -3
View File
@@ -260,6 +260,7 @@ export async function selectSession(id: string): Promise<void> {
currentSession.value = id;
messages.value = [];
streamingTurn.value = null;
queuedMessages.value = [];
isLoadingSession.value = true;
@@ -371,10 +372,33 @@ export function setTurnHooks(hooks: typeof turnHooks): void {
}
export function newChat(): void {
composerText.value = "/new";
void sendMessage({ textOverride: "/new" });
}
/** Messages sent while a turn runs, oldest first; each goes when the turn before it ends. */
export const queuedMessages = ref<string[]>([]);
// 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 });
});
export function removeQueued(index: number): void {
queuedMessages.value = queuedMessages.value.filter((_, i) => i !== index);
}
/** Moves a queued message back into the composer, after anything already typed. */
export function editQueued(index: number): void {
const text = queuedMessages.value[index];
if (text === undefined) return;
removeQueued(index);
composerText.value = composerText.value.trim() ? `${composerText.value}\n${text}` : text;
}
/** Opens the palette for the slash word the caret sits in, or closes it. */
export function syncCommandMenu(value: string, caret: number): void {
const matches = matchesFor(commandSpecs.value, value, caret);
@@ -408,7 +432,16 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
const rawValue =
explicitText !== undefined ? explicitText : composerText.value;
const { text, turn, isRetry } = resolveTurn(retryOpts, rawValue);
if (!text || isSending.value) return;
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;
queuedMessages.value = [...queuedMessages.value, text];
if (explicitText === undefined) composerText.value = "";
closeCommandMenu();
return;
}
closeCommandMenu();
isSending.value = true;
@@ -416,7 +449,8 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
if (!isRetry) {
messages.value = [...messages.value, { from: "web", text }];
composerText.value = "";
// A queued or command send must not clear what is being typed.
if (explicitText === undefined) composerText.value = "";
}
// A bare /model offers its choices as buttons, as Telegram does; with an
@@ -548,6 +582,14 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
await refreshSessions();
} catch (err) {
const failed = err as Error;
// What already streamed is kept; the stop or failure note follows it.
if (streamedText) {
messages.value = [
...messages.value,
{ from: "assistant", text: streamedText, tool_calls: activeTools },
];
activeTools = [];
}
if (failed.name === "AbortError" && !timedOut) {
streamingTurn.value = {
text: "Turn stopped.",
+15 -1
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { Plus, Trash2 } from "@lucide/vue";
import { ChevronRight, Plus, Trash2 } from "@lucide/vue";
import PageHeader from "@/base/PageHeader.vue";
import {
@@ -14,6 +14,7 @@ import {
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Input } from "@/components/ui/input";
import { Badge } from "@/components/ui/badge";
@@ -83,6 +84,19 @@ const tones = {
</p>
<p class="text-xs text-fg-subtle">{{ extension.description }}</p>
<p class="truncate font-mono text-xs text-fg-subtle">{{ extension.digest }}</p>
<Collapsible v-if="extension.accepted">
<CollapsibleTrigger as-child>
<Button variant="ghost" size="sm" class="-ml-2 h-6 px-2 text-xs font-normal text-fg-subtle">
<ChevronRight class="transition-transform group-data-[state=open]/button:rotate-90" />
Accepted authority
</Button>
</CollapsibleTrigger>
<CollapsibleContent>
<ul class="font-mono text-xs text-fg-subtle">
<li v-for="line in grants(extension.accepted)" :key="line">{{ line }}</li>
</ul>
</CollapsibleContent>
</Collapsible>
</div>
<Badge v-if="tones[stage(extension)].tone" :variant="tones[stage(extension)].tone">{{ tones[stage(extension)].label }}</Badge>
<div v-if="extension.pending" class="w-full rounded-md border border-border px-3 py-2">