Wait for iplcodata to load before first message

- Fix the console khoj ai ascii art
- Remove some not so good suggested prompt
This commit is contained in:
sabaimran
2024-11-24 14:52:36 -08:00
parent 7c77d65d35
commit d7e68a2d1b
4 changed files with 37 additions and 39 deletions

View File

@@ -994,7 +994,7 @@ export default function Automations() {
const [suggestedAutomations, setSuggestedAutomations] = useState<AutomationsData[]>([]); const [suggestedAutomations, setSuggestedAutomations] = useState<AutomationsData[]>([]);
const [showLoginPrompt, setShowLoginPrompt] = useState(false); const [showLoginPrompt, setShowLoginPrompt] = useState(false);
const isMobileWidth = useIsMobileWidth(); const isMobileWidth = useIsMobileWidth();
const ipLocationData = useIPLocationData(); const { locationData, locationDataError, locationDataLoading } = useIPLocationData();
useEffect(() => { useEffect(() => {
if (newAutomationData) { if (newAutomationData) {
@@ -1044,18 +1044,18 @@ export default function Automations() {
{authenticatedData.email} {authenticatedData.email}
</span> </span>
) : null} ) : null}
{ipLocationData && ( {locationData && (
<span className="rounded-lg text-sm border-secondary border p-1 flex items-center shadow-sm"> <span className="rounded-lg text-sm border-secondary border p-1 flex items-center shadow-sm">
<MapPinSimple className="h-4 w-4 mr-2 inline text-purple-500" /> <MapPinSimple className="h-4 w-4 mr-2 inline text-purple-500" />
{ipLocationData {locationData
? `${ipLocationData.city}, ${ipLocationData.country}` ? `${locationData.city}, ${locationData.country}`
: "Unknown"} : "Unknown"}
</span> </span>
)} )}
{ipLocationData && ( {locationData && (
<span className="rounded-lg text-sm border-secondary border p-1 flex items-center shadow-sm"> <span className="rounded-lg text-sm border-secondary border p-1 flex items-center shadow-sm">
<Clock className="h-4 w-4 mr-2 inline text-green-500" /> <Clock className="h-4 w-4 mr-2 inline text-green-500" />
{ipLocationData ? `${ipLocationData.timezone}` : "Unknown"} {locationData ? `${locationData.timezone}` : "Unknown"}
</span> </span>
)} )}
</div> </div>
@@ -1086,7 +1086,7 @@ export default function Automations() {
setNewAutomationData={setNewAutomationData} setNewAutomationData={setNewAutomationData}
authenticatedData={authenticatedData} authenticatedData={authenticatedData}
isCreating={isCreating} isCreating={isCreating}
ipLocationData={ipLocationData} ipLocationData={locationData}
/> />
) : ( ) : (
<Button <Button
@@ -1103,7 +1103,7 @@ export default function Automations() {
<SharedAutomationCard <SharedAutomationCard
isMobileWidth={isMobileWidth} isMobileWidth={isMobileWidth}
authenticatedData={authenticatedData} authenticatedData={authenticatedData}
locationData={ipLocationData} locationData={locationData}
isLoggedIn={authenticatedData ? true : false} isLoggedIn={authenticatedData ? true : false}
setShowLoginPrompt={setShowLoginPrompt} setShowLoginPrompt={setShowLoginPrompt}
setNewAutomationData={setNewAutomationData} setNewAutomationData={setNewAutomationData}
@@ -1125,7 +1125,7 @@ export default function Automations() {
setNewAutomationData={setNewAutomationData} setNewAutomationData={setNewAutomationData}
authenticatedData={authenticatedData} authenticatedData={authenticatedData}
isCreating={isCreating} isCreating={isCreating}
ipLocationData={ipLocationData} ipLocationData={locationData}
/> />
) : ( ) : (
<Button <Button
@@ -1147,7 +1147,7 @@ export default function Automations() {
key={automation.id} key={automation.id}
authenticatedData={authenticatedData} authenticatedData={authenticatedData}
automation={automation} automation={automation}
locationData={ipLocationData} locationData={locationData}
isLoggedIn={authenticatedData ? true : false} isLoggedIn={authenticatedData ? true : false}
setShowLoginPrompt={setShowLoginPrompt} setShowLoginPrompt={setShowLoginPrompt}
/> />
@@ -1158,7 +1158,7 @@ export default function Automations() {
key={automation.id} key={automation.id}
authenticatedData={authenticatedData} authenticatedData={authenticatedData}
automation={automation} automation={automation}
locationData={ipLocationData} locationData={locationData}
isLoggedIn={authenticatedData ? true : false} isLoggedIn={authenticatedData ? true : false}
setShowLoginPrompt={setShowLoginPrompt} setShowLoginPrompt={setShowLoginPrompt}
/> />
@@ -1173,7 +1173,7 @@ export default function Automations() {
key={automation.id} key={automation.id}
authenticatedData={authenticatedData} authenticatedData={authenticatedData}
automation={automation} automation={automation}
locationData={ipLocationData} locationData={locationData}
isLoggedIn={authenticatedData ? true : false} isLoggedIn={authenticatedData ? true : false}
setShowLoginPrompt={setShowLoginPrompt} setShowLoginPrompt={setShowLoginPrompt}
suggestedCard={true} suggestedCard={true}

View File

@@ -184,8 +184,10 @@ export default function Chat() {
useState<AbortController | null>(null); useState<AbortController | null>(null);
const [triggeredAbort, setTriggeredAbort] = useState(false); const [triggeredAbort, setTriggeredAbort] = useState(false);
const locationData = useIPLocationData() || { const { locationData, locationDataError, locationDataLoading } = useIPLocationData() || {
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, locationData: {
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
},
}; };
const authenticatedData = useAuthenticatedData(); const authenticatedData = useAuthenticatedData();
const isMobileWidth = useIsMobileWidth(); const isMobileWidth = useIsMobileWidth();
@@ -239,9 +241,13 @@ export default function Chat() {
useEffect(() => { useEffect(() => {
if (processQuerySignal) { if (processQuerySignal) {
if (locationDataLoading) {
return;
}
chat(); chat();
} }
}, [processQuerySignal]); }, [processQuerySignal, locationDataLoading]);
async function readChatStream(response: Response) { async function readChatStream(response: Response) {
if (!response.ok) throw new Error(response.statusText); if (!response.ok) throw new Error(response.statusText);

View File

@@ -23,32 +23,30 @@ export function welcomeConsole() {
`%c %s`, `%c %s`,
"font-family:monospace", "font-family:monospace",
` `
__ __ __ __ ______ __ _____ __ __ __ __ __ ______ __ _____ __
/\\ \\/ / /\\ \\_\\ \\ /\\ __ \\ /\\ \\ /\\ __ \\ /\\ \\ /\\ \\/ / /\\ \\_\\ \\ /\\ __ \\ /\\ \\ /\\ __ \\ /\\ \\
\\ \\ _"-. \\ \\ __ \\ \\ \\ \\/\\ \\ _\\_\\ \\ \\ \\ __ \\ \\ \\ \\ \\ \\ _"-. \\ \\ __ \\ \\ \\ \\/\\ \\ _\\_\\ \\ \\ \\ __ \\ \\ \\ \\
\\ \\_\\ \\_\\ \\ \\_\\ \\_\\ \\ \\_____\\ /\\_____\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ \\_\\ \\_\\ \\ \\_\\ \\_\\ \\ \\_____\\ /\\_____\\ \\ \\_\\ \\_\\ \\ \\_\\
\\/_/\\/_/ \\/_/\\/_/ \\/_____/ \\/_____/ \\/_/\\/_/ \\/_/ \\/_/\\/_/ \\/_/\\/_/ \\/_____/ \\/_____/ \\/_/\\/_/ \\/_/
Greetings traveller, Greetings traveller,
I am ✨Khoj✨, your open-source, personal AI copilot. I am ✨Khoj✨, your open-source, personal AI copilot.
See my source code at https://github.com/khoj-ai/khoj See my source code at https://github.com/khoj-ai/khoj
Read my operating manual at https://docs.khoj.dev Read my operating manual at https://docs.khoj.dev
`, `,
); );
} }
export function useIPLocationData() { export function useIPLocationData() {
const { data: locationData, error: locationDataError } = useSWR<LocationData>( const {
"/api/ip", data: locationData,
locationFetcher, error: locationDataError,
{ revalidateOnFocus: false }, isLoading: locationDataLoading,
); } = useSWR<LocationData>("/api/ip", locationFetcher, { revalidateOnFocus: false });
return { locationData, locationDataError, locationDataLoading };
if (locationDataError || !locationData) return;
return locationData;
} }
export function useIsMobileWidth() { export function useIsMobileWidth() {

View File

@@ -724,12 +724,6 @@ export const suggestionsData: Suggestion[] = [
description: "Draw a diagram illustrating the structure of the United States government.", description: "Draw a diagram illustrating the structure of the United States government.",
link: "", link: "",
}, },
{
type: SuggestionType.Health,
color: suggestionToColorMap[SuggestionType.Health] || DEFAULT_COLOR,
description: "Draw a diagram of the human skeletal system.",
link: "",
},
{ {
type: SuggestionType.Code, type: SuggestionType.Code,
color: suggestionToColorMap[SuggestionType.Code] || DEFAULT_COLOR, color: suggestionToColorMap[SuggestionType.Code] || DEFAULT_COLOR,