Files
archie/ui/src/chat/ChatAskCard.vue
T
sam e9937ded6b
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
fix(ui): a failed answer keeps the question card and its filled-in answer (#1728)
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.
2026-11-07 01:23:10 +11:00

77 lines
3.0 KiB
Vue

<script setup lang="ts">
import { ShieldQuestion } from "@lucide/vue";
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, askError, type ChatAsk } from "./state";
defineProps<{ ask: ChatAsk }>();
const reply = ref("");
// 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;
// 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>
<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>
<ItemContent>
<ItemTitle>Allow {{ ask.prompt }}?</ItemTitle>
<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="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>
<div v-else class="mt-2 rounded-lg border border-border bg-card p-3 text-label" role="group" :aria-label="ask.prompt">
<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="answer(choice.id)">
{{ choice.label }}
</Button>
</div>
</template>
<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="answer(choice.label)">
{{ choice.label }}
</Button>
</div>
<form class="mt-3 flex gap-2" @submit.prevent="sendReply">
<Input v-model="reply" class="flex-1" placeholder="Your answer" aria-label="Your answer" />
<Button type="submit" size="sm" :disabled="!reply.trim()">Send</Button>
</form>
</template>
</div>
</template>