Skip to content

Commit 05adc16

Browse files
authored
fix(web): hide empty replies when renders show the result (#34182)
1 parent 0815d98 commit 05adc16

3 files changed

Lines changed: 82 additions & 1 deletion

File tree

‎apps/web/src/components/chat/MessagesTimeline.logic.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,74 @@ describe("resolveAssistantMessageCopyState", () => {
5555
});
5656

5757
describe("deriveMessagesTimelineRows", () => {
58+
it.each([
59+
["html-render", "reply-run", true],
60+
["mcp-app", "reply-run", true],
61+
["html-render", "other-run", false],
62+
["html-render", null, false],
63+
[null, null, false],
64+
] as const)("suppresses the empty fallback for %s in %s: %s", (kind, renderRun, expected) => {
65+
const at = "2026-11-06T00:00:00Z";
66+
const runId = RunId.make("reply-run");
67+
const renderBase = {
68+
id: "render",
69+
createdAt: at,
70+
runId: renderRun ? RunId.make(renderRun) : null,
71+
};
72+
const embedded: TimelineEntry[] =
73+
kind === "html-render"
74+
? [
75+
{
76+
...renderBase,
77+
kind,
78+
htmlRender: { attachmentId: "preview", title: "Preview", height: 420 },
79+
},
80+
]
81+
: kind === "mcp-app"
82+
? [
83+
{
84+
...renderBase,
85+
kind,
86+
sourceThreadId: ThreadId.make("thread"),
87+
itemId: TurnItemId.make("app"),
88+
revision: "1",
89+
mcpApp: {
90+
attachmentId: "app",
91+
server: "weather",
92+
tool: "weather",
93+
resourceUri: "ui://weather",
94+
},
95+
},
96+
]
97+
: [];
98+
const rows = deriveMessagesTimelineRows({
99+
timelineEntries: [
100+
...embedded,
101+
{
102+
kind: "message",
103+
id: "reply",
104+
createdAt: at,
105+
message: {
106+
id: MessageId.make("reply"),
107+
role: "assistant",
108+
runId,
109+
text: "",
110+
streaming: false,
111+
createdAt: at,
112+
updatedAt: at,
113+
},
114+
},
115+
],
116+
latestRun: null,
117+
isWorking: false,
118+
activeTurnStartedAt: null,
119+
turnDiffSummaries: [],
120+
supportsConversationRollback: false,
121+
});
122+
const reply = rows.find((row) => row.kind === "message" && row.id === "reply");
123+
expect(reply).toMatchObject({ suppressEmptyResponse: expected });
124+
});
125+
58126
it.each(["alone", "before tool", "before commentary and tool"])(
59127
"keeps an unfinished task update static %s",
60128
(placement) => {

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ type MessagesTimelineRowContent =
594594
message: ChatMessage;
595595
projectedItem?: OrchestrationV2ProjectedTurnItem;
596596
showAssistantMeta: boolean;
597+
suppressEmptyResponse?: boolean;
597598
showAssistantCopyButton: boolean;
598599
assistantCopyStreaming: boolean;
599600
assistantTurnDiffSummary?: TurnDiffSummary | undefined;
@@ -1520,6 +1521,12 @@ export function deriveMessagesTimelineRows(input: {
15201521
revealedMessageId?: MessageId | null;
15211522
}): MessagesTimelineRow[] {
15221523
const timelineEntries = timelineRowEntries(input);
1524+
const embeddedResultRunIds = new Set<RunId>();
1525+
for (const entry of timelineEntries) {
1526+
if ((entry.kind === "html-render" || entry.kind === "mcp-app") && entry.runId !== null) {
1527+
embeddedResultRunIds.add(entry.runId);
1528+
}
1529+
}
15231530
const isPendingApproval = (entry: WorkLogEntry) => {
15241531
const item = entry.projectedItem?.item;
15251532
return (
@@ -2164,6 +2171,10 @@ export function deriveMessagesTimelineRows(input: {
21642171
? {}
21652172
: { projectedItem: timelineEntry.projectedItem }),
21662173
showAssistantMeta,
2174+
suppressEmptyResponse:
2175+
timelineEntry.message.role === "assistant" &&
2176+
timelineEntry.message.runId != null &&
2177+
embeddedResultRunIds.has(timelineEntry.message.runId),
21672178
showAssistantCopyButton: showAssistantMeta,
21682179
assistantCopyStreaming: timelineEntry.message.streaming || assistantResponseStillInProgress,
21692180
assistantTurnDiffSummary:
@@ -2633,6 +2644,7 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
26332644
a.message === bm.message &&
26342645
a.projectedItem === bm.projectedItem &&
26352646
a.showAssistantMeta === bm.showAssistantMeta &&
2647+
a.suppressEmptyResponse === bm.suppressEmptyResponse &&
26362648
a.showAssistantCopyButton === bm.showAssistantCopyButton &&
26372649
a.assistantCopyStreaming === bm.assistantCopyStreaming &&
26382650
a.assistantTurnDiffSummary === bm.assistantTurnDiffSummary &&

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind
3232
row.projectedItem?.item.id,
3333
);
3434
const text = liveText ?? row.message.text;
35-
const messageText = text || (row.message.streaming ? "" : "(empty response)");
35+
const messageText =
36+
text || (row.message.streaming || row.suppressEmptyResponse ? "" : "(empty response)");
3637

3738
return (
3839
<>

0 commit comments

Comments
 (0)