Skip to content

Commit f6c9bbd

Browse files
committed
fix(web): reveal linked agent and automation messages
1 parent 6fe56ec commit f6c9bbd

4 files changed

Lines changed: 58 additions & 2 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,3 +993,43 @@ it("renders automatic compaction as one live divider that finishes with its reas
993993
expect(container.querySelectorAll('[role="separator"]')).toHaveLength(1);
994994
expect(container.textContent).not.toContain("Compacting before");
995995
});
996+
997+
it.each(["agent", "automation"] as const)(
998+
"opens a linked %s body and keeps it open after consuming the link",
999+
async (attribution) => {
1000+
setup();
1001+
const props = baseProps();
1002+
const entries = [
1003+
message(
1004+
"Folded preview\n\nThe linked body must be visible.",
1005+
attribution === "agent"
1006+
? { createdBy: "agent", senderThreadId: SENDER_THREAD_ID }
1007+
: { scheduledTaskId: TASK_ID },
1008+
),
1009+
];
1010+
const onLinkedMessageHandled = vi.fn();
1011+
const timeline = (key: string | null) => (
1012+
<MessagesTimeline
1013+
{...props}
1014+
timelineEntries={entries}
1015+
linkedMessageSynced
1016+
linkedMessage={key === null ? null : { messageId: MessageId.make("message-1"), key }}
1017+
onLinkedMessageHandled={onLinkedMessageHandled}
1018+
/>
1019+
);
1020+
await using screen = await renderElement(timeline(null));
1021+
const heading = attribution === "agent" ? /^Agent/ : /^Automation/;
1022+
expect(screen.button(heading).getAttribute("aria-expanded")).toBe("false");
1023+
await screen.rerender(timeline("first-link"));
1024+
await vi.waitFor(() => expect(onLinkedMessageHandled).toHaveBeenCalledWith("first-link"));
1025+
expect(screen.button(heading).getAttribute("aria-expanded")).toBe("true");
1026+
expect(screen.text()).toContain("The linked body must be visible.");
1027+
await screen.rerender(timeline(null));
1028+
expect(screen.button(heading).getAttribute("aria-expanded")).toBe("true");
1029+
await click(screen.button(heading));
1030+
expect(screen.button(heading).getAttribute("aria-expanded")).toBe("false");
1031+
await screen.rerender(timeline("second-link"));
1032+
await vi.waitFor(() => expect(onLinkedMessageHandled).toHaveBeenCalledWith("second-link"));
1033+
expect(screen.button(heading).getAttribute("aria-expanded")).toBe("true");
1034+
},
1035+
);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
10571057

10581058
const sharedState: TimelineRowSharedState = {
10591059
citationRequest: readyCitationRequest,
1060+
linkedMessage,
10601061
listRef,
10611062
timestampFormat,
10621063
routeThreadKey,

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ import {
7474
} from "./TimelineRowParts";
7575
import { UserMessageContextReferenceChip } from "./UserMessageContextChips";
7676
import { resolvePreviewAnnotationImage } from "./TimelineUserMessageRow.logic";
77+
import type { LinkedMessageRequest } from "../promptLinks/ThreadLinkParams";
78+
79+
function useLinkedMessageExpansion(messageId: MessageId, request: LinkedMessageRequest | null) {
80+
const revealKey = request?.messageId === messageId ? request.key : null;
81+
const [lastRevealKey, setLastRevealKey] = useState(revealKey);
82+
const [expanded, setExpanded] = useState(revealKey !== null);
83+
// Reveal before the timeline positions the row, and retain it after URL consumption.
84+
if (revealKey !== null && revealKey !== lastRevealKey) {
85+
setLastRevealKey(revealKey);
86+
setExpanded(true);
87+
}
88+
return [expanded, setExpanded] as const;
89+
}
7790

7891
function UserVideoAttachment({ file }: { readonly file: ChatFileAttachment }) {
7992
const ctx = use(TimelineRowCtx);
@@ -137,7 +150,7 @@ export function UserMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mes
137150
/** Automation prompts are long, repeated runbooks; a folded bubble keeps them out of the way. */
138151
function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
139152
const ctx = use(TimelineRowCtx);
140-
const [expanded, setExpanded] = useState(false);
153+
const [expanded, setExpanded] = useLinkedMessageExpansion(row.message.id, ctx.linkedMessage);
141154
const revealRef = findRevealRef(() => setExpanded(true));
142155
const { text, scheduledTaskId } = resolveUserMessagePresentation(row.message);
143156
const tasksQuery = useEnvironmentQuery(
@@ -305,7 +318,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
305318
const userMessage = resolveUserMessagePresentation(row.message);
306319
// Messages from other agents fold to one line so the user's own messages stay easy to find.
307320
const folded = userMessage.attribution === "agent";
308-
const [expanded, setExpanded] = useState(false);
321+
const [expanded, setExpanded] = useLinkedMessageExpansion(row.message.id, ctx.linkedMessage);
309322
const revealFoldRef = findRevealRef(() => setExpanded(true));
310323
const senderShell = useQuietThreadShell(
311324
folded && senderThreadId

‎apps/web/src/components/chat/timelineRowContext.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { type MessagesTimelineRow, type WorkGroupScrollAnchor } from "./Messages
2323
import { type TimestampFormat } from "@t3tools/contracts/settings";
2424
import type { TurnItemDetailSource } from "../../state/queries";
2525
import { type HandoffTimelineRun } from "./V2LifecycleRow";
26+
import type { LinkedMessageRequest } from "../promptLinks/ThreadLinkParams";
2627

2728
/**
2829
* Where an expanded row reads an item's detail and a command's output. The owner's rows read them
@@ -38,6 +39,7 @@ export interface TurnItemSource {
3839

3940
export interface TimelineRowSharedState {
4041
citationRequest: AssistantCitationTarget | null;
42+
linkedMessage: LinkedMessageRequest | null;
4143
listRef: React.RefObject<LegendListRef | null>;
4244
timestampFormat: TimestampFormat;
4345
routeThreadKey: string;

0 commit comments

Comments
 (0)