findTurnStartIndex function
Find the user-visible message that starts the turn containing an entry.
Ported from pi's findTurnStartIndex.
Implementation
int findTurnStartIndex(
List<SessionRecord> entries,
int entryIndex,
int startIndex,
) {
for (var i = entryIndex; i >= startIndex; i--) {
final entry = entries[i];
if (entry is BranchSummaryRecord || entry is CustomMessageRecord) {
return i;
}
if (entry is MessageRecord && entry.message.role == 'user') return i;
}
return -1;
}