Agent Zero AI framework
Expose Browser runtime selection to CLI
Alessandro229de5166b96
diff --git a/plugins/_a0_connector/api/v1/browser_runtime.py b/plugins/_a0_connector/api/v1/browser_runtime.pynew file mode 100644index 000000000..62a875427--- /dev/null+++ b/plugins/_a0_connector/api/v1/browser_runtime.py@@ -0,0 +1,98 @@+"""POST /api/plugins/_a0_connector/v1/browser_runtime."""+from __future__ import annotations++from helpers.api import Request, Response+import plugins._a0_connector.api.v1.base as connector_base+++_PRIVACY_NOTICE = (+ "For GDPR/content policy, visit Agent Zero WebUI > Browser settings to choose "+ "Local models only, Warn when using cloud, or Allow."+)+++def _string(value: object) -> str:+ return str(value or "").strip()+++def _normalize_requested_backend(value: object) -> str:+ normalized = _string(value).lower().replace("-", "_").replace(" ", "_")+ if normalized in {"container", "docker", "docker_container"}:+ return "container"+ if normalized in {"host", "host_required", "byob", "bring_your_own_browser"}:+ return "host_required"+ return ""+++def _runtime_label(value: str) -> str:+ if value == "host_required":+ return "Bring Your Own Browser"+ return "Docker browser"+++class BrowserRuntime(connector_base.ProtectedConnectorApiHandler):+ async def process(self, input: dict, request: Request) -> dict | Response:+ action = _string(input.get("action")).lower() or "get"+ if action not in {"get", "set"}:+ return Response(+ response='{"error":"Unsupported action"}',+ status=400,+ mimetype="application/json",+ )++ try:+ project_name = self._project_name_for_context(_string(input.get("context_id")))+ except LookupError:+ return Response(+ response='{"error":"Context not found"}',+ status=404,+ mimetype="application/json",+ )++ settings = self._load_browser_config(project_name)+ if action == "set":+ runtime_backend = _normalize_requested_backend(input.get("runtime_backend"))+ if not runtime_backend:+ return Response(+ response='{"error":"runtime_backend must be host or container"}',+ status=400,+ mimetype="application/json",+ )+ settings["runtime_backend"] = runtime_backend+ self._save_browser_config(project_name, settings)++ return {+ "ok": True,+ "runtime_backend": settings["runtime_backend"],+ "label": _runtime_label(settings["runtime_backend"]),+ "project_name": project_name,+ "agent_profile": "",+ "privacy_notice": _PRIVACY_NOTICE,+ }++ def _project_name_for_context(self, context_id: str) -> str:+ if not context_id:+ return ""++ from agent import AgentContext+ from helpers import projects++ context = AgentContext.get(context_id)+ if context is None:+ raise LookupError(context_id)+ return projects.get_context_project_name(context) or ""++ def _load_browser_config(self, project_name: str) -> dict:+ from helpers import plugins+ from plugins._browser.helpers.config import PLUGIN_NAME, normalize_browser_config++ return normalize_browser_config(+ plugins.get_plugin_config(PLUGIN_NAME, project_name=project_name, agent_profile="")+ or {}+ )++ def _save_browser_config(self, project_name: str, settings: dict) -> None:+ from helpers import plugins+ from plugins._browser.helpers.config import PLUGIN_NAME++ plugins.save_plugin_config(PLUGIN_NAME, project_name, "", settings)diff --git a/plugins/_a0_connector/api/v1/capabilities.py b/plugins/_a0_connector/api/v1/capabilities.pyindex 3dca2a297..902bca1c1 100644--- a/plugins/_a0_connector/api/v1/capabilities.py+++ b/plugins/_a0_connector/api/v1/capabilities.py@@ -37,6 +37,7 @@ _OPTIONAL_FEATURES: dict[str, tuple[str, ...]] = {"skills_delete": ("helpers.skills", "helpers.files", "helpers.projects", "helpers.runtime"),"model_presets": ("plugins._model_config.helpers.model_config",),"model_switcher": ("plugins._model_config.helpers.model_config",),+ "browser_runtime_config": ("plugins._browser.helpers.config", "helpers.plugins"),"compact_chat": ("plugins._chat_compaction.helpers.compactor","plugins._model_config.helpers.model_config",diff --git a/plugins/_browser/helpers/config.py b/plugins/_browser/helpers/config.pyindex 8bea56bba..f3e2b55ec 100644--- a/plugins/_browser/helpers/config.py+++ b/plugins/_browser/helpers/config.py@@ -13,7 +13,7 @@ DEFAULT_HOMEPAGE_KEY = "default_homepage"AUTOFOCUS_ACTIVE_PAGE_KEY = "autofocus_active_page"RUNTIME_BACKEND_KEY = "runtime_backend"HOST_BROWSER_PRIVACY_POLICY_KEY = "host_browser_privacy_policy"-RUNTIME_BACKENDS = {"container", "host_when_available", "host_required"}+RUNTIME_BACKENDS = {"container", "host_required"}HOST_BROWSER_PRIVACY_POLICIES = {"enforce_local", "warn", "allow"}BASE_BROWSER_ARGS = ["--no-sandbox",@@ -75,6 +75,13 @@ def _normalize_choice(value: Any, *, allowed: set[str], default: str) -> str:return default+def _normalize_runtime_backend(value: Any) -> str:+ normalized = str(value or "").strip().lower().replace("-", "_")+ if normalized == "host_when_available":+ return "host_required"+ return _normalize_choice(normalized, allowed=RUNTIME_BACKENDS, default="container")++def _model_config_summary(config: dict[str, Any] | None) -> str:if not isinstance(config, dict):return ""@@ -95,10 +102,8 @@ def normalize_browser_config(settings: dict[str, Any] | None) -> dict[str, Any]:raw.get(AUTOFOCUS_ACTIVE_PAGE_KEY, True),default=True,),- RUNTIME_BACKEND_KEY: _normalize_choice(- raw.get(RUNTIME_BACKEND_KEY, "container"),- allowed=RUNTIME_BACKENDS,- default="container",+ RUNTIME_BACKEND_KEY: _normalize_runtime_backend(+ raw.get(RUNTIME_BACKEND_KEY, "container")),HOST_BROWSER_PRIVACY_POLICY_KEY: _normalize_choice(raw.get(HOST_BROWSER_PRIVACY_POLICY_KEY, "enforce_local"),diff --git a/plugins/_browser/webui/config.html b/plugins/_browser/webui/config.htmlindex 509d15a9e..7da0bea68 100644--- a/plugins/_browser/webui/config.html+++ b/plugins/_browser/webui/config.html@@ -15,41 +15,6 @@x-effect="$store.browserConfig.bindConfig(config)"x-destroy="$store.browserConfig.cleanup()">- <div class="browser-config-card">- <div class="section-title">Browsing</div>- <div class="section-description">- Set how new Browser sessions start and how an already-open Browser surface follows agent activity.- </div>-- <label class="browser-config-field">- <span class="browser-config-field-label">Starting page</span>- <input- type="text"- x-model="$store.browserConfig.config.default_homepage"- placeholder="about:blank or https://example.com"- autocomplete="off"- />- </label>-- <label class="browser-config-switch-row">- <span class="browser-config-switch-copy">- <span class="browser-config-field-label">Autofocus active page</span>- <span class="browser-config-field-help">Update the visible Browser surface for pages opened or changed by Browser tool results.</span>- </span>- <span class="browser-config-toggle-with-label">- <span class="browser-config-toggle-label" x-text="$store.browserConfig.autofocusLabel()"></span>- <span class="browser-config-toggle">- <input- type="checkbox"- :checked="$store.browserConfig.config.autofocus_active_page !== false"- @change="$store.browserConfig.setAutofocusActivePage($event.target.checked)"- />- <span class="browser-config-switch"></span>- </span>- </span>- </label>- </div>-<div class="browser-config-card"><div class="section-title">Host Browser</div><div class="section-description">@@ -86,6 +51,41 @@</div></div>+ <div class="browser-config-card">+ <div class="section-title">Browsing</div>+ <div class="section-description">+ Set how new Browser sessions start and how an already-open Browser surface follows agent activity.+ </div>++ <label class="browser-config-field">+ <span class="browser-config-field-label">Starting page</span>+ <input+ type="text"+ x-model="$store.browserConfig.config.default_homepage"+ placeholder="about:blank or https://example.com"+ autocomplete="off"+ />+ </label>++ <label class="browser-config-switch-row">+ <span class="browser-config-switch-copy">+ <span class="browser-config-field-label">Autofocus active page</span>+ <span class="browser-config-field-help">Update the visible Browser surface for pages opened or changed by Browser tool results.</span>+ </span>+ <span class="browser-config-toggle-with-label">+ <span class="browser-config-toggle-label" x-text="$store.browserConfig.autofocusLabel()"></span>+ <span class="browser-config-toggle">+ <input+ type="checkbox"+ :checked="$store.browserConfig.config.autofocus_active_page !== false"+ @change="$store.browserConfig.setAutofocusActivePage($event.target.checked)"+ />+ <span class="browser-config-switch"></span>+ </span>+ </span>+ </label>+ </div>+<div class="browser-config-card"><div class="section-title">Extensions</div><div class="section-description">diff --git a/tests/test_browser_agent_regressions.py b/tests/test_browser_agent_regressions.pyindex aa38469a1..cc2c73269 100644--- a/tests/test_browser_agent_regressions.py+++ b/tests/test_browser_agent_regressions.py@@ -174,6 +174,10 @@ def test_browser_config_normalizes_host_backend_and_privacy_policy():assert config["runtime_backend"] == "host_required"assert config["host_browser_privacy_policy"] == "warn"+ assert (+ normalize_browser_config({"runtime_backend": "host_when_available"})["runtime_backend"]+ == "host_required"+ )def test_browser_model_selection_uses_presets(monkeypatch):