Compare commits

...

6 Commits

Author SHA1 Message Date
Robert Brennan
e0e5792542 minor fixes 2024-12-30 11:48:16 -05:00
Robert Brennan
c17f8a6d68 minor fixes 2024-12-30 11:38:23 -05:00
Robert Brennan
336c5d3c2b remove isAuthed 2024-12-30 11:35:41 -05:00
Robert Brennan
baf2f766f4 remove null check 2024-12-30 11:34:18 -05:00
Robert Brennan
dfb1731922 fix up settings prompt 2024-12-30 11:32:58 -05:00
Robert Brennan
be497a34ed return 404 when settings not found 2024-12-30 11:09:23 -05:00
3 changed files with 30 additions and 16 deletions

View File

@@ -3,7 +3,6 @@ import { useLocation } from "react-router";
import { useAuth } from "#/context/auth-context";
import { useSettings } from "#/context/settings-context";
import { useGitHubUser } from "#/hooks/query/use-github-user";
import { useIsAuthed } from "#/hooks/query/use-is-authed";
import { UserActions } from "./user-actions";
import { AllHandsLogoButton } from "#/components/shared/buttons/all-hands-logo-button";
import { DocsButton } from "#/components/shared/buttons/docs-button";
@@ -18,13 +17,12 @@ export function Sidebar() {
const location = useLocation();
const user = useGitHubUser();
const { data: isAuthed } = useIsAuthed();
const { logout } = useAuth();
const { settingsAreUpToDate } = useSettings();
const { settingsAreUpToDate, settings } = useSettings();
const [accountSettingsModalOpen, setAccountSettingsModalOpen] =
React.useState(false);
const [settingsModalIsOpen, setSettingsModalIsOpen] = React.useState(false);
const [startNewProjectModalIsOpen, setStartNewProjectModalIsOpen] =
React.useState(false);
@@ -36,6 +34,12 @@ export function Sidebar() {
}
}, [user.isError]);
React.useEffect(() => {
if (!settings || !settingsAreUpToDate) {
setSettingsModalIsOpen(true);
}
}, [settings, settingsAreUpToDate]);
const handleAccountSettingsModalClose = () => {
// If the user closes the modal without connecting to GitHub,
// we need to log them out to clear the invalid token from the
@@ -49,9 +53,6 @@ export function Sidebar() {
setStartNewProjectModalIsOpen(true);
};
const showSettingsModal =
isAuthed && (!settingsAreUpToDate || settingsModalIsOpen);
return (
<>
<aside className="h-[40px] md:h-auto px-1 flex flex-row md:flex-col gap-1">
@@ -79,7 +80,7 @@ export function Sidebar() {
{accountSettingsModalOpen && (
<AccountSettingsModal onClose={handleAccountSettingsModalClose} />
)}
{showSettingsModal && (
{!accountSettingsModalOpen && settingsModalIsOpen && (
<SettingsModal onClose={() => setSettingsModalIsOpen(false)} />
)}
{startNewProjectModalIsOpen && (

View File

@@ -131,9 +131,9 @@ export const getDefaultSettings = (): Settings => DEFAULT_SETTINGS;
* Get the settings from the server or use the default settings if not found
*/
export const getSettings = async (): Promise<Settings> => {
const { data: apiSettings } =
await openHands.get<ApiSettings>("/api/settings");
if (apiSettings != null) {
try {
const { data: apiSettings } =
await openHands.get<ApiSettings>("/api/settings");
return {
LLM_MODEL: apiSettings.llm_model,
LLM_BASE_URL: apiSettings.llm_base_url,
@@ -143,6 +143,14 @@ export const getSettings = async (): Promise<Settings> => {
SECURITY_ANALYZER: apiSettings.security_analyzer,
LLM_API_KEY: "",
};
} catch (error) {
// @ts-expect-error we don't have a type annotation for the response
if (error.response?.status !== 404) {
throw error;
}
}
return getLocalStorageSettings();
// FIXME: remove local storage settings after 1/31/2025
const localSettings = getLocalStorageSettings();
await saveSettings(localSettings);
return localSettings;
};

View File

@@ -12,7 +12,8 @@ app = APIRouter(prefix='/api')
SettingsStoreImpl = get_impl(SettingsStore, openhands_config.settings_store_class) # type: ignore
ConversationStoreImpl = get_impl(
ConversationStore, openhands_config.conversation_store_class # type: ignore
ConversationStore, # type: ignore
openhands_config.conversation_store_class, # type: ignore
)
@@ -26,9 +27,13 @@ async def load_settings(
try:
settings_store = await SettingsStoreImpl.get_instance(config, github_token)
settings = await settings_store.load()
if settings:
# For security reasons we don't ever send the api key to the client
settings.llm_api_key = None
if not settings:
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={'error': 'Settings not found'},
)
# For security reasons we don't ever send the api key to the client
settings.llm_api_key = None
return settings
except Exception as e:
logger.warning(f'Invalid token: {e}')