| 810 | * (tie-break by longest duration) per session_id. |
| 811 | */ |
| 812 | export function deduplicateSessionBranches( |
| 813 | entries: Array<{ log: LogOption; meta: SessionMeta }>, |
| 814 | ): Array<{ log: LogOption; meta: SessionMeta }> { |
| 815 | const bestBySession = new Map<string, { log: LogOption; meta: SessionMeta }>() |
| 816 | for (const entry of entries) { |
| 817 | const id = entry.meta.session_id |
| 818 | const existing = bestBySession.get(id) |
| 819 | if ( |
| 820 | !existing || |
| 821 | entry.meta.user_message_count > existing.meta.user_message_count || |
| 822 | (entry.meta.user_message_count === existing.meta.user_message_count && |
| 823 | entry.meta.duration_minutes > existing.meta.duration_minutes) |
| 824 | ) { |
| 825 | bestBySession.set(id, entry) |
| 826 | } |
| 827 | } |
| 828 | return [...bestBySession.values()] |
| 829 | } |
| 830 | |
| 831 | function formatTranscriptForFacets(log: LogOption): string { |
| 832 | const lines: string[] = [] |