Skip to content

Commit 4841735

Browse files
committed
fix(web): find and collapse count a quote card the way it renders
Find indexed the text before a quote together with the quote's comment, so a query spanning both counted a match it could not highlight. A message made only of uncommented quotes had no visible text and never collapsed.
1 parent 4a5d885 commit 4841735

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4538,22 +4538,25 @@ describe("subagent continued by a later turn", () => {
45384538
});
45394539

45404540
describe("shouldCollapseUserMessage", () => {
4541-
it("measures a quote chip by its label, not its encoded link", () => {
4541+
it("measures a quote by its card, not its encoded link", () => {
45424542
const quote = "A long assistant paragraph that the user quoted. ".repeat(40);
4543-
const citation = serializeAssistantCitation({
4544-
version: 1,
4543+
const source = {
4544+
version: 1 as const,
45454545
environmentId: EnvironmentId.make("environment"),
45464546
threadId: ThreadId.make("thread"),
45474547
messageId: MessageId.make("source"),
45484548
text: quote,
4549-
comment: "Why does this matter?",
45504549
start: 0,
45514550
end: quote.length,
45524551
prefix: "",
45534552
suffix: "",
4554-
});
4553+
};
4554+
const citation = serializeAssistantCitation({ ...source, comment: "Why does this matter?" });
4555+
const bare = serializeAssistantCitation(source);
45554556

45564557
expect(shouldCollapseUserMessage(`${citation} Can you expand on this?`)).toBe(false);
45574558
expect(shouldCollapseUserMessage(`${citation} ${"More text. ".repeat(60)}`)).toBe(true);
4559+
expect(shouldCollapseUserMessage(bare.repeat(2))).toBe(false);
4560+
expect(shouldCollapseUserMessage(bare.repeat(10))).toBe(true);
45584561
});
45594562
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,9 +2651,9 @@ function visibleUserMessageText(text: string): string {
26512651
let visible = "";
26522652
let cursor = 0;
26532653
for (const match of collectAssistantCitations(text)) {
2654-
// A quote shows as a two-line card with its comment under it.
2654+
// A quote shows as a two-line card, counted here as a mark, with its comment under it.
26552655
visible += linkLabels(text.slice(cursor, match.start));
2656-
visible += "\n\n" + (match.citation.comment ?? "") + "\n";
2656+
visible += "\n\u275D\n" + (match.citation.comment ?? "") + "\n";
26572657
cursor = match.end;
26582658
}
26592659
return visible + linkLabels(text.slice(cursor));

‎packages/shared/src/threadFindText.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ it("indexes a citation by its comment, not its quote or link text", () => {
110110
};
111111
const text = `Please fix ${serializeAssistantCitation(citation)} thanks`;
112112
expect(searchableMessageSegments({ role: "user", text, streaming: false })).toEqual([
113-
"Please fix thanks",
113+
"Please fix ",
114+
" thanks",
114115
]);
115116
const commented = serializeAssistantCitation({ ...citation, comment: "my\nnote" });
116-
expect(searchableMessageSegments({ role: "user", text: commented, streaming: false })).toEqual([
117-
"my note",
118-
]);
117+
expect(
118+
searchableMessageSegments({ role: "user", text: `fix ${commented} thanks`, streaming: false }),
119+
).toEqual(["fix ", "my note thanks"]);
119120
});

‎packages/shared/src/threadFindText.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ function markdownThreadFindText(
141141
const citation =
142142
node.tagName === "a" && typeof href === "string" ? parseAssistantCitationHref(href) : null;
143143
if (citation) {
144-
// The quote card is not searched; its text is found in the message it came from.
144+
// The quote card is not searched, and it splits the text before it from its comment.
145+
flush();
145146
text += (citation.comment ?? "").replace(/\r?\n/g, " ");
146147
return;
147148
}

0 commit comments

Comments
 (0)