π OpenHands: AI-Driven Development
Move GitHub Token export to backend (#6153)
Robert Brennanc411a29db408
diff --git a/frontend/src/routes/_oh.app/hooks/use-handle-runtime-active.ts b/frontend/src/routes/_oh.app/hooks/use-handle-runtime-active.tsindex 1165127e24..246d3794ad 100644--- a/frontend/src/routes/_oh.app/hooks/use-handle-runtime-active.ts+++ b/frontend/src/routes/_oh.app/hooks/use-handle-runtime-active.ts@@ -1,24 +1,16 @@import React from "react";import toast from "react-hot-toast";import { useDispatch, useSelector } from "react-redux";-import { useAuth } from "#/context/auth-context";-import { useWsClient } from "#/context/ws-client-provider";-import { getGitHubTokenCommand } from "#/services/terminal-service";import { setImportedProjectZip } from "#/state/initial-query-slice";import { RootState } from "#/store";import { base64ToBlob } from "#/utils/base64-to-blob";import { useUploadFiles } from "../../../hooks/mutation/use-upload-files";-import { useGitHubUser } from "../../../hooks/query/use-github-user";-import { isGitHubErrorReponse } from "#/api/github-axios-instance";+import { RUNTIME_INACTIVE_STATES } from "#/types/agent-state";export const useHandleRuntimeActive = () => {- const { gitHubToken } = useAuth();- const { send } = useWsClient();-const dispatch = useDispatch();- const { data: user } = useGitHubUser();const { mutate: uploadFiles } = useUploadFiles();const { curAgentState } = useSelector((state: RootState) => state.agent);@@ -28,11 +20,6 @@ export const useHandleRuntimeActive = () => {(state: RootState) => state.initialQuery,);- const userId = React.useMemo(() => {- if (user && !isGitHubErrorReponse(user)) return user.id;- return null;- }, [user]);-const handleUploadFiles = (zip: string) => {const blob = base64ToBlob(zip);const file = new File([blob], "imported-project.zip", {@@ -49,13 +36,6 @@ export const useHandleRuntimeActive = () => {dispatch(setImportedProjectZip(null));};- React.useEffect(() => {- if (runtimeActive && userId && gitHubToken) {- // Export if the user valid, this could happen mid-session so it is handled here- send(getGitHubTokenCommand(gitHubToken));- }- }, [userId, gitHubToken, runtimeActive]);-React.useEffect(() => {if (runtimeActive && importedProjectZip) {handleUploadFiles(importedProjectZip);diff --git a/frontend/src/services/terminal-service.ts b/frontend/src/services/terminal-service.tsindex c5807596b6..9ef1cdf151 100644--- a/frontend/src/services/terminal-service.ts+++ b/frontend/src/services/terminal-service.ts@@ -4,9 +4,3 @@ export function getTerminalCommand(command: string, hidden: boolean = false) {const event = { action: ActionType.RUN, args: { command, hidden } };return event;}--export function getGitHubTokenCommand(gitHubToken: string) {- const command = `export GITHUB_TOKEN=${gitHubToken}`;- const event = getTerminalCommand(command, true);- return event;-}diff --git a/openhands/runtime/impl/remote/remote_runtime.py b/openhands/runtime/impl/remote/remote_runtime.pyindex cc2fdbf939..cc9fae9e88 100644--- a/openhands/runtime/impl/remote/remote_runtime.py+++ b/openhands/runtime/impl/remote/remote_runtime.py@@ -249,6 +249,8 @@ class RemoteRuntime(ActionExecutionClient):timeout=60,):pass+ self._wait_until_alive()+ self.setup_initial_env()self.log('debug', 'Runtime resumed.')def _parse_runtime_response(self, response: requests.Response):@@ -388,7 +390,6 @@ class RemoteRuntime(ActionExecutionClient):elif e.response.status_code == 503:self.log('warning', 'Runtime appears to be paused. Resuming...')self._resume_runtime()- self._wait_until_alive()return super()._send_action_server_request(method, url, **kwargs)else:raise ediff --git a/openhands/server/session/agent_session.py b/openhands/server/session/agent_session.pyindex b8a440d32f..f7ffbaecad 100644--- a/openhands/server/session/agent_session.py+++ b/openhands/server/session/agent_session.py@@ -180,6 +180,13 @@ class AgentSession:logger.debug(f'Initializing runtime `{runtime_name}` now...')runtime_cls = get_runtime_cls(runtime_name)+ env_vars = (+ {+ 'GITHUB_TOKEN': github_token,+ }+ if github_token+ else None+ )self.runtime = runtime_cls(config=config,event_stream=self.event_stream,@@ -187,6 +194,7 @@ class AgentSession:plugins=agent.sandbox_plugins,status_callback=self._status_callback,headless_mode=False,+ env_vars=env_vars,)# FIXME: this sleep is a terrible hack.