The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(browser): strict cloud-provider selection; camofox becomes a selection
Teknium7f83d3808c13
diff --git a/plugins/browser/browser_use/provider.py b/plugins/browser/browser_use/provider.pyindex f4008d440c0..bfc2709e5e2 100644--- a/plugins/browser/browser_use/provider.py+++ b/plugins/browser/browser_use/provider.py@@ -134,37 +134,74 @@ class BrowserUseBrowserProvider(BrowserProvider):peek_nous_access_token,resolve_managed_tool_gateway,)- from tools.tool_backend_helpers import prefers_gateway+ from tools.tool_backend_helpers import (+ NOUS_MANAGED_PROVIDER,+ read_selection,+ )++ def _managed_config() -> Optional[Dict[str, Any]]:+ # Keep availability scans off the synchronous OAuth refresh path.+ managed = resolve_managed_tool_gateway(+ "browser-use",+ token_reader=None if refresh_token else peek_nous_access_token,+ )+ if managed is None:+ return None+ return {+ "api_key": managed.nous_user_token,+ "base_url": managed.gateway_origin.rstrip("/"),+ "managed_mode": True,+ }- # Direct API key wins unless the user has explicitly opted into the- # managed Nous gateway via ``tool_gateway.browser: gateway``.api_key = get_secret("BROWSER_USE_API_KEY")- if api_key and not prefers_gateway("browser"):+ selected = read_selection("browser")++ # Strict selection: "nous" (or legacy use_gateway: true) → managed+ # gateway ONLY; any other stored browser selection → direct API key+ # ONLY (no silent managed fallback); never-configured → legacy+ # behavior (direct key when present, else managed gateway).+ if selected == NOUS_MANAGED_PROVIDER:+ return _managed_config()+ if selected is not None:+ if api_key:+ return {+ "api_key": api_key,+ "base_url": _BASE_URL,+ "managed_mode": False,+ }+ return None+ if api_key:return {"api_key": api_key,"base_url": _BASE_URL,"managed_mode": False,}-- # Keep availability scans off the synchronous OAuth refresh path.- managed = resolve_managed_tool_gateway(- "browser-use",- token_reader=None if refresh_token else peek_nous_access_token,- )- if managed is None:- return None-- return {- "api_key": managed.nous_user_token,- "base_url": managed.gateway_origin.rstrip("/"),- "managed_mode": True,- }+ return _managed_config()def _get_config(self) -> Dict[str, Any]:- from tools.tool_backend_helpers import managed_nous_tools_enabled+ from tools.tool_backend_helpers import (+ NOUS_MANAGED_PROVIDER,+ managed_nous_tools_enabled,+ read_selection,+ selection_error,+ )config = self._get_config_or_none()if config is None:+ selected = read_selection("browser")+ if selected == NOUS_MANAGED_PROVIDER:+ raise ValueError(selection_error(+ "browser",+ NOUS_MANAGED_PROVIDER,+ "the Nous Tool Gateway is not available (not entitled or "+ "unreachable)",+ ))+ if selected is not None:+ raise ValueError(selection_error(+ "browser",+ selected,+ "BROWSER_USE_API_KEY is not set",+ ))message = ("Browser Use requires a direct BROWSER_USE_API_KEY credential.")diff --git a/tools/browser_camofox.py b/tools/browser_camofox.pyindex ef68112f55e..432ca85f0b3 100644--- a/tools/browser_camofox.py+++ b/tools/browser_camofox.py@@ -113,21 +113,39 @@ def _config_cdp_url() -> str:def is_camofox_mode() -> bool:- """True when Camofox backend is configured and no CDP override is active.+ """True when the Camofox backend is selected and no CDP override is active.++ Camofox is a selection: ``browser.cloud_provider: camofox`` (set via+ ``hermes tools``). ``CAMOFOX_URL`` is the server ADDRESS only — its+ presence no longer selects the backend when a different+ ``browser.cloud_provider`` is stored. Legacy read-time interpretation:+ when NO cloud provider selection was ever written, a set ``CAMOFOX_URL``+ keeps activating Camofox exactly as before (nothing is migrated/written+ to config).A CDP override takes priority over Camofox so the browser tools operate onthe real CDP browser (and a CDP backend is treated as non-local for SSRFchecks) instead of being silently routed to Camofox. The override may comefrom the ``BROWSER_CDP_URL`` env var (set by ``/browser connect``) OR apersistent ``browser.cdp_url`` in config.yaml — both are honored, matching- ``browser_tool._get_cdp_override()``'s precedence. (Previously only the env- var suppressed Camofox, so ``CAMOFOX_URL`` + a config CDP override still- routed navigation through Camofox.)+ ``browser_tool._get_cdp_override()``'s precedence."""if os.getenv("BROWSER_CDP_URL", "").strip():return Falseif _config_cdp_url():return False+ try:+ from tools.tool_backend_helpers import read_selection++ selected = read_selection("browser")+ except Exception: # pragma: no cover — helpers are in-repo+ selected = None+ if selected == "camofox":+ return True+ if selected is not None:+ # An explicit different browser selection wins: CAMOFOX_URL is just+ # an address, not a choice.+ return Falsereturn bool(get_camofox_url())diff --git a/tools/browser_tool.py b/tools/browser_tool.pyindex 544a06d5127..34f38baa1e8 100644--- a/tools/browser_tool.py+++ b/tools/browser_tool.py@@ -815,19 +815,26 @@ def _resolve_cloud_provider_uncached() -> Optional[CloudBrowserProvider]:global _cached_cloud_provider, _cloud_provider_resolvedresolved: Optional[CloudBrowserProvider] = None+ provider_key = Nonetry:from hermes_cli.config import read_raw_configcfg = read_raw_config()browser_cfg = cfg.get("browser", {})- provider_key = Noneif isinstance(browser_cfg, dict) and "cloud_provider" in browser_cfg:provider_key = normalize_browser_cloud_provider(browser_cfg.get("cloud_provider"))- if provider_key == "local":+ if provider_key in ("local", "camofox"):+ # Camofox runs through the built-in browser tools+ # (is_camofox_mode() dispatch), not a cloud provider._cached_cloud_provider = None_cloud_provider_resolved = Truereturn None+ if provider_key == "nous":+ # Managed "Nous Subscription" selection is serviced by the+ # Browser Use provider, whose config resolver routes it+ # through the managed browser-use gateway.+ provider_key = "browser-use"if provider_key:try:if _is_legacy_provider_registry_overridden():@@ -841,20 +848,20 @@ def _resolve_cloud_provider_uncached() -> Optional[CloudBrowserProvider]:# populated. Idempotent — cheap on subsequent calls._ensure_browser_plugins_loaded()resolved = _registry_get_browser_provider(provider_key)- if resolved is None:- # Explicit config name unknown to the registry —- # might be a typo, an uninstalled plugin, or a- # registry-population failure. Warn the user- # (legacy code would have surfaced a typed- # credentials error via direct class instantiation;- # post-migration we surface this WARNING instead).- logger.warning(- "browser.cloud_provider=%r is not a registered "- "browser plugin; falling back to auto-detect "- "(install the corresponding plugin or fix the "- "config key spelling).",- provider_key,- )+ if resolved is None:+ # Strict selection: a stored-but-unregistered name is an+ # honest error, never a silent reroute to auto-detect.+ from tools.tool_backend_helpers import selection_error++ raise ValueError(selection_error(+ "browser",+ f"'{provider_key}'",+ "no registered browser plugin has that name (install "+ "the corresponding plugin or fix the config key "+ "spelling)",+ ))+ except ValueError:+ raiseexcept Exception:logger.warning("Failed to instantiate explicit cloud_provider %r; will retry on next call",@@ -862,13 +869,16 @@ def _resolve_cloud_provider_uncached() -> Optional[CloudBrowserProvider]:exc_info=True,)return None+ except ValueError:+ raiseexcept Exception as e:# Config file may be temporarily unreadable; still try auto-detect so# env-based / managed-gateway credentials can resolve. Don't pin cache.logger.debug("Could not read cloud_provider from config: %s", e)- if resolved is None:- # Auto-detect path: Browser Use first (managed Nous gateway or+ if resolved is None and provider_key is None:+ # Auto-detect path — permitted ONLY when no cloud_provider selection+ # was ever written: Browser Use first (managed Nous gateway or# direct API key), then Browserbase (direct credentials). Uses# the legacy class names imported at the top of this module so# tests that ``monkeypatch.setattr(browser_tool, "BrowserUseProvider", ...)``