Skip to content

Commit 9a946ce

Browse files
committed
fix(web): keep incoming questions from replacing drafts
1 parent 32b6909 commit 9a946ce

5 files changed

Lines changed: 64 additions & 13 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,6 +2658,12 @@ export default function ChatView(props: ChatViewProps) {
26582658
activeThreadId,
26592659
activePendingUserInput?.requestId,
26602660
]);
2661+
const [answeringRequestKey, setAnsweringRequestKey] = useState<string | null>(null);
2662+
const isAnsweringPendingUserInput =
2663+
activePendingUserInput !== null && answeringRequestKey === activePendingRequestKey;
2664+
if (answeringRequestKey !== null && !isAnsweringPendingUserInput) {
2665+
setAnsweringRequestKey(null);
2666+
}
26612667
const pendingQuestionDraftKeys = useMemo(
26622668
() =>
26632669
activeThreadId
@@ -6553,7 +6559,7 @@ export default function ChatView(props: ChatViewProps) {
65536559
});
65546560
return;
65556561
}
6556-
if (activePendingProgress) {
6562+
if (isAnsweringPendingUserInput && activePendingProgress) {
65576563
if (directAnnotation) {
65586564
notifyDirectAnnotationAttached();
65596565
return;
@@ -7416,14 +7422,17 @@ export default function ChatView(props: ChatViewProps) {
74167422
},
74177423
};
74187424
});
7419-
promptRef.current = "";
7420-
composerRef.current?.resetCursorState({ cursor: 0 });
7425+
if (isAnsweringPendingUserInput) {
7426+
promptRef.current = "";
7427+
composerRef.current?.resetCursorState({ cursor: 0 });
7428+
}
74217429
},
74227430
[
74237431
activePendingProgress?.activeQuestion,
74247432
activePendingUserInput,
74257433
activePendingRequestKey,
74267434
composerRef,
7435+
isAnsweringPendingUserInput,
74277436
],
74287437
);
74297438

@@ -8530,7 +8539,15 @@ export default function ChatView(props: ChatViewProps) {
85308539
activePendingApproval={activePendingApproval}
85318540
pendingApprovals={pendingApprovals}
85328541
pendingUserInputs={pendingUserInputs}
8533-
activePendingProgress={activePendingProgress}
8542+
activePendingProgress={
8543+
isAnsweringPendingUserInput ? activePendingProgress : null
8544+
}
8545+
onToggleAnsweringPendingUserInput={() => {
8546+
setAnsweringRequestKey(
8547+
isAnsweringPendingUserInput ? null : activePendingRequestKey,
8548+
);
8549+
scheduleComposerFocus();
8550+
}}
85348551
activePendingResolvedAnswers={activePendingResolvedAnswers}
85358552
activePendingIsResponding={activePendingIsResponding}
85368553
activePendingDraftAnswers={activePendingDraftAnswers}

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,7 @@ export interface ChatComposerProps {
12801280
activePendingApproval: PendingApproval | null;
12811281
pendingApprovals: PendingApproval[];
12821282
pendingUserInputs: PendingUserInput[];
1283+
onToggleAnsweringPendingUserInput: () => void;
12831284
activePendingProgress: {
12841285
questionIndex: number;
12851286
isLastQuestion: boolean;
@@ -1418,7 +1419,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
14181419
environmentUnavailable,
14191420
activePendingApproval,
14201421
pendingApprovals,
1421-
pendingUserInputs,
1422+
pendingUserInputs: availablePendingUserInputs,
1423+
onToggleAnsweringPendingUserInput,
14221424
activePendingProgress,
14231425
activePendingResolvedAnswers,
14241426
activePendingIsResponding,
@@ -1481,6 +1483,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
14811483
onExpandImage,
14821484
onFileOpen,
14831485
} = props;
1486+
const isAnsweringPendingUserInput = activePendingProgress !== null;
1487+
// Only an explicitly chosen question can own the editor and its attachments.
1488+
const pendingUserInputs = isAnsweringPendingUserInput ? availablePendingUserInputs : [];
14841489
const activeTasksProgress = props.threadSyncPhase === null ? props.activeTasksProgress : null;
14851490
const activeTaskSteps = props.threadSyncPhase === null ? props.activeTaskSteps : null;
14861491
// ------------------------------------------------------------------
@@ -2178,12 +2183,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
21782183
);
21792184

21802185
const isComposerApprovalState = activePendingApproval !== null;
2181-
const activePendingUserInput = pendingUserInputs[0] ?? null;
2186+
const activePendingUserInput = availablePendingUserInputs[0] ?? null;
21822187
const isChoiceOnlyPendingQuestion =
21832188
activePendingProgress?.activeQuestion?.allowCustomAnswer === false;
21842189
const showComposerTopDrawer =
21852190
isComposerApprovalState ||
2186-
pendingUserInputs.length > 0 ||
2191+
availablePendingUserInputs.length > 0 ||
21872192
(!isComposerCollapsedMobile && showPlanFollowUpPrompt && activeProposedPlan !== null);
21882193
const showCollapsedMobilePromptRow =
21892194
isComposerCollapsedMobile && !isComposerApprovalState && pendingUserInputs.length === 0;
@@ -2407,9 +2412,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
24072412
// Sync refs back to parent
24082413
// ------------------------------------------------------------------
24092414
useEffect(() => {
2415+
if (isAnsweringPendingUserInput) return;
24102416
promptRef.current = prompt;
24112417
setComposerCursor((existing) => clampCollapsedComposerCursor(prompt, existing));
2412-
}, [prompt, promptRef]);
2418+
}, [isAnsweringPendingUserInput, prompt, promptRef]);
24132419

