perf(web): collect active tool calls without array shifts (#18853)
Co-authored-by: SAPHID <[email protected]> Co-authored-by: GPT-6.1 Sol <[email protected]>
This commit is contained in:
2 files changed
+53
-1
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { RunId } from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import { deriveMessagesTimelineRows, liveWorkEntryLabel } from "./MessagesTimeline.logic";
|
||||
|
||||
describe("long active tool groups", () => {
|
||||
it.each([false, true])(
|
||||
"preserves chronological order and the latest activity, expanded=%s",
|
||||
(expanded) => {
|
||||
const runId = RunId.make("long-active-run");
|
||||
const createdAt = "2026-10-12T00:00:00Z";
|
||||
const timelineEntries = Array.from({ length: 1_000 }, (_, index) => ({
|
||||
id: `work-entry-${index}`,
|
||||
kind: "work" as const,
|
||||
createdAt,
|
||||
entry: {
|
||||
id: `work-${index}`,
|
||||
createdAt,
|
||||
runId,
|
||||
label: `Tool ${index}`,
|
||||
tone: index % 2 === 0 ? ("thinking" as const) : ("tool" as const),
|
||||
itemType: index % 2 === 0 ? ("reasoning" as const) : ("command_execution" as const),
|
||||
...(index % 2 === 0 ? { detail: `Thought ${index}` } : {}),
|
||||
toolLifecycleStatus: index === 999 ? ("inProgress" as const) : ("completed" as const),
|
||||
},
|
||||
}));
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries,
|
||||
isWorking: true,
|
||||
runningRunId: runId,
|
||||
activeTurnStartedAt: createdAt,
|
||||
turnDiffSummaries: [],
|
||||
supportsConversationRollback: false,
|
||||
expandedWorkGroupIds: new Set(expanded ? ["work-group:work-entry-0"] : []),
|
||||
});
|
||||
const live = rows.find((row) => row.kind === "work-live");
|
||||
expect(live).toBeDefined();
|
||||
expect(live?.entry.id).toBe("work-999");
|
||||
expect(live && liveWorkEntryLabel(live.entry, undefined, live.active)).toContain("999");
|
||||
expect(live?.thought?.id).toBe("work-998");
|
||||
expect(live?.groupedEntries.map(({ id }) => id)).toEqual(
|
||||
timelineEntries.map(({ entry }) => entry.id),
|
||||
);
|
||||
expect(live?.groupId).toBe("work-group:work-entry-0");
|
||||
const details = rows.filter((row) => row.kind === "work");
|
||||
expect(details).toHaveLength(expanded ? 1 : 0);
|
||||
if (expanded) {
|
||||
expect(details[0]?.groupedEntries).toEqual(live?.groupedEntries);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -1504,9 +1504,10 @@ export function deriveMessagesTimelineRows(input: {
|
||||
} else if ((entry.attempt?.id ?? null) !== tailAttemptId) {
|
||||
break;
|
||||
}
|
||||
activeToolEntries.unshift(entry);
|
||||
activeToolEntries.push(entry);
|
||||
}
|
||||
}
|
||||
activeToolEntries.reverse();
|
||||
const visibleActiveToolEntries = activeToolEntries.filter((entry) =>
|
||||
workEntryIsVisibleInGroup(entry.entry, true),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user