Skip to content

Personal AI, On Personal Devices

Python

fix: run Google OAuth flow in background thread to prevent server freeze

Jon Saad-Falcon53a20fde3019
diff --git a/src/openjarvis/agents/deep_research.py b/src/openjarvis/agents/deep_research.py
index 9724e575..6dd81c32 100644
--- a/src/openjarvis/agents/deep_research.py
+++ b/src/openjarvis/agents/deep_research.py
@@ -122,6 +122,8 @@ class DeepResearchAgent(ToolUsingAgent):
max_tokens: Optional[int] = None,
interactive: bool = False,
confirm_callback=None,
+ system_prompt: Optional[str] = None,
+ **kwargs: Any,
) -> None:
super().__init__(
engine,
diff --git a/src/openjarvis/connectors/gcalendar.py b/src/openjarvis/connectors/gcalendar.py
index 46ed89ee..5b7a85c3 100644
--- a/src/openjarvis/connectors/gcalendar.py
+++ b/src/openjarvis/connectors/gcalendar.py
@@ -251,22 +251,27 @@ class GCalendarConnector(BaseConnector):
# If user pastes client_id:client_secret, store and run OAuth flow
if ":" in code and ".apps.googleusercontent.com" in code:
client_id, client_secret = code.split(":", 1)
- try:
- run_oauth_flow(
- client_id=client_id.strip(),
- client_secret=client_secret.strip(),
- scopes=[_GCAL_SCOPE],
- credentials_path=self._credentials_path,
- )
- except Exception: # noqa: BLE001
- # Fallback: just save the credentials for later
- save_tokens(
- self._credentials_path,
- {
- "client_id": client_id.strip(),
- "client_secret": client_secret.strip(),
- },
- )
+ save_tokens(
+ self._credentials_path,
+ {
+ "client_id": client_id.strip(),
+ "client_secret": client_secret.strip(),
+ },
+ )
+ import threading
+
+ def _run() -> None:
+ try:
+ run_oauth_flow(
+ client_id=client_id.strip(),
+ client_secret=client_secret.strip(),
+ scopes=[_GCAL_SCOPE],
+ credentials_path=self._credentials_path,
+ )
+ except Exception: # noqa: BLE001
+ pass
+
+ threading.Thread(target=_run, daemon=True).start()
else:
# Raw token or auth code
save_tokens(self._credentials_path, {"token": code})
diff --git a/src/openjarvis/connectors/gcontacts.py b/src/openjarvis/connectors/gcontacts.py
index 5715e2a3..88350b65 100644
--- a/src/openjarvis/connectors/gcontacts.py
+++ b/src/openjarvis/connectors/gcontacts.py
@@ -198,22 +198,27 @@ class GContactsConnector(BaseConnector):
# If user pastes client_id:client_secret, store and run OAuth flow
if ":" in code and ".apps.googleusercontent.com" in code:
client_id, client_secret = code.split(":", 1)
- try:
- run_oauth_flow(
- client_id=client_id.strip(),
- client_secret=client_secret.strip(),
- scopes=[_GCONTACTS_SCOPE],
- credentials_path=self._credentials_path,
- )
- except Exception: # noqa: BLE001
- # Fallback: just save the credentials for later
- save_tokens(
- self._credentials_path,
- {
- "client_id": client_id.strip(),
- "client_secret": client_secret.strip(),
- },
- )
+ save_tokens(
+ self._credentials_path,
+ {
+ "client_id": client_id.strip(),
+ "client_secret": client_secret.strip(),
+ },
+ )
+ import threading
+
+ def _run() -> None:
+ try:
+ run_oauth_flow(
+ client_id=client_id.strip(),
+ client_secret=client_secret.strip(),
+ scopes=[_GCONTACTS_SCOPE],
+ credentials_path=self._credentials_path,
+ )
+ except Exception: # noqa: BLE001
+ pass
+
+ threading.Thread(target=_run, daemon=True).start()
else:
# Raw token or auth code
save_tokens(self._credentials_path, {"token": code})
diff --git a/src/openjarvis/connectors/gdrive.py b/src/openjarvis/connectors/gdrive.py
index e979ff35..19e912a1 100644
--- a/src/openjarvis/connectors/gdrive.py
+++ b/src/openjarvis/connectors/gdrive.py
@@ -181,22 +181,29 @@ class GDriveConnector(BaseConnector):
# If user pastes client_id:client_secret, store and run OAuth flow
if ":" in code and ".apps.googleusercontent.com" in code:
client_id, client_secret = code.split(":", 1)
- try:
- run_oauth_flow(
- client_id=client_id.strip(),
- client_secret=client_secret.strip(),
- scopes=[_GDRIVE_SCOPE],
- credentials_path=self._credentials_path,
- )
- except Exception: # noqa: BLE001
- # Fallback: just save the credentials for later
- save_tokens(
- self._credentials_path,
- {
- "client_id": client_id.strip(),
- "client_secret": client_secret.strip(),
- },
- )
+ # Save credentials immediately
+ save_tokens(
+ self._credentials_path,
+ {
+ "client_id": client_id.strip(),
+ "client_secret": client_secret.strip(),
+ },
+ )
+ # Run OAuth flow in background thread to avoid blocking
+ import threading
+
+ def _run() -> None:
+ try:
+ run_oauth_flow(
+ client_id=client_id.strip(),
+ client_secret=client_secret.strip(),
+ scopes=[_GDRIVE_SCOPE],
+ credentials_path=self._credentials_path,
+ )
+ except Exception: # noqa: BLE001
+ pass
+
+ threading.Thread(target=_run, daemon=True).start()
else:
# Raw token or auth code
save_tokens(self._credentials_path, {"token": code})