Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(standalone): disable LLM features
Elian Dorande037b3ced4a
diff --git a/apps/client/src/services/experimental_features.ts b/apps/client/src/services/experimental_features.tsindex d56836ef6b..22e868d3af 100644--- a/apps/client/src/services/experimental_features.ts+++ b/apps/client/src/services/experimental_features.ts@@ -1,6 +1,6 @@import { t } from "./i18n";import options from "./options";-import { isMobile } from "./utils";+import { isMobile, isStandalone } from "./utils";export interface ExperimentalFeature {id: string;@@ -23,6 +23,11 @@ export const experimentalFeatures = [export type ExperimentalFeatureId = typeof experimentalFeatures[number]["id"];+/** Returns experimental features available for the current platform (excludes LLM in standalone mode). */+export function getAvailableExperimentalFeatures() {+ return experimentalFeatures.filter(f => !(f.id === "llm" && isStandalone));+}+let enabledFeatures: Set<ExperimentalFeatureId> | null = null;export function isExperimentalFeatureEnabled(featureId: ExperimentalFeatureId): boolean {@@ -30,14 +35,24 @@ export function isExperimentalFeatureEnabled(featureId: ExperimentalFeatureId):return (isMobile() || options.is("newLayout"));}+ // LLM features require server-side API calls that don't work in standalone mode+ // due to CORS restrictions from LLM providers (OpenAI, Google don't allow browser requests)+ if (featureId === "llm" && isStandalone) {+ return false;+ }+return getEnabledFeatures().has(featureId);}export function getEnabledExperimentalFeatureIds() {- const values = [ ...getEnabledFeatures().values() ];+ let values = [ ...getEnabledFeatures().values() ];if (isMobile() || options.is("newLayout")) {values.push("new-layout");}+ // LLM is not available in standalone mode+ if (isStandalone) {+ values = values.filter(v => v !== "llm");+ }return values;}diff --git a/apps/client/src/widgets/buttons/global_menu.tsx b/apps/client/src/widgets/buttons/global_menu.tsxindex d5d3422197..a6f58ced1e 100644--- a/apps/client/src/widgets/buttons/global_menu.tsx+++ b/apps/client/src/widgets/buttons/global_menu.tsx@@ -6,7 +6,7 @@ import { useContext, useEffect, useRef, useState } from "preact/hooks";import { CommandNames } from "../../components/app_context";import Component from "../../components/component";-import { ExperimentalFeature, ExperimentalFeatureId, experimentalFeatures, isExperimentalFeatureEnabled, toggleExperimentalFeature } from "../../services/experimental_features";+import { ExperimentalFeature, ExperimentalFeatureId, getAvailableExperimentalFeatures, isExperimentalFeatureEnabled, toggleExperimentalFeature } from "../../services/experimental_features";import { t } from "../../services/i18n";import utils, { dynamicRequire, isElectron, isMobile, isStandalone, reloadFrontendApp } from "../../services/utils";import Dropdown from "../react/Dropdown";@@ -112,7 +112,7 @@ function DevelopmentOptions({ dropStart }: { dropStart: boolean }) {return <><FormListHeader text="Development Options" /><FormDropdownSubmenu icon="bx bx-test-tube" title="Experimental features" dropStart={dropStart}>- {experimentalFeatures.map((feature) => (+ {getAvailableExperimentalFeatures().map((feature) => (<ExperimentalFeatureToggle key={feature.id} experimentalFeature={feature as ExperimentalFeature} />))}</FormDropdownSubmenu>diff --git a/apps/client/src/widgets/type_widgets/options/advanced.tsx b/apps/client/src/widgets/type_widgets/options/advanced.tsxindex 619a1fb514..e426e2b5eb 100644--- a/apps/client/src/widgets/type_widgets/options/advanced.tsx+++ b/apps/client/src/widgets/type_widgets/options/advanced.tsx@@ -1,7 +1,7 @@import { AnonymizedDbResponse, DatabaseAnonymizeResponse, DatabaseCheckIntegrityResponse } from "@triliumnext/commons";import { useCallback, useEffect, useMemo, useState } from "preact/hooks";-import { experimentalFeatures, type ExperimentalFeatureId } from "../../../services/experimental_features";+import { getAvailableExperimentalFeatures, type ExperimentalFeatureId } from "../../../services/experimental_features";import { t } from "../../../services/i18n";import server from "../../../services/server";import toast from "../../../services/toast";@@ -182,7 +182,7 @@ function VacuumDatabaseOptions() {function ExperimentalOptions() {const [enabledFeatures, setEnabledFeatures] = useTriliumOptionJson<ExperimentalFeatureId[]>("experimentalFeatures", true);- const filteredFeatures = useMemo(() => experimentalFeatures.filter(e => e.id !== "new-layout"), []);+ const filteredFeatures = useMemo(() => getAvailableExperimentalFeatures().filter(e => e.id !== "new-layout"), []);const toggleFeature = useCallback((featureId: ExperimentalFeatureId, enabled: boolean) => {if (enabled) {