import { useState } from "react"; import ChatBox from "./components/ChatBox"; import ChatInput from "./components/ChatInput"; import FileUpload from "./components/FileUpload"; import { streamChat } from "./utils/streamChat"; import { Button, Box, Typography } from "@mui/material"; import "./index.css"; import "./App.css"; export default function App() { const [messages, setMessages] = useState([]); const [lastCode, setLastCode] = useState(""); const [loading, setLoading] = useState(false); const [resetKey, setResetKey] = useState(0); const [fileUploaded, setFileUploaded] = useState(false); const detectLanguage = (filename) => { if (!filename || typeof filename !== "string") return ""; const ext = filename.split('.').pop().toLowerCase(); switch (ext) { case "js": return "javascript"; case "py": return "python"; case "java": return "java"; case "cpp": return "cpp"; case "ts": return "typescript"; case "cs": return "csharp"; default: return ""; } }; const handleSend = async (msg) => { const newHistory = [...messages, { role: "user", content: msg }]; setMessages(newHistory); setLoading(true); if (msg.includes("```")) setLastCode(msg); let fullContent = ""; await streamChat({ message: msg, history: messages, onChunk: (chunk) => { fullContent += chunk; setMessages([...newHistory, { role: "assistant", content: fullContent }]); }, onDone: () => { setLoading(false); setFileUploaded(false); }, }); }; const handleExplain = () => { //if (lastCode) handleSend(`Explain this code:\n\n${lastCode}`); if (lastCode)handleSend("Explain this code"); }; const handleFixBug = () => { // if (lastCode) handleSend(`Fix the bug in this code and explain:\n\n${lastCode}`); if (lastCode) handleSend("Fix the bug in this code and explain"); }; const handleClear = () => { setMessages([]); setLastCode(""); setFileUploaded(false); setResetKey((k) => k + 1); }; return (