|
export const LATEST_SETTINGS_VERSION = 5;
|
|
|
|
export type Settings = {
|
|
LLM_MODEL: string;
|
|
LLM_BASE_URL: string;
|
|
AGENT: string;
|
|
LANGUAGE: string;
|
|
LLM_API_KEY: string | null;
|
|
CONFIRMATION_MODE: boolean;
|
|
SECURITY_ANALYZER: string;
|
|
REMOTE_RUNTIME_RESOURCE_FACTOR: number;
|
|
};
|
|
|
|
export type ApiSettings = {
|
|
llm_model: string;
|
|
llm_base_url: string;
|
|
agent: string;
|
|
language: string;
|
|
llm_api_key: string | null;
|
|
confirmation_mode: boolean;
|
|
security_analyzer: string;
|
|
remote_runtime_resource_factor: number;
|
|
};
|
|
|
|
export const DEFAULT_SETTINGS: Settings = {
|
|
LLM_MODEL: "anthropic/claude-3-5-sonnet-20241022",
|
|
LLM_BASE_URL: "",
|
|
AGENT: "CodeActAgent",
|
|
LANGUAGE: "en",
|
|
LLM_API_KEY: null,
|
|
CONFIRMATION_MODE: false,
|
|
SECURITY_ANALYZER: "",
|
|
REMOTE_RUNTIME_RESOURCE_FACTOR: 1,
|
|
};
|
|
|
|
export const getCurrentSettingsVersion = () => {
|
|
const settingsVersion = localStorage.getItem("SETTINGS_VERSION");
|
|
if (!settingsVersion) return 0;
|
|
try {
|
|
return parseInt(settingsVersion, 10);
|
|
} catch (e) {
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
export const settingsAreUpToDate = () =>
|
|
getCurrentSettingsVersion() === LATEST_SETTINGS_VERSION;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getLocalStorageSettings = (): Settings => {
|
|
const llmModel = localStorage.getItem("LLM_MODEL");
|
|
const baseUrl = localStorage.getItem("LLM_BASE_URL");
|
|
const agent = localStorage.getItem("AGENT");
|
|
const language = localStorage.getItem("LANGUAGE");
|
|
const llmApiKey = localStorage.getItem("LLM_API_KEY");
|
|
const confirmationMode = localStorage.getItem("CONFIRMATION_MODE") === "true";
|
|
const securityAnalyzer = localStorage.getItem("SECURITY_ANALYZER");
|
|
|
|
return {
|
|
LLM_MODEL: llmModel || DEFAULT_SETTINGS.LLM_MODEL,
|
|
LLM_BASE_URL: baseUrl || DEFAULT_SETTINGS.LLM_BASE_URL,
|
|
AGENT: agent || DEFAULT_SETTINGS.AGENT,
|
|
LANGUAGE: language || DEFAULT_SETTINGS.LANGUAGE,
|
|
LLM_API_KEY: llmApiKey || DEFAULT_SETTINGS.LLM_API_KEY,
|
|
CONFIRMATION_MODE: confirmationMode || DEFAULT_SETTINGS.CONFIRMATION_MODE,
|
|
SECURITY_ANALYZER: securityAnalyzer || DEFAULT_SETTINGS.SECURITY_ANALYZER,
|
|
REMOTE_RUNTIME_RESOURCE_FACTOR:
|
|
DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getDefaultSettings = (): Settings => DEFAULT_SETTINGS;
|
|
|
|
|
|
|
|
|
|
export const getSettings = (): Settings => getLocalStorageSettings();
|
|
|