diff --git a/docs/configuration.md b/docs/configuration.md index c7cf32dfc..311e5cdfa 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1709,6 +1709,13 @@ Keep whitelist entries as narrow as possible, such as a single host CIDR (`192.1 HTTP/SSE MCP connections use the same process-wide proxy environment behavior as `web_fetch`: proxied targets use the configured proxy, and URLs excluded by `NO_PROXY` remain DNS-pinned direct connections. +In WebUI, open **Settings → Capabilities → Web access → Configure → Advanced options** +to set the web proxy. This setting applies to the agent's web search and page reading, +not model providers, MCP, or your browser. `127.0.0.1` refers to the machine that runs +nanobot, not the phone or computer that opens WebUI. Clear the field to use the default +network settings, which can include proxy environment variables. After saving, restart +nanobot when WebUI requests it. You can configure the proxy before enabling web access. + > [!TIP] > Use `proxy` in `tools.web` to route web requests through a proxy: > ```json diff --git a/tests/webui/test_settings_runtime.py b/tests/webui/test_settings_runtime.py index 7cf753a1f..f72550256 100644 --- a/tests/webui/test_settings_runtime.py +++ b/tests/webui/test_settings_runtime.py @@ -17,6 +17,22 @@ from nanobot.webui.settings_runtime import ( ) +def test_web_proxy_roundtrip_while_disabled_preserves_model_proxy(tmp_path): + path = tmp_path / "config.json" + config = Config() + config.tools.web.enable = False + config.providers.openai.proxy = "http://model-proxy.example:8080" + save_config(config, path) + for proxy in ("http://web-proxy.example:7890", None): + payload = update_runtime_config_settings({"tools.web.proxy": proxy}, local_browser=True, config_path=path) + assert payload["runtime_config"]["tools.web.proxy"] == proxy + assert payload["requires_restart"] + saved = load_config(path) + assert saved.tools.web.proxy == proxy + assert saved.tools.web.enable is False + assert saved.providers.openai.proxy == "http://model-proxy.example:8080" + + def test_runtime_patch_persists_and_preserves_other_domains(tmp_path): path = tmp_path / "config.json" config = Config.model_validate({ diff --git a/webui/src/components/settings/SettingsPage.tsx b/webui/src/components/settings/SettingsPage.tsx index 414d10fbe..082964590 100644 --- a/webui/src/components/settings/SettingsPage.tsx +++ b/webui/src/components/settings/SettingsPage.tsx @@ -519,7 +519,9 @@ export function SettingsPage({ olostepFeature={featureCatalog.find((feature) => feature.name === "olostep")} olostepInstalling={nanobotFeatureAction === "enable:olostep"} capabilityError={nanobotFeaturesError} - /> + > + {settings.runtime_config ? runtimeConfiguration("network") : null} + ); case "channels": diff --git a/webui/src/components/settings/capabilities/WebSettings.tsx b/webui/src/components/settings/capabilities/WebSettings.tsx index 7d8bdcc02..6a3221cd0 100644 --- a/webui/src/components/settings/capabilities/WebSettings.tsx +++ b/webui/src/components/settings/capabilities/WebSettings.tsx @@ -1,6 +1,6 @@ import { useAutoSave } from "@/components/settings/shared/useAutoSave"; import { SettingsAdvancedOptions } from "@/components/settings/shared/SettingsFeature"; -import type { Dispatch, SetStateAction } from "react"; +import type { Dispatch, ReactNode, SetStateAction } from "react"; import { Eye, EyeOff, Pencil } from "lucide-react"; import { useTranslation } from "react-i18next"; @@ -96,6 +96,7 @@ export function WebSettings({ olostepFeature, olostepInstalling, capabilityError, + children, }: { embedded?: boolean; error?: string; @@ -118,6 +119,7 @@ export function WebSettings({ olostepFeature?: NanobotFeatureInfo; olostepInstalling: boolean; capabilityError: string | null; + children?: ReactNode; }) { const { t } = useTranslation(); const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); @@ -272,6 +274,7 @@ export function WebSettings({ label={effectiveJinaReader ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")} /> + {children} { installSettingsViewTestHooks(); + it("edits the existing web proxy in web access even while disabled, without a duplicate advanced editor", async () => { + let payload = { ...settingsPayload(), runtime_config: { + "tools.web.enable": false, "tools.web.proxy": "http://old-proxy.example:8080", "tools.web.user_agent": null, + } } as SettingsPayload; + requestMutationMock.mockImplementation(async (_method, update) => { + payload = { ...payload, runtime_config: { ...payload.runtime_config, ...update.values }, + requires_restart: true, restart_required_sections: ["runtime"] }; + return payload; + }); + renderSettingsView({ initialSection: "capabilities", initialSettings: payload }); + fireEvent.click(within(screen.getByRole("region", { name: "Web access" })).getByRole("button", { name: "Configure" })); + fireEvent.click(screen.getByRole("button", { name: "Advanced options" })); + const proxy = screen.getByRole("textbox", { name: "Web proxy", exact: true }); + expect(proxy).toHaveValue("http://old-proxy.example:8080"); + fireEvent.change(proxy, { target: { value: "http://new-proxy.example:7890" } }); + await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith( + "settings.runtime_config.update", { values: { "tools.web.proxy": "http://new-proxy.example:7890" } }, 20_000, + )); + expect(await screen.findByText("Saved. Restart to apply changes.")).toBeVisible(); + fireEvent.change(proxy, { target: { value: "" } }); + await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith( + "settings.runtime_config.update", { values: { "tools.web.proxy": null } }, 20_000, + )); + fireEvent.click(within(screen.getByRole("dialog", { name: "Web access" })).getByRole("button", { name: "Close", exact: true })); + expect(screen.getByRole("switch", { name: "Web access" })).not.toBeChecked(); + fireEvent.click(screen.getByRole("button", { name: "Advanced", exact: true })); + expect(screen.queryByRole("textbox", { name: "Web proxy", exact: true })).not.toBeInTheDocument(); + }); + it("opens configuration for disabled features without enabling them", () => { const payload = settingsPayload(); payload.image_generation.enabled = false;