mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-03 05:29:12 +00:00
Merge branch 'features/big-upgrade-chat-ux' of github.com:khoj-ai/khoj into features/use-new-sse-in-new-chat-ux
This commit is contained in:
@@ -11,15 +11,69 @@ export interface UserProfile {
|
||||
detail: string;
|
||||
}
|
||||
|
||||
const userFetcher = () => window.fetch('/api/v1/user').then(res => res.json()).catch(err => console.log(err));
|
||||
const fetcher = (url: string) =>
|
||||
window.fetch(url)
|
||||
.then(res => res.json())
|
||||
.catch(err => console.warn(err));
|
||||
|
||||
export function useAuthenticatedData() {
|
||||
const { data, error } = useSWR<UserProfile>('/api/v1/user', fetcher, { revalidateOnFocus: false });
|
||||
|
||||
const { data, error } = useSWR<UserProfile>('/api/v1/user', userFetcher, { revalidateOnFocus: false });
|
||||
|
||||
if (error) return null;
|
||||
if (!data) return null;
|
||||
if (data.detail === 'Forbidden') return null;
|
||||
if (error || !data || data.detail === 'Forbidden') return null;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export interface ModelOptions {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
export interface SyncedContent {
|
||||
computer: boolean;
|
||||
github: boolean;
|
||||
notion: boolean;
|
||||
}
|
||||
export interface UserConfig {
|
||||
// user info
|
||||
username: string;
|
||||
user_photo: string | null;
|
||||
is_active: boolean;
|
||||
given_name: string;
|
||||
phone_number: string;
|
||||
is_phone_number_verified: boolean;
|
||||
// user content settings
|
||||
enabled_content_source: SyncedContent;
|
||||
has_documents: boolean;
|
||||
notion_token: string | null;
|
||||
// user model settings
|
||||
search_model_options: ModelOptions[];
|
||||
selected_search_model_config: number;
|
||||
chat_model_options: ModelOptions[];
|
||||
selected_chat_model_config: number;
|
||||
paint_model_options: ModelOptions[];
|
||||
selected_paint_model_config: number;
|
||||
voice_model_options: ModelOptions[];
|
||||
selected_voice_model_config: number;
|
||||
// user billing info
|
||||
subscription_state: string;
|
||||
subscription_renewal_date: string;
|
||||
// server settings
|
||||
khoj_cloud_subscription_url: string | undefined;
|
||||
billing_enabled: boolean;
|
||||
is_eleven_labs_enabled: boolean;
|
||||
is_twilio_enabled: boolean;
|
||||
khoj_version: string;
|
||||
anonymous_mode: boolean;
|
||||
notion_oauth_url: string;
|
||||
detail: string;
|
||||
}
|
||||
|
||||
|
||||
export function useUserConfig(detailed: boolean = false) {
|
||||
const url = `/api/settings?detailed=${detailed}`;
|
||||
const { data, error } = useSWR<UserConfig>(url, fetcher, { revalidateOnFocus: false });
|
||||
|
||||
if (error || !data || data.detail === 'Forbidden') return null;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ export interface LocationData {
|
||||
|
||||
const locationFetcher = () => window.fetch("https://ipapi.co/json").then((res) => res.json()).catch((err) => console.log(err));
|
||||
|
||||
export const toTitleCase = (str: string) => str.replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase());
|
||||
|
||||
export function welcomeConsole() {
|
||||
console.log(`%c %s`, "font-family:monospace", `
|
||||
__ __ __ __ ______ __ _____ __
|
||||
|
||||
Reference in New Issue
Block a user