fix: determine clarification answered state from conversation

Instead of localStorage, check if there's a user message after the
clarification request in the conversation. This works across browsers
since the conversation is stored in the backend.
This commit is contained in:
Zamil Majdy
2026-01-30 15:28:40 -06:00
parent 4362aaab75
commit d1723760aa
2 changed files with 17 additions and 7 deletions

View File

@@ -156,12 +156,20 @@ export function ChatMessage({
}
if (isClarificationNeeded && message.type === "clarification_needed") {
// Check if user already replied after this clarification (answered)
const hasUserReplyAfter =
index >= 0 &&
messages
.slice(index + 1)
.some((m) => m.type === "message" && m.role === "user");
return (
<ClarificationQuestionsWidget
questions={message.questions}
message={message.message}
sessionId={message.sessionId}
onSubmitAnswers={handleClarificationAnswers}
isAnswered={hasUserReplyAfter}
className={className}
/>
);

View File

@@ -20,6 +20,7 @@ interface Props {
sessionId?: string;
onSubmitAnswers: (answers: Record<string, string>) => void;
onCancel?: () => void;
isAnswered?: boolean;
className?: string;
}
@@ -34,6 +35,7 @@ export function ClarificationQuestionsWidget({
sessionId,
onSubmitAnswers,
onCancel,
isAnswered = false,
className,
}: Props) {
const [answers, setAnswers] = useState<Record<string, string>>({});
@@ -54,11 +56,10 @@ export function ClarificationQuestionsWidget({
if (saved) {
const parsed = JSON.parse(saved) as Record<string, string>;
setAnswers(parsed);
setIsSubmitted(false);
} else {
setAnswers({});
setIsSubmitted(false);
}
setIsSubmitted(false);
} catch {
setAnswers({});
setIsSubmitted(false);
@@ -96,16 +97,17 @@ export function ClarificationQuestionsWidget({
onSubmitAnswers(answers);
const storageKey = getStorageKey(sessionId);
if (storageKey) {
try {
try {
if (storageKey) {
localStorage.removeItem(storageKey);
} catch {}
}
}
} catch {}
}
const allAnswered = questions.every((q) => answers[q.keyword]?.trim());
if (isSubmitted) {
// Show submitted state if answered from conversation or just submitted
if (isAnswered || isSubmitted) {
return (
<div
className={cn(