fix: optimize agent stream rendering and timeline cursor updates

This commit is contained in:
Mohamed Boudra
2026-02-23 15:47:58 +07:00
parent 42786956c7
commit 560e0f2362
3 changed files with 30 additions and 16 deletions
+14 -8
View File
@@ -803,16 +803,22 @@ function SessionProviderInternal({
) {
setAgentTimelineCursor(serverId, (prev) => {
const current = prev.get(agentId);
const next = new Map(prev);
if (!current || current.epoch !== epoch) {
next.set(agentId, { epoch, startSeq: seq, endSeq: seq });
if (current && current.epoch === epoch) {
// Fast-path: seq only extends the range during streaming.
// Skip the Map copy when nothing actually changes.
if (seq >= current.startSeq && seq <= current.endSeq) {
return prev;
}
const next = new Map(prev);
next.set(agentId, {
epoch,
startSeq: Math.min(current.startSeq, seq),
endSeq: Math.max(current.endSeq, seq),
});
return next;
}
next.set(agentId, {
epoch,
startSeq: Math.min(current.startSeq, seq),
endSeq: Math.max(current.endSeq, seq),
});
const next = new Map(prev);
next.set(agentId, { epoch, startSeq: seq, endSeq: seq });
return next;
});
}