"use client"; import { useEffect, useRef } from "react"; import { Card, CardContent, CardHeader, CardTitle, CardDescription, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import { HelpTip } from "@/components/ui/help-tip"; import { useAgentStream, ConnectionState } from "@/hooks/use-websocket"; import { Wifi, WifiOff, Loader2, Trash2 } from "lucide-react"; interface AgentStreamViewerProps { agentId: string; agentName?: string; } const stateColors: Record = { connected: "bg-green-500", connecting: "bg-yellow-500", reconnecting: "bg-orange-500", disconnected: "bg-gray-500", }; const stateLabels: Record = { connected: "Connected", connecting: "Connecting...", reconnecting: "Reconnecting...", disconnected: "Disconnected", }; export function AgentStreamViewer({ agentId, agentName, }: AgentStreamViewerProps) { const { state, streamOutput, streamChunks, clearMessages, isConnected, isConnecting, } = useAgentStream(agentId); const outputRef = useRef(null); // Auto-scroll to bottom when new content arrives useEffect(() => { if (outputRef.current) { outputRef.current.scrollTop = outputRef.current.scrollHeight; } }, [streamOutput]); return (
Agent Output Stream {isConnecting ? ( ) : isConnected ? ( ) : ( )} Real-time LLM output from {agentName || agentId}
{stateLabels[state]} {streamChunks.length > 0 && ( Clear stream output )}
          {streamOutput || (
            
              {isConnected
                ? "Waiting for agent output..."
                : isConnecting
                  ? "Connecting to agent stream..."
                  : "Agent stream disconnected"}
            
          )}
        
{streamChunks.length} chunks received {streamOutput.length} characters
); }