'use client' import { useEffect, useRef } from 'react' export type TerminalLine = { type: 'stdout' | 'stderr' | 'info' text: string } export type TerminalStatus = 'idle' | 'running' | 'done' | 'failed' | 'error' type Props = { lines: TerminalLine[] status: TerminalStatus error?: string | null className?: string } export default function StreamingTerminal({ lines, status, error, className = '' }: Props) { const bottomRef = useRef(null) useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: 'smooth' }) }, [lines]) const statusBar = () => { if (status === 'running') { return (
Running…
) } if (status === 'done') { return (
Completed successfully
) } if (status === 'failed') { return (
Exited with error
) } if (status === 'error') { return (
{error ?? 'Unknown error'}
) } return null } return (
{lines.length === 0 && status === 'running' && ( Waiting for output… )} {lines.map((line, i) => (
            {line.text}
          
))}
{statusBar()}
) }