diff --git a/frontend/__tests__/routes/settings.test.tsx b/frontend/__tests__/routes/settings.test.tsx index f307e4fb4b17..b0ab7c96b594 100644 --- a/frontend/__tests__/routes/settings.test.tsx +++ b/frontend/__tests__/routes/settings.test.tsx @@ -71,7 +71,7 @@ describe("Settings Screen", () => { renderSettingsScreen(); await waitFor(() => { - screen.getByTestId("github-token-input"); + screen.getByTestId("token-input"); screen.getByTestId("github-token-help-anchor"); screen.getByTestId("language-input"); screen.getByTestId("enable-analytics-switch"); @@ -82,13 +82,13 @@ describe("Settings Screen", () => { it.skip("should render an indicator if the GitHub token is not set", async () => { getSettingsSpy.mockResolvedValue({ ...MOCK_DEFAULT_USER_SETTINGS, - github_token_is_set: false, + token_is_set: false, }); renderSettingsScreen(); await waitFor(() => { - const input = screen.getByTestId("github-token-input"); + const input = screen.getByTestId("token-input"); const inputParent = input.parentElement; if (inputParent) { @@ -103,13 +103,13 @@ describe("Settings Screen", () => { it("should set asterik placeholder if the GitHub token is set", async () => { getSettingsSpy.mockResolvedValue({ ...MOCK_DEFAULT_USER_SETTINGS, - github_token_is_set: true, + token_is_set: true, }); renderSettingsScreen(); await waitFor(() => { - const input = screen.getByTestId("github-token-input"); + const input = screen.getByTestId("token-input"); expect(input).toHaveProperty("placeholder", "**********"); }); }); @@ -117,12 +117,12 @@ describe("Settings Screen", () => { it("should render an indicator if the GitHub token is set", async () => { getSettingsSpy.mockResolvedValue({ ...MOCK_DEFAULT_USER_SETTINGS, - github_token_is_set: true, + token_is_set: true, }); renderSettingsScreen(); - const input = await screen.findByTestId("github-token-input"); + const input = await screen.findByTestId("token-input"); const inputParent = input.parentElement; if (inputParent) { @@ -136,7 +136,7 @@ describe("Settings Screen", () => { it("should render a disabled 'Disconnect from GitHub' button if the GitHub token is not set", async () => { getSettingsSpy.mockResolvedValue({ ...MOCK_DEFAULT_USER_SETTINGS, - github_token_is_set: false, + token_is_set: false, }); renderSettingsScreen(); @@ -149,7 +149,7 @@ describe("Settings Screen", () => { it("should render an enabled 'Disconnect from GitHub' button if the GitHub token is set", async () => { getSettingsSpy.mockResolvedValue({ ...MOCK_DEFAULT_USER_SETTINGS, - github_token_is_set: true, + token_is_set: true, }); renderSettingsScreen(); @@ -158,7 +158,7 @@ describe("Settings Screen", () => { expect(button).toBeEnabled(); // input should still be rendered - const input = await screen.findByTestId("github-token-input"); + const input = await screen.findByTestId("token-input"); expect(input).toBeInTheDocument(); }); @@ -167,7 +167,7 @@ describe("Settings Screen", () => { getSettingsSpy.mockResolvedValue({ ...MOCK_DEFAULT_USER_SETTINGS, - github_token_is_set: true, + token_is_set: true, }); renderSettingsScreen(); @@ -213,7 +213,7 @@ describe("Settings Screen", () => { renderSettingsScreen(); await waitFor(() => { - const input = screen.queryByTestId("github-token-input"); + const input = screen.queryByTestId("token-input"); const helpAnchor = screen.queryByTestId("github-token-help-anchor"); expect(input).not.toBeInTheDocument(); @@ -225,7 +225,7 @@ describe("Settings Screen", () => { const user = userEvent.setup(); getSettingsSpy.mockResolvedValue({ ...MOCK_DEFAULT_USER_SETTINGS, - github_token_is_set: false, + token_is_set: false, llm_model: "anthropic/claude-3-5-sonnet-20241022", }); saveSettingsSpy.mockRejectedValueOnce(new Error("Invalid GitHub token")); @@ -238,7 +238,7 @@ describe("Settings Screen", () => { expect(llmProviderInput).toHaveValue("Anthropic"); expect(llmModelInput).toHaveValue("claude-3-5-sonnet-20241022"); - const input = await screen.findByTestId("github-token-input"); + const input = await screen.findByTestId("token-input"); await user.type(input, "invalid-token"); const saveButton = screen.getByText("Save Changes"); @@ -646,7 +646,7 @@ describe("Settings Screen", () => { getSettingsSpy.mockResolvedValue({ ...MOCK_DEFAULT_USER_SETTINGS, language: "no", - github_token_is_set: true, + token_is_set: true, user_consents_to_analytics: true, llm_base_url: "https://test.com", llm_model: "anthropic/claude-3-5-sonnet-20241022", @@ -699,7 +699,7 @@ describe("Settings Screen", () => { expect(saveSettingsSpy).toHaveBeenCalledWith( expect.objectContaining({ llm_api_key: "", // empty because it's not set previously - github_token: undefined, + token: undefined, language: "no", }), ); @@ -736,7 +736,7 @@ describe("Settings Screen", () => { expect(saveSettingsSpy).toHaveBeenCalledWith( expect.objectContaining({ - github_token: undefined, + token: undefined, llm_api_key: "", // empty because it's not set previously llm_model: "openai/gpt-4o", }), @@ -773,13 +773,13 @@ describe("Settings Screen", () => { const mockCopy: Partial = { ...MOCK_DEFAULT_USER_SETTINGS, }; - delete mockCopy.github_token_is_set; - delete mockCopy.unset_github_token; + delete mockCopy.token_is_set; + delete mockCopy.unset_token; delete mockCopy.user_consents_to_analytics; expect(saveSettingsSpy).toHaveBeenCalledWith({ ...mockCopy, - github_token: undefined, // not set + token: undefined, // not set llm_api_key: "", // reset as well }); expect(screen.queryByTestId("reset-modal")).not.toBeInTheDocument(); diff --git a/frontend/src/components/features/chat/action-suggestions.tsx b/frontend/src/components/features/chat/action-suggestions.tsx index ec0917e49ea0..113c9c517d2f 100644 --- a/frontend/src/components/features/chat/action-suggestions.tsx +++ b/frontend/src/components/features/chat/action-suggestions.tsx @@ -13,7 +13,7 @@ interface ActionSuggestionsProps { export function ActionSuggestions({ onSuggestionsClick, }: ActionSuggestionsProps) { - const { githubTokenIsSet } = useAuth(); + const { tokenIsSet } = useAuth(); const { selectedRepository } = useSelector( (state: RootState) => state.initialQuery, ); @@ -32,7 +32,7 @@ export function ActionSuggestions({ onClose={handleDownloadClose} isOpen={isDownloading} /> - {githubTokenIsSet && selectedRepository ? ( + {tokenIsSet && selectedRepository ? (
{!hasPullRequest ? ( <> diff --git a/frontend/src/context/auth-context.tsx b/frontend/src/context/auth-context.tsx index 845de12ab390..b05d5d55601c 100644 --- a/frontend/src/context/auth-context.tsx +++ b/frontend/src/context/auth-context.tsx @@ -12,9 +12,7 @@ interface AuthContextProps extends React.PropsWithChildren { const AuthContext = React.createContext(undefined); function AuthProvider({ children, initialTokenIsSet }: AuthContextProps) { - const [tokenIsSet, setTokenIsSet] = React.useState( - !!initialTokenIsSet, - ); + const [tokenIsSet, setTokenIsSet] = React.useState(!!initialTokenIsSet); const value = React.useMemo( () => ({ diff --git a/frontend/src/hooks/mutation/use-logout.ts b/frontend/src/hooks/mutation/use-logout.ts index 4207c1dd191f..0151d640e3c1 100644 --- a/frontend/src/hooks/mutation/use-logout.ts +++ b/frontend/src/hooks/mutation/use-logout.ts @@ -3,13 +3,13 @@ import OpenHands from "#/api/open-hands"; import { useAuth } from "#/context/auth-context"; export const useLogout = () => { - const { setGitHubTokenIsSet } = useAuth(); + const { setTokenIsSet } = useAuth(); const queryClient = useQueryClient(); return useMutation({ mutationFn: OpenHands.logout, onSuccess: async () => { - setGitHubTokenIsSet(false); + setTokenIsSet(false); await queryClient.invalidateQueries(); }, }); diff --git a/frontend/src/hooks/mutation/use-save-settings.ts b/frontend/src/hooks/mutation/use-save-settings.ts index 294a8a3a36b3..a937e3f5a5c1 100644 --- a/frontend/src/hooks/mutation/use-save-settings.ts +++ b/frontend/src/hooks/mutation/use-save-settings.ts @@ -18,7 +18,6 @@ const saveSettingsMutationFn = async (settings: Partial) => { : settings.LLM_API_KEY?.trim() || undefined, remote_runtime_resource_factor: settings.REMOTE_RUNTIME_RESOURCE_FACTOR, token: settings.token, - token_type: settings.token_type, unset_token: settings.unset_token, enable_default_condenser: settings.ENABLE_DEFAULT_CONDENSER, enable_sound_notifications: settings.ENABLE_SOUND_NOTIFICATIONS, diff --git a/frontend/src/hooks/query/use-app-installations.ts b/frontend/src/hooks/query/use-app-installations.ts index 691d48f2d664..0ef058adf047 100644 --- a/frontend/src/hooks/query/use-app-installations.ts +++ b/frontend/src/hooks/query/use-app-installations.ts @@ -5,14 +5,12 @@ import { useAuth } from "#/context/auth-context"; export const useAppInstallations = () => { const { data: config } = useConfig(); - const { githubTokenIsSet } = useAuth(); + const { tokenIsSet } = useAuth(); return useQuery({ - queryKey: ["installations", githubTokenIsSet, config?.GITHUB_CLIENT_ID], + queryKey: ["installations", tokenIsSet, config?.GITHUB_CLIENT_ID], queryFn: OpenHands.getGitHubUserInstallationIds, enabled: - githubTokenIsSet && - !!config?.GITHUB_CLIENT_ID && - config?.APP_MODE === "saas", + tokenIsSet && !!config?.GITHUB_CLIENT_ID && config?.APP_MODE === "saas", }); }; diff --git a/frontend/src/hooks/query/use-app-repositories.ts b/frontend/src/hooks/query/use-app-repositories.ts index 6d07a6292fcf..38eeb0d3c936 100644 --- a/frontend/src/hooks/query/use-app-repositories.ts +++ b/frontend/src/hooks/query/use-app-repositories.ts @@ -6,12 +6,12 @@ import { useConfig } from "./use-config"; import { useAuth } from "#/context/auth-context"; export const useAppRepositories = () => { - const { githubTokenIsSet } = useAuth(); + const { tokenIsSet } = useAuth(); const { data: config } = useConfig(); const { data: installations } = useAppInstallations(); const repos = useInfiniteQuery({ - queryKey: ["repositories", githubTokenIsSet, installations], + queryKey: ["repositories", tokenIsSet, installations], queryFn: async ({ pageParam, }: { @@ -46,7 +46,7 @@ export const useAppRepositories = () => { return null; }, enabled: - githubTokenIsSet && + tokenIsSet && Array.isArray(installations) && installations.length > 0 && config?.APP_MODE === "saas", diff --git a/frontend/src/hooks/query/use-is-authed.ts b/frontend/src/hooks/query/use-is-authed.ts index bb58993ce4af..d3bfab2deadb 100644 --- a/frontend/src/hooks/query/use-is-authed.ts +++ b/frontend/src/hooks/query/use-is-authed.ts @@ -5,13 +5,13 @@ import { useConfig } from "./use-config"; import { useAuth } from "#/context/auth-context"; export const useIsAuthed = () => { - const { githubTokenIsSet } = useAuth(); + const { tokenIsSet } = useAuth(); const { data: config } = useConfig(); const appMode = React.useMemo(() => config?.APP_MODE, [config]); return useQuery({ - queryKey: ["user", "authenticated", githubTokenIsSet, appMode], + queryKey: ["user", "authenticated", tokenIsSet, appMode], queryFn: () => OpenHands.authenticate(appMode!), enabled: !!appMode, staleTime: 1000 * 60 * 5, // 5 minutes diff --git a/frontend/src/hooks/query/use-settings.ts b/frontend/src/hooks/query/use-settings.ts index 5b4af7dc8fbf..a1e90919a8c0 100644 --- a/frontend/src/hooks/query/use-settings.ts +++ b/frontend/src/hooks/query/use-settings.ts @@ -19,7 +19,6 @@ const getSettingsQueryFn = async () => { LLM_API_KEY: apiSettings.llm_api_key, REMOTE_RUNTIME_RESOURCE_FACTOR: apiSettings.remote_runtime_resource_factor, TOKEN_IS_SET: apiSettings.token_is_set, - TOKEN_TYPE: apiSettings.token_type, ENABLE_DEFAULT_CONDENSER: apiSettings.enable_default_condenser, ENABLE_SOUND_NOTIFICATIONS: apiSettings.enable_sound_notifications, USER_CONSENTS_TO_ANALYTICS: apiSettings.user_consents_to_analytics, diff --git a/frontend/src/hooks/query/use-user-repositories.ts b/frontend/src/hooks/query/use-user-repositories.ts index 0dfc24e6b53a..c1136650dff0 100644 --- a/frontend/src/hooks/query/use-user-repositories.ts +++ b/frontend/src/hooks/query/use-user-repositories.ts @@ -5,16 +5,16 @@ import { useConfig } from "./use-config"; import { useAuth } from "#/context/auth-context"; export const useUserRepositories = () => { - const { githubTokenIsSet } = useAuth(); + const { tokenIsSet } = useAuth(); const { data: config } = useConfig(); const repos = useInfiniteQuery({ - queryKey: ["repositories", githubTokenIsSet], + queryKey: ["repositories", tokenIsSet], queryFn: async ({ pageParam }) => retrieveGitHubUserRepositories(pageParam, 100), initialPageParam: 1, getNextPageParam: (lastPage) => lastPage.nextPage, - enabled: githubTokenIsSet && config?.APP_MODE === "oss", + enabled: tokenIsSet && config?.APP_MODE === "oss", }); // TODO: Once we create our custom dropdown component, we should fetch data onEndReached diff --git a/frontend/src/hooks/use-github-auth-url.ts b/frontend/src/hooks/use-github-auth-url.ts index b058913b613d..c38c1da80063 100644 --- a/frontend/src/hooks/use-github-auth-url.ts +++ b/frontend/src/hooks/use-github-auth-url.ts @@ -9,15 +9,15 @@ interface UseGitHubAuthUrlConfig { } export const useGitHubAuthUrl = (config: UseGitHubAuthUrlConfig) => { - const { githubTokenIsSet } = useAuth(); + const { tokenIsSet } = useAuth(); return React.useMemo(() => { - if (config.appMode === "saas" && !githubTokenIsSet) + if (config.appMode === "saas" && !tokenIsSet) return generateGitHubAuthUrl( config.gitHubClientId || "", new URL(window.location.href), ); return null; - }, [githubTokenIsSet, config.appMode, config.gitHubClientId]); + }, [tokenIsSet, config.appMode, config.gitHubClientId]); }; diff --git a/frontend/src/mocks/handlers.ts b/frontend/src/mocks/handlers.ts index 25c09e72a305..036628f0b1f3 100644 --- a/frontend/src/mocks/handlers.ts +++ b/frontend/src/mocks/handlers.ts @@ -19,7 +19,6 @@ export const MOCK_DEFAULT_USER_SETTINGS: ApiSettings | PostApiSettings = { remote_runtime_resource_factor: DEFAULT_SETTINGS.REMOTE_RUNTIME_RESOURCE_FACTOR, token_is_set: DEFAULT_SETTINGS.TOKEN_IS_SET, - token_type: DEFAULT_SETTINGS.TOKEN_TYPE, enable_default_condenser: DEFAULT_SETTINGS.ENABLE_DEFAULT_CONDENSER, enable_sound_notifications: DEFAULT_SETTINGS.ENABLE_SOUND_NOTIFICATIONS, user_consents_to_analytics: DEFAULT_SETTINGS.USER_CONSENTS_TO_ANALYTICS, @@ -204,7 +203,6 @@ export const handlers = [ if (newSettings.unset_token) { newSettings.token = undefined; newSettings.token_is_set = false; - newSettings.token_type = undefined; delete newSettings.unset_token; } } diff --git a/frontend/src/routes/_oh/route.tsx b/frontend/src/routes/_oh/route.tsx index 55ec6b783836..b495306f235c 100644 --- a/frontend/src/routes/_oh/route.tsx +++ b/frontend/src/routes/_oh/route.tsx @@ -44,7 +44,7 @@ export function ErrorBoundary() { } export default function MainApp() { - const { githubTokenIsSet } = useAuth(); + const { tokenIsSet } = useAuth(); const { data: settings } = useSettings(); const { migrateUserConsent } = useMigrateUserConsent(); @@ -104,7 +104,7 @@ export default function MainApp() { {renderWaitlistModal && ( )} diff --git a/frontend/src/routes/account-settings.tsx b/frontend/src/routes/account-settings.tsx index e3de6c648406..59b070c79688 100644 --- a/frontend/src/routes/account-settings.tsx +++ b/frontend/src/routes/account-settings.tsx @@ -109,8 +109,7 @@ function AccountSettings() { saveSettings( { - token: - formData.get("token-input")?.toString() || undefined, + token: formData.get("token-input")?.toString() || undefined, LANGUAGE: languageValue, user_consents_to_analytics: userConsentsToAnalytics, ENABLE_DEFAULT_CONDENSER: enableMemoryCondenser, @@ -347,13 +346,11 @@ function AccountSettings() { - ) + isTokenSet && } placeholder={isTokenSet ? "**********" : ""} /> diff --git a/frontend/src/services/settings.ts b/frontend/src/services/settings.ts index 7253be51a5c9..b2f4c9425187 100644 --- a/frontend/src/services/settings.ts +++ b/frontend/src/services/settings.ts @@ -12,7 +12,6 @@ export const DEFAULT_SETTINGS: Settings = { SECURITY_ANALYZER: "", REMOTE_RUNTIME_RESOURCE_FACTOR: 1, TOKEN_IS_SET: false, - TOKEN_TYPE: null, ENABLE_DEFAULT_CONDENSER: true, ENABLE_SOUND_NOTIFICATIONS: false, USER_CONSENTS_TO_ANALYTICS: false, diff --git a/frontend/src/types/core/variances.ts b/frontend/src/types/core/variances.ts index bf2baab601df..0492588c5cf9 100644 --- a/frontend/src/types/core/variances.ts +++ b/frontend/src/types/core/variances.ts @@ -21,7 +21,6 @@ export interface InitConfig { LLM_MODEL: string; }; token?: string; - token_type?: 'github' | 'gitlab'; latest_event_id?: unknown; // Not sure what this is } diff --git a/frontend/src/types/settings.ts b/frontend/src/types/settings.ts index 6c96df72995f..77fcfe82866a 100644 --- a/frontend/src/types/settings.ts +++ b/frontend/src/types/settings.ts @@ -8,7 +8,6 @@ export type Settings = { SECURITY_ANALYZER: string; REMOTE_RUNTIME_RESOURCE_FACTOR: number | null; TOKEN_IS_SET: boolean; - TOKEN_TYPE: 'github' | 'gitlab' | null; ENABLE_DEFAULT_CONDENSER: boolean; ENABLE_SOUND_NOTIFICATIONS: boolean; USER_CONSENTS_TO_ANALYTICS: boolean | null; @@ -24,7 +23,6 @@ export type ApiSettings = { security_analyzer: string; remote_runtime_resource_factor: number | null; token_is_set: boolean; - token_type: 'github' | 'gitlab' | null; enable_default_condenser: boolean; enable_sound_notifications: boolean; user_consents_to_analytics: boolean | null; @@ -32,14 +30,12 @@ export type ApiSettings = { export type PostSettings = Settings & { token: string; - token_type: 'github' | 'gitlab' | null; unset_token: boolean; user_consents_to_analytics: boolean | null; }; export type PostApiSettings = ApiSettings & { token: string; - token_type: 'github' | 'gitlab' | null; unset_token: boolean; user_consents_to_analytics: boolean | null; }; diff --git a/frontend/test-utils.tsx b/frontend/test-utils.tsx index d39ced887a39..3f9e8b1e96bc 100644 --- a/frontend/test-utils.tsx +++ b/frontend/test-utils.tsx @@ -66,7 +66,7 @@ export function renderWithProviders( function Wrapper({ children }: PropsWithChildren) { return ( - + GETSettingsModel | None: settings_with_token_data.llm_api_key = settings.llm_api_key del settings_with_token_data.token + del settings_with_token_data.token_type return settings_with_token_data except Exception as e: logger.warning(f'Invalid token: {e}') @@ -128,6 +129,6 @@ def convert_to_settings(settings_with_token_data: POSTSettingsModel) -> Settings # Convert the `llm_api_key` and `github_token` to a `SecretStr` instance filtered_settings_data['llm_api_key'] = settings_with_token_data.llm_api_key - filtered_settings_data['github_token'] = settings_with_token_data.github_token + filtered_settings_data['token'] = settings_with_token_data.token return Settings(**filtered_settings_data)