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