feat(web): render AskUserQuestion exchanges as a stylized Q&A list #5867
Closedzacksmash(GitHub profile, opens in a new tab)wants to merge 8 commits into
main fromrefs/pull/5867/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/chat/MessagesTimeline.tsx line 2432OutdatedResolvedby zacksmash(GitHub profile, opens in a new tab)@@ -2367,3 +2429,4 @@23672429 </div>23682430 </div>23692431 </div>2432+ {workEntry.userInput ? <UserInputQABlock userInput={workEntry.userInput} /> : null}
- apps/web/src/session-logic.ts lines 1049 to 1050OutdatedResolvedby zacksmash(GitHub profile, opens in a new tab)@@ -950,3 +1030,21 @@9501030 // rows (live-test finding, thread 7ac7ef05).9511031 const groupKeyByTaskId = new Map<string, string>();1032+ // User-input exchanges collapse by requestId, not adjacency: unrelated rows1033+ // (e.g. background task ticks) can land between the request and the answer.1034+ const userInputRowIndex = new Map<string, number>();9521035 for (const entry of entries) {1036+ if (entry.userInputRequestId !== undefined) {1037+ if (entry.activityKind === "user-input.requested") {1038+ userInputRowIndex.set(entry.userInputRequestId, collapsed.length);1039+ collapsed.push(entry);1040+ continue;1041+ }1042+ if (entry.activityKind === "user-input.resolved") {1043+ const requestedIndex = userInputRowIndex.get(entry.userInputRequestId);1044+ if (requestedIndex !== undefined) {1045+ const requested = collapsed[requestedIndex]!;1046+ // Keep the request's anchor identity (id/createdAt/turnId) so the1047+ // row renders where the questions appeared; the resolved row wins1048+ // the label and contributes the answers.1049+ collapsed[requestedIndex] = {1050+ ...requested,
- apps/web/src/components/chat/MessagesTimeline.tsx line 2290OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2229,4 +2285,6 @@22292285 }) {22302286 const { workEntry, workspaceRoot } = props;22312287 const activity = use(TimelineRowActivityCtx);2232- const [expanded, setExpanded] = useState(false);2288+ // User-input Q&A rows start expanded — the exchange is conversation2289+ // content — but collapse through the same row toggle as tool bodies.2290+ const [expanded, setExpanded] = useState(workEntry.userInput !== undefined);
- @@ -759,3 +808,6 @@759808 if (activity.kind === "context-window.updated") continue;760809 if (activity.summary === "Checkpoint captured") continue;761810 if (isPlanBoundaryToolActivity(activity)) continue;811+ // User-input exchanges are first-class timeline entries (see812+ // deriveUserInputExchanges), not work-log rows.813+ if (activity.kind === "user-input.requested" || activity.kind === "user-input.resolved") {
- apps/web/src/session-logic.ts line 1760OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1600,6 +1745,16 @@16001745 createdAt: entry.createdAt,16011746 entry,16021747 }));1603- return [...messageRows, ...proposedPlanRows, ...turnPlanRows, ...workRows].toSorted((a, b) =>1604- a.createdAt.localeCompare(b.createdAt),1605- );1748+ const userInputRows: TimelineEntry[] = userInputExchanges.map((userInputExchange) => ({1749+ id: userInputExchange.id,1750+ kind: "user-input",1751+ createdAt: userInputExchange.createdAt,1752+ userInputExchange,1753+ }));1754+ return [1755+ ...messageRows,1756+ ...proposedPlanRows,1757+ ...turnPlanRows,1758+ ...workRows,1759+ ...userInputRows,1760+ ].toSorted((a, b) => a.createdAt.localeCompare(b.createdAt));
- apps/web/src/session-logic.ts lines 1047 to 1053Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -770,0 +875,21 @@875+ if (openIndex !== undefined) {876+ const open = entries[openIndex]!;877+ entries[openIndex] = {878+ ...open,879+ ...(answers ? { answers } : {}),880+ resolved: true,881+ };882+ continue;883+ }884+ // Resolved without a visible request (e.g. truncated history): the answer885+ // keys are the question texts, so the exchange still renders.886+ if (answers) {887+ entries.push({888+ id: activity.id,889+ createdAt: activity.createdAt,890+ turnId: activity.turnId,891+ ...(activity.sequence !== undefined ? { sequence: activity.sequence } : {}),892+ questions: [],893+ answers,894+ resolved: true,895+ });apps/web/src/session-logic.ts line 874OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -770,0 +854,21 @@854+ if (activity.kind === "user-input.requested") {855+ const questions = parseUserInputQuestions(payload);856+ if (!questions) {857+ continue;858+ }859+ if (requestId) {860+ openIndexByRequestId.set(requestId, entries.length);861+ }862+ entries.push({863+ id: activity.id,864+ createdAt: activity.createdAt,865+ turnId: activity.turnId,866+ ...(activity.sequence !== undefined ? { sequence: activity.sequence } : {}),867+ questions,868+ resolved: false,869+ });870+ continue;871+ }872+873+ const answers = parseUserInputAnswers(payload);874+ const openIndex = requestId !== null ? openIndexByRequestId.get(requestId) : undefined;
- @@ -768,3 +829,18 @@768829 });769830 }770831832+/**833+ * Pairs `user-input.requested`/`user-input.resolved` activities by requestId834+ * into one Q&A exchange per interaction, anchored where the questions835+ * appeared. Unrelated rows may land between the request and the answer.836+ */837+export function deriveUserInputExchanges(838+ activities: ReadonlyArray<OrchestrationThreadActivity>,839+): UserInputExchangeEntry[] {840+ const ordered = [...activities].toSorted(compareActivitiesByOrder);841+ const entries: UserInputExchangeEntry[] = [];842+ const openIndexByRequestId = new Map<string, number>();843+ for (const activity of ordered) {844+ if (activity.kind !== "user-input.requested" && activity.kind !== "user-input.resolved") {845+ continue;846+ }
- apps/web/src/session-logic.ts line 935Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -768,3 +832,12 @@768832 });769833 }770834835+/**836+ * Pairs `user-input.requested`/`user-input.resolved` activities by requestId837+ * into one Q&A exchange per interaction, anchored where the questions838+ * appeared. Unrelated rows may land between the request and the answer.839+ */840+export function deriveUserInputExchanges(841+ activities: ReadonlyArray<OrchestrationThreadActivity>,842+): UserInputExchangeEntry[] {843+ const ordered = [...activities].toSorted(compareActivitiesByOrder);
- @@ -770,0 +932,21 @@932+ };933+ continue;934+ }935+ // Resolved without a visible request (e.g. truncated history, or the936+ // request sorted after us): the answer keys are the question texts, so937+ // the exchange still renders; a later request re-anchors it.938+ if (answers) {939+ if (requestId !== null) {940+ orphanResolvedIndexByRequestId.set(requestId, entries.length);941+ }942+ entries.push({943+ id: activity.id,944+ createdAt: activity.createdAt,945+ turnId: activity.turnId,946+ ...(activity.sequence !== undefined ? { sequence: activity.sequence } : {}),947+ ...(requestId !== null ? { requestId } : {}),948+ questions: [],949+ answers,950+ resolved: true,951+ });952+ }
- apps/web/src/components/chat/MessagesTimeline.tsx lines 2196 to 2229OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2122,0 +2209,21 @@2209+ className="flex cursor-pointer select-none items-center gap-1.5 px-2 py-1.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"2210+ >2211+ <span className="flex size-5 shrink-0 items-center justify-center text-icon-muted">2212+ <MessageCircleIcon2213+ className="block size-3.5 shrink-0 stroke-[1.8] opacity-80"2214+ aria-hidden2215+ />2216+ </span>2217+ <p className="min-w-0 flex-1 truncate font-medium text-[12px] text-foreground leading-5">2218+ {label}2219+ </p>2220+ <span className="flex size-4 shrink-0 items-center justify-center text-icon-muted">2221+ <ChevronDownIcon2222+ className={cn(2223+ "size-3 shrink-0 opacity-70 transition-transform duration-200",2224+ expanded && "rotate-180",2225+ )}2226+ aria-hidden2227+ />2228+ </span>2229+ </div>
- apps/web/src/components/chat/MessagesTimeline.logic.ts lines 741 to 741OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -725,4 +735,7 @@725735 entry.entry.toolLifecycleStatus === "inProgress"726736 );727737 }738+ // A Q&A card is rendered content, and a pending one means the agent is739+ // blocked on the user — a "Thinking" shimmer under it would be a lie.728740 if (entry.kind === "proposed-plan" || entry.kind === "turn-plan") return true;741+ if (entry.kind === "user-input") return true;
- apps/web/src/session-logic.ts lines 968 to 970OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -862,0 +950,21 @@950+ ) {951+ continue;952+ }953+ const payload =954+ activity.payload && typeof activity.payload === "object"955+ ? (activity.payload as Record<string, unknown>)956+ : null;957+ const requestId =958+ typeof payload?.requestId === "string" && payload.requestId.length > 0959+ ? payload.requestId960+ : null;961+962+ // A stale respond-failure retires the prompt (the composer clears it via963+ // derivePendingUserInputs) — settle the card too, else it waits forever.964+ if (activity.kind === "provider.user-input.respond.failed") {965+ const detail = typeof payload?.detail === "string" ? payload.detail : undefined;966+ if (requestId !== null && isStalePendingRequestFailureDetail(detail)) {967+ const openIndex = openIndexByRequestId.get(requestId);968+ if (openIndex !== undefined && !entries[openIndex]!.resolved) {969+ entries[openIndex] = { ...entries[openIndex]!, resolved: true };970+ }
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed