Remove dead code and old settings migration (#4180)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { getApiUrl } from '../config';
|
||||
import { FullExtensionConfig } from '../extensions';
|
||||
import { initializeAgent } from '../agent';
|
||||
import {
|
||||
initializeBundledExtensions,
|
||||
@@ -8,16 +7,7 @@ import {
|
||||
} from '../components/settings/extensions';
|
||||
import { extractExtensionConfig } from '../components/settings/extensions/utils';
|
||||
import type { ExtensionConfig, FixedExtensionEntry } from '../components/ConfigContext';
|
||||
// TODO: remove when removing migration logic
|
||||
import { toastService } from '../toasts';
|
||||
import {
|
||||
ExtensionQuery,
|
||||
RecipeParameter,
|
||||
SubRecipe,
|
||||
addExtension as apiAddExtension,
|
||||
updateSessionConfig,
|
||||
extendPrompt,
|
||||
} from '../api';
|
||||
import { RecipeParameter, SubRecipe, updateSessionConfig, extendPrompt } from '../api';
|
||||
import { addSubRecipesToAgent } from '../recipe/add_sub_recipe_on_agent';
|
||||
|
||||
export interface Provider {
|
||||
@@ -119,81 +109,6 @@ export const updateSystemPromptWithParameters = async (
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Migrates extensions from localStorage to config.yaml (settings v2)
|
||||
* This function handles the migration from settings v1 to v2 by:
|
||||
* 1. Reading extensions from localStorage
|
||||
* 2. Adding non-builtin extensions to config.yaml
|
||||
* 3. Marking the migration as complete
|
||||
*
|
||||
* NOTE: This logic can be removed eventually when enough versions have passed
|
||||
* We leave the existing user settings in localStorage, in case users downgrade
|
||||
* or things need to be reverted.
|
||||
*/
|
||||
export const migrateExtensionsToSettingsV3 = async () => {
|
||||
console.log('need to perform extension migration v3');
|
||||
|
||||
const userSettingsStr = localStorage.getItem('user_settings');
|
||||
let localStorageExtensions: FullExtensionConfig[] = [];
|
||||
|
||||
try {
|
||||
if (userSettingsStr) {
|
||||
const userSettings = JSON.parse(userSettingsStr);
|
||||
localStorageExtensions = userSettings.extensions ?? [];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to parse user settings:', error);
|
||||
}
|
||||
|
||||
if (localStorageExtensions.length === 0) {
|
||||
localStorage.setItem('configVersion', '3');
|
||||
console.log('No extensions to migrate. Config version set to 3.');
|
||||
return;
|
||||
}
|
||||
|
||||
const migrationErrors: { name: string; error: unknown }[] = [];
|
||||
|
||||
// Process extensions in parallel for better performance
|
||||
const migrationPromises = localStorageExtensions
|
||||
.filter((extension) => extension.type !== 'builtin') // Skip builtins as before
|
||||
.map(async (extension) => {
|
||||
console.log(`Migrating extension ${extension.name} to config.yaml`);
|
||||
try {
|
||||
const query: ExtensionQuery = {
|
||||
name: extension.name,
|
||||
config: extension,
|
||||
enabled: extension.enabled,
|
||||
};
|
||||
await apiAddExtension({
|
||||
body: query,
|
||||
throwOnError: true,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(`Failed to migrate extension ${extension.name}:`, err);
|
||||
migrationErrors.push({
|
||||
name: extension.name,
|
||||
error: `failed migration with ${JSON.stringify(err)}`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.allSettled(migrationPromises);
|
||||
|
||||
if (migrationErrors.length === 0) {
|
||||
localStorage.setItem('configVersion', '3');
|
||||
console.log('Extension migration complete. Config version set to 3.');
|
||||
} else {
|
||||
const errorSummaryStr = migrationErrors
|
||||
.map(({ name, error }) => `- ${name}: ${JSON.stringify(error)}`)
|
||||
.join('\n');
|
||||
toastService.error({
|
||||
title: 'Config Migration Error',
|
||||
msg: 'There was a problem updating your config file',
|
||||
traceback: errorSummaryStr,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const initializeSystem = async (
|
||||
provider: string,
|
||||
model: string,
|
||||
@@ -254,22 +169,6 @@ export const initializeSystem = async (
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: remove when we want to stop migration logic
|
||||
// Check if we need to migrate extensions from localStorage to config.yaml
|
||||
const configVersion = localStorage.getItem('configVersion');
|
||||
const shouldMigrateExtensions = !configVersion || parseInt(configVersion, 10) < 3;
|
||||
|
||||
if (shouldMigrateExtensions) {
|
||||
await migrateExtensionsToSettingsV3();
|
||||
}
|
||||
|
||||
/* NOTE:
|
||||
* If we've migrated and this is a version update, refreshedExtensions should be > 0
|
||||
* and we'll want to syncBundledExtensions to ensure any new extensions are added.
|
||||
* Otherwise if the user has never opened goose - refreshedExtensions will be 0
|
||||
* and we want to fall into the case to initializeBundledExtensions.
|
||||
*/
|
||||
|
||||
// Initialize or sync built-in extensions into config.yaml
|
||||
let refreshedExtensions = await options.getExtensions(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user