Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions apps/web/src/components/chat/MessagesTimeline.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,74 @@ describe("deriveMessagesTimelineRows", () => {
]);
});

it("stacks back-to-back steers as one burst with a single steer label", () => {
const runId = RunId.make("double-steer-run");
const time = (second: number) => new Date(Date.UTC(2026, 0, 1, 0, 0, second)).toISOString();
const message = (
id: string,
second: number,
role: "user" | "assistant",
inputIntent?: "turn_start" | "steer",
): TimelineEntry => ({
kind: "message",
id,
createdAt: time(second),
message: {
id: MessageId.make(id),
role,
text: id,
runId,
...(inputIntent ? { inputIntent } : {}),
createdAt: time(second),
updatedAt: time(second),
streaming: false,
},
});
const prompt = message("prompt", 0, "user", "turn_start");
const work: TimelineEntry = {
kind: "work",
id: "work",
createdAt: time(4),
entry: { id: "work", createdAt: time(4), runId, label: "Ran command", tone: "tool" },
};
const firstSteer = message("first-steer", 10, "user", "steer");
const deriveRows = (timelineEntries: TimelineEntry[]) =>
deriveMessagesTimelineRows({
timelineEntries,
latestRun: { runId, status: "completed", startedAt: time(0), completedAt: time(30) },
isWorking: false,
expandedRunIds: new Set(),
turnDiffSummaries: [],
supportsConversationRollback: false,
});
// The second steer arrives while the first message object is reused, as live updates do.
const before = computeStableMessagesTimelineRows(deriveRows([prompt, work, firstSteer]), {
result: [],
byId: new Map(),
});
const rows = computeStableMessagesTimelineRows(
deriveRows([
prompt,
work,
firstSteer,
message("second-steer", 12, "user", "steer"),
message("final", 30, "assistant"),
]),
before,
).result;

const byId = new Map(rows.map((row) => [row.id, row]));
expect(byId.get("prompt")).not.toHaveProperty("groupedWithNext");
expect(byId.get("first-steer")).toMatchObject({
groupedWithNext: true,
continuesSteer: false,
});
expect(byId.get("second-steer")).toMatchObject({
groupedWithNext: false,
continuesSteer: true,
});
});

it("keeps the previous turn folded while a newly sent message awaits its turn", () => {
const rows = deriveMessagesTimelineRows({
timelineEntries: [
Expand Down
40 changes: 35 additions & 5 deletions apps/web/src/components/chat/MessagesTimeline.logic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
import { isLiveSubagentTurnItem } from "@t3tools/client-runtime/state/subagentRuntime";
import * as DateTime from "effect/DateTime";
import * as Equal from "effect/Equal";
Expand Down Expand Up @@ -594,6 +595,10 @@ type MessagesTimelineRowContent =
assistantCopyStreaming: boolean;
assistantTurnDiffSummary?: TurnDiffSummary | undefined;
revertTurnCount?: number | undefined;
/** Another of your messages follows directly, so the two sit closer together. */
groupedWithNext?: boolean;
/** Set when the message above is a steer too, so the label shows once. */
continuesSteer?: boolean;
}
| {
kind: "assistant-meta";
Expand Down Expand Up @@ -2134,13 +2139,36 @@ export function deriveMessagesTimelineRows(input: {
const result = attachTrailingToolGroupsToAssistant(
attachCreatedThreadSummaries(nextRows, timelineEntries, collapsedFoldMemberIds),
);
return result.map((row, index) =>
timelineRowIsWorkLog(row) && timelineRowIsWorkLog(result[index + 1])
? { ...row, continuesWorkLog: true }
: row,
return result.map((row, index) => {
if (timelineRowIsWorkLog(row) && timelineRowIsWorkLog(result[index + 1])) {
return { ...row, continuesWorkLog: true };
}
if (!timelineRowIsOwnUserMessage(row)) return row;
const previous = result[index - 1];
const groupedWithNext = timelineRowIsOwnUserMessage(result[index + 1]);
const continuesSteer =
timelineRowIsOwnUserMessage(previous) &&
messageIsSteer(row.message) &&
messageIsSteer(previous.message);
if (!groupedWithNext && !continuesSteer) return row;
return { ...row, groupedWithNext, continuesSteer };
});
}

function timelineRowIsOwnUserMessage(
row: MessagesTimelineRow | undefined,
): row is Extract<MessagesTimelineRow, { kind: "message" }> {
return (
row?.kind === "message" &&
row.message.role === "user" &&
resolveUserMessagePresentation(row.message).attribution === null
);
}

function messageIsSteer(message: ChatMessage): boolean {
return message.inputIntent === "steer" || message.inputIntent === "promoted_queued_to_steer";
}

function timelineRowIsWorkLog(row: MessagesTimelineRow | undefined): boolean {
return (
row !== undefined &&
Expand Down Expand Up @@ -2478,7 +2506,9 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
a.showAssistantCopyButton === bm.showAssistantCopyButton &&
a.assistantCopyStreaming === bm.assistantCopyStreaming &&
a.assistantTurnDiffSummary === bm.assistantTurnDiffSummary &&
a.revertTurnCount === bm.revertTurnCount
a.revertTurnCount === bm.revertTurnCount &&
a.groupedWithNext === bm.groupedWithNext &&
a.continuesSteer === bm.continuesSteer
);
}
}
Expand Down
22 changes: 12 additions & 10 deletions apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1433,16 +1433,18 @@ const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: Time
? undefined
: row.kind === "turn-fold" || row.kind === "working"
? "pb-1.5"
: (row.kind === "message" &&
row.message.role === "assistant" &&
!row.showAssistantMeta) ||
row.kind === "worktree-setup" ||
row.kind === "event" ||
row.kind === "attempt-fold" ||
row.kind === "html-render" ||
row.kind === "mcp-app"
? "pb-2"
: "pb-4",
: row.kind === "message" && row.groupedWithNext
? "pb-1"
: (row.kind === "message" &&
row.message.role === "assistant" &&
!row.showAssistantMeta) ||
row.kind === "worktree-setup" ||
row.kind === "event" ||
row.kind === "attempt-fold" ||
row.kind === "html-render" ||
row.kind === "mcp-app"
? "pb-2"
: "pb-4",
(row.kind === "message" && row.message.role === "assistant") ||
row.kind === "assistant-meta"
? "group/assistant"
Expand Down
5 changes: 3 additions & 2 deletions apps/web/src/components/chat/TimelineUserMessageRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,9 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
<GuestMessageName name={userMessage.guestName} />
</div>
) : null}
{row.message.inputIntent === "steer" ||
row.message.inputIntent === "promoted_queued_to_steer" ? (
{(row.message.inputIntent === "steer" ||
row.message.inputIntent === "promoted_queued_to_steer") &&
!row.continuesSteer ? (
<UserMessageIntentMarker intent={row.message.inputIntent} />
) : null}
<div
Expand Down
Loading