|
|
|
|
|
import React from "react";
|
|
import { useCurrentSettings } from "#/context/settings-context";
|
|
import {
|
|
getCurrentSettingsVersion,
|
|
DEFAULT_SETTINGS,
|
|
getLocalStorageSettings,
|
|
} from "#/services/settings";
|
|
import { useSaveSettings } from "./mutation/use-save-settings";
|
|
|
|
|
|
export const useMaybeMigrateSettings = () => {
|
|
const { mutateAsync: saveSettings } = useSaveSettings();
|
|
const { isUpToDate } = useCurrentSettings();
|
|
|
|
const maybeMigrateSettings = async () => {
|
|
const currentVersion = getCurrentSettingsVersion();
|
|
|
|
if (currentVersion < 1) {
|
|
localStorage.setItem("AGENT", DEFAULT_SETTINGS.AGENT);
|
|
}
|
|
if (currentVersion < 2) {
|
|
const customModel = localStorage.getItem("CUSTOM_LLM_MODEL");
|
|
if (customModel) {
|
|
localStorage.setItem("LLM_MODEL", customModel);
|
|
}
|
|
localStorage.removeItem("CUSTOM_LLM_MODEL");
|
|
localStorage.removeItem("USING_CUSTOM_MODEL");
|
|
}
|
|
if (currentVersion < 3) {
|
|
localStorage.removeItem("token");
|
|
}
|
|
|
|
if (currentVersion < 4) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentVersion !== 0 && currentVersion < 5) {
|
|
const localSettings = getLocalStorageSettings();
|
|
await saveSettings(localSettings);
|
|
}
|
|
};
|
|
|
|
React.useEffect(() => {
|
|
if (!isUpToDate) {
|
|
maybeMigrateSettings();
|
|
}
|
|
}, []);
|
|
};
|
|
|