|
1 | 1 | import React from 'react' |
2 | 2 | import { AgentModeToggle } from './agent-mode-toggle' |
3 | 3 | import { FeedbackContainer } from './feedback-container' |
| 4 | +import { MultipleChoiceForm } from './multiple-choice-form' |
4 | 5 | import { MultilineInput, type MultilineInputHandle } from './multiline-input' |
5 | 6 | import { SuggestionMenu, type SuggestionItem } from './suggestion-menu' |
6 | 7 | import { UsageBanner } from './usage-banner' |
7 | 8 | import { BORDER_CHARS } from '../utils/ui-constants' |
8 | 9 | import { useTheme } from '../hooks/use-theme' |
9 | 10 | import { useChatStore } from '../state/chat-store' |
| 11 | +import { useAskUserBridge } from '../hooks/use-ask-user-bridge' |
10 | 12 | import type { AgentMode } from '../utils/constants' |
11 | 13 | import type { InputValue } from '../state/chat-store' |
12 | 14 |
|
@@ -84,6 +86,11 @@ export const ChatInputBar = ({ |
84 | 86 | }: ChatInputBarProps) => { |
85 | 87 | const isBashMode = useChatStore((state) => state.isBashMode) |
86 | 88 | const setBashMode = useChatStore((state) => state.setBashMode) |
| 89 | + const askUserState = useChatStore((state) => state.askUserState) |
| 90 | + const updateAskUserAnswer = useChatStore((state) => state.updateAskUserAnswer) |
| 91 | + const updateAskUserOtherText = useChatStore((state) => state.updateAskUserOtherText) |
| 92 | + const { submitAnswers, skip } = useAskUserBridge() |
| 93 | + |
87 | 94 | if (feedbackMode) { |
88 | 95 | return ( |
89 | 96 | <FeedbackContainer |
@@ -115,12 +122,66 @@ export const ChatInputBar = ({ |
115 | 122 | setInputValue(value) |
116 | 123 | } |
117 | 124 |
|
| 125 | + const handleFormSubmit = (finalAnswers?: number[], finalOtherTexts?: string[]) => { |
| 126 | + console.log('[ChatInputBar] handleFormSubmit called', { askUserState, finalAnswers, finalOtherTexts }) |
| 127 | + if (!askUserState) return |
| 128 | + |
| 129 | + // Use final values if provided (for immediate submission), otherwise use current state |
| 130 | + const answersToUse = finalAnswers || askUserState.selectedAnswers |
| 131 | + const otherTextsToUse = finalOtherTexts || askUserState.otherTexts |
| 132 | + |
| 133 | + const answers = askUserState.questions.map((q, idx) => { |
| 134 | + const otherText = otherTextsToUse[idx]?.trim() |
| 135 | + if (otherText) { |
| 136 | + // User provided custom text |
| 137 | + return { |
| 138 | + questionIndex: idx, |
| 139 | + otherText, |
| 140 | + } |
| 141 | + } else { |
| 142 | + // User selected an option |
| 143 | + return { |
| 144 | + questionIndex: idx, |
| 145 | + selectedOption: q.options[answersToUse[idx]], |
| 146 | + } |
| 147 | + } |
| 148 | + }) |
| 149 | + console.log('[ChatInputBar] Submitting answers', { answers }) |
| 150 | + submitAnswers(answers) |
| 151 | + } |
| 152 | + |
118 | 153 | // Adjust input width for bash mode (subtract 2 for '!' column) |
119 | 154 | const adjustedInputWidth = isBashMode ? inputWidth - 2 : inputWidth |
120 | 155 | const effectivePlaceholder = isBashMode |
121 | 156 | ? 'Enter bash command...' |
122 | 157 | : inputPlaceholder |
123 | 158 |
|
| 159 | + if (askUserState) { |
| 160 | + return ( |
| 161 | + <box |
| 162 | + title=" Action Required " |
| 163 | + titleAlignment="center" |
| 164 | + style={{ |
| 165 | + width: '100%', |
| 166 | + borderStyle: 'single', |
| 167 | + borderColor: theme.primary, |
| 168 | + customBorderChars: BORDER_CHARS, |
| 169 | + }} |
| 170 | + > |
| 171 | + <MultipleChoiceForm |
| 172 | + questions={askUserState.questions} |
| 173 | + selectedAnswers={askUserState.selectedAnswers} |
| 174 | + otherTexts={askUserState.otherTexts} |
| 175 | + onSelectAnswer={updateAskUserAnswer} |
| 176 | + onOtherTextChange={updateAskUserOtherText} |
| 177 | + onSubmit={handleFormSubmit} |
| 178 | + onSkip={skip} |
| 179 | + width={inputWidth} |
| 180 | + /> |
| 181 | + </box> |
| 182 | + ) |
| 183 | + } |
| 184 | + |
124 | 185 | return ( |
125 | 186 | <> |
126 | 187 | <box |
|
0 commit comments