import type { ContextualChatEntry } from '../game-chat.js'; export type ChatMessageEntry = Extract; export type ChatBoundaryEntry = Extract; export type ChatTimelineItem = | { type: 'message'; entry: ChatMessageEntry } | { type: 'boundaries'; entries: ChatBoundaryEntry[] }; /** Group adjacent lifecycle events for display without discarding log history. */ export function groupChatTimeline(entries: readonly ContextualChatEntry[]): ChatTimelineItem[] { const timeline: ChatTimelineItem[] = []; for (const entry of entries) { if (entry.type === 'message') { timeline.push({ type: 'message', entry }); } else { const previous = timeline.at(-1); if (previous?.type === 'boundaries') previous.entries.push(entry); else timeline.push({ type: 'boundaries', entries: [entry] }); } } return timeline; }