ui: load builtins (#1679)

This commit is contained in:
Lily Delalande
2025-03-13 19:40:39 -07:00
committed by GitHub
parent bc0158c828
commit 49dc396c83
9 changed files with 164 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { addExtensionFromDeepLink } from './extensions';
import { getStoredModel } from './utils/providerUtils';
import { getStoredProvider, initializeSystem } from './utils/providerUtils';
@@ -24,6 +24,11 @@ import ProviderSettings from './components/settings_v2/providers/ProviderSetting
import { useChat } from './hooks/useChat';
import 'react-toastify/dist/ReactToastify.css';
import { useConfig } from './components/ConfigContext';
import {
initializeBuiltInExtensions,
syncBuiltInExtensions,
} from './components/settings_v2/extensions/LoadBuiltins';
// Views and their options
export type View =
@@ -57,6 +62,41 @@ export default function App() {
view: 'welcome',
viewOptions: {},
});
const { getExtensions, addExtension } = useConfig();
const initAttemptedRef = useRef(false);
useEffect(() => {
// Skip if feature flag is not enabled
if (!process.env.ALPHA) {
return;
}
const setupExtensions = async () => {
try {
// Set the ref immediately to prevent duplicate runs
initAttemptedRef.current = true;
// Force refresh extensions from the backend to ensure we have the latest
const refreshedExtensions = await getExtensions(true);
if (refreshedExtensions.length === 0) {
// If we still have no extensions, this is truly a first-time setup
console.log('First-time setup: Adding all built-in extensions...');
await initializeBuiltInExtensions(addExtension);
} else {
// Extensions exist, check for any missing built-ins
console.log('Checking for missing built-in extensions...');
console.log(refreshedExtensions);
await syncBuiltInExtensions(refreshedExtensions, addExtension);
}
} catch (error) {
console.error('Error setting up extensions:', error);
}
};
setupExtensions();
}, []); // Empty dependency array since we're using initAttemptedRef
const [isGoosehintsModalOpen, setIsGoosehintsModalOpen] = useState(false);
const [isLoadingSession, setIsLoadingSession] = useState(false);