-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Sometimes we ship major changes, like a new default agent. | ||
|
||
import React from "react"; | ||
import { useAuth } from "#/context/auth-context"; | ||
import { useSettingsUpToDate } from "#/context/settings-up-to-date-context"; | ||
import { | ||
DEFAULT_SETTINGS, | ||
getCurrentSettingsVersion, | ||
getLocalStorageSettings, | ||
} from "#/services/settings"; | ||
import { useSaveSettings } from "./mutation/use-save-settings"; | ||
|
||
// In this case, we may want to override a previous choice made by the user. | ||
export const useMaybeMigrateSettings = () => { | ||
const { logout } = useAuth(); | ||
const { mutateAsync: saveSettings } = useSaveSettings(); | ||
const { isUpToDate } = useSettingsUpToDate(); | ||
|
||
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) { | ||
logout(); | ||
} | ||
|
||
// Only save settings if user already previously saved settings | ||
// That way we avoid setting defaults for new users too early | ||
if (currentVersion !== 0 && currentVersion < 5) { | ||
const localSettings = getLocalStorageSettings(); | ||
await saveSettings(localSettings); | ||
} | ||
}; | ||
|
||
React.useEffect(() => { | ||
if (!isUpToDate) { | ||
maybeMigrateSettings(); | ||
} | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters