import { cleanUrl } from "@/libs/clean-url" import { useStorage } from "@plasmohq/storage/hook" import { useQuery } from "@tanstack/react-query" import { RotateCcw } from "lucide-react" import { useEffect, useState } from "react" import { Trans, useTranslation } from "react-i18next" import { getOllamaURL, isOllamaRunning, setOllamaURL as saveOllamaURL } from "~/services/ollama" export const PlaygroundEmpty = () => { const [ollamaURL, setOllamaURL] = useState("") const { t } = useTranslation(["playground", "common"]) const [checkOllamaStatus] = useStorage("checkOllamaStatus", true) const { data: ollamaInfo, status: ollamaStatus, refetch, isRefetching } = useQuery({ queryKey: ["ollamaStatus"], queryFn: async () => { const ollamaURL = await getOllamaURL() const isOk = await isOllamaRunning() if (ollamaURL) { saveOllamaURL(ollamaURL) } return { isOk, ollamaURL } }, enabled: checkOllamaStatus }) if (!checkOllamaStatus) { return (

👋 {t("welcome")}

) } return (
{(ollamaStatus === "pending" || isRefetching) && (

{t("ollamaState.searching")}

)} {!isRefetching && ollamaStatus === "success" ? ( ollamaInfo.isOk ? (

{t("ollamaState.running")}

) : (

{t("ollamaState.notRunning")}

setOllamaURL(e.target.value)} /> {ollamaURL && cleanUrl(ollamaURL) !== "http://127.0.0.1:11434" && (

) }} />

)}
) ) : null}
) }