import React, { useState } from "react"; import { ChevronsDownUp, ChevronsUpDown, AlertTriangle, XCircle, Sparkles, } from "lucide-react"; import { useAtom, useSetAtom } from "jotai"; import { chatInputValueAtom, selectedChatIdAtom } from "@/atoms/chatAtoms"; import { useStreamChat } from "@/hooks/useStreamChat"; interface DyadOutputProps { type: "error" | "warning"; message?: string; children?: React.ReactNode; } export const DyadOutput: React.FC = ({ type, message, children, }) => { const [isContentVisible, setIsContentVisible] = useState(false); const [selectedChatId, setSelectedChatId] = useAtom(selectedChatIdAtom); const { streamMessage } = useStreamChat(); // If the type is not warning, it is an error (in case LLM gives a weird "type") const isError = type !== "warning"; const borderColor = isError ? "border-red-500" : "border-amber-500"; const iconColor = isError ? "text-red-500" : "text-amber-500"; const icon = isError ? ( ) : ( ); const label = isError ? "Error" : "Warning"; const handleAIFix = (e: React.MouseEvent) => { e.stopPropagation(); if (message && selectedChatId) { streamMessage({ prompt: `Fix the error: ${message}`, chatId: selectedChatId, }); } }; return (
setIsContentVisible(!isContentVisible)} > {/* Top-left label badge */}
{icon} {label}
{/* Fix with AI button - always visible for errors */} {isError && message && (
)} {/* Main content, padded to avoid label */}
{message && ( {message.slice(0, isContentVisible ? undefined : 100) + (!isContentVisible ? "..." : "")} )}
{isContentVisible ? ( ) : ( )}
{/* Content area */} {isContentVisible && children && (
{children}
)}
); };