24142420
useEffect(() => {
24152421
if (composerSubmissionError === null) return;
@@ -3837,7 +3843,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
38373843
}, []);
38383844
const hasBannerItems = props.bannerItems.length > 0;
38393845
const hasBlockingComposerTopDrawer =
3840-
activePendingApproval !== null || pendingUserInputs.length > 0;
3846+
activePendingApproval !== null || availablePendingUserInputs.length > 0;
38413847
const showInlineTasksBadge =
38423848
activeTasksProgress !== null &&
38433849
activeTaskSteps !== null &&
@@ -5046,9 +5052,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
50465052
/>
50475053
</ComposerBanner.Actions>
50485054
</ComposerBanner.Row>
5049-
) : !isComposerCollapsedMobile && pendingUserInputs.length > 0 ? (
5055+
) : availablePendingUserInputs.length > 0 &&
5056+
(!isComposerCollapsedMobile || !isAnsweringPendingUserInput) ? (
50505057
<ComposerPendingUserInputPanel
5051-
pendingUserInputs={pendingUserInputs}
5058+
pendingUserInputs={availablePendingUserInputs}
50525059
respondingRequestIds={
50535060
activePendingIsResponding && activePendingUserInput
50545061
? [...respondingRequestIds, activePendingUserInput.requestId]
@@ -5059,6 +5066,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
50595066
onToggleOption={onSelectActivePendingUserInputOption}
50605067
onAdvance={onAdvanceActivePendingUserInput}
50615068
onDismiss={onDismissActivePendingUserInput}
5069+
isAnswering={isAnsweringPendingUserInput}
5070+
onToggleAnswering={onToggleAnsweringPendingUserInput}
50625071
/>
50635072
) : !isComposerCollapsedMobile && showPlanFollowUpPrompt && activeProposedPlan ? (
50645073
<ComposerPlanFollowUpBanner
@@ -5079,6 +5088,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
50795088
onToggleOption={onSelectActivePendingUserInputOption}
50805089
onAdvance={onAdvanceActivePendingUserInput}
50815090
onDismiss={onDismissActivePendingUserInput}
5091+
isAnswering={isAnsweringPendingUserInput}
5092+
onToggleAnswering={onToggleAnsweringPendingUserInput}
50825093
/>
50835094
{!isChoiceOnlyPendingQuestion ||
50845095
activePendingProgress?.activeQuestion?.multiSelect ? (
@@ -5737,7 +5748,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
57375748
isComposerApprovalState ||
57385749
projectSelectionRequired ||
57395750
isChoiceOnlyPendingQuestion ||
5740-
activePendingIsResponding
5751+
(isAnsweringPendingUserInput && activePendingIsResponding)
57415752
}
57425753
/>
57435754
{isComposerResting ? collapsedComposerImagePreviews : null}

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.test.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ function renderPanel(pendingUserInput: PendingUserInput = prompt) {
3333
onToggleOption={() => {}}
3434
onAdvance={() => {}}
3535
onDismiss={() => {}}
36+
isAnswering={false}
37+
onToggleAnswering={() => {}}
3638
/>,
3739
);
3840
}

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { CheckIcon } from "lucide-react";
99
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
1010
import { cn } from "~/lib/utils";
1111
import { ComposerBanner } from "./ComposerBanner";
12+
import { Button } from "../ui/button";
1213

1314
interface PendingUserInputPanelProps {
1415
pendingUserInputs: PendingUserInput[];
@@ -18,6 +19,8 @@ interface PendingUserInputPanelProps {
1819
onToggleOption: (questionId: string, optionValue: string) => void;
1920
onAdvance: () => void;
2021
onDismiss: (requestId: ApprovalRequestId) => void;
22+
isAnswering: boolean;
23+
onToggleAnswering: () => void;
2124
}
2225

2326
export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserInputPanel({
@@ -28,6 +31,8 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
2831
onToggleOption,
2932
onAdvance,
3033
onDismiss,
34+
isAnswering,
35+
onToggleAnswering,
3136
}: PendingUserInputPanelProps) {
3237
if (pendingUserInputs.length === 0) return null;
3338
const activePrompt = pendingUserInputs[0];
@@ -43,6 +48,8 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
4348
onToggleOption={onToggleOption}
4449
onAdvance={onAdvance}
4550
onDismiss={onDismiss}
51+
isAnswering={isAnswering}
52+
onToggleAnswering={onToggleAnswering}
4653
/>
4754
);
4855
});
@@ -55,6 +62,8 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
5562
onToggleOption,
5663
onAdvance,
5764
onDismiss,
65+
isAnswering,
66+
onToggleAnswering,
5867
}: {
5968
prompt: PendingUserInput;
6069
isResponding: boolean;
@@ -63,6 +72,8 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
6372
onToggleOption: (questionId: string, optionValue: string) => void;
6473
onAdvance: () => void;
6574
onDismiss: (requestId: ApprovalRequestId) => void;
75+
isAnswering: boolean;
76+
onToggleAnswering: () => void;
6677
}) {
6778
const progress = derivePendingUserInputProgress(prompt.questions, answers, questionIndex);
6879
const activeQuestion = progress.activeQuestion;
@@ -287,6 +298,16 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
287298
);
288299
})}
289300
</div>
301+
<Button
302+
type="button"
303+
variant="ghost"
304+
size="sm"
305+
className="mt-1"
306+
disabled={isResponding}
307+
onClick={onToggleAnswering}
308+
>
309+
{isAnswering ? "Back to message" : "Answer question"}
310+
</Button>
290311
</ComposerBanner.Body>
291312
</CollapsiblePanel>
292313
</Collapsible>

‎docs/user/question-attachments.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Files in question answers
22

3-
When an agent asks a question that accepts a custom answer, use **Attach files** or paste an image into the answer field. On mobile, use the attachment button to choose photos or files. You can send a file by itself, with a selected option, or with a typed answer.
3+
When an agent asks a question that accepts a custom answer, choose **Answer question** on web or desktop, then use **Attach files** or paste an image into the answer field. **Back to message** returns to your normal draft. On mobile, use the attachment button to choose photos or files. You can send a file by itself, with a selected option, or with a typed answer.
44

55
Each question keeps its own attachments as you move between questions. Your normal prompt draft stays separate. Wait for uploads to finish before submitting; retry or remove any failed upload. A failed response keeps the draft available to try again.
66

0 commit comments

Comments
 (0)