'use client'; import { useEffect, useMemo, useState } from 'react'; interface StreamingMessageProps { text: string; modelName?: string | null; thinking?: string; } const WAITING_QUIPS = [ 'The AI is warming up... give it a moment.', 'Brewing some thoughts...', 'Summoning intelligence from the void...', 'Consulting the silicon oracle...', 'Teaching electrons to think...', ]; const TIMEOUT_QUIPS = [ 'The model wandered off. Let’s try to find it again.', 'Response is taking the scenic route.', 'That answer is clearly overthinking things.', 'Still working. Either brilliance or a detour.', ]; export function StreamingMessage({ text, modelName, thinking, }: StreamingMessageProps): React.ReactElement { const [elapsedMs, setElapsedMs] = useState(0); useEffect(() => { setElapsedMs(0); const startedAt = Date.now(); const timer = window.setInterval(() => { setElapsedMs(Date.now() - startedAt); }, 1000); return () => window.clearInterval(timer); }, [text, modelName, thinking]); const quip = useMemo(() => { if (elapsedMs >= 18_000) { return TIMEOUT_QUIPS[Math.floor((elapsedMs / 1000) % TIMEOUT_QUIPS.length)]; } if (elapsedMs >= 4_000) { return WAITING_QUIPS[Math.floor((elapsedMs / 1000) % WAITING_QUIPS.length)]; } return null; }, [elapsedMs]); return (
Assistant {modelName ? ( {modelName} ) : null} {text ? 'Responding…' : 'Thinking…'}
{text ? (
{text}
) : (
)} {thinking ? (
{thinking}
) : null}
{quip ?? (text ? 'Responding…' : 'Thinking…')}
); }