A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
import { createContext, use, useMemo } from "react";
import type { ZClientConfig } from "@karakeep/shared/types/config";
export const DEFAULT_CLIENT_CONFIG: ZClientConfig = {
publicUrl: "",
publicApiUrl: "",
auth: {
disableSignups: false,
disablePasswordAuth: false,
oauthAutoRedirect: false,
},
turnstile: null,
inference: {
isConfigured: false,
inferredTagLang: "english",
enableAutoTagging: false,
enableAutoSummarization: false,
},
chat: {
enabled: false,
},
search: {
semanticSearchEnabled: false,
},
stripe: {
isConfigured: false,
},
crawler: {
videoDownloadOnDemand: false,
},
revenueCat: {
isConfigured: false,
purchasePlatforms: [],
},
legal: {},
problemReports: {
enabled: false,
},
disableNewReleaseCheck: true,
};
const ClientConfigContext = createContext<ZClientConfig>(DEFAULT_CLIENT_CONFIG);
export function ClientConfigProvider({
children,
value,
}: {
children: React.ReactNode;
value?: ZClientConfig;
}) {
// Merge every nested group so an older server can omit newly introduced
// capabilities without breaking a newer client.
const config = useMemo<ZClientConfig>(
() => ({
...DEFAULT_CLIENT_CONFIG,
...value,
auth: {
...DEFAULT_CLIENT_CONFIG.auth,
...value?.auth,
},
inference: {
...DEFAULT_CLIENT_CONFIG.inference,
...value?.inference,
},
chat: {
...DEFAULT_CLIENT_CONFIG.chat,
...value?.chat,
},
search: {
...DEFAULT_CLIENT_CONFIG.search,
...value?.search,
},
stripe: {
...DEFAULT_CLIENT_CONFIG.stripe,
...value?.stripe,
},
crawler: {
...DEFAULT_CLIENT_CONFIG.crawler,
...value?.crawler,
},
revenueCat: {
...DEFAULT_CLIENT_CONFIG.revenueCat,
...value?.revenueCat,
},
legal: {
...DEFAULT_CLIENT_CONFIG.legal,
...value?.legal,
},
problemReports: {
...DEFAULT_CLIENT_CONFIG.problemReports,
...value?.problemReports,
},
}),
[value],
);
return (
<ClientConfigContext.Provider value={config}>
{children}
</ClientConfigContext.Provider>
);
}
export function useClientConfig() {
return use(ClientConfigContext);
}