speed up loading extensions by loading in parallel (#4054)
thx verified locally should be gtg 👍
This commit is contained in:
@@ -213,61 +213,6 @@ export async function removeExtension(name: string, silent: boolean = false): Pr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store extension config in user_settings
|
|
||||||
function storeExtensionConfig(config: FullExtensionConfig) {
|
|
||||||
try {
|
|
||||||
const userSettingsStr = localStorage.getItem('user_settings');
|
|
||||||
const userSettings = userSettingsStr
|
|
||||||
? JSON.parse(userSettingsStr)
|
|
||||||
: { models: [], extensions: [] };
|
|
||||||
|
|
||||||
// Check if config already exists (based on cmd for stdio, uri for sse, name for builtin)
|
|
||||||
const extensionExists = userSettings.extensions.some(
|
|
||||||
(extension: { id: string }) => extension.id === config.id
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!extensionExists) {
|
|
||||||
userSettings.extensions.push(config);
|
|
||||||
localStorage.setItem('user_settings', JSON.stringify(userSettings));
|
|
||||||
console.log('Extension config stored successfully in user_settings');
|
|
||||||
// Notify settings update through electron IPC
|
|
||||||
window.electron.emit('settings-updated');
|
|
||||||
} else {
|
|
||||||
console.log('Extension config already exists in user_settings');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error storing extension config:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function loadAndAddStoredExtensions() {
|
|
||||||
try {
|
|
||||||
const userSettingsStr = localStorage.getItem('user_settings');
|
|
||||||
|
|
||||||
if (userSettingsStr) {
|
|
||||||
const userSettings = JSON.parse(userSettingsStr);
|
|
||||||
const enabledExtensions = userSettings.extensions.filter(
|
|
||||||
(ext: FullExtensionConfig) => ext.enabled
|
|
||||||
);
|
|
||||||
console.log('Adding extensions from localStorage: ', enabledExtensions);
|
|
||||||
for (const ext of enabledExtensions) {
|
|
||||||
await addExtension(ext, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('Saving default builtin extensions to localStorage');
|
|
||||||
// TODO - Revisit
|
|
||||||
BUILT_IN_EXTENSIONS.forEach(async (extension: FullExtensionConfig) => {
|
|
||||||
storeExtensionConfig(extension);
|
|
||||||
if (extension.enabled) {
|
|
||||||
await addExtension(extension, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading and activating extensions from localStorage: ', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the path to the binary based on the command
|
// Update the path to the binary based on the command
|
||||||
export async function replaceWithShims(cmd: string) {
|
export async function replaceWithShims(cmd: string) {
|
||||||
const binaryPathMap: Record<string, string> = {
|
const binaryPathMap: Record<string, string> = {
|
||||||
|
|||||||
@@ -291,13 +291,21 @@ export const initializeSystem = async (
|
|||||||
await syncBundledExtensions(refreshedExtensions, options.addExtension);
|
await syncBundledExtensions(refreshedExtensions, options.addExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add enabled extensions to agent
|
// Add enabled extensions to agent in parallel
|
||||||
for (const extensionEntry of refreshedExtensions) {
|
const enabledExtensions = refreshedExtensions.filter((ext) => ext.enabled);
|
||||||
if (extensionEntry.enabled) {
|
|
||||||
const extensionConfig = extractExtensionConfig(extensionEntry);
|
const extensionLoadingPromises = enabledExtensions.map(async (extensionEntry) => {
|
||||||
await addToAgentOnStartup({ addToConfig: options.addExtension, extensionConfig });
|
const extensionConfig = extractExtensionConfig(extensionEntry);
|
||||||
|
const extensionName = extensionConfig.name;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await addToAgentOnStartup({ addToConfig: options.addExtension!, extensionConfig });
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to load extension ${extensionName}:`, error);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
await Promise.allSettled(extensionLoadingPromises);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize agent:', error);
|
console.error('Failed to initialize agent:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in New Issue
Block a user