Files
tkmind_go/ui/desktop/src/contexts/FeaturesContext.tsx
T
이대희 c493c6160c feat: feature-gate local inference dependencies (#7976)
Signed-off-by: DaeHee Lee <lee111dae11@proton.me>
Signed-off-by: jh-block <jhugo@block.xyz>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: jh-block <jhugo@block.xyz>
2026-03-23 15:49:24 +00:00

50 lines
1.4 KiB
TypeScript

import { createContext, useContext, useEffect, useState, useMemo } from 'react';
import { getFeatures } from '../api';
interface FeaturesContextValue {
localInference: boolean;
codeMode: boolean;
isLoading: boolean;
}
const FeaturesContext = createContext<FeaturesContextValue | null>(null);
export function FeaturesProvider({ children }: { children: React.ReactNode }) {
const [features, setFeatures] = useState<Record<string, boolean>>({});
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
(async () => {
try {
const response = await getFeatures({ throwOnError: false });
if (response.data) {
setFeatures(response.data.features);
}
} catch (error) {
console.warn('[FeaturesContext] Failed to fetch features:', error);
} finally {
setIsLoading(false);
}
})();
}, []);
const value = useMemo<FeaturesContextValue>(
() => ({
localInference: features['local-inference'] ?? false,
codeMode: features['code-mode'] ?? true,
isLoading,
}),
[features, isLoading]
);
return <FeaturesContext.Provider value={value}>{children}</FeaturesContext.Provider>;
}
export function useFeatures(): FeaturesContextValue {
const context = useContext(FeaturesContext);
if (!context) {
throw new Error('useFeatures must be used within a FeaturesProvider');
}
return context;
}