From a0165cdf5f92542277a8a33b4141e24c49fa6a20 Mon Sep 17 00:00:00 2001 From: Will Chen Date: Thu, 1 May 2025 23:09:02 -0700 Subject: [PATCH] Provide a way to fix dyad-output errors with AI (#67) --- src/components/chat/DyadOutput.tsx | 41 ++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/components/chat/DyadOutput.tsx b/src/components/chat/DyadOutput.tsx index 8a78a2c..fef825b 100644 --- a/src/components/chat/DyadOutput.tsx +++ b/src/components/chat/DyadOutput.tsx @@ -4,8 +4,11 @@ import { 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; @@ -18,6 +21,8 @@ export const DyadOutput: React.FC = ({ 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"; @@ -30,9 +35,19 @@ export const DyadOutput: React.FC = ({ ); 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 */} @@ -43,12 +58,26 @@ export const DyadOutput: React.FC = ({ {icon} {label}
+ + {/* Fix with AI button - always visible for errors */} + {isError && message && ( +
+ +
+ )} + {/* Main content, padded to avoid label */} -
+
{message && ( - {message.slice(0, isContentVisible ? undefined : 80) + + {message.slice(0, isContentVisible ? undefined : 100) + (!isContentVisible ? "..." : "")} )} @@ -67,8 +96,10 @@ export const DyadOutput: React.FC = ({ )}
+ + {/* Content area */} {isContentVisible && children && ( -
+
{children}
)}