Skip to content

πŸ™Œ OpenHands: AI-Driven Development

[ALL-571] chore(frontend): Move `saas`-related configs to `config.json` (#4496)

sp.wack6fe5482b209c
diff --git a/frontend/.env.sample b/frontend/.env.sample
index 9d6bf87a70..ff98ab15aa 100644
--- a/frontend/.env.sample
+++ b/frontend/.env.sample
@@ -1,5 +1,2 @@
VITE_BACKEND_BASE_URL="localhost:3000" # Backend URL without protocol (e.g. localhost:3000)
VITE_MOCK_API="false" # true or false
-
-# GitHub OAuth
-VITE_GITHUB_CLIENT_ID=""
diff --git a/frontend/global.d.ts b/frontend/global.d.ts
index e71757d809..f3ad7483ea 100644
--- a/frontend/global.d.ts
+++ b/frontend/global.d.ts
@@ -1,3 +1,4 @@
interface Window {
__APP_MODE__?: "saas" | "oss";
+ __GITHUB_CLIENT_ID__?: string | null;
}
diff --git a/frontend/public/config.json b/frontend/public/config.json
index bdc29014a4..49dd5e4362 100644
--- a/frontend/public/config.json
+++ b/frontend/public/config.json
@@ -1,3 +1,4 @@
{
- "APP_MODE": "oss"
+ "APP_MODE": "oss",
+ "GITHUB_CLIENT_ID": ""
}
diff --git a/frontend/src/api/open-hands.ts b/frontend/src/api/open-hands.ts
index 0dd4199840..25a0c82c25 100644
--- a/frontend/src/api/open-hands.ts
+++ b/frontend/src/api/open-hands.ts
@@ -6,6 +6,7 @@ import {
FeedbackResponse,
GitHubAccessTokenResponse,
ErrorResponse,
+ GetConfigResponse,
} from "./open-hands.types";
/**
@@ -60,7 +61,7 @@ class OpenHands {
return response.json();
}
- static async getConfig(): Promise<{ APP_MODE: "saas" | "oss" }> {
+ static async getConfig(): Promise<GetConfigResponse> {
const response = await fetch(`${OpenHands.BASE_URL}/config.json`, {
headers: {
"Cache-Control": "no-cache",
diff --git a/frontend/src/api/open-hands.types.ts b/frontend/src/api/open-hands.types.ts
index 63edc9b034..ba0e8642bc 100644
--- a/frontend/src/api/open-hands.types.ts
+++ b/frontend/src/api/open-hands.types.ts
@@ -35,3 +35,8 @@ export interface Feedback {
permissions: "public" | "private";
trajectory: unknown[];
}
+
+export interface GetConfigResponse {
+ APP_MODE: "saas" | "oss";
+ GITHUB_CLIENT_ID: string | null;
+}
diff --git a/frontend/src/components/modals/connect-to-github-modal.tsx b/frontend/src/components/modals/connect-to-github-modal.tsx
index 708dbc21c9..e0315d14c8 100644
--- a/frontend/src/components/modals/connect-to-github-modal.tsx
+++ b/frontend/src/components/modals/connect-to-github-modal.tsx
@@ -26,7 +26,7 @@ export function ConnectToGitHubModal({ onClose }: ConnectToGitHubModalProps) {
<span>
Get your token{" "}
<a
- href="https://github.com/settings/tokens/new?description=openhands-app&scopes=repo,user"
+ href="https://github.com/settings/tokens/new?description=openhands-app&scopes=repo,user,workflow"
target="_blank"
rel="noreferrer noopener"
className="text-[#791B80] underline"
diff --git a/frontend/src/routes/_oh._index/route.tsx b/frontend/src/routes/_oh._index/route.tsx
index ed69ae98f1..473b71976f 100644
--- a/frontend/src/routes/_oh._index/route.tsx
+++ b/frontend/src/routes/_oh._index/route.tsx
@@ -82,10 +82,13 @@ export const clientLoader = async ({ request }: ClientLoaderFunctionArgs) => {
}
}
- const clientId = import.meta.env.VITE_GITHUB_CLIENT_ID;
- const requestUrl = new URL(request.url);
- const redirectUri = `${requestUrl.origin}/oauth/github/callback`;
- const githubAuthUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&scope=repo,user,workflow`;
+ let githubAuthUrl: string | null = null;
+ if (window.__APP_MODE__ === "saas") {
+ const clientId = window.__GITHUB_CLIENT_ID__;
+ const requestUrl = new URL(request.url);
+ const redirectUri = `${requestUrl.origin}/oauth/github/callback`;
+ githubAuthUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&scope=repo,user,workflow`;
+ }
return json({ repositories, githubAuthUrl });
};
@@ -110,9 +113,7 @@ function Home() {
const { files } = useSelector((state: RootState) => state.initalQuery);
const handleConnectToGitHub = () => {
- const isSaas = window.__APP_MODE__ === "saas";
-
- if (isSaas) {
+ if (githubAuthUrl) {
window.location.href = githubAuthUrl;
} else {
setConnectToGitHubModalOpen(true);
diff --git a/frontend/src/routes/_oh.tsx b/frontend/src/routes/_oh.tsx
index 13913380ea..573cb0dc5f 100644
--- a/frontend/src/routes/_oh.tsx
+++ b/frontend/src/routes/_oh.tsx
@@ -29,8 +29,10 @@ export const clientLoader = async () => {
try {
const config = await OpenHands.getConfig();
window.__APP_MODE__ = config.APP_MODE;
+ window.__GITHUB_CLIENT_ID__ = config.GITHUB_CLIENT_ID;
} catch (error) {
window.__APP_MODE__ = "oss";
+ window.__GITHUB_CLIENT_ID__ = null;
}
let token = localStorage.getItem("token");