fix(ui): a failed answer keeps the question card and its filled-in answer (#1728)
Quality / check (push) Successful in 9m2s
deploy / gate (push) Successful in 4m49s
deploy / archied-image (push) Successful in 3m25s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped

answerAsk now clears the pending question only after api.chatAnswer
accepts it, and resolves whether it did. On failure the new askError ref
carries the message, shown on the card as a ReadError whose Retry resends
the last answer; ChatAskCard keeps the typed reply until acceptance and
routes every choice button through the same path, and the questionnaire
submits through the card so its answers are retryable too. askError resets
on turn start, on a new ask, and on conversation switch.
This commit is contained in:
sam committed 2026-11-07 01:23:10 +11:00
1 parent bd1acdd0cc
commit e9937ded6b
3 files changed
+52 -18

No files matched your search

+25 -10
View File
@@ -5,22 +5,37 @@ import { ref } from "vue";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Item, ItemActions, ItemContent, ItemDescription, ItemMedia, ItemTitle } from "@/components/ui/item";
import { ReadError } from "@/components/ui/read-error";
import ChatQuestionnaire from "./ChatQuestionnaire.vue";
import { answerAsk, type ChatAsk } from "./state";
import { answerAsk, askError, type ChatAsk } from "./state";
defineProps<{ ask: ChatAsk }>();
const reply = ref("");
function sendReply() {
// The last answer tried, so a failed send can be retried from the error.
const lastAnswer = ref("");
async function answer(value: string): Promise<boolean> {
lastAnswer.value = value;
return answerAsk(value);
}
async function sendReply(): Promise<void> {
const text = reply.value.trim();
if (!text) return;
reply.value = "";
void answerAsk(text);
// The answer stays filled in until the server accepts it.
if (await answer(text)) reply.value = "";
}
function retry(): void {
if (lastAnswer.value) void answer(lastAnswer.value);
}
</script>
<template>
<ChatQuestionnaire v-if="ask.kind === 'questionnaire'" :ask="ask" />
<ReadError v-if="askError" :message="askError" retry-label="Retry answer" class="mt-2" @retry="retry" />
<ChatQuestionnaire v-if="ask.kind === 'questionnaire'" :ask="ask" :send="answer" />
<Item v-else-if="ask.kind === 'approval'" variant="outline" size="sm" class="mt-2" role="group" :aria-label="ask.prompt">
<ItemMedia variant="icon"><ShieldQuestion /></ItemMedia>
@@ -29,9 +44,9 @@ function sendReply() {
<ItemDescription v-if="ask.detail" class="font-mono text-caption break-all">{{ ask.detail }}</ItemDescription>
</ItemContent>
<ItemActions class="flex-wrap">
<Button size="sm" variant="outline" @click="answerAsk('deny')">Deny</Button>
<Button size="sm" variant="outline" @click="answerAsk('always')">Always this session</Button>
<Button size="sm" @click="answerAsk('approve')">Approve</Button>
<Button size="sm" variant="outline" @click="answer('deny')">Deny</Button>
<Button size="sm" variant="outline" @click="answer('always')">Always this session</Button>
<Button size="sm" @click="answer('approve')">Approve</Button>
</ItemActions>
</Item>
@@ -39,7 +54,7 @@ function sendReply() {
<template v-if="ask.kind === 'picker'">
<p class="font-medium">{{ ask.prompt }}</p>
<div class="mt-3 flex flex-wrap gap-2">
<Button v-for="choice in ask.choices" :key="choice.id" size="sm" variant="outline" @click="answerAsk(choice.id)">
<Button v-for="choice in ask.choices" :key="choice.id" size="sm" variant="outline" @click="answer(choice.id)">
{{ choice.label }}
</Button>
</div>
@@ -48,7 +63,7 @@ function sendReply() {
<template v-else>
<p class="font-medium">{{ ask.prompt }}</p>
<div v-if="ask.choices?.length" class="mt-3 flex flex-wrap gap-2">
<Button v-for="choice in ask.choices" :key="choice.id" size="sm" variant="outline" @click="answerAsk(choice.label)">
<Button v-for="choice in ask.choices" :key="choice.id" size="sm" variant="outline" @click="answer(choice.label)">
{{ choice.label }}
</Button>
</div>
+5 -4
View File
@@ -17,14 +17,15 @@ import {
QuestionnaireSubmit,
QuestionnaireTitle,
} from "@/components/ui/questionnaire";
import { answerAsk, type ChatAsk } from "./state";
import type { ChatAsk } from "./state";
/**
* Several questions from one turn, answered in a single reply. The answers go
* back as a JSON object of question name to the list of values given, the shape
* the server checks against the questions it asked.
* the server checks against the questions it asked. The card owns answerAsk so
* a failed submit is recorded for the card's retry.
*/
const props = defineProps<{ ask: ChatAsk }>();
const props = defineProps<{ ask: ChatAsk; send: (answer: string) => Promise<boolean> }>();
const questions = computed(() => props.ask.questions ?? []);
const items = computed(() =>
@@ -44,7 +45,7 @@ function submit(event: Event): void {
const values = form.getAll(q.name).map(String).filter((v) => v.trim());
if (values.length) answers[q.name] = values;
}
void answerAsk(JSON.stringify(answers));
void props.send(JSON.stringify(answers));
}
</script>
+22 -4
View File
@@ -167,13 +167,28 @@ interface ChatStreamFrame extends ChatToolCall {
const STREAM_TIMEOUT_MS = 120000;
let rearmTimeout: (() => void) | null = null;
/** answerAsk sends the operator's answer to the question the turn waits on. */
export async function answerAsk(answer: string): Promise<void> {
// A failed answer keeps the question card up; the failure shows on the card.
export const askError = ref("");
/**
* answerAsk sends the operator's answer to the question the turn waits on.
* Resolves true only when the answer was accepted: the question is cleared
* then, and only then. On failure the question stays, askError carries the
* message for the card, and the caller's answer stays filled in for a retry.
*/
export async function answerAsk(answer: string): Promise<boolean> {
const ask = streamingTurn.value?.ask;
if (!ask) return;
if (!ask) return false;
try {
await api.chatAnswer(ask.id, answer);
} catch (err) {
askError.value = (err as Error).message || "Could not send the answer";
return false;
}
streamingTurn.value = streamingTurn.value ? { ...streamingTurn.value, ask: undefined } : null;
askError.value = "";
rearmTimeout?.();
await api.chatAnswer(ask.id, answer);
return true;
}
export const sessions = ref<ChatSession[]>([]);
@@ -267,6 +282,7 @@ export async function selectSession(id: string): Promise<void> {
queuedMessages.value = [];
isLoadingSession.value = true;
sessionError.value = "";
askError.value = "";
try {
// Resuming is the server's own command, so the transcript read below is of
@@ -516,6 +532,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
let activeTools: ChatToolCall[] = [];
streamingTurn.value = { text: "", tools: [], isError: false, turn, isRetry };
askError.value = "";
let streamedText = "";
let finished = false;
@@ -597,6 +614,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
}
if (event.type === "ask" && event.ask) {
clearTimeout(timeoutId);
askError.value = "";
streamingTurn.value = streamingTurn.value
? { ...streamingTurn.value, ask: event.ask }
: null;