fix(clients): keep opening responses visible after turns settle (#7723)
This commit is contained in:
1 parent
77c9d1eb5b
commit
6c693baecf
4 files changed
+160
-23
No files matched your search
@@ -371,7 +371,7 @@ describe("buildThreadFeed", () => {
|
||||
expect(serializedToolOutputs).toBe(1);
|
||||
});
|
||||
|
||||
it("folds settled turn work while leaving the terminal answer visible", () => {
|
||||
it("keeps the first and terminal assistant messages visible around settled work", () => {
|
||||
const turnId = TurnId.make("turn-1");
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-3"),
|
||||
@@ -387,9 +387,9 @@ describe("buildThreadFeed", () => {
|
||||
},
|
||||
messages: [
|
||||
{
|
||||
id: MessageId.make("assistant-commentary"),
|
||||
id: MessageId.make("assistant-first"),
|
||||
role: "assistant",
|
||||
text: "I am checking.",
|
||||
text: "Synthetic deployment checklist\n1. Confirm the deployment is ready.",
|
||||
turnId,
|
||||
streaming: false,
|
||||
createdAt: "2026-04-01T00:00:02.000Z",
|
||||
@@ -424,8 +424,12 @@ describe("buildThreadFeed", () => {
|
||||
|
||||
const feed = buildThreadFeed(thread);
|
||||
const collapsed = deriveThreadFeedPresentation(feed, thread.latestTurn, new Set());
|
||||
expect(collapsed.map((entry) => entry.id)).toEqual(["turn-fold:turn-1", "assistant-final"]);
|
||||
expect(collapsed[0]).toMatchObject({
|
||||
expect(collapsed.map((entry) => entry.id)).toEqual([
|
||||
"assistant-first",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-final",
|
||||
]);
|
||||
expect(collapsed[1]).toMatchObject({
|
||||
type: "turn-fold",
|
||||
label: "Worked for 17s",
|
||||
expanded: false,
|
||||
@@ -433,13 +437,68 @@ describe("buildThreadFeed", () => {
|
||||
|
||||
const expanded = deriveThreadFeedPresentation(feed, thread.latestTurn, new Set([turnId]));
|
||||
expect(expanded.map((entry) => entry.id)).toEqual([
|
||||
"assistant-first",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-commentary",
|
||||
"tool-completed",
|
||||
"assistant-final",
|
||||
]);
|
||||
});
|
||||
|
||||
it("folds assistant messages between the first and terminal messages", () => {
|
||||
const turnId = TurnId.make("turn-1");
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-middle-message"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Bounded narration",
|
||||
latestTurn: {
|
||||
turnId,
|
||||
state: "completed",
|
||||
requestedAt: "2026-04-01T00:00:00.000Z",
|
||||
startedAt: "2026-04-01T00:00:01.000Z",
|
||||
completedAt: "2026-04-01T00:00:06.000Z",
|
||||
assistantMessageId: MessageId.make("assistant-final"),
|
||||
},
|
||||
messages: [
|
||||
{
|
||||
id: MessageId.make("assistant-first"),
|
||||
role: "assistant",
|
||||
text: "The main result is ready.",
|
||||
turnId,
|
||||
streaming: false,
|
||||
createdAt: "2026-04-01T00:00:01.000Z",
|
||||
updatedAt: "2026-04-01T00:00:02.000Z",
|
||||
},
|
||||
{
|
||||
id: MessageId.make("assistant-middle"),
|
||||
role: "assistant",
|
||||
text: "I am checking one more detail.",
|
||||
turnId,
|
||||
streaming: false,
|
||||
createdAt: "2026-04-01T00:00:03.000Z",
|
||||
updatedAt: "2026-04-01T00:00:04.000Z",
|
||||
},
|
||||
{
|
||||
id: MessageId.make("assistant-final"),
|
||||
role: "assistant",
|
||||
text: "Verification finished.",
|
||||
turnId,
|
||||
streaming: false,
|
||||
createdAt: "2026-04-01T00:00:05.000Z",
|
||||
updatedAt: "2026-04-01T00:00:06.000Z",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const feed = buildThreadFeed(thread);
|
||||
const rows = deriveThreadFeedPresentation(feed, thread.latestTurn, new Set());
|
||||
|
||||
expect(rows.map((entry) => entry.id)).toEqual([
|
||||
"assistant-first",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-final",
|
||||
]);
|
||||
});
|
||||
|
||||
it("measures a steer-superseded turn from its user boundary through trailing work", () => {
|
||||
const firstTurnId = TurnId.make("turn-1");
|
||||
const secondTurnId = TurnId.make("turn-2");
|
||||
|
||||
@@ -1144,9 +1144,13 @@ function deriveThreadFeedTurnFolds(
|
||||
feed: ReadonlyArray<ThreadFeedEntry>,
|
||||
latestTurn: ThreadFeedLatestTurn | null,
|
||||
): ReadonlyMap<string, ThreadFeedTurnFold> {
|
||||
const firstAssistantMessageIdByTurn = new Map<TurnId, string>();
|
||||
const terminalAssistantMessageIdByTurn = new Map<TurnId, string>();
|
||||
for (const entry of feed) {
|
||||
if (entry.type === "message" && entry.message.role === "assistant" && entry.message.turnId) {
|
||||
if (!firstAssistantMessageIdByTurn.has(entry.message.turnId)) {
|
||||
firstAssistantMessageIdByTurn.set(entry.message.turnId, entry.id);
|
||||
}
|
||||
terminalAssistantMessageIdByTurn.set(entry.message.turnId, entry.id);
|
||||
}
|
||||
}
|
||||
@@ -1194,17 +1198,24 @@ function deriveThreadFeedTurnFolds(
|
||||
continue;
|
||||
}
|
||||
|
||||
const firstAssistantMessageId = firstAssistantMessageIdByTurn.get(turnId);
|
||||
const terminalAssistantMessageId = terminalAssistantMessageIdByTurn.get(turnId);
|
||||
const hiddenEntryIds = new Set(
|
||||
entries.filter((entry) => entry.id !== terminalAssistantMessageId).map((entry) => entry.id),
|
||||
entries
|
||||
.filter(
|
||||
(entry) =>
|
||||
entry.id !== firstAssistantMessageId && entry.id !== terminalAssistantMessageId,
|
||||
)
|
||||
.map((entry) => entry.id),
|
||||
);
|
||||
if (hiddenEntryIds.size === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const firstEntry = entries[0];
|
||||
const firstHiddenEntry = entries.find((entry) => hiddenEntryIds.has(entry.id));
|
||||
const lastEntry = entries.at(-1);
|
||||
if (!firstEntry || !lastEntry) {
|
||||
if (!firstEntry || !firstHiddenEntry || !lastEntry) {
|
||||
continue;
|
||||
}
|
||||
const terminalEntry = terminalAssistantMessageId
|
||||
@@ -1233,9 +1244,9 @@ function deriveThreadFeedTurnFolds(
|
||||
? `Worked for ${duration}`
|
||||
: "Worked";
|
||||
|
||||
foldsByAnchorId.set(firstEntry.id, {
|
||||
foldsByAnchorId.set(firstHiddenEntry.id, {
|
||||
turnId,
|
||||
createdAt: firstEntry.createdAt,
|
||||
createdAt: firstHiddenEntry.createdAt,
|
||||
hiddenEntryIds,
|
||||
label,
|
||||
});
|
||||
|
||||
@@ -452,7 +452,7 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expect(assistantRow?.assistantTurnDiffSummary).toBe(assistantTurnDiffSummary);
|
||||
});
|
||||
|
||||
it("folds settled-turn commentary and work behind a Worked-for row", () => {
|
||||
it("keeps the first and terminal assistant messages visible around settled work", () => {
|
||||
const timelineEntries = [
|
||||
{
|
||||
id: "user-entry",
|
||||
@@ -469,13 +469,13 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "assistant-thought-entry",
|
||||
id: "assistant-first-entry",
|
||||
kind: "message" as const,
|
||||
createdAt: "2026-01-01T00:00:05Z",
|
||||
message: {
|
||||
id: "assistant-thought" as never,
|
||||
id: "assistant-first" as never,
|
||||
role: "assistant" as const,
|
||||
text: "Looking around first.",
|
||||
text: "Synthetic deployment checklist\n1. Confirm the deployment is ready.",
|
||||
turnId: "turn-1" as never,
|
||||
createdAt: "2026-01-01T00:00:05Z",
|
||||
updatedAt: "2026-01-01T00:00:06Z",
|
||||
@@ -528,6 +528,7 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expect(foldRow?.label).toBe("Worked for 22s");
|
||||
expect(collapsedRows.map((row) => row.id)).toEqual([
|
||||
"user-entry",
|
||||
"assistant-first-entry",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-final-entry",
|
||||
]);
|
||||
@@ -543,8 +544,8 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
|
||||
expect(expandedRows.map((row) => row.id)).toEqual([
|
||||
"user-entry",
|
||||
"assistant-first-entry",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-thought-entry",
|
||||
"work-toggle:work-entry-1",
|
||||
"assistant-final-entry",
|
||||
]);
|
||||
@@ -553,6 +554,67 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
it("folds assistant messages between the first and terminal messages", () => {
|
||||
const timelineEntries = [
|
||||
{
|
||||
id: "assistant-first-entry",
|
||||
kind: "message" as const,
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
message: {
|
||||
id: "assistant-first" as never,
|
||||
role: "assistant" as const,
|
||||
text: "The main result is ready.",
|
||||
turnId: "turn-1" as never,
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
updatedAt: "2026-01-01T00:00:02Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "assistant-middle-entry",
|
||||
kind: "message" as const,
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
message: {
|
||||
id: "assistant-middle" as never,
|
||||
role: "assistant" as const,
|
||||
text: "I am checking one more detail.",
|
||||
turnId: "turn-1" as never,
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
updatedAt: "2026-01-01T00:00:04Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "assistant-final-entry",
|
||||
kind: "message" as const,
|
||||
createdAt: "2026-01-01T00:00:05Z",
|
||||
message: {
|
||||
id: "assistant-final" as never,
|
||||
role: "assistant" as const,
|
||||
text: "Verification finished.",
|
||||
turnId: "turn-1" as never,
|
||||
createdAt: "2026-01-01T00:00:05Z",
|
||||
updatedAt: "2026-01-01T00:00:06Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries,
|
||||
isWorking: false,
|
||||
activeTurnStartedAt: null,
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.map((row) => row.id)).toEqual([
|
||||
"assistant-first-entry",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-final-entry",
|
||||
]);
|
||||
});
|
||||
|
||||
it("derives a sane duration for a steer-superseded turn with one instant commentary message", () => {
|
||||
// A steer ends the previous turn early: its only message completes the
|
||||
// instant it is created, and trailing work entries land after it. The
|
||||
|
||||
@@ -521,9 +521,10 @@ function timelineEntryTurnId(entry: TimelineEntry): TurnId | null {
|
||||
}
|
||||
|
||||
/**
|
||||
* Settled turns fold their commentary and tool activity behind a
|
||||
* "Worked for ..." row anchored at the turn's first foldable entry; the
|
||||
* terminal assistant message stays visible below the fold.
|
||||
* Settled turns keep their first and terminal assistant messages visible.
|
||||
* Everything between them folds behind a "Worked for ..." row anchored at
|
||||
* the first hidden entry. Keeping both ends prevents a short follow-up from
|
||||
* hiding a substantive opening response while still bounding noisy turns.
|
||||
*/
|
||||
function deriveTurnFolds(input: {
|
||||
timelineEntries: ReadonlyArray<TimelineEntry>;
|
||||
@@ -593,9 +594,12 @@ function deriveTurnFolds(input: {
|
||||
if (group.hasStreamingMessage) {
|
||||
continue;
|
||||
}
|
||||
const firstAssistantEntry = group.entries.find(
|
||||
(entry): entry is Extract<TimelineEntry, { kind: "message" }> => entry.kind === "message",
|
||||
);
|
||||
const hiddenEntryIds = new Set<string>();
|
||||
for (const entry of group.entries) {
|
||||
if (entry.id === group.terminalEntry?.id) {
|
||||
if (entry.id === firstAssistantEntry?.id || entry.id === group.terminalEntry?.id) {
|
||||
continue;
|
||||
}
|
||||
// Agent-spawn CTA rows never fold: workflows outlive their launching
|
||||
@@ -611,8 +615,9 @@ function deriveTurnFolds(input: {
|
||||
}
|
||||
|
||||
const firstEntry = group.entries[0];
|
||||
const firstHiddenEntry = group.entries.find((entry) => hiddenEntryIds.has(entry.id));
|
||||
const lastEntry = group.entries.at(-1);
|
||||
if (!firstEntry || !lastEntry) {
|
||||
if (!firstEntry || !firstHiddenEntry || !lastEntry) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -641,10 +646,10 @@ function deriveTurnFolds(input: {
|
||||
? `Worked for ${duration}`
|
||||
: "Worked";
|
||||
|
||||
foldsByAnchorEntryId.set(firstEntry.id, {
|
||||
foldsByAnchorEntryId.set(firstHiddenEntry.id, {
|
||||
turnId,
|
||||
anchorEntryId: firstEntry.id,
|
||||
createdAt: firstEntry.createdAt,
|
||||
anchorEntryId: firstHiddenEntry.id,
|
||||
createdAt: firstHiddenEntry.createdAt,
|
||||
hiddenEntryIds,
|
||||
label,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user