import { Fragment, useEffect, useRef } from "react"; import { MessageBubble } from "./MessageBubble"; import { ReasoningBlock } from "./ReasoningBlock"; import { Markdown } from "../lib/markdown"; import { splitThinking } from "../lib/thinking"; import { en } from "../i18n/en"; import type { Message } from "../types"; interface Props { messages: Message[]; streaming: boolean; pending: string; onRegenerate(): void; } /** * A divider appears before a turn (a user message) when the conversation has * gone quiet for a while, so re-reading a long chat shows where each day's * exchange happened. Messages written before `createdAt` existed carry no * time, and pairs without times never produce a divider. */ const GAP_THRESHOLD_MS = 10 * 60 * 1000; function showDividerBefore(messages: Message[], i: number): boolean { const m = messages[i]; if (m.role !== "user" || typeof m.createdAt !== "number") return false; if (i === 0) return true; const prev = messages[i - 1]; if (typeof prev.createdAt !== "number") return false; return m.createdAt - prev.createdAt >= GAP_THRESHOLD_MS; } function formatStamp(ts: number): string { const d = new Date(ts); const day = d.toLocaleDateString("en-US", { weekday: "short" }); const time = d.toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", hour12: false }); return `${day} ${time}`; } export function MessageList({ messages, streaming, pending, onRegenerate }: Props) { const endRef = useRef(null); useEffect(() => { endRef.current?.scrollIntoView({ block: "end" }); }, [messages, pending, streaming]); const lastAssistantIdx = (() => { for (let i = messages.length - 1; i >= 0; i--) { if (messages[i].role === "assistant") return i; } return -1; })(); const live = splitThinking(pending); if (messages.length === 0 && !streaming) { return (

{en.emptyChatTitle}

); } return ( // Centered column: user pill (right) and reply (left) sit close together // horizontally instead of hugging opposite edges of a wide screen. ); } function Spinner() { return ( ); }