| 1 | import { useContext, useMemo } from "react"; |
| 2 | import { useNavigate } from "react-router-dom"; |
| 3 | import { useAuth } from "../../context/Auth"; |
| 4 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 5 | import { useAppSelector } from "../../redux/hooks"; |
| 6 | import { ROUTES } from "../../util/navigation"; |
| 7 | import Alert from "../gui/Alert"; |
| 8 | import { useLump } from "../mainInput/Lump/LumpContext"; |
| 9 | |
| 10 | export const FatalErrorIndicator = () => { |
| 11 | const { refreshProfiles } = useAuth(); |
| 12 | const configError = useAppSelector((store) => store.config.configError); |
| 13 | const ideMessenger = useContext(IdeMessengerContext); |
| 14 | |
| 15 | const navigate = useNavigate(); |
| 16 | |
| 17 | const hasFatalErrors = useMemo(() => { |
| 18 | return configError?.some((error) => error.fatal); |
| 19 | }, [configError]); |
| 20 | |
| 21 | const { setSelectedSection, selectedSection } = useLump(); |
| 22 | const configLoading = useAppSelector((state) => state.config.loading); |
| 23 | |
| 24 | const showLumpErrorSection = () => { |
| 25 | navigate(ROUTES.HOME); |
| 26 | setSelectedSection("error"); |
| 27 | }; |
| 28 | |
| 29 | const { selectedProfile } = useAuth(); |
| 30 | |
| 31 | if (!hasFatalErrors) { |
| 32 | return null; |
| 33 | } |
| 34 | |
| 35 | const displayName = selectedProfile |
| 36 | ? (selectedProfile.title ?? |
| 37 | `${selectedProfile.fullSlug?.ownerSlug}/${selectedProfile.fullSlug?.packageSlug}`) |
| 38 | : "agent"; |
| 39 | |
| 40 | return ( |
| 41 | <Alert type="error" className="mx-2 my-1 px-2"> |
| 42 | <span>{`Error loading`}</span>{" "} |
| 43 | <span className="italic">{displayName}</span> |
| 44 | {". "} |
| 45 | <span>{`Chat is disabled until a model is available.`}</span> |
| 46 | <div className="mt-2 flex flex-row flex-wrap items-center gap-x-3 gap-y-1.5"> |
| 47 | <div |
| 48 | onClick={() => { |
| 49 | ideMessenger.post( |
| 50 | "openUrl", |
| 51 | "https://docs.continue.dev/troubleshooting", |
| 52 | ); |
| 53 | }} |
| 54 | className="cursor-pointer underline" |
| 55 | > |
| 56 | Help |
| 57 | </div> |
| 58 | {configLoading ? ( |
| 59 | <div>Reloading...</div> |
| 60 | ) : ( |
| 61 | <div |
| 62 | className={`cursor-pointer underline`} |
| 63 | onClick={() => { |
| 64 | refreshProfiles("Clicked reload in fatal indicator"); |
| 65 | }} |
| 66 | > |
| 67 | Reload |
| 68 | </div> |
| 69 | )} |
| 70 | <div |
| 71 | onClick={showLumpErrorSection} |
| 72 | className={`cursor-pointer underline transition-all ${selectedSection === "error" ? "opacity-0" : ""}`} |
| 73 | > |
| 74 | View |
| 75 | </div> |
| 76 | </div> |
| 77 | </Alert> |
| 78 | ); |
| 79 | }; |