>((acc, question, index) => {
- if (freeText.trim()) {
- acc[question.question] = freeText.trim()
+ const freeText = freeTexts[index]?.trim()
+ if (freeText) {
+ acc[question.question] = freeText
} else {
const selected = getSelectedAnswer(question, selections[index])
if (selected) acc[question.question] = selected
@@ -162,9 +192,9 @@ export function AskUserQuestion({ sessionId, toolUseId, input, result }: Props)
}
// All questions must be answered (via selection or free text) to enable submit
- const allAnswered = freeText.trim().length > 0 || questions.every((_, i) => (selections[i]?.length ?? 0) > 0)
- const safeActiveTab = Math.min(activeTab, questions.length - 1)
- const activeQuestion = questions[safeActiveTab]
+ const allAnswered = questions.every((_, i) =>
+ Boolean(freeTexts[i]?.trim()) || (selections[i]?.length ?? 0) > 0,
+ )
if (!activeQuestion) return null
@@ -202,7 +232,7 @@ export function AskUserQuestion({ sessionId, toolUseId, input, result }: Props)
{questions.map((q, i) => {
const isActive = safeActiveTab === i
- const isAnswered = (selections[i]?.length ?? 0) > 0
+ const isAnswered = Boolean(freeTexts[i]?.trim()) || (selections[i]?.length ?? 0) > 0
const tabLabel = q.header || `Q${i + 1}`
return (