diff --git a/packages/ui/src/components/tool-call/question-block.tsx b/packages/ui/src/components/tool-call/question-block.tsx index 7e273fac..5604375b 100644 --- a/packages/ui/src/components/tool-call/question-block.tsx +++ b/packages/ui/src/components/tool-call/question-block.tsx @@ -112,7 +112,6 @@ export function QuestionToolBlock(props: QuestionToolBlockProps) { if (!props.active()) return const rawValue = input?.value ?? "" const value = rawValue - if (value.trim().length === 0) return const info = questions()[questionIndex] const multi = info?.multiple === true @@ -121,6 +120,19 @@ export function QuestionToolBlock(props: QuestionToolBlockProps) { updateAnswer(questionIndex, []) } + // If the custom field is empty, treat it as unanswered. + // This prevents submitting a previously selected option when the user + // has explicitly switched focus to the custom input. + if (value.trim().length === 0) return + + if (multi) { + const existing = answers()[questionIndex] ?? [] + if (!existing.includes(value)) { + updateAnswer(questionIndex, [...existing, value]) + } + return + } + toggleOption(questionIndex, value) } @@ -281,6 +293,9 @@ export function QuestionToolBlock(props: QuestionToolBlockProps) { onInput={(e) => handleCustomTyping(i(), e.currentTarget)} onKeyDown={(e) => { if (e.key === "Enter" && !e.isComposing) { + // Don't submit if the custom field is empty (common when switching to it). + if (e.currentTarget.value.trim().length === 0) return + e.preventDefault() if (!submitDisabled()) { props.onSubmit() }