diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts index 2890b68110b3f..90fbabb18334d 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts @@ -546,7 +546,7 @@ describe("deriveMessagesTimelineRows", () => { expect(foldRow?.label).toBe("Worked for 22s"); expect(collapsedRows.map((row) => row.id)).toEqual([ "user-entry", - "turn-fold:turn-1", + "turn-fold:assistant-first-entry", "assistant-final-entry", ]); @@ -561,7 +561,7 @@ describe("deriveMessagesTimelineRows", () => { expect(expandedRows.map((row) => row.id)).toEqual([ "user-entry", - "turn-fold:turn-1", + "turn-fold:assistant-first-entry", "assistant-first-entry", "work-toggle:work-entry-1", "assistant-final-entry", @@ -625,7 +625,10 @@ describe("deriveMessagesTimelineRows", () => { revertTurnCountByUserMessageId: new Map(), }); - expect(rows.map((row) => row.id)).toEqual(["turn-fold:turn-1", "assistant-final-entry"]); + expect(rows.map((row) => row.id)).toEqual([ + "turn-fold:assistant-first-entry", + "assistant-final-entry", + ]); }); it("derives a sane duration for a steer-superseded turn with one instant commentary message", () => { @@ -822,7 +825,7 @@ describe("deriveMessagesTimelineRows", () => { }); expect(rows.map((row) => row.id)).toEqual([ - "turn-fold:turn-1", + "turn-fold:work-entry-1", "assistant-final-entry", "user-followup-entry", "working-indicator-row", @@ -1379,7 +1382,7 @@ describe("deriveMessagesTimelineRows", () => { // turn id that opened the response. expect(rows.map((row) => row.id)).toEqual([ "user-1-entry", - "turn-fold:turn-1", + "turn-fold:work-1-entry", "assistant-final-entry", ]); const foldRow = rows.find( @@ -1411,7 +1414,7 @@ describe("deriveMessagesTimelineRows", () => { expect(rows.some((row) => row.kind === "turn-fold")).toBe(false); }); - it("keeps one fold across a same-turn steer and keeps both user messages visible", () => { + it("folds a same-turn steer as one segment per side of the steer", () => { const timelineEntries = [ userEntry("user-1", "2026-01-01T00:00:00Z"), workEntry("work-1", "2026-01-01T00:00:05Z", "turn-1"), @@ -1431,7 +1434,12 @@ describe("deriveMessagesTimelineRows", () => { isWorking: true, activeTurnStartedAt: "2026-01-01T00:00:00Z", }); - expect(runningRows.some((row) => row.kind === "turn-fold")).toBe(false); + // The pre-steer segment is settled and folds as soon as the steer is + // sent; the post-steer segment is the live one and stays unfolded. + const runningFoldRows = runningRows.filter((row) => row.kind === "turn-fold"); + expect(runningFoldRows.map((row) => row.id)).toEqual(["turn-fold:work-1-entry"]); + expect(runningFoldRows[0]?.label).toBe("Worked for 5.0s"); + expect(runningRows.map((row) => row.id)).toContain("work-toggle:work-2-entry"); const settledRows = deriveMessagesTimelineRows({ ...baseFoldInput, @@ -1445,13 +1453,24 @@ describe("deriveMessagesTimelineRows", () => { }); expect(settledRows.map((row) => row.id)).toEqual([ "user-1-entry", - "turn-fold:turn-1", + "turn-fold:work-1-entry", "user-steer-entry", + "turn-fold:work-2-entry", "assistant-final-entry", ]); + expect( + settledRows + .filter((row) => row.kind === "turn-fold") + .map((row) => row.kind === "turn-fold" && row.label), + ).toEqual(["Worked for 5.0s", "Worked for 20s"]); + expect( + settledRows.flatMap((row) => + row.kind === "message" && row.showsTurnFoldSeparator ? [row.id] : [], + ), + ).toEqual(["assistant-final-entry"]); }); - it("keeps fold row ids unique when an old-turn row straddles the next user message", () => { + it("keys the fold after a user message by the new turn even when old-turn residue lands first", () => { const rows = deriveMessagesTimelineRows({ ...baseFoldInput, timelineEntries: [ @@ -1459,34 +1478,36 @@ describe("deriveMessagesTimelineRows", () => { workEntry("work-1", "2026-01-01T00:00:05Z", "turn-1"), assistantEntry("assistant-one", "2026-01-01T00:00:10Z", "turn-1"), userEntry("user-2", "2026-01-01T00:00:20Z"), - workEntry("work-2", "2026-01-01T00:00:22Z", "turn-2"), - // Background turn-1 row landing after the next user message: it must - // join turn-1's fold, not spawn a duplicate row id or absorb turn-2. - workEntry("work-late", "2026-01-01T00:00:23Z", "turn-1"), - // A wake-up continuation after the straddling row still belongs to the - // second response, not to the straddler's. - workEntry("work-3", "2026-01-01T00:00:25Z", "turn-3"), - assistantEntry("assistant-two", "2026-01-01T00:00:40Z", "turn-3"), + // Background turn-1 row landing after the next user message, before + // turn-2's own rows: the segment's turnId must still key off the new + // turn, not the straddling residue that happens to come first. + workEntry("work-late", "2026-01-01T00:00:22Z", "turn-1"), + workEntry("work-2", "2026-01-01T00:00:24Z", "turn-2"), + assistantEntry("assistant-two", "2026-01-01T00:00:40Z", "turn-2"), ], latestTurn: { - turnId: "turn-3" as never, + turnId: "turn-2" as never, state: "completed", - startedAt: "2026-01-01T00:00:24Z", + startedAt: "2026-01-01T00:00:21Z", completedAt: "2026-01-01T00:00:40Z", }, }); expect(rows.map((row) => row.id)).toEqual([ "user-1-entry", - "turn-fold:turn-1", + "turn-fold:work-1-entry", "assistant-one-entry", "user-2-entry", - "turn-fold:turn-2", + "turn-fold:work-late-entry", "assistant-two-entry", ]); + expect(rows.filter((row) => row.kind === "turn-fold").map((row) => row.turnId)).toEqual([ + "turn-1", + "turn-2", + ]); }); - it("folds turn-less background rows into the latest response segment", () => { + it("folds turn-less background rows into the segment they land in", () => { // Background subagent activity carries no turn id at all. const turnlessEntry = (id: string, createdAt: string) => ({ id: `${id}-entry`, @@ -1502,7 +1523,8 @@ describe("deriveMessagesTimelineRows", () => { turnlessEntry("bg-1", "2026-01-01T00:00:10Z"), assistantEntry("assistant-one", "2026-01-01T00:00:15Z", "turn-1"), userEntry("user-2", "2026-01-01T00:00:20Z"), - // Residue of the first response landing before the next turn starts. + // Residue of the first response landing after the next user message + // opens the second segment, so it anchors that segment's fold. turnlessEntry("bg-2", "2026-01-01T00:00:21Z"), workEntry("work-2", "2026-01-01T00:00:25Z", "turn-2"), turnlessEntry("bg-3", "2026-01-01T00:00:26Z"), @@ -1518,10 +1540,10 @@ describe("deriveMessagesTimelineRows", () => { expect(rows.map((row) => row.id)).toEqual([ "user-1-entry", - "turn-fold:turn-1", + "turn-fold:work-1-entry", "assistant-one-entry", "user-2-entry", - "turn-fold:turn-2", + "turn-fold:bg-2-entry", "assistant-two-entry", ]); }); @@ -1558,7 +1580,7 @@ describe("deriveMessagesTimelineRows", () => { const rows = deriveMessagesTimelineRows({ ...baseFoldInput, timelineEntries, latestTurn }); expect(rows.map((row) => row.id)).toEqual([ "user-1-entry", - "turn-fold:turn-1", + "turn-fold:work-1-entry", "spawn-1-entry", "spawn-wf-entry", "assistant-final-entry", @@ -1574,7 +1596,7 @@ describe("deriveMessagesTimelineRows", () => { ...baseFoldInput, timelineEntries, latestTurn, - expandedTurnIds: new Set(["turn-1" as never]), + expandedTurnIds: new Set(["turn-2" as never]), }); expect(expandedRows.map((row) => row.id)).toContain("spawn-2-entry"); const originalRow = expandedRows.find((row) => row.id === "spawn-1-entry"); @@ -1584,6 +1606,45 @@ describe("deriveMessagesTimelineRows", () => { }); }); + it("keeps the response and its spawn row in the post-steer segment only", () => { + const rows = deriveMessagesTimelineRows({ + ...baseFoldInput, + timelineEntries: [ + userEntry("user-1", "2026-01-01T00:00:00Z"), + assistantEntry("assistant-plan", "2026-01-01T00:00:04Z", "turn-1"), + workEntry("work-1", "2026-01-01T00:00:06Z", "turn-1"), + userEntry("user-steer", "2026-01-01T00:00:12Z"), + workEntry("work-2", "2026-01-01T00:00:18Z", "turn-1"), + spawnEntry("spawn-1", "2026-01-01T00:00:20Z", "turn-1", ["agent-a"]), + assistantEntry("assistant-final", "2026-01-01T00:00:40Z", "turn-1"), + ], + latestTurn: { + turnId: "turn-1" as never, + state: "completed", + startedAt: "2026-01-01T00:00:00Z", + completedAt: "2026-01-01T00:00:45Z", + }, + }); + + // The pre-steer segment ends with a tool row, so its commentary folds too. + expect(rows.map((row) => row.id)).toEqual([ + "user-1-entry", + "turn-fold:assistant-plan-entry", + "user-steer-entry", + "turn-fold:work-2-entry", + "spawn-1-entry", + "assistant-final-entry", + ]); + expect( + rows + .filter((row) => row.kind === "turn-fold") + .map((row) => row.kind === "turn-fold" && row.label), + ).toEqual(["Worked for 6.0s", "Worked for 33s"]); + expect( + rows.flatMap((row) => (row.kind === "message" && row.showsTurnFoldSeparator ? [row.id] : [])), + ).toEqual(["assistant-final-entry"]); + }); + it("uses the stopped label when the interrupted turn is a grouped synthetic continuation", () => { const rows = deriveMessagesTimelineRows({ ...baseFoldInput, @@ -1600,9 +1661,59 @@ describe("deriveMessagesTimelineRows", () => { }, }); + // The segment's own entries end at 00:00:10, but this segment holds the + // latest turn's entries, so the end is latestTurn.completedAt (00:00:47). expect(rows.filter((row) => row.kind === "turn-fold")).toEqual([ - expect.objectContaining({ turnId: "turn-1", label: "You stopped after 10s" }), + expect.objectContaining({ turnId: "turn-2", label: "You stopped after 47s" }), + ]); + }); + + it("shows assistant metadata on a fold's terminal message once its turn settles", () => { + const timelineEntries = [ + userEntry("user-1", "2026-01-01T00:00:00Z"), + workEntry("work-1", "2026-01-01T00:00:05Z", "turn-1"), + assistantEntry("assistant-plan", "2026-01-01T00:00:10Z", "turn-1"), + userEntry("user-steer", "2026-01-01T00:00:20Z"), + workEntry("work-2", "2026-01-01T00:00:25Z", "turn-1"), + assistantEntry("assistant-final", "2026-01-01T00:00:40Z", "turn-1"), + ]; + + const runningRows = deriveMessagesTimelineRows({ + ...baseFoldInput, + timelineEntries, + latestTurn: { + turnId: "turn-1" as never, + state: "running", + startedAt: "2026-01-01T00:00:00Z", + completedAt: null, + }, + isWorking: true, + activeTurnStartedAt: "2026-01-01T00:00:00Z", + }); + // The pre-steer fold is settled, but turn-1 itself is still running, so + // its terminal message still withholds metadata. + const runningPlanRow = runningRows.find((row) => row.id === "assistant-plan-entry"); + expect(runningPlanRow?.kind === "message" && runningPlanRow.showAssistantMeta).toBe(false); + + const settledRows = deriveMessagesTimelineRows({ + ...baseFoldInput, + timelineEntries, + latestTurn: { + turnId: "turn-1" as never, + state: "completed", + startedAt: "2026-01-01T00:00:00Z", + completedAt: "2026-01-01T00:00:40Z", + }, + }); + expect(settledRows.filter((row) => row.kind === "turn-fold").map((row) => row.id)).toEqual([ + "turn-fold:work-1-entry", + "turn-fold:work-2-entry", ]); + for (const id of ["assistant-plan-entry", "assistant-final-entry"]) { + const row = settledRows.find((r) => r.id === id); + expect(row?.kind === "message" && row.showAssistantMeta).toBe(true); + expect(row?.kind === "message" && row.showsTurnFoldSeparator).toBe(true); + } }); it("only shows assistant metadata on the terminal assistant message", () => { diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts index 68f6d5060914b..2c8bc847f654a 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -236,6 +236,8 @@ export type MessagesTimelineRow = message: ChatMessage; durationStart: string; showAssistantMeta: boolean; + /** Draws the separator of the fold this message closes. */ + showsTurnFoldSeparator: boolean; showAssistantCopyButton: boolean; assistantCopyStreaming: boolean; assistantTurnDiffSummary?: TurnDiffSummary | undefined; @@ -341,8 +343,10 @@ interface TurnFold { createdAt: string; hiddenEntryIds: ReadonlySet; label: string; - /** The group's direct-spawn CTA, carrying every direct spawn the fold absorbed. */ + /** The segment's direct-spawn CTA, carrying every direct spawn the fold absorbed. */ spawnRow: { entryId: string; entry: WorkLogEntry } | null; + /** The assistant message that closes the segment, when one does. */ + terminalEntryId: string | null; } /** @@ -392,98 +396,72 @@ function workEntryIsActiveTurnActivity(entry: WorkLogEntry): boolean { } /** - * Settled turns keep only their terminal assistant message visible. - * Everything before it folds behind a "Worked for ..." row anchored at the - * first hidden entry, so the duration leads directly into the final response. + * User messages cut the timeline into segments, and every settled segment + * folds behind one "Worked for ..." row anchored at its first hidden entry. + * A segment keeps only its direct-spawn CTA row and, when an assistant + * message closes it, that message. Because the timeline is in transcript + * order, a steer (a user message sent mid-turn) simply starts a new segment: + * the work it interrupted folds above it and the work it caused folds below. */ function deriveTurnFolds(input: { timelineEntries: ReadonlyArray; - terminalAssistantMessageIds: ReadonlySet; latestTurn: TimelineLatestTurn | null; unsettledTurnId: TurnId | null; }): ReadonlyMap { - interface TurnGroup { - /** The turn id that opened the group; keeps the fold's identity stable. */ - turnId: TurnId; + interface Segment { + /** Last turn id in the segment; folds expand per turn id. */ + turnId: TurnId | null; entries: Array; - terminalEntry: Extract | null; - hasStreamingMessage: boolean; /** - * The user message that kicked the turn off. Entry timestamps alone - * undercount the duration (the first entry appears only once the - * provider starts producing output), and a turn cut short by a steer may - * hold a single instantaneous commentary message. + * The user message that opened the segment. Entry timestamps alone + * undercount the duration: the first entry appears only once the + * provider starts producing output. */ startBoundary: string | null; } - const groupsByTurnId = new Map(); - - let pendingUserBoundary: string | null = null; - let lastGroup: TurnGroup | null = null; + const segments: Array = [{ turnId: null, entries: [], startBoundary: null }]; for (const entry of input.timelineEntries) { if (entry.kind === "message" && entry.message.role === "user") { - pendingUserBoundary = entry.message.createdAt; + segments.push({ turnId: null, entries: [], startBoundary: entry.message.createdAt }); continue; } - const turnId = - entry.kind === "message" && entry.message.role === "assistant" - ? (entry.message.turnId ?? null) - : entry.kind === "work" - ? (entry.entry.turnId ?? null) - : null; - // A turn-less row is background subagent activity: it rides the latest - // group, even past the next user message, since no new response has - // started until a turn id shows up. - let group: TurnGroup | null = turnId ? (groupsByTurnId.get(turnId) ?? null) : lastGroup; - if (!group) { - if (!turnId) { - continue; - } - // A fresh turn id with no user message since the last group opened is a - // synthetic mid-response continuation (subagent wake-up, stop-hook - // retry): it joins that group instead of starting a fold of its own. - group = (pendingUserBoundary === null ? lastGroup : null) ?? { - turnId, - entries: [], - terminalEntry: null, - hasStreamingMessage: false, - startBoundary: pendingUserBoundary, - }; - pendingUserBoundary = null; - groupsByTurnId.set(turnId, group); - lastGroup = group; - } - group.entries.push(entry); - if (entry.kind === "message") { - if (input.terminalAssistantMessageIds.has(entry.message.id)) { - group.terminalEntry = entry; - } - if (entry.message.streaming) { - group.hasStreamingMessage = true; - } - } + const segment = segments.at(-1)!; + segment.turnId = timelineEntryTurnId(entry) ?? segment.turnId; + segment.entries.push(entry); } + // New entries only ever append, so while a turn is unsettled the last + // segment is the live one; everything above it is finished. + const liveSegment = input.unsettledTurnId === null ? null : segments.at(-1); + // The latest turn's own clock covers the segment that ends it: a stop has + // no entry of its own, and a turn may start before it produces any entry. + const latestTurnSegment = segments.findLast((segment) => + segment.entries.some((entry) => timelineEntryTurnId(entry) === input.latestTurn?.turnId), + ); const foldsByAnchorEntryId = new Map(); - for (const group of new Set(groupsByTurnId.values())) { - const { turnId } = group; - if (input.unsettledTurnId !== null && groupsByTurnId.get(input.unsettledTurnId) === group) { + for (const segment of segments) { + const { turnId } = segment; + if (turnId === null || segment === liveSegment) { continue; } - if (group.hasStreamingMessage) { + if (segment.entries.some((entry) => entry.kind === "message" && entry.message.streaming)) { continue; } + // A turn id came from an entry, so the segment is not empty. + const lastEntry = segment.entries.at(-1)!; + const terminalEntry = + lastEntry.kind === "message" && lastEntry.message.role === "assistant" ? lastEntry : null; const hiddenEntryIds = new Set(); let spawnRow: TurnFold["spawnRow"] = null; - for (const entry of group.entries) { - if (entry.id === group.terminalEntry?.id) { + for (const entry of segment.entries) { + if (entry === terminalEntry) { continue; } // Agent-spawn CTA rows never fold: workflows outlive their launching // turn (dynamic spawns, background execution), and folding the CTA // when the turn settles makes a still-running fleet invisible. Direct // spawns are batched per turn id upstream, so a synthetic continuation - // yields a second CTA; the fold merges them into the group's first one. + // yields a second CTA; the fold merges them into the segment's first one. if (entry.kind === "work" && entry.entry.agentSpawn !== undefined) { if (entry.entry.agentSpawn.workflowId !== null) { continue; @@ -503,42 +481,27 @@ function deriveTurnFolds(input: { } hiddenEntryIds.add(entry.id); } - if (hiddenEntryIds.size === 0) { + const firstHiddenEntry = segment.entries.find((entry) => hiddenEntryIds.has(entry.id)); + if (!firstHiddenEntry) { continue; } - const firstEntry = group.entries[0]; - const firstHiddenEntry = group.entries.find((entry) => hiddenEntryIds.has(entry.id)); - const lastEntry = group.entries.at(-1); - if (!firstEntry || !firstHiddenEntry || !lastEntry) { - continue; - } - - const isLatestInterruptedTurn = - input.latestTurn?.state === "interrupted" && - groupsByTurnId.get(input.latestTurn.turnId) === group; - // A turn cut short by a steer leaves trailing work entries behind its - // terminal message — take whichever ended last. + const turn = segment === latestTurnSegment ? input.latestTurn : null; const lastEntryEnd = lastEntry.kind === "message" ? lastEntry.message.updatedAt : lastEntry.createdAt; - const elapsedMs = - input.latestTurn?.turnId === turnId && - input.latestTurn.startedAt && - input.latestTurn.completedAt - ? computeElapsedMs(input.latestTurn.startedAt, input.latestTurn.completedAt) - : computeElapsedMs( - group.startBoundary ?? firstEntry.createdAt, - maxIsoTimestamp(group.terminalEntry?.message.updatedAt ?? null, lastEntryEnd) ?? - lastEntryEnd, - ); + const elapsedMs = computeElapsedMs( + segment.startBoundary ?? turn?.startedAt ?? segment.entries[0]!.createdAt, + maxIsoTimestamp(lastEntryEnd, turn?.completedAt ?? null) ?? lastEntryEnd, + ); const duration = elapsedMs !== null ? formatDuration(elapsedMs) : null; - const label = isLatestInterruptedTurn - ? duration - ? `You stopped after ${duration}` - : "You stopped this response" - : duration - ? `Worked for ${duration}` - : "Worked"; + const label = + turn?.state === "interrupted" + ? duration + ? `You stopped after ${duration}` + : "You stopped this response" + : duration + ? `Worked for ${duration}` + : "Worked"; foldsByAnchorEntryId.set(firstHiddenEntry.id, { turnId, @@ -547,6 +510,7 @@ function deriveTurnFolds(input: { hiddenEntryIds, label, spawnRow, + terminalEntryId: terminalEntry?.id ?? null, }); } return foldsByAnchorEntryId; @@ -574,13 +538,16 @@ export function deriveMessagesTimelineRows(input: { ); const foldsByAnchorEntryId = deriveTurnFolds({ timelineEntries: input.timelineEntries, - terminalAssistantMessageIds, latestTurn: input.latestTurn ?? null, unsettledTurnId, }); const collapsedEntryIds = new Set(); const mergedSpawnEntries = new Map(); + const foldTerminalEntryIds = new Set(); for (const fold of foldsByAnchorEntryId.values()) { + if (fold.terminalEntryId !== null) { + foldTerminalEntryIds.add(fold.terminalEntryId); + } if (!input.expandedTurnIds?.has(fold.turnId)) { for (const entryId of fold.hiddenEntryIds) { collapsedEntryIds.add(entryId); @@ -704,7 +671,7 @@ export function deriveMessagesTimelineRows(input: { if (anchoredTurnFold) { nextRows.push({ kind: "turn-fold", - id: `turn-fold:${anchoredTurnFold.turnId}`, + id: `turn-fold:${anchoredTurnFold.anchorEntryId}`, createdAt: anchoredTurnFold.createdAt, turnId: anchoredTurnFold.turnId, label: anchoredTurnFold.label, @@ -848,7 +815,8 @@ export function deriveMessagesTimelineRows(input: { // settles so commentary doesn't flash timestamps mid-work. const showAssistantMeta = timelineEntry.message.role === "assistant" && - terminalAssistantMessageIds.has(timelineEntry.message.id) && + (terminalAssistantMessageIds.has(timelineEntry.message.id) || + foldTerminalEntryIds.has(timelineEntry.id)) && !assistantTurnStillInProgress; nextRows.push({ @@ -858,6 +826,7 @@ export function deriveMessagesTimelineRows(input: { message: timelineEntry.message, durationStart, showAssistantMeta, + showsTurnFoldSeparator: foldTerminalEntryIds.has(timelineEntry.id), showAssistantCopyButton: showAssistantMeta, assistantCopyStreaming: timelineEntry.message.streaming || assistantTurnStillInProgress, assistantTurnDiffSummary: @@ -916,7 +885,12 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean case "turn-fold": { const bf = b as typeof a; - return a.createdAt === bf.createdAt && a.label === bf.label && a.expanded === bf.expanded; + return ( + a.turnId === bf.turnId && + a.createdAt === bf.createdAt && + a.label === bf.label && + a.expanded === bf.expanded + ); } case "proposed-plan": @@ -962,6 +936,7 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean a.message === bm.message && a.durationStart === bm.durationStart && a.showAssistantMeta === bm.showAssistantMeta && + a.showsTurnFoldSeparator === bm.showsTurnFoldSeparator && a.showAssistantCopyButton === bm.showAssistantCopyButton && a.assistantCopyStreaming === bm.assistantCopyStreaming && a.assistantTurnDiffSummary === bm.assistantTurnDiffSummary && diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index 2f9cd56c893c2..348475129b32c 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -169,7 +169,7 @@ interface TimelineRowSharedState { onFileOpen: (attachment: ChatFileAttachment) => void; openingVideoAttachmentId: string | null; onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void; - onToggleTurnFold: (turnId: TurnId) => void; + onToggleTurnFold: (turnId: TurnId, anchorKey: string) => void; onToggleWorkGroup: (groupId: string, anchorKey: string) => void; agentPanelModel: AgentPanelModel; onOpenAgents: () => void; @@ -378,8 +378,8 @@ export const MessagesTimeline = memo(function MessagesTimeline({ ); const onToggleTurnFold = useCallback( - (turnId: TurnId) => { - suspendEndScrollMaintenanceForDisclosure(`turn-fold:${turnId}`); + (turnId: TurnId, anchorKey: string) => { + suspendEndScrollMaintenanceForDisclosure(anchorKey); setExpandedTurnIds((existing) => { const next = new Set(existing); if (next.has(turnId)) { @@ -998,6 +998,10 @@ const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: Time ? "pb-2" : "pb-4", row.kind === "message" && row.message.role === "assistant" ? "group/assistant" : null, + // The separator belongs to the fold above, below any spawn row it kept. + row.kind === "message" && row.showsTurnFoldSeparator + ? "border-t border-border/60 pt-2" + : null, )} data-timeline-row-id={row.id} data-timeline-row-kind={row.kind} @@ -1240,12 +1244,12 @@ function TurnFoldTimelineRow({ row }: { row: Extract +