fix: System prompt sorting

This commit is contained in:
Aleksander Grygier 2026-01-24 13:44:41 +01:00
parent 2601bf0f59
commit c39c6ef436
1 changed files with 7 additions and 2 deletions

View File

@ -65,8 +65,13 @@ export function filterByLeafNodeId(
currentNode = nodeMap.get(currentNode.parent);
}
// Sort by timestamp to get chronological order (root to leaf)
result.sort((a, b) => a.timestamp - b.timestamp);
// Sort: system messages first, then by timestamp
result.sort((a, b) => {
if (a.role === 'system' && b.role !== 'system') return -1;
if (a.role !== 'system' && b.role === 'system') return 1;
return a.timestamp - b.timestamp;
});
return result;
